Skip to contentSkip to conversation

make e1000 work on MIPS

PATCH Applied Denis Orlov 2 participants 4 messages Feb 10, 2023 – Feb 13, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover make e1000 work on MIPS

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(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/2 net: e1000: properly map dma allocations

From: Antony Pavlov <[email protected]>

---
 drivers/net/e1000/e1000.h | 2 ++
 drivers/net/e1000/main.c  | 8 ++++----
 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/net/e1000/e1000.h +2 -0
index 558a4ac271..d440d7540a 100644
@@ -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;
 
drivers/net/e1000/main.c +4 -4
index e00bc48417..c259d72f27 100644
@@ -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;
 
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/2 dma: use virt/phys conversions when no dma_offset is specified

In reply to 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.

---
 drivers/dma/map.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
drivers/dma/map.c +10 -15
index a00abf6421..13dbf2840f 100644
@@ -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);
 }
Signature · 1 line
2.30.2
Applied
#3 lore raw
In reply to Denis Orlov
Quoted 7 lines · 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

Quoted 7 lines

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

Signature · 4 lines
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 |