]> Git Repo - linux.git/blob - drivers/net/ethernet/ibm/emac/tah.c
Linux 6.14-rc3
[linux.git] / drivers / net / ethernet / ibm / emac / tah.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * drivers/net/ethernet/ibm/emac/tah.c
4  *
5  * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
6  *
7  * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
8  *                <[email protected]>
9  *
10  * Based on the arch/ppc version of the driver:
11  *
12  * Copyright 2004 MontaVista Software, Inc.
13  * Matt Porter <[email protected]>
14  *
15  * Copyright (c) 2005 Eugene Surovegin <[email protected]>
16  */
17 #include <linux/mod_devicetable.h>
18 #include <linux/of_address.h>
19 #include <linux/platform_device.h>
20 #include <asm/io.h>
21
22 #include "emac.h"
23 #include "core.h"
24
25 int tah_attach(struct platform_device *ofdev, int channel)
26 {
27         struct tah_instance *dev = platform_get_drvdata(ofdev);
28
29         mutex_lock(&dev->lock);
30         /* Reset has been done at probe() time... nothing else to do for now */
31         ++dev->users;
32         mutex_unlock(&dev->lock);
33
34         return 0;
35 }
36
37 void tah_detach(struct platform_device *ofdev, int channel)
38 {
39         struct tah_instance *dev = platform_get_drvdata(ofdev);
40
41         mutex_lock(&dev->lock);
42         --dev->users;
43         mutex_unlock(&dev->lock);
44 }
45
46 void tah_reset(struct platform_device *ofdev)
47 {
48         struct tah_instance *dev = platform_get_drvdata(ofdev);
49         struct tah_regs __iomem *p = dev->base;
50         int n;
51
52         /* Reset TAH */
53         out_be32(&p->mr, TAH_MR_SR);
54         n = 100;
55         while ((in_be32(&p->mr) & TAH_MR_SR) && n)
56                 --n;
57
58         if (unlikely(!n))
59                 printk(KERN_ERR "%pOF: reset timeout\n", ofdev->dev.of_node);
60
61         /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
62         out_be32(&p->mr,
63                  TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
64                  TAH_MR_DIG);
65 }
66
67 int tah_get_regs_len(struct platform_device *ofdev)
68 {
69         return sizeof(struct emac_ethtool_regs_subhdr) +
70                 sizeof(struct tah_regs);
71 }
72
73 void *tah_dump_regs(struct platform_device *ofdev, void *buf)
74 {
75         struct tah_instance *dev = platform_get_drvdata(ofdev);
76         struct emac_ethtool_regs_subhdr *hdr = buf;
77         struct tah_regs *regs = (struct tah_regs *)(hdr + 1);
78
79         hdr->version = 0;
80         hdr->index = 0; /* for now, are there chips with more than one
81                          * zmii ? if yes, then we'll add a cell_index
82                          * like we do for emac
83                          */
84         memcpy_fromio(regs, dev->base, sizeof(struct tah_regs));
85         return regs + 1;
86 }
87
88 static int tah_probe(struct platform_device *ofdev)
89 {
90         struct tah_instance *dev;
91         int err;
92
93         dev = devm_kzalloc(&ofdev->dev, sizeof(struct tah_instance),
94                            GFP_KERNEL);
95         if (!dev)
96                 return -ENOMEM;
97
98         err = devm_mutex_init(&ofdev->dev, &dev->lock);
99         if (err)
100                 return err;
101
102         dev->ofdev = ofdev;
103
104         dev->base = devm_platform_ioremap_resource(ofdev, 0);
105         if (IS_ERR(dev->base)) {
106                 dev_err(&ofdev->dev, "can't map device registers");
107                 return PTR_ERR(dev->base);
108         }
109
110         platform_set_drvdata(ofdev, dev);
111
112         /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
113         tah_reset(ofdev);
114
115         printk(KERN_INFO "TAH %pOF initialized\n", ofdev->dev.of_node);
116         wmb();
117
118         return 0;
119 }
120
121 static const struct of_device_id tah_match[] =
122 {
123         {
124                 .compatible     = "ibm,tah",
125         },
126         /* For backward compat with old DT */
127         {
128                 .type           = "tah",
129         },
130         {},
131 };
132
133 static struct platform_driver tah_driver = {
134         .driver = {
135                 .name = "emac-tah",
136                 .of_match_table = tah_match,
137         },
138         .probe = tah_probe,
139 };
140
141 int __init tah_init(void)
142 {
143         return platform_driver_register(&tah_driver);
144 }
145
146 void tah_exit(void)
147 {
148         platform_driver_unregister(&tah_driver);
149 }
This page took 0.039481 seconds and 4 git commands to generate.