| .. | .. |
|---|
| 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: |
|---|
| .. | .. |
|---|
| 151 | 137 | } else { |
|---|
| 152 | 138 | ac = sas_to_ata_err(stat); |
|---|
| 153 | 139 | if (ac) { |
|---|
| 154 | | - SAS_DPRINTK("%s: SAS error %x\n", __func__, |
|---|
| 155 | | - stat->stat); |
|---|
| 140 | + pr_warn("%s: SAS error 0x%x\n", __func__, stat->stat); |
|---|
| 156 | 141 | /* We saw a SAS error. Send a vague error. */ |
|---|
| 157 | 142 | if (!link->sactive) { |
|---|
| 158 | 143 | qc->err_mask = ac; |
|---|
| .. | .. |
|---|
| 175 | 160 | } |
|---|
| 176 | 161 | |
|---|
| 177 | 162 | static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) |
|---|
| 163 | + __must_hold(ap->lock) |
|---|
| 178 | 164 | { |
|---|
| 179 | 165 | struct sas_task *task; |
|---|
| 180 | 166 | struct scatterlist *sg; |
|---|
| .. | .. |
|---|
| 216 | 202 | task->total_xfer_len = qc->nbytes; |
|---|
| 217 | 203 | task->num_scatter = qc->n_elem; |
|---|
| 218 | 204 | task->data_dir = qc->dma_dir; |
|---|
| 219 | | - } else if (qc->tf.protocol == ATA_PROT_NODATA) { |
|---|
| 205 | + } else if (!ata_is_data(qc->tf.protocol)) { |
|---|
| 220 | 206 | task->data_dir = DMA_NONE; |
|---|
| 221 | 207 | } else { |
|---|
| 222 | 208 | for_each_sg(qc->sg, sg, qc->n_elem, si) |
|---|
| .. | .. |
|---|
| 239 | 225 | |
|---|
| 240 | 226 | ret = i->dft->lldd_execute_task(task, GFP_ATOMIC); |
|---|
| 241 | 227 | if (ret) { |
|---|
| 242 | | - SAS_DPRINTK("lldd_execute_task returned: %d\n", ret); |
|---|
| 228 | + pr_debug("lldd_execute_task returned: %d\n", ret); |
|---|
| 243 | 229 | |
|---|
| 244 | 230 | if (qc->scsicmd) |
|---|
| 245 | 231 | ASSIGN_SAS_TASK(qc->scsicmd, NULL); |
|---|
| .. | .. |
|---|
| 284 | 270 | res = sas_get_report_phy_sata(dev->parent, phy->phy_id, |
|---|
| 285 | 271 | &dev->sata_dev.rps_resp); |
|---|
| 286 | 272 | 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); |
|---|
| 273 | + pr_debug("report phy sata to %016llx:%02d returned 0x%x\n", |
|---|
| 274 | + SAS_ADDR(dev->parent->sas_addr), |
|---|
| 275 | + phy->phy_id, res); |
|---|
| 290 | 276 | return res; |
|---|
| 291 | 277 | } |
|---|
| 292 | 278 | memcpy(dev->frame_rcvd, &dev->sata_dev.rps_resp.rps.fis, |
|---|
| .. | .. |
|---|
| 340 | 326 | case SAS_END_DEVICE: |
|---|
| 341 | 327 | if (ex_phy->attached_sata_dev) |
|---|
| 342 | 328 | return sas_ata_clear_pending(dev, ex_phy); |
|---|
| 343 | | - /* fall through */ |
|---|
| 329 | + fallthrough; |
|---|
| 344 | 330 | default: |
|---|
| 345 | 331 | return -ENODEV; |
|---|
| 346 | 332 | } |
|---|
| .. | .. |
|---|
| 377 | 363 | vaf.fmt = fmt; |
|---|
| 378 | 364 | vaf.va = &args; |
|---|
| 379 | 365 | |
|---|
| 380 | | - r = printk("%ssas: ata%u: %s: %pV", |
|---|
| 366 | + r = printk("%s" SAS_FMT "ata%u: %s: %pV", |
|---|
| 381 | 367 | level, ap->print_id, dev_name(dev), &vaf); |
|---|
| 382 | 368 | |
|---|
| 383 | 369 | va_end(args); |
|---|
| .. | .. |
|---|
| 433 | 419 | if (task->task_state_flags & SAS_TASK_STATE_ABORTED || |
|---|
| 434 | 420 | task->task_state_flags & SAS_TASK_STATE_DONE) { |
|---|
| 435 | 421 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
|---|
| 436 | | - SAS_DPRINTK("%s: Task %p already finished.\n", __func__, |
|---|
| 437 | | - task); |
|---|
| 422 | + pr_debug("%s: Task %p already finished.\n", __func__, task); |
|---|
| 438 | 423 | goto out; |
|---|
| 439 | 424 | } |
|---|
| 440 | 425 | task->task_state_flags |= SAS_TASK_STATE_ABORTED; |
|---|
| .. | .. |
|---|
| 454 | 439 | * aborted ata tasks, otherwise we (likely) leak the sas task |
|---|
| 455 | 440 | * here |
|---|
| 456 | 441 | */ |
|---|
| 457 | | - SAS_DPRINTK("%s: Task %p leaked.\n", __func__, task); |
|---|
| 442 | + pr_warn("%s: Task %p leaked.\n", __func__, task); |
|---|
| 458 | 443 | |
|---|
| 459 | 444 | if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) |
|---|
| 460 | 445 | task->task_state_flags &= ~SAS_TASK_STATE_ABORTED; |
|---|
| .. | .. |
|---|
| 524 | 509 | spin_unlock_irqrestore(&ha->lock, flags); |
|---|
| 525 | 510 | } |
|---|
| 526 | 511 | |
|---|
| 512 | +static int sas_ata_prereset(struct ata_link *link, unsigned long deadline) |
|---|
| 513 | +{ |
|---|
| 514 | + struct ata_port *ap = link->ap; |
|---|
| 515 | + struct domain_device *dev = ap->private_data; |
|---|
| 516 | + struct sas_phy *local_phy = sas_get_local_phy(dev); |
|---|
| 517 | + int res = 0; |
|---|
| 518 | + |
|---|
| 519 | + if (!local_phy->enabled || test_bit(SAS_DEV_GONE, &dev->state)) |
|---|
| 520 | + res = -ENOENT; |
|---|
| 521 | + sas_put_local_phy(local_phy); |
|---|
| 522 | + |
|---|
| 523 | + return res; |
|---|
| 524 | +} |
|---|
| 525 | + |
|---|
| 527 | 526 | static struct ata_port_operations sas_sata_ops = { |
|---|
| 528 | | - .prereset = ata_std_prereset, |
|---|
| 527 | + .prereset = sas_ata_prereset, |
|---|
| 529 | 528 | .hardreset = sas_ata_hard_reset, |
|---|
| 530 | | - .postreset = ata_std_postreset, |
|---|
| 531 | 529 | .error_handler = ata_std_error_handler, |
|---|
| 532 | 530 | .post_internal_cmd = sas_ata_post_internal, |
|---|
| 533 | 531 | .qc_defer = ata_std_qc_defer, |
|---|
| .. | .. |
|---|
| 560 | 558 | |
|---|
| 561 | 559 | ata_host = kzalloc(sizeof(*ata_host), GFP_KERNEL); |
|---|
| 562 | 560 | if (!ata_host) { |
|---|
| 563 | | - SAS_DPRINTK("ata host alloc failed.\n"); |
|---|
| 561 | + pr_err("ata host alloc failed.\n"); |
|---|
| 564 | 562 | return -ENOMEM; |
|---|
| 565 | 563 | } |
|---|
| 566 | 564 | |
|---|
| .. | .. |
|---|
| 568 | 566 | |
|---|
| 569 | 567 | ap = ata_sas_port_alloc(ata_host, &sata_port_info, shost); |
|---|
| 570 | 568 | if (!ap) { |
|---|
| 571 | | - SAS_DPRINTK("ata_sas_port_alloc failed.\n"); |
|---|
| 569 | + pr_err("ata_sas_port_alloc failed.\n"); |
|---|
| 572 | 570 | rc = -ENODEV; |
|---|
| 573 | 571 | goto free_host; |
|---|
| 574 | 572 | } |
|---|
| .. | .. |
|---|
| 603 | 601 | |
|---|
| 604 | 602 | /* Bounce SCSI-initiated commands to the SCSI EH */ |
|---|
| 605 | 603 | 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 | 604 | blk_abort_request(qc->scsicmd->request); |
|---|
| 611 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
|---|
| 612 | 605 | return; |
|---|
| 613 | 606 | } |
|---|
| 614 | 607 | |
|---|
| .. | .. |
|---|
| 656 | 649 | /* if libata could not bring the link up, don't surface |
|---|
| 657 | 650 | * the device |
|---|
| 658 | 651 | */ |
|---|
| 659 | | - if (ata_dev_disabled(sas_to_ata_dev(dev))) |
|---|
| 652 | + if (!ata_dev_enabled(sas_to_ata_dev(dev))) |
|---|
| 660 | 653 | sas_fail_probe(dev, __func__, -ENODEV); |
|---|
| 661 | 654 | } |
|---|
| 662 | 655 | |
|---|
| .. | .. |
|---|
| 732 | 725 | */ |
|---|
| 733 | 726 | int sas_discover_sata(struct domain_device *dev) |
|---|
| 734 | 727 | { |
|---|
| 735 | | - int res; |
|---|
| 736 | | - |
|---|
| 737 | 728 | if (dev->dev_type == SAS_SATA_PM) |
|---|
| 738 | 729 | return -ENODEV; |
|---|
| 739 | 730 | |
|---|
| 740 | 731 | dev->sata_dev.class = sas_get_ata_command_set(dev); |
|---|
| 741 | 732 | sas_fill_in_rphy(dev, dev->rphy); |
|---|
| 742 | 733 | |
|---|
| 743 | | - res = sas_notify_lldd_dev_found(dev); |
|---|
| 744 | | - if (res) |
|---|
| 745 | | - return res; |
|---|
| 746 | | - |
|---|
| 747 | | - return 0; |
|---|
| 734 | + return sas_notify_lldd_dev_found(dev); |
|---|
| 748 | 735 | } |
|---|
| 749 | 736 | |
|---|
| 750 | 737 | static void async_sas_ata_eh(void *data, async_cookie_t cookie) |
|---|