.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Support for SATA devices on Serial Attached SCSI (SAS) controllers |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2006 IBM Corporation |
---|
5 | 6 | * |
---|
6 | 7 | * Written by: Darrick J. Wong <djwong@us.ibm.com>, IBM Corporation |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or |
---|
9 | | - * modify it under the terms of the GNU General Public License as |
---|
10 | | - * published by the Free Software Foundation; either version 2 of the |
---|
11 | | - * License, or (at your option) any later version. |
---|
12 | | - * |
---|
13 | | - * This program is distributed in the hope that it will be useful, but |
---|
14 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | | - * General Public License for more details. |
---|
17 | | - * |
---|
18 | | - * You should have received a copy of the GNU General Public License |
---|
19 | | - * along with this program; if not, write to the Free Software |
---|
20 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
21 | | - * USA |
---|
22 | 8 | */ |
---|
23 | 9 | |
---|
24 | 10 | #include <linux/scatterlist.h> |
---|
.. | .. |
---|
75 | 61 | |
---|
76 | 62 | case SAS_OPEN_TO: |
---|
77 | 63 | case SAS_OPEN_REJECT: |
---|
78 | | - SAS_DPRINTK("%s: Saw error %d. What to do?\n", |
---|
79 | | - __func__, ts->stat); |
---|
| 64 | + pr_warn("%s: Saw error %d. What to do?\n", |
---|
| 65 | + __func__, ts->stat); |
---|
80 | 66 | return AC_ERR_OTHER; |
---|
81 | 67 | |
---|
82 | 68 | case SAM_STAT_CHECK_CONDITION: |
---|
.. | .. |
---|
136 | 122 | } |
---|
137 | 123 | } |
---|
138 | 124 | |
---|
139 | | - if (stat->stat == SAS_PROTO_RESPONSE || stat->stat == SAM_STAT_GOOD || |
---|
140 | | - ((stat->stat == SAM_STAT_CHECK_CONDITION && |
---|
141 | | - dev->sata_dev.class == ATA_DEV_ATAPI))) { |
---|
| 125 | + if (stat->stat == SAS_PROTO_RESPONSE || |
---|
| 126 | + stat->stat == SAS_SAM_STAT_GOOD || |
---|
| 127 | + (stat->stat == SAS_SAM_STAT_CHECK_CONDITION && |
---|
| 128 | + dev->sata_dev.class == ATA_DEV_ATAPI)) { |
---|
142 | 129 | memcpy(dev->sata_dev.fis, resp->ending_fis, ATA_RESP_FIS_SIZE); |
---|
143 | 130 | |
---|
144 | 131 | if (!link->sactive) { |
---|
.. | .. |
---|
151 | 138 | } else { |
---|
152 | 139 | ac = sas_to_ata_err(stat); |
---|
153 | 140 | if (ac) { |
---|
154 | | - SAS_DPRINTK("%s: SAS error %x\n", __func__, |
---|
155 | | - stat->stat); |
---|
| 141 | + pr_warn("%s: SAS error 0x%x\n", __func__, stat->stat); |
---|
156 | 142 | /* We saw a SAS error. Send a vague error. */ |
---|
157 | 143 | if (!link->sactive) { |
---|
158 | 144 | qc->err_mask = ac; |
---|
.. | .. |
---|
175 | 161 | } |
---|
176 | 162 | |
---|
177 | 163 | static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) |
---|
| 164 | + __must_hold(ap->lock) |
---|
178 | 165 | { |
---|
179 | 166 | struct sas_task *task; |
---|
180 | 167 | struct scatterlist *sg; |
---|
.. | .. |
---|
216 | 203 | task->total_xfer_len = qc->nbytes; |
---|
217 | 204 | task->num_scatter = qc->n_elem; |
---|
218 | 205 | task->data_dir = qc->dma_dir; |
---|
219 | | - } else if (qc->tf.protocol == ATA_PROT_NODATA) { |
---|
| 206 | + } else if (!ata_is_data(qc->tf.protocol)) { |
---|
220 | 207 | task->data_dir = DMA_NONE; |
---|
221 | 208 | } else { |
---|
222 | 209 | for_each_sg(qc->sg, sg, qc->n_elem, si) |
---|
.. | .. |
---|
239 | 226 | |
---|
240 | 227 | ret = i->dft->lldd_execute_task(task, GFP_ATOMIC); |
---|
241 | 228 | if (ret) { |
---|
242 | | - SAS_DPRINTK("lldd_execute_task returned: %d\n", ret); |
---|
| 229 | + pr_debug("lldd_execute_task returned: %d\n", ret); |
---|
243 | 230 | |
---|
244 | 231 | if (qc->scsicmd) |
---|
245 | 232 | ASSIGN_SAS_TASK(qc->scsicmd, NULL); |
---|
.. | .. |
---|
284 | 271 | res = sas_get_report_phy_sata(dev->parent, phy->phy_id, |
---|
285 | 272 | &dev->sata_dev.rps_resp); |
---|
286 | 273 | if (res) { |
---|
287 | | - SAS_DPRINTK("report phy sata to %016llx:0x%x returned " |
---|
288 | | - "0x%x\n", SAS_ADDR(dev->parent->sas_addr), |
---|
289 | | - phy->phy_id, res); |
---|
| 274 | + pr_debug("report phy sata to %016llx:%02d returned 0x%x\n", |
---|
| 275 | + SAS_ADDR(dev->parent->sas_addr), |
---|
| 276 | + phy->phy_id, res); |
---|
290 | 277 | return res; |
---|
291 | 278 | } |
---|
292 | 279 | memcpy(dev->frame_rcvd, &dev->sata_dev.rps_resp.rps.fis, |
---|
.. | .. |
---|
340 | 327 | case SAS_END_DEVICE: |
---|
341 | 328 | if (ex_phy->attached_sata_dev) |
---|
342 | 329 | return sas_ata_clear_pending(dev, ex_phy); |
---|
343 | | - /* fall through */ |
---|
| 330 | + fallthrough; |
---|
344 | 331 | default: |
---|
345 | 332 | return -ENODEV; |
---|
346 | 333 | } |
---|
.. | .. |
---|
377 | 364 | vaf.fmt = fmt; |
---|
378 | 365 | vaf.va = &args; |
---|
379 | 366 | |
---|
380 | | - r = printk("%ssas: ata%u: %s: %pV", |
---|
| 367 | + r = printk("%s" SAS_FMT "ata%u: %s: %pV", |
---|
381 | 368 | level, ap->print_id, dev_name(dev), &vaf); |
---|
382 | 369 | |
---|
383 | 370 | va_end(args); |
---|
.. | .. |
---|
433 | 420 | if (task->task_state_flags & SAS_TASK_STATE_ABORTED || |
---|
434 | 421 | task->task_state_flags & SAS_TASK_STATE_DONE) { |
---|
435 | 422 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
---|
436 | | - SAS_DPRINTK("%s: Task %p already finished.\n", __func__, |
---|
437 | | - task); |
---|
| 423 | + pr_debug("%s: Task %p already finished.\n", __func__, task); |
---|
438 | 424 | goto out; |
---|
439 | 425 | } |
---|
440 | 426 | task->task_state_flags |= SAS_TASK_STATE_ABORTED; |
---|
.. | .. |
---|
454 | 440 | * aborted ata tasks, otherwise we (likely) leak the sas task |
---|
455 | 441 | * here |
---|
456 | 442 | */ |
---|
457 | | - SAS_DPRINTK("%s: Task %p leaked.\n", __func__, task); |
---|
| 443 | + pr_warn("%s: Task %p leaked.\n", __func__, task); |
---|
458 | 444 | |
---|
459 | 445 | if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) |
---|
460 | 446 | task->task_state_flags &= ~SAS_TASK_STATE_ABORTED; |
---|
.. | .. |
---|
524 | 510 | spin_unlock_irqrestore(&ha->lock, flags); |
---|
525 | 511 | } |
---|
526 | 512 | |
---|
| 513 | +static int sas_ata_prereset(struct ata_link *link, unsigned long deadline) |
---|
| 514 | +{ |
---|
| 515 | + struct ata_port *ap = link->ap; |
---|
| 516 | + struct domain_device *dev = ap->private_data; |
---|
| 517 | + struct sas_phy *local_phy = sas_get_local_phy(dev); |
---|
| 518 | + int res = 0; |
---|
| 519 | + |
---|
| 520 | + if (!local_phy->enabled || test_bit(SAS_DEV_GONE, &dev->state)) |
---|
| 521 | + res = -ENOENT; |
---|
| 522 | + sas_put_local_phy(local_phy); |
---|
| 523 | + |
---|
| 524 | + return res; |
---|
| 525 | +} |
---|
| 526 | + |
---|
527 | 527 | static struct ata_port_operations sas_sata_ops = { |
---|
528 | | - .prereset = ata_std_prereset, |
---|
| 528 | + .prereset = sas_ata_prereset, |
---|
529 | 529 | .hardreset = sas_ata_hard_reset, |
---|
530 | | - .postreset = ata_std_postreset, |
---|
531 | 530 | .error_handler = ata_std_error_handler, |
---|
532 | 531 | .post_internal_cmd = sas_ata_post_internal, |
---|
533 | 532 | .qc_defer = ata_std_qc_defer, |
---|
.. | .. |
---|
560 | 559 | |
---|
561 | 560 | ata_host = kzalloc(sizeof(*ata_host), GFP_KERNEL); |
---|
562 | 561 | if (!ata_host) { |
---|
563 | | - SAS_DPRINTK("ata host alloc failed.\n"); |
---|
| 562 | + pr_err("ata host alloc failed.\n"); |
---|
564 | 563 | return -ENOMEM; |
---|
565 | 564 | } |
---|
566 | 565 | |
---|
.. | .. |
---|
568 | 567 | |
---|
569 | 568 | ap = ata_sas_port_alloc(ata_host, &sata_port_info, shost); |
---|
570 | 569 | if (!ap) { |
---|
571 | | - SAS_DPRINTK("ata_sas_port_alloc failed.\n"); |
---|
| 570 | + pr_err("ata_sas_port_alloc failed.\n"); |
---|
572 | 571 | rc = -ENODEV; |
---|
573 | 572 | goto free_host; |
---|
574 | 573 | } |
---|
.. | .. |
---|
603 | 602 | |
---|
604 | 603 | /* Bounce SCSI-initiated commands to the SCSI EH */ |
---|
605 | 604 | if (qc->scsicmd) { |
---|
606 | | - struct request_queue *q = qc->scsicmd->device->request_queue; |
---|
607 | | - unsigned long flags; |
---|
608 | | - |
---|
609 | | - spin_lock_irqsave(q->queue_lock, flags); |
---|
610 | 605 | blk_abort_request(qc->scsicmd->request); |
---|
611 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
---|
612 | 606 | return; |
---|
613 | 607 | } |
---|
614 | 608 | |
---|
.. | .. |
---|
656 | 650 | /* if libata could not bring the link up, don't surface |
---|
657 | 651 | * the device |
---|
658 | 652 | */ |
---|
659 | | - if (ata_dev_disabled(sas_to_ata_dev(dev))) |
---|
| 653 | + if (!ata_dev_enabled(sas_to_ata_dev(dev))) |
---|
660 | 654 | sas_fail_probe(dev, __func__, -ENODEV); |
---|
661 | 655 | } |
---|
662 | 656 | |
---|
.. | .. |
---|
732 | 726 | */ |
---|
733 | 727 | int sas_discover_sata(struct domain_device *dev) |
---|
734 | 728 | { |
---|
735 | | - int res; |
---|
736 | | - |
---|
737 | 729 | if (dev->dev_type == SAS_SATA_PM) |
---|
738 | 730 | return -ENODEV; |
---|
739 | 731 | |
---|
740 | 732 | dev->sata_dev.class = sas_get_ata_command_set(dev); |
---|
741 | 733 | sas_fill_in_rphy(dev, dev->rphy); |
---|
742 | 734 | |
---|
743 | | - res = sas_notify_lldd_dev_found(dev); |
---|
744 | | - if (res) |
---|
745 | | - return res; |
---|
746 | | - |
---|
747 | | - return 0; |
---|
| 735 | + return sas_notify_lldd_dev_found(dev); |
---|
748 | 736 | } |
---|
749 | 737 | |
---|
750 | 738 | static void async_sas_ata_eh(void *data, async_cookie_t cookie) |
---|