forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
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:
....@@ -151,8 +137,7 @@
151137 } else {
152138 ac = sas_to_ata_err(stat);
153139 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);
156141 /* We saw a SAS error. Send a vague error. */
157142 if (!link->sactive) {
158143 qc->err_mask = ac;
....@@ -175,6 +160,7 @@
175160 }
176161
177162 static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
163
+ __must_hold(ap->lock)
178164 {
179165 struct sas_task *task;
180166 struct scatterlist *sg;
....@@ -216,7 +202,7 @@
216202 task->total_xfer_len = qc->nbytes;
217203 task->num_scatter = qc->n_elem;
218204 task->data_dir = qc->dma_dir;
219
- } else if (qc->tf.protocol == ATA_PROT_NODATA) {
205
+ } else if (!ata_is_data(qc->tf.protocol)) {
220206 task->data_dir = DMA_NONE;
221207 } else {
222208 for_each_sg(qc->sg, sg, qc->n_elem, si)
....@@ -239,7 +225,7 @@
239225
240226 ret = i->dft->lldd_execute_task(task, GFP_ATOMIC);
241227 if (ret) {
242
- SAS_DPRINTK("lldd_execute_task returned: %d\n", ret);
228
+ pr_debug("lldd_execute_task returned: %d\n", ret);
243229
244230 if (qc->scsicmd)
245231 ASSIGN_SAS_TASK(qc->scsicmd, NULL);
....@@ -284,9 +270,9 @@
284270 res = sas_get_report_phy_sata(dev->parent, phy->phy_id,
285271 &dev->sata_dev.rps_resp);
286272 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);
290276 return res;
291277 }
292278 memcpy(dev->frame_rcvd, &dev->sata_dev.rps_resp.rps.fis,
....@@ -340,7 +326,7 @@
340326 case SAS_END_DEVICE:
341327 if (ex_phy->attached_sata_dev)
342328 return sas_ata_clear_pending(dev, ex_phy);
343
- /* fall through */
329
+ fallthrough;
344330 default:
345331 return -ENODEV;
346332 }
....@@ -377,7 +363,7 @@
377363 vaf.fmt = fmt;
378364 vaf.va = &args;
379365
380
- r = printk("%ssas: ata%u: %s: %pV",
366
+ r = printk("%s" SAS_FMT "ata%u: %s: %pV",
381367 level, ap->print_id, dev_name(dev), &vaf);
382368
383369 va_end(args);
....@@ -433,8 +419,7 @@
433419 if (task->task_state_flags & SAS_TASK_STATE_ABORTED ||
434420 task->task_state_flags & SAS_TASK_STATE_DONE) {
435421 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);
438423 goto out;
439424 }
440425 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
....@@ -454,7 +439,7 @@
454439 * aborted ata tasks, otherwise we (likely) leak the sas task
455440 * here
456441 */
457
- SAS_DPRINTK("%s: Task %p leaked.\n", __func__, task);
442
+ pr_warn("%s: Task %p leaked.\n", __func__, task);
458443
459444 if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
460445 task->task_state_flags &= ~SAS_TASK_STATE_ABORTED;
....@@ -524,10 +509,23 @@
524509 spin_unlock_irqrestore(&ha->lock, flags);
525510 }
526511
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
+
527526 static struct ata_port_operations sas_sata_ops = {
528
- .prereset = ata_std_prereset,
527
+ .prereset = sas_ata_prereset,
529528 .hardreset = sas_ata_hard_reset,
530
- .postreset = ata_std_postreset,
531529 .error_handler = ata_std_error_handler,
532530 .post_internal_cmd = sas_ata_post_internal,
533531 .qc_defer = ata_std_qc_defer,
....@@ -560,7 +558,7 @@
560558
561559 ata_host = kzalloc(sizeof(*ata_host), GFP_KERNEL);
562560 if (!ata_host) {
563
- SAS_DPRINTK("ata host alloc failed.\n");
561
+ pr_err("ata host alloc failed.\n");
564562 return -ENOMEM;
565563 }
566564
....@@ -568,7 +566,7 @@
568566
569567 ap = ata_sas_port_alloc(ata_host, &sata_port_info, shost);
570568 if (!ap) {
571
- SAS_DPRINTK("ata_sas_port_alloc failed.\n");
569
+ pr_err("ata_sas_port_alloc failed.\n");
572570 rc = -ENODEV;
573571 goto free_host;
574572 }
....@@ -603,12 +601,7 @@
603601
604602 /* Bounce SCSI-initiated commands to the SCSI EH */
605603 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);
610604 blk_abort_request(qc->scsicmd->request);
611
- spin_unlock_irqrestore(q->queue_lock, flags);
612605 return;
613606 }
614607
....@@ -656,7 +649,7 @@
656649 /* if libata could not bring the link up, don't surface
657650 * the device
658651 */
659
- if (ata_dev_disabled(sas_to_ata_dev(dev)))
652
+ if (!ata_dev_enabled(sas_to_ata_dev(dev)))
660653 sas_fail_probe(dev, __func__, -ENODEV);
661654 }
662655
....@@ -732,19 +725,13 @@
732725 */
733726 int sas_discover_sata(struct domain_device *dev)
734727 {
735
- int res;
736
-
737728 if (dev->dev_type == SAS_SATA_PM)
738729 return -ENODEV;
739730
740731 dev->sata_dev.class = sas_get_ata_command_set(dev);
741732 sas_fill_in_rphy(dev, dev->rphy);
742733
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);
748735 }
749736
750737 static void async_sas_ata_eh(void *data, async_cookie_t cookie)