netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Configure Distributed Switch Architecture Via Device Tree
@ 2011-06-08 17:18 Barry G
  2011-06-10 15:14 ` Barry G
  0 siblings, 1 reply; 2+ messages in thread
From: Barry G @ 2011-06-08 17:18 UTC (permalink / raw)
  To: netdev

Hello,

We are working on bringing up a powerpc platform that has a few
Marvell switches on it.  We would like to make use of the DSA
stuff in the kernel.

It appears all the devices currently in the kernel that use DSA
are done via the platform_add_devices route.  I was hoping
to use the device tree since most of the powerpc stuff does.

My main two questions right now are:
How do I pull together the various components into the
dsa structures and how do I register that structure with
the dsa subsystem.

I added the following to my device tree:
   virtual-device {
      compatible = "simple-bus";
      dsa {
         compatible = "vendor,my-dsa-of";
         ethernet-handle = <&enet0>;
         mdio-handle = <&mdio0>;
      };
   };

And wrote the attached driver.  It loads at boot, so I
know the compatible stuff is working and all, but
I am a little lost as to the next steps.  Any help
would be much appreciated.

Thanks,

Barry


Here is my first hack at a drive:
#include <linux/of.h>
#include <linux/kernel.h>
#include <linux/of_platform.h>
#include <net/dsa.h>

static struct dsa_chip_data switches[] = {
   {
      .sw_addr = 0,
      .port_names = {
         "eth%d", //0
         "eth%d", //1
         "eth%d", //2
         "eth%d", //3
         "eth%d", //4
         "eth%d", //5
         "eth%d", //6
         "eth%d", //7
         "dsa",   //8
         "dsa",   //9
      },
      .rtable = (s8 []){-1, 8, 9},
   },
   {
      .sw_addr = 1,
      .port_names = {
         "eth%d", //0
         "eth%d", //1
         "eth%d", //2
         "eth%d", //3
         "eth%d", //4
         "eth%d", //5
         "eth%d", //6
         "eth%d", //7
         "dsa",   //8
         "dsa",   //9
         "cpu",   //10
      },
      .rtable = (s8 []){9, -1, 8},
   },
   {
      .sw_addr = 2,
      .port_names = {
         "eth%d", //0
         "eth%d", //1
         "eth%d", //2
         "eth%d", //3
         "eth%d", //4
         "eth%d", //5
         "eth%d", //6
         "eth%d", //7
         "dsa",   //8
         "dsa",   //9
         NULL,    //10
      },
      .rtable = (s8 []){8, 9, -1},
   },
};

static struct dsa_platform_data my_switch_data = {
   .nr_chips = 3,
   .chip = switches,
};

static int __devinit dsa_probe(struct platform_device *);
static int __devexit dsa_remove(struct platform_device *);

static const struct of_device_id dsa_match[] = {
   {
      .compatible = "vendor,my-dsa-of",
   },
   {}
};

static struct platform_driver dsa_driver = {
   .driver = {
      .name = "dsa-driver",
      .owner = THIS_MODULE,
      .of_match_table = dsa_match,
   },
   .probe = dsa_probe,
   .remove = dsa_remove,
};

static int __devinit dsa_probe(struct platform_device *pdev)
{
   /* Question 1:
      I need to hookup the mii_bus in the dsa_chip_data and
      the netdev in the dsa_platform_data to the various
      struct device *s.  I could get access to the device nodes
      like:

      ph = of_get_property(np, "mdio-handle", NULL);
      mdio = of_find_node_by_phandle(*ph);

      Now I have the mdio device_node, but what do I do with
      it?  How do I get the device *?

      */

   /* Question 2: Whats the entry point into the DSA stuff
      now that I have my snazzy chips setup in the
      my_switch_data?  Usually it is added as a stamp device
      ad added with platform_add_devices.  Do I need to edit
      the DSA stuff to work with OF devices? */


   dev_info(&pdev->dev, "Initializing OF Marvell DSA driver\n");

   return 0;
}

static int __devexit dsa_remove(struct platform_device *pdev)
{
   printk("dsa_remove\n");
   return 0;
}


static int __init dsa_driver_init(void)
{
   printk("dsa_drver_init\n");
   return platform_driver_register(&dsa_driver);
}

static void __exit dsa_driver_cleanup(void)
{
   printk("dsa_driver_cleanup\n");
   platform_driver_unregister(&dsa_driver);
}

module_init(dsa_driver_init);
module_exit(dsa_driver_cleanup);

MODULE_DESCRIPTION("Marvell DSA OF driver");
MODULE_AUTHOR("Barry G <mr.scada@gmail.com>");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:dsa-driver");

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Configure Distributed Switch Architecture Via Device Tree
  2011-06-08 17:18 Configure Distributed Switch Architecture Via Device Tree Barry G
@ 2011-06-10 15:14 ` Barry G
  0 siblings, 0 replies; 2+ messages in thread
