RE: [RFC PATCH ethtool v2 00/23] ethtool netlink interface (userspace side) (WiP)

2018-11-08 Thread Woojung.Huh
Hi Michal,

> Based on the subject you quoted, you tried to apply the patch series for
> ethtool (userspace utility). Kernel patch series was sent shortly before
> this one with subject "[RFC PATCH net-next v2 00/17] ethtool netlink
> interface (WiP)":
Oh.. You are right. I picked up wrong email header. :(

> But if you want to try it, I would rather suggest updated version from
> 
>   https://github.com/mkubecek/ethnl
> 
> It has kernel series based on current net-next (this morning) and
> ethtool series based on v4.19.
Thanks for this link. It would be clean tree.

> I would like to send a v3 to the list soon but in the last few weeks
> I was quite busy with higher priority work.
Great news. Will wait new series.

Regards,
Woojung


RE: TJA1100 100Base-T1 PHY features via ethtool?

2018-08-16 Thread Woojung.Huh
Hi Florian & Michael,

> > ethtool is being converted to netlink, and that will be a much more
> > flexible interface to work with since it is basically easily extensible
> > (unlike the current ethtool + ioctl approach).
> 
> Yes, netlink sounds absolutely more useful here.
Is ethtool + netlink expected to be merged in net-next soon?
Couldn't find anything on the web except some experimental information.

Thanks.
Woojung


RE: [RFC net-next 4/5] net: phy: Add support for IEEE standard test modes

2018-05-06 Thread Woojung.Huh
Hi Florian,

> Well, the way the code is structure is that if you call that function
> with a test mode value that is not part of the standard set, it returns
> -EOPNOTSUPP, so if your particular PHY driver wants to "overlay"
> standard and non-standard modes, it can by using that hint.
> 
> This should work even if we have more standard test modes in the future
> because the test modes are dynamically fetched by user-space using the
> ETH_GSTRINGS ioctl().
> 
> Does that cover what you had in mind?
Basically, agree on your explanation.

My idea was making genphy_set_test() more expandable for other test modes
because it would be a good place to add more standard test modes later.

No problem to keep current codes.

Thanks.
Woojung


RE: [RFC net-next 4/5] net: phy: Add support for IEEE standard test modes

2018-05-01 Thread Woojung.Huh
Hi Florian,

> Not sure I completely understand your suggestion, do you mean that I
> should break down the body of that function above such that there are
> per-speed lower level functions? Something like the pseudo-code below:
> 
> genphy_set_test() {
>   switch (mode) {
>   case PHY_STD_TEST_MODE_100BASET2_1:
>   ..
>   case PHY_STD_TEST_MODE_100BASET2_3:
>   return genphy_set_100baset2();
> 
>   case PHY_STD_TEST_MODE_1000BASET_1:
>   ..
>   case PHY_STD_TEST_MODE_1000BASET_4:
>   return genphy_set_1000baset();
> 
>   case PHY_STD_TEST_MODE_8021BWQCQ_1:
>   return genphy_set_100baset1();
> 
> }
Yes, I should write pseudo code. Sorry about confusion.
User can override this function or expand to other modes.

Thanks.
Woojung



RE: [RFC net-next 4/5] net: phy: Add support for IEEE standard test modes

2018-05-01 Thread Woojung.Huh
Hi Florian,

> diff --git a/drivers/net/phy/phy-tests.c b/drivers/net/phy/phy-tests.c
...
> +/* genphy_set_test - Make a PHY enter one of the standard IEEE defined
> + * test modes
> + * @phydev: the PHY device instance
> + * @test: the desired test mode
> + * @data: test specific data (none)
> + *
> + * This function makes the designated @phydev enter the desired standard
> + * 100BaseT2 or 1000BaseT test mode as defined in IEEE 802.3-2012 section TWO
> + * and THREE under 32.6.1.2.1 and 40.6.1.1.2 respectively
> + */
> +int genphy_set_test(struct phy_device *phydev,
> + struct ethtool_phy_test *test, const u8 *data)
> +{
> + u16 shift, base, bmcr = 0;
> + int ret;
> +
> + /* Exit test mode */
> + if (test->mode == PHY_STD_TEST_MODE_NORMAL) {
> + ret = phy_read(phydev, MII_CTRL1000);
> + if (ret < 0)
> + return ret;
> +
> + ret &= ~GENMASK(15, 13);
> +
> + return phy_write(phydev, MII_CTRL1000, ret);
> + }
> +
> + switch (test->mode) {
> + case PHY_STD_TEST_MODE_100BASET2_1:
> + case PHY_STD_TEST_MODE_100BASET2_2:
> + case PHY_STD_TEST_MODE_100BASET2_3:
> + if (!(phydev->supported & PHY_100BT_FEATURES))
> + return -EOPNOTSUPP;
> +
> + shift = 14;
> + base = test->mode - PHY_STD_TEST_MODE_NORMAL;
> + bmcr = BMCR_SPEED100;
> + break;
> +
> + case PHY_STD_TEST_MODE_1000BASET_1:
> + case PHY_STD_TEST_MODE_1000BASET_2:
> + case PHY_STD_TEST_MODE_1000BASET_3:
> + case PHY_STD_TEST_MODE_1000BASET_4:
> + if (!(phydev->supported & PHY_1000BT_FEATURES))
> + return -EOPNOTSUPP;
> +
> + shift = 13;
> + base = test->mode - PHY_STD_TEST_MODE_100BASET2_MAX;
> + bmcr = BMCR_SPEED1000;
> + break;
> +
> + default:
> + /* Let an upper driver deal with additional modes it may
> +  * support
> +  */
> + return -EOPNOTSUPP;
> + }
> +
> + /* Force speed and duplex */
> + ret = phy_write(phydev, MII_BMCR, bmcr | BMCR_FULLDPLX);
> + if (ret < 0)
> + return ret;
> +
> + /* Set the desired test mode bit */
> + return phy_write(phydev, MII_CTRL1000, (test->mode + base) << shift);
> +}
For now, these are for 100B-T2 & 1000B-TX.
But, other speeds such as 802.3bw/bq/cq have very similar format,
how about make  phy_write() to BMCR & CTRL1000 as another function call per 
speed?

Thanks.
Woojung


RE: smsc95xx: aligment issues

2018-04-30 Thread Woojung.Huh
Hi Stefan,

Thanks for report. We will try to repro issue and contact you if need more 
details.

Regards,
Woojung

> -Original Message-
> From: Stefan Wahren [mailto:stefan.wah...@i2se.com]
> Sent: Saturday, April 28, 2018 3:59 AM
> To: Nisar Sayed - I17970 ; Woojung Huh - C21699
> 
> Cc: David S. Miller ; linux-usb 
> ; netdev
> ; popcorn mix ; James Hughes
> 
> Subject: net: smsc95xx: aligment issues
> 
> Hi,
> after connecting a Raspberry Pi 1 B to my local network i'm seeing aligment 
> issues under
> /proc/cpu/alignment:
> 
> User: 0
> System:   142 (_decode_session4+0x12c/0x3c8)
> Skipped:  0
> Half: 0
> Word: 0
> DWord:127
> Multi:15
> User faults:  2 (fixup)
> 
> I've also seen outputs with _csum_ipv6_magic.
> 
> Kernel config: bcm2835_defconfig
> Reproducible kernel trees: current linux-next, 4.17-rc2 and 4.14.37 (i didn't 
> test older versions)
> 
> Please tell if you need more information to narrow down this issue.
> 
> Best regards
> Stefan


RE: [PATCH 3/4] lan78xx: Read LED modes from Device Tree

2018-04-12 Thread Woojung.Huh
> > @@ -2097,6 +2098,25 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
> > (void)lan78xx_set_eee(dev->net, );
> > }
> >
> > +   if (!of_property_read_u32_array(dev->udev->dev.of_node,
> > +   "microchip,led-modes",
> > +   led_modes, ARRAY_SIZE(led_modes))) {
> > +   u32 reg;
> > +   int i;
> > +
> > +   reg = phy_read(phydev, 0x1d);
> > +   for (i = 0; i < ARRAY_SIZE(led_modes); i++) {
> > +   reg &= ~(0xf << (i * 4));
> > +   reg |= (led_modes[i] & 0xf) << (i * 4);
> > +   }
> > +   (void)phy_write(phydev, 0x1d, reg);
> 
> Poking PHY registers directly from the MAC driver is not always a good
> idea. This MAC driver does that in a few places :-(
Agree but, some are for workaround unfortunately.

> What do we know about the PHY? It is built into the device or is it
> external? If it is external, how do you know the LED register is at
> 0x1d?
This register is not defined in include/linux/microchipphy.h. :(
Also agree that there parts should be applied to internal PHY only.



RE: [PATCH] lan78xx: Connect phy early

2018-03-14 Thread Woojung.Huh
Hi Alexander,

Thanks for patch. We will look into it if there is any corner case
Such as plug in/out while operations.

Woojung

> -Original Message-
> From: Alexander Graf [mailto:ag...@suse.de]
> Sent: Wednesday, March 14, 2018 10:55 AM
> To: Woojung Huh - C21699 
> Cc: UNGLinuxDriver ; netdev@vger.kernel.org; 
> linux-
> u...@vger.kernel.org; linux-ker...@vger.kernel.org; Thomas Bogendoerfer
> ; Phil Elwell 
> Subject: [PATCH] lan78xx: Connect phy early
> 
> When using wicked with a lan78xx device attached to the system, we
> end up with ethtool commands issued on the device before an ifup
> got issued. That lead to the following crash:
> 
> Unable to handle kernel NULL pointer dereference at virtual address 
> 039c
> pgd = 800035b3
> [039c] *pgd=
> Internal error: Oops: 9604 [#1] SMP
> Modules linked in: [...]
> Supported: Yes
> CPU: 3 PID: 638 Comm: wickedd Tainted: GE  
> 4.12.14-0-default #1
> Hardware name: raspberrypi rpi/rpi, BIOS 2018.03-rc2 02/21/2018
> task: 800035e74180 task.stack: 800036718000
> PC is at phy_ethtool_ksettings_get+0x20/0x98
> LR is at lan78xx_get_link_ksettings+0x44/0x60 [lan78xx]
> pc : [] lr : [] pstate: 2005
> sp : 80003671bb20
> x29: 80003671bb20 x28: 800035e74180
> x27: 08912000 x26: 001d
> x25: 0124 x24: 08f74d00
> x23: 004000114809 x22: 
> x21: 80003671bbd0 x20: 
> x19: 80003671bbd0 x18: 040d
> x17: 0001 x16: 
> x15:  x14: 
> x13:  x12: 0020
> x11: 0101010101010101 x10: fefefefefefefeff
> x9 : 7f7f7f7f7f7f7f7f x8 : fefefeff31677364
> x7 : 80808080 x6 : 80003671bc9c
> x5 : 80003671b9f8 x4 : 80002c296190
> x3 :  x2 : 
> x1 : 80003671bbd0 x0 : 80003671bc00
> Process wickedd (pid: 638, stack limit = 0x800036718000)
> Call trace:
> Exception stack(0x80003671b9e0 to 0x80003671bb20)
> b9e0: 80003671bc00 80003671bbd0  
> ba00: 80002c296190 80003671b9f8 80003671bc9c 80808080
> ba20: fefefeff31677364 7f7f7f7f7f7f7f7f fefefefefefefeff 0101010101010101
> ba40: 0020   
> ba60:  0001 040d 80003671bbd0
> ba80:  80003671bbd0  004000114809
> baa0: 08f74d00 0124 001d 08912000
> bac0: 800035e74180 80003671bb20 00dcca84 80003671bb20
> bae0: 086f7f30 2005 80002c296000 800035223900
> bb00:   80003671bb20 086f7f30
> [] phy_ethtool_ksettings_get+0x20/0x98
> [] lan78xx_get_link_ksettings+0x44/0x60 [lan78xx]
> [] ethtool_get_settings+0x68/0x210
> [] dev_ethtool+0x214/0x2180
> [] dev_ioctl+0x400/0x630
> [] sock_do_ioctl+0x70/0x88
> [] sock_ioctl+0x208/0x368
> [] do_vfs_ioctl+0xb0/0x848
> [] SyS_ioctl+0x8c/0xa8
> Exception stack(0x80003671bec0 to 0x80003671c000)
> bec0: 0009 8946 f4e841d0 aa0032687465
> bee0: fa2319d4 f4e841d4 32687465 32687465
> bf00: 001d 7f7fff7f7f7f7f7f 72606b622e71ff4c 7f7f7f7f7f7f7f7f
> bf20: 0101010101010101 0020  7f510c68
> bf40: 7f6a9d18 7f44ce30 040d 7f6f98f0
> bf60: f4e842c0 0001 fa2c2e00 7f6ab000
> bf80: f4e842c0 7f62a000 fa2b9f20 fa2c2e00
> bfa0: f4e84818 f4e841a0 7f5ad0cc f4e841a0
> bfc0: 7f44ce3c 8000 0009 001d
> bfe0:    
> 
> The culprit is quite simple: The driver tries to access the phy left and 
> right,
> but only actually has a working reference to it when the device is up.
> 
> The fix thus is quite simple too: Get a reference to the phy on probe already
> and keep it even when the device is going down.
> 
> With this patch applied, I can successfully run wicked on my system and bring
> the interface up and down as many times as I want, without getting NULL 
> pointer
> dereferences in between.
> 
> Signed-off-by: Alexander Graf 
> ---
>  drivers/net/usb/lan78xx.c | 21 ++---
>  1 file changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git 

RE: [PATCH] lan78xx: Use common error handling code in lan78xx_phy_init()

2017-10-30 Thread Woojung.Huh
> From: SF Markus Elfring [mailto:elfr...@users.sourceforge.net]
> Sent: Saturday, October 28, 2017 4:57 PM
> To: netdev@vger.kernel.org; linux-...@vger.kernel.org; UNGLinuxDriver;
> Woojung Huh - C21699
> Cc: LKML; kernel-janit...@vger.kernel.org
> Subject: [PATCH] lan78xx: Use common error handling code in
> lan78xx_phy_init()
> 
> From: Markus Elfring 
> Date: Sat, 28 Oct 2017 22:42:52 +0200
> 
> * Add a jump target so that a specific error message is stored only once
>   at the end of this function implementation.
> 
> * Replace two calls of the function "netdev_err" by goto statements.
> 
> * Adjust two condition checks.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring 
> ---

Reviewed-by: Woojung Huh 


RE: [PATCH net-next 2/2] net: dsa: lan9303: Learn addresses on CPU port when bridged

2017-10-25 Thread Woojung.Huh
Hi Egil,

> >> @@ -62,7 +80,10 @@ static struct sk_buff *lan9303_xmit(struct sk_buff
> *skb,
> >> struct net_device *dev)
> >>
> >>lan9303_tag = (u16 *)(skb->data + 2 * ETH_ALEN);
> >>lan9303_tag[0] = htons(ETH_P_8021Q);
> >> -  lan9303_tag[1] = htons(dp->index | BIT(4));
> >> +  lan9303_tag[1] = lan9303_tx_use_arl(dp, skb->data) ?
> >
> > How about using skb_mac_header(skb) than skb->data?
> >
> >> +  LAN9303_TAG_TX_USE_ALR :
> >> +  dp->index |
> >
> 
> I am not the expert here.
> 
> I see that skb_mac_header() is (skb->head + skb->mac_header). So it will
> cost a few nano seconds per packet. Not the end of the world though.
> But I see that other net/dsa/tag_*.c use skb->data, assuming that
> skb->data point to mac header.
> 

Revisited skb_mac_header(). It is basically skb->data after math.
Understand that it would be extra steps than referring skb->data directly.
Unless no one comments on this, please keep first patch.

Thanks.
Woojung


RE: [PATCH net-next 2/2] net: dsa: lan9303: Learn addresses on CPU port when bridged

2017-10-24 Thread Woojung.Huh
Hi Egil,

> +static inline int lan9303_tx_use_arl(struct dsa_port *dp, u8 *dest_addr)
> +{
> + struct lan9303 *chip = dp->ds->priv;
> +
> + return chip->is_bridged && !ether_addr_equal(dest_addr,
> eth_stp_addr);
> +}
> 
>  static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device
> *dev)
>  {
> @@ -62,7 +80,10 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb,
> struct net_device *dev)
> 
>   lan9303_tag = (u16 *)(skb->data + 2 * ETH_ALEN);
>   lan9303_tag[0] = htons(ETH_P_8021Q);
> - lan9303_tag[1] = htons(dp->index | BIT(4));
> + lan9303_tag[1] = lan9303_tx_use_arl(dp, skb->data) ?

How about using skb_mac_header(skb) than skb->data?

> + LAN9303_TAG_TX_USE_ALR :
> + dp->index |

Thanks.
Woojung



RE: [PATCH net] net: dsa: mv88e6060: fix switch MAC address

2017-10-13 Thread Woojung.Huh
> -Original Message-
> From: netdev-ow...@vger.kernel.org [mailto:netdev-
> ow...@vger.kernel.org] On Behalf Of Vivien Didelot
> Sent: Friday, October 13, 2017 1:39 PM
> To: netdev@vger.kernel.org
> Cc: linux-ker...@vger.kernel.org; ker...@savoirfairelinux.com; David S.
> Miller; Florian Fainelli; Andrew Lunn; David Laight; Vivien Didelot
> Subject: [PATCH net] net: dsa: mv88e6060: fix switch MAC address
> 
> The 88E6060 Ethernet switch always transmits the multicast bit of the
> switch MAC address as a zero. It re-uses the corresponding bit 8 of the
> register "Switch MAC Address Register Bytes 0 & 1" for "DiffAddr".
> 
> If the "DiffAddr" bit is 0, then all ports transmit the same source
> address. If it is set to 1, then bit 2:0 are used for the port number.
> 
> The mv88e6060 driver is currently wrongly shifting the MAC address byte
> 0 by 9. To fix this, shift it by 8 as usual and clear its bit 0.
> 
> Signed-off-by: Vivien Didelot 
> ---

Reviewed-by: Woojung Huh 

- Woojung


RE: [PATCH net-next v2 2/4] net: dsa: mv88e6060: setup random mac address

2017-10-13 Thread Woojung.Huh
Hi Vivien,

> >> > +REG_WRITE(REG_GLOBAL, GLOBAL_MAC_01, (addr[0] << 9) |
> >> addr[1]);
> >>
> >> Is that supposed to be 9 ?
> >
> > Looks like it.
> > Check
> http://www.marvell.com/switching/assets/marvell_linkstreet_88E6060_data
> sheet.pdf
> 
> Hum, David is correct, there is a bug in the driver which needs to be
> addressed first. MAC address bit 40 is addr[0] & 0x1, thus we must
> shift byte 0 by 8 and mask it against 0xfe.
> 
> I'll respin this serie including a fix for both net and net-next.

Yes, you are right. Missed description about bit 40.

Thanks.
Woojung


RE: [PATCH net-next v2 2/4] net: dsa: mv88e6060: setup random mac address

2017-10-13 Thread Woojung.Huh
> From: Vivien Didelot
> > Sent: 13 October 2017 02:41
> > As for mv88e6xxx, setup the switch from within the mv88e6060 driver with
> > a random MAC address, and remove the .set_addr implementation.
> >
> > Signed-off-by: Vivien Didelot 
> > ---
> >  drivers/net/dsa/mv88e6060.c | 30 +++---
> >  1 file changed, 19 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/net/dsa/mv88e6060.c b/drivers/net/dsa/mv88e6060.c
> > index 621cdc46ad81..2f9d5e6a0f97 100644
> > --- a/drivers/net/dsa/mv88e6060.c
> > +++ b/drivers/net/dsa/mv88e6060.c
> ...
> > +   REG_WRITE(REG_GLOBAL, GLOBAL_MAC_01, (addr[0] << 9) |
> addr[1]);
> 
> Is that supposed to be 9 ?

Looks like it.
Check 
http://www.marvell.com/switching/assets/marvell_linkstreet_88E6060_datasheet.pdf

Woojung



RE: [PATCH v2 net-next 1/2] net: dsa: lan9303: Move tag setup to new lan9303_setup_tagging

2017-10-11 Thread Woojung.Huh
>  @@ -644,6 +648,10 @@ static int lan9303_setup(struct dsa_switch *ds)
>   return -EINVAL;
>   }
> 
>  +ret = lan9303_setup_tagging(chip);
>  +if (ret)
>  +dev_err(chip->dev, "failed to setup port tagging %d\n", 
>  ret);
>  +
> >>> Still move on when error happens?
> >>>
> >> Good question. I just followed the pattern from the original function,
> >> which was not made by me. Actually I did once reflect on whether this
> >> was the correct way. Perhaps it could be argued that it is better to
> >> allow the device to come up, so the problem can be investigated?
> > Maybe depends on severity of setting?
> > BTW, lan9303_setup() still returns ZERO at the end?
> I did quick survey of the _setup functions of the other dsa drivers.
> Some return on error, some ignore errors.
> If you think so, I can make a v3 series that return on error. Otherwise
> I leave it as it is.

Unless Andrew, Vivien or Florian raises flag, I guess it will be fine as-is.

Thanks.
Woojung


RE: [PATCH v5 1/2] net: phy: DP83822 initial driver submission

2017-10-10 Thread Woojung.Huh
> +static int dp83822_config_intr(struct phy_device *phydev)
> +{
> + int misr_status;
> + int physcr_status;
> + int err;
> +
> + if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
> + misr_status = phy_read(phydev, MII_DP83822_MISR1);
> + if (misr_status < 0)
> + return misr_status;
> +
> + misr_status |= (DP83822_RX_ERR_HF_INT_EN |
> + DP83822_FALSE_CARRIER_HF_INT_EN |
> + DP83822_ANEG_COMPLETE_INT_EN |
> + DP83822_DUP_MODE_CHANGE_INT_EN |
> + DP83822_SPEED_CHANGED_INT_EN |
> + DP83822_LINK_STAT_INT_EN |
> + DP83822_ENERGY_DET_INT_EN |
> + DP83822_LINK_QUAL_INT_EN);
> +
> + err = phy_write(phydev, MII_DP83822_MISR1, misr_status);
> + if (err < 0)
> + return err;
> +
> + misr_status = phy_read(phydev, MII_DP83822_MISR2);
> + if (misr_status < 0)
> + return misr_status;
> +
> + misr_status |= (DP83822_JABBER_DET_INT_EN |
> + DP83822_WOL_PKT_INT_EN |
> + DP83822_SLEEP_MODE_INT_EN |
> + DP83822_MDI_XOVER_INT_EN |
> + DP83822_LB_FIFO_INT_EN |
> + DP83822_PAGE_RX_INT_EN |
> + DP83822_ANEG_ERR_INT_EN |
> + DP83822_EEE_ERROR_CHANGE_INT_EN);
> +
> + err = phy_write(phydev, MII_DP83822_MISR2, misr_status);
> + if (err < 0)
> + return err;
> +
> + physcr_status = phy_read(phydev, MII_DP83822_PHYSCR);
> + if (physcr_status < 0)
> + return physcr_status;
> +
> + physcr_status |= DP83822_PHYSCR_INT_OE |
> DP83822_PHYSCR_INTEN;
> +
Don't want to be picky, but seeing extra blank line here. 

> + } else {
> + err = phy_write(phydev, MII_DP83822_MISR1, 0);
> + if (err < 0)
> + return err;
> +
> + err = phy_write(phydev, MII_DP83822_MISR1, 0);
> + if (err < 0)
> + return err;
> +
> + physcr_status = phy_read(phydev, MII_DP83822_PHYSCR);
> + if (physcr_status < 0)
> + return physcr_status;
> +
> + physcr_status &= ~DP83822_PHYSCR_INTEN;
> + }



RE: [PATCH v2 net-next 1/2] net: dsa: lan9303: Move tag setup to new lan9303_setup_tagging

2017-10-10 Thread Woojung.Huh
> > Specific reason to use val then using
> LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT0
> > like previous line?
> >
> Specific reason was to please a reviewer that did not like my
> indenting in first version. I did not agree with him, but since
> nobody else spoke up, I changed the code.
Got it. Missed previous patch/comment.

> >> @@ -644,6 +648,10 @@ static int lan9303_setup(struct dsa_switch *ds)
> >>return -EINVAL;
> >>}
> >>
> >> +  ret = lan9303_setup_tagging(chip);
> >> +  if (ret)
> >> +  dev_err(chip->dev, "failed to setup port tagging %d\n", ret);
> >> +
> > Still move on when error happens?
> >
> Good question. I just followed the pattern from the original function,
> which was not made by me. Actually I did once reflect on whether this
> was the correct way. Perhaps it could be argued that it is better to
> allow the device to come up, so the problem can be investigated?
Maybe depends on severity of setting?
BTW, lan9303_setup() still returns ZERO at the end?

Thanks.
Woojung


RE: [PATCH v2 net-next 1/2] net: dsa: lan9303: Move tag setup to new lan9303_setup_tagging

2017-10-10 Thread Woojung.Huh
> +/* forward special tagged packets from port 0 to port 1 *or* port 2 */
> +static int lan9303_setup_tagging(struct lan9303 *chip)
> +{
> + int ret;
> + u32 val;
> + /* enable defining the destination port via special VLAN tagging
> +  * for port 0
> +  */
> + ret = lan9303_write_switch_reg(chip,
> LAN9303_SWE_INGRESS_PORT_TYPE,
> +
> LAN9303_SWE_INGRESS_PORT_TYPE_VLAN);
> + if (ret)
> + return ret;
> +
> + /* tag incoming packets at port 1 and 2 on their way to port 0 to be
> +  * able to discover their source port
> +  */
> + val = LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT0;
> + return lan9303_write_switch_reg(chip,
> LAN9303_BM_EGRSS_PORT_TYPE, val);
Specific reason to use val then using 
LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT0
like previous line?

> @@ -644,6 +648,10 @@ static int lan9303_setup(struct dsa_switch *ds)
>   return -EINVAL;
>   }
> 
> + ret = lan9303_setup_tagging(chip);
> + if (ret)
> + dev_err(chip->dev, "failed to setup port tagging %d\n", ret);
> +
Still move on when error happens?

>   ret = lan9303_separate_ports(chip);
>   if (ret)
>   dev_err(chip->dev, "failed to separate ports %d\n", ret);
> --
> 2.11.0

- Woojung


RE: [PATCH v1 RFC 1/7] Replace license with GPL

2017-10-09 Thread Woojung.Huh
> Subject: [PATCH v1 RFC 1/7] Replace license with GPL
> 
> From: Tristram Ha 
> 
> Replace license with GPL.
> 
> Signed-off-by: Tristram Ha 

Reviewed-by: Woojung Huh 


RE: [PATCH v3 2/3] net: phy: DP83822 initial driver submission

2017-10-09 Thread Woojung.Huh
> Subject: [PATCH v3 2/3] net: phy: DP83822 initial driver submission
> 
> Add support for the TI  DP83822 10/100Mbit ethernet phy.
> 
> The DP83822 provides flexibility to connect to a MAC through a
> standard MII, RMII or RGMII interface.
> 
> Datasheet:
> http://www.ti.com/product/DP83822I/datasheet
> 
> Signed-off-by: Dan Murphy 
> ---

Reviewed-by: Woojung Huh 


RE: [PATCH 2/3 v2] net: phy: DP83822 initial driver submission

2017-10-05 Thread Woojung.Huh
> > > +static int dp83822_suspend(struct phy_device *phydev)
> > > +{
> > > + int value;
> > > +
> > > + mutex_lock(>lock);
> > > + value = phy_read_mmd(phydev, DP83822_DEVADDR,
> > > MII_DP83822_WOL_CFG);
> > > + mutex_unlock(>lock);
> 
> > Would we need mutex to access phy_read_mmd()?
> > phy_read_mmd() has mdio_lock for indirect access.
> 
> Hi Woojung
> 
> The mdio lock is not sufficient. It protects against two mdio
> accesses. But here we need to protect against two phy operations.
> There is a danger something else tries to access the phy during
> suspend.

Hi Andrew,

Thanks for comment. I have question then.
phy_read_mmd() is protected by bus->mdio_lock around mmd_indirect & mdio_read.
While these operation, other phy_read() & phy_write() will be blocked inside
mdiobus_read() & mdiobus_write().

Because this phy_read_mmd(.., DP83822_DEVADDR, MII_DP83822_WOL_CFG) is not 
read-modify-write operation, I think phydev->lock may not be necessary.

Am I missing something?

> > > + if (!(value & DP83822_WOL_EN))
> > > + genphy_suspend(phydev);
> 
> Releasing the lock before calling genphy_suspend() is not so nice.
> Maybe add a version which assumes the lock has already been taken?
> 
We can expand genphy_suspend() per setting by phy_driver->set_wol.
When genphy_suspend() acts per wol setting, not many phy driver needs to extra 
work
When WOL is enabled.
How do you think?

- Woojung


RE: [PATCH 2/3 v2] net: phy: DP83822 initial driver submission

2017-10-04 Thread Woojung.Huh
> +static int dp83822_suspend(struct phy_device *phydev)
> +{
> + int value;
> +
> + mutex_lock(>lock);
> + value = phy_read_mmd(phydev, DP83822_DEVADDR,
> MII_DP83822_WOL_CFG);
> + mutex_unlock(>lock);
Would we need mutex to access phy_read_mmd()?
phy_read_mmd() has mdio_lock for indirect access.

> + if (!(value & DP83822_WOL_EN))
> + genphy_suspend(phydev);
> +
> + return 0;
> +}
> +
> +static int dp83822_resume(struct phy_device *phydev)
> +{
> + int value;
> +
> + genphy_resume(phydev);
> +
> + mutex_lock(>lock);
> + value = phy_read_mmd(phydev, DP83822_DEVADDR,
> MII_DP83822_WOL_CFG);
> +
> + phy_write_mmd(phydev, DP83822_DEVADDR,
> MII_DP83822_WOL_CFG, value |
> +   DP83822_WOL_CLR_INDICATION);
> +
> + mutex_unlock(>lock);
Same here.

Woojung


RE: [PATCH] net: phy: DP83822 initial driver submission

2017-10-03 Thread Woojung.Huh
> +static int dp83822_suspend(struct phy_device *phydev)
> +{
> + int value;
> +
> + mutex_lock(>lock);
> +
> + value = phy_read_mmd(phydev, DP83822_DEVADDR,
> MII_DP83822_WOL_CFG);
> + if (~value & DP83822_WOL_EN) {
Same result, but how about " if (!(value & DP83822_WOL_EN))" ?

> + value = phy_read(phydev, MII_BMCR);
> + phy_write(phydev, MII_BMCR, value | BMCR_PDOWN);
> + }
> +
> + mutex_unlock(>lock);
> +
> + return 0;
> +}



RE: [PATCH v2 net 2/3] lan78xx: Allow EEPROM write for less than MAX_EEPROM_SIZE

2017-09-11 Thread Woojung.Huh
Nisar,

>@@ -1290,8 +1290,8 @@ static int lan78xx_ethtool_set_eeprom(struct net_device 
>*netdev,
>
>/* Allow entire eeprom update only */
>if ((ee->magic == LAN78XX_EEPROM_MAGIC) &&
>-   (ee->offset == 0) &&
>-   (ee->len == 512) &&
>+   (ee->offset >= 0 && ee->offset < MAX_EEPROM_SIZE) &&
>+   (ee->len > 0 && (ee->offset + ee->len) <= MAX_EEPROM_SIZE) &&
>(data[0] == EEPROM_INDICATOR))
This patch is for writing  any len at any offset.
However, "(data[0] == EEPROM_INDICATOR)" prevents it.

>ret = lan78xx_write_raw_eeprom(dev, ee->offset, ee->len, data);
>else if ((ee->magic == LAN78XX_OTP_MAGIC) &&

- Woojung


RE: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check

2017-09-08 Thread Woojung.Huh
> >> I think it means CONFIG_GPIOLIB=n in the kernel because it's not needed,
> >> yet you run code (like drivers/net/phy/mdio_bus.c) that unconditionally
> >> calls into GPIOLIB and attempts to configure a given GPIO if available.
> > Yes. I'm facing issue on PC which won't need GPIOLIB as default.
> > Warning message goes away when GPIOLIB is enabled, and fortunately,
> > Ubuntu default config has it.
> > So, it may not be seen by many users when with full/default configuration.
> 
> Woojung, I suppose you are also getting a warning from
> gpiod_set_value_cansleep() done in mdiobus_unregister() right? With
> CONFIG_GPIOLIB=n devm_gpiod_get_optional() returns NULL, which we
> don't
> check as an error, on purpose however we still call
> gpiod_set_value_cansleep() on a NULL GPIO descriptor, so the following
> should do:
> 
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index b6f9fa670168..67dbb7c26840 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -424,7 +424,8 @@ void mdiobus_unregister(struct mii_bus *bus)
> }
> 
> /* Put PHYs in RESET to save power */
> -   gpiod_set_value_cansleep(bus->reset_gpiod, 1);
> +   if (!IS_ERR_OR_NULL(bus->reset_gpiod))
> +   gpiod_set_value_cansleep(bus->reset_gpiod, 1);
> 
> device_del(>dev);
>  }
Hi Florian,

Thanks for the patch. I'm avoiding warning with CONFIG_GPIOLIB=y for now.
I'm curious that there is a final conclusion to resolve this issue,
either with CONFIG_GPIOLIB=y or something else.

- Woojung


RE: [PATCH RFC 3/5] Add KSZ8795 switch driver

2017-09-08 Thread Woojung.Huh
> > > > @@ -0,0 +1,2066 @@
> > > > +/*
> > > > + * Microchip KSZ8795 switch driver
> > > > + *
> > > > + * Copyright (C) 2017 Microchip Technology Inc.
> > > > + * Tristram Ha 
> > > > + *
> > > > + * Permission to use, copy, modify, and/or distribute this software for
> any
> > > > + * purpose with or without fee is hereby granted, provided that the
> above
> > > > + * copyright notice and this permission notice appear in all copies.
> > > > + *
> > > > + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS
> ALL
> > > WARRANTIES
> > > > + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
> WARRANTIES
> > > OF
> > > > + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
> BE
> > > LIABLE FOR
> > > > + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR
> ANY
> > > DAMAGES
> > > > + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
> WHETHER
> > > IN AN
> > > > + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
> > > ARISING OUT OF
> > > > + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
> SOFTWARE.
> > > > + */
> > >
> > > This is not exactly GPL, right? But tagging below says it is
> > > GPL. Please fix one.
> > >
> >
> > This boilerplate paragraph was copied from the KSZ9477 driver, although I
> did
> > wonder why this was used.
> 
> Hi Tristram
> 
> Please can you talk to your legal people and see if this can be
> replaced with the standard GPL text?
This should be replaced to GPL. These text copied from drivers/net/dsa/b53/*.
Will submit patches of drivers/net/dsa/microchip/*

- Woojung


RE: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check

2017-09-07 Thread Woojung.Huh
> >>> If someone is using GPIO descriptors with GPIO disabled, i.e. calling
> >>> gpiod_get() and friends, this is very likely to be a bug, and what
> >>> the driver wants to do is:
> >>>
> >>>  depends on GPIOLIB
> >>>
> >>> or
> >>>
> >>>  select GPIOLIB
> >>>
> >>> in Kconfig. The whole optional thing is mainly a leftover from when it
> >>> was possible to have a local implementation of the GPIOLIB API in
> >>> some custom header file, noone sane should be doing that anymore,
> >>> and if they do, they can very well face the warnings.
> >>>
> >>> If someone is facing a lot of WARN_ON() messages to this, it is a clear
> >>> indication that they need to fix their Kconfig and in that case it is 
> >>> proper.
> >> Linus & Andrew,
> >>
> >> I knew that it is already in David's pulling request.
> >> Configuring GPIOLIB is the right solution  even if platform doesn't use it?
> >
> > I guess?
> >
> > "Platform doesn't use it" what does that mean?
> >
> > Does it mean it does not call the
> > APIs of the GPIOLIB, does it mean it doesn't have a GPIO driver
> > at probe (but may have one by having it probed from a module)
> > or does it mean the platform can never have it?
> 
> I think it means CONFIG_GPIOLIB=n in the kernel because it's not needed,
> yet you run code (like drivers/net/phy/mdio_bus.c) that unconditionally
> calls into GPIOLIB and attempts to configure a given GPIO if available.
Yes. I'm facing issue on PC which won't need GPIOLIB as default.
Warning message goes away when GPIOLIB is enabled, and fortunately,
Ubuntu default config has it.
So, it may not be seen by many users when with full/default configuration.

> This thread is actually what prompted me to write this email:
>
> https://lkml.org/lkml/2017/9/2/3
Thanks for the link.




RE: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check

2017-09-07 Thread Woojung.Huh
> If someone is using GPIO descriptors with GPIO disabled, i.e. calling
> gpiod_get() and friends, this is very likely to be a bug, and what
> the driver wants to do is:
> 
>  depends on GPIOLIB
> 
> or
> 
>  select GPIOLIB
> 
> in Kconfig. The whole optional thing is mainly a leftover from when it
> was possible to have a local implementation of the GPIOLIB API in
> some custom header file, noone sane should be doing that anymore,
> and if they do, they can very well face the warnings.
> 
> If someone is facing a lot of WARN_ON() messages to this, it is a clear
> indication that they need to fix their Kconfig and in that case it is proper.
Linus & Andrew,

I knew that it is already in David's pulling request.
Configuring GPIOLIB is the right solution  even if platform doesn't use it?

Did I miss any new patch?

Thanks.
Woojung


RE: [PATCH net 0/3] lan78xx: Fixes to lan78xx driver

2017-09-07 Thread Woojung.Huh
> > > > This series of patches are for lan78xx driver.
> > > >
> > > > These patches fixes potential issues associated with lan78xx driver
> > >
> > > Hi Nisar
> > >
> > > So this is version 2? Please include v2 in the subject line.
> > >
> > > Also, briefly list what is different from the previous version.
> > Hi Andrew,
> >
> > Because Nisar dropped of non-mdio patch in the series,
> > I suggested to treat as new patch than version 2.
> > In this case, it is still considered as version 2 than new series?
> 
> Hi Woojung
> 
> So it is not a clear hard rule here. But we have seen these patches
> before, and they have been modified based on my comments. So i would
> say these are version 2. But a new series would also be O.K. What
> really matters is that the cover note explains what is going on. That
> some of the patches in the previous version have been dropped and will
> be posted later, and what changes have been made to the remaining
> patches.

Andrew,
Thanks for detail explanation and agree that cover page has more description.

Thanks.
Woojung


RE: [PATCH net 0/3] lan78xx: Fixes to lan78xx driver

2017-09-07 Thread Woojung.Huh
> On Thu, Sep 07, 2017 at 07:10:51AM +, nisar.sa...@microchip.com
> wrote:
> > From: Nisar Sayed 
> >
> > This series of patches are for lan78xx driver.
> >
> > These patches fixes potential issues associated with lan78xx driver
> 
> Hi Nisar
> 
> So this is version 2? Please include v2 in the subject line.
> 
> Also, briefly list what is different from the previous version.
Hi Andrew,

Because Nisar dropped of non-mdio patch in the series,
I suggested to treat as new patch than version 2.
In this case, it is still considered as version 2 than new series?

- Woojung


RE: [PATCH v2 rfc 0/8] IGMP snooping for local traffic

2017-09-06 Thread Woojung.Huh
> That being said, I have a feeling that the Marvell switches behave a
> tiny bit differently than others in that they do not flood broadcast by
> default in a given L2 domain.
Florian,

Because some DSA switches from Marvell & Microchip can do IGMP snooping, 
can we propose switch layer another flag what to do when HW support it?

- Woojung


RE: [PATCH v2 rfc 0/8] IGMP snooping for local traffic

2017-09-06 Thread Woojung.Huh
Andrew,

> What i found is that the Marvell chips don't flood broadcast frames
> between bridged ports. What appears to happen is there is a fdb miss,
> so it gets forwarded to the CPU port for the host to deal with. The
> software bridge when floods it out all ports of the bridge.
Is this IGMP snooping enabled mode in Marvell chip?




RE: [PATCH] DSA support for Micrel KSZ8895

2017-08-27 Thread Woojung.Huh
Pavel,

Thanks for update and sorry about email format (due to web-access version)
I'll do review when getting back to office later this week.

- Woojung

From: Pavel Machek [pa...@denx.de]
Sent: Sunday, August 27, 2017 8:36 AM
To: Woojung Huh - C21699; nathan.leigh.con...@gmail.com
Cc: vivien.dide...@savoirfairelinux.com; f.faine...@gmail.com; 
netdev@vger.kernel.org; linux-ker...@vger.kernel.org; tristram...@micrel.com; 
and...@lunn.ch; pa...@denx.de
Subject: [PATCH] DSA support for Micrel KSZ8895

Hi!

So I fought with the driver a bit more, and now I have something that
kind-of-works.

"great great hack" belows worries me.

Yeah, disabled code needs to be removed before merge.

No, tag_ksz part probably is not acceptable. Do you see solution
better than just copying it into tag_ksz1 file?

Any more comments, etc?

Help would be welcome.


RE: DSA support for Micrel KSZ8895

2017-08-23 Thread Woojung.Huh
Pavel,

> > I'll forward your email to our support.
> > AFAIK, KSZ8895 has different register mapping from KSZ9477,
> > it will be more than ID changes in current driver.
> 
> More than ID changes, indeed. As layout is completely different, it
> looks like different source file will be needed for support.
> 
> I'm not nearly there; but I can ifconfig lanX up, already, and perform
> some pings.
> 
> Any ideas how to do the work in a way to minimize code duplication are
> welcome...

Which version do you use to create patch?
Getting error when applying patch to the latest net-next.

- Woojung


RE: [PATCH net v2 1/2] net: core: Specify skb_pad()/skb_put_padto() SKB freeing

2017-08-23 Thread Woojung.Huh
> Cc: da...@davemloft.net; vivien.dide...@savoirfairelinux.com; Woojung
> Huh - C21699; UNGLinuxDriver; Florian Fainelli
> Subject: [PATCH net v2 1/2] net: core: Specify skb_pad()/skb_put_padto()
> SKB freeing
> 
> Rename skb_pad() into __skb_pad() and make it take a third argument:
> free_on_error which controls whether kfree_skb() should be called or
> not, skb_pad() directly makes use of it and passes true to preserve its
> existing behavior. Do exactly the same thing with __skb_put_padto() and
> skb_put_padto().
> 
> Suggested-by: David Miller 
> Signed-off-by: Florian Fainelli 

Reviewed-by: Woojung Huh 

- Woojung



RE: [PATCH net v2 2/2] net: dsa: skb_put_padto() already frees nskb

2017-08-23 Thread Woojung.Huh
> The first call of skb_put_padto() will free up the SKB on error, but we
> return NULL which tells dsa_slave_xmit() that the original SKB should be
> freed so this would lead to a double free here.
> 
> The second skb_put_padto() already frees the passed sk_buff reference
> upon error, so calling kfree_skb() on it again is not necessary.
> 
> Detected by CoverityScan, CID#1416687 ("USE_AFTER_FREE")
> 
> Fixes: e71cb9e00922 ("net: dsa: ksz: fix skb freeing")
> Signed-off-by: Florian Fainelli 

Reviewed-by: Woojung Huh 

- Woojung


RE: [PATCH net] net: dsa: skb_put_padto() already frees nskb

2017-08-22 Thread Woojung.Huh
> > Because skb_put_padto() frees skb when it fails,  below lines in
> e71cb9e00922
> > ("net: dsa: ksz: fix skb freeing") will be an issue to.
> >
> > if (skb_tailroom(skb) >= padlen + KSZ_INGRESS_TAG_LEN) {
> > +   if (skb_put_padto(skb, skb->len + padlen))
> > +   return NULL;
> > +
> >
> > When it fails skb will be freed twice in skb_put_padto() and
> > caller of dsa_slave_xmit().
> 
> You are right, I am not sure what is the best way to fix tag_ksz.c other
> than somehow open coding skb_put_padto() minus the freeing on error part?

Agree. May need to go back to 1st submission without skb_put_padto().
Will check more if any other ideas.

Thanks.
Woojung


RE: [PATCH net] net: dsa: skb_put_padto() already frees nskb

2017-08-21 Thread Woojung.Huh
Florian,

> -Original Message-
> From: Florian Fainelli [mailto:f.faine...@gmail.com]
> Sent: Monday, August 21, 2017 3:42 PM
> To: netdev@vger.kernel.org
> Cc: da...@davemloft.net; and...@lunn.ch;
> vivien.dide...@savoirfairelinux.com; Woojung Huh - C21699; Florian Fainelli
> Subject: [PATCH net] net: dsa: skb_put_padto() already frees nskb
> 
> skb_put_padto() already frees the passed sk_buff reference upon error,
> so calling kfree_skb() on it again is not necessary.
> 
> Detected by CoverityScan, CID#1416687 ("USE_AFTER_FREE")
> 
> Fixes: e71cb9e00922 ("net: dsa: ksz: fix skb freeing")
> Signed-off-by: Florian Fainelli 
> ---
>  net/dsa/tag_ksz.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
> index de66ca8e6201..107172c82107 100644
> --- a/net/dsa/tag_ksz.c
> +++ b/net/dsa/tag_ksz.c
> @@ -60,10 +60,8 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb,
> struct net_device *dev)
>skb_transport_header(skb) - skb-
> >head);
>   skb_copy_and_csum_dev(skb, skb_put(nskb, skb->len));
> 
> - if (skb_put_padto(nskb, nskb->len + padlen)) {
> - kfree_skb(nskb);
> + if (skb_put_padto(nskb, nskb->len + padlen))
>   return NULL;
> - }
> 
>   kfree_skb(skb);
>   }
> --

Because skb_put_padto() frees skb when it fails,  below lines in e71cb9e00922
("net: dsa: ksz: fix skb freeing") will be an issue to.

if (skb_tailroom(skb) >= padlen + KSZ_INGRESS_TAG_LEN) {
+   if (skb_put_padto(skb, skb->len + padlen))
+   return NULL;
+

When it fails skb will be freed twice in skb_put_padto() and
caller of dsa_slave_xmit().

Woojung


RE: DSA support for Micrel KSZ8895

2017-08-16 Thread Woojung.Huh
> > Hi!
> >
> > I've got hardware with KSZ8895, and I'd like to use switch ports as
> > separate ethernet cards. I believe that means DSA support.
> >
> > And there are even patches available from microchip... unfortunately
> > they are in strange form and for v3.18.
> >
> >
> http://www.microchip.com/SWLibraryWeb/product.aspx?product=KSZ8895
> %20Software%20Linux%203.18
> >
> > Is there newer version of the driver available somewhere? Is the
> > driver good starting point, or should I start with something else?
> 
> Hi Pavel
> 
> Woojung is the expert here. His DSA driver for the 9477 is a nice
> clean driver.
> 
> Have you compared the 8895 to the 9477. Are they similar? Could the
> existing 9477 be extended to support the 8895?
> 
>Andrew

Hi Pavel,

I'll forward your email to our support.
AFAIK, KSZ8895 has different register mapping from KSZ9477,
it will be more than ID changes in current driver.

Thanks.
Woojung



RE: [PATCH net-next 06/11] net: dsa: debugfs: add port registers

2017-08-15 Thread Woojung.Huh
Vivien,

> Subject: [PATCH net-next 06/11] net: dsa: debugfs: add port registers
> 
> Add a debug filesystem "regs" entry to query a port's hardware registers
> through the .get_regs_len and .get_regs_len switch operations.
> 
> This is very convenient because it allows one to dump the registers of
> DSA links, which are not exposed to userspace.
This series will be very useful to get various debug information.
Do you have any plan to expand 32bit register access and switch-level registers
In addition to port-level registers?

> +static void dsa_debugfs_regs_read_count(struct dsa_switch *ds, int id,
> + struct seq_file *seq, int count)
> +{
> + u16 data[count * ETH_GSTRING_LEN];
I think this should be u16 data[count] because it is value of registers.

> + struct ethtool_regs regs;
> + int i;
> +
> + ds->ops->get_regs(ds, id, , data);
> +
> + for (i = 0; i < count / 2; i++)
> + seq_printf(seq, "%2d: %04x\n", i, data[i]);
> +}
> +
> +static int dsa_debugfs_regs_read(struct dsa_switch *ds, int id,
> +  struct seq_file *seq)
> +{
> + int count;
> +
> + if (!ds->ops->get_regs_len || !ds->ops->get_regs)
> + return -EOPNOTSUPP;
> +
> + count = ds->ops->get_regs_len(ds, id);
> + if (count < 0)
> + return count;
Because get_regs_len returns length than count per mv88e6xxx/chip.c,
it requires some math before passing to dsa_debugfs_regs_read_count().

It does "count/2" in dsa-debugfs_regs_read_count(), however,
As commented above, "count" is used at "u16 data[...]".
So, it would be nice to match with name. Ie, count or size/length.

Thanks.
Woojung


RE: [PATCH net] net: dsa: ksz: fix skb freeing

2017-08-09 Thread Woojung.Huh
> The DSA layer frees the original skb when an xmit function returns NULL,
> meaning an error occurred. But if the tagging code copied the original
> skb, it is responsible of freeing the copy if an error occurs.
> 
> The ksz tagging code currently has two issues: if skb_put_padto fails,
> the skb copy is not freed, and the original skb will be freed twice.
> 
> To fix that, move skb_put_padto inside both branches of the skb_tailroom
> condition, before freeing the original skb, and free the copy on error.
> 
> Signed-off-by: Vivien Didelot 
Reviewed-by: Woojung Huh 


RE: [PATCH] smsc95xx: use ethtool_op_get_ts_info()

2017-07-13 Thread Woojung.Huh
> -Original Message-
> From: Petr Kulhavy [mailto:br...@jikos.cz]
> Sent: Thursday, July 13, 2017 1:41 PM
> To: steve.glendinn...@shawell.net; UNGLinuxDriver
> Cc: netdev@vger.kernel.org; linux-...@vger.kernel.org; Petr Kulhavy
> Subject: [PATCH] smsc95xx: use ethtool_op_get_ts_info()
> 
> This change enables the use of SW timestamping on Raspberry PI.
> 
> smsc95xx uses the usbnet transmit function usbnet_start_xmit(), which
> implements software timestamping. However the
> SOF_TIMESTAMPING_TX_SOFTWARE
> capability was missing and only SOF_TIMESTAMPING_RX_SOFTWARE was
> announced.
> By using ethtool_op_get_ts_info() as get_ts_info() also the
> SOF_TIMESTAMPING_TX_SOFTWARE is announced.
> 
> Signed-off-by: Petr Kulhavy 

Reviewed-by: Woojung Huh 

Thanks



RE: [PATCH net-next] net: phy: smsc: Implement PHY statistics

2017-06-02 Thread Woojung.Huh
>> Just cosmetic thing.
>> How about aligning with other members in structure like
>
>Yes, i can do that. v2 tomorrow sometime.
Thanks.

>
>Can you confirm the LAN911x Internal PHY don't have this. The register
>is not listed in the switch datasheet.
>
This register is NOT in LAN911x internal phy.
http://ww1.microchip.com/downloads/en/DeviceDoc/2266A.pdf

- Woojung


RE: [PATCH net-next] net: phy: smsc: Implement PHY statistics

2017-06-02 Thread Woojung.Huh
Andrew,

>  static int smsc_phy_probe(struct phy_device *phydev)
>  {
>   struct device *dev = >mdio.dev;
> @@ -206,6 +258,11 @@ static struct phy_driver smsc_phy_driver[] = {
>   .ack_interrupt  = smsc_phy_ack_interrupt,
>   .config_intr= smsc_phy_config_intr,
> 
> + /* Statistics */
> + .get_sset_count = smsc_get_sset_count,
> + .get_strings = smsc_get_strings,
> + .get_stats = smsc_get_stats,
> +
...
> 
> + /* Statistics */
> + .get_sset_count = smsc_get_sset_count,
> + .get_strings = smsc_get_strings,
> + .get_stats = smsc_get_stats,
> +
...
> + /* Statistics */
> + .get_sset_count = smsc_get_sset_count,
> + .get_strings = smsc_get_strings,
> + .get_stats = smsc_get_stats,
> +
...
> + /* Statistics */
> + .get_sset_count = smsc_get_sset_count,
> + .get_strings = smsc_get_strings,
> + .get_stats = smsc_get_stats,
> +
Just cosmetic thing.
How about aligning with other members in structure like
> + .get_sset_count = smsc_get_sset_count,
> + .get_strings = smsc_get_strings,
> + .get_stats= smsc_get_stats,

Reviewed-By: Woojung Huh 



RE: [PATCH][net-next] net: dsa: make function ksz_rcv static

2017-06-01 Thread Woojung.Huh
> function ksz_rcv can be made static as it does not need to be
> in global scope. Reformat arguments to make it checkpatch warning
> free too.
> 
> Cleans up sparse warning: "symbol 'ksz_rcv' was not declared. Should
> it be static?"
> 
> Signed-off-by: Colin Ian King 

Reviewed-by: Woojung Huh 


[PATCH v5 net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477

2017-05-31 Thread Woojung.Huh
From: Woojung Huh 

The KSZ9477 is a fully integrated layer 2, managed, 7 ports GigE switch
with numerous advanced features. 5 ports incorporate 10/100/1000 Mbps PHYs.
The other 2 ports have interfaces that can be configured as SGMII, RGMII, MII
or RMII. Either of these may connect directly to a host processor or
to an external PHY. The SGMII port may interface to a fiber optic transceiver.

This driver currently supports vlan, fdb, mdb & mirror dsa switch operations.

Reviewed-by: Florian Fainelli 
Signed-off-by: Woojung Huh 
---
 drivers/net/dsa/Kconfig |2 +
 drivers/net/dsa/Makefile|1 +
 drivers/net/dsa/microchip/Kconfig   |   12 +
 drivers/net/dsa/microchip/Makefile  |2 +
 drivers/net/dsa/microchip/ksz_9477_reg.h| 1676 +++
 drivers/net/dsa/microchip/ksz_common.c  | 1279 
 drivers/net/dsa/microchip/ksz_priv.h|  210 
 drivers/net/dsa/microchip/ksz_spi.c |  216 
 include/linux/platform_data/microchip-ksz.h |   29 +
 9 files changed, 3427 insertions(+)
 create mode 100644 drivers/net/dsa/microchip/Kconfig
 create mode 100644 drivers/net/dsa/microchip/Makefile
 create mode 100644 drivers/net/dsa/microchip/ksz_9477_reg.h
 create mode 100644 drivers/net/dsa/microchip/ksz_common.c
 create mode 100644 drivers/net/dsa/microchip/ksz_priv.h
 create mode 100644 drivers/net/dsa/microchip/ksz_spi.c
 create mode 100644 include/linux/platform_data/microchip-ksz.h

diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig
index 68131a4..83a9bc8 100644
--- a/drivers/net/dsa/Kconfig
+++ b/drivers/net/dsa/Kconfig
@@ -39,6 +39,8 @@ config NET_DSA_MV88E6060
  This enables support for the Marvell 88E6060 ethernet switch
  chip.
 
+source "drivers/net/dsa/microchip/Kconfig"
+
 source "drivers/net/dsa/mv88e6xxx/Kconfig"
 
 config NET_DSA_QCA8K
diff --git a/drivers/net/dsa/Makefile b/drivers/net/dsa/Makefile
index 9613f36..4a5b5bd 100644
--- a/drivers/net/dsa/Makefile
+++ b/drivers/net/dsa/Makefile
@@ -8,4 +8,5 @@ obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303_I2C) += lan9303_i2c.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303_MDIO) += lan9303_mdio.o
 obj-y  += b53/
+obj-y  += microchip/
 obj-y  += mv88e6xxx/
diff --git a/drivers/net/dsa/microchip/Kconfig 
b/drivers/net/dsa/microchip/Kconfig
new file mode 100644
index 000..a8b8f59
--- /dev/null
+++ b/drivers/net/dsa/microchip/Kconfig
@@ -0,0 +1,12 @@
+menuconfig MICROCHIP_KSZ
+   tristate "Microchip KSZ series switch support"
+   depends on NET_DSA
+   select NET_DSA_TAG_KSZ
+   help
+ This driver adds support for Microchip KSZ switch chips.
+
+config MICROCHIP_KSZ_SPI_DRIVER
+   tristate "KSZ series SPI connected switch driver"
+   depends on MICROCHIP_KSZ && SPI
+   help
+ Select to enable support for registering switches configured through 
SPI.
diff --git a/drivers/net/dsa/microchip/Makefile 
b/drivers/net/dsa/microchip/Makefile
new file mode 100644
index 000..ed335e2
--- /dev/null
+++ b/drivers/net/dsa/microchip/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_MICROCHIP_KSZ)+= ksz_common.o
+obj-$(CONFIG_MICROCHIP_KSZ_SPI_DRIVER) += ksz_spi.o
diff --git a/drivers/net/dsa/microchip/ksz_9477_reg.h 
b/drivers/net/dsa/microchip/ksz_9477_reg.h
new file mode 100644
index 000..6aa6752
--- /dev/null
+++ b/drivers/net/dsa/microchip/ksz_9477_reg.h
@@ -0,0 +1,1676 @@
+/*
+ * Microchip KSZ9477 register definitions
+ *
+ * Copyright (C) 2017
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef __KSZ9477_REGS_H
+#define __KSZ9477_REGS_H
+
+#define KS_PRIO_M  0x7
+#define KS_PRIO_S  4
+
+/* 0 - Operation */
+#define REG_CHIP_ID0__10x
+
+#define REG_CHIP_ID1__10x0001
+
+#define FAMILY_ID  0x95
+#define FAMILY_ID_94   0x94
+#define FAMILY_ID_95   0x95
+#define FAMILY_ID_85   0x85
+#define FAMILY_ID_98   0x98
+#define FAMILY_ID_88   

[PATCH v5 net-next 5/5] dsa: add maintainer of Microchip KSZ switches

2017-05-31 Thread Woojung.Huh
From: Woojung Huh 

Adding maintainer of Microchip KSZ switches.

Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
Signed-off-by: Woojung Huh 
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 42378cf..0fcb5e75 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8479,6 +8479,16 @@ F:   drivers/media/platform/atmel/atmel-isc.c
 F: drivers/media/platform/atmel/atmel-isc-regs.h
 F: devicetree/bindings/media/atmel-isc.txt
 
+MICROCHIP KSZ SERIES ETHERNET SWITCH DRIVER
+M: Woojung Huh 
+M: Microchip Linux Driver Support 
+L: netdev@vger.kernel.org
+S: Maintained
+F: net/dsa/tag_ksz.c
+F: drivers/net/dsa/microchip/*
+F: include/linux/platform_data/microchip-ksz.h
+F: Documentation/devicetree/bindings/net/dsa/ksz.txt
+
 MICROCHIP USB251XB DRIVER
 M: Richard Leitner 
 L: linux-...@vger.kernel.org
-- 
2.7.4



[PATCH v5 net-next 2/5] phy: micrel: add Microchip KSZ 9477 Switch PHY support

2017-05-31 Thread Woojung.Huh
From: Woojung Huh 

Adding Microchip 9477 Phy included in KSZ9477 Switch.

Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
Signed-off-by: Woojung Huh 
---
 drivers/net/phy/micrel.c   | 11 +++
 include/linux/micrel_phy.h |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 4cfd541..46e80bc 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -20,6 +20,7 @@
  *ksz8081, ksz8091,
  *ksz8061,
  * Switch : ksz8873, ksz886x
+ *  ksz9477
  */
 
 #include 
@@ -996,6 +997,16 @@ static struct phy_driver ksphy_driver[] = {
.read_status= ksz8873mll_read_status,
.suspend= genphy_suspend,
.resume = genphy_resume,
+}, {
+   .phy_id = PHY_ID_KSZ9477,
+   .phy_id_mask= MICREL_PHY_ID_MASK,
+   .name   = "Microchip KSZ9477",
+   .features   = PHY_GBIT_FEATURES,
+   .config_init= kszphy_config_init,
+   .config_aneg= genphy_config_aneg,
+   .read_status= genphy_read_status,
+   .suspend= genphy_suspend,
+   .resume = genphy_resume,
 } };
 
 module_phy_driver(ksphy_driver);
diff --git a/include/linux/micrel_phy.h b/include/linux/micrel_phy.h
index f541da6..472fa4d 100644
--- a/include/linux/micrel_phy.h
+++ b/include/linux/micrel_phy.h
@@ -37,6 +37,8 @@
 
 #define PHY_ID_KSZ8795 0x00221550
 
+#definePHY_ID_KSZ9477  0x00221631
+
 /* struct phy_device dev_flags definitions */
 #define MICREL_PHY_50MHZ_CLK   0x0001
 #define MICREL_PHY_FXEN0x0002
-- 
2.7.4


[PATCH v5 net-next 1/5] dsa: add support for Microchip KSZ tail tagging

2017-05-31 Thread Woojung.Huh
From: Woojung Huh 

Adding support for the Microchip KSZ switch family tail tagging.

Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
Signed-off-by: Woojung Huh 
---
 include/net/dsa.h  |   1 +
 net/dsa/Kconfig|   3 ++
 net/dsa/Makefile   |   1 +
 net/dsa/dsa.c  |   3 ++
 net/dsa/dsa_priv.h |   3 ++
 net/dsa/tag_ksz.c  | 101 +
 6 files changed, 112 insertions(+)
 create mode 100644 net/dsa/tag_ksz.c

diff --git a/include/net/dsa.h b/include/net/dsa.h
index d9bd693..7de1234 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -31,6 +31,7 @@ enum dsa_tag_protocol {
DSA_TAG_PROTO_BRCM,
DSA_TAG_PROTO_DSA,
DSA_TAG_PROTO_EDSA,
+   DSA_TAG_PROTO_KSZ,
DSA_TAG_PROTO_LAN9303,
DSA_TAG_PROTO_MTK,
DSA_TAG_PROTO_QCA,
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index 297389b..cc5f8f9 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -25,6 +25,9 @@ config NET_DSA_TAG_DSA
 config NET_DSA_TAG_EDSA
bool
 
+config NET_DSA_TAG_KSZ
+   bool
+
 config NET_DSA_TAG_LAN9303
bool
 
diff --git a/net/dsa/Makefile b/net/dsa/Makefile
index 90e5aa6..fcce25d 100644
--- a/net/dsa/Makefile
+++ b/net/dsa/Makefile
@@ -6,6 +6,7 @@ dsa_core-y += dsa.o dsa2.o legacy.o port.o slave.o switch.o
 dsa_core-$(CONFIG_NET_DSA_TAG_BRCM) += tag_brcm.o
 dsa_core-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o
 dsa_core-$(CONFIG_NET_DSA_TAG_EDSA) += tag_edsa.o
+dsa_core-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
 dsa_core-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
 dsa_core-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
 dsa_core-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 3288a80..402459e 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -49,6 +49,9 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
 #ifdef CONFIG_NET_DSA_TAG_EDSA
[DSA_TAG_PROTO_EDSA] = _netdev_ops,
 #endif
+#ifdef CONFIG_NET_DSA_TAG_KSZ
+   [DSA_TAG_PROTO_KSZ] = _netdev_ops,
+#endif
 #ifdef CONFIG_NET_DSA_TAG_LAN9303
[DSA_TAG_PROTO_LAN9303] = _netdev_ops,
 #endif
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index c1d4180..7459d57 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -167,6 +167,9 @@ extern const struct dsa_device_ops dsa_netdev_ops;
 /* tag_edsa.c */
 extern const struct dsa_device_ops edsa_netdev_ops;
 
+/* tag_ksz.c */
+extern const struct dsa_device_ops ksz_netdev_ops;
+
 /* tag_lan9303.c */
 extern const struct dsa_device_ops lan9303_netdev_ops;
 
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
new file mode 100644
index 000..0b08a40
--- /dev/null
+++ b/net/dsa/tag_ksz.c
@@ -0,0 +1,101 @@
+/*
+ * net/dsa/tag_ksz.c - Microchip KSZ Switch tag format handling
+ * Copyright (c) 2017 Microchip Technology
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "dsa_priv.h"
+
+/* For Ingress (Host -> KSZ), 2 bytes are added before FCS.
+ * ---
+ * DA(6bytes)|SA(6bytes)||Data(nbytes)|tag0(1byte)|tag1(1byte)|FCS(4bytes)
+ * ---
+ * tag0 : Prioritization (not used now)
+ * tag1 : each bit represents port (eg, 0x01=port1, 0x02=port2, 0x10=port5)
+ *
+ * For Egress (KSZ -> Host), 1 byte is added before FCS.
+ * ---
+ * DA(6bytes)|SA(6bytes)||Data(nbytes)|tag0(1byte)|FCS(4bytes)
+ * ---
+ * tag0 : zero-based value represents port
+ *   (eg, 0x00=port1, 0x02=port3, 0x06=port7)
+ */
+
+#defineKSZ_INGRESS_TAG_LEN 2
+#defineKSZ_EGRESS_TAG_LEN  1
+
+static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+   struct dsa_slave_priv *p = netdev_priv(dev);
+   struct sk_buff *nskb;
+   int padlen;
+   u8 *tag;
+
+   padlen = (skb->len >= ETH_ZLEN) ? 0 : ETH_ZLEN - skb->len;
+
+   if (skb_tailroom(skb) >= padlen + KSZ_INGRESS_TAG_LEN) {
+   nskb = skb;
+   } else {
+   nskb = alloc_skb(NET_IP_ALIGN + skb->len +
+padlen + KSZ_INGRESS_TAG_LEN, GFP_ATOMIC);
+   if (!nskb) {
+   kfree_skb(skb);
+   return NULL;
+   }
+   skb_reserve(nskb, NET_IP_ALIGN);
+
+   skb_reset_mac_header(nskb);
+   skb_set_network_header(nskb,
+  skb_network_header(skb) - 

[PATCH v5 net-next 0/5] dsa: add Microchip KSZ9477 DSA driver

2017-05-31 Thread Woojung.Huh
From: Woojung Huh 

This series of patches is for Microchip KSZ9477 DSA driver.
KSZ9477 is 7 ports GigE switch with numerous advanced features.
5 ports are 10/100/1000 Mbps internal PHYs and 2 ports have
Interfaces to SGMII, RGMII, MII or RMII.

This patch supports VLAN, MDB, FDB and port mirroring offloads.

Welcome reviews and comments from community.

Note: Tests are performed on internal development board.

V5
- add missing MODULE_LICENSE

V4
- update per review comments
- cosmetic changes
- net/dsa/tag_ksz.c
  * skb_put() & memset() are changed to skb_put_padto()
- drivers/net/dsa/microchip/ksz_common.
   * vlan access mutex is updated
   * mib_names[] is changed to static const

V3
- update per review comments
- cosmetic changes
- drivers/net/dsa/microchip/ksz_common.c 
  * clean up ksz_switch_chips[] 
  * consolidate checking loops into functions
  * update mutex for better locking
  * replace devm_kmalloc_array() to devm_kcalloc()
- MAINTAINERS
  * add missing net/dsa/tag_ksz.c

V2
- update per review comments
- several cosmetic changes
- net/dsa/tag_ksz.c
  * constants are changed to defines
  * remove skb_linearize() in ksz_rcv()
  * ksz_xmit()checks skb tailroom before allocate new skb
- drivers/net/phy/micrel.c
  * remove PHY_HAS_MAGICANEG from ksphy_driver[]
- drivers/net/dsa/microchip/ksz_common.c
  * add timeout to avoid endless loop
  * port initialization is move to ksz_port_enable() instead of  
ksz_setup_ports()
- Documentation/devicetree/bindings/net/dsa/ksz.txt
  * fix typo and indentations

Woojung Huh (5):
  dsa: add support for Microchip KSZ tail tagging
  phy: micrel: add Microchip KSZ 9477 Switch PHY support
  dsa: add DSA switch driver for Microchip KSZ9477
  net: dsa: Add Microchip KSZ switches binding
  dsa: add maintainer of Microchip KSZ switches

 Documentation/devicetree/bindings/net/dsa/ksz.txt |   72 +
 MAINTAINERS   |   10 +
 drivers/net/dsa/Kconfig   |2 +
 drivers/net/dsa/Makefile  |1 +
 drivers/net/dsa/microchip/Kconfig |   12 +
 drivers/net/dsa/microchip/Makefile|2 +
 drivers/net/dsa/microchip/ksz_9477_reg.h  | 1676 +
 drivers/net/dsa/microchip/ksz_common.c| 1279 
 drivers/net/dsa/microchip/ksz_priv.h  |  210 +++
 drivers/net/dsa/microchip/ksz_spi.c   |  216 +++
 drivers/net/phy/micrel.c  |   11 +
 include/linux/micrel_phy.h|2 +
 include/linux/platform_data/microchip-ksz.h   |   29 +
 include/net/dsa.h |1 +
 net/dsa/Kconfig   |3 +
 net/dsa/Makefile  |1 +
 net/dsa/dsa.c |3 +
 net/dsa/dsa_priv.h|3 +
 net/dsa/tag_ksz.c |  101 ++
 19 files changed, 3634 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/ksz.txt
 create mode 100644 drivers/net/dsa/microchip/Kconfig
 create mode 100644 drivers/net/dsa/microchip/Makefile
 create mode 100644 drivers/net/dsa/microchip/ksz_9477_reg.h
 create mode 100644 drivers/net/dsa/microchip/ksz_common.c
 create mode 100644 drivers/net/dsa/microchip/ksz_priv.h
 create mode 100644 drivers/net/dsa/microchip/ksz_spi.c
 create mode 100644 include/linux/platform_data/microchip-ksz.h
 create mode 100644 net/dsa/tag_ksz.c

-- 
2.7.4


RE: [PATCH v5 net-next 0/5] dsa: add Microchip KSZ9477 DSA driver

2017-05-31 Thread Woojung.Huh
> Unfortunately, I had to revert, you didn't add MODULE_LICENSE() tags
> to the new drivers.
> 
> WARNING: modpost: missing MODULE_LICENSE() in
> drivers/net/dsa/microchip/ksz_common.o
> see include/linux/module.h for more information
> WARNING: modpost: missing MODULE_LICENSE() in
> drivers/net/dsa/microchip/ksz_spi.o
> see include/linux/module.h for more information
Ouch! Will submit update soon.

Thanks.
- Woojung


[PATCH v5 net-next 5/5] dsa: add maintainer of Microchip KSZ switches

2017-05-30 Thread Woojung.Huh
From: Woojung Huh 

Adding maintainer of Microchip KSZ switches.

Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
Signed-off-by: Woojung Huh 
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 42378cf..0fcb5e75 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8479,6 +8479,16 @@ F:   drivers/media/platform/atmel/atmel-isc.c
 F: drivers/media/platform/atmel/atmel-isc-regs.h
 F: devicetree/bindings/media/atmel-isc.txt
 
+MICROCHIP KSZ SERIES ETHERNET SWITCH DRIVER
+M: Woojung Huh 
+M: Microchip Linux Driver Support 
+L: netdev@vger.kernel.org
+S: Maintained
+F: net/dsa/tag_ksz.c
+F: drivers/net/dsa/microchip/*
+F: include/linux/platform_data/microchip-ksz.h
+F: Documentation/devicetree/bindings/net/dsa/ksz.txt
+
 MICROCHIP USB251XB DRIVER
 M: Richard Leitner 
 L: linux-...@vger.kernel.org
-- 
2.7.4



[PATCH v5 net-next 2/5] phy: micrel: add Microchip KSZ 9477 Switch PHY support

2017-05-30 Thread Woojung.Huh
From: Woojung Huh 

Adding Microchip 9477 Phy included in KSZ9477 Switch.

Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
Signed-off-by: Woojung Huh 
---
 drivers/net/phy/micrel.c   | 11 +++
 include/linux/micrel_phy.h |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 4cfd541..46e80bc 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -20,6 +20,7 @@
  *ksz8081, ksz8091,
  *ksz8061,
  * Switch : ksz8873, ksz886x
+ *  ksz9477
  */
 
 #include 
@@ -996,6 +997,16 @@ static struct phy_driver ksphy_driver[] = {
.read_status= ksz8873mll_read_status,
.suspend= genphy_suspend,
.resume = genphy_resume,
+}, {
+   .phy_id = PHY_ID_KSZ9477,
+   .phy_id_mask= MICREL_PHY_ID_MASK,
+   .name   = "Microchip KSZ9477",
+   .features   = PHY_GBIT_FEATURES,
+   .config_init= kszphy_config_init,
+   .config_aneg= genphy_config_aneg,
+   .read_status= genphy_read_status,
+   .suspend= genphy_suspend,
+   .resume = genphy_resume,
 } };
 
 module_phy_driver(ksphy_driver);
diff --git a/include/linux/micrel_phy.h b/include/linux/micrel_phy.h
index f541da6..472fa4d 100644
--- a/include/linux/micrel_phy.h
+++ b/include/linux/micrel_phy.h
@@ -37,6 +37,8 @@
 
 #define PHY_ID_KSZ8795 0x00221550
 
+#definePHY_ID_KSZ9477  0x00221631
+
 /* struct phy_device dev_flags definitions */
 #define MICREL_PHY_50MHZ_CLK   0x0001
 #define MICREL_PHY_FXEN0x0002
-- 
2.7.4



[PATCH v5 net-next 1/5] dsa: add support for Microchip KSZ tail tagging

2017-05-30 Thread Woojung.Huh
From: Woojung Huh 

Adding support for the Microchip KSZ switch family tail tagging.

Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
Signed-off-by: Woojung Huh 
---
 include/net/dsa.h  |   1 +
 net/dsa/Kconfig|   3 ++
 net/dsa/Makefile   |   1 +
 net/dsa/dsa.c  |   3 ++
 net/dsa/dsa_priv.h |   3 ++
 net/dsa/tag_ksz.c  | 101 +
 6 files changed, 112 insertions(+)
 create mode 100644 net/dsa/tag_ksz.c

diff --git a/include/net/dsa.h b/include/net/dsa.h
index c0e567c..42c28ae 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -31,6 +31,7 @@ enum dsa_tag_protocol {
DSA_TAG_PROTO_BRCM,
DSA_TAG_PROTO_DSA,
DSA_TAG_PROTO_EDSA,
+   DSA_TAG_PROTO_KSZ,
DSA_TAG_PROTO_LAN9303,
DSA_TAG_PROTO_MTK,
DSA_TAG_PROTO_QCA,
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index 297389b..cc5f8f9 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -25,6 +25,9 @@ config NET_DSA_TAG_DSA
 config NET_DSA_TAG_EDSA
bool
 
+config NET_DSA_TAG_KSZ
+   bool
+
 config NET_DSA_TAG_LAN9303
bool
 
diff --git a/net/dsa/Makefile b/net/dsa/Makefile
index 90e5aa6..fcce25d 100644
--- a/net/dsa/Makefile
+++ b/net/dsa/Makefile
@@ -6,6 +6,7 @@ dsa_core-y += dsa.o dsa2.o legacy.o port.o slave.o switch.o
 dsa_core-$(CONFIG_NET_DSA_TAG_BRCM) += tag_brcm.o
 dsa_core-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o
 dsa_core-$(CONFIG_NET_DSA_TAG_EDSA) += tag_edsa.o
+dsa_core-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
 dsa_core-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
 dsa_core-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
 dsa_core-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 3288a80..402459e 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -49,6 +49,9 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
 #ifdef CONFIG_NET_DSA_TAG_EDSA
[DSA_TAG_PROTO_EDSA] = _netdev_ops,
 #endif
+#ifdef CONFIG_NET_DSA_TAG_KSZ
+   [DSA_TAG_PROTO_KSZ] = _netdev_ops,
+#endif
 #ifdef CONFIG_NET_DSA_TAG_LAN9303
[DSA_TAG_PROTO_LAN9303] = _netdev_ops,
 #endif
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index c1d4180..7459d57 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -167,6 +167,9 @@ extern const struct dsa_device_ops dsa_netdev_ops;
 /* tag_edsa.c */
 extern const struct dsa_device_ops edsa_netdev_ops;
 
+/* tag_ksz.c */
+extern const struct dsa_device_ops ksz_netdev_ops;
+
 /* tag_lan9303.c */
 extern const struct dsa_device_ops lan9303_netdev_ops;
 
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
new file mode 100644
index 000..0b08a40
--- /dev/null
+++ b/net/dsa/tag_ksz.c
@@ -0,0 +1,101 @@
+/*
+ * net/dsa/tag_ksz.c - Microchip KSZ Switch tag format handling
+ * Copyright (c) 2017 Microchip Technology
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "dsa_priv.h"
+
+/* For Ingress (Host -> KSZ), 2 bytes are added before FCS.
+ * ---
+ * DA(6bytes)|SA(6bytes)||Data(nbytes)|tag0(1byte)|tag1(1byte)|FCS(4bytes)
+ * ---
+ * tag0 : Prioritization (not used now)
+ * tag1 : each bit represents port (eg, 0x01=port1, 0x02=port2, 0x10=port5)
+ *
+ * For Egress (KSZ -> Host), 1 byte is added before FCS.
+ * ---
+ * DA(6bytes)|SA(6bytes)||Data(nbytes)|tag0(1byte)|FCS(4bytes)
+ * ---
+ * tag0 : zero-based value represents port
+ *   (eg, 0x00=port1, 0x02=port3, 0x06=port7)
+ */
+
+#defineKSZ_INGRESS_TAG_LEN 2
+#defineKSZ_EGRESS_TAG_LEN  1
+
+static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+   struct dsa_slave_priv *p = netdev_priv(dev);
+   struct sk_buff *nskb;
+   int padlen;
+   u8 *tag;
+
+   padlen = (skb->len >= ETH_ZLEN) ? 0 : ETH_ZLEN - skb->len;
+
+   if (skb_tailroom(skb) >= padlen + KSZ_INGRESS_TAG_LEN) {
+   nskb = skb;
+   } else {
+   nskb = alloc_skb(NET_IP_ALIGN + skb->len +
+padlen + KSZ_INGRESS_TAG_LEN, GFP_ATOMIC);
+   if (!nskb) {
+   kfree_skb(skb);
+   return NULL;
+   }
+   skb_reserve(nskb, NET_IP_ALIGN);
+
+   skb_reset_mac_header(nskb);
+   skb_set_network_header(nskb,
+  skb_network_header(skb) - 

[PATCH v5 net-next 4/5] net: dsa: Add Microchip KSZ switches binding

2017-05-30 Thread Woojung.Huh
From: Woojung Huh 

A sample SPI configuration for Microchip KSZ switches.

Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
Signed-off-by: Woojung Huh 
---
 Documentation/devicetree/bindings/net/dsa/ksz.txt | 72 +++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/ksz.txt

diff --git a/Documentation/devicetree/bindings/net/dsa/ksz.txt 
b/Documentation/devicetree/bindings/net/dsa/ksz.txt
new file mode 100644
index 000..9acdb6c
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/dsa/ksz.txt
@@ -0,0 +1,72 @@
+Microchip KSZ Series Ethernet switches
+==
+
+Required properties:
+
+- compatible: For external switch chips, compatible string must be exactly one
+  of: "microchip,ksz9477"
+
+See Documentation/devicetree/bindings/dsa/dsa.txt for a list of additional
+required and optional properties.
+
+Examples:
+
+Ethernet switch connected via SPI to the host, CPU port wired to eth0:
+
+   eth0: ethernet@10001000 {
+   fixed-link {
+   speed = <1000>;
+   full-duplex;
+   };
+   };
+
+   spi1: spi@f8008000 {
+   pinctrl-0 = <_spi_ksz>;
+   cs-gpios = < 25 0>;
+   id = <1>;
+   status = "okay";
+
+   ksz9477: ksz9477@0 {
+   compatible = "microchip,ksz9477";
+   reg = <0>;
+
+   spi-max-frequency = <4400>;
+   spi-cpha;
+   spi-cpol;
+
+   status = "okay";
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   port@0 {
+   reg = <0>;
+   label = "lan1";
+   };
+   port@1 {
+   reg = <1>;
+   label = "lan2";
+   };
+   port@2 {
+   reg = <2>;
+   label = "lan3";
+   };
+   port@3 {
+   reg = <3>;
+   label = "lan4";
+   };
+   port@4 {
+   reg = <4>;
+   label = "lan5";
+   };
+   port@5 {
+   reg = <5>;
+   label = "cpu";
+   ethernet = <>;
+   fixed-link {
+   speed = <1000>;
+   full-duplex;
+   };
+   };
+   };
+   };
+   };
-- 
2.7.4



[PATCH v5 net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477

2017-05-30 Thread Woojung.Huh
From: Woojung Huh 

The KSZ9477 is a fully integrated layer 2, managed, 7 ports GigE switch
with numerous advanced features. 5 ports incorporate 10/100/1000 Mbps PHYs.
The other 2 ports have interfaces that can be configured as SGMII, RGMII, MII
or RMII. Either of these may connect directly to a host processor or
to an external PHY. The SGMII port may interface to a fiber optic transceiver.

This driver currently supports vlan, fdb, mdb & mirror dsa switch operations.

Reviewed-by: Florian Fainelli 
Signed-off-by: Woojung Huh 
---
 drivers/net/dsa/Kconfig |2 +
 drivers/net/dsa/Makefile|1 +
 drivers/net/dsa/microchip/Kconfig   |   12 +
 drivers/net/dsa/microchip/Makefile  |2 +
 drivers/net/dsa/microchip/ksz_9477_reg.h| 1676 +++
 drivers/net/dsa/microchip/ksz_common.c  | 1278 
 drivers/net/dsa/microchip/ksz_priv.h|  210 
 drivers/net/dsa/microchip/ksz_spi.c |  215 
 include/linux/platform_data/microchip-ksz.h |   29 +
 9 files changed, 3425 insertions(+)
 create mode 100644 drivers/net/dsa/microchip/Kconfig
 create mode 100644 drivers/net/dsa/microchip/Makefile
 create mode 100644 drivers/net/dsa/microchip/ksz_9477_reg.h
 create mode 100644 drivers/net/dsa/microchip/ksz_common.c
 create mode 100644 drivers/net/dsa/microchip/ksz_priv.h
 create mode 100644 drivers/net/dsa/microchip/ksz_spi.c
 create mode 100644 include/linux/platform_data/microchip-ksz.h

diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig
index 68131a4..83a9bc8 100644
--- a/drivers/net/dsa/Kconfig
+++ b/drivers/net/dsa/Kconfig
@@ -39,6 +39,8 @@ config NET_DSA_MV88E6060
  This enables support for the Marvell 88E6060 ethernet switch
  chip.
 
+source "drivers/net/dsa/microchip/Kconfig"
+
 source "drivers/net/dsa/mv88e6xxx/Kconfig"
 
 config NET_DSA_QCA8K
diff --git a/drivers/net/dsa/Makefile b/drivers/net/dsa/Makefile
index 9613f36..4a5b5bd 100644
--- a/drivers/net/dsa/Makefile
+++ b/drivers/net/dsa/Makefile
@@ -8,4 +8,5 @@ obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303_I2C) += lan9303_i2c.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303_MDIO) += lan9303_mdio.o
 obj-y  += b53/
+obj-y  += microchip/
 obj-y  += mv88e6xxx/
diff --git a/drivers/net/dsa/microchip/Kconfig 
b/drivers/net/dsa/microchip/Kconfig
new file mode 100644
index 000..a8b8f59
--- /dev/null
+++ b/drivers/net/dsa/microchip/Kconfig
@@ -0,0 +1,12 @@
+menuconfig MICROCHIP_KSZ
+   tristate "Microchip KSZ series switch support"
+   depends on NET_DSA
+   select NET_DSA_TAG_KSZ
+   help
+ This driver adds support for Microchip KSZ switch chips.
+
+config MICROCHIP_KSZ_SPI_DRIVER
+   tristate "KSZ series SPI connected switch driver"
+   depends on MICROCHIP_KSZ && SPI
+   help
+ Select to enable support for registering switches configured through 
SPI.
diff --git a/drivers/net/dsa/microchip/Makefile 
b/drivers/net/dsa/microchip/Makefile
new file mode 100644
index 000..ed335e2
--- /dev/null
+++ b/drivers/net/dsa/microchip/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_MICROCHIP_KSZ)+= ksz_common.o
+obj-$(CONFIG_MICROCHIP_KSZ_SPI_DRIVER) += ksz_spi.o
diff --git a/drivers/net/dsa/microchip/ksz_9477_reg.h 
b/drivers/net/dsa/microchip/ksz_9477_reg.h
new file mode 100644
index 000..6aa6752
--- /dev/null
+++ b/drivers/net/dsa/microchip/ksz_9477_reg.h
@@ -0,0 +1,1676 @@
+/*
+ * Microchip KSZ9477 register definitions
+ *
+ * Copyright (C) 2017
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef __KSZ9477_REGS_H
+#define __KSZ9477_REGS_H
+
+#define KS_PRIO_M  0x7
+#define KS_PRIO_S  4
+
+/* 0 - Operation */
+#define REG_CHIP_ID0__10x
+
+#define REG_CHIP_ID1__10x0001
+
+#define FAMILY_ID  0x95
+#define FAMILY_ID_94   0x94
+#define FAMILY_ID_95   0x95
+#define FAMILY_ID_85   0x85
+#define FAMILY_ID_98   0x98
+#define FAMILY_ID_88   

[PATCH v5 net-next 0/5] dsa: add Microchip KSZ9477 DSA driver

2017-05-30 Thread Woojung.Huh
From: Woojung Huh 

This series of patches is for Microchip KSZ9477 DSA driver.
KSZ9477 is 7 ports GigE switch with numerous advanced features.
5 ports are 10/100/1000 Mbps internal PHYs and 2 ports have
Interfaces to SGMII, RGMII, MII or RMII.

This patch supports VLAN, MDB, FDB and port mirroring offloads.

Welcome reviews and comments from community.

Note: Tests are performed on internal development board.

V5
- drivers/net/dsa/microchip/ksz_common.c
  * remove wrong mutex_unlock() in ksz_port_mdb_del()

V4
- update per review comments
- cosmetic changes
- net/dsa/tag_ksz.c
  * skb_put() & memset() are changed to skb_put_padto()
- drivers/net/dsa/microchip/ksz_common.
   * vlan access mutex is updated
   * mib_names[] is changed to static const

V3
- update per review comments
- cosmetic changes
- drivers/net/dsa/microchip/ksz_common.c 
  * clean up ksz_switch_chips[] 
  * consolidate checking loops into functions
  * update mutex for better locking
  * replace devm_kmalloc_array() to devm_kcalloc()
- MAINTAINERS
  * add missing net/dsa/tag_ksz.c

V2
- update per review comments
- several cosmetic changes
- net/dsa/tag_ksz.c
  * constants are changed to defines
  * remove skb_linearize() in ksz_rcv()
  * ksz_xmit()checks skb tailroom before allocate new skb
- drivers/net/phy/micrel.c
  * remove PHY_HAS_MAGICANEG from ksphy_driver[]
- drivers/net/dsa/microchip/ksz_common.c
  * add timeout to avoid endless loop
  * port initialization is move to ksz_port_enable() instead of  
ksz_setup_ports()
- Documentation/devicetree/bindings/net/dsa/ksz.txt
  * fix typo and indentations

Woojung Huh (5):
  dsa: add support for Microchip KSZ tail tagging
  phy: micrel: add Microchip KSZ 9477 Switch PHY support
  dsa: add DSA switch driver for Microchip KSZ9477
  net: dsa: Add Microchip KSZ switches binding
  dsa: add maintainer of Microchip KSZ switches

 Documentation/devicetree/bindings/net/dsa/ksz.txt |   72 +
 MAINTAINERS   |   10 +
 drivers/net/dsa/Kconfig   |2 +
 drivers/net/dsa/Makefile  |1 +
 drivers/net/dsa/microchip/Kconfig |   12 +
 drivers/net/dsa/microchip/Makefile|2 +
 drivers/net/dsa/microchip/ksz_9477_reg.h  | 1676 +
 drivers/net/dsa/microchip/ksz_common.c| 1278 
 drivers/net/dsa/microchip/ksz_priv.h  |  210 +++
 drivers/net/dsa/microchip/ksz_spi.c   |  215 +++
 drivers/net/phy/micrel.c  |   11 +
 include/linux/micrel_phy.h|2 +
 include/linux/platform_data/microchip-ksz.h   |   29 +
 include/net/dsa.h |1 +
 net/dsa/Kconfig   |3 +
 net/dsa/Makefile  |1 +
 net/dsa/dsa.c |3 +
 net/dsa/dsa_priv.h|3 +
 net/dsa/tag_ksz.c |  101 ++
 19 files changed, 3632 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/ksz.txt
 create mode 100644 drivers/net/dsa/microchip/Kconfig
 create mode 100644 drivers/net/dsa/microchip/Makefile
 create mode 100644 drivers/net/dsa/microchip/ksz_9477_reg.h
 create mode 100644 drivers/net/dsa/microchip/ksz_common.c
 create mode 100644 drivers/net/dsa/microchip/ksz_priv.h
 create mode 100644 drivers/net/dsa/microchip/ksz_spi.c
 create mode 100644 include/linux/platform_data/microchip-ksz.h
 create mode 100644 net/dsa/tag_ksz.c

-- 
2.7.4


RE: [PATCH v4 net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477

2017-05-30 Thread Woojung.Huh
Hi Andrew,
> > +static int ksz_port_mdb_del(struct dsa_switch *ds, int port,
> > +   const struct switchdev_obj_port_mdb *mdb)
> > +{
> > +   struct ksz_device *dev = ds->priv;
> > +   u32 static_table[4];
> > +   u32 data;
> > +   int index;
> > +   int ret = 0;
> > +   u32 mac_hi, mac_lo;
> > +
> > +   mac_hi = ((mdb->addr[0] << 8) | mdb->addr[1]);
> > +   mac_lo = ((mdb->addr[2] << 24) | (mdb->addr[3] << 16));
> > +   mac_lo |= ((mdb->addr[4] << 8) | mdb->addr[5]);
> > +
> > +   mutex_lock(>alu_mutex);
> > +
> > +   for (index = 0; index < dev->num_statics; index++) {
> > +   /* find empty slot first */
> > +   data = (index << ALU_STAT_INDEX_S) |
> > +   ALU_STAT_READ | ALU_STAT_START;
> > +   ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
> > +
> > +   /* wait to be finished */
> > +   ret = wait_alu_sta_ready(dev, ALU_STAT_START, 1000);
> > +   if (ret < 0) {
> > +   dev_dbg(dev->dev, "Failed to read ALU STATIC\n");
> > +   goto exit;
> > +   }
> > +
> > +   /* read ALU static table */
> > +   read_table(ds, static_table);
> > +
> > +   mutex_unlock(>alu_mutex);
> 
> Is this mutex unlock here correct? It looks like we will unlock it
> again when we eventually get to exit: below.
> 
Thanks for catching this. Will submit new patch soon.

- Woojung


[PATCH v4 net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477

2017-05-30 Thread Woojung.Huh
From: Woojung Huh 

The KSZ9477 is a fully integrated layer 2, managed, 7 ports GigE switch
with numerous advanced features. 5 ports incorporate 10/100/1000 Mbps PHYs.
The other 2 ports have interfaces that can be configured as SGMII, RGMII, MII
or RMII. Either of these may connect directly to a host processor or
to an external PHY. The SGMII port may interface to a fiber optic transceiver.

This driver currently supports vlan, fdb, mdb & mirror dsa switch operations.

Signed-off-by: Woojung Huh 
Reviewed-by: Florian Fainelli 
---
 drivers/net/dsa/Kconfig |2 +
 drivers/net/dsa/Makefile|1 +
 drivers/net/dsa/microchip/Kconfig   |   12 +
 drivers/net/dsa/microchip/Makefile  |2 +
 drivers/net/dsa/microchip/ksz_9477_reg.h| 1676 +++
 drivers/net/dsa/microchip/ksz_common.c  | 1280 
 drivers/net/dsa/microchip/ksz_priv.h|  210 
 drivers/net/dsa/microchip/ksz_spi.c |  215 
 include/linux/platform_data/microchip-ksz.h |   29 +
 9 files changed, 3427 insertions(+)
 create mode 100644 drivers/net/dsa/microchip/Kconfig
 create mode 100644 drivers/net/dsa/microchip/Makefile
 create mode 100644 drivers/net/dsa/microchip/ksz_9477_reg.h
 create mode 100644 drivers/net/dsa/microchip/ksz_common.c
 create mode 100644 drivers/net/dsa/microchip/ksz_priv.h
 create mode 100644 drivers/net/dsa/microchip/ksz_spi.c
 create mode 100644 include/linux/platform_data/microchip-ksz.h

diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig
index 68131a4..83a9bc8 100644
--- a/drivers/net/dsa/Kconfig
+++ b/drivers/net/dsa/Kconfig
@@ -39,6 +39,8 @@ config NET_DSA_MV88E6060
  This enables support for the Marvell 88E6060 ethernet switch
  chip.
 
+source "drivers/net/dsa/microchip/Kconfig"
+
 source "drivers/net/dsa/mv88e6xxx/Kconfig"
 
 config NET_DSA_QCA8K
diff --git a/drivers/net/dsa/Makefile b/drivers/net/dsa/Makefile
index 9613f36..4a5b5bd 100644
--- a/drivers/net/dsa/Makefile
+++ b/drivers/net/dsa/Makefile
@@ -8,4 +8,5 @@ obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303_I2C) += lan9303_i2c.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303_MDIO) += lan9303_mdio.o
 obj-y  += b53/
+obj-y  += microchip/
 obj-y  += mv88e6xxx/
diff --git a/drivers/net/dsa/microchip/Kconfig 
b/drivers/net/dsa/microchip/Kconfig
new file mode 100644
index 000..a8b8f59
--- /dev/null
+++ b/drivers/net/dsa/microchip/Kconfig
@@ -0,0 +1,12 @@
+menuconfig MICROCHIP_KSZ
+   tristate "Microchip KSZ series switch support"
+   depends on NET_DSA
+   select NET_DSA_TAG_KSZ
+   help
+ This driver adds support for Microchip KSZ switch chips.
+
+config MICROCHIP_KSZ_SPI_DRIVER
+   tristate "KSZ series SPI connected switch driver"
+   depends on MICROCHIP_KSZ && SPI
+   help
+ Select to enable support for registering switches configured through 
SPI.
diff --git a/drivers/net/dsa/microchip/Makefile 
b/drivers/net/dsa/microchip/Makefile
new file mode 100644
index 000..ed335e2
--- /dev/null
+++ b/drivers/net/dsa/microchip/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_MICROCHIP_KSZ)+= ksz_common.o
+obj-$(CONFIG_MICROCHIP_KSZ_SPI_DRIVER) += ksz_spi.o
diff --git a/drivers/net/dsa/microchip/ksz_9477_reg.h 
b/drivers/net/dsa/microchip/ksz_9477_reg.h
new file mode 100644
index 000..6aa6752
--- /dev/null
+++ b/drivers/net/dsa/microchip/ksz_9477_reg.h
@@ -0,0 +1,1676 @@
+/*
+ * Microchip KSZ9477 register definitions
+ *
+ * Copyright (C) 2017
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef __KSZ9477_REGS_H
+#define __KSZ9477_REGS_H
+
+#define KS_PRIO_M  0x7
+#define KS_PRIO_S  4
+
+/* 0 - Operation */
+#define REG_CHIP_ID0__10x
+
+#define REG_CHIP_ID1__10x0001
+
+#define FAMILY_ID  0x95
+#define FAMILY_ID_94   0x94
+#define FAMILY_ID_95   0x95
+#define FAMILY_ID_85   0x85
+#define FAMILY_ID_98   0x98
+#define FAMILY_ID_88   

[PATCH v4 net-next 5/5] dsa: add maintainer of Microchip KSZ switches

2017-05-30 Thread Woojung.Huh
From: Woojung Huh 

Adding maintainer of Microchip KSZ switches.

Signed-off-by: Woojung Huh 
Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 42378cf..0fcb5e75 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8479,6 +8479,16 @@ F:   drivers/media/platform/atmel/atmel-isc.c
 F: drivers/media/platform/atmel/atmel-isc-regs.h
 F: devicetree/bindings/media/atmel-isc.txt
 
+MICROCHIP KSZ SERIES ETHERNET SWITCH DRIVER
+M: Woojung Huh 
+M: Microchip Linux Driver Support 
+L: netdev@vger.kernel.org
+S: Maintained
+F: net/dsa/tag_ksz.c
+F: drivers/net/dsa/microchip/*
+F: include/linux/platform_data/microchip-ksz.h
+F: Documentation/devicetree/bindings/net/dsa/ksz.txt
+
 MICROCHIP USB251XB DRIVER
 M: Richard Leitner 
 L: linux-...@vger.kernel.org
-- 
2.7.4



[PATCH v4 net-next 4/5] net: dsa: Add Microchip KSZ switches binding

2017-05-30 Thread Woojung.Huh
From: Woojung Huh 

A sample SPI configuration for Microchip KSZ switches.

Signed-off-by: Woojung Huh 
Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
---
 Documentation/devicetree/bindings/net/dsa/ksz.txt | 72 +++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/ksz.txt

diff --git a/Documentation/devicetree/bindings/net/dsa/ksz.txt 
b/Documentation/devicetree/bindings/net/dsa/ksz.txt
new file mode 100644
index 000..9acdb6c
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/dsa/ksz.txt
@@ -0,0 +1,72 @@
+Microchip KSZ Series Ethernet switches
+==
+
+Required properties:
+
+- compatible: For external switch chips, compatible string must be exactly one
+  of: "microchip,ksz9477"
+
+See Documentation/devicetree/bindings/dsa/dsa.txt for a list of additional
+required and optional properties.
+
+Examples:
+
+Ethernet switch connected via SPI to the host, CPU port wired to eth0:
+
+   eth0: ethernet@10001000 {
+   fixed-link {
+   speed = <1000>;
+   full-duplex;
+   };
+   };
+
+   spi1: spi@f8008000 {
+   pinctrl-0 = <_spi_ksz>;
+   cs-gpios = < 25 0>;
+   id = <1>;
+   status = "okay";
+
+   ksz9477: ksz9477@0 {
+   compatible = "microchip,ksz9477";
+   reg = <0>;
+
+   spi-max-frequency = <4400>;
+   spi-cpha;
+   spi-cpol;
+
+   status = "okay";
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   port@0 {
+   reg = <0>;
+   label = "lan1";
+   };
+   port@1 {
+   reg = <1>;
+   label = "lan2";
+   };
+   port@2 {
+   reg = <2>;
+   label = "lan3";
+   };
+   port@3 {
+   reg = <3>;
+   label = "lan4";
+   };
+   port@4 {
+   reg = <4>;
+   label = "lan5";
+   };
+   port@5 {
+   reg = <5>;
+   label = "cpu";
+   ethernet = <>;
+   fixed-link {
+   speed = <1000>;
+   full-duplex;
+   };
+   };
+   };
+   };
+   };
-- 
2.7.4



[PATCH v4 net-next 2/5] phy: micrel: add Microchip KSZ 9477 Switch PHY support

2017-05-30 Thread Woojung.Huh
From: Woojung Huh 

Adding Microchip 9477 Phy included in KSZ9477 Switch.

Signed-off-by: Woojung Huh 
Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
---
 drivers/net/phy/micrel.c   | 11 +++
 include/linux/micrel_phy.h |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 4cfd541..46e80bc 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -20,6 +20,7 @@
  *ksz8081, ksz8091,
  *ksz8061,
  * Switch : ksz8873, ksz886x
+ *  ksz9477
  */
 
 #include 
@@ -996,6 +997,16 @@ static struct phy_driver ksphy_driver[] = {
.read_status= ksz8873mll_read_status,
.suspend= genphy_suspend,
.resume = genphy_resume,
+}, {
+   .phy_id = PHY_ID_KSZ9477,
+   .phy_id_mask= MICREL_PHY_ID_MASK,
+   .name   = "Microchip KSZ9477",
+   .features   = PHY_GBIT_FEATURES,
+   .config_init= kszphy_config_init,
+   .config_aneg= genphy_config_aneg,
+   .read_status= genphy_read_status,
+   .suspend= genphy_suspend,
+   .resume = genphy_resume,
 } };
 
 module_phy_driver(ksphy_driver);
diff --git a/include/linux/micrel_phy.h b/include/linux/micrel_phy.h
index f541da6..472fa4d 100644
--- a/include/linux/micrel_phy.h
+++ b/include/linux/micrel_phy.h
@@ -37,6 +37,8 @@
 
 #define PHY_ID_KSZ8795 0x00221550
 
+#definePHY_ID_KSZ9477  0x00221631
+
 /* struct phy_device dev_flags definitions */
 #define MICREL_PHY_50MHZ_CLK   0x0001
 #define MICREL_PHY_FXEN0x0002
-- 
2.7.4



[PATCH v4 net-next 1/5] dsa: add support for Microchip KSZ tail tagging

2017-05-30 Thread Woojung.Huh
From: Woojung Huh 

Adding support for the Microchip KSZ switch family tail tagging.

Signed-off-by: Woojung Huh 
Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
---
 include/net/dsa.h  |   1 +
 net/dsa/Kconfig|   3 ++
 net/dsa/Makefile   |   1 +
 net/dsa/dsa.c  |   3 ++
 net/dsa/dsa_priv.h |   3 ++
 net/dsa/tag_ksz.c  | 101 +
 6 files changed, 112 insertions(+)
 create mode 100644 net/dsa/tag_ksz.c

diff --git a/include/net/dsa.h b/include/net/dsa.h
index c0e567c..42c28ae 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -31,6 +31,7 @@ enum dsa_tag_protocol {
DSA_TAG_PROTO_BRCM,
DSA_TAG_PROTO_DSA,
DSA_TAG_PROTO_EDSA,
+   DSA_TAG_PROTO_KSZ,
DSA_TAG_PROTO_LAN9303,
DSA_TAG_PROTO_MTK,
DSA_TAG_PROTO_QCA,
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index 297389b..cc5f8f9 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -25,6 +25,9 @@ config NET_DSA_TAG_DSA
 config NET_DSA_TAG_EDSA
bool
 
+config NET_DSA_TAG_KSZ
+   bool
+
 config NET_DSA_TAG_LAN9303
bool
 
diff --git a/net/dsa/Makefile b/net/dsa/Makefile
index 90e5aa6..fcce25d 100644
--- a/net/dsa/Makefile
+++ b/net/dsa/Makefile
@@ -6,6 +6,7 @@ dsa_core-y += dsa.o dsa2.o legacy.o port.o slave.o switch.o
 dsa_core-$(CONFIG_NET_DSA_TAG_BRCM) += tag_brcm.o
 dsa_core-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o
 dsa_core-$(CONFIG_NET_DSA_TAG_EDSA) += tag_edsa.o
+dsa_core-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
 dsa_core-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
 dsa_core-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
 dsa_core-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 3288a80..402459e 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -49,6 +49,9 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
 #ifdef CONFIG_NET_DSA_TAG_EDSA
[DSA_TAG_PROTO_EDSA] = _netdev_ops,
 #endif
+#ifdef CONFIG_NET_DSA_TAG_KSZ
+   [DSA_TAG_PROTO_KSZ] = _netdev_ops,
+#endif
 #ifdef CONFIG_NET_DSA_TAG_LAN9303
[DSA_TAG_PROTO_LAN9303] = _netdev_ops,
 #endif
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index c1d4180..7459d57 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -167,6 +167,9 @@ extern const struct dsa_device_ops dsa_netdev_ops;
 /* tag_edsa.c */
 extern const struct dsa_device_ops edsa_netdev_ops;
 
+/* tag_ksz.c */
+extern const struct dsa_device_ops ksz_netdev_ops;
+
 /* tag_lan9303.c */
 extern const struct dsa_device_ops lan9303_netdev_ops;
 
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
new file mode 100644
index 000..0b08a40
--- /dev/null
+++ b/net/dsa/tag_ksz.c
@@ -0,0 +1,101 @@
+/*
+ * net/dsa/tag_ksz.c - Microchip KSZ Switch tag format handling
+ * Copyright (c) 2017 Microchip Technology
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "dsa_priv.h"
+
+/* For Ingress (Host -> KSZ), 2 bytes are added before FCS.
+ * ---
+ * DA(6bytes)|SA(6bytes)||Data(nbytes)|tag0(1byte)|tag1(1byte)|FCS(4bytes)
+ * ---
+ * tag0 : Prioritization (not used now)
+ * tag1 : each bit represents port (eg, 0x01=port1, 0x02=port2, 0x10=port5)
+ *
+ * For Egress (KSZ -> Host), 1 byte is added before FCS.
+ * ---
+ * DA(6bytes)|SA(6bytes)||Data(nbytes)|tag0(1byte)|FCS(4bytes)
+ * ---
+ * tag0 : zero-based value represents port
+ *   (eg, 0x00=port1, 0x02=port3, 0x06=port7)
+ */
+
+#defineKSZ_INGRESS_TAG_LEN 2
+#defineKSZ_EGRESS_TAG_LEN  1
+
+static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+   struct dsa_slave_priv *p = netdev_priv(dev);
+   struct sk_buff *nskb;
+   int padlen;
+   u8 *tag;
+
+   padlen = (skb->len >= ETH_ZLEN) ? 0 : ETH_ZLEN - skb->len;
+
+   if (skb_tailroom(skb) >= padlen + KSZ_INGRESS_TAG_LEN) {
+   nskb = skb;
+   } else {
+   nskb = alloc_skb(NET_IP_ALIGN + skb->len +
+padlen + KSZ_INGRESS_TAG_LEN, GFP_ATOMIC);
+   if (!nskb) {
+   kfree_skb(skb);
+   return NULL;
+   }
+   skb_reserve(nskb, NET_IP_ALIGN);
+
+   skb_reset_mac_header(nskb);
+   skb_set_network_header(nskb,
+  skb_network_header(skb) - 

RE: [PATCH net-next 1/3] net: phy: Create sysfs reciprocal links for attached_dev/phydev

2017-05-26 Thread Woojung.Huh
> @@ -960,6 +960,15 @@ int phy_attach_direct(struct net_device *dev, struct
> phy_device *phydev,
> 
>   phydev->attached_dev = dev;
>   dev->phydev = phydev;
> + err = sysfs_create_link(>mdio.dev.kobj, >dev.kobj,
> + "attached_dev");
> + if (err)
> + goto error;
> +
> + err = sysfs_create_link(>dev.kobj, >mdio.dev.kobj,
> + "phydev");
> + if (err)
> + goto error;
> 
Florian,

I knew that it is applied to net-next.
However, sysfs_create_link() fails when fixed phy (drivers/net/phy/fixed_phy.c)
Do you have a chance to test with it?

- Woojung


RE: [PATCH net-next 1/3] net: phy: Create sysfs reciprocal links for attached_dev/phydev

2017-05-26 Thread Woojung.Huh
Hi Florian,

> > I knew that it is applied to net-next.
> > However, sysfs_create_link() fails when fixed phy
> (drivers/net/phy/fixed_phy.c)
> > Do you have a chance to test with it?
> 
> I did, my main test system (BCM7445 w/ bcm_sf2) has one normal PHY
> driver and 3 fixed PHYs (including one for the CPU port/master netdev),
> see below.
> 
> What kind of error do you get here?
sysfs_create_link() returns -2 (-ENOENT).

> 
> # ls -l /sys/class/net/gphy/phydev
> lrwxrwxrwx1 root root 0 Jan  1 00:00
> /sys/class/net/gphy/phydev ->
> ../../../f0b403c0.mdio/mdio_bus/f0b403c0.mdio/f0b403c0.mdio:05
> # ls -l /sys/class/net/*/phydev
> lrwxrwxrwx1 root root 0 Jan  1 00:01
> /sys/class/net/eth0/phydev -> ../../../../Fixed MDIO
> bus.0/mdio_bus/fixed-0/fixed-0:00
> lrwxrwxrwx1 root root 0 Jan  1 00:00
> /sys/class/net/gphy/phydev ->
> ../../../f0b403c0.mdio/mdio_bus/f0b403c0.mdio/f0b403c0.mdio:05
> lrwxrwxrwx1 root root 0 Jan  1 00:01
> /sys/class/net/moca/phydev -> ../../../../../Fixed MDIO
> bus.0/mdio_bus/fixed-0/fixed-0:02
> lrwxrwxrwx1 root root 0 Jan  1 00:01
> /sys/class/net/rgmii_1/phydev -> ../../../mdio_bus/sf2-1/sf2-1:00
> lrwxrwxrwx1 root root 0 Jan  1 00:01
> /sys/class/net/rgmii_2/phydev -> ../../../../../Fixed MDIO
> bus.0/mdio_bus/fixed-0/fixed-0:01
> 
> # ls -l /sys/class/mdio_bus/fixed-0/*/attached_dev
> lrwxrwxrwx1 root root 0 Jan  1 00:01
> /sys/class/mdio_bus/fixed-0/fixed-0:00/attached_dev ->
> ../../../../rdb/f04a.ethernet/net/eth0
> lrwxrwxrwx1 root root 0 Jan  1 00:02
> /sys/class/mdio_bus/fixed-0/fixed-0:01/attached_dev ->
> ../../../../rdb/rdb:switch_top@f0b0/f0b0.ethernet_switch/net/rgm
> ii_2
> lrwxrwxrwx1 root root 0 Jan  1 00:02
> /sys/class/mdio_bus/fixed-0/fixed-0:02/attached_dev ->
> ../../../../rdb/rdb:switch_top@f0b0/f0b0.ethernet_switch/net/moc
> a
> 
> # ls -l /sys/class/mdio_bus/f0b403c0.mdio/f0b403c0.mdio\:05/attached_dev
> lrwxrwxrwx1 root root 0 Jan  1 00:02
> /sys/class/mdio_bus/f0b403c0.mdio/f0b403c0.mdio:05/attached_dev ->
> ../../../../f0b0.ethernet_switch/net/gphy

/sys/class/mdio_bus/devices/fixed-0:00/* exists.
But not /sys/class/net/eth0.. because Ethernet driver initialization failed.

- Woojung


RE: [PATCH net-next 1/3] net: phy: Create sysfs reciprocal links for attached_dev/phydev

2017-05-26 Thread Woojung.Huh
> OK, I am confused now. You are describing what is going on with your
> platform right? Can you describe a bit further here what is happening
> and with which type of interface? Is this with the CPU interface or
> something?

Yes. It's on our platform.
Like your platform, fixed phy is used to connect switch CPU port/master netdev.
GMAC of SoC is cadence/macb.c with fixed phy modification.

static int macb_mii_probe(struct net_device *dev)
{
...
phydev = phy_find_first(bp->mii_bus);
if (!phydev) {
phydev = fixed_phy_register(PHY_POLL, _status, -1, NULL);
if (IS_ERR(phydev)) {
netdev_err(dev, "no PHY found\n");
return -ENXIO;
}
}
...
When failed to find phydev from phy_find_first(), it forces to fixed phy.
...
/* attach the mac to the phy */
ret = phy_connect_direct(dev, phydev, _handle_link_change,
 bp->phy_interface);

sysfs_create_lin() inside of phy_connect_direct() fails.

What is driver you are testing? I can check the file.

Thanks.
- Woojung



RE: [PATCH net-next 1/3] net: phy: Create sysfs reciprocal links for attached_dev/phydev

2017-05-26 Thread Woojung.Huh
Hi Florian,
 
> OK, so here is what is happening: macb_mii_init() calls macb_mii_probe()
> and so by the time we call phy_connect_direct(), we have not called
> register_netdevice() yet, netdev_register_kobject() has not been called
> either, and so sysfs_create_link() fails
I just found same thing.
Yes, register_netdev() was not called at phy_connect_direct() time. 

> Let me think about a way to solve that, even though I am leaning towards
> ignoring the errors from sysfs_create_link() rather than fixing each and
> every Ethernet driver to make it probe its MII bus *after* calling
> register_netdevice()
Agree.
 
> >
> > What is driver you are testing? I can check the file.
> 
> Drivers involved are the following:
> 
> drivers/net/ethernet/broadcom/bcmsysport.c,
> drivers/net/dsa/bcm_sf2.c
> drivers/net/ethernet/broadcom/genet/
> drivers/net/phy/bcm7xxx.c
Thanks for list of files.

- Woojung


RE: [PATCH net-next 1/3] net: phy: Create sysfs reciprocal links for attached_dev/phydev

2017-05-26 Thread Woojung.Huh
Hi Florian,
> >> OK, so here is what is happening: macb_mii_init() calls macb_mii_probe()
> >> and so by the time we call phy_connect_direct(), we have not called
> >> register_netdevice() yet, netdev_register_kobject() has not been called
> >> either, and so sysfs_create_link() fails
> > I just found same thing.
> > Yes, register_netdev() was not called at phy_connect_direct() time.
> >
> >> Let me think about a way to solve that, even though I am leaning towards
> >> ignoring the errors from sysfs_create_link() rather than fixing each and
> >> every Ethernet driver to make it probe its MII bus *after* calling
> >> register_netdevice()
> > Agree.
> 
> Thanks, would the following work for you? I don't want to do something
> more complex than that, although, if we really wanted to see this
> information, we could imagine having netdev_register_kobject() check
> whether phydev->dev.kobj is valid, and set the symbolic link at that
> point... The problem with that approach is that we are no longer
> symetrical within the core PHYLIB code (phy_attach_direct and phy_detach).
>
> Let me know if this works so I can make a formal submission:
> 
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index f84414b8f2ee..daad816ee1d1 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -960,14 +960,20 @@ int phy_attach_direct(struct net_device *dev,
> struct phy_device *phydev,
> 
> phydev->attached_dev = dev;
> dev->phydev = phydev;
> +
> +   /* Some Ethernet drivers try to connect to a PHY device before
> +* calling register_netdevice(). register_netdevice() does
> ultimately
> +* lead to netdev_register_kobject() which would do the
> dev->dev.kobj
> +* initialization. Here we explicitly ignore those particular errors
> +*/
> err = sysfs_create_link(>mdio.dev.kobj, >dev.kobj,
> "attached_dev");
> -   if (err)
> +   if (err && err != -ENOENT)
> goto error;
This one fine. However, next one returns -14 (-EFAULT)

> err = sysfs_create_link(>dev.kobj, >mdio.dev.kobj,
> "phydev");
> -   if (err)
> +   if (err && err != -ENOENT)
> goto error;
No need to call 2nd sysfs_create_link(), how about following?

err = sysfs_create_link(>mdio.dev.kobj, >dev.kobj,
"attached_dev");
-   if (err)
+   if (err && err != -ENOENT)
goto error;
 
-   err = sysfs_create_link(>dev.kobj, >mdio.dev.kobj,
-   "phydev");
-   if (err)
-   goto error;
+   if (!err) {
+   err = sysfs_create_link(>dev.kobj, >mdio.dev.kobj,
+   "phydev");
+   if (err)
+   goto error;
+   }
 
phydev->dev_flags = flags;

- Woojung


RE: [PATCH net-next 1/3] net: phy: Create sysfs reciprocal links for attached_dev/phydev

2017-05-26 Thread Woojung.Huh
> 
> Yes, that's a very valid point, how about we even do this:
> 
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index f84414b8f2ee..dc666ec13651 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -960,15 +960,21 @@ int phy_attach_direct(struct net_device *dev,
> struct phy_device *phydev,
> 
> phydev->attached_dev = dev;
> dev->phydev = phydev;
> +
> +   /* Some Ethernet drivers try to connect to a PHY device before
> +* calling register_netdevice() -> netdev_register_kobject() and
> +* does the dev->dev.kobj initialization. Here we only check for
> +* success which indicates that the network device kobject is
> +* ready.
> +*/
> err = sysfs_create_link(>mdio.dev.kobj, >dev.kobj,
> "attached_dev");
> -   if (err)
> -   goto error;
> -
> -   err = sysfs_create_link(>dev.kobj, >mdio.dev.kobj,
> -   "phydev");
> -   if (err)
> -   goto error;
> +   if (!err) {
> +   err = sysfs_create_link(>dev.kobj,
> >mdio.dev.kobj,
> +   "phydev");
> +   if (err)
> +   goto error;
> +   }
> 
> phydev->dev_flags = flags;
> 
Looks better and clean.

How about sysfs_remove_link() in phy_detach()?

- Woojung


RE: [PATCH v3 net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477

2017-05-22 Thread Woojung.Huh
> > > > +static int get_vlan_table(struct dsa_switch *ds, u16 vid, u32
> *vlan_table)
> > > > +{
> > > > +   struct ksz_device *dev = ds->priv;
> > > > +   u8 data;
> > > > +   int timeout = 1000;
> > > > +
> > > > +   ksz_write16(dev, REG_SW_VLAN_ENTRY_INDEX__2, vid &
> > > VLAN_INDEX_M);
> > > > +   ksz_write8(dev, REG_SW_VLAN_CTRL, VLAN_READ | VLAN_START);
> > > > +
> > > > +   /* wait to be cleared */
> > > > +   data = 0;
> > > > +   do {
> > > > +   ksz_read8(dev, REG_SW_VLAN_CTRL, );
> > > > +   if (!(data & VLAN_START))
> > > > +   break;
> > > > +   usleep_range(1, 10);
> > > > +   } while (timeout-- > 0);
> > > > +
> > > > +   if (!timeout)
> > > > +   return -ETIMEDOUT;
> > > > +
> > > > +   ksz_read32(dev, REG_SW_VLAN_ENTRY__4, _table[0]);
> > > > +   ksz_read32(dev, REG_SW_VLAN_ENTRY_UNTAG__4,
> > > _table[1]);
> > > > +   ksz_read32(dev, REG_SW_VLAN_ENTRY_PORTS__4, _table[2]);
> > > > +
> > > > +   ksz_write8(dev, REG_SW_VLAN_CTRL, 0);
> > > > +
> > > > +   return 0;
> > > > +}
> > > > +
> > > > +static int set_vlan_table(struct dsa_switch *ds, u16 vid, u32
> *vlan_table)
> > > > +{
> > > > +   struct ksz_device *dev = ds->priv;
> > > > +   u8 data;
> > > > +   int timeout = 1000;
> > > > +
> > > > +   ksz_write32(dev, REG_SW_VLAN_ENTRY__4, vlan_table[0]);
> > > > +   ksz_write32(dev, REG_SW_VLAN_ENTRY_UNTAG__4, vlan_table[1]);
> > > > +   ksz_write32(dev, REG_SW_VLAN_ENTRY_PORTS__4, vlan_table[2]);
> > > > +
> > > > +   ksz_write16(dev, REG_SW_VLAN_ENTRY_INDEX__2, vid &
> > > VLAN_INDEX_M);
> > > > +   ksz_write8(dev, REG_SW_VLAN_CTRL, VLAN_START | VLAN_WRITE);
> > > > +
> > > > +   do {
> > > > +   ksz_read8(dev, REG_SW_VLAN_CTRL, );
> > > > +   if (!(data & VLAN_START))
> > > > +   break;
> > > > +   usleep_range(1, 10);
> > > > +   } while (timeout-- > 0);
> > > > +
> > > > +   if (!timeout)
> > > > +   return -ETIMEDOUT;
> > > > +
> > > > +   ksz_write8(dev, REG_SW_VLAN_CTRL, 0);
> > > > +
> > > > +   mutex_lock(>vlancache_mutex);
> > >
> > > Humm. I think this is wrong. Shouldn't you hold the mutex while you
> > > change the hardware as well as the cache. Otherwise there is a risk
> > > your cache could be different to the hardware when you get a race
> > > between two threads?
> > Thanks for pointing this out.
> > Rather than two separate mutex (H/W and vlancache), will put one HW
> access mutex
> > around get_vlan_table and set_vlan_table to cover vlancache access too.
> Even though
> > little bit overhead. How do you think?
> 
> I would move the mutex_lock(>vlancache_mutex) to be beginning of
> the function. It then protects both the hardware and the vlan cache,
> and keeps them synchronised.
> 
Andrew,

I believe mutex is needed in get_vlan_table() too.
vlancache_mutex doesn't match exactly what it does, I would change name to
vlan_mutex.

Thanks.
- Woojung


RE: [PATCH v3 net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477

2017-05-22 Thread Woojung.Huh
Hi Andres,

> > +static struct {
> > +   int index;
> > +   char string[ETH_GSTRING_LEN];
> 
> Hi Woojung
> 
> Since you need to respin for the skb_put_padto(), please make this
> const.
OK.

> > +static int get_vlan_table(struct dsa_switch *ds, u16 vid, u32 *vlan_table)
> > +{
> > +   struct ksz_device *dev = ds->priv;
> > +   u8 data;
> > +   int timeout = 1000;
> > +
> > +   ksz_write16(dev, REG_SW_VLAN_ENTRY_INDEX__2, vid &
> VLAN_INDEX_M);
> > +   ksz_write8(dev, REG_SW_VLAN_CTRL, VLAN_READ | VLAN_START);
> > +
> > +   /* wait to be cleared */
> > +   data = 0;
> > +   do {
> > +   ksz_read8(dev, REG_SW_VLAN_CTRL, );
> > +   if (!(data & VLAN_START))
> > +   break;
> > +   usleep_range(1, 10);
> > +   } while (timeout-- > 0);
> > +
> > +   if (!timeout)
> > +   return -ETIMEDOUT;
> > +
> > +   ksz_read32(dev, REG_SW_VLAN_ENTRY__4, _table[0]);
> > +   ksz_read32(dev, REG_SW_VLAN_ENTRY_UNTAG__4,
> _table[1]);
> > +   ksz_read32(dev, REG_SW_VLAN_ENTRY_PORTS__4, _table[2]);
> > +
> > +   ksz_write8(dev, REG_SW_VLAN_CTRL, 0);
> > +
> > +   return 0;
> > +}
> > +
> > +static int set_vlan_table(struct dsa_switch *ds, u16 vid, u32 *vlan_table)
> > +{
> > +   struct ksz_device *dev = ds->priv;
> > +   u8 data;
> > +   int timeout = 1000;
> > +
> > +   ksz_write32(dev, REG_SW_VLAN_ENTRY__4, vlan_table[0]);
> > +   ksz_write32(dev, REG_SW_VLAN_ENTRY_UNTAG__4, vlan_table[1]);
> > +   ksz_write32(dev, REG_SW_VLAN_ENTRY_PORTS__4, vlan_table[2]);
> > +
> > +   ksz_write16(dev, REG_SW_VLAN_ENTRY_INDEX__2, vid &
> VLAN_INDEX_M);
> > +   ksz_write8(dev, REG_SW_VLAN_CTRL, VLAN_START | VLAN_WRITE);
> > +
> > +   do {
> > +   ksz_read8(dev, REG_SW_VLAN_CTRL, );
> > +   if (!(data & VLAN_START))
> > +   break;
> > +   usleep_range(1, 10);
> > +   } while (timeout-- > 0);
> > +
> > +   if (!timeout)
> > +   return -ETIMEDOUT;
> > +
> > +   ksz_write8(dev, REG_SW_VLAN_CTRL, 0);
> > +
> > +   mutex_lock(>vlancache_mutex);
> 
> Humm. I think this is wrong. Shouldn't you hold the mutex while you
> change the hardware as well as the cache. Otherwise there is a risk
> your cache could be different to the hardware when you get a race
> between two threads?
Thanks for pointing this out.
Rather than two separate mutex (H/W and vlancache), will put one HW access mutex
around get_vlan_table and set_vlan_table to cover vlancache access too. Even 
though
little bit overhead. How do you think?

- Woojung


RE: [PATCH v3 net-next 2/5] phy: micrel: add Microchip KSZ 9477 Switch PHY support

2017-05-22 Thread Woojung.Huh
> > Signed-off-by: Woojung Huh 
> > Signed-off-by: Andrew Lunn 
> 
> Signed-off-by? I didn't contribute any code. It probably should be
> 
> Reviewed-by: Andrew Lunn 
Andrew,

Your reply on 5/13 was with "Signed-off" :)
Will change to "Reviewed-by" in next patch.

Woojung


RE: [PATCH v3 net-next 1/5] dsa: add support for Microchip KSZ tail tagging

2017-05-19 Thread Woojung.Huh
>> + if (padlen) {
>> + u8 *pad = skb_put(nskb, padlen);
>> +
>> + memset(pad, 0, padlen);
>> + }
>
>Can you use skb_put_padto() here instead of open coding this?
>
>> +
>> + tag = skb_put(nskb, KSZ_INGRESS_TAG_LEN);
>> + tag[0] = 0;
>> + tag[1] = 1 << p->dp->index; /* destnation port */
>
>typo: destination port
>
>With that fixed:
>
>Reviewed-by: Florian Fainelli 
HI Florian,

Thanks for prompt reviews. Will submit another version.

- Woojung


[PATCH v3 net-next 5/5] dsa: add maintainer of Microchip KSZ switches

2017-05-19 Thread Woojung.Huh
From: Woojung Huh 

Adding maintainer of Microchip KSZ switches.

Signed-off-by: Woojung Huh 
Reviewed-by: Andrew Lunn 
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index f7d568b..a72b40c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8454,6 +8454,16 @@ F:   drivers/media/platform/atmel/atmel-isc.c
 F: drivers/media/platform/atmel/atmel-isc-regs.h
 F: devicetree/bindings/media/atmel-isc.txt
 
+MICROCHIP KSZ SERIES ETHERNET SWITCH DRIVER
+M: Woojung Huh 
+M: Microchip Linux Driver Support 
+L: netdev@vger.kernel.org
+S: Maintained
+F: net/dsa/tag_ksz.c
+F: drivers/net/dsa/microchip/*
+F: include/linux/platform_data/microchip-ksz.h
+F: Documentation/devicetree/bindings/net/dsa/ksz.txt
+
 MICROCHIP USB251XB DRIVER
 M: Richard Leitner 
 L: linux-...@vger.kernel.org
-- 
2.7.4



[PATCH v3 net-next 4/5] dsa: Add spi support to Microchip KSZ switches

2017-05-19 Thread Woojung.Huh
From: Woojung Huh 

A sample SPI configuration for Microchip KSZ switches.

Signed-off-by: Woojung Huh 
Reviewed-by: Andrew Lunn 
---
 Documentation/devicetree/bindings/net/dsa/ksz.txt | 73 +++
 1 file changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/ksz.txt

diff --git a/Documentation/devicetree/bindings/net/dsa/ksz.txt 
b/Documentation/devicetree/bindings/net/dsa/ksz.txt
new file mode 100644
index 000..8a13966
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/dsa/ksz.txt
@@ -0,0 +1,73 @@
+Microchip KSZ Series Ethernet switches
+==
+
+Required properties:
+
+- compatible: For external switch chips, compatible string must be exactly one
+  of: "microchip,ksz9477"
+
+See Documentation/devicetree/bindings/dsa/dsa.txt for a list of additional
+required and optional properties.
+
+Examples:
+
+Ethernet switch connected via SPI to the host, CPU port wired to eth0:
+
+   eth0: ethernet@10001000 {
+   fixed-link {
+   reg = <7>
+   speed = <1000>;
+   duplex-full;
+   };
+   };
+
+   spi1: spi@f8008000 {
+   pinctrl-0 = <_spi_ksz>;
+   cs-gpios = < 25 0>;
+   id = <1>;
+   status = "okay";
+
+   ksz9477: ksz9477@0 {
+   compatible = "microchip,ksz9477";
+   reg = <0>;
+
+   spi-max-frequency = <4400>;
+   spi-cpha;
+   spi-cpol;
+
+   status = "okay";
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   port@0 {
+   reg = <0>;
+   label = "lan1";
+   };
+   port@1 {
+   reg = <1>;
+   label = "lan2";
+   };
+   port@2 {
+   reg = <2>;
+   label = "lan3";
+   };
+   port@3 {
+   reg = <3>;
+   label = "lan4";
+   };
+   port@4 {
+   reg = <4>;
+   label = "lan5";
+   };
+   port@5 {
+   reg = <5>;
+   label = "cpu";
+   ethernet = <>;
+   fixed-link {
+   speed = <1000>;
+   full-duplex;
+   };
+   };
+   };
+   };
+   };
-- 
2.7.4



[PATCH v3 net-next 2/5] phy: micrel: add Microchip KSZ 9477 Switch PHY support

2017-05-19 Thread Woojung.Huh
From: Woojung Huh 

Adding Microchip 9477 Phy included in KSZ9477 Switch.

Signed-off-by: Woojung Huh 
Signed-off-by: Andrew Lunn 
---
 drivers/net/phy/micrel.c   | 11 +++
 include/linux/micrel_phy.h |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 4cfd541..46e80bc 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -20,6 +20,7 @@
  *ksz8081, ksz8091,
  *ksz8061,
  * Switch : ksz8873, ksz886x
+ *  ksz9477
  */
 
 #include 
@@ -996,6 +997,16 @@ static struct phy_driver ksphy_driver[] = {
.read_status= ksz8873mll_read_status,
.suspend= genphy_suspend,
.resume = genphy_resume,
+}, {
+   .phy_id = PHY_ID_KSZ9477,
+   .phy_id_mask= MICREL_PHY_ID_MASK,
+   .name   = "Microchip KSZ9477",
+   .features   = PHY_GBIT_FEATURES,
+   .config_init= kszphy_config_init,
+   .config_aneg= genphy_config_aneg,
+   .read_status= genphy_read_status,
+   .suspend= genphy_suspend,
+   .resume = genphy_resume,
 } };
 
 module_phy_driver(ksphy_driver);
diff --git a/include/linux/micrel_phy.h b/include/linux/micrel_phy.h
index f541da6..472fa4d 100644
--- a/include/linux/micrel_phy.h
+++ b/include/linux/micrel_phy.h
@@ -37,6 +37,8 @@
 
 #define PHY_ID_KSZ8795 0x00221550
 
+#definePHY_ID_KSZ9477  0x00221631
+
 /* struct phy_device dev_flags definitions */
 #define MICREL_PHY_50MHZ_CLK   0x0001
 #define MICREL_PHY_FXEN0x0002
-- 
2.7.4



[PATCH v3 net-next 0/5] dsa: add Microchip KSZ9477 DSA driver

2017-05-19 Thread Woojung.Huh
From: Woojung Huh 

This series of patches is for Microchip KSZ9477 DSA driver.
KSZ9477 is 7 ports GigE switch with numerous advanced features.
5 ports are 10/100/1000 Mbps internal PHYs and 2 ports have
Interfaces to SGMII, RGMII, MII or RMII.

This patch supports VLAN, MDB, FDB and port mirroring offloads.

Welcome reviews and comments from community.

Note: Tests are performed on internal development board.

V3
- update per review comments
- cosmetic changes
- drivers/net/dsa/microchip/ksz_common.c 
  * clean up ksz_switch_chips[] 
  * consolidate checking loops into functions
  * update mutex for better locking
  * replace devm_kmalloc_array() to devm_kcalloc()
- MAINTAINERS
  * add missing net/dsa/tag_ksz.c

V2
- update per review comments
- several cosmetic changes
- net/dsa/tag_ksz.c
  * constants are changed to defines
  * remove skb_linearize() in ksz_rcv()
  * ksz_xmit()checks skb tailroom before allocate new skb
- drivers/net/phy/micrel.c
  * remove PHY_HAS_MAGICANEG from ksphy_driver[]
- drivers/net/dsa/microchip/ksz_common.c
  * add timeout to avoid endless loop
  * port initialization is move to ksz_port_enable() instead of  
ksz_setup_ports()
- Documentation/devicetree/bindings/net/dsa/ksz.txt
  * fix typo and indentations

Woojung Huh (5):
  dsa: add support for Microchip KSZ tail tagging
  phy: micrel: add Microchip KSZ 9477 Switch PHY support
  dsa: add DSA switch driver for Microchip KSZ9477
  dsa: Add spi support to Microchip KSZ switches
  dsa: add maintainer of Microchip KSZ switches

 Documentation/devicetree/bindings/net/dsa/ksz.txt |   73 +
 MAINTAINERS   |   10 +
 drivers/net/dsa/Kconfig   |2 +
 drivers/net/dsa/Makefile  |1 +
 drivers/net/dsa/microchip/Kconfig |   12 +
 drivers/net/dsa/microchip/Makefile|2 +
 drivers/net/dsa/microchip/ksz_9477_reg.h  | 1676 +
 drivers/net/dsa/microchip/ksz_common.c| 1255 +++
 drivers/net/dsa/microchip/ksz_priv.h  |  210 +++
 drivers/net/dsa/microchip/ksz_spi.c   |  215 +++
 drivers/net/phy/micrel.c  |   11 +
 include/linux/micrel_phy.h|2 +
 include/linux/platform_data/microchip-ksz.h   |   29 +
 include/net/dsa.h |1 +
 net/dsa/Kconfig   |3 +
 net/dsa/Makefile  |1 +
 net/dsa/dsa.c |3 +
 net/dsa/dsa_priv.h|3 +
 net/dsa/tag_ksz.c |  103 ++
 19 files changed, 3612 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/ksz.txt
 create mode 100644 drivers/net/dsa/microchip/Kconfig
 create mode 100644 drivers/net/dsa/microchip/Makefile
 create mode 100644 drivers/net/dsa/microchip/ksz_9477_reg.h
 create mode 100644 drivers/net/dsa/microchip/ksz_common.c
 create mode 100644 drivers/net/dsa/microchip/ksz_priv.h
 create mode 100644 drivers/net/dsa/microchip/ksz_spi.c
 create mode 100644 include/linux/platform_data/microchip-ksz.h
 create mode 100644 net/dsa/tag_ksz.c

-- 
2.7.4



[PATCH v3 net-next 1/5] dsa: add support for Microchip KSZ tail tagging

2017-05-19 Thread Woojung.Huh
From: Woojung Huh 

Adding support for the Microchip KSZ switch family tail tagging.

Signed-off-by: Woojung Huh 
Reviewed-by: Andrew Lunn 
---
 include/net/dsa.h  |   1 +
 net/dsa/Kconfig|   3 ++
 net/dsa/Makefile   |   1 +
 net/dsa/dsa.c  |   3 ++
 net/dsa/dsa_priv.h |   3 ++
 net/dsa/tag_ksz.c  | 103 +
 6 files changed, 114 insertions(+)
 create mode 100644 net/dsa/tag_ksz.c

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 791fed6..fbb00a6 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -31,6 +31,7 @@ enum dsa_tag_protocol {
DSA_TAG_PROTO_BRCM,
DSA_TAG_PROTO_DSA,
DSA_TAG_PROTO_EDSA,
+   DSA_TAG_PROTO_KSZ,
DSA_TAG_PROTO_LAN9303,
DSA_TAG_PROTO_MTK,
DSA_TAG_PROTO_QCA,
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index 297389b..cc5f8f9 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -25,6 +25,9 @@ config NET_DSA_TAG_DSA
 config NET_DSA_TAG_EDSA
bool
 
+config NET_DSA_TAG_KSZ
+   bool
+
 config NET_DSA_TAG_LAN9303
bool
 
diff --git a/net/dsa/Makefile b/net/dsa/Makefile
index f8c0251..b15141f 100644
--- a/net/dsa/Makefile
+++ b/net/dsa/Makefile
@@ -6,6 +6,7 @@ dsa_core-y += dsa.o slave.o dsa2.o switch.o legacy.o
 dsa_core-$(CONFIG_NET_DSA_TAG_BRCM) += tag_brcm.o
 dsa_core-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o
 dsa_core-$(CONFIG_NET_DSA_TAG_EDSA) += tag_edsa.o
+dsa_core-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
 dsa_core-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
 dsa_core-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
 dsa_core-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 3288a80..402459e 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -49,6 +49,9 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
 #ifdef CONFIG_NET_DSA_TAG_EDSA
[DSA_TAG_PROTO_EDSA] = _netdev_ops,
 #endif
+#ifdef CONFIG_NET_DSA_TAG_KSZ
+   [DSA_TAG_PROTO_KSZ] = _netdev_ops,
+#endif
 #ifdef CONFIG_NET_DSA_TAG_LAN9303
[DSA_TAG_PROTO_LAN9303] = _netdev_ops,
 #endif
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index c274130..6f23dfa 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -85,6 +85,9 @@ extern const struct dsa_device_ops dsa_netdev_ops;
 /* tag_edsa.c */
 extern const struct dsa_device_ops edsa_netdev_ops;
 
+/* tag_ksz.c */
+extern const struct dsa_device_ops ksz_netdev_ops;
+
 /* tag_lan9303.c */
 extern const struct dsa_device_ops lan9303_netdev_ops;
 
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
new file mode 100644
index 000..cbc79b5
--- /dev/null
+++ b/net/dsa/tag_ksz.c
@@ -0,0 +1,103 @@
+/*
+ * net/dsa/tag_ksz.c - Microchip KSZ Switch tag format handling
+ * Copyright (c) 2017 Microchip Technology
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "dsa_priv.h"
+
+/* For Ingress (Host -> KSZ), 2 bytes are added before FCS.
+ * ---
+ * DA(6bytes)|SA(6bytes)||Data(nbytes)|tag0(1byte)|tag1(1byte)|FCS(4bytes)
+ * ---
+ * tag0 : Prioritization (not used now)
+ * tag1 : each bit represents port (eg, 0x01=port1, 0x02=port2, 0x10=port5)
+ *
+ * For Egress (KSZ -> Host), 1 byte is added before FCS.
+ * ---
+ * DA(6bytes)|SA(6bytes)||Data(nbytes)|tag0(1byte)|FCS(4bytes)
+ * ---
+ * tag0 : zero-based value represents port
+ *   (eg, 0x00=port1, 0x02=port3, 0x06=port7)
+ */
+
+#defineKSZ_INGRESS_TAG_LEN 2
+#defineKSZ_EGRESS_TAG_LEN  1
+
+static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+   struct dsa_slave_priv *p = netdev_priv(dev);
+   struct sk_buff *nskb;
+   int padlen;
+   u8 *tag;
+
+   padlen = (skb->len >= ETH_ZLEN) ? 0 : ETH_ZLEN - skb->len;
+
+   if (skb_tailroom(skb) >= padlen + KSZ_INGRESS_TAG_LEN) {
+   nskb = skb;
+   } else {
+   nskb = alloc_skb(NET_IP_ALIGN + skb->len +
+padlen + KSZ_INGRESS_TAG_LEN, GFP_ATOMIC);
+   if (!nskb) {
+   kfree_skb(skb);
+   return NULL;
+   }
+   skb_reserve(nskb, NET_IP_ALIGN);
+
+   skb_reset_mac_header(nskb);
+   skb_set_network_header(nskb,
+  skb_network_header(skb) - skb->head);
+   skb_set_transport_header(nskb,
+   

[PATCH v3 net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477

2017-05-19 Thread Woojung.Huh
From: Woojung Huh 

The KSZ9477 is a fully integrated layer 2, managed, 7 ports GigE switch
with numerous advanced features. 5 ports incorporate 10/100/1000 Mbps PHYs.
The other 2 ports have interfaces that can be configured as SGMII, RGMII, MII
or RMII. Either of these may connect directly to a host processor or
to an external PHY. The SGMII port may interface to a fiber optic transceiver.

This driver currently supports vlan, fdb, mdb & mirror dsa switch operations.

Signed-off-by: Woojung Huh 
---
 drivers/net/dsa/Kconfig |2 +
 drivers/net/dsa/Makefile|1 +
 drivers/net/dsa/microchip/Kconfig   |   12 +
 drivers/net/dsa/microchip/Makefile  |2 +
 drivers/net/dsa/microchip/ksz_9477_reg.h| 1676 +++
 drivers/net/dsa/microchip/ksz_common.c  | 1255 
 drivers/net/dsa/microchip/ksz_priv.h|  210 
 drivers/net/dsa/microchip/ksz_spi.c |  215 
 include/linux/platform_data/microchip-ksz.h |   29 +
 9 files changed, 3402 insertions(+)
 create mode 100644 drivers/net/dsa/microchip/Kconfig
 create mode 100644 drivers/net/dsa/microchip/Makefile
 create mode 100644 drivers/net/dsa/microchip/ksz_9477_reg.h
 create mode 100644 drivers/net/dsa/microchip/ksz_common.c
 create mode 100644 drivers/net/dsa/microchip/ksz_priv.h
 create mode 100644 drivers/net/dsa/microchip/ksz_spi.c
 create mode 100644 include/linux/platform_data/microchip-ksz.h

diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig
index 68131a4..83a9bc8 100644
--- a/drivers/net/dsa/Kconfig
+++ b/drivers/net/dsa/Kconfig
@@ -39,6 +39,8 @@ config NET_DSA_MV88E6060
  This enables support for the Marvell 88E6060 ethernet switch
  chip.
 
+source "drivers/net/dsa/microchip/Kconfig"
+
 source "drivers/net/dsa/mv88e6xxx/Kconfig"
 
 config NET_DSA_QCA8K
diff --git a/drivers/net/dsa/Makefile b/drivers/net/dsa/Makefile
index 9613f36..4a5b5bd 100644
--- a/drivers/net/dsa/Makefile
+++ b/drivers/net/dsa/Makefile
@@ -8,4 +8,5 @@ obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303_I2C) += lan9303_i2c.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303_MDIO) += lan9303_mdio.o
 obj-y  += b53/
+obj-y  += microchip/
 obj-y  += mv88e6xxx/
diff --git a/drivers/net/dsa/microchip/Kconfig 
b/drivers/net/dsa/microchip/Kconfig
new file mode 100644
index 000..a8b8f59
--- /dev/null
+++ b/drivers/net/dsa/microchip/Kconfig
@@ -0,0 +1,12 @@
+menuconfig MICROCHIP_KSZ
+   tristate "Microchip KSZ series switch support"
+   depends on NET_DSA
+   select NET_DSA_TAG_KSZ
+   help
+ This driver adds support for Microchip KSZ switch chips.
+
+config MICROCHIP_KSZ_SPI_DRIVER
+   tristate "KSZ series SPI connected switch driver"
+   depends on MICROCHIP_KSZ && SPI
+   help
+ Select to enable support for registering switches configured through 
SPI.
diff --git a/drivers/net/dsa/microchip/Makefile 
b/drivers/net/dsa/microchip/Makefile
new file mode 100644
index 000..ed335e2
--- /dev/null
+++ b/drivers/net/dsa/microchip/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_MICROCHIP_KSZ)+= ksz_common.o
+obj-$(CONFIG_MICROCHIP_KSZ_SPI_DRIVER) += ksz_spi.o
diff --git a/drivers/net/dsa/microchip/ksz_9477_reg.h 
b/drivers/net/dsa/microchip/ksz_9477_reg.h
new file mode 100644
index 000..6aa6752
--- /dev/null
+++ b/drivers/net/dsa/microchip/ksz_9477_reg.h
@@ -0,0 +1,1676 @@
+/*
+ * Microchip KSZ9477 register definitions
+ *
+ * Copyright (C) 2017
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef __KSZ9477_REGS_H
+#define __KSZ9477_REGS_H
+
+#define KS_PRIO_M  0x7
+#define KS_PRIO_S  4
+
+/* 0 - Operation */
+#define REG_CHIP_ID0__10x
+
+#define REG_CHIP_ID1__10x0001
+
+#define FAMILY_ID  0x95
+#define FAMILY_ID_94   0x94
+#define FAMILY_ID_95   0x95
+#define FAMILY_ID_85   0x85
+#define FAMILY_ID_98   0x98
+#define FAMILY_ID_88   0x88
+
+#define REG_CHIP_ID2__1  

RE: [PATCH v2 net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477

2017-05-15 Thread Woojung.Huh
> > +static const struct ksz_chip_data ksz_switch_chips[] = {
> > +   {
> > +   .chip_id = 0x00947700,
> > +   .dev_name = "KSZ9477",
> > +   .num_vlans = 4096,
> > +   .num_alus = 4096,
> > +   .num_statics = 16,
> > +   .enabled_ports = 0x1F,  /* port0-4 */
> > +   .cpu_port = 5,  /* port5 (RGMII) */
> > +   .port_cnt = 7,
> > +   .phy_port_cnt = 5,
> > +   },
> > +};
> 
> Hi Woojung
> 
> Do we need cpu_port in this table? Can any port be used as a CPU port?
> From the code in ksz_config_cpu_port() it seems like it can.
> 
> And do we need enabled_ports? This seems to suggest only ports 0-4 can
> be user ports?
> 
Andrew,

Intention of cpu_port is for default cpu_port when devicetree doesn't have it.
However, it won't get back to dst, so it won't be needed.
Will remove it.

Enabled_ports was to configure physically connected ports. (For instance, 7 
ports switch but board only uses 4 ports.)
This code path is not working as expected. Will update at next version of patch.

Thanks.
Woojung



RE: [PATCH v2 net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477

2017-05-15 Thread Woojung.Huh
> >> +  dev->vlan_cache = devm_kmalloc_array(dev->dev,
> >> +   sizeof(struct vlan_table),
> >> +   dev->num_vlans, GFP_KERNEL);
> >
> > You should check, but i think devm_kmalloc_array sets the allocated
> > memory to 0.
> 
> No. Else there would be no need for it, since kcalloc() is a function that
> allocates the arrays and zeroes them.
> 
> > So i don't think you need the memset. If it is needed, i
> > would move it here, after the check the allocation is successful.
> 
> If it could be done here, kcalloc() should be used.
Andrew & Sergei,

Source shows that devm_kcalloc() calls devm_kmalloc_array() wit __GFP_ZERO.
Will use it instead.

Thanks.
Woojung


[PATCH v2 net-next 5/5] dsa: add maintainer of Microchip KSZ switches

2017-05-12 Thread Woojung.Huh
From: Woojung Huh 

Adding maintainer of Microchip KSZ switches.

Signed-off-by: Woojung Huh 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 45b173a..e65e501 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8370,6 +8370,15 @@ F:   drivers/media/platform/atmel/atmel-isc.c
 F: drivers/media/platform/atmel/atmel-isc-regs.h
 F: devicetree/bindings/media/atmel-isc.txt
 
+MICROCHIP KSZ SERIES ETHERNET SWITCH DRIVER
+M: Woojung Huh 
+M: Microchip Linux Driver Support 
+L: netdev@vger.kernel.org
+S: Maintained
+F: drivers/net/dsa/microchip/*
+F: include/linux/platform_data/microchip-ksz.h
+F: Documentation/devicetree/bindings/net/dsa/ksz.txt
+
 MICROCHIP USB251XB DRIVER
 M: Richard Leitner 
 L: linux-...@vger.kernel.org
-- 
2.7.4



[PATCH v2 net-next 4/5] dsa: Add spi support to Microchip KSZ switches

2017-05-12 Thread Woojung.Huh
From: Woojung Huh 

A sample SPI configuration for Microchip KSZ switches.

Signed-off-by: Woojung Huh 
---
 Documentation/devicetree/bindings/net/dsa/ksz.txt | 73 +++
 1 file changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/ksz.txt

diff --git a/Documentation/devicetree/bindings/net/dsa/ksz.txt 
b/Documentation/devicetree/bindings/net/dsa/ksz.txt
new file mode 100644
index 000..8a13966
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/dsa/ksz.txt
@@ -0,0 +1,73 @@
+Microchip KSZ Series Ethernet switches
+==
+
+Required properties:
+
+- compatible: For external switch chips, compatible string must be exactly one
+  of: "microchip,ksz9477"
+
+See Documentation/devicetree/bindings/dsa/dsa.txt for a list of additional
+required and optional properties.
+
+Examples:
+
+Ethernet switch connected via SPI to the host, CPU port wired to eth0:
+
+   eth0: ethernet@10001000 {
+   fixed-link {
+   reg = <7>
+   speed = <1000>;
+   duplex-full;
+   };
+   };
+
+   spi1: spi@f8008000 {
+   pinctrl-0 = <_spi_ksz>;
+   cs-gpios = < 25 0>;
+   id = <1>;
+   status = "okay";
+
+   ksz9477: ksz9477@0 {
+   compatible = "microchip,ksz9477";
+   reg = <0>;
+
+   spi-max-frequency = <4400>;
+   spi-cpha;
+   spi-cpol;
+
+   status = "okay";
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   port@0 {
+   reg = <0>;
+   label = "lan1";
+   };
+   port@1 {
+   reg = <1>;
+   label = "lan2";
+   };
+   port@2 {
+   reg = <2>;
+   label = "lan3";
+   };
+   port@3 {
+   reg = <3>;
+   label = "lan4";
+   };
+   port@4 {
+   reg = <4>;
+   label = "lan5";
+   };
+   port@5 {
+   reg = <5>;
+   label = "cpu";
+   ethernet = <>;
+   fixed-link {
+   speed = <1000>;
+   full-duplex;
+   };
+   };
+   };
+   };
+   };
-- 
2.7.4



[PATCH v2 net-next 1/5] dsa: add support for Microchip KSZ tail tagging

2017-05-12 Thread Woojung.Huh
From: Woojung Huh 

Adding support for the Microchip KSZ switch family tail tagging.

Signed-off-by: Woojung Huh 
---
 include/net/dsa.h  |   1 +
 net/dsa/Kconfig|   3 ++
 net/dsa/Makefile   |   1 +
 net/dsa/dsa.c  |   3 ++
 net/dsa/dsa_priv.h |   3 ++
 net/dsa/tag_ksz.c  | 103 +
 6 files changed, 114 insertions(+)
 create mode 100644 net/dsa/tag_ksz.c

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 8e24677..c92204a 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -34,6 +34,7 @@ enum dsa_tag_protocol {
DSA_TAG_PROTO_QCA,
DSA_TAG_PROTO_MTK,
DSA_TAG_PROTO_LAN9303,
+   DSA_TAG_PROTO_KSZ,
DSA_TAG_LAST,   /* MUST BE LAST */
 };
 
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index 81a0868..ce31428 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -37,4 +37,7 @@ config NET_DSA_TAG_MTK
 config NET_DSA_TAG_LAN9303
bool
 
+config NET_DSA_TAG_KSZ
+   bool
+
 endif
diff --git a/net/dsa/Makefile b/net/dsa/Makefile
index 0b747d7..8becb26 100644
--- a/net/dsa/Makefile
+++ b/net/dsa/Makefile
@@ -10,3 +10,4 @@ dsa_core-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
 dsa_core-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
 dsa_core-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
 dsa_core-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
+dsa_core-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 26130ae..6340323 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -61,6 +61,9 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
 #ifdef CONFIG_NET_DSA_TAG_LAN9303
[DSA_TAG_PROTO_LAN9303] = _netdev_ops,
 #endif
+#ifdef CONFIG_NET_DSA_TAG_KSZ
+   [DSA_TAG_PROTO_KSZ] = _netdev_ops,
+#endif
[DSA_TAG_PROTO_NONE] = _ops,
 };
 
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index f4a88e4..70183ac 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -96,4 +96,7 @@ extern const struct dsa_device_ops mtk_netdev_ops;
 /* tag_lan9303.c */
 extern const struct dsa_device_ops lan9303_netdev_ops;
 
+/* tag_ksz.c */
+extern const struct dsa_device_ops ksz_netdev_ops;
+
 #endif
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
new file mode 100644
index 000..9dda96e
--- /dev/null
+++ b/net/dsa/tag_ksz.c
@@ -0,0 +1,103 @@
+/*
+ * net/dsa/tag_ksz.c - Microchip KSZ Switch tag format handling
+ * Copyright (c) 2017 Microchip Technology
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "dsa_priv.h"
+
+/* For Ingress (Host -> KSZ), 2 bytes are added before FCS.
+ * ---
+ * DA(6bytes)|SA(6bytes)||Data(nbytes)|tag0(1byte)|tag1(1byte)|FCS(4bytes)
+ * ---
+ * tag0 : Prioritization (not used now)
+ * tag1 : each bit represents port (eg, 0x01=port1, 0x02=port2, 0x10=port5)
+ *
+ * For Egress (KSZ -> Host), 1 byte is added before FCS.
+ * ---
+ * DA(6bytes)|SA(6bytes)||Data(nbytes)|tag0(1byte)|FCS(4bytes)
+ * ---
+ * tag0 : zero-based value represents port
+ *   (eg, 0x00=port1, 0x02=port3, 0x06=port7)
+ */
+
+#defineKSZ_INGRESS_TAG_LEN 2
+#defineKSZ_EGRESS_TAG_LEN  1
+
+static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+   struct dsa_slave_priv *p = netdev_priv(dev);
+   struct sk_buff *nskb;
+   int padlen;
+   u8 *tag;
+
+   padlen = (skb->len >= ETH_ZLEN) ? 0 : ETH_ZLEN - skb->len;
+
+   if (skb_tailroom(skb) >= padlen + KSZ_INGRESS_TAG_LEN) {
+   nskb = skb;
+   } else {
+   nskb = alloc_skb(NET_IP_ALIGN + skb->len +
+padlen + KSZ_INGRESS_TAG_LEN, GFP_ATOMIC);
+   if (!nskb) {
+   kfree_skb(skb);
+   return NULL;
+   }
+   skb_reserve(nskb, NET_IP_ALIGN);
+
+   skb_reset_mac_header(nskb);
+   skb_set_network_header(nskb,
+  skb_network_header(skb) - skb->head);
+   skb_set_transport_header(nskb,
+skb_transport_header(skb) - skb->head);
+   skb_copy_and_csum_dev(skb, skb_put(nskb, skb->len));
+   kfree_skb(skb);
+   }
+
+   if (padlen) {
+   u8 *pad = skb_put(nskb, padlen);
+
+   memset(pad, 0, padlen);
+   }
+
+   tag = skb_put(nskb, 

[PATCH v2 net-next 2/5] phy: micrel: add Microchip KSZ 9477 Switch PHY support

2017-05-12 Thread Woojung.Huh
From: Woojung Huh 

Adding Microchip 9477 Phy included in KSZ9477 Switch.

Signed-off-by: Woojung Huh 
---
 drivers/net/phy/micrel.c   | 11 +++
 include/linux/micrel_phy.h |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 6a5fd18..263ba3a 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -20,6 +20,7 @@
  *ksz8081, ksz8091,
  *ksz8061,
  * Switch : ksz8873, ksz886x
+ *  ksz9477
  */
 
 #include 
@@ -997,6 +998,16 @@ static struct phy_driver ksphy_driver[] = {
.read_status= ksz8873mll_read_status,
.suspend= genphy_suspend,
.resume = genphy_resume,
+}, {
+   .phy_id = PHY_ID_KSZ9477,
+   .phy_id_mask= MICREL_PHY_ID_MASK,
+   .name   = "Microchip KSZ9477",
+   .features   = PHY_GBIT_FEATURES,
+   .config_init= kszphy_config_init,
+   .config_aneg= genphy_config_aneg,
+   .read_status= genphy_read_status,
+   .suspend= genphy_suspend,
+   .resume = genphy_resume,
 } };
 
 module_phy_driver(ksphy_driver);
diff --git a/include/linux/micrel_phy.h b/include/linux/micrel_phy.h
index f541da6..472fa4d 100644
--- a/include/linux/micrel_phy.h
+++ b/include/linux/micrel_phy.h
@@ -37,6 +37,8 @@
 
 #define PHY_ID_KSZ8795 0x00221550
 
+#definePHY_ID_KSZ9477  0x00221631
+
 /* struct phy_device dev_flags definitions */
 #define MICREL_PHY_50MHZ_CLK   0x0001
 #define MICREL_PHY_FXEN0x0002
-- 
2.7.4



[PATCH v2 net-next 0/5] dsa: add Microchip KSZ9477 DSA driver

2017-05-12 Thread Woojung.Huh
From: Woojung Huh 

This series of patches is for Microchip KSZ9477 DSA driver.
KSZ9477 is 7 ports GigE switch with numerous advanced features.
5 ports are 10/100/1000 Mbps internal PHYs and 2 ports have
Interfaces to SGMII, RGMII, MII or RMII.

This patch supports VLAN, MDB, FDB and port mirroring offloads.

Welcome reviews and comments from community.

Note: Tests are performed on internal development board.

V2
- update per review comments
- several cosmetic changes
- net/dsa/tag_ksz.c
  * constants are changed to defines
  * remove skb_linearize() in ksz_rcv()
  * ksz_xmit()checks skb tailroom before allocate new skb
- drivers/net/phy/micrel.c
  * remove PHY_HAS_MAGICANEG from ksphy_driver[]
- drivers/net/dsa/microchip/ksz_common.c
  * add timeout to avoid endless loop
  * port initialization is move to ksz_port_enable() instead of  
ksz_setup_ports()
- Documentation/devicetree/bindings/net/dsa/ksz.txt
  * fix typo and indentations
Thanks to Andres, Florian, Sergei for reviews.

Woojung Huh (5):
  dsa: add support for Microchip KSZ tail tagging
  phy: micrel: add Microchip KSZ 9477 Switch PHY support
  dsa: add DSA switch driver for Microchip KSZ9477
  dsa: Add spi support to Microchip KSZ switches
  dsa: add maintainer of Microchip KSZ switches

 Documentation/devicetree/bindings/net/dsa/ksz.txt |   73 +
 MAINTAINERS   |9 +
 drivers/net/dsa/Kconfig   |2 +
 drivers/net/dsa/Makefile  |1 +
 drivers/net/dsa/microchip/Kconfig |   12 +
 drivers/net/dsa/microchip/Makefile|2 +
 drivers/net/dsa/microchip/ksz_9477_reg.h  | 1676 +
 drivers/net/dsa/microchip/ksz_common.c| 1211 +++
 drivers/net/dsa/microchip/ksz_priv.h  |  209 +++
 drivers/net/dsa/microchip/ksz_spi.c   |  215 +++
 drivers/net/phy/micrel.c  |   11 +
 include/linux/micrel_phy.h|2 +
 include/linux/platform_data/microchip-ksz.h   |   29 +
 include/net/dsa.h |1 +
 net/dsa/Kconfig   |3 +
 net/dsa/Makefile  |1 +
 net/dsa/dsa.c |3 +
 net/dsa/dsa_priv.h|3 +
 net/dsa/tag_ksz.c |  103 ++
 19 files changed, 3566 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/ksz.txt
 create mode 100644 drivers/net/dsa/microchip/Kconfig
 create mode 100644 drivers/net/dsa/microchip/Makefile
 create mode 100644 drivers/net/dsa/microchip/ksz_9477_reg.h
 create mode 100644 drivers/net/dsa/microchip/ksz_common.c
 create mode 100644 drivers/net/dsa/microchip/ksz_priv.h
 create mode 100644 drivers/net/dsa/microchip/ksz_spi.c
 create mode 100644 include/linux/platform_data/microchip-ksz.h
 create mode 100644 net/dsa/tag_ksz.c

-- 
2.7.4


[PATCH v2 net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477

2017-05-12 Thread Woojung.Huh
From: Woojung Huh 

The KSZ9477 is a fully integrated layer 2, managed, 7 ports GigE switch
with numerous advanced features. 5 ports incorporate 10/100/1000 Mbps PHYs.
The other 2 ports have interfaces that can be configured as SGMII, RGMII, MII
or RMII. Either of these may connect directly to a host processor or
to an external PHY. The SGMII port may interface to a fiber optic transceiver.

This driver currently supports vlan, fdb, mdb & mirror dsa switch operations.

Signed-off-by: Woojung Huh 
---
 drivers/net/dsa/Kconfig |2 +
 drivers/net/dsa/Makefile|1 +
 drivers/net/dsa/microchip/Kconfig   |   12 +
 drivers/net/dsa/microchip/Makefile  |2 +
 drivers/net/dsa/microchip/ksz_9477_reg.h| 1676 +++
 drivers/net/dsa/microchip/ksz_common.c  | 1211 +++
 drivers/net/dsa/microchip/ksz_priv.h|  209 
 drivers/net/dsa/microchip/ksz_spi.c |  215 
 include/linux/platform_data/microchip-ksz.h |   29 +
 9 files changed, 3357 insertions(+)
 create mode 100644 drivers/net/dsa/microchip/Kconfig
 create mode 100644 drivers/net/dsa/microchip/Makefile
 create mode 100644 drivers/net/dsa/microchip/ksz_9477_reg.h
 create mode 100644 drivers/net/dsa/microchip/ksz_common.c
 create mode 100644 drivers/net/dsa/microchip/ksz_priv.h
 create mode 100644 drivers/net/dsa/microchip/ksz_spi.c
 create mode 100644 include/linux/platform_data/microchip-ksz.h

diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig
index 862ee22..e4d5c41 100644
--- a/drivers/net/dsa/Kconfig
+++ b/drivers/net/dsa/Kconfig
@@ -23,6 +23,8 @@ config NET_DSA_BCM_SF2
 
 source "drivers/net/dsa/b53/Kconfig"
 
+source "drivers/net/dsa/microchip/Kconfig"
+
 source "drivers/net/dsa/mv88e6xxx/Kconfig"
 
 config NET_DSA_QCA8K
diff --git a/drivers/net/dsa/Makefile b/drivers/net/dsa/Makefile
index edd6303..d3b6cb0 100644
--- a/drivers/net/dsa/Makefile
+++ b/drivers/net/dsa/Makefile
@@ -7,5 +7,6 @@ obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303_I2C) += lan9303_i2c.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303_MDIO) += lan9303_mdio.o
 obj-y  += b53/
+obj-y  += microchip/
 obj-y  += mv88e6xxx/
 obj-$(CONFIG_NET_DSA_LOOP) += dsa_loop.o dsa_loop_bdinfo.o
diff --git a/drivers/net/dsa/microchip/Kconfig 
b/drivers/net/dsa/microchip/Kconfig
new file mode 100644
index 000..a8b8f59
--- /dev/null
+++ b/drivers/net/dsa/microchip/Kconfig
@@ -0,0 +1,12 @@
+menuconfig MICROCHIP_KSZ
+   tristate "Microchip KSZ series switch support"
+   depends on NET_DSA
+   select NET_DSA_TAG_KSZ
+   help
+ This driver adds support for Microchip KSZ switch chips.
+
+config MICROCHIP_KSZ_SPI_DRIVER
+   tristate "KSZ series SPI connected switch driver"
+   depends on MICROCHIP_KSZ && SPI
+   help
+ Select to enable support for registering switches configured through 
SPI.
diff --git a/drivers/net/dsa/microchip/Makefile 
b/drivers/net/dsa/microchip/Makefile
new file mode 100644
index 000..ed335e2
--- /dev/null
+++ b/drivers/net/dsa/microchip/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_MICROCHIP_KSZ)+= ksz_common.o
+obj-$(CONFIG_MICROCHIP_KSZ_SPI_DRIVER) += ksz_spi.o
diff --git a/drivers/net/dsa/microchip/ksz_9477_reg.h 
b/drivers/net/dsa/microchip/ksz_9477_reg.h
new file mode 100644
index 000..6aa6752
--- /dev/null
+++ b/drivers/net/dsa/microchip/ksz_9477_reg.h
@@ -0,0 +1,1676 @@
+/*
+ * Microchip KSZ9477 register definitions
+ *
+ * Copyright (C) 2017
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef __KSZ9477_REGS_H
+#define __KSZ9477_REGS_H
+
+#define KS_PRIO_M  0x7
+#define KS_PRIO_S  4
+
+/* 0 - Operation */
+#define REG_CHIP_ID0__10x
+
+#define REG_CHIP_ID1__10x0001
+
+#define FAMILY_ID  0x95
+#define FAMILY_ID_94   0x94
+#define FAMILY_ID_95   0x95
+#define FAMILY_ID_85   0x85
+#define FAMILY_ID_98   0x98
+#define FAMILY_ID_88   0x88
+
+#define 

RE: [PATCH net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477

2017-05-08 Thread Woojung.Huh
Hi Florian,

> > The KSZ9477 is a fully integrated layer 2, managed, 7 ports GigE switch
> > with numerous advanced features. 5 ports incorporate
> > 10/100/1000 Mbps PHYs. The other 2 ports have interfaces that can be
> > configured as SGMII, RGMII, MII or RMII.
> > Either of these may connect directly to a host processor or to
> > an external PHY. The SGMII port may interface to a fiber optic transceiver.
> >
> > This driver currently supports vlan, fdb, mdb & mirror dsa switch 
> > operations.
> >
> > Signed-off-by: Woojung Huh 
> > ---
> 
> Overall, this looks really nice and clean, there are a few minor nits,
> most of them being that busy polling loop have no timeout to make sure
> they terminate in a finite amount of time.
Thanks for your full review on this patch.
Will add limit in the loop and update per your other comments below.
Added my comment in few section.

> For VLAN programming, can you describe how the CPU port works? Is it
> similar to B53 where we explictly need to have the CPU port be part of a
> VLAN entry (including tagged/untagged attribute) or is it similar to
> Marvell where it seems to be smarter and requires little to no
> configuration?
Can you explain little bit this question? I understand that how this chip 
handles
VLAN in CPU port. Am I understanding your question?

> > +
> > +static u64 mib_value[TOTAL_SWITCH_COUNTER_NUM];
> 
> This probably needs to be driver instance specific and in the ksz_device
> structure?
> 
> > +
> > +static void ksz_cfg(struct ksz_device *dev, u32 addr, u8 bits, int set)
> > +{
> 
> bool set?
> 
> > +   u8 data;
> > +
> > +   ksz_read8(dev, addr, );
> > +   if (set)
> > +   data |= bits;
> > +   else
> > +   data &= ~bits;
> > +   ksz_write8(dev, addr, data);
> > +}
> > +
> > +static void ksz_cfg32(struct ksz_device *dev, u32 addr, u32 bits, int set)
> > +{
> 
> Same thing
> 
> > +   u32 data;
> > +
> > +   ksz_read32(dev, addr, );
> > +   if (set)
> > +   data |= bits;
> > +   else
> > +   data &= ~bits;
> > +   ksz_write32(dev, addr, data);
> > +}
> > +
> > +static void ksz_port_cfg(struct ksz_device *dev, int port, int offset, u8 
> > bits,
> > +int set)
> > +{
> > +   u32 addr;
> > +   u8 data;
> > +
> > +   addr = PORT_CTRL_ADDR(port, offset);
> > +   ksz_read8(dev, addr, );
> > +
> > +   if (set)
> > +   data |= bits;
> > +   else
> > +   data &= ~bits;
> > +
> > +   ksz_write8(dev, addr, data);
> > +}
> > +
> > +static void ksz_port_cfg32(struct ksz_device *dev, int port, int offset,
> > +  u32 bits, int set)
> > +{
> > +   u32 addr;
> > +   u32 data;
> > +
> > +   addr = PORT_CTRL_ADDR(port, offset);
> > +   ksz_read32(dev, addr, );
> > +
> > +   if (set)
> > +   data |= bits;
> > +   else
> > +   data &= ~bits;
> > +
> > +   ksz_write32(dev, addr, data);
> > +}
> > +
> > +static void get_vlan_table(struct dsa_switch *ds, u16 vid, u32 *vlan_table)
> > +{
> > +   struct ksz_device *dev = ds->priv;
> > +   u8 data;
> > +
> > +   ksz_write16(dev, REG_SW_VLAN_ENTRY_INDEX__2, vid &
> VLAN_INDEX_M);
> > +   ksz_write8(dev, REG_SW_VLAN_CTRL, VLAN_READ | VLAN_START);
> > +   /* wait to be cleared */
> > +   data = 0;
> > +   do {
> > +   ksz_read8(dev, REG_SW_VLAN_CTRL, );
> > +   } while (data & VLAN_START);
> 
> You need to put an upper boundary on how this can take, potentially
> spinning forever is not very safe.
> 
> > +
> > +   ksz_read32(dev, REG_SW_VLAN_ENTRY__4, _table[0]);
> > +   ksz_read32(dev, REG_SW_VLAN_ENTRY_UNTAG__4,
> _table[1]);
> > +   ksz_read32(dev, REG_SW_VLAN_ENTRY_PORTS__4, _table[2]);
> > +
> > +   ksz_write8(dev, REG_SW_VLAN_CTRL, 0);
> > +}
> > +
> > +static void set_vlan_table(struct dsa_switch *ds, u16 vid, u32 *vlan_table)
> > +{
> > +   struct ksz_device *dev = ds->priv;
> > +   u8 data;
> > +
> > +   ksz_write32(dev, REG_SW_VLAN_ENTRY__4, vlan_table[0]);
> > +   ksz_write32(dev, REG_SW_VLAN_ENTRY_UNTAG__4, vlan_table[1]);
> > +   ksz_write32(dev, REG_SW_VLAN_ENTRY_PORTS__4, vlan_table[2]);
> > +
> > +   ksz_write16(dev, REG_SW_VLAN_ENTRY_INDEX__2, vid &
> VLAN_INDEX_M);
> > +   ksz_write8(dev, REG_SW_VLAN_CTRL, VLAN_START | VLAN_WRITE);
> > +
> > +   do {
> > +   ksz_read8(dev, REG_SW_VLAN_CTRL, );
> > +   } while (data & VLAN_START);
> 
> Same here.
> 
> > +
> > +   ksz_write8(dev, REG_SW_VLAN_CTRL, 0);
> > +
> > +   /* update vlan cache table */
> > +   dev->vlan_cache[vid].table[0] = vlan_table[0];
> > +   dev->vlan_cache[vid].table[1] = vlan_table[1];
> > +   dev->vlan_cache[vid].table[2] = vlan_table[2];
> > +}
> > +
> > +static void read_table(struct dsa_switch *ds, u32 *table)
> > +{
> > +   struct ksz_device *dev = ds->priv;
> > +
> > +   ksz_read32(dev, REG_SW_ALU_VAL_A, [0]);
> > +   ksz_read32(dev, REG_SW_ALU_VAL_B, [1]);
> > +   ksz_read32(dev, REG_SW_ALU_VAL_C, [2]);
> > +   ksz_read32(dev, REG_SW_ALU_VAL_D, [3]);
> > +}
> > +
> > +static void 

RE: [PATCH net-next 2/5] phy: micrel: add Microchip KSZ 9477 Switch PHY support

2017-05-08 Thread Woojung.Huh
> > >> +}, {
> > >> + .phy_id = PHY_ID_KSZ9477,
> > >> + .phy_id_mask= MICREL_PHY_ID_MASK,
> > >> + .name   = "Microchip KSZ9477",
> > >> + .features   = PHY_GBIT_FEATURES,
> > >> + .flags  = PHY_HAS_MAGICANEG,
> > >
> > >Is this magic still used anywhere? I could not find anything.
> > >
> > Hi Andrew,
> >
> > Really no usage in define and flags.
> > Will double check and remove it.
> 
> Hi Woojung
> 
> I just created a patch to remove PHY_HAS_MAGICANEG from the kernel.
> Once net-next has reopened when the merge window closes, i will submit
> it. So please don't add it here.
Hi Andrew,

Thanks you. I'll remove it.

Woojung


RE: [PATCH net-next 4/5] dsa: Microchip KSZ switches SPI devicetree configuration

2017-05-07 Thread Woojung.Huh
Hi Sergei

>> + spi1: spi@f8008000 {
>> + pinctrl-0 = <_spi_ksz>;
>> + cs-gpios = < 25 0>;
>> + id = <1>;
>> + status = "okay";
>
>4 lines above should be indented more to the right.
>> + };
>> + };
>
>Unmatched }?

Will fix both.

- Woojung


RE: [PATCH net-next 2/5] phy: micrel: add Microchip KSZ 9477 Switch PHY support

2017-05-07 Thread Woojung.Huh
>> +}, {
>> + .phy_id = PHY_ID_KSZ9477,
>> + .phy_id_mask= MICREL_PHY_ID_MASK,
>> + .name   = "Microchip KSZ9477",
>> + .features   = PHY_GBIT_FEATURES,
>> + .flags  = PHY_HAS_MAGICANEG,
>
>Is this magic still used anywhere? I could not find anything.
>
Hi Andrew,

Really no usage in define and flags.
Will double check and remove it.

- Woojung


RE: [PATCH net-next 1/5] dsa: add support for Microchip KSZ tail tagging

2017-05-05 Thread Woojung.Huh
> > +   padlen = 0;
> > +   if (skb->len < 60)
> > +   padlen = 60 - skb->len;
> 
> Can you use ETH_ZLEN instead of 60 such that it is clear this is padding
> to a minimum packet size (minus FCS)?
> 
> > +
> > +   nskb = alloc_skb(NET_IP_ALIGN + skb->len + padlen + 2,
> GFP_ATOMIC);
> 
> Can you also define the "2" at the beginning of the file as being e.g:
> TAG_KSZ_LEN?
Got it. Will update.

> > +   ds = dst->cpu_switch;
> > +
> > +   if (skb_linearize(skb))
> > +   return NULL;
> 
> Is that really necessary?
I don't think so. Will check it.

> > +
> > +   tag = skb_tail_pointer(skb) - 1;
> > +
> > +   source_port = tag[0] & 7;
> > +   if (source_port >= ds->num_ports || !ds-
> >ports[source_port].netdev)
> > +   return NULL;
> > +
> > +   pskb_trim_rcsum(skb, skb->len - 1);
> 
> Humm, so we are still keeping tag[1] at the end of the frame?
It tags 2 bytes for ingress (ksz_xmit) and 1 byte for egress (ksz_rcv).
Put comment at the begin of net/dsa/tag_ksz.c.

Thanks.
Woojung


[PATCH net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477

2017-05-05 Thread Woojung.Huh
From: Woojung Huh 

The KSZ9477 is a fully integrated layer 2, managed, 7 ports GigE switch
with numerous advanced features. 5 ports incorporate
10/100/1000 Mbps PHYs. The other 2 ports have interfaces that can be
configured as SGMII, RGMII, MII or RMII.
Either of these may connect directly to a host processor or to
an external PHY. The SGMII port may interface to a fiber optic transceiver.

This driver currently supports vlan, fdb, mdb & mirror dsa switch operations.

Signed-off-by: Woojung Huh 
---
 drivers/net/dsa/Kconfig |2 +
 drivers/net/dsa/Makefile|1 +
 drivers/net/dsa/microchip/Kconfig   |   12 +
 drivers/net/dsa/microchip/Makefile  |2 +
 drivers/net/dsa/microchip/ksz_9477_reg.h| 1676 +++
 drivers/net/dsa/microchip/ksz_common.c  | 1184 +++
 drivers/net/dsa/microchip/ksz_priv.h|  207 
 drivers/net/dsa/microchip/ksz_spi.c |  215 
 include/linux/platform_data/microchip-ksz.h |   29 +
 9 files changed, 3328 insertions(+)
 create mode 100644 drivers/net/dsa/microchip/Kconfig
 create mode 100644 drivers/net/dsa/microchip/Makefile
 create mode 100644 drivers/net/dsa/microchip/ksz_9477_reg.h
 create mode 100644 drivers/net/dsa/microchip/ksz_common.c
 create mode 100644 drivers/net/dsa/microchip/ksz_priv.h
 create mode 100644 drivers/net/dsa/microchip/ksz_spi.c
 create mode 100644 include/linux/platform_data/microchip-ksz.h

diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig
index 862ee22..e4d5c41 100644
--- a/drivers/net/dsa/Kconfig
+++ b/drivers/net/dsa/Kconfig
@@ -23,6 +23,8 @@ config NET_DSA_BCM_SF2
 
 source "drivers/net/dsa/b53/Kconfig"
 
+source "drivers/net/dsa/microchip/Kconfig"
+
 source "drivers/net/dsa/mv88e6xxx/Kconfig"
 
 config NET_DSA_QCA8K
diff --git a/drivers/net/dsa/Makefile b/drivers/net/dsa/Makefile
index edd6303..d3b6cb0 100644
--- a/drivers/net/dsa/Makefile
+++ b/drivers/net/dsa/Makefile
@@ -7,5 +7,6 @@ obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303_I2C) += lan9303_i2c.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303_MDIO) += lan9303_mdio.o
 obj-y  += b53/
+obj-y  += microchip/
 obj-y  += mv88e6xxx/
 obj-$(CONFIG_NET_DSA_LOOP) += dsa_loop.o dsa_loop_bdinfo.o
diff --git a/drivers/net/dsa/microchip/Kconfig 
b/drivers/net/dsa/microchip/Kconfig
new file mode 100644
index 000..a8b8f59
--- /dev/null
+++ b/drivers/net/dsa/microchip/Kconfig
@@ -0,0 +1,12 @@
+menuconfig MICROCHIP_KSZ
+   tristate "Microchip KSZ series switch support"
+   depends on NET_DSA
+   select NET_DSA_TAG_KSZ
+   help
+ This driver adds support for Microchip KSZ switch chips.
+
+config MICROCHIP_KSZ_SPI_DRIVER
+   tristate "KSZ series SPI connected switch driver"
+   depends on MICROCHIP_KSZ && SPI
+   help
+ Select to enable support for registering switches configured through 
SPI.
diff --git a/drivers/net/dsa/microchip/Makefile 
b/drivers/net/dsa/microchip/Makefile
new file mode 100644
index 000..ed335e2
--- /dev/null
+++ b/drivers/net/dsa/microchip/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_MICROCHIP_KSZ)+= ksz_common.o
+obj-$(CONFIG_MICROCHIP_KSZ_SPI_DRIVER) += ksz_spi.o
diff --git a/drivers/net/dsa/microchip/ksz_9477_reg.h 
b/drivers/net/dsa/microchip/ksz_9477_reg.h
new file mode 100644
index 000..6aa6752
--- /dev/null
+++ b/drivers/net/dsa/microchip/ksz_9477_reg.h
@@ -0,0 +1,1676 @@
+/*
+ * Microchip KSZ9477 register definitions
+ *
+ * Copyright (C) 2017
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef __KSZ9477_REGS_H
+#define __KSZ9477_REGS_H
+
+#define KS_PRIO_M  0x7
+#define KS_PRIO_S  4
+
+/* 0 - Operation */
+#define REG_CHIP_ID0__10x
+
+#define REG_CHIP_ID1__10x0001
+
+#define FAMILY_ID  0x95
+#define FAMILY_ID_94   0x94
+#define FAMILY_ID_95   0x95
+#define FAMILY_ID_85   0x85
+#define FAMILY_ID_98   0x98
+#define FAMILY_ID_88   0x88
+
+#define 

[PATCH net-next 5/5] dsa: add maintainer of Microchip KSZ switches

2017-05-05 Thread Woojung.Huh
From: Woojung Huh 

Adding maintainer of Microchip KSZ switches.

Signed-off-by: Woojung Huh 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 45b173a..e65e501 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8370,6 +8370,15 @@ F:   drivers/media/platform/atmel/atmel-isc.c
 F: drivers/media/platform/atmel/atmel-isc-regs.h
 F: devicetree/bindings/media/atmel-isc.txt
 
+MICROCHIP KSZ SERIES ETHERNET SWITCH DRIVER
+M: Woojung Huh 
+M: Microchip Linux Driver Support 
+L: netdev@vger.kernel.org
+S: Maintained
+F: drivers/net/dsa/microchip/*
+F: include/linux/platform_data/microchip-ksz.h
+F: Documentation/devicetree/bindings/net/dsa/ksz.txt
+
 MICROCHIP USB251XB DRIVER
 M: Richard Leitner 
 L: linux-...@vger.kernel.org
-- 
2.7.4



[PATCH net-next 0/5] dsa: add Microchip KSZ9477 DSA driver

2017-05-05 Thread Woojung.Huh
From: Woojung Huh 

This series of patches is for Microchip KSZ9477 DSA driver.
KSZ9477 is 7 ports GigE switch with numerous advanced features.
5 ports are 10/100/1000 Mbps internal PHYs and 2 ports have
Interfaces to SGMII, RGMII, MII or RMII.

This patch supports VLAN, MDB, FDB and port mirroring offloads.

Welcome reviews and comments from community.

Note: Tests are performed on internal development board.

Woojung Huh (5):
  dsa: add support for Microchip KSZ tail tagging
  phy: micrel: add Microchip KSZ 9477 Switch PHY support
  dsa: dsa: add DSA switch driver for Microchip KSZ9477
  dsa: Microchip KSZ switches SPI devicetree configuration
  dsa: add maintainer of Microchip KSZ switches

 Documentation/devicetree/bindings/net/dsa/ksz.txt |   73 +
 MAINTAINERS   |9 +
 drivers/net/dsa/Kconfig   |2 +
 drivers/net/dsa/Makefile  |1 +
 drivers/net/dsa/microchip/Kconfig |   12 +
 drivers/net/dsa/microchip/Makefile|2 +
 drivers/net/dsa/microchip/ksz_9477_reg.h  | 1676 +
 drivers/net/dsa/microchip/ksz_common.c| 1184 +++
 drivers/net/dsa/microchip/ksz_priv.h  |  207 +++
 drivers/net/dsa/microchip/ksz_spi.c   |  215 +++
 drivers/net/phy/micrel.c  |   12 +
 include/linux/micrel_phy.h|2 +
 include/linux/platform_data/microchip-ksz.h   |   29 +
 include/net/dsa.h |1 +
 net/dsa/Kconfig   |3 +
 net/dsa/Makefile  |1 +
 net/dsa/dsa.c |3 +
 net/dsa/dsa_priv.h|3 +
 net/dsa/tag_ksz.c |   98 ++
 19 files changed, 3533 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/ksz.txt
 create mode 100644 drivers/net/dsa/microchip/Kconfig
 create mode 100644 drivers/net/dsa/microchip/Makefile
 create mode 100644 drivers/net/dsa/microchip/ksz_9477_reg.h
 create mode 100644 drivers/net/dsa/microchip/ksz_common.c
 create mode 100644 drivers/net/dsa/microchip/ksz_priv.h
 create mode 100644 drivers/net/dsa/microchip/ksz_spi.c
 create mode 100644 include/linux/platform_data/microchip-ksz.h
 create mode 100644 net/dsa/tag_ksz.c

-- 
2.7.4


[PATCH net-next 4/5] dsa: Microchip KSZ switches SPI devicetree configuration

2017-05-05 Thread Woojung.Huh
From: Woojung Huh 

A sample SPI configuration for Microchip KSZ switches.

Signed-off-by: Woojung Huh 
---
 Documentation/devicetree/bindings/net/dsa/ksz.txt | 73 +++
 1 file changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/ksz.txt

diff --git a/Documentation/devicetree/bindings/net/dsa/ksz.txt 
b/Documentation/devicetree/bindings/net/dsa/ksz.txt
new file mode 100644
index 000..9cca7d4
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/dsa/ksz.txt
@@ -0,0 +1,73 @@
+Microchip KSZ Series Ethernet switches
+==
+
+Required properties:
+
+- compatible: For external switch chips, compatible string must be exactly one
+  of: "microchip,ksz9477"
+
+See Documentation/devicetree/bindings/dsa/dsa.txt for a list of additional
+required and optional properties.
+
+Examples:
+
+Ethernet switch connected via SPI to the host, CPU port wired to eth0:
+
+   eth0: ethernet@10001000 {
+   fixed-link {
+   reg = <7>
+   speed = <1000>;
+   duplex-full;
+   };
+   };
+
+   spi1: spi@f8008000 {
+   pinctrl-0 = <_spi_ksz>;
+   cs-gpios = < 25 0>;
+   id = <1>;
+   status = "okay";
+
+   ksz9477: ksz9477@0 {
+   compatible = "microchip,ksz9477";
+   reg = <0>;
+
+   spi-max-frequency = <4400>;
+   spi-cpha;
+   spi-cpol;
+
+   status = "okay";
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   port@0 {
+   reg = <0>;
+   label = "lan1";
+   };
+   port@1 {
+   reg = <1>;
+   label = "lan2";
+   };
+   port@2 {
+   reg = <2>;
+   label = "lan3";
+   };
+   port@3 {
+   reg = <3>;
+   label = "lan4";
+   };
+   port@4 {
+   reg = <4>;
+   label = "lan5";
+   };
+   port@5 {
+   reg = <5>;
+   label = "cpu";
+   ethernet = <>;
+   fixed-link {
+   speed = <1000>;
+   full-duplex;
+   };
+   };
+   };
+   };
+   };
-- 
2.7.4



[PATCH net-next 2/5] phy: micrel: add Microchip KSZ 9477 Switch PHY support

2017-05-05 Thread Woojung.Huh
From: Woojung Huh 

Adding Microchip 9477 Phy included in KSZ9477 Switch.

Signed-off-by: Woojung Huh 
---
 drivers/net/phy/micrel.c   | 12 
 include/linux/micrel_phy.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 6a5fd18..65520990 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -20,6 +20,7 @@
  *ksz8081, ksz8091,
  *ksz8061,
  * Switch : ksz8873, ksz886x
+ *  ksz9477
  */
 
 #include 
@@ -997,6 +998,17 @@ static struct phy_driver ksphy_driver[] = {
.read_status= ksz8873mll_read_status,
.suspend= genphy_suspend,
.resume = genphy_resume,
+}, {
+   .phy_id = PHY_ID_KSZ9477,
+   .phy_id_mask= MICREL_PHY_ID_MASK,
+   .name   = "Microchip KSZ9477",
+   .features   = PHY_GBIT_FEATURES,
+   .flags  = PHY_HAS_MAGICANEG,
+   .config_init= kszphy_config_init,
+   .config_aneg= genphy_config_aneg,
+   .read_status= genphy_read_status,
+   .suspend= genphy_suspend,
+   .resume = genphy_resume,
 } };
 
 module_phy_driver(ksphy_driver);
diff --git a/include/linux/micrel_phy.h b/include/linux/micrel_phy.h
index f541da6..472fa4d 100644
--- a/include/linux/micrel_phy.h
+++ b/include/linux/micrel_phy.h
@@ -37,6 +37,8 @@
 
 #define PHY_ID_KSZ8795 0x00221550
 
+#definePHY_ID_KSZ9477  0x00221631
+
 /* struct phy_device dev_flags definitions */
 #define MICREL_PHY_50MHZ_CLK   0x0001
 #define MICREL_PHY_FXEN0x0002
-- 
2.7.4



[PATCH net-next 1/5] dsa: add support for Microchip KSZ tail tagging

2017-05-05 Thread Woojung.Huh
From: Woojung Huh 

Adding support for the Microchip KSZ switch family tail tagging.

Signed-off-by: Woojung Huh 
---
 include/net/dsa.h  |  1 +
 net/dsa/Kconfig|  3 ++
 net/dsa/Makefile   |  1 +
 net/dsa/dsa.c  |  3 ++
 net/dsa/dsa_priv.h |  3 ++
 net/dsa/tag_ksz.c  | 98 ++
 6 files changed, 109 insertions(+)
 create mode 100644 net/dsa/tag_ksz.c

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 8e24677..c92204a 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -34,6 +34,7 @@ enum dsa_tag_protocol {
DSA_TAG_PROTO_QCA,
DSA_TAG_PROTO_MTK,
DSA_TAG_PROTO_LAN9303,
+   DSA_TAG_PROTO_KSZ,
DSA_TAG_LAST,   /* MUST BE LAST */
 };
 
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index 81a0868..ce31428 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -37,4 +37,7 @@ config NET_DSA_TAG_MTK
 config NET_DSA_TAG_LAN9303
bool
 
+config NET_DSA_TAG_KSZ
+   bool
+
 endif
diff --git a/net/dsa/Makefile b/net/dsa/Makefile
index 0b747d7..8becb26 100644
--- a/net/dsa/Makefile
+++ b/net/dsa/Makefile
@@ -10,3 +10,4 @@ dsa_core-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
 dsa_core-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
 dsa_core-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
 dsa_core-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
+dsa_core-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 26130ae..6340323 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -61,6 +61,9 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
 #ifdef CONFIG_NET_DSA_TAG_LAN9303
[DSA_TAG_PROTO_LAN9303] = _netdev_ops,
 #endif
+#ifdef CONFIG_NET_DSA_TAG_KSZ
+   [DSA_TAG_PROTO_KSZ] = _netdev_ops,
+#endif
[DSA_TAG_PROTO_NONE] = _ops,
 };
 
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index f4a88e4..70183ac 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -96,4 +96,7 @@ extern const struct dsa_device_ops mtk_netdev_ops;
 /* tag_lan9303.c */
 extern const struct dsa_device_ops lan9303_netdev_ops;
 
+/* tag_ksz.c */
+extern const struct dsa_device_ops ksz_netdev_ops;
+
 #endif
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
new file mode 100644
index 000..270bfb9
--- /dev/null
+++ b/net/dsa/tag_ksz.c
@@ -0,0 +1,98 @@
+/*
+ * net/dsa/tag_ksz.c - Microchip KSZ Switch tag format handling
+ * Copyright (c) 2017 Microchip Technology
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "dsa_priv.h"
+
+/* For Ingress (Host -> KSZ), 2 bytes are added before FCS.
+ * ---
+ * DA(6bytes)|SA(6bytes)||Data(nbytes)|tag0(1byte)|tag1(1byte)|FCS(4bytes)
+ * ---
+ * tag0 : Prioritization (not used now)
+ * tag1 : each bit represents port (eg, 0x01=port1, 0x02=port2, 0x10=port5)
+ *
+ * For Egress (KSZ -> Host), 1 byte is added before FCS.
+ * ---
+ * DA(6bytes)|SA(6bytes)||Data(nbytes)|tag0(1byte)|FCS(4bytes)
+ * ---
+ * tag0 : zero-based value represents port
+ *   (eg, 0x00=port1, 0x02=port3, 0x06=port7)
+ */
+
+static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+   struct dsa_slave_priv *p = netdev_priv(dev);
+   struct sk_buff *nskb;
+   int padlen;
+   u8 *tag;
+
+   padlen = 0;
+   if (skb->len < 60)
+   padlen = 60 - skb->len;
+
+   nskb = alloc_skb(NET_IP_ALIGN + skb->len + padlen + 2, GFP_ATOMIC);
+   if (!nskb) {
+   kfree_skb(skb);
+   return NULL;
+   }
+   skb_reserve(nskb, NET_IP_ALIGN);
+
+   skb_reset_mac_header(nskb);
+   skb_set_network_header(nskb, skb_network_header(skb) - skb->head);
+   skb_set_transport_header(nskb, skb_transport_header(skb) - skb->head);
+   skb_copy_and_csum_dev(skb, skb_put(nskb, skb->len));
+   kfree_skb(skb);
+
+   if (padlen) {
+   u8 *pad = skb_put(nskb, padlen);
+
+   memset(pad, 0, padlen);
+   }
+
+   tag = skb_put(nskb, 2);
+   tag[0] = 0;
+   tag[1] = 1 << p->dp->index; /* destnation port */
+
+   return nskb;
+}
+
+struct sk_buff *ksz_rcv(struct sk_buff *skb, struct net_device *dev,
+   struct packet_type *pt, struct net_device *orig_dev)
+{
+   struct dsa_switch_tree *dst = dev->dsa_ptr;
+   struct dsa_switch *ds;
+   u8 *tag;
+   int source_port;
+
+   ds = dst->cpu_switch;
+
+   

RE: [PATCH v4 net-next]smsc911x: Adding support for Micochip LAN9250 Ethernet controller

2017-05-01 Thread Woojung.Huh
> Isn't this now pointless? If it is not used anywhere, you should not
> add it.
> 
Andrew,

David is going to submit another patch.
(He already sent discard request email right after v4 patch.)

- Woojung


RE: [PATCH v4] smsc95xx: Use skb_cow_head to deal with cloned skbs

2017-04-19 Thread Woojung.Huh
> The driver was failing to check that the SKB wasn't cloned
> before adding checksum data.
> Replace existing handling to extend/copy the header buffer
> with skb_cow_head.
> 
> Signed-off-by: James Hughes 
> ---

Acked-by: Woojung Huh 


  1   2   3   >