hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/scsi/libsas/sas_ata.c
....@@ -1,24 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Support for SATA devices on Serial Attached SCSI (SAS) controllers
34 *
45 * Copyright (C) 2006 IBM Corporation
56 *
67 * 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
228 */
239
2410 #include <linux/scatterlist.h>
....@@ -75,8 +61,8 @@
7561
7662 case SAS_OPEN_TO:
7763 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);
8066 return AC_ERR_OTHER;
8167
8268 case SAM_STAT_CHECK_CONDITION:
....@@ -136,9 +122,10 @@
136122 }
137123 }
138124
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)) {
142129 memcpy(dev->sata_dev.fis, resp->ending_fis, ATA_RESP_FIS_SIZE);
143130
144131 if (!link->sactive) {
....@@ -151,8 +138,7 @@
151138 } else {
152139 ac = sas_to_ata_err(stat);
153140 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);
156142 /* We saw a SAS error. Send a vague error. */
157143 if (!link->sactive) {
158144 qc->err_mask = ac;
....@@ -175,6 +161,7 @@
175161 }
176162
177163 static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
164
+ __must_hold(ap->lock)
178165 {
179166 struct sas_task *task;
180167 struct scatterlist *sg;
....@@ -216,7 +203,7 @@
216203 task->total_xfer_len = qc->nbytes;
217204 task->num_scatter = qc->n_elem;
218205 task->data_dir = qc->dma_dir;
219
- } else if (qc->tf.protocol == ATA_PROT_NODATA) {
206
+ } else if (!ata_is_data(qc->tf.protocol)) {
220207 task->data_dir = DMA_NONE;
221208 } else {
222209 for_each_sg(qc->sg, sg, qc->n_elem, si)
....@@ -239,7 +226,7 @@
239226
240227 ret = i->dft->lldd_execute_task(task, GFP_ATOMIC);
241228 if (ret) {
242
- SAS_DPRINTK("lldd_execute_task returned: %d\n", ret);
229
+ pr_debug("lldd_execute_task returned: %d\n", ret);
243230
244231 if (qc->scsicmd)
245232 ASSIGN_SAS_TASK(qc->scsicmd, NULL);
....@@ -284,9 +271,9 @@
284271 res = sas_get_report_phy_sata(dev->parent, phy->phy_id,
285272 &dev->sata_dev.rps_resp);
286273 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);
290277 return res;
291278 }
292279 memcpy(dev->frame_rcvd, &dev->sata_dev.rps_resp.rps.fis,
....@@ -340,7 +327,7 @@
340327 case SAS_END_DEVICE:
341328 if (ex_phy->attached_sata_dev)
342329 return sas_ata_clear_pending(dev, ex_phy);
343
- /* fall through */
330
+ fallthrough;
344331 default:
345332 return -ENODEV;
346333 }
....@@ -377,7 +364,7 @@
377364 vaf.fmt = fmt;
378365 vaf.va = &args;
379366
380
- r = printk("%ssas: ata%u: %s: %pV",
367
+ r = printk("%s" SAS_FMT "ata%u: %s: %pV",
381368 level, ap->print_id, dev_name(dev), &vaf);
382369
383370 va_end(args);
....@@ -433,8 +420,7 @@
433420 if (task->task_state_flags & SAS_TASK_STATE_ABORTED ||
434421 task->task_state_flags & SAS_TASK_STATE_DONE) {
435422 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);
438424 goto out;
439425 }
440426 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
....@@ -454,7 +440,7 @@
454440 * aborted ata tasks, otherwise we (likely) leak the sas task
455441 * here
456442 */
457
- SAS_DPRINTK("%s: Task %p leaked.\n", __func__, task);
443
+ pr_warn("%s: Task %p leaked.\n", __func__, task);
458444
459445 if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
460446 task->task_state_flags &= ~SAS_TASK_STATE_ABORTED;
....@@ -524,10 +510,23 @@
524510 spin_unlock_irqrestore(&ha->lock, flags);
525511 }
526512
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
+
527527 static struct ata_port_operations sas_sata_ops = {
528
- .prereset = ata_std_prereset,
528
+ .prereset = sas_ata_prereset,
529529 .hardreset = sas_ata_hard_reset,
530
- .postreset = ata_std_postreset,
531530 .error_handler = ata_std_error_handler,
532531 .post_internal_cmd = sas_ata_post_internal,
533532 .qc_defer = ata_std_qc_defer,
....@@ -560,7 +559,7 @@
560559
561560 ata_host = kzalloc(sizeof(*ata_host), GFP_KERNEL);
562561 if (!ata_host) {
563
- SAS_DPRINTK("ata host alloc failed.\n");
562
+ pr_err("ata host alloc failed.\n");
564563 return -ENOMEM;
565564 }
566565
....@@ -568,7 +567,7 @@
568567
569568 ap = ata_sas_port_alloc(ata_host, &sata_port_info, shost);
570569 if (!ap) {
571
- SAS_DPRINTK("ata_sas_port_alloc failed.\n");
570
+ pr_err("ata_sas_port_alloc failed.\n");
572571 rc = -ENODEV;
573572 goto free_host;
574573 }
....@@ -603,12 +602,7 @@
603602
604603 /* Bounce SCSI-initiated commands to the SCSI EH */
605604 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);
610605 blk_abort_request(qc->scsicmd->request);
611
- spin_unlock_irqrestore(q->queue_lock, flags);
612606 return;
613607 }
614608
....@@ -656,7 +650,7 @@
656650 /* if libata could not bring the link up, don't surface
657651 * the device
658652 */
659
- if (ata_dev_disabled(sas_to_ata_dev(dev)))
653
+ if (!ata_dev_enabled(sas_to_ata_dev(dev)))
660654 sas_fail_probe(dev, __func__, -ENODEV);
661655 }
662656
....@@ -732,19 +726,13 @@
732726 */
733727 int sas_discover_sata(struct domain_device *dev)
734728 {
735
- int res;
736
-
737729 if (dev->dev_type == SAS_SATA_PM)
738730 return -ENODEV;
739731
740732 dev->sata_dev.class = sas_get_ata_command_set(dev);
741733 sas_fill_in_rphy(dev, dev->rphy);
742734
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);
748736 }
749737
750738 static void async_sas_ata_eh(void *data, async_cookie_t cookie)