Skip to content

Commit 87ab207

Browse files
a-willdavem330
authored andcommitted
net: nixge: Separate ctrl and dma resources
The DMA engine is a separate entity altogether, and this allows the DMA controller's address to float elsewhere in the FPGA's map. Signed-off-by: Alex Williams <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5ea25b1 commit 87ab207

File tree

1 file changed

+58
-16
lines changed

1 file changed

+58
-16
lines changed

drivers/net/ethernet/ni/nixge.c

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
#define NIXGE_MAX_JUMBO_FRAME_SIZE \
106106
(NIXGE_JUMBO_MTU + NIXGE_HDR_SIZE + NIXGE_TRL_SIZE)
107107

108+
enum nixge_version {
109+
NIXGE_V2,
110+
NIXGE_V3,
111+
NIXGE_VERSION_COUNT
112+
};
113+
108114
struct nixge_hw_dma_bd {
109115
u32 next_lo;
110116
u32 next_hi;
@@ -1225,11 +1231,59 @@ static void *nixge_get_nvmem_address(struct device *dev)
12251231
return mac;
12261232
}
12271233

1234+
/* Match table for of_platform binding */
1235+
static const struct of_device_id nixge_dt_ids[] = {
1236+
{ .compatible = "ni,xge-enet-2.00", .data = (void *)NIXGE_V2 },
1237+
{ .compatible = "ni,xge-enet-3.00", .data = (void *)NIXGE_V3 },
1238+
{},
1239+
};
1240+
MODULE_DEVICE_TABLE(of, nixge_dt_ids);
1241+
1242+
static int nixge_of_get_resources(struct platform_device *pdev)
1243+
{
1244+
const struct of_device_id *of_id;
1245+
enum nixge_version version;
1246+
struct resource *ctrlres;
1247+
struct resource *dmares;
1248+
struct net_device *ndev;
1249+
struct nixge_priv *priv;
1250+
1251+
ndev = platform_get_drvdata(pdev);
1252+
priv = netdev_priv(ndev);
1253+
of_id = of_match_node(nixge_dt_ids, pdev->dev.of_node);
1254+
if (!of_id)
1255+
return -ENODEV;
1256+
1257+
version = (enum nixge_version)of_id->data;
1258+
if (version <= NIXGE_V2)
1259+
dmares = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1260+
else
1261+
dmares = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1262+
"dma");
1263+
1264+
priv->dma_regs = devm_ioremap_resource(&pdev->dev, dmares);
1265+
if (IS_ERR(priv->dma_regs)) {
1266+
netdev_err(ndev, "failed to map dma regs\n");
1267+
return PTR_ERR(priv->dma_regs);
1268+
}
1269+
if (version <= NIXGE_V2) {
1270+
priv->ctrl_regs = priv->dma_regs + NIXGE_REG_CTRL_OFFSET;
1271+
} else {
1272+
ctrlres = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1273+
"ctrl");
1274+
priv->ctrl_regs = devm_ioremap_resource(&pdev->dev, ctrlres);
1275+
}
1276+
if (IS_ERR(priv->ctrl_regs)) {
1277+
netdev_err(ndev, "failed to map ctrl regs\n");
1278+
return PTR_ERR(priv->ctrl_regs);
1279+
}
1280+
return 0;
1281+
}
1282+
12281283
static int nixge_probe(struct platform_device *pdev)
12291284
{
12301285
struct nixge_priv *priv;
12311286
struct net_device *ndev;
1232-
struct resource *dmares;
12331287
const u8 *mac_addr;
12341288
int err;
12351289

@@ -1261,14 +1315,9 @@ static int nixge_probe(struct platform_device *pdev)
12611315
priv->dev = &pdev->dev;
12621316

12631317
netif_napi_add(ndev, &priv->napi, nixge_poll, NAPI_POLL_WEIGHT);
1264-
1265-
dmares = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1266-
priv->dma_regs = devm_ioremap_resource(&pdev->dev, dmares);
1267-
if (IS_ERR(priv->dma_regs)) {
1268-
netdev_err(ndev, "failed to map dma regs\n");
1269-
return PTR_ERR(priv->dma_regs);
1270-
}
1271-
priv->ctrl_regs = priv->dma_regs + NIXGE_REG_CTRL_OFFSET;
1318+
err = nixge_of_get_resources(pdev);
1319+
if (err)
1320+
return err;
12721321
__nixge_hw_set_mac_address(ndev);
12731322

12741323
priv->tx_irq = platform_get_irq_byname(pdev, "tx");
@@ -1337,13 +1386,6 @@ static int nixge_remove(struct platform_device *pdev)
13371386
return 0;
13381387
}
13391388

1340-
/* Match table for of_platform binding */
1341-
static const struct of_device_id nixge_dt_ids[] = {
1342-
{ .compatible = "ni,xge-enet-2.00", },
1343-
{},
1344-
};
1345-
MODULE_DEVICE_TABLE(of, nixge_dt_ids);
1346-
13471389
static struct platform_driver nixge_driver = {
13481390
.probe = nixge_probe,
13491391
.remove = nixge_remove,

0 commit comments

Comments
 (0)