mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 10:49:33 +00:00
![Marek Vasut](/assets/img/avatar_default.png)
In case the destination address is link local, add override bit into the switch tag to let such a packet through the switch even if the port is blocked. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Tristram Ha <Tristram.Ha@microchip.com> Cc: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Cc: Woojung Huh <woojung.huh@microchip.com> Cc: David S. Miller <davem@davemloft.net> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
141 lines
3.8 KiB
C
141 lines
3.8 KiB
C
/*
|
|
* 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 <linux/etherdevice.h>
|
|
#include <linux/list.h>
|
|
#include <linux/slab.h>
|
|
#include <net/dsa.h>
|
|
#include "dsa_priv.h"
|
|
|
|
/* Typically only one byte is used for tail tag. */
|
|
#define KSZ_EGRESS_TAG_LEN 1
|
|
|
|
static struct sk_buff *ksz_common_xmit(struct sk_buff *skb,
|
|
struct net_device *dev, int len)
|
|
{
|
|
struct sk_buff *nskb;
|
|
int padlen;
|
|
|
|
padlen = (skb->len >= ETH_ZLEN) ? 0 : ETH_ZLEN - skb->len;
|
|
|
|
if (skb_tailroom(skb) >= padlen + len) {
|
|
/* Let dsa_slave_xmit() free skb */
|
|
if (__skb_put_padto(skb, skb->len + padlen, false))
|
|
return NULL;
|
|
|
|
nskb = skb;
|
|
} else {
|
|
nskb = alloc_skb(NET_IP_ALIGN + skb->len +
|
|
padlen + len, GFP_ATOMIC);
|
|
if (!nskb)
|
|
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));
|
|
|
|
/* Let skb_put_padto() free nskb, and let dsa_slave_xmit() free
|
|
* skb
|
|
*/
|
|
if (skb_put_padto(nskb, nskb->len + padlen))
|
|
return NULL;
|
|
|
|
consume_skb(skb);
|
|
}
|
|
|
|
return nskb;
|
|
}
|
|
|
|
static struct sk_buff *ksz_common_rcv(struct sk_buff *skb,
|
|
struct net_device *dev,
|
|
unsigned int port, unsigned int len)
|
|
{
|
|
skb->dev = dsa_master_find_slave(dev, 0, port);
|
|
if (!skb->dev)
|
|
return NULL;
|
|
|
|
pskb_trim_rcsum(skb, skb->len - len);
|
|
|
|
return skb;
|
|
}
|
|
|
|
/*
|
|
* For Ingress (Host -> KSZ9477), 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 (KSZ9477 -> 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)
|
|
*/
|
|
|
|
#define KSZ9477_INGRESS_TAG_LEN 2
|
|
#define KSZ9477_PTP_TAG_LEN 4
|
|
#define KSZ9477_PTP_TAG_INDICATION 0x80
|
|
|
|
#define KSZ9477_TAIL_TAG_OVERRIDE BIT(9)
|
|
#define KSZ9477_TAIL_TAG_LOOKUP BIT(10)
|
|
|
|
static struct sk_buff *ksz9477_xmit(struct sk_buff *skb,
|
|
struct net_device *dev)
|
|
{
|
|
struct dsa_port *dp = dsa_slave_to_port(dev);
|
|
struct sk_buff *nskb;
|
|
u16 *tag;
|
|
u8 *addr;
|
|
|
|
nskb = ksz_common_xmit(skb, dev, KSZ9477_INGRESS_TAG_LEN);
|
|
if (!nskb)
|
|
return NULL;
|
|
|
|
/* Tag encoding */
|
|
tag = skb_put(nskb, KSZ9477_INGRESS_TAG_LEN);
|
|
addr = skb_mac_header(nskb);
|
|
|
|
*tag = BIT(dp->index);
|
|
|
|
if (is_link_local_ether_addr(addr))
|
|
*tag |= KSZ9477_TAIL_TAG_OVERRIDE;
|
|
|
|
*tag = cpu_to_be16(*tag);
|
|
|
|
return nskb;
|
|
}
|
|
|
|
static struct sk_buff *ksz9477_rcv(struct sk_buff *skb, struct net_device *dev,
|
|
struct packet_type *pt)
|
|
{
|
|
/* Tag decoding */
|
|
u8 *tag = skb_tail_pointer(skb) - KSZ_EGRESS_TAG_LEN;
|
|
unsigned int port = tag[0] & 7;
|
|
unsigned int len = KSZ_EGRESS_TAG_LEN;
|
|
|
|
/* Extra 4-bytes PTP timestamp */
|
|
if (tag[0] & KSZ9477_PTP_TAG_INDICATION)
|
|
len += KSZ9477_PTP_TAG_LEN;
|
|
|
|
return ksz_common_rcv(skb, dev, port, len);
|
|
}
|
|
|
|
const struct dsa_device_ops ksz9477_netdev_ops = {
|
|
.xmit = ksz9477_xmit,
|
|
.rcv = ksz9477_rcv,
|
|
.overhead = KSZ9477_INGRESS_TAG_LEN,
|
|
};
|