From: Barry G @ 2011-06-10 15:14 UTC (permalink / raw)
  To: netdev

Just in case anyone else runs into this problem, this is what I ended up doing.
This code needs more error checking and isn't "right", plus it needs
to read the
chip mapping stuff from the OF, but it answers my original two questions :-)

#include <linux/of.h>
#include <linux/kernel.h>
#include <linux/of_platform.h>
#include <net/dsa.h>

static struct dsa_chip_data switches[] = {
   {
      .sw_addr = 0x9,
      .port_names = {
         "eth%d", //0
         "eth%d", //1
         "eth%d", //2
         "eth%d", //3
         "eth%d", //4
         "eth%d", //5
         "eth%d", //6
         "eth%d", //7
         NULL,   //8
         NULL,   //9
         "cpu",   //10
      },
      .rtable = (s8 []){-1, 9, 8},
   },
   {
      .sw_addr = 0xa,
      .port_names = {
         "eth%d", //0
         "eth%d", //1
         "eth%d", //2
         "eth%d", //3
         "eth%d", //4
         "eth%d", //5
         "eth%d", //6
         "eth%d", //7
         "dsa",   //8
         "dsa",   //9
      },
      .rtable = (s8 []){8, -1, 9},
   },
   {
      .sw_addr = 0x8,
      .port_names = {
         "eth%d", //0
         "eth%d", //1
         "eth%d", //2
         "eth%d", //3
         "eth%d", //4
         "eth%d", //5
         "eth%d", //6
         "eth%d", //7
         "dsa",   //8
         "dsa",   //9
         NULL,    //10
      },
      .rtable = (s8 []){9, 8, -1},
   },
};

static struct dsa_platform_data my_switch_data = {
   .nr_chips = 3,
   .chip = switches,
};

static int __devinit dsa_probe(struct platform_device *);
static int __devexit dsa_remove(struct platform_device *);

static const struct of_device_id dsa_match[] = {
   {
      .compatible = "vendor,my-dsa-of",
   },
   {}
};

static struct platform_driver dsa_driver = {
   .driver = {
      .name = "dsa-driver",
      .owner = THIS_MODULE,
      .of_match_table = dsa_match,
   },
   .probe = dsa_probe,
   .remove = dsa_remove,
};

static struct platform_device switchdriver = {
   .name = "dsa",
   .id = 0,
   .num_resources = 0,
   .dev.platform_data = &my_switch_data
};

static int __devinit dsa_probe(struct platform_device *pdev)
{
   struct device_node *np = pdev->dev.of_node;
   const phandle *mdio_ph;
   const phandle *ethernet_ph;

   struct device_node *mdio;
   struct device_node *ethernet;

   struct platform_device *mdio_pd;
   struct platform_device *ethernet_pd;

   int i;

   dev_info(&pdev->dev, "Initializing OF Marvell DSA driver\n");

   mdio_ph = of_get_property(np, "mdio-handle", NULL);
   ethernet_ph = of_get_property(np, "ethernet-handle", NULL);

   mdio = of_find_node_by_phandle(*mdio_ph);
   ethernet = of_find_node_by_phandle(*ethernet_ph);

   mdio_pd = of_find_device_by_node(mdio);
   ethernet_pd = of_find_device_by_node(ethernet);

   my_switch_data.netdev = &ethernet_pd->dev;

   for(i = 0; i < my_switch_data.nr_chips; i++)
   {
      switches[i].mii_bus = &mdio_pd->dev;
   }

   platform_device_register(&switchdriver);

   return 0;
}

static int __devexit dsa_remove(struct platform_device *pdev)
{
   printk("dsa_remove\n");
   return 0;
}


static int __init dsa_driver_init(void)
{
   printk("dsa_drver_init\n");
   return platform_driver_register(&dsa_driver);
}

static void __exit dsa_driver_cleanup(void)
{
   printk("dsa_driver_cleanup\n");
   platform_driver_unregister(&dsa_driver);
}

module_init(dsa_driver_init);
module_exit(dsa_driver_cleanup);

MODULE_DESCRIPTION("Marvell DSA OF driver");
MODULE_AUTHOR("Barry G <mr.scada@gmail.com>");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:dsa-driver");

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-06-10 15:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-08 17:18 Configure Distributed Switch Architecture Via Device Tree Barry G
2011-06-10 15:14 ` Barry G

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).