Skip to content

Commit

Permalink
net: lpc-enet: factor out iram access
Browse files Browse the repository at this point in the history
The lpc_eth driver uses a platform specific method to find
the internal sram. This prevents building it on other machines.

Rework to only use one function call and keep the other platform
internals where they belong. Ideally this would look up the
sram location from DT, but as this is a rarely used driver,
I want to keep the modifications to a minimum.

Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Arnd Bergmann <[email protected]>
  • Loading branch information
arndb committed Aug 15, 2019
1 parent d88ce24 commit 9dc03ff
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
9 changes: 7 additions & 2 deletions arch/arm/mach-lpc32xx/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#include <linux/init.h>
#include <linux/soc/nxp/lpc32xx-misc.h>

#include <asm/mach/map.h>
#include <asm/system_info.h>
Expand All @@ -32,7 +33,7 @@ void lpc32xx_get_uid(u32 devid[4])
*/
#define LPC32XX_IRAM_BANK_SIZE SZ_128K
static u32 iram_size;
u32 lpc32xx_return_iram_size(void)
u32 lpc32xx_return_iram(void __iomem **mapbase, dma_addr_t *dmaaddr)
{
if (iram_size == 0) {
u32 savedval1, savedval2;
Expand All @@ -53,10 +54,14 @@ u32 lpc32xx_return_iram_size(void)
} else
iram_size = LPC32XX_IRAM_BANK_SIZE * 2;
}
if (dmaaddr)
*dmaaddr = LPC32XX_IRAM_BASE;
if (mapbase)
*mapbase = io_p2v(LPC32XX_IRAM_BASE);

return iram_size;
}
EXPORT_SYMBOL_GPL(lpc32xx_return_iram_size);
EXPORT_SYMBOL_GPL(lpc32xx_return_iram);

static struct map_desc lpc32xx_io_desc[] __initdata = {
{
Expand Down
1 change: 0 additions & 1 deletion arch/arm/mach-lpc32xx/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ extern void __init lpc32xx_serial_init(void);
*/
extern void lpc32xx_get_uid(u32 devid[4]);

extern u32 lpc32xx_return_iram_size(void);
/*
* Pointers used for sizing and copying suspend function data
*/
Expand Down
15 changes: 0 additions & 15 deletions arch/arm/mach-lpc32xx/include/mach/board.h

This file was deleted.

17 changes: 8 additions & 9 deletions drivers/net/ethernet/nxp/lpc_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <linux/phy.h>
#include <linux/platform_device.h>
#include <linux/spinlock.h>
#include <linux/soc/nxp/lpc32xx-misc.h>

#include <mach/board.h>
#include <mach/hardware.h>
#include <mach/platform.h>

Expand Down Expand Up @@ -1311,16 +1311,15 @@ static int lpc_eth_drv_probe(struct platform_device *pdev)
/* Get size of DMA buffers/descriptors region */
pldat->dma_buff_size = (ENET_TX_DESC + ENET_RX_DESC) * (ENET_MAXF_SIZE +
sizeof(struct txrx_desc_t) + sizeof(struct rx_status_t));
pldat->dma_buff_base_v = 0;

if (use_iram_for_net(dev)) {
dma_handle = LPC32XX_IRAM_BASE;
if (pldat->dma_buff_size <= lpc32xx_return_iram_size())
pldat->dma_buff_base_v =
io_p2v(LPC32XX_IRAM_BASE);
else
if (pldat->dma_buff_size >
lpc32xx_return_iram(&pldat->dma_buff_base_v, &dma_handle)) {
pldat->dma_buff_base_v = NULL;
pldat->dma_buff_size = 0;
netdev_err(ndev,
"IRAM not big enough for net buffers, using SDRAM instead.\n");
}
}

if (pldat->dma_buff_base_v == 0) {
Expand Down Expand Up @@ -1409,7 +1408,7 @@ static int lpc_eth_drv_probe(struct platform_device *pdev)
unregister_netdev(ndev);
err_out_dma_unmap:
if (!use_iram_for_net(dev) ||
pldat->dma_buff_size > lpc32xx_return_iram_size())
pldat->dma_buff_size > lpc32xx_return_iram(NULL, NULL))
dma_free_coherent(dev, pldat->dma_buff_size,
pldat->dma_buff_base_v,
pldat->dma_buff_base_p);
Expand All @@ -1436,7 +1435,7 @@ static int lpc_eth_drv_remove(struct platform_device *pdev)
unregister_netdev(ndev);

if (!use_iram_for_net(&pldat->pdev->dev) ||
pldat->dma_buff_size > lpc32xx_return_iram_size())
pldat->dma_buff_size > lpc32xx_return_iram(NULL, NULL))
dma_free_coherent(&pldat->pdev->dev, pldat->dma_buff_size,
pldat->dma_buff_base_v,
pldat->dma_buff_base_p);
Expand Down
24 changes: 24 additions & 0 deletions include/linux/soc/nxp/lpc32xx-misc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Author: Kevin Wells <[email protected]>
*
* Copyright (C) 2010 NXP Semiconductors
*/

#ifndef __SOC_LPC32XX_MISC_H
#define __SOC_LPC32XX_MISC_H

#include <linux/types.h>

#ifdef CONFIG_ARCH_LPC32XX
extern u32 lpc32xx_return_iram(void __iomem **mapbase, dma_addr_t *dmaaddr);
#else
static inline u32 lpc32xx_return_iram(void __iomem **mapbase, dma_addr_t *dmaaddr)
{
*mapbase = NULL;
*dmaaddr = 0;
return 0;
}
#endif

#endif /* __SOC_LPC32XX_MISC_H */

0 comments on commit 9dc03ff

Please sign in to comment.