netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kaisrlik <kaisrja1@fel.cvut.cz>
To: kaisrja1@fel.cvut.cz
Cc: sojkam1@fel.cvut.cz, tkonecny@retia.cz, netdev@vger.kernel.org,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jan Kaisrlik <ja.kaisrlik@gmail.com>
Subject: [RFC PATCH 2/3] net/dsa: Allow probing dsa from usbnet
Date: Tue, 21 Apr 2015 13:26:30 +0000	[thread overview]
Message-ID: <1429622791-7195-3-git-send-email-kaisrja1@fel.cvut.cz> (raw)
In-Reply-To: <1429622791-7195-1-git-send-email-kaisrja1@fel.cvut.cz>

From: Jan Kaisrlik <ja.kaisrlik@gmail.com>

This patch adds a function which helps to connect net device
to DSA switch based on mii_bus and netdev.

The switch parameters of the switch are configured in fill_platform_data().
Currently, the configuration data is hardcoded in the code.
I don't know how to pass the configuration data from
user space.

It is not possible to determine the configuration data in plug-and-play
manner in mv88e6060 driver.

I have thought about two possibilities how to do that. First one is to
load data from the device tree, because loading from device tree is
already implemented in dsa_of_probe().

Second possibility is to send configuration of switch via sysfs.

In my opinion, the second one is better because I have already used
sysfs to bind USB to DSA in patch 3/3.

---
 include/net/dsa.h |   3 ++
 net/dsa/dsa.c     | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index ed3c34b..df7b748 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -290,4 +290,7 @@ static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
 {
 	return dst->rcv != NULL;
 }
+
+int dsa_probe_mii(struct mii_bus *bus, struct net_device * dev);
+
 #endif
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index e2c0703..cb5d9c2 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -798,6 +798,127 @@ out:
 	return ret;
 }
 
+static int fill_platform_data(struct dsa_platform_data *pd,
+		struct mii_bus *bus, struct device * parent){
+	struct dsa_chip_data * cd;
+	int i;
+
+	static struct device_node dn = {
+		.name = "name",
+		.type = "type",
+		.phandle = 0,
+		.full_name = "fullname",
+		.fwnode =  {1},
+		.properties = NULL,
+		.deadprops = NULL,
+		.parent = NULL,
+		.child = NULL,
+		.sibling = NULL,
+		.kobj = {NULL},
+		._flags = 0,
+		.data = NULL
+	};
+	static struct device_node dnc = {
+		.name = "name",
+		.type = "type",
+		.phandle = 0,
+		.full_name = "fullname",
+		.fwnode =  {1},
+		.properties = NULL,
+		.deadprops = NULL,
+		.parent = &dn,
+		.child = NULL,
+		.sibling = NULL,
+		.kobj = {NULL},
+		._flags = 0,
+		.data = NULL
+	};
+	static char *port_names[12] = {"0", "1", "2", "3", "4",
+		"5", "6", "7", "8", "9", "10", "11"};
+
+	pd->nr_chips = 1;
+	pd->netdev = parent;
+
+	cd = kzalloc(sizeof(*cd), GFP_KERNEL);
+	if (cd == NULL)
+		return -ENOMEM;
+
+	pd->chip = cd;
+
+	cd->host_dev = parent;
+	cd->sw_addr = 0x10;
+	cd->eeprom_len = 256;
+	cd->of_node = &dn;
+	cd->rtable = 0;
+
+//	cd->of_node = kzalloc(sizeof(*cd->of_node), GFP_KERNEL);
+//	if(cd->of_node == NULL)
+//		goto free;
+
+	for (i = 0; i < DSA_MAX_PORTS; i++) {
+		cd->port_names[i] = port_names[i];
+		cd->port_dn[i] = &dnc;
+	}
+
+	return 0;
+
+//free:
+//	kfree(cd);
+//	return -ENOMEM;
+}
+
+int dsa_probe_mii(struct mii_bus *bus, struct net_device * dev)
+{
+	struct dsa_platform_data *pd;
+	struct dsa_switch_tree *dst;
+	int ret;
+
+	pr_notice_once("Distributed Switch Architecture driver version %s\n",
+		       dsa_driver_version);
+
+	if (dev == NULL || bus == NULL)
+		return -EINVAL;
+
+	pd = kzalloc(sizeof(*pd), GFP_KERNEL);
+	if (pd == NULL) {
+		ret = -ENOMEM;
+		goto freep;
+	}
+
+	ret = fill_platform_data(pd, bus, bus->parent); //TODO fix it!
+	if (ret)
+		goto freep;
+
+	if (dev->dsa_ptr != NULL) {
+		dev_put(dev);
+		ret = -EEXIST;
+		goto freep;
+	}
+
+	dst = kzalloc(sizeof(*dst), GFP_KERNEL);
+	if (dst == NULL) {
+		dev_put(dev);
+		ret = -ENOMEM;
+		goto freed;
+	}
+
+	dev_set_drvdata(bus->parent, dst);
+
+	dst->pd = pd;
+	dst->master_netdev = dev;
+
+	dsa_probe_common(dst, bus->parent);
+
+	return 0;
+
+freed:
+	kfree(dst);
+freep:
+	kfree(pd);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(dsa_probe_mii);
+
 static int dsa_remove(struct platform_device *pdev)
 {
 	struct dsa_switch_tree *dst = platform_get_drvdata(pdev);
-- 
2.1.3

  parent reply	other threads:[~2015-04-21 13:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-21 13:26 [RFC PATCH 0/3] Enable connecting DSA-based switch to the USB RMII interface Jan Kaisrlik
2015-04-21 12:47 ` Andrew Lunn
2015-04-21 17:18   ` Florian Fainelli
2015-04-21 17:30     ` Andrew Lunn
2015-04-21 17:46       ` Florian Fainelli
2015-04-21 17:39     ` Andrew Lunn
2015-04-21 17:51       ` Florian Fainelli
2015-04-22 16:14         ` Jan Kaisrlik
2015-04-22 16:39           ` Andrew Lunn
2015-04-21 13:26 ` [RFC PATCH 1/3] net/dsa: Refactor dsa_probe() Jan Kaisrlik
2015-04-21 16:58   ` Florian Fainelli
2015-04-21 13:26 ` Jan Kaisrlik [this message]
2015-04-22  7:15   ` [RFC PATCH 2/3] net/dsa: Allow probing dsa from usbnet rajeev kumar
2015-04-21 13:26 ` [RFC PATCH 3/3] driver/net/usb: Add support for DSA to ax88772b Jan Kaisrlik
2015-04-21 13:10   ` Bjørn Mork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1429622791-7195-3-git-send-email-kaisrja1@fel.cvut.cz \
    --to=kaisrja1@fel.cvut.cz \
    --cc=ja.kaisrlik@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sojkam1@fel.cvut.cz \
    --cc=tkonecny@retia.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).