Linux Audio

Check our new training course

Loading...
v6.8
  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 *                <benh@kernel.crashing.org>
  9 *
 10 * Based on the arch/ppc version of the driver:
 11 *
 12 * Copyright 2004 MontaVista Software, Inc.
 13 * Matt Porter <mporter@kernel.crashing.org>
 14 *
 15 * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net>
 
 
 
 
 
 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
 25int 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
 37void 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
 46void 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
 67int tah_get_regs_len(struct platform_device *ofdev)
 68{
 69	return sizeof(struct emac_ethtool_regs_subhdr) +
 70		sizeof(struct tah_regs);
 71}
 72
 73void *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
 88static int tah_probe(struct platform_device *ofdev)
 89{
 90	struct device_node *np = ofdev->dev.of_node;
 91	struct tah_instance *dev;
 92	struct resource regs;
 93	int rc;
 94
 95	rc = -ENOMEM;
 96	dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL);
 97	if (dev == NULL)
 98		goto err_gone;
 99
100	mutex_init(&dev->lock);
101	dev->ofdev = ofdev;
102
103	rc = -ENXIO;
104	if (of_address_to_resource(np, 0, &regs)) {
105		printk(KERN_ERR "%pOF: Can't get registers address\n", np);
106		goto err_free;
107	}
108
109	rc = -ENOMEM;
110	dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
111					       sizeof(struct tah_regs));
112	if (dev->base == NULL) {
113		printk(KERN_ERR "%pOF: Can't map device registers!\n", np);
114		goto err_free;
115	}
116
117	platform_set_drvdata(ofdev, dev);
118
119	/* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
120	tah_reset(ofdev);
121
122	printk(KERN_INFO "TAH %pOF initialized\n", ofdev->dev.of_node);
123	wmb();
124
125	return 0;
126
127 err_free:
128	kfree(dev);
129 err_gone:
130	return rc;
131}
132
133static void tah_remove(struct platform_device *ofdev)
134{
135	struct tah_instance *dev = platform_get_drvdata(ofdev);
136
137	WARN_ON(dev->users != 0);
138
139	iounmap(dev->base);
140	kfree(dev);
 
 
141}
142
143static const struct of_device_id tah_match[] =
144{
145	{
146		.compatible	= "ibm,tah",
147	},
148	/* For backward compat with old DT */
149	{
150		.type		= "tah",
151	},
152	{},
153};
154
155static struct platform_driver tah_driver = {
156	.driver = {
157		.name = "emac-tah",
158		.of_match_table = tah_match,
159	},
160	.probe = tah_probe,
161	.remove_new = tah_remove,
162};
163
164int __init tah_init(void)
165{
166	return platform_driver_register(&tah_driver);
167}
168
169void tah_exit(void)
170{
171	platform_driver_unregister(&tah_driver);
172}
v4.17
 
  1/*
  2 * drivers/net/ethernet/ibm/emac/tah.c
  3 *
  4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
  5 *
  6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
  7 *                <benh@kernel.crashing.org>
  8 *
  9 * Based on the arch/ppc version of the driver:
 10 *
 11 * Copyright 2004 MontaVista Software, Inc.
 12 * Matt Porter <mporter@kernel.crashing.org>
 13 *
 14 * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net>
 15 *
 16 * This program is free software; you can redistribute  it and/or modify it
 17 * under  the terms of  the GNU General  Public License as published by the
 18 * Free Software Foundation;  either version 2 of the  License, or (at your
 19 * option) any later version.
 20 */
 
 21#include <linux/of_address.h>
 
 22#include <asm/io.h>
 23
 24#include "emac.h"
 25#include "core.h"
 26
 27int tah_attach(struct platform_device *ofdev, int channel)
 28{
 29	struct tah_instance *dev = platform_get_drvdata(ofdev);
 30
 31	mutex_lock(&dev->lock);
 32	/* Reset has been done at probe() time... nothing else to do for now */
 33	++dev->users;
 34	mutex_unlock(&dev->lock);
 35
 36	return 0;
 37}
 38
 39void tah_detach(struct platform_device *ofdev, int channel)
 40{
 41	struct tah_instance *dev = platform_get_drvdata(ofdev);
 42
 43	mutex_lock(&dev->lock);
 44	--dev->users;
 45	mutex_unlock(&dev->lock);
 46}
 47
 48void tah_reset(struct platform_device *ofdev)
 49{
 50	struct tah_instance *dev = platform_get_drvdata(ofdev);
 51	struct tah_regs __iomem *p = dev->base;
 52	int n;
 53
 54	/* Reset TAH */
 55	out_be32(&p->mr, TAH_MR_SR);
 56	n = 100;
 57	while ((in_be32(&p->mr) & TAH_MR_SR) && n)
 58		--n;
 59
 60	if (unlikely(!n))
 61		printk(KERN_ERR "%pOF: reset timeout\n", ofdev->dev.of_node);
 62
 63	/* 10KB TAH TX FIFO accommodates the max MTU of 9000 */
 64	out_be32(&p->mr,
 65		 TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
 66		 TAH_MR_DIG);
 67}
 68
 69int tah_get_regs_len(struct platform_device *ofdev)
 70{
 71	return sizeof(struct emac_ethtool_regs_subhdr) +
 72		sizeof(struct tah_regs);
 73}
 74
 75void *tah_dump_regs(struct platform_device *ofdev, void *buf)
 76{
 77	struct tah_instance *dev = platform_get_drvdata(ofdev);
 78	struct emac_ethtool_regs_subhdr *hdr = buf;
 79	struct tah_regs *regs = (struct tah_regs *)(hdr + 1);
 80
 81	hdr->version = 0;
 82	hdr->index = 0; /* for now, are there chips with more than one
 83			 * zmii ? if yes, then we'll add a cell_index
 84			 * like we do for emac
 85			 */
 86	memcpy_fromio(regs, dev->base, sizeof(struct tah_regs));
 87	return regs + 1;
 88}
 89
 90static int tah_probe(struct platform_device *ofdev)
 91{
 92	struct device_node *np = ofdev->dev.of_node;
 93	struct tah_instance *dev;
 94	struct resource regs;
 95	int rc;
 96
 97	rc = -ENOMEM;
 98	dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL);
 99	if (dev == NULL)
