Skip to content

Commit fdc32fb

Browse files
Christoph Hellwigmartinkpetersen
authored andcommitted
scsi: esas2r: use dma_set_mask_and_coherent
The driver currently uses pci_set_dma_mask despite otherwise using the generic DMA API. Also move the dma_get_required_mask check before actually setting the dma mask so that we don't end up with inconsistent settings in corner cases. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent c79cd9a commit fdc32fb

File tree

1 file changed

+14
-35
lines changed

1 file changed

+14
-35
lines changed

drivers/scsi/esas2r/esas2r_init.c

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ int esas2r_init_adapter(struct Scsi_Host *host, struct pci_dev *pcid,
266266
int i;
267267
void *next_uncached;
268268
struct esas2r_request *first_request, *last_request;
269+
bool dma64 = false;
269270

270271
if (index >= MAX_ADAPTERS) {
271272
esas2r_log(ESAS2R_LOG_CRIT,
@@ -286,42 +287,20 @@ int esas2r_init_adapter(struct Scsi_Host *host, struct pci_dev *pcid,
286287
a->pcid = pcid;
287288
a->host = host;
288289

289-
if (sizeof(dma_addr_t) > 4) {
290-
const uint64_t required_mask = dma_get_required_mask
291-
(&pcid->dev);
292-
if (required_mask > DMA_BIT_MASK(32)
293-
&& !pci_set_dma_mask(pcid, DMA_BIT_MASK(64))
294-
&& !pci_set_consistent_dma_mask(pcid,
295-
DMA_BIT_MASK(64))) {
296-
esas2r_log_dev(ESAS2R_LOG_INFO,
297-
&(a->pcid->dev),
298-
"64-bit PCI addressing enabled\n");
299-
} else if (!pci_set_dma_mask(pcid, DMA_BIT_MASK(32))
300-
&& !pci_set_consistent_dma_mask(pcid,
301-
DMA_BIT_MASK(32))) {
302-
esas2r_log_dev(ESAS2R_LOG_INFO,
303-
&(a->pcid->dev),
304-
"32-bit PCI addressing enabled\n");
305-
} else {
306-
esas2r_log(ESAS2R_LOG_CRIT,
307-
"failed to set DMA mask");
308-
esas2r_kill_adapter(index);
309-
return 0;
310-
}
311-
} else {
312-
if (!pci_set_dma_mask(pcid, DMA_BIT_MASK(32))
313-
&& !pci_set_consistent_dma_mask(pcid,
314-
DMA_BIT_MASK(32))) {
315-
esas2r_log_dev(ESAS2R_LOG_INFO,
316-
&(a->pcid->dev),
317-
"32-bit PCI addressing enabled\n");
318-
} else {
319-
esas2r_log(ESAS2R_LOG_CRIT,
320-
"failed to set DMA mask");
321-
esas2r_kill_adapter(index);
322-
return 0;
323-
}
290+
if (sizeof(dma_addr_t) > 4 &&
291+
dma_get_required_mask(&pcid->dev) > DMA_BIT_MASK(32) &&
292+
!dma_set_mask_and_coherent(&pcid->dev, DMA_BIT_MASK(64)))
293+
dma64 = true;
294+
295+
if (!dma64 && dma_set_mask_and_coherent(&pcid->dev, DMA_BIT_MASK(32))) {
296+
esas2r_log(ESAS2R_LOG_CRIT, "failed to set DMA mask");
297+
esas2r_kill_adapter(index);
298+
return 0;
324299
}
300+
301+
esas2r_log_dev(ESAS2R_LOG_INFO, &pcid->dev,
302+
"%s-bit PCI addressing enabled\n", dma64 ? "64" : "32");
303+
325304
esas2r_adapters[index] = a;
326305
sprintf(a->name, ESAS2R_DRVR_NAME "_%02d", index);
327306
esas2r_debug("new adapter %p, name %s", a, a->name);

0 commit comments

Comments
 (0)