phase out CONFIG_VIRT_TO_BUS
Subsystems (16)
v2 cover phase out CONFIG_VIRT_TO_BUS
From: Arnd Bergmann <[email protected]>
The virt_to_bus/bus_to_virt interface has been deprecated for decades. After Jakub Kicinski put a lot of work into cleaning out the network drivers using them, there are only a couple of other drivers left, which can all be removed or otherwise cleaned up, to remove the old interface for good.
Any out of tree drivers using virt_to_bus() should be converted to using the dma-mapping interfaces, typically dma_alloc_coherent() or dma_map_single()).
There are a few m68k and ppc32 specific drivers that keep using the interfaces, but these are all guarded with architecture-specific Kconfig dependencies, and are not actually broken.
There are still a number of drivers that are using virt_to_phys() and phys_to_virt() in place of dma-mapping operations, and these are often broken, but they are out of scope for this series.
I would like the first two patches to either get merged through the SCSI tree, or get an Ack from the SCSI maintainers so I can merge them through the asm-generic tree
Arnd
---
Changes since v1:
- dropped VME patches that are already in staging-next
- dropped media patch that gets merged independently
- added a networking patch and dropped it again after it got merged
- replace BusLogic removal with a workaround
Arnd Bergmann (3):
scsi: dpt_i2o: drop stale VIRT_TO_BUS dependency
scsi: BusLogic remove bus_to_virt arch/*/: remove CONFIG_VIRT_TO_BUS
.../core-api/bus-virt-phys-mapping.rst | 220 ------------------ Documentation/core-api/dma-api-howto.rst | 14 -- Documentation/core-api/index.rst | 1 - .../translations/zh_CN/core-api/index.rst | 1 - arch/alpha/Kconfig | 1 - arch/alpha/include/asm/floppy.h | 2 +- arch/alpha/include/asm/io.h | 8 +- arch/ia64/Kconfig | 1 - arch/ia64/include/asm/io.h | 8 - arch/m68k/Kconfig | 1 - arch/m68k/include/asm/virtconvert.h | 4 +- arch/microblaze/Kconfig | 1 - arch/microblaze/include/asm/io.h | 2 - arch/mips/Kconfig | 1 - arch/mips/include/asm/io.h | 9 - arch/parisc/Kconfig | 1 - arch/parisc/include/asm/floppy.h | 4 +- arch/parisc/include/asm/io.h | 2 - arch/powerpc/Kconfig | 1 - arch/powerpc/include/asm/io.h | 2 - arch/riscv/include/asm/page.h | 1 - arch/x86/Kconfig | 1 - arch/x86/include/asm/io.h | 9 - arch/xtensa/Kconfig | 1 - arch/xtensa/include/asm/io.h | 3 - drivers/scsi/BusLogic.c | 27 ++- drivers/scsi/Kconfig | 4 +- drivers/scsi/dpt_i2o.c | 4 +- include/asm-generic/io.h | 14 -- mm/Kconfig | 8 - 30 files changed, 30 insertions(+), 326 deletions(-) delete mode 100644 Documentation/core-api/bus-virt-phys-mapping.rst
Signature · 1 line
2.29.2
PATCH v2 1/3 scsi: dpt_i2o: drop stale VIRT_TO_BUS dependency
From: Arnd Bergmann <[email protected]>
The dpt_i2o driver was fixed to stop using virt_to_bus() in 2008, but it still has a stale reference in an error handling code path that could never work.
Fix it up to build without VIRT_TO_BUS and remove the Kconfig dependency.
The alternative to this would be to just remove the driver, as it is clearly obsolete. The i2o driver layer was removed in 2015 with commit 4a72a7af462d ("staging: remove i2o subsystem"), but the even older dpt_i2o scsi driver stayed around.
The last non-cleanup patches I could find were from Miquel van Smoorenburg and Mark Salyzyn back in 2008, they might know if there is any chance of the hardware still being used anywhere.
--- drivers/scsi/Kconfig | 2 +- drivers/scsi/dpt_i2o.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/Kconfig +1 -1
@@ -460,7 +460,7 @@ config SCSI_MVUMI config SCSI_DPT_I2O tristate "Adaptec I2O RAID support " - depends on SCSI && PCI && VIRT_TO_BUS + depends on SCSI && PCI help This driver supports all of Adaptec's I2O based RAID controllers as well as the DPT SmartRaid V cards. This is an Adaptec maintained
drivers/scsi/dpt_i2o.c +2 -2
@@ -52,11 +52,11 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");#include <linux/timer.h> #include <linux/string.h> +#include <linux/io.h> #include <linux/ioport.h> #include <linux/mutex.h> #include <asm/processor.h> /* for boot_cpu_data */ -#include <asm/io.h> /* for virt_to_bus, etc. */ #include <scsi/scsi.h> #include <scsi/scsi_cmnd.h>
@@ -2112,7 +2112,7 @@ static irqreturn_t adpt_isr(int irq, void *dev_id) }else {/* Ick, we should *never* be here */ printk (KERN_ERR "dpti: reply frame not from pool\n" ); - reply = (u8 *)bus_to_virt (m); + goto out; }if (readl (reply) &MSG_FAIL ) {
Signature · 1 line
2.29.2
Re: [PATCH v2 1/3] scsi: dpt_i2o: drop stale VIRT_TO_BUS dependency
Quoted 57 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The
dpt_i2odriver was fixed to stop usingvirt_to_bus()in 2008, but it still has a stale reference in an error handling code path that could never work.Fix it up to build without
VIRT_TO_BUSand remove theKconfigdependency.The alternative to this would be to just remove the driver, as it is clearly obsolete. The i2o driver layer was removed in 2015 with commit
4a72a7af462d("staging: remove i2o subsystem"), but the even olderdpt_i2oscsi driver stayed around.The last non-cleanup patches I could find were from Miquel van Smoorenburg and Mark Salyzyn back in 2008, they might know if there is any chance of the hardware still being used anywhere.
Fixes 67af2b060e02 ("[SCSI] dpt_i2o: move from virt_to_bus/bus_to_virt to dma_alloc_coherent")Cc Miquel van Smoorenburg <[email protected]>Cc Mark Salyzyn <[email protected]>Signed-off-by Arnd Bergmann <[email protected]>--- drivers/scsi/Kconfig | 2 +- drivers/scsi/dpt_i2o.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/scsi/Kconfig +1
-1@@ -460,7 +460,7 @@ config SCSI_MVUMI config SCSI_DPT_I2O tristate "Adaptec I2O RAID support " - depends on SCSI && PCI && VIRT_TO_BUS + depends on SCSI && PCI help This driver supports all of Adaptec's I2O based RAID controllers as well as the DPT SmartRaid V cards. This is an Adaptec maintaineddrivers/scsi/dpt_i2o.c +1
-1@@ -52,11 +52,11 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");#include <linux/timer.h> #include <linux/string.h> +#include <linux/io.h> #include <linux/ioport.h> #include <linux/mutex.h> #include <asm/processor.h> /* for boot_cpu_data */ -#include <asm/io.h> /* for virt_to_bus, etc. */ #include <scsi/scsi.h> #include <scsi/scsi_cmnd.h>
drivers/scsi/dpt_i2o.c static irqreturn_t adpt_isr(int irq, void *dev_id) · line 2118
Quoted 8 lines
drivers/scsi/dpt_i2o.c +1
-1@@ -2112,7 +2112,7 @@ static irqreturn_t adpt_isr(int irq, void *dev_id) }else {/* Ick, we should *never* be here */ printk (KERN_ERR "dpti: reply frame not from pool\n" ); - reply = (u8 *)bus_to_virt (m); + goto out; }if (readl (reply) &MSG_FAIL ) {
Personally I wouldn't mind to see this driver gone, as it's being built upon the (long-defunct) I2O specification. We already deleted the i2o subsystem years ago, so maybe it's time to consign this driver to history, too.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
PATCH v2 2/3 scsi: BusLogic remove bus_to_virt
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
The BusLogic driver is the last remaining driver that relies on the deprecated bus_to_virt() function, which in turn only works on a few architectures, and is incompatible with both swiotlb and iommu support.
Before commit 391e2f25601e ("[SCSI] BusLogic: Port driver to 64-bit."), the driver had a dependency on x86-32, presumably because of this problem. However, the change introduced another bug that made it still impossible to use the driver on any 64-bit machine.
This was in turn fixed in commit 56f396146af2 ("scsi: BusLogic: Fix 64-bit system enumeration error for Buslogic"), 8 years later, which shows that there are not a lot of users.
Maciej is still using the driver on 32-bit hardware, and Khalid mentioned that the driver works with the device emulation used in VirtualBox and VMware. Both of those only emulate it for Windows 2000 and older operating systems that did not ship with the better LSI logic driver.
Do a minimum fix that searches through the list of descriptors to find one that matches the bus address. This is clearly as inefficient as was indicated in the code comment about the lack of a bus_to_virt() replacement. A better fix would likely involve changing out the entire descriptor allocation for a simpler one, but that would be much more invasive.
--- drivers/scsi/BusLogic.c | 27 ++++++++++++++++----------- drivers/scsi/Kconfig | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-)
drivers/scsi/BusLogic.c +16 -11
@@ -2515,12 +2515,26 @@ static int blogic_resultcode(struct blogic_adapter *adapter,return (hoststatus <<16 ) | tgt_status; } +/* +* turn the dma address from an inbox into a ccb pointer +* This is rather inefficient. +*/ +static struct blogic_ccb * +blogic_inbox_to_ccb (struct blogic_adapter *adapter,struct blogic_inbox *inbox) +{ +struct blogic_ccb *ccb; + +for (ccb = adapter->all_ccbs; ccb; ccb = ccb->next_all) +if (inbox->ccb == ccb->dma_handle) +break ; + +return ccb; +}/* blogic_scan_inbox scans the Incoming Mailboxes saving any Incoming Mailbox entries for completion processing. */ -static void blogic_scan_inbox (struct blogic_adapter *adapter) {/*
@@ -2540,16 +2554,7 @@ static void blogic_scan_inbox(struct blogic_adapter *adapter)enum blogic_cmplt_code comp_code;while ((comp_code = next_inbox->comp_code) !=BLOGIC_INBOX_FREE ) { -/* -We are only allowed to do this because we limit our -architectures we run on to machines where bus_to_virt( -actually works. There *needs* to be a dma_addr_to_virt() -in the new PCI DMA mapping interface to replace -bus_to_virt() or else this code is going to become very -innefficient. -*/ -struct blogic_ccb *ccb = - (struct blogic_ccb *)bus_to_virt (next_inbox->ccb); +struct blogic_ccb *ccb =blogic_inbox_to_ccb (adapter, adapter->next_inbox);if (comp_code !=BLOGIC_CMD_NOTFOUND ) {if (ccb->status ==BLOGIC_CCB_ACTIVE || ccb->status ==BLOGIC_CCB_RESET ) {
drivers/scsi/Kconfig +1 -1
@@ -513,7 +513,7 @@ config SCSI_HPTIOP config SCSI_BUSLOGIC tristate "BusLogic SCSI support" - depends on PCI && SCSI && VIRT_TO_BUS + depends on PCI && SCSI help This is support for BusLogic MultiMaster and FlashPoint SCSI Host Adapters. Consult the SCSI-HOWTO, available from
Signature · 1 line
2.29.2
Re: [PATCH v2 2/3] scsi: BusLogic remove bus_to_virt
Quoted 20 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The BusLogic driver is the last remaining driver that relies on the deprecated
bus_to_virt()function, which in turn only works on a few architectures, and is incompatible with both swiotlb and iommu support.Before commit
391e2f25601e("[SCSI] BusLogic: Port driver to 64-bit."), the driver had a dependency on x86-32, presumably because of this problem. However, the change introduced another bug that made it still impossible to use the driver on any 64-bit machine.This was in turn fixed in commit
56f396146af2("scsi: BusLogic: Fix 64-bit system enumeration error for Buslogic"), 8 years later, which shows that there are not a lot of users.Maciej is still using the driver on 32-bit hardware, and Khalid mentioned that the driver works with the device emulation used in VirtualBox and VMware. Both of those only emulate it for Windows 2000 and older operating systems that did not ship with the better LSI logic driver.
Quoted 6 lines
Do a minimum fix that searches through the list of descriptors to find one that matches the bus address. This is clearly as inefficient as was indicated in the code comment about the lack of a
bus_to_virt()replacement. A better fix would likely involve changing out the entire descriptor allocation for a simpler one, but that would be much more invasive.
FWIW, if efficiency *is* a practical concern, even under the current allocation scheme it looks like there are only 4 actual DMA allocations to search through. From a quick scan (since it's too hot here not to get distracted...), if I wanted to optimise this in future I'd probably remove the semi-redundant allocgrp_* fields from struct blogic_ccb and hang a dedicated list of the block allocations off the adapter - at that point the lookup could likely already be more efficient than a theoretical dma_to_virt() interface would be if it had to go off and walk an IOMMU pagetable. Then the next question would be whether it's viable to make a single 32KB allocation rather 4*8KB, so it's no longer even a list.
For now, though, I agree with the simple change that's clear and easy to reason about:
Thanks,
Robin.
Quoted 72 lines
Cc Maciej W. Rozycki <[email protected]>Cc Matt Wang <[email protected]>Cc Khalid Aziz <[email protected]>Signed-off-by Arnd Bergmann <[email protected]>--- drivers/scsi/BusLogic.c | 27 ++++++++++++++++----------- drivers/scsi/Kconfig | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-)drivers/scsi/BusLogic.c +16
-11@@ -2515,12 +2515,26 @@ static int blogic_resultcode(struct blogic_adapter *adapter,return (hoststatus <<16 ) | tgt_status; } +/* +* turn the dma address from an inbox into a ccb pointer +* This is rather inefficient. +*/ +static struct blogic_ccb * +blogic_inbox_to_ccb (struct blogic_adapter *adapter,struct blogic_inbox *inbox) +{ +struct blogic_ccb *ccb; + +for (ccb = adapter->all_ccbs; ccb; ccb = ccb->next_all) +if (inbox->ccb == ccb->dma_handle) +break ; + +return ccb; +}/* blogic_scan_inbox scans the Incoming Mailboxes saving any Incoming Mailbox entries for completion processing. */ -static void blogic_scan_inbox (struct blogic_adapter *adapter) {/* @@ -2540,16 +2554,7 @@ static void blogic_scan_inbox(struct blogic_adapter *adapter)enum blogic_cmplt_code comp_code;while ((comp_code = next_inbox->comp_code) !=BLOGIC_INBOX_FREE ) { -/* -We are only allowed to do this because we limit our -architectures we run on to machines where bus_to_virt( -actually works. There *needs* to be a dma_addr_to_virt() -in the new PCI DMA mapping interface to replace -bus_to_virt() or else this code is going to become very -innefficient. -*/ -struct blogic_ccb *ccb = - (struct blogic_ccb *)bus_to_virt (next_inbox->ccb); +struct blogic_ccb *ccb =blogic_inbox_to_ccb (adapter, adapter->next_inbox);if (comp_code !=BLOGIC_CMD_NOTFOUND ) {if (ccb->status ==BLOGIC_CCB_ACTIVE || ccb->status ==BLOGIC_CCB_RESET ) {drivers/scsi/Kconfig +1
-1@@ -513,7 +513,7 @@ config SCSI_HPTIOP config SCSI_BUSLOGIC tristate "BusLogic SCSI support" - depends on PCI && SCSI && VIRT_TO_BUS + depends on PCI && SCSI help This is support for BusLogic MultiMaster and FlashPoint SCSI Host Adapters. Consult the SCSI-HOWTO, available from
Re: [PATCH v2 2/3] scsi: BusLogic remove bus_to_virt
In reply to Arnd BergmannQuoted 91 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The BusLogic driver is the last remaining driver that relies on the deprecated
bus_to_virt()function, which in turn only works on a few architectures, and is incompatible with both swiotlb and iommu support.Before commit
391e2f25601e("[SCSI] BusLogic: Port driver to 64-bit."), the driver had a dependency on x86-32, presumably because of this problem. However, the change introduced another bug that made it still impossible to use the driver on any 64-bit machine.This was in turn fixed in commit
56f396146af2("scsi: BusLogic: Fix 64-bit system enumeration error for Buslogic"), 8 years later, which shows that there are not a lot of users.Maciej is still using the driver on 32-bit hardware, and Khalid mentioned that the driver works with the device emulation used in VirtualBox and VMware. Both of those only emulate it for Windows 2000 and older operating systems that did not ship with the better LSI logic driver.
Do a minimum fix that searches through the list of descriptors to find one that matches the bus address. This is clearly as inefficient as was indicated in the code comment about the lack of a
bus_to_virt()replacement. A better fix would likely involve changing out the entire descriptor allocation for a simpler one, but that would be much more invasive.Cc Maciej W. Rozycki <[email protected]>Cc Matt Wang <[email protected]>Cc Khalid Aziz <[email protected]>Signed-off-by Arnd Bergmann <[email protected]>--- drivers/scsi/BusLogic.c | 27 ++++++++++++++++----------- drivers/scsi/Kconfig | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-)drivers/scsi/BusLogic.c +16
-11@@ -2515,12 +2515,26 @@ static int blogic_resultcode(struct blogic_adapter *adapter,return (hoststatus <<16 ) | tgt_status; } +/* +* turn the dma address from an inbox into a ccb pointer +* This is rather inefficient. +*/ +static struct blogic_ccb * +blogic_inbox_to_ccb (struct blogic_adapter *adapter,struct blogic_inbox *inbox) +{ +struct blogic_ccb *ccb; + +for (ccb = adapter->all_ccbs; ccb; ccb = ccb->next_all) +if (inbox->ccb == ccb->dma_handle) +break ; + +return ccb; +}/* blogic_scan_inbox scans the Incoming Mailboxes saving any Incoming Mailbox entries for completion processing. */ -static void blogic_scan_inbox (struct blogic_adapter *adapter) {/* @@ -2540,16 +2554,7 @@ static void blogic_scan_inbox(struct blogic_adapter *adapter)enum blogic_cmplt_code comp_code;while ((comp_code = next_inbox->comp_code) !=BLOGIC_INBOX_FREE ) { -/* -We are only allowed to do this because we limit our -architectures we run on to machines where bus_to_virt( -actually works. There *needs* to be a dma_addr_to_virt() -in the new PCI DMA mapping interface to replace -bus_to_virt() or else this code is going to become very -innefficient. -*/ -struct blogic_ccb *ccb = - (struct blogic_ccb *)bus_to_virt (next_inbox->ccb); +struct blogic_ccb *ccb =blogic_inbox_to_ccb (adapter, adapter->next_inbox);if (comp_code !=BLOGIC_CMD_NOTFOUND ) {if (ccb->status ==BLOGIC_CCB_ACTIVE || ccb->status ==BLOGIC_CCB_RESET ) {drivers/scsi/Kconfig +0
-0
drivers/scsi/Kconfig config SCSI_HPTIOP · line 519
Quoted 8 lines
drivers/scsi/Kconfig +1
-1@@ -513,7 +513,7 @@ config SCSI_HPTIOP config SCSI_BUSLOGIC tristate "BusLogic SCSI support" - depends on PCI && SCSI && VIRT_TO_BUS + depends on PCI && SCSI help This is support for BusLogic MultiMaster and FlashPoint SCSI Host Adapters. Consult the SCSI-HOWTO, available from
CCB handling in the driver is ugly anyway, so that'll be good enough.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
Khalid Aziz
maintainerRe: [PATCH v2 2/3] scsi: BusLogic remove bus_to_virt
In reply to Arnd BergmannQuoted 73 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The BusLogic driver is the last remaining driver that relies on the deprecated
bus_to_virt()function, which in turn only works on a few architectures, and is incompatible with both swiotlb and iommu support.Before commit
391e2f25601e("[SCSI] BusLogic: Port driver to 64-bit."), the driver had a dependency on x86-32, presumably because of this problem. However, the change introduced another bug that made it still impossible to use the driver on any 64-bit machine.This was in turn fixed in commit
56f396146af2("scsi: BusLogic: Fix 64-bit system enumeration error for Buslogic"), 8 years later, which shows that there are not a lot of users.Maciej is still using the driver on 32-bit hardware, and Khalid mentioned that the driver works with the device emulation used in VirtualBox and VMware. Both of those only emulate it for Windows 2000 and older operating systems that did not ship with the better LSI logic driver.
Do a minimum fix that searches through the list of descriptors to find one that matches the bus address. This is clearly as inefficient as was indicated in the code comment about the lack of a
bus_to_virt()replacement. A better fix would likely involve changing out the entire descriptor allocation for a simpler one, but that would be much more invasive.Cc Maciej W. Rozycki <[email protected]>Cc Matt Wang <[email protected]>Cc Khalid Aziz <[email protected]>Signed-off-by Arnd Bergmann <[email protected]>--- drivers/scsi/BusLogic.c | 27 ++++++++++++++++----------- drivers/scsi/Kconfig | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-)drivers/scsi/BusLogic.c +15
-2@@ -2515,12 +2515,26 @@ static int blogic_resultcode(struct blogic_adapter *adapter,return (hoststatus <<16 ) | tgt_status; } +/* +* turn the dma address from an inbox into a ccb pointer +* This is rather inefficient. +*/ +static struct blogic_ccb * +blogic_inbox_to_ccb (struct blogic_adapter *adapter,struct blogic_inbox *inbox) +{ +struct blogic_ccb *ccb; + +for (ccb = adapter->all_ccbs; ccb; ccb = ccb->next_all) +if (inbox->ccb == ccb->dma_handle) +break ; + +return ccb; +}/* blogic_scan_inbox scans the Incoming Mailboxes saving any Incoming Mailbox entries for completion processing. */ -static void blogic_scan_inbox (struct blogic_adapter *adapter) {/* @@ -2540,16 +2554,7 @@ static void blogic_scan_inbox(struct blogic_adapter *adapter)enum blogic_cmplt_code comp_code;while ((comp_code = next_inbox->comp_code) !=BLOGIC_INBOX_FREE ) { -/*
drivers/scsi/BusLogic.c static void blogic_scan_inbox(struct blogic_adapter *adapter) · line 2557
Quoted 10 lines
drivers/scsi/BusLogic.c +1
-9-We are only allowed to do this because we limit our -architectures we run on to machines where bus_to_virt( -actually works. There *needs* to be a dma_addr_to_virt() -in the new PCI DMA mapping interface to replace -bus_to_virt() or else this code is going to become very -innefficient. -*/ -struct blogic_ccb *ccb = - (struct blogic_ccb *)bus_to_virt (next_inbox->ccb); +struct blogic_ccb *ccb =blogic_inbox_to_ccb (adapter, adapter->next_inbox);
This change looks good enough as workaround to not use bus_to_virt() for now. There are two problems I see though. One, I do worry about blogic_inbox_to_ccb() returning NULL for ccb which should not happen unless the mailbox pointer was corrupted which would indicate a bigger problem. Nevertheless a NULL pointer causing kernel panic concerns me. How about adding a check before we dereference ccb?
Second, with this patch applied, I am seeing errors from the driver:
=====================
[ 1623.902685] sdb: sdb1 sdb2 [ 1623.903245] sd 2:0:0:0: [sdb] Attached SCSI disk [ 1623.911000] scsi2: Illegal CCB #76 status 2 in Incoming Mailbox [ 1623.911005] scsi2: Illegal CCB #76 status 2 in Incoming Mailbox [ 1623.911070] scsi2: Illegal CCB #79 status 2 in Incoming Mailbox [ 1651.458008] scsi2: Warning: Partition Table appears to have Geometry 256/63 which is [ 1651.458013] scsi2: not compatible with current BusLogic Host Adapter Geometry 255/63 [ 1658.797609] scsi2: Resetting BusLogic BT-958D Failed [ 1659.533208] sd 2:0:0:0: Device offlined - not ready after error recovery [ 1659.533331] sd 2:0:0:0: Device offlined - not ready after error recovery [ 1659.533333] sd 2:0:0:0: Device offlined - not ready after error recovery [ 1659.533342] sd 2:0:0:0: [sdb] tag#101 FAILED Result: hostbyte=DID_TIME_OUT driverbyte=DRIVER_OK cmd_age=35s [ 1659.533345] sd 2:0:0:0: [sdb] tag#101 CDB: Read(10) 28 00 00 00 00 28 00 00 10 00 [ 1659.533346] I/O error, dev sdb, sector 40 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 0
=================
This is on VirtualBox using emulated BusLogic adapter.
This patch needs more refinement.
Thanks,
Khalid
Quoted 16 lines
drivers/scsi/BusLogic.c +0
-0if (comp_code != BLOGIC_Cn erroneousMD_NOTFOUND) {if (ccb->status ==BLOGIC_CCB_ACTIVE || ccb->status ==BLOGIC_CCB_RESET ) {drivers/scsi/Kconfig +1
-1@@ -513,7 +513,7 @@ config SCSI_HPTIOP config SCSI_BUSLOGIC tristate "BusLogic SCSI support" - depends on PCI && SCSI && VIRT_TO_BUS + depends on PCI && SCSI help This is support for BusLogic MultiMaster and FlashPoint SCSI Host Adapters. Consult the SCSI-HOWTO, available from
Re: [PATCH v2 2/3] scsi: BusLogic remove bus_to_virt
Quoted 13 lines · Khalid Aziz
Review
Quoted 12 lines
while ((comp_code = next_inbox->comp_code) != BLOGIC_INBOX_FREE) {(quoted diff) +1
-10- /* - We are only allowed to do this because we limit our - architectures we run on to machines where bus_to_virt( - actually works. There *needs* to be a dma_addr_to_virt() - in the new PCI DMA mapping interface to replace - bus_to_virt() or else this code is going to become very - innefficient. - */ - struct blogic_ccb *ccb = - (struct blogic_ccb *) bus_to_virt(next_inbox->ccb); + struct blogic_ccb *ccb = blogic_inbox_to_ccb(adapter, adapter->next_inbox);
Quoted 6 lines
This change looks good enough as workaround to not use
bus_to_virt()for now. There are two problems I see though. One, I do worry aboutblogic_inbox_to_ccb()returning NULL for ccb which should not happen unless the mailbox pointer was corrupted which would indicate a bigger problem. Nevertheless a NULL pointer causing kernel panic concerns me. How about adding a check before we dereference ccb?
Right, makes sense
Quoted 21 lines
Second, with this patch applied, I am seeing errors from the driver:
=====================
[ 1623.902685] sdb: sdb1 sdb2 [ 1623.903245] sd 2:0:0:0: [sdb] Attached SCSI disk [ 1623.911000] scsi2: Illegal CCB #76 status 2 in Incoming Mailbox [ 1623.911005] scsi2: Illegal CCB #76 status 2 in Incoming Mailbox [ 1623.911070] scsi2: Illegal CCB #79 status 2 in Incoming Mailbox [ 1651.458008] scsi2: Warning: Partition Table appears to have Geometry 256/63 which is [ 1651.458013] scsi2: not compatible with current BusLogic Host Adapter Geometry 255/63 [ 1658.797609] scsi2: Resetting BusLogic BT-958D Failed [ 1659.533208] sd 2:0:0:0: Device offlined - not ready after error recovery [ 1659.533331] sd 2:0:0:0: Device offlined - not ready after error recovery [ 1659.533333] sd 2:0:0:0: Device offlined - not ready after error recovery [ 1659.533342] sd 2:0:0:0: [sdb] tag#101 FAILED Result: hostbyte=DID_TIME_OUT driverbyte=DRIVER_OK cmd_age=35s [ 1659.533345] sd 2:0:0:0: [sdb] tag#101 CDB: Read(10) 28 00 00 00 00 28 00 00 10 00 [ 1659.533346] I/O error, dev sdb, sector 40 op 0x0:(READ) flags 0x80700
Quoted 7 lines
phys_seg1 prio class 0=================
This is on VirtualBox using emulated BusLogic adapter.
This patch needs more refinement.
Thanks for testing the patch, too bad it didn't work. At least I quickly found one stupid mistake on my end, hope it's the only one.
Can you test it again with this patch on top?
drivers/scsi/BusLogic.c +0 -0
@@ -2554,8 +2554,14 @@ static void blogic_scan_inbox(struct
blogic_adapter *adapter)
enum blogic_cmplt_code comp_code;
while ((comp_code = next_inbox->comp_code) != BLOGIC_INBOX_FREE) {- struct blogic_ccb *ccb = blogic_inbox_to_ccb(adapter,adapter->next_inbox);
- if (comp_code != BLOGIC_CMD_NOTFOUND) {
+ struct blogic_ccb *ccb = blogic_inbox_to_ccb(adapter,next_inbox);
+ if (!ccb) {
+ /*
+ * This should never happen, unless the CCB list is
+ * corrupted in memory.
+ */
+ blogic_warn("Could not find CCB for dma
address 0x%x\n", adapter, next_inbox->ccb);
+ } else if (comp_code != BLOGIC_CMD_NOTFOUND) {
if (ccb->status == BLOGIC_CCB_ACTIVE ||
ccb->status == BLOGIC_CCB_RESET) {Khalid Aziz
maintainerRe: [PATCH v2 2/3] scsi: BusLogic remove bus_to_virt
Quoted 25 lines · Arnd Bergmann
Can you test it again with this patch on top?
drivers/scsi/BusLogic.c +7
-2@@ -2554,8 +2554,14 @@ static void blogic_scan_inbox(struct blogic_adapter *adapter)enum blogic_cmplt_code comp_code;while ((comp_code = next_inbox->comp_code) !=BLOGIC_INBOX_FREE ) { -struct blogic_ccb *ccb =blogic_inbox_to_ccb (adapter, adapter->next_inbox); -if (comp_code !=BLOGIC_CMD_NOTFOUND ) { +struct blogic_ccb *ccb =blogic_inbox_to_ccb (adapter, next_inbox); +if (!ccb) { +/* +* This should never happen, unless the CCB list is +* corrupted in memory. +*/ + blogic_warn("Could not find CCB for dmaaddress 0x%x\n", adapter,
next_inbox->ccb);
Quoted 3 lines
+ } else if (comp_code != BLOGIC_CMD_NOTFOUND) {
if (ccb->status == BLOGIC_CCB_ACTIVE ||
ccb->status == BLOGIC_CCB_RESET) {Hi Arnd,
Driver works with this change. next_inbox is the correct pointer to pass.
Thanks,
Khalid
Re: [PATCH v2 2/3] scsi: BusLogic remove bus_to_virt
Quoted 3 lines · Khalid Aziz
On 6/23/22 08:47, Arnd Bergmann wrote:
Driver works with this change.
next_inboxis the correct pointer to pass.
Ok, great! I'll add a 'Tested-by' line then. I was already in the process of preparing a v3 patch set, will send out the fixed patch in a bit.
Arnd
PATCH v2 3/3 arch/*/: remove CONFIG_VIRT_TO_BUS
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
All architecture-independent users of virt_to_bus() and bus_to_virt() have been fixed to use the dma mapping interfaces or have been removed now. This means the definitions on most architectures, and the CONFIG_VIRT_TO_BUS symbol are now obsolete and can be removed.
The only exceptions to this are a few network and scsi drivers for m68k Amiga and VME machines and ppc32 Macintosh. These drivers work correctly with the old interfaces and are probably not worth changing.
On alpha and parisc, virt_to_bus() were still used in asm/floppy.h. alpha can use isa_virt_to_bus() like x86 does, and parisc can just open-code the virt_to_phys() here, as this is architecture specific code.
I tried updating the bus-virt-phys-mapping.rst documentation, which started as an email from Linus to explain some details of the Linux-2.0 driver interfaces. The bits about virt_to_bus() were declared obsolete backin 2000, and the rest is not all that relevant any more, so in the end I just decided to remove the file completely.
--- .../core-api/bus-virt-phys-mapping.rst | 220 ------------------ Documentation/core-api/dma-api-howto.rst | 14 -- Documentation/core-api/index.rst | 1 - .../translations/zh_CN/core-api/index.rst | 1 - arch/alpha/Kconfig | 1 - arch/alpha/include/asm/floppy.h | 2 +- arch/alpha/include/asm/io.h | 8 +- arch/ia64/Kconfig | 1 - arch/ia64/include/asm/io.h | 8 - arch/m68k/Kconfig | 1 - arch/m68k/include/asm/virtconvert.h | 4 +- arch/microblaze/Kconfig | 1 - arch/microblaze/include/asm/io.h | 2 - arch/mips/Kconfig | 1 - arch/mips/include/asm/io.h | 9 - arch/parisc/Kconfig | 1 - arch/parisc/include/asm/floppy.h | 4 +- arch/parisc/include/asm/io.h | 2 - arch/powerpc/Kconfig | 1 - arch/powerpc/include/asm/io.h | 2 - arch/riscv/include/asm/page.h | 1 - arch/x86/Kconfig | 1 - arch/x86/include/asm/io.h | 9 - arch/xtensa/Kconfig | 1 - arch/xtensa/include/asm/io.h | 3 - include/asm-generic/io.h | 14 -- mm/Kconfig | 8 - 27 files changed, 10 insertions(+), 311 deletions(-) delete mode 100644 Documentation/core-api/bus-virt-phys-mapping.rst
Documentation/core-api/bus-virt-phys-mapping.rst deleted +0 -220
@@ -1,220 +0,0 @@ -========================================================== -How to access I/O mapped memory from within device drivers -========================================================== - -:Author: Linus - -.. warning:: - - The virt_to_bus() and bus_to_virt() functions have been - superseded by the functionality provided by the PCI DMA interface - (see Documentation/core-api/dma-api-howto.rst). They continue - to be documented below for historical purposes, but new code - must not use them. --davidm 00/12/12 - -:: - - [ This is a mail message in response to a query on IO mapping, thus the - strange format for a "document" ] - -The AHA-1542 is a bus-master device, and your patch makes the driver give the -controller the physical address of the buffers, which is correct on x86 -(because all bus master devices see the physical memory mappings directly). - -However, on many setups, there are actually **three** different ways of looking -at memory addresses, and in this case we actually want the third, the -so-called "bus address". - -Essentially, the three ways of addressing memory are (this is "real memory", -that is, normal RAM--see later about other details): - - - CPU untranslated. This is the "physical" address. Physical address - 0 is what the CPU sees when it drives zeroes on the memory bus. - - - CPU translated address. This is the "virtual" address, and is - completely internal to the CPU itself with the CPU doing the appropriate - translations into "CPU untranslated". - - - bus address. This is the address of memory as seen by OTHER devices, - not the CPU. Now, in theory there could be many different bus - addresses, with each device seeing memory in some device-specific way, but - happily most hardware designers aren't actually actively trying to make - things any more complex than necessary, so you can assume that all - external hardware sees the memory the same way. - -Now, on normal PCs the bus address is exactly the same as the physical -address, and things are very simple indeed. However, they are that simple -because the memory and the devices share the same address space, and that is -not generally necessarily true on other PCI/ISA setups. - -Now, just as an example, on the PReP (PowerPC Reference Platform), the -CPU sees a memory map something like this (this is from memory):: - - 0-2 GB "real memory" - 2 GB-3 GB "system IO" (inb/out and similar accesses on x86) - 3 GB-4 GB "IO memory" (shared memory over the IO bus) - -Now, that looks simple enough. However, when you look at the same thing from -the viewpoint of the devices, you have the reverse, and the physical memory -address 0 actually shows up as address 2 GB for any IO master. - -So when the CPU wants any bus master to write to physical memory 0, it -has to give the master address 0x80000000 as the memory address. - -So, for example, depending on how the kernel is actually mapped on the -PPC, you can end up with a setup like this:: - - physical address: 0 - virtual address: 0xC0000000 - bus address: 0x80000000 - -where all the addresses actually point to the same thing. It's just seen -through different translations.. - -Similarly, on the Alpha, the normal translation is:: - - physical address: 0 - virtual address: 0xfffffc0000000000 - bus address: 0x40000000 - -(but there are also Alphas where the physical address and the bus address -are the same). - -Anyway, the way to look up all these translations, you do:: - - #include <asm/io.h> - - phys_addr = virt_to_phys(virt_addr); - virt_addr = phys_to_virt(phys_addr); - bus_addr = virt_to_bus(virt_addr); - virt_addr = bus_to_virt(bus_addr); - -Now, when do you need these? - -You want the **virtual** address when you are actually going to access that -pointer from the kernel. So you can have something like this:: - - /* - * this is the hardware "mailbox" we use to communicate with - * the controller. The controller sees this directly. - */ - struct mailbox { - __u32 status; - __u32 bufstart; - __u32 buflen; - .. - } mbox; - - unsigned char * retbuffer; - - /* get the address from the controller */ - retbuffer = bus_to_virt(mbox.bufstart); - switch (retbuffer[0]) { - case STATUS_OK: - ... - -on the other hand, you want the bus address when you have a buffer that -you want to give to the controller:: - - /* ask the controller to read the sense status into "sense_buffer" */ - mbox.bufstart = virt_to_bus(&sense_buffer); - mbox.buflen = sizeof(sense_buffer); - mbox.status = 0; - notify_controller(&mbox); - -And you generally **never** want to use the physical address, because you can't -use that from the CPU (the CPU only uses translated virtual addresses), and -you can't use it from the bus master. - -So why do we care about the physical address at all? We do need the physical -address in some cases, it's just not very often in normal code. The physical -address is needed if you use memory mappings, for example, because the -"remap_pfn_range()" mm function wants the physical address of the memory to -be remapped as measured in units of pages, a.k.a. the pfn (the memory -management layer doesn't know about devices outside the CPU, so it -shouldn't need to know about "bus addresses" etc). - -.. note:: - - The above is only one part of the whole equation. The above - only talks about "real memory", that is, CPU memory (RAM). - -There is a completely different type of memory too, and that's the "shared -memory" on the PCI or ISA bus. That's generally not RAM (although in the case -of a video graphics card it can be normal DRAM that is just used for a frame -buffer), but can be things like a packet buffer in a network card etc. - -This memory is called "PCI memory" or "shared memory" or "IO memory" or -whatever, and there is only one way to access it: the readb/writeb and -related functions. You should never take the address of such memory, because -there is really nothing you can do with such an address: it's not -conceptually in the same memory space as "real memory" at all, so you cannot -just dereference a pointer. (Sadly, on x86 it **is** in the same memory space, -so on x86 it actually works to just deference a pointer, but it's not -portable). - -For such memory, you can do things like: - - - reading:: - - /* - * read first 32 bits from ISA memory at 0xC0000, aka - * C000:0000 in DOS terms - */ - unsigned int signature = isa_readl(0xC0000); - - - remapping and writing:: - - /* - * remap framebuffer PCI memory area at 0xFC000000, - * size 1MB, so that we can access it: We can directly - * access only the 640k-1MB area, so anything else - * has to be remapped. - */ - void __iomem *baseptr = ioremap(0xFC000000, 1024*1024); - - /* write a 'A' to the offset 10 of the area */ - writeb('A',baseptr+10); - - /* unmap when we unload the driver */ - iounmap(baseptr); - - - copying and clearing:: - - /* get the 6-byte Ethernet address at ISA address E000:0040 */ - memcpy_fromio(kernel_buffer, 0xE0040, 6); - /* write a packet to the driver */ - memcpy_toio(0xE1000, skb->data, skb->len); - /* clear the frame buffer */ - memset_io(0xA0000, 0, 0x10000); - -OK, that just about covers the basics of accessing IO portably. Questions? -Comments? You may think that all the above is overly complex, but one day you -might find yourself with a 500 MHz Alpha in front of you, and then you'll be -happy that your driver works ;) - -Note that kernel versions 2.0.x (and earlier) mistakenly called the -ioremap() function "vremap()". ioremap() is the proper name, but I -didn't think straight when I wrote it originally. People who have to -support both can do something like:: - - /* support old naming silliness */ - #if LINUX_VERSION_CODE < 0x020100 - #define ioremap vremap - #define iounmap vfree - #endif - -at the top of their source files, and then they can use the right names -even on 2.0.x systems. - -And the above sounds worse than it really is. Most real drivers really -don't do all that complex things (or rather: the complexity is not so -much in the actual IO accesses as in error handling and timeouts etc). -It's generally not hard to fix drivers, and in many cases the code -actually looks better afterwards:: - - unsigned long signature = *(unsigned int *) 0xC0000; - vs - unsigned long signature = readl(0xC0000); - -I think the second version actually is more readable, no?
Documentation/core-api/dma-api-howto.rst +0 -14
@@ -707,20 +707,6 @@ to use the dma_sync_*() interfaces:: } } -Drivers converted fully to this interface should not use virt_to_bus() any -longer, nor should they use bus_to_virt(). Some drivers have to be changed a -little bit, because there is no longer an equivalent to bus_to_virt() in the -dynamic DMA mapping scheme - you have to always store the DMA addresses -returned by the dma_alloc_coherent(), dma_pool_alloc(), and dma_map_single() -calls (dma_map_sg() stores them in the scatterlist itself if the platform -supports dynamic DMA mapping in hardware) in your driver structures and/or -in the card registers. - -All drivers should be using these interfaces with no exceptions. It -is planned to completely remove virt_to_bus() and bus_to_virt() as -they are entirely deprecated. Some ports already do not provide these -as it is impossible to correctly support them. - Handling Errors ===============
Documentation/core-api/index.rst +0 -1
@@ -42,7 +42,6 @@ Library functionality that is used throughout the kernel. rbtree generic-radix-tree packing - bus-virt-phys-mapping this_cpu_ops timekeeping errseq
Documentation/translations/zh_CN/core-api/index.rst +0 -1
@@ -52,7 +52,6 @@ Todolist: circular-buffers generic-radix-tree packing - bus-virt-phys-mapping this_cpu_ops timekeeping errseq
arch/alpha/Kconfig +0 -1
@@ -17,7 +17,6 @@ config ALPHA select HAVE_PERF_EVENTS select NEED_DMA_MAP_STATE select NEED_SG_DMA_LENGTH - select VIRT_TO_BUS select GENERIC_IRQ_PROBE select GENERIC_PCI_IOMAP select AUTO_IRQ_AFFINITY if SMP
arch/alpha/include/asm/floppy.h +1 -1
@@ -20,7 +20,7 @@#define fd_free_dma () free_dma(FLOPPY_DMA)#define fd_clear_dma_ff () clear_dma_ff(FLOPPY_DMA)#define fd_set_dma_mode (mode) set_dma_mode(FLOPPY_DMA,mode) -#define fd_set_dma_addr (addr) set_dma_addr(FLOPPY_DMA,virt_to_bus(addr)) +#define fd_set_dma_addr (addr) set_dma_addr(FLOPPY_DMA,isa_virt_to_bus(addr))#define fd_set_dma_count (count) set_dma_count(FLOPPY_DMA,count)#define fd_enable_irq () enable_irq(FLOPPY_IRQ)#define fd_disable_irq () disable_irq(FLOPPY_IRQ)
arch/alpha/include/asm/io.h +4 -4
@@ -106,15 +106,15 @@ static inline void * phys_to_virt(unsigned long address)extern unsigned long __direct_map_base;extern unsigned long __direct_map_size; -static inline unsigned long __deprecated virt_to_bus (volatile void *address) +static inline unsigned long __deprecated isa_virt_to_bus (volatile void *address) {unsigned long phys =virt_to_phys (address);unsigned long bus = phys + __direct_map_base;return phys <= __direct_map_size ? bus :0 ; } -#define isa_virt_to_bus virt_to_bus +#define isa_virt_to_bus isa_virt_to_bus -static inline void *__deprecated bus_to_virt (unsigned long address) +static inline void *__deprecated isa_bus_to_virt (unsigned long address) {void *virt;
@@ -125,7 +125,7 @@ static inline void * __deprecated bus_to_virt(unsigned long address) virt =phys_to_virt (address);return (long )address <=0 ?NULL : virt; } -#define isa_bus_to_virt bus_to_virt +#define isa_bus_to_virt isa_bus_to_virt/* * There are different chipsets to interface the Alpha CPUs to the world.
arch/ia64/Kconfig +0 -1
@@ -39,7 +39,6 @@ config IA64 select HAVE_FUNCTION_DESCRIPTORS select HAVE_VIRT_CPU_ACCOUNTING select HUGETLB_PAGE_SIZE_VARIABLE if HUGETLB_PAGE - select VIRT_TO_BUS select GENERIC_IRQ_PROBE select GENERIC_PENDING_IRQ if SMP select GENERIC_IRQ_SHOW
arch/ia64/include/asm/io.h +0 -8
@@ -96,14 +96,6 @@ extern u64 kern_mem_attribute (unsigned long phys_addr, unsigned long size);extern int valid_phys_addr_range (phys_addr_t addr,size_t count);/* efi.c */ extern int valid_mmap_phys_addr_range (unsigned long pfn,size_t count); -/* -* The following two macros are deprecated and scheduled for removal. -* Please use the PCI-DMA interface defined in <asm/pci.h> instead. -*/ -#define bus_to_virt phys_to_virt -#define virt_to_bus virt_to_phys -#define page_to_bus page_to_phys -# endif /* KERNEL */ /*
arch/m68k/Kconfig +0 -1
@@ -30,7 +30,6 @@ config M68K select OLD_SIGACTION select OLD_SIGSUSPEND3 select UACCESS_MEMCPY if !MMU - select VIRT_TO_BUS select ZONE_DMA config CPU_BIG_ENDIAN
arch/m68k/include/asm/virtconvert.h +3 -1
@@ -33,9 +33,11 @@ static inline void *phys_to_virt(unsigned long address)/* * IO bus memory addresses are 1:1 with the physical address, +* deprecated globally but still used on two machines. */ +#if defined(CONFIG_AMIGA ) || defined(CONFIG_VME )#define virt_to_bus virt_to_phys -#define bus_to_virt phys_to_virt +#endif #endif #endif
arch/microblaze/Kconfig +0 -1
@@ -38,7 +38,6 @@ config MICROBLAZE select OF_EARLY_FLATTREE select PCI_DOMAINS_GENERIC if PCI select PCI_SYSCALL if PCI - select VIRT_TO_BUS select CPU_NO_EFFICIENT_FFS select MMU_GATHER_NO_RANGE select SPARSE_IRQ
arch/microblaze/include/asm/io.h +0 -2
@@ -30,8 +30,6 @@ extern resource_size_t isa_mem_base;#define PCI_IOBASE ((void __iomem *)_IO_BASE)#define IO_SPACE_LIMIT (0xFFFFFFFF) -#define page_to_bus (page) (page_to_phys(page)) -extern void iounmap (volatile void __iomem *addr);extern void __iomem *ioremap (phys_addr_t address,unsigned long size);
arch/mips/Kconfig +0 -1
@@ -100,7 +100,6 @@ config MIPS select RTC_LIB select SYSCTL_EXCEPTION_TRACE select TRACE_IRQFLAGS_SUPPORT - select VIRT_TO_BUS select ARCH_HAS_ELFCORE_COMPAT select HAVE_ARCH_KCSAN if 64BIT
arch/mips/include/asm/io.h +0 -9
@@ -147,15 +147,6 @@ static inline void *isa_bus_to_virt(unsigned long address)return phys_to_virt (address); } -/* -* However PCI ones are not necessarily 1:1 and therefore these interfaces -* are forbidden in portable PCI drivers. -* -* Allow them for x86 for legacy drivers, though. -*/ -#define virt_to_bus virt_to_phys -#define bus_to_virt phys_to_virt -/* * Change "struct page" to physical address. */
arch/parisc/Kconfig +0 -1
@@ -43,7 +43,6 @@ config PARISC select SYSCTL_ARCH_UNALIGN_ALLOW select SYSCTL_EXCEPTION_TRACE select HAVE_MOD_ARCH_SPECIFIC - select VIRT_TO_BUS select MODULES_USE_ELF_RELA select CLONE_BACKWARDS select TTY # Needed for pdc_cons.c
arch/parisc/include/asm/floppy.h +2 -2
@@ -179,7 +179,7 @@ static void _fd_chose_dma_mode(char *addr, unsigned long size) {if (can_use_virtual_dma ==2 ) {if ((unsigned int ) addr >= (unsigned int ) high_memory || -virt_to_bus (addr) >=0x1000000 || +virt_to_phys (addr) >=0x1000000 ||_CROSS_64KB (addr, size,0 )) use_virtual_dma =1 ;else
@@ -215,7 +215,7 @@ static int hard_dma_setup(char *addr, unsigned long size, int mode, int io) doing_pdma =0 ;clear_dma_ff (FLOPPY_DMA );set_dma_mode (FLOPPY_DMA ,mode); -set_dma_addr (FLOPPY_DMA ,virt_to_bus (addr)); +set_dma_addr (FLOPPY_DMA ,virt_to_phys (addr));set_dma_count (FLOPPY_DMA ,size);enable_dma (FLOPPY_DMA );return 0 ;
arch/parisc/include/asm/io.h +0 -2
@@ -7,8 +7,6 @@#define virt_to_phys (a) ((unsigned long)__pa(a))#define phys_to_virt (a) __va(a) -#define virt_to_bus virt_to_phys -#define bus_to_virt phys_to_virtstatic inline unsigned long isa_bus_to_virt (unsigned long addr) {BUG ();
arch/powerpc/Kconfig +0 -1
@@ -277,7 +277,6 @@ config PPC select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK select TRACE_IRQFLAGS_SUPPORT - select VIRT_TO_BUS if !PPC64 # # Please keep this list sorted alphabetically. #
arch/powerpc/include/asm/io.h +0 -2
@@ -985,8 +985,6 @@ static inline void * bus_to_virt(unsigned long address) }#define bus_to_virt bus_to_virt -#define page_to_bus (page) (page_to_phys(page) + PCI_DRAM_OFFSET) -#endif /* CONFIG_PPC32 */ /* access ports */
arch/riscv/include/asm/page.h +0 -1
@@ -167,7 +167,6 @@ extern phys_addr_t __phys_addr_symbol(unsigned long x);#define page_to_virt (page) (pfn_to_virt(page_to_pfn(page)))#define page_to_phys (page) (pfn_to_phys(page_to_pfn(page))) -#define page_to_bus (page) (page_to_phys(page))#define phys_to_page (paddr) (pfn_to_page(phys_to_pfn(paddr)))#define sym_to_pfn (x) __phys_to_pfn(__pa_symbol(x))
arch/x86/Kconfig +0 -1
@@ -279,7 +279,6 @@ config X86 select THREAD_INFO_IN_TASK select TRACE_IRQFLAGS_SUPPORT select USER_STACKTRACE_SUPPORT - select VIRT_TO_BUS select HAVE_ARCH_KCSAN if X86_64 select X86_FEATURE_NAMES if PROC_FS select PROC_PID_ARCH_STATUS if PROC_FS
arch/x86/include/asm/io.h +0 -9
@@ -169,15 +169,6 @@ static inline unsigned int isa_virt_to_bus(volatile void *address) }#define isa_bus_to_virt phys_to_virt -/* -* However PCI ones are not necessarily 1:1 and therefore these interfaces -* are forbidden in portable PCI drivers. -* -* Allow them on x86 for legacy drivers, though. -*/ -#define virt_to_bus virt_to_phys -#define bus_to_virt phys_to_virt -/* * The default ioremap() behavior is non-cached; if you need something * else, you probably want one of the following.
arch/xtensa/Kconfig +0 -1
@@ -50,7 +50,6 @@ config XTENSA select MODULES_USE_ELF_RELA select PERF_USE_VMALLOC select TRACE_IRQFLAGS_SUPPORT - select VIRT_TO_BUS help Xtensa processors are 32-bit RISC machines designed by Tensilica primarily for embedded systems. These processors are both
arch/xtensa/include/asm/io.h +0 -3
@@ -63,9 +63,6 @@ static inline void iounmap(volatile void __iomem *addr) xtensa_iounmap(addr); } -#define virt_to_bus virt_to_phys -#define bus_to_virt phys_to_virt -#endif /* CONFIG_MMU */ #include <asm-generic/io.h>
include/asm-generic/io.h +0 -14
@@ -1059,20 +1059,6 @@ static inline void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr) }#endif -#ifdef CONFIG_VIRT_TO_BUS -#ifndef virt_to_bus -static inline unsigned long virt_to_bus (void *address) -{ -return (unsigned long )address; -} - -static inline void *bus_to_virt (unsigned long address) -{ -return (void *)address; -} -#endif -#endif -#ifndef memset_io#define memset_io memset_io/**
mm/Kconfig +0 -8
@@ -639,14 +639,6 @@ config BOUNCE memory available to the CPU. Enabled by default when HIGHMEM is selected, but you may say n to override this. -config VIRT_TO_BUS - bool - help - An architecture should select this if it implements the - deprecated interface virt_to_bus(). All new architectures - should probably not select this. - - config MMU_NOTIFIER bool select SRCU
Signature · 1 line
2.29.2
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Arnd,
Am 18.06.2022 um 00:57 schrieb Arnd Bergmann:
Quoted 10 lines
From: Arnd Bergmann <[email protected]>
All architecture-independent users of
virt_to_bus()andbus_to_virt()have been fixed to use the dma mapping interfaces or have been removed now. This means the definitions on most architectures, and theCONFIG_VIRT_TO_BUSsymbol are now obsolete and can be removed.The only exceptions to this are a few network and scsi drivers for m68k Amiga and VME machines and ppc32 Macintosh. These drivers work correctly with the old interfaces and are probably not worth changing.
The Amiga SCSI drivers are all old WD33C93 ones, and replacing virt_to_bus by virt_to_phys in the dma_setup() function there would cause no functional change at all.
drivers/vme/bridges/vme_ca91cx42.c hasn't been used at all on m68k (it is a PCI-to-VME bridge chipset driver that would be needed on architectures that natively use a PCI bus). I haven't found anything that selects that driver, so not sure it is even still in use??
That would allow you to drop the remaining virt_to_bus define from arch/m68k/include/asm/virtconvert.h.
I could submit a patch to convert the Amiga SCSI drivers to use virt_to_phys if Geert and the SCSI maintainers think it's worth the churn.
32bit powerpc is a different matter though.
Cheers,
Michael
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Quoted 7 lines · Michael Schmitz
Am 18.06.2022 um 00:57 schrieb Arnd Bergmann:
Quoted 6 lines
All architecture-independent users of
virt_to_bus()andbus_to_virt()have been fixed to use the dma mapping interfaces or have been removed now. This means the definitions on most architectures, and theCONFIG_VIRT_TO_BUSsymbol are now obsolete and can be removed.
Quoted 7 lines
Quoted 3 lines
The only exceptions to this are a few network and scsi drivers for m68k Amiga and VME machines and ppc32 Macintosh. These drivers work correctly with the old interfaces and are probably not worth changing.
The Amiga SCSI drivers are all old WD33C93 ones, and replacing
virt_to_busbyvirt_to_physin thedma_setup()function there would cause no functional change at all.
Ok, thanks for taking a look here.
Quoted 4 lines
drivers/vme/bridges/vme_ca91cx42.chasn't been used at all on m68k (it is a PCI-to-VME bridge chipset driver that would be needed on architectures that natively use a PCI bus). I haven't found anything that selects that driver, so not sure it is even still in use??
It's gone now, Greg has already taken my patches for this through the staging tree.
Quoted 5 lines
That would allow you to drop the remaining
virt_to_busdefine fromarch/m68k/include/asm/virtconvert.h.I could submit a patch to convert the Amiga SCSI drivers to use
virt_to_physif Geert and the SCSI maintainers think it's worth the churn.
I don't think using virt_to_phys() is an improvement here, as virt_to_bus() was originally meant as a better abstraction to replace the use of virt_to_phys() to make drivers portable, before it got replaced by the dma-mapping interface in turn.
It looks like the Amiga SCSI drivers have an open-coded version of what dma_map_single() does, to do bounce buffering and cache management. The ideal solution would be to convert the drivers actually use the appropriate dma-mapping interfaces and remove this custom code.
The same could be done for the two vme drivers (scsi/mvme147.c and ethernet/82596.c), which do the cache management but apparently don't need swiotlb bounce buffering.
Rewriting the drivers to modern APIs is of course non-trivial, and if you want a shortcut here, I would suggest introducing platform specific helpers similar to isa_virt_to_bus() and call them amiga_virt_to_bus() and vme_virt_to_bus, respectively.
Putting these into a platform specific header file at least helps clarify that both the helper functions and the drivers using them are non-portable.
Quoted 1 line
32bit powerpc is a different matter though.
It's similar, but unrelated. The two apple ethernet drivers (bmac and mace) can again either get changed to use the dma-mapping interfaces, or get a custom pmac_virt_to_bus()/ pmac_bus_to_virt() helper.
There is also drivers/tty/serial/cpm_uart/cpm_uart_cpm2.c, which I think just needs a trivial change, but I'm not sure how to do it correctly.
Arnd
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Arnd,
Am 24.06.2022 um 21:10 schrieb Arnd Bergmann:
Quoted 18 lines · Michael Schmitz
Quoted 7 lines
Am 18.06.2022 um 00:57 schrieb Arnd Bergmann:
Quoted 6 lines
All architecture-independent users of
virt_to_bus()andbus_to_virt()have been fixed to use the dma mapping interfaces or have been removed now. This means the definitions on most architectures, and theCONFIG_VIRT_TO_BUSsymbol are now obsolete and can be removed.Quoted 7 lines
Quoted 3 lines
The only exceptions to this are a few network and scsi drivers for m68k Amiga and VME machines and ppc32 Macintosh. These drivers work correctly with the old interfaces and are probably not worth changing.
The Amiga SCSI drivers are all old WD33C93 ones, and replacing
virt_to_busbyvirt_to_physin thedma_setup()function there would cause no functional change at all.Ok, thanks for taking a look here.
Quoted 7 lines
Quoted 4 lines
drivers/vme/bridges/vme_ca91cx42.chasn't been used at all on m68k (it is a PCI-to-VME bridge chipset driver that would be needed on architectures that natively use a PCI bus). I haven't found anything that selects that driver, so not sure it is even still in use??It's gone now, Greg has already taken my patches for this through the staging tree.
One less to worry about, thanks.
Quoted 11 lines
Quoted 5 lines
That would allow you to drop the remaining
virt_to_busdefine fromarch/m68k/include/asm/virtconvert.h.I could submit a patch to convert the Amiga SCSI drivers to use
virt_to_physif Geert and the SCSI maintainers think it's worth the churn.I don't think using
virt_to_phys()is an improvement here, asvirt_to_bus()was originally meant as a better abstraction to replace the use ofvirt_to_phys()to make drivers portable, before it got replaced by the dma-mapping interface in turn.
Quoted 5 lines
It looks like the Amiga SCSI drivers have an open-coded version of what
dma_map_single()does, to do bounce buffering and cache management. The ideal solution would be to convert the drivers actually use the appropriate dma-mapping interfaces and remove this custom code.
I've taken another look at these drivers' dma_setup() functions and they all look much more complex than the Amiga ESP drivers (which do use the dma-mapping interface for parts of the DMA setup). From my limited understanding, the difference between the ESP and WD33C93 drivers is that the former are used on 040/060 accelerator boards only (where the processor does do bus snooping and DMA can access all of RAM). The latter ones would need cache management, could only use non-coherent mappings and would require special case handling for DMA-inaccessible RAM inside a device-specific dma ops' map_page() function.
That's several bridges too far for me ... I have no Amiga hardware whatsoever, and know no one who could test changes to WD33C93 drivers for me.
What I have is a NCR5380 with the proverbial 'pathological DMA' integration example (and its driver was never changed to even use virt_to_bus()!). I might learn enough about using the dma-mapping API on that one eventually (though the requirement for at least 1 MB swiotlb bounce buffers looks hard to meet), and use that to convert the WD33C93 drivers, but it would still remain untested.
Quoted 8 lines
The same could be done for the two vme drivers (
scsi/mvme147.cand ethernet/82596.c), which do the cache management but apparently don't need swiotlb bounce buffering.Rewriting the drivers to modern APIs is of course non-trivial, and if you want a shortcut here, I would suggest introducing platform specific helpers similar to
isa_virt_to_bus()and call themamiga_virt_to_bus()andvme_virt_to_bus, respectively.
I don't think Amiga and m68k VME differ at all in that respect, so might just call it m68k_virt_to_bus() for now.
Quoted 3 lines
Putting these into a platform specific header file at least helps clarify that both the helper functions and the drivers using them are non-portable.
There are no platform specific header files other than asm/amigahw.h and asm/mvme147hw.h, currently only holding register address definitions. Would it be OK to add m68k_virt_to_bus() in there if it can't remain in asm/virtconvert.h, Geert?
Quoted 7 lines
Quoted 2 lines
32bit powerpc is a different matter though.
It's similar, but unrelated. The two apple ethernet drivers (bmac and mace) can again either get changed to use the dma-mapping interfaces, or get a custom pmac_virt_to_bus()/
pmac_bus_to_virt()helper.
Hmmm - I see Finn had done the DMA API conversion on macmace.c which might give some hints on what to do about mace.c ... no idea about bmac.c though. And again, haven't got hardware to test, so custom helpers is it, then.
Cheers,
Michael
Quoted 6 lines
There is also
drivers/tty/serial/cpm_uart/cpm_uart_cpm2.c, which I think just needs a trivial change, but I'm not sure how to do it correctly.Arnd
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Quoted 12 lines · Michael Schmitz
Quoted 8 lines
The same could be done for the two vme drivers (
scsi/mvme147.cand ethernet/82596.c), which do the cache management but apparently don't need swiotlb bounce buffering.Rewriting the drivers to modern APIs is of course non-trivial, and if you want a shortcut here, I would suggest introducing platform specific helpers similar to
isa_virt_to_bus()and call themamiga_virt_to_bus()andvme_virt_to_bus, respectively.I don't think Amiga and m68k VME differ at all in that respect, so might just call it
m68k_virt_to_bus()for now.
Quoted 8 lines
Quoted 3 lines
Putting these into a platform specific header file at least helps clarify that both the helper functions and the drivers using them are non-portable.
There are no platform specific header files other than
asm/amigahw.handasm/mvme147hw.h, currently only holding register address definitions. Would it be OK to addm68k_virt_to_bus()in there if it can't remain inasm/virtconvert.h, Geert?
In that case, I would just leave it under the current name and not change m68k at all. I don't like the m68k_virt_to_bus() name because there is not anything CPU specific in what it does, and keeping it in a common header does nothing to prevent it from being used on other platforms either.
Quoted 11 lines
Quoted 6 lines
Quoted 1 line
32bit powerpc is a different matter though.
It's similar, but unrelated. The two apple ethernet drivers (bmac and mace) can again either get changed to use the dma-mapping interfaces, or get a custom pmac_virt_to_bus()/
pmac_bus_to_virt()helper.Hmmm - I see Finn had done the DMA API conversion on
macmace.cwhich might give some hints on what to do aboutmace.c... no idea aboutbmac.cthough. And again, haven't got hardware to test, so custom helpers is it, then.
Ok.
Arnd
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Arnd,
Am 26.06.2022 um 20:36 schrieb Arnd Bergmann:
Quoted 10 lines
Quoted 4 lines
There are no platform specific header files other than
asm/amigahw.handasm/mvme147hw.h, currently only holding register address definitions. Would it be OK to addm68k_virt_to_bus()in there if it can't remain inasm/virtconvert.h, Geert?In that case, I would just leave it under the current name and not change m68k at all. I don't like the
m68k_virt_to_bus()name because there is not anything CPU specific in what it does, and keeping it in a common header does nothing to prevent it from being used on other platforms either.
Fair enough.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
32bit powerpc is a different matter though.
It's similar, but unrelated. The two apple ethernet drivers (bmac and mace) can again either get changed to use the dma-mapping interfaces, or get a custom pmac_virt_to_bus()/
pmac_bus_to_virt()helper.
Quoted 6 lines
Quoted 4 lines
Hmmm - I see Finn had done the DMA API conversion on
macmace.cwhich might give some hints on what to do aboutmace.c... no idea aboutbmac.cthough. And again, haven't got hardware to test, so custom helpers is it, then.Ok.
Again, no platform specific headers to shift renamed helpers to, so may as well keep this as-is.
Cheers,
Michael
Quoted 3 lines
Arnd
Geert Uytterhoeven
maintainerRe: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
In reply to Michael SchmitzHi Michael,
Quoted 8 lines · Michael Schmitz
Am 18.06.2022 um 00:57 schrieb Arnd Bergmann:
Quoted 7 lines
From: Arnd Bergmann <[email protected]>
All architecture-independent users of
virt_to_bus()andbus_to_virt()have been fixed to use the dma mapping interfaces or have been removed now. This means the definitions on most architectures, and theCONFIG_VIRT_TO_BUSsymbol are now obsolete and can be removed.
Quoted 7 lines
Quoted 3 lines
The only exceptions to this are a few network and scsi drivers for m68k Amiga and VME machines and ppc32 Macintosh. These drivers work correctly with the old interfaces and are probably not worth changing.
The Amiga SCSI drivers are all old WD33C93 ones, and replacing
virt_to_busbyvirt_to_physin thedma_setup()function there would cause no functional change at all.
FTR, the sgiwd93 driver use dma_map_single().
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Hi Geert,
Quoted 11 lines · Geert Uytterhoeven
Hi Michael,
Quoted 8 lines · Michael Schmitz
Am 18.06.2022 um 00:57 schrieb Arnd Bergmann:
Quoted 7 lines
From: Arnd Bergmann <[email protected]>
All architecture-independent users of
virt_to_bus()andbus_to_virt()have been fixed to use the dma mapping interfaces or have been removed now. This means the definitions on most architectures, and theCONFIG_VIRT_TO_BUSsymbol are now obsolete and can be removed.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
The only exceptions to this are a few network and scsi drivers for m68k Amiga and VME machines and ppc32 Macintosh. These drivers work correctly with the old interfaces and are probably not worth changing.
The Amiga SCSI drivers are all old WD33C93 ones, and replacing
virt_to_busbyvirt_to_physin thedma_setup()function there would cause no functional change at all.FTR, the sgiwd93 driver use
dma_map_single().
Thanks! From what I see, it doesn't have to deal with bounce buffers though?
Cheers,
Michael
Quoted 11 lines
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Hii Geert
Am 28.06.2022 um 09:12 schrieb Michael Schmitz:
Quoted 19 lines
Hi Geert,
Quoted 16 lines · Geert Uytterhoeven
Hi Michael,
Quoted 12 lines · Michael Schmitz
Am 18.06.2022 um 00:57 schrieb Arnd Bergmann:
Quoted 11 lines
From: Arnd Bergmann <[email protected]>
All architecture-independent users of
virt_to_bus()andbus_to_virt()have been fixed to use the dma mapping interfaces or have been removed now. This means the definitions on most architectures, and theCONFIG_VIRT_TO_BUSsymbol are now obsolete and can be removed.The only exceptions to this are a few network and scsi drivers for m68k Amiga and VME machines and ppc32 Macintosh. These drivers work correctly
with the old interfaces and are probably not worth changing.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
The Amiga SCSI drivers are all old WD33C93 ones, and replacing
virt_to_busbyvirt_to_physin thedma_setup()function there would cause no functional change at all.FTR, the sgiwd93 driver use
dma_map_single().Thanks! From what I see, it doesn't have to deal with bounce buffers though?
Leaving the bounce buffer handling in place, and taking a few other liberties - this is what converting the easiest case (a3000 SCSI) might look like. Any obvious mistakes? The mvme147 driver would be very similar to handle (after conversion to a platform device).
The driver allocates bounce buffers using kmalloc if it hits an unaligned data buffer - can such buffers still even happen these days? If I understand dma_map_single() correctly, the resulting dma handle would be equally misaligned?
To allocate a bounce buffer, would it be OK to use dma_alloc_coherent() even though AFAIU memory used for DMA buffers generally isn't consistent on m68k?
Thinking ahead to the other two Amiga drivers - I wonder whether allocating a static bounce buffer or a DMA pool at driver init is likely to succeed if the kernel runs from the low 16 MB RAM chunk? It certainly won't succeed if the kernel runs from a higher memory address, so the present bounce buffer logic around amiga_chip_alloc() might still need to be used here.
Leaves the question whether converting the gvp11 and a2091 drivers is actually worth it, if bounce buffers still have to be handled explicitly.
Untested (except for compile testing), un-checkpatched, don't try this on any disk with valuable data ...
Cheers,
Michael
From e8c6aa068d27901c49dfb7442d4200cc966350a5 Mon Sep 17 00:00:00 2001
From: Michael Schmitz <[email protected]>
Date: Tue, 28 Jun 2022 12:45:08 +1200
Subject: [PATCH] scsi - convert m68k WD33C93 drivers to DMA API
Use dma_map_single() for gvp11 driver (leave bounce buffer logic unchanged).
Compile-tested only.
--- drivers/scsi/a3000.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
drivers/scsi/a3000.c +20 -2
@@ -7,6 +7,7 @@#include <linux/spinlock.h> #include <linux/interrupt.h> #include <linux/platform_device.h> +#include <linux/dma-mapping.h> #include <linux/module.h> #include <asm/page.h>
@@ -25,8 +26,11 @@struct a3000_hostdata {struct WD33C93_hostdata wh;struct a3000_scsiregs *regs; +struct device *dev; }; +#define DMA_DIR (d) ((d == DATA_OUT_DIR) ? DMA_TO_DEVICE : DMA_FROM_DEVICE) +static irqreturn_t a3000_intr (int irq,void *data) {struct Scsi_Host *instance = data;
@@ -49,12 +53,16 @@ static irqreturn_t a3000_intr(int irq, void *data)static int dma_setup (struct scsi_cmnd *cmd,int dir_in) {struct scsi_pointer *scsi_pointer =WD33C93_scsi_pointer (cmd); +unsigned long len = scsi_pointer->this_residual;struct Scsi_Host *instance = cmd->device->host;struct a3000_hostdata *hdata =shost_priv (instance);struct WD33C93_hostdata *wh = &hdata->wh;struct a3000_scsiregs *regs = hdata->regs;unsigned short cntr =CNTR_PDMD |CNTR_INTEN ; -unsigned long addr =virt_to_bus (scsi_pointer->ptr); +dma_addr_t addr; + + addr =dma_map_single (hdata->dev, scsi_pointer->ptr, len,DMA_DIR (dir_in)); + scsi_pointer->dma_handle = addr;/* * if the physical address has the wrong alignment, or if
@@ -79,7 +87,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in) scsi_pointer->this_residual); } - addr =virt_to_bus (wh->dma_bounce_buffer); + addr =virt_to_phys (wh->dma_bounce_buffer); }/* setup dma direction */
@@ -166,6 +174,10 @@ static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, wh->dma_bounce_len =0 ; } } +dma_unmap_single (hdata->dev, scsi_pointer->dma_handle, + scsi_pointer->this_residual, +DMA_DIR (wh->dma_dir)); + }static struct scsi_host_template amiga_a3000_scsi_template = {
@@ -193,6 +205,11 @@ static int __init amiga_a3000_scsi_probe(struct platform_device *pdev)wd33c93_regs wdregs;struct a3000_hostdata *hdata; +if (dma_set_mask (&pdev->dev,DMA_BIT_MASK (32 ))) { +dev_warn (&pdev->dev,"cannot use 32 bit DMA\n" ); +return -ENODEV ; + } + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res)return -ENODEV ;
@@ -216,6 +233,7 @@ static int __init amiga_a3000_scsi_probe(struct platform_device *pdev) wdregs.SCMD = ®s->SCMD; hdata =shost_priv (instance); + hdata->dev = &pdev->dev; hdata->wh.no_sync =0xff ; hdata->wh.fast =0 ; hdata->wh.dma_mode =CTRL_DMA ;
Signature · 1 line
2.17.1
Geert Uytterhoeven
maintainerRe: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Hi Michael,
Quoted 21 lines · Michael Schmitz
Am 28.06.2022 um 09:12 schrieb Michael Schmitz:
Quoted 20 lines · Geert Uytterhoeven
Quoted 18 lines
Quoted 8 lines · Michael Schmitz
Am 18.06.2022 um 00:57 schrieb Arnd Bergmann:
Quoted 7 lines
From: Arnd Bergmann <[email protected]>
All architecture-independent users of
virt_to_bus()andbus_to_virt()have been fixed to use the dma mapping interfaces or have been removed now. This means the definitions on most architectures, and theCONFIG_VIRT_TO_BUSsymbol are now obsolete and can be removed.Quoted 7 lines
Quoted 4 lines
The only exceptions to this are a few network and scsi drivers for m68k Amiga and VME machines and ppc32 Macintosh. These drivers work correctly
with the old interfaces and are probably not worth changing.The Amiga SCSI drivers are all old WD33C93 ones, and replacing
virt_to_busbyvirt_to_physin thedma_setup()function there would cause no functional change at all.FTR, the sgiwd93 driver use
dma_map_single().
Quoted 7 lines
Quoted 2 lines
Thanks! From what I see, it doesn't have to deal with bounce buffers though?
Leaving the bounce buffer handling in place, and taking a few other liberties - this is what converting the easiest case (a3000 SCSI) might look like. Any obvious mistakes? The mvme147 driver would be very similar to handle (after conversion to a platform device).
Thanks, looks reasonable.
Quoted 2 lines
The driver allocates bounce buffers using kmalloc if it hits an unaligned data buffer - can such buffers still even happen these days?
No idea.
Quoted 14 lines
If I understand
dma_map_single()correctly, the resulting dma handle would be equally misaligned?To allocate a bounce buffer, would it be OK to use
dma_alloc_coherent()even though AFAIU memory used for DMA buffers generally isn't consistent on m68k?Thinking ahead to the other two Amiga drivers - I wonder whether allocating a static bounce buffer or a DMA pool at driver init is likely to succeed if the kernel runs from the low 16 MB RAM chunk? It certainly won't succeed if the kernel runs from a higher memory address, so the present bounce buffer logic around
amiga_chip_alloc()might still need to be used here.
Quoted 2 lines
Leaves the question whether converting the gvp11 and a2091 drivers is actually worth it, if bounce buffers still have to be handled explicitly.
A2091 should be straight-forward, as A3000 is basically A2091 on the motherboard (comparing the two drivers, looks like someone's been sprinkling mb()s over the A3000 driver).
I don't have any of these SCSI host adapters (not counting the A590 (~A2091) expansion of the old A500, which is not Linux-capable, and
hasn't been powered on for 20 years).
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Hi Geert,
Quoted 6 lines · Geert Uytterhoeven
Quoted 5 lines
Leaving the bounce buffer handling in place, and taking a few other liberties - this is what converting the easiest case (a3000 SCSI) might look like. Any obvious mistakes? The mvme147 driver would be very similar to handle (after conversion to a platform device).
Thanks, looks reasonable.
Thanks, I'll take care of Arnd's comments and post a corrected version later.
Quoted 3 lines
Quoted 2 lines
The driver allocates bounce buffers using kmalloc if it hits an unaligned data buffer - can such buffers still even happen these days?
No idea.
Hmmm - I think I'll stick a WARN_ONCE() in there so we know whether this code path is still being used.
Quoted 15 lines
Quoted 15 lines
If I understand
dma_map_single()correctly, the resulting dma handle would be equally misaligned?To allocate a bounce buffer, would it be OK to use
dma_alloc_coherent()even though AFAIU memory used for DMA buffers generally isn't consistent on m68k?Thinking ahead to the other two Amiga drivers - I wonder whether allocating a static bounce buffer or a DMA pool at driver init is likely to succeed if the kernel runs from the low 16 MB RAM chunk? It certainly won't succeed if the kernel runs from a higher memory address, so the present bounce buffer logic around
amiga_chip_alloc()might still need to be used here.
Quoted 5 lines
Quoted 2 lines
Leaves the question whether converting the gvp11 and a2091 drivers is actually worth it, if bounce buffers still have to be handled explicitly.
A2091 should be straight-forward, as A3000 is basically A2091 on the motherboard (comparing the two drivers, looks like someone's been sprinkling mb()s over the A3000 driver).
Yep, and at least the ones in the dma_setup() function are there for no reason (the compiler won't reorder stores around the cache flush calls, I hope?).
Just leaves the 24 bit DMA mask there (and likely need for bounce buffers).
Quoted 3 lines
I don't have any of these SCSI host adapters (not counting the A590 (~A2091) expansion of the old A500, which is not Linux-capable, and
hasn't been powered on for 20 years).
I wonder whether kullervo has survived - that one was an A3000. Should have gone to Adrian a few years ago...
Cheers,
Michael
Quoted 11 lines
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Quoted 6 lines · Michael Schmitz
Quoted 3 lines · Geert Uytterhoeven
Quoted 2 lines
The driver allocates bounce buffers using kmalloc if it hits an unaligned data buffer - can such buffers still even happen these days?
No idea.
Hmmm - I think I'll stick a
WARN_ONCE()in there so we know whether this code path is still being used.
kmalloc() guarantees alignment to the next power-of-two size or KMALLOC_MIN_ALIGN, whichever is bigger. On m68k this means it is cacheline aligned.
Arnd
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Hi Arnd,
Quoted 10 lines · Arnd Bergmann
Quoted 6 lines · Michael Schmitz
Quoted 3 lines · Geert Uytterhoeven
Quoted 2 lines
The driver allocates bounce buffers using kmalloc if it hits an unaligned data buffer - can such buffers still even happen these days?
No idea.
Hmmm - I think I'll stick a
WARN_ONCE()in there so we know whether this code path is still being used.
kmalloc()guarantees alignment to the next power-of-two size orKMALLOC_MIN_ALIGN, whichever is bigger. On m68k this means it is cacheline aligned.
And all SCSI buffers are allocated using kmalloc? No way at all for user space to pass unaligned data?
(SCSI is a weird beast - I have used a SCSI DAT tape driver many many years ago, which broke all sorts of assumptions about transfer block sizes ... but that might actually have been in the v0.99 days, many rewrites of SCSI midlevel ago).
Just being cautious, as getting any of this tested will be a stretch.
Cheers,
Michael
Quoted 2 lines
Arnd
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Quoted 12 lines · Michael Schmitz
Quoted 10 lines · Arnd Bergmann
Quoted 6 lines · Michael Schmitz
Quoted 3 lines · Geert Uytterhoeven
Quoted 2 lines
The driver allocates bounce buffers using kmalloc if it hits an unaligned data buffer - can such buffers still even happen these days?
No idea.
Hmmm - I think I'll stick a
WARN_ONCE()in there so we know whether this code path is still being used.
kmalloc()guarantees alignment to the next power-of-two size orKMALLOC_MIN_ALIGN, whichever is bigger. On m68k this means it is cacheline aligned.
Quoted 5 lines
And all SCSI buffers are allocated using kmalloc? No way at all for user space to pass unaligned data?
(SCSI is a weird beast - I have used a SCSI DAT tape driver many many years ago, which broke all sorts of assumptions about transfer block sizes ... but that might actually have been in the v0.99 days, many rewrites of SCSI midlevel ago).
Just being cautious, as getting any of this tested will be a stretch.
An example of a user space application that passes an SG I/O data buffer to the kernel that is aligned to a four byte boundary but not to an eight byte boundary if the -s (scattered) command line option is used: https://github.com/osandov/blktests/blob/master/src/discontiguous-io.cpp
Bart.
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Hi Bart,
Quoted 13 lines · Bart Van Assche
Quoted 12 lines · Michael Schmitz
Quoted 10 lines · Arnd Bergmann
Quoted 6 lines · Michael Schmitz
Quoted 3 lines · Geert Uytterhoeven
Quoted 2 lines
The driver allocates bounce buffers using kmalloc if it hits an unaligned data buffer - can such buffers still even happen these days?
No idea.
Hmmm - I think I'll stick a
WARN_ONCE()in there so we know whether this code path is still being used.
kmalloc()guarantees alignment to the next power-of-two size orKMALLOC_MIN_ALIGN, whichever is bigger. On m68k this means it is cacheline aligned.
Quoted 7 lines
Quoted 5 lines
And all SCSI buffers are allocated using kmalloc? No way at all for user space to pass unaligned data?
(SCSI is a weird beast - I have used a SCSI DAT tape driver many many years ago, which broke all sorts of assumptions about transfer block sizes ... but that might actually have been in the v0.99 days, many rewrites of SCSI midlevel ago).
Just being cautious, as getting any of this tested will be a stretch.
An example of a user space application that passes an SG I/O data buffer to the kernel that is aligned to a four byte boundary but not to an eight byte boundary if the -s (scattered) command line option is used: https://github.com/osandov/blktests/blob/master/src/discontiguous-io.cpp
Thanks - four byte alignment actually wouldn't be an issue for me. It's two byte or smaller that would trip up the SCSI DMA.
While I'm sure such an even more pathological test case could be written, I was rather worried about st.c and sr.c input ...
Cheers,
Michael
Quoted 2 lines
Bart.
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Hi Bart,
Quoted 6 lines · Michael Schmitz
Quoted 2 lines
An example of a user space application that passes an SG I/O data buffer to the kernel that is aligned to a four byte boundary but not to an eight byte boundary if the -s (scattered) command line option is used: https://github.com/osandov/blktests/blob/master/src/discontiguous-io.cpp
Thanks - four byte alignment actually wouldn't be an issue for me. It's two byte or smaller that would trip up the SCSI DMA.
While I'm sure such an even more pathological test case could be written, I was rather worried about
st.candsr.cinput ...
Nevermind - I just see m68k defines ARCH_DMA_MINALIGN to be four bytes. Should be safe for all that matters, then.
Cheers,
Michael
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
In reply to Michael SchmitzQuoted 2 lines · Michael Schmitz
And all SCSI buffers are allocated using kmalloc? No way at all for user space to pass unaligned data?
Most that you will see actually comes from the page allocator. But the block layer has a dma_alignment limit, and when userspace sends I/O that is not properly aligned it will be bounce buffered before it it sent to the driver.
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Hi Christoph,
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Michael Schmitz
And all SCSI buffers are allocated using kmalloc? No way at all for user space to pass unaligned data?
Most that you will see actually comes from the page allocator. But the block layer has a
dma_alignmentlimit, and when userspace sends I/O that is not properly aligned it will be bounce buffered before it it sent to the driver.
That limit is set to L1_CACHE_BYTES on m68k so we're good here.
Thanks,
Michael
RE: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
In reply to Michael SchmitzFrom: Michael Schmitz
Quoted 10 lines
Sent: 29 June 2022 00:09
Hi Arnd,
Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · Michael Schmitz
Quoted 3 lines · Geert Uytterhoeven
Quoted 2 lines
The driver allocates bounce buffers using kmalloc if it hits an unaligned data buffer - can such buffers still even happen these days?
No idea.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Hmmm - I think I'll stick a
WARN_ONCE()in there so we know whether this code path is still being used.
kmalloc()guarantees alignment to the next power-of-two size orKMALLOC_MIN_ALIGN, whichever is bigger. On m68k this means it is cacheline aligned.And all SCSI buffers are allocated using kmalloc? No way at all for user space to pass unaligned data?
I didn't think kmalloc() gave any such guarantee about alignment. There are cache-line alignment requirements on systems with non-coherent dma, but otherwise the alignment can be much smaller.
One of the allocators adds a header to each item, IIRC that can lead to 'unexpected' alignments - especially on m68k.
dma_alloc_coherent() does align to next 'power of 2'. And sometimes you need (eg) 16k allocates that are 16k aligned.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Le 30/06/2022 à 10:04, David Laight a écrit :
Quoted 13 lines
From: Michael Schmitz
Quoted 12 lines
Sent: 29 June 2022 00:09
Hi Arnd,
Quoted 7 lines · Arnd Bergmann
Quoted 6 lines · Michael Schmitz
Quoted 3 lines · Geert Uytterhoeven
Quoted 2 lines
The driver allocates bounce buffers using kmalloc if it hits an unaligned data buffer - can such buffers still even happen these days?
No idea.
Hmmm - I think I'll stick a
WARN_ONCE()in there so we know whether this code path is still being used.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
kmalloc()guarantees alignment to the next power-of-two size orKMALLOC_MIN_ALIGN, whichever is bigger. On m68k this means it is cacheline aligned.And all SCSI buffers are allocated using kmalloc? No way at all for user space to pass unaligned data?
I didn't think
kmalloc()gave any such guarantee about alignment.
I does since commit 59bb47985c1d ("mm, sl[aou]b: guarantee natural alignment for kmalloc(power-of-two)")
Christophe
Quoted 6 lines
There are cache-line alignment requirements on systems with non-coherent dma, but otherwise the alignment can be much smaller.
One of the allocators adds a header to each item, IIRC that can lead to 'unexpected' alignments - especially on m68k.
Quoted 8 lines
dma_alloc_coherent()does align to next 'power of 2'. And sometimes you need (eg) 16k allocates that are 16k aligned.David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
RE: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
From: Christophe Leroy
Quoted 20 lines
Sent: 30 June 2022 10:40
Le 30/06/2022 à 10:04, David Laight a écrit :
Quoted 17 lines
From: Michael Schmitz
Quoted 16 lines
Sent: 29 June 2022 00:09
Hi Arnd,
Quoted 10 lines · Arnd Bergmann
Quoted 6 lines · Michael Schmitz
Quoted 3 lines · Geert Uytterhoeven
Quoted 2 lines
The driver allocates bounce buffers using kmalloc if it hits an unaligned data buffer - can such buffers still even happen these days?
No idea.
Hmmm - I think I'll stick a
WARN_ONCE()in there so we know whether this code path is still being used.
kmalloc()guarantees alignment to the next power-of-two size orKMALLOC_MIN_ALIGN, whichever is bigger. On m68k this means it is cacheline aligned.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
And all SCSI buffers are allocated using kmalloc? No way at all for user space to pass unaligned data?
I didn't think
kmalloc()gave any such guarantee about alignment.I does since commit
59bb47985c1d("mm, sl[aou]b: guarantee natural alignment for kmalloc(power-of-two)")
Looks like it is done for 'power-of-two' less than PAGE_SIZE. This may not help scsi tape writes which could easily be (say) 47 bytes. I think that only guarantees 2 byte alignment on m68k. (Although increasing the min-alignment on m68k to 4 (or even 8) will probably make no measurable difference.)
What happens above PAGE_SIZE?
Any structure with a trailing [] field could easily request '64k + a_bit' bytes.
You don't really want to extend this to 128k - but I suspect that is what happens.
David
Quoted 17 lines
Christophe
Quoted 14 lines
There are cache-line alignment requirements on systems with non-coherent dma, but otherwise the alignment can be much smaller.
One of the allocators adds a header to each item, IIRC that can lead to 'unexpected' alignments - especially on m68k.
dma_alloc_coherent()does align to next 'power of 2'. And sometimes you need (eg) 16k allocates that are 16k aligned.David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
In reply to Michael SchmitzQuoted 7 lines · Michael Schmitz
Am 28.06.2022 um 09:12 schrieb Michael Schmitz:
Leaving the bounce buffer handling in place, and taking a few other liberties - this is what converting the easiest case (a3000 SCSI) might look like. Any obvious mistakes? The mvme147 driver would be very similar to handle (after conversion to a platform device).
Quoted 8 lines
The driver allocates bounce buffers using kmalloc if it hits an unaligned data buffer - can such buffers still even happen these days? If I understand
dma_map_single()correctly, the resulting dma handle would be equally misaligned?To allocate a bounce buffer, would it be OK to use
dma_alloc_coherent()even though AFAIU memory used for DMA buffers generally isn't consistent on m68k?
I think it makes sense to skip the bounce buffering as you do here:
the only standardized way we have for integrating that part is to use the swiotlb infrastructure, but as you mentioned earlier that part is probably too resource-heavy here for Amiga.
I see two other problems with your patch though:
a) you still duplicate the cache handling: the cache_clear()/cache_push() is supposed to already be done by dma_map_single() when the device is not cache-coherent.
b) The bounce buffer is never mapped here, instead you have the virt_to_phys() here, which is not the same. I think you need to map the pointer that actually gets passed down to the device after deciding to use a bouce buffer or not.
Arnd
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Hi Arnd,
Quoted 13 lines · Arnd Bergmann
Quoted 12 lines · Michael Schmitz
Am 28.06.2022 um 09:12 schrieb Michael Schmitz:
Leaving the bounce buffer handling in place, and taking a few other liberties - this is what converting the easiest case (a3000 SCSI) might look like. Any obvious mistakes? The mvme147 driver would be very similar to handle (after conversion to a platform device).
The driver allocates bounce buffers using kmalloc if it hits an unaligned data buffer - can such buffers still even happen these days? If I understand
dma_map_single()correctly, the resulting dma handle would be equally misaligned?
Quoted 7 lines
Quoted 3 lines
To allocate a bounce buffer, would it be OK to use
dma_alloc_coherent()even though AFAIU memory used for DMA buffers generally isn't consistent on m68k?I think it makes sense to skip the bounce buffering as you do here:
the only standardized way we have for integrating that part is to use the swiotlb infrastructure, but as you mentioned earlier that part is probably too resource-heavy here for Amiga.
OK, leaving the old custom logic in place allows to convert the 24 bit DMA drivers more easily.
Quoted 6 lines
I see two other problems with your patch though:
a) you still duplicate the cache handling: the cache_clear()/cache_push() is supposed to already be done by
dma_map_single()when the device is not cache-coherent.
That's one of the 'liberties' I alluded to. The reason I left these in is that I'm none too certain what device feature the DMA API uses to decide a device isn't cache-coherent. If it's dev->coherent_dma_mask, the way I set up the device in the a3000 driver should leave the coherent mask unchanged. For the Zorro drivers, devices are set up to use the same storage to store normal and coherent masks - something we most likely want to change. I need to think about the ramifications of that.
Note that zorro_esp.c uses dma_sync_single_for_device() and uses a 32 bit coherent DMA mask which does work OK. I might ask Adrian to test a change to only set dev->dma_mask, and drop the dma_sync_single_for_device() calls if there's any doubt on this aspect.
Quoted 4 lines
b) The bounce buffer is never mapped here, instead you have the
virt_to_phys()here, which is not the same. I think you need to map the pointer that actually gets passed down to the device after deciding to use a bouce buffer or not.
I hadn't realized that I can map the bounce buffer just as it's done for the SCp data buffer. Should have been obvious, but I'm still learning about the DMA API.
I've updated the patch now, will re-send as part of a complete series once done.
Cheers,
Michael
Quoted 2 lines
Arnd
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Quoted 16 lines · Michael Schmitz
Quoted 5 lines · Arnd Bergmann
I see two other problems with your patch though:
a) you still duplicate the cache handling: the cache_clear()/cache_push() is supposed to already be done by
dma_map_single()when the device is not cache-coherent.That's one of the 'liberties' I alluded to. The reason I left these in is that I'm none too certain what device feature the DMA API uses to decide a device isn't cache-coherent. If it's
dev->coherent_dma_mask, the way I set up the device in the a3000 driver should leave the coherent mask unchanged. For the Zorro drivers, devices are set up to use the same storage to store normal and coherent masks - something we most likely want to change. I need to think about the ramifications of that.
Quoted 4 lines
Note that
zorro_esp.cusesdma_sync_single_for_device()and uses a 32 bit coherent DMA mask which does work OK. I might ask Adrian to test a change to only setdev->dma_mask, and drop thedma_sync_single_for_device()calls if there's any doubt on this aspect.
The "coherent_mask" is independent of the cache flushing. On some architectures, a device can indicate whether it needs cache management or not to guarantee coherency, but on m68k it appears that we always assume it does, see arch/m68k/kernel/dma.c
Quoted 11 lines
Quoted 4 lines
b) The bounce buffer is never mapped here, instead you have the
virt_to_phys()here, which is not the same. I think you need to map the pointer that actually gets passed down to the device after deciding to use a bouce buffer or not.I hadn't realized that I can map the bounce buffer just as it's done for the SCp data buffer. Should have been obvious, but I'm still learning about the DMA API.
I've updated the patch now, will re-send as part of a complete series once done.
I suppose you can just drop the bounce buffer if this just comes from kmalloc().
Arnd
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Hi Arnd,
Quoted 16 lines · Arnd Bergmann
Quoted 15 lines · Michael Schmitz
Quoted 5 lines · Arnd Bergmann
I see two other problems with your patch though:
a) you still duplicate the cache handling: the cache_clear()/cache_push() is supposed to already be done by
dma_map_single()when the device is not cache-coherent.That's one of the 'liberties' I alluded to. The reason I left these in is that I'm none too certain what device feature the DMA API uses to decide a device isn't cache-coherent. If it's
dev->coherent_dma_mask, the way I set up the device in the a3000 driver should leave the coherent mask unchanged. For the Zorro drivers, devices are set up to use the same storage to store normal and coherent masks - something we most likely want to change. I need to think about the ramifications of that.
Quoted 8 lines
Quoted 4 lines
Note that
zorro_esp.cusesdma_sync_single_for_device()and uses a 32 bit coherent DMA mask which does work OK. I might ask Adrian to test a change to only setdev->dma_mask, and drop thedma_sync_single_for_device()calls if there's any doubt on this aspect.The "
coherent_mask" is independent of the cache flushing. On some architectures, a device can indicate whether it needs cache management or not to guarantee coherency, but on m68k it appears that we always assume it does, seearch/m68k/kernel/dma.c
Thanks - what I see there indicates that on the relevant platforms, pages mapped for DMA have their page table cache bits modified to make them non-cacheable (and I suppose unmapping restores the default cache bits). That means I should use dma_set_mask_and_coherent() here to take advantage of this, and no need to mess around with dma_sync_single_for_device() in the drivers' dma_setup() functions.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
b) The bounce buffer is never mapped here, instead you have the
virt_to_phys()here, which is not the same. I think you need to map the pointer that actually gets passed down to the device after deciding to use a bouce buffer or not.
Quoted 8 lines
Quoted 6 lines
I hadn't realized that I can map the bounce buffer just as it's done for the SCp data buffer. Should have been obvious, but I'm still learning about the DMA API.
I've updated the patch now, will re-send as part of a complete series once done.
I suppose you can just drop the bounce buffer if this just comes from
kmalloc().
That's only true for a3000 and mvme147 though.
Cheers,
Michael
Quoted 2 lines
Arnd
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
In reply to Michael SchmitzQuoted 3 lines · Michael Schmitz
That's one of the 'liberties' I alluded to. The reason I left these in is that I'm none too certain what device feature the DMA API uses to decide a device isn't cache-coherent.
The DMA API does not look at device features at all. It needs to be told so by the platform code. Once an architecture implements the hooks to support non-coherent DMA all devices are treated as non-coherent by default unless overriden by the architecture either globally (using the global dma_default_coherent variable) or per-device (using the dev->dma_coherent field, usually set by arch_setup_dma_ops).
Quoted 5 lines
If it's
dev->coherent_dma_mask, the way I set
up the device in the a3000 driver should leave the coherent mask unchanged. For the Zorro drivers, devices are set up to use the same storage to store normal and coherent masks - something we most likely want to change. I need to think about the ramifications of that.
No, the coherent mask is slightly misnamed amd not actually related.
Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS
Hi Christoph,
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Michael Schmitz
That's one of the 'liberties' I alluded to. The reason I left these in is that I'm none too certain what device feature the DMA API uses to decide a device isn't cache-coherent.
The DMA API does not look at device features at all. It needs to be told so by the platform code. Once an architecture implements the hooks to support non-coherent DMA all devices are treated as non-coherent by default unless overriden by the architecture either globally (using the global
dma_default_coherentvariable) or per-device (using thedev->dma_coherentfield, usually set byarch_setup_dma_ops).
Haven't got any of that, so non-coherent DMA is all we can use (even though some of the RAM used for bounce buffers may actually be coherent due to the page table cache bits).
Quoted 7 lines
Quoted 6 lines
If it's
dev->coherent_dma_mask, the way I set
up the device in the a3000 driver should leave the coherent mask unchanged. For the Zorro drivers, devices are set up to use the same storage to store normal and coherent masks - something we most likely want to change. I need to think about the ramifications of that.No, the coherent mask is slightly misnamed amd not actually related.
Thanks, that had me confused.
Cheers,
Michael