* [PATCH 0/2] make e1000 work on MIPS
@ 2023-02-10 14:39 Denis Orlov
2023-02-10 14:39 ` [PATCH 1/2] net: e1000: properly map dma allocations Denis Orlov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Denis Orlov @ 2023-02-10 14:39 UTC (permalink / raw)
To: barebox; +Cc: Denis Orlov
With these changes, e1000 driver now works on MIPS Malta in QEMU with
the corresponding network controller attached:
-netdev user,tftp=/tftpboot,id=net0 -device e1000,netdev=net0
Antony Pavlov (1):
net: e1000: properly map dma allocations
Denis Orlov (1):
dma: use virt/phys conversions when no dma_offset is specified
drivers/dma/map.c | 25 ++++++++++---------------
drivers/net/e1000/e1000.h | 2 ++
drivers/net/e1000/main.c | 8 ++++----
3 files changed, 16 insertions(+), 19 deletions(-)
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] net: e1000: properly map dma allocations
2023-02-10 14:39 [PATCH 0/2] make e1000 work on MIPS Denis Orlov
@ 2023-02-10 14:39 ` Denis Orlov
2023-02-10 14:39 ` [PATCH 2/2] dma: use virt/phys conversions when no dma_offset is specified Denis Orlov
2023-02-13 9:00 ` [PATCH 0/2] make e1000 work on MIPS Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Denis Orlov @ 2023-02-10 14:39 UTC (permalink / raw)
To: barebox; +Cc: Denis Orlov
From: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
drivers/net/e1000/e1000.h | 2 ++
drivers/net/e1000/main.c | 8 ++++----
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/net/e1000/e1000.h b/drivers/net/e1000/e1000.h
index 558a4ac271..d440d7540a 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -2183,7 +2183,9 @@ struct e1000_hw {
struct mii_bus miibus;
struct e1000_tx_desc *tx_base;
+ dma_addr_t tx_base_phys;
struct e1000_rx_desc *rx_base;
+ dma_addr_t rx_base_phys;
unsigned char *packet;
dma_addr_t packet_dma;
diff --git a/drivers/net/e1000/main.c b/drivers/net/e1000/main.c
index e00bc48417..c259d72f27 100644
--- a/drivers/net/e1000/main.c
+++ b/drivers/net/e1000/main.c
@@ -3267,7 +3267,7 @@ static void e1000_configure_tx(struct e1000_hw *hw)
unsigned long tctl;
unsigned long tipg, tarc;
uint32_t ipgr1, ipgr2;
- const unsigned long tx_base = (unsigned long)hw->tx_base;
+ const unsigned long tx_base = (unsigned long)hw->tx_base_phys;
e1000_write_reg(hw, E1000_TDBAL, lower_32_bits(tx_base));
e1000_write_reg(hw, E1000_TDBAH, upper_32_bits(tx_base));
@@ -3386,7 +3386,7 @@ static void e1000_setup_rctl(struct e1000_hw *hw)
static void e1000_configure_rx(struct e1000_hw *hw)
{
unsigned long rctl, ctrl_ext;
- const unsigned long rx_base = (unsigned long)hw->rx_base;
+ const unsigned long rx_base = (unsigned long)hw->rx_base_phys;
hw->rx_tail = 0;
/* make sure receives are disabled while setting up the descriptors */
@@ -3595,8 +3595,8 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *id)
hw = xzalloc(sizeof(*hw));
- hw->tx_base = dma_alloc_coherent(16 * sizeof(*hw->tx_base), DMA_ADDRESS_BROKEN);
- hw->rx_base = dma_alloc_coherent(16 * sizeof(*hw->rx_base), DMA_ADDRESS_BROKEN);
+ hw->tx_base = dma_alloc_coherent(16 * sizeof(*hw->tx_base), &hw->tx_base_phys);
+ hw->rx_base = dma_alloc_coherent(16 * sizeof(*hw->rx_base), &hw->rx_base_phys);
edev = &hw->edev;
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] dma: use virt/phys conversions when no dma_offset is specified
2023-02-10 14:39 [PATCH 0/2] make e1000 work on MIPS Denis Orlov
2023-02-10 14:39 ` [PATCH 1/2] net: e1000: properly map dma allocations Denis Orlov
@ 2023-02-10 14:39 ` Denis Orlov
2023-02-13 9:00 ` [PATCH 0/2] make e1000 work on MIPS Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Denis Orlov @ 2023-02-10 14:39 UTC (permalink / raw)
To: barebox; +Cc: Denis Orlov
The code was assuming that in such cases we can just use cpu addresses
as physical ones. This is incorrect on MIPS, the only platform that has
its own virt_to_phys/phys_to_virt functions defined.
This fixes issues with DMA mappings on MIPS, with e1000 PCI ethernet
card now working on Malta in QEMU.
Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
drivers/dma/map.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/drivers/dma/map.c b/drivers/dma/map.c
index a00abf6421..13dbf2840f 100644
--- a/drivers/dma/map.c
+++ b/drivers/dma/map.c
@@ -3,25 +3,20 @@
#include <dma.h>
-static inline dma_addr_t cpu_to_dma(struct device *dev,
- unsigned long cpu_addr)
+static inline dma_addr_t cpu_to_dma(struct device *dev, void *cpu_addr)
{
- dma_addr_t dma_addr = cpu_addr;
+ if (dev && dev->dma_offset)
+ return (unsigned long)cpu_addr - dev->dma_offset;
- if (dev)
- dma_addr -= dev->dma_offset;
-
- return dma_addr;
+ return virt_to_phys(cpu_addr);
}
-static inline unsigned long dma_to_cpu(struct device *dev, dma_addr_t addr)
+static inline void *dma_to_cpu(struct device *dev, dma_addr_t addr)
{
- unsigned long cpu_addr = addr;
-
- if (dev)
- cpu_addr += dev->dma_offset;
+ if (dev && dev->dma_offset)
+ return (void *)(addr + dev->dma_offset);
- return cpu_addr;
+ return phys_to_virt(addr);
}
dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
@@ -31,13 +26,13 @@ dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
dma_sync_single_for_device(addr, size, dir);
- return cpu_to_dma(dev, addr);
+ return cpu_to_dma(dev, ptr);
}
void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
enum dma_data_direction dir)
{
- unsigned long addr = dma_to_cpu(dev, dma_addr);
+ unsigned long addr = (unsigned long)dma_to_cpu(dev, dma_addr);
dma_sync_single_for_cpu(addr, size, dir);
}
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] make e1000 work on MIPS
2023-02-10 14:39 [PATCH 0/2] make e1000 work on MIPS Denis Orlov
2023-02-10 14:39 ` [PATCH 1/2] net: e1000: properly map dma allocations Denis Orlov
2023-02-10 14:39 ` [PATCH 2/2] dma: use virt/phys conversions when no dma_offset is specified Denis Orlov
@ 2023-02-13 9:00 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2023-02-13 9:00 UTC (permalink / raw)
To: Denis Orlov; +Cc: barebox
On Fri, Feb 10, 2023 at 05:39:22PM +0300, Denis Orlov wrote:
> With these changes, e1000 driver now works on MIPS Malta in QEMU with
> the corresponding network controller attached:
> -netdev user,tftp=/tftpboot,id=net0 -device e1000,netdev=net0
>
> Antony Pavlov (1):
> net: e1000: properly map dma allocations
>
> Denis Orlov (1):
> dma: use virt/phys conversions when no dma_offset is specified
>
> drivers/dma/map.c | 25 ++++++++++---------------
> drivers/net/e1000/e1000.h | 2 ++
> drivers/net/e1000/main.c | 8 ++++----
> 3 files changed, 16 insertions(+), 19 deletions(-)
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-02-13 9:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-10 14:39 [PATCH 0/2] make e1000 work on MIPS Denis Orlov
2023-02-10 14:39 ` [PATCH 1/2] net: e1000: properly map dma allocations Denis Orlov
2023-02-10 14:39 ` [PATCH 2/2] dma: use virt/phys conversions when no dma_offset is specified Denis Orlov
2023-02-13 9:00 ` [PATCH 0/2] make e1000 work on MIPS Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox