Skip to content

Commit c6e26ea

Browse files
madalinbucurdavem330
authored andcommitted
dpaa_eth: change device used
Change device used for DMA mapping to the MAC device that is an of_device, with proper DMA ops. Using this device for the netdevice should also address the issue with DSA scenarios that need the netdevice to be backed by an of_device. Signed-off-by: Madalin Bucur <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3c38ec6 commit c6e26ea

File tree

3 files changed

+27
-53
lines changed

3 files changed

+27
-53
lines changed

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -385,34 +385,19 @@ static int dpaa_setup_tc(struct net_device *net_dev, enum tc_setup_type type,
385385

386386
static struct mac_device *dpaa_mac_dev_get(struct platform_device *pdev)
387387
{
388-
struct platform_device *of_dev;
389388
struct dpaa_eth_data *eth_data;
390-
struct device *dpaa_dev, *dev;
391-
struct device_node *mac_node;
389+
struct device *dpaa_dev;
392390
struct mac_device *mac_dev;
393391

394392
dpaa_dev = &pdev->dev;
395393
eth_data = dpaa_dev->platform_data;
396-
if (!eth_data)
394+
if (!eth_data) {
395+
dev_err(dpaa_dev, "eth_data missing\n");
397396
return ERR_PTR(-ENODEV);
398-
399-
mac_node = eth_data->mac_node;
400-
401-
of_dev = of_find_device_by_node(mac_node);
402-
if (!of_dev) {
403-
dev_err(dpaa_dev, "of_find_device_by_node(%pOF) failed\n",
404-
mac_node);
405-
of_node_put(mac_node);
406-
return ERR_PTR(-EINVAL);
407397
}
408-
of_node_put(mac_node);
409-
410-
dev = &of_dev->dev;
411-
412-
mac_dev = dev_get_drvdata(dev);
398+
mac_dev = eth_data->mac_dev;
413399
if (!mac_dev) {
414-
dev_err(dpaa_dev, "dev_get_drvdata(%s) failed\n",
415-
dev_name(dev));
400+
dev_err(dpaa_dev, "mac_dev missing\n");
416401
return ERR_PTR(-EINVAL);
417402
}
418403

@@ -2696,7 +2681,13 @@ static int dpaa_eth_probe(struct platform_device *pdev)
26962681
int err = 0, i, channel;
26972682
struct device *dev;
26982683

2699-
dev = &pdev->dev;
2684+
/* device used for DMA mapping */
2685+
dev = pdev->dev.parent;
2686+
err = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(40));
2687+
if (err) {
2688+
dev_err(dev, "dma_coerce_mask_and_coherent() failed\n");
2689+
return err;
2690+
}
27002691

27012692
/* Allocate this early, so we can store relevant information in
27022693
* the private area
@@ -2738,14 +2729,6 @@ static int dpaa_eth_probe(struct platform_device *pdev)
27382729
priv->buf_layout[RX].priv_data_size = DPAA_RX_PRIV_DATA_SIZE; /* Rx */
27392730
priv->buf_layout[TX].priv_data_size = DPAA_TX_PRIV_DATA_SIZE; /* Tx */
27402731

2741-
/* device used for DMA mapping */
2742-
set_dma_ops(dev, get_dma_ops(&pdev->dev));
2743-
err = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(40));
2744-
if (err) {
2745-
dev_err(dev, "dma_coerce_mask_and_coherent() failed\n");
2746-
goto dev_mask_failed;
2747-
}
2748-
27492732
/* bp init */
27502733
for (i = 0; i < DPAA_BPS_NUM; i++) {
27512734
int err;
@@ -2879,7 +2862,6 @@ static int dpaa_eth_probe(struct platform_device *pdev)
28792862
dpaa_bps_free(priv);
28802863
bp_create_failed:
28812864
fq_probe_failed:
2882-
dev_mask_failed:
28832865
mac_probe_failed:
28842866
dev_set_drvdata(dev, NULL);
28852867
free_netdev(net_dev);

drivers/net/ethernet/freescale/fman/mac.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,7 @@ static const u16 phy2speed[] = {
542542
};
543543

544544
static struct platform_device *dpaa_eth_add_device(int fman_id,
545-
struct mac_device *mac_dev,
546-
struct device_node *node)
545+
struct mac_device *mac_dev)
547546
{
548547
struct platform_device *pdev;
549548
struct dpaa_eth_data data;
@@ -556,10 +555,8 @@ static struct platform_device *dpaa_eth_add_device(int fman_id,
556555
data.mac_dev = mac_dev;
557556
data.mac_hw_id = priv->cell_index;
558557
data.fman_hw_id = fman_id;
559-
data.mac_node = node;
560558

561559
mutex_lock(&eth_lock);
562-
563560
pdev = platform_device_alloc("dpaa-ethernet", dpaa_eth_dev_cnt);
564561
if (!pdev) {
565562
ret = -ENOMEM;
@@ -648,9 +645,6 @@ static int mac_probe(struct platform_device *_of_dev)
648645
goto _return;
649646
}
650647

651-
/* Register mac_dev */
652-
dev_set_drvdata(dev, mac_dev);
653-
654648
INIT_LIST_HEAD(&priv->mc_addr_list);
655649

656650
/* Get the FM node */
@@ -659,7 +653,7 @@ static int mac_probe(struct platform_device *_of_dev)
659653
dev_err(dev, "of_get_parent(%pOF) failed\n",
660654
mac_node);
661655
err = -EINVAL;
662-
goto _return_dev_set_drvdata;
656+
goto _return_of_get_parent;
663657
}
664658

665659
of_dev = of_find_device_by_node(dev_node);
@@ -693,7 +687,7 @@ static int mac_probe(struct platform_device *_of_dev)
693687
if (err < 0) {
694688
dev_err(dev, "of_address_to_resource(%pOF) = %d\n",
695689
mac_node, err);
696-
goto _return_dev_set_drvdata;
690+
goto _return_of_get_parent;
697691
}
698692

699693
mac_dev->res = __devm_request_region(dev,
@@ -703,15 +697,15 @@ static int mac_probe(struct platform_device *_of_dev)
703697
if (!mac_dev->res) {
704698
dev_err(dev, "__devm_request_mem_region(mac) failed\n");
705699
err = -EBUSY;
706-
goto _return_dev_set_drvdata;
700+
goto _return_of_get_parent;
707701
}
708702

709703
priv->vaddr = devm_ioremap(dev, mac_dev->res->start,
710704
mac_dev->res->end + 1 - mac_dev->res->start);
711705
if (!priv->vaddr) {
712706
dev_err(dev, "devm_ioremap() failed\n");
713707
err = -EIO;
714-
goto _return_dev_set_drvdata;
708+
goto _return_of_get_parent;
715709
}
716710

717711
if (!of_device_is_available(mac_node)) {
@@ -728,7 +722,7 @@ static int mac_probe(struct platform_device *_of_dev)
728722
if (err) {
729723
dev_err(dev, "failed to read cell-index for %pOF\n", mac_node);
730724
err = -EINVAL;
731-
goto _return_dev_set_drvdata;
725+
goto _return_of_get_parent;
732726
}
733727
priv->cell_index = (u8)val;
734728

@@ -737,7 +731,7 @@ static int mac_probe(struct platform_device *_of_dev)
737731
if (!mac_addr) {
738732
dev_err(dev, "of_get_mac_address(%pOF) failed\n", mac_node);
739733
err = -EINVAL;
740-
goto _return_dev_set_drvdata;
734+
goto _return_of_get_parent;
741735
}
742736
memcpy(mac_dev->addr, mac_addr, sizeof(mac_dev->addr));
743737

@@ -747,14 +741,14 @@ static int mac_probe(struct platform_device *_of_dev)
747741
dev_err(dev, "of_count_phandle_with_args(%pOF, fsl,fman-ports) failed\n",
748742
mac_node);
749743
err = nph;
750-
goto _return_dev_set_drvdata;
744+
goto _return_of_get_parent;
751745
}
752746

753747
if (nph != ARRAY_SIZE(mac_dev->port)) {
754748
dev_err(dev, "Not supported number of fman-ports handles of mac node %pOF from device tree\n",
755749
mac_node);
756750
err = -EINVAL;
757-
goto _return_dev_set_drvdata;
751+
goto _return_of_get_parent;
758752
}
759753

760754
for (i = 0; i < ARRAY_SIZE(mac_dev->port); i++) {
@@ -818,20 +812,20 @@ static int mac_probe(struct platform_device *_of_dev)
818812

819813
err = of_phy_register_fixed_link(mac_node);
820814
if (err)
821-
goto _return_dev_set_drvdata;
815+
goto _return_of_get_parent;
822816

823817
priv->fixed_link = kzalloc(sizeof(*priv->fixed_link),
824818
GFP_KERNEL);
825819
if (!priv->fixed_link) {
826820
err = -ENOMEM;
827-
goto _return_dev_set_drvdata;
821+
goto _return_of_get_parent;
828822
}
829823

830824
mac_dev->phy_node = of_node_get(mac_node);
831825
phy = of_phy_find_device(mac_dev->phy_node);
832826
if (!phy) {
833827
err = -EINVAL;
834-
goto _return_dev_set_drvdata;
828+
goto _return_of_get_parent;
835829
}
836830

837831
priv->fixed_link->link = phy->link;
@@ -847,7 +841,7 @@ static int mac_probe(struct platform_device *_of_dev)
847841
if (err < 0) {
848842
dev_err(dev, "mac_dev->init() = %d\n", err);
849843
of_node_put(mac_dev->phy_node);
850-
goto _return_dev_set_drvdata;
844+
goto _return_of_get_parent;
851845
}
852846

853847
/* pause frame autonegotiation enabled */
@@ -868,7 +862,7 @@ static int mac_probe(struct platform_device *_of_dev)
868862
mac_dev->addr[0], mac_dev->addr[1], mac_dev->addr[2],
869863
mac_dev->addr[3], mac_dev->addr[4], mac_dev->addr[5]);
870864

871-
priv->eth_dev = dpaa_eth_add_device(fman_id, mac_dev, mac_node);
865+
priv->eth_dev = dpaa_eth_add_device(fman_id, mac_dev);
872866
if (IS_ERR(priv->eth_dev)) {
873867
dev_err(dev, "failed to add Ethernet platform device for MAC %d\n",
874868
priv->cell_index);
@@ -879,9 +873,8 @@ static int mac_probe(struct platform_device *_of_dev)
879873

880874
_return_of_node_put:
881875
of_node_put(dev_node);
882-
_return_dev_set_drvdata:
876+
_return_of_get_parent:
883877
kfree(priv->fixed_link);
884-
dev_set_drvdata(dev, NULL);
885878
_return:
886879
return err;
887880
}

drivers/net/ethernet/freescale/fman/mac.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ struct mac_device {
8383
};
8484

8585
struct dpaa_eth_data {
86-
struct device_node *mac_node;
8786
struct mac_device *mac_dev;
8887
int mac_hw_id;
8988
int fman_hw_id;

0 commit comments

Comments
 (0)