// SPDX-License-Identifier: GPL-2.0+ /* * net/dsa/tag_ksz.c - Microchip KSZ Switch tag format handling * Copyright (c) 2017 Microchip Technology */ #include <linux/dsa/ksz_common.h> #include <linux/etherdevice.h> #include <linux/list.h> #include <linux/ptp_classify.h> #include <net/dsa.h> #include "tag.h" #define KSZ8795_NAME … #define KSZ9477_NAME … #define KSZ9893_NAME … #define LAN937X_NAME … /* Typically only one byte is used for tail tag. */ #define KSZ_PTP_TAG_LEN … #define KSZ_EGRESS_TAG_LEN … #define KSZ_INGRESS_TAG_LEN … #define KSZ_HWTS_EN … struct ksz_tagger_private { … }; static struct ksz_tagger_private * ksz_tagger_private(struct dsa_switch *ds) { … } static void ksz_hwtstamp_set_state(struct dsa_switch *ds, bool on) { … } static void ksz_disconnect(struct dsa_switch *ds) { … } static int ksz_connect(struct dsa_switch *ds) { … } static struct sk_buff *ksz_common_rcv(struct sk_buff *skb, struct net_device *dev, unsigned int port, unsigned int len) { … } /* * For Ingress (Host -> KSZ8795), 1 byte is added before FCS. * --------------------------------------------------------------------------- * DA(6bytes)|SA(6bytes)|....|Data(nbytes)|tag(1byte)|FCS(4bytes) * --------------------------------------------------------------------------- * tag : each bit represents port (eg, 0x01=port1, 0x02=port2, 0x10=port5) * * For Egress (KSZ8795 -> 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 KSZ8795_TAIL_TAG_OVERRIDE … #define KSZ8795_TAIL_TAG_LOOKUP … static struct sk_buff *ksz8795_xmit(struct sk_buff *skb, struct net_device *dev) { … } static struct sk_buff *ksz8795_rcv(struct sk_buff *skb, struct net_device *dev) { … } static const struct dsa_device_ops ksz8795_netdev_ops = …; DSA_TAG_DRIVER(ksz8795_netdev_ops); MODULE_ALIAS_DSA_TAG_DRIVER(…); /* * For Ingress (Host -> KSZ9477), 2/6 bytes are added before FCS. * --------------------------------------------------------------------------- * DA(6bytes)|SA(6bytes)|....|Data(nbytes)|ts(4bytes)|tag0(1byte)|tag1(1byte)| * FCS(4bytes) * --------------------------------------------------------------------------- * ts : time stamp (Present only if PTP is enabled in the Hardware) * tag0 : Prioritization (not used now) * tag1 : each bit represents port (eg, 0x01=port1, 0x02=port2, 0x10=port5) * * For Egress (KSZ9477 -> Host), 1/5 bytes is added before FCS. * --------------------------------------------------------------------------- * DA(6bytes)|SA(6bytes)|....|Data(nbytes)|ts(4bytes)|tag0(1byte)|FCS(4bytes) * --------------------------------------------------------------------------- * ts : time stamp (Present only if bit 7 of tag0 is set) * tag0 : zero-based value represents port * (eg, 0x00=port1, 0x02=port3, 0x06=port7) */ #define KSZ9477_INGRESS_TAG_LEN … #define KSZ9477_PTP_TAG_LEN … #define KSZ9477_PTP_TAG_INDICATION … #define KSZ9477_TAIL_TAG_PRIO … #define KSZ9477_TAIL_TAG_OVERRIDE … #define KSZ9477_TAIL_TAG_LOOKUP … static void ksz_rcv_timestamp(struct sk_buff *skb, u8 *tag) { … } /* Time stamp tag *needs* to be inserted if PTP is enabled in hardware. * Regardless of Whether it is a PTP frame or not. */ static void ksz_xmit_timestamp(struct dsa_port *dp, struct sk_buff *skb) { … } /* Defer transmit if waiting for egress time stamp is required. */ static struct sk_buff *ksz_defer_xmit(struct dsa_port *dp, struct sk_buff *skb) { … } static struct sk_buff *ksz9477_xmit(struct sk_buff *skb, struct net_device *dev) { … } static struct sk_buff *ksz9477_rcv(struct sk_buff *skb, struct net_device *dev) { … } static const struct dsa_device_ops ksz9477_netdev_ops = …; DSA_TAG_DRIVER(ksz9477_netdev_ops); MODULE_ALIAS_DSA_TAG_DRIVER(…); #define KSZ9893_TAIL_TAG_PRIO … #define KSZ9893_TAIL_TAG_OVERRIDE … #define KSZ9893_TAIL_TAG_LOOKUP … static struct sk_buff *ksz9893_xmit(struct sk_buff *skb, struct net_device *dev) { … } static const struct dsa_device_ops ksz9893_netdev_ops = …; DSA_TAG_DRIVER(ksz9893_netdev_ops); MODULE_ALIAS_DSA_TAG_DRIVER(…); /* For xmit, 2/6 bytes are added before FCS. * --------------------------------------------------------------------------- * DA(6bytes)|SA(6bytes)|....|Data(nbytes)|ts(4bytes)|tag0(1byte)|tag1(1byte)| * FCS(4bytes) * --------------------------------------------------------------------------- * ts : time stamp (Present only if PTP is enabled in the Hardware) * tag0 : represents tag override, lookup and valid * tag1 : each bit represents port (eg, 0x01=port1, 0x02=port2, 0x80=port8) * * For rcv, 1/5 bytes is added before FCS. * --------------------------------------------------------------------------- * DA(6bytes)|SA(6bytes)|....|Data(nbytes)|ts(4bytes)|tag0(1byte)|FCS(4bytes) * --------------------------------------------------------------------------- * ts : time stamp (Present only if bit 7 of tag0 is set) * tag0 : zero-based value represents port * (eg, 0x00=port1, 0x02=port3, 0x07=port8) */ #define LAN937X_EGRESS_TAG_LEN … #define LAN937X_TAIL_TAG_BLOCKING_OVERRIDE … #define LAN937X_TAIL_TAG_LOOKUP … #define LAN937X_TAIL_TAG_VALID … #define LAN937X_TAIL_TAG_PRIO … #define LAN937X_TAIL_TAG_PORT_MASK … static struct sk_buff *lan937x_xmit(struct sk_buff *skb, struct net_device *dev) { … } static const struct dsa_device_ops lan937x_netdev_ops = …; DSA_TAG_DRIVER(lan937x_netdev_ops); MODULE_ALIAS_DSA_TAG_DRIVER(…); static struct dsa_tag_driver *dsa_tag_driver_array[] = …; module_dsa_tag_drivers(dsa_tag_driver_array); MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;