100		goto err_gone;
101
102	mutex_init(&dev->lock);
103	dev->ofdev = ofdev;
104
105	rc = -ENXIO;
106	if (of_address_to_resource(np, 0, &regs)) {
107		printk(KERN_ERR "%pOF: Can't get registers address\n", np);
108		goto err_free;
109	}
110
111	rc = -ENOMEM;
112	dev->base = (struct tah_regs __iomem *)ioremap(regs.start,
113					       sizeof(struct tah_regs));
114	if (dev->base == NULL) {
115		printk(KERN_ERR "%pOF: Can't map device registers!\n", np);
116		goto err_free;
117	}
118
119	platform_set_drvdata(ofdev, dev);
120
121	/* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
122	tah_reset(ofdev);
123
124	printk(KERN_INFO "TAH %pOF initialized\n", ofdev->dev.of_node);
125	wmb();
126
127	return 0;
128
129 err_free:
130	kfree(dev);
131 err_gone:
132	return rc;
133}
134
135static int tah_remove(struct platform_device *ofdev)
136{
137	struct tah_instance *dev = platform_get_drvdata(ofdev);
138
139	WARN_ON(dev->users != 0);
140
141	iounmap(dev->base);
142	kfree(dev);
143
144	return 0;
145}
146
147static const struct of_device_id tah_match[] =
148{
149	{
150		.compatible	= "ibm,tah",
151	},
152	/* For backward compat with old DT */
153	{
154		.type		= "tah",
155	},
156	{},
157};
158
159static struct platform_driver tah_driver = {
160	.driver = {
161		.name = "emac-tah",
162		.of_match_table = tah_match,
163	},
164	.probe = tah_probe,
165	.remove = tah_remove,
166};
167
168int __init tah_init(void)
169{
170	return platform_driver_register(&tah_driver);
171}
172
173void tah_exit(void)
174{
175	platform_driver_unregister(&tah_driver);
176}