| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | |
|---|
| 2 | 3 | /* |
|---|
| 3 | 4 | * acard-ahci.c - ACard AHCI SATA support |
|---|
| .. | .. |
|---|
| 8 | 9 | * |
|---|
| 9 | 10 | * Copyright 2010 Red Hat, Inc. |
|---|
| 10 | 11 | * |
|---|
| 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 | | - * |
|---|
| 27 | 12 | * libata documentation is available via 'make {ps|pdf}docs', |
|---|
| 28 | 13 | * as Documentation/driver-api/libata.rst |
|---|
| 29 | 14 | * |
|---|
| 30 | 15 | * AHCI hardware documentation: |
|---|
| 31 | 16 | * http://www.intel.com/technology/serialata/pdf/rev1_0.pdf |
|---|
| 32 | 17 | * http://www.intel.com/technology/serialata/pdf/rev1_1.pdf |
|---|
| 33 | | - * |
|---|
| 34 | 18 | */ |
|---|
| 35 | 19 | |
|---|
| 36 | 20 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 176 | 160 | } |
|---|
| 177 | 161 | #endif |
|---|
| 178 | 162 | |
|---|
| 179 | | -static int acard_ahci_configure_dma_masks(struct pci_dev *pdev, int using_dac) |
|---|
| 180 | | -{ |
|---|
| 181 | | - int rc; |
|---|
| 182 | | - |
|---|
| 183 | | - if (using_dac && |
|---|
| 184 | | - !dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
|---|
| 185 | | - rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
|---|
| 186 | | - if (rc) { |
|---|
| 187 | | - rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); |
|---|
| 188 | | - if (rc) { |
|---|
| 189 | | - dev_err(&pdev->dev, |
|---|
| 190 | | - "64-bit DMA enable failed\n"); |
|---|
| 191 | | - return rc; |
|---|
| 192 | | - } |
|---|
| 193 | | - } |
|---|
| 194 | | - } else { |
|---|
| 195 | | - rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
|---|
| 196 | | - if (rc) { |
|---|
| 197 | | - dev_err(&pdev->dev, "32-bit DMA enable failed\n"); |
|---|
| 198 | | - return rc; |
|---|
| 199 | | - } |
|---|
| 200 | | - rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); |
|---|
| 201 | | - if (rc) { |
|---|
| 202 | | - dev_err(&pdev->dev, |
|---|
| 203 | | - "32-bit consistent DMA enable failed\n"); |
|---|
| 204 | | - return rc; |
|---|
| 205 | | - } |
|---|
| 206 | | - } |
|---|
| 207 | | - return 0; |
|---|
| 208 | | -} |
|---|
| 209 | | - |
|---|
| 210 | 163 | static void acard_ahci_pci_print_info(struct ata_host *host) |
|---|
| 211 | 164 | { |
|---|
| 212 | 165 | struct pci_dev *pdev = to_pci_dev(host->dev); |
|---|
| .. | .. |
|---|
| 265 | 218 | void *cmd_tbl; |
|---|
| 266 | 219 | u32 opts; |
|---|
| 267 | 220 | const u32 cmd_fis_len = 5; /* five dwords */ |
|---|
| 268 | | - unsigned int n_elem; |
|---|
| 269 | 221 | |
|---|
| 270 | 222 | /* |
|---|
| 271 | 223 | * Fill in command table information. First, the header, |
|---|
| .. | .. |
|---|
| 279 | 231 | memcpy(cmd_tbl + AHCI_CMD_TBL_CDB, qc->cdb, qc->dev->cdb_len); |
|---|
| 280 | 232 | } |
|---|
| 281 | 233 | |
|---|
| 282 | | - n_elem = 0; |
|---|
| 283 | 234 | if (qc->flags & ATA_QCFLAG_DMAMAP) |
|---|
| 284 | | - n_elem = acard_ahci_fill_sg(qc, cmd_tbl); |
|---|
| 235 | + acard_ahci_fill_sg(qc, cmd_tbl); |
|---|
| 285 | 236 | |
|---|
| 286 | 237 | /* |
|---|
| 287 | 238 | * Fill in command slot information. |
|---|
| .. | .. |
|---|
| 362 | 313 | mem = dmam_alloc_coherent(dev, dma_sz, &mem_dma, GFP_KERNEL); |
|---|
| 363 | 314 | if (!mem) |
|---|
| 364 | 315 | return -ENOMEM; |
|---|
| 365 | | - memset(mem, 0, dma_sz); |
|---|
| 366 | 316 | |
|---|
| 367 | 317 | /* |
|---|
| 368 | 318 | * First item in chunk of DMA memory: 32-slot command table, |
|---|
| .. | .. |
|---|
| 490 | 440 | } |
|---|
| 491 | 441 | |
|---|
| 492 | 442 | /* initialize adapter */ |
|---|
| 493 | | - rc = acard_ahci_configure_dma_masks(pdev, hpriv->cap & HOST_CAP_64); |
|---|
| 494 | | - if (rc) |
|---|
| 443 | + rc = dma_set_mask_and_coherent(&pdev->dev, |
|---|
| 444 | + DMA_BIT_MASK((hpriv->cap & HOST_CAP_64) ? 64 : 32)); |
|---|
| 445 | + if (rc) { |
|---|
| 446 | + dev_err(&pdev->dev, "DMA enable failed\n"); |
|---|
| 495 | 447 | return rc; |
|---|
| 448 | + } |
|---|
| 496 | 449 | |
|---|
| 497 | 450 | rc = ahci_reset_controller(host); |
|---|
| 498 | 451 | if (rc) |
|---|