0001
0002
0003
0004 #include <linux/dsa/ocelot.h>
0005 #include "dsa_priv.h"
0006
0007
0008
0009
0010
0011
0012 static void ocelot_xmit_get_vlan_info(struct sk_buff *skb, struct dsa_port *dp,
0013 u64 *vlan_tci, u64 *tag_type)
0014 {
0015 struct net_device *br = dsa_port_bridge_dev_get(dp);
0016 struct vlan_ethhdr *hdr;
0017 u16 proto, tci;
0018
0019 if (!br || !br_vlan_enabled(br)) {
0020 *vlan_tci = 0;
0021 *tag_type = IFH_TAG_TYPE_C;
0022 return;
0023 }
0024
0025 hdr = (struct vlan_ethhdr *)skb_mac_header(skb);
0026 br_vlan_get_proto(br, &proto);
0027
0028 if (ntohs(hdr->h_vlan_proto) == proto) {
0029 __skb_vlan_pop(skb, &tci);
0030 *vlan_tci = tci;
0031 } else {
0032 rcu_read_lock();
0033 br_vlan_get_pvid_rcu(br, &tci);
0034 rcu_read_unlock();
0035 *vlan_tci = tci;
0036 }
0037
0038 *tag_type = (proto != ETH_P_8021Q) ? IFH_TAG_TYPE_S : IFH_TAG_TYPE_C;
0039 }
0040
0041 static void ocelot_xmit_common(struct sk_buff *skb, struct net_device *netdev,
0042 __be32 ifh_prefix, void **ifh)
0043 {
0044 struct dsa_port *dp = dsa_slave_to_port(netdev);
0045 struct dsa_switch *ds = dp->ds;
0046 u64 vlan_tci, tag_type;
0047 void *injection;
0048 __be32 *prefix;
0049 u32 rew_op = 0;
0050 u64 qos_class;
0051
0052 ocelot_xmit_get_vlan_info(skb, dp, &vlan_tci, &tag_type);
0053
0054 qos_class = netdev_get_num_tc(netdev) ?
0055 netdev_get_prio_tc_map(netdev, skb->priority) : skb->priority;
0056
0057 injection = skb_push(skb, OCELOT_TAG_LEN);
0058 prefix = skb_push(skb, OCELOT_SHORT_PREFIX_LEN);
0059
0060 *prefix = ifh_prefix;
0061 memset(injection, 0, OCELOT_TAG_LEN);
0062 ocelot_ifh_set_bypass(injection, 1);
0063 ocelot_ifh_set_src(injection, ds->num_ports);
0064 ocelot_ifh_set_qos_class(injection, qos_class);
0065 ocelot_ifh_set_vlan_tci(injection, vlan_tci);
0066 ocelot_ifh_set_tag_type(injection, tag_type);
0067
0068 rew_op = ocelot_ptp_rew_op(skb);
0069 if (rew_op)
0070 ocelot_ifh_set_rew_op(injection, rew_op);
0071
0072 *ifh = injection;
0073 }
0074
0075 static struct sk_buff *ocelot_xmit(struct sk_buff *skb,
0076 struct net_device *netdev)
0077 {
0078 struct dsa_port *dp = dsa_slave_to_port(netdev);
0079 void *injection;
0080
0081 ocelot_xmit_common(skb, netdev, cpu_to_be32(0x8880000a), &injection);
0082 ocelot_ifh_set_dest(injection, BIT_ULL(dp->index));
0083
0084 return skb;
0085 }
0086
0087 static struct sk_buff *seville_xmit(struct sk_buff *skb,
0088 struct net_device *netdev)
0089 {
0090 struct dsa_port *dp = dsa_slave_to_port(netdev);
0091 void *injection;
0092
0093 ocelot_xmit_common(skb, netdev, cpu_to_be32(0x88800005), &injection);
0094 seville_ifh_set_dest(injection, BIT_ULL(dp->index));
0095
0096 return skb;
0097 }
0098
0099 static struct sk_buff *ocelot_rcv(struct sk_buff *skb,
0100 struct net_device *netdev)
0101 {
0102 u64 src_port, qos_class;
0103 u64 vlan_tci, tag_type;
0104 u8 *start = skb->data;
0105 struct dsa_port *dp;
0106 u8 *extraction;
0107 u16 vlan_tpid;
0108 u64 rew_val;
0109
0110
0111
0112
0113 skb_push(skb, ETH_HLEN);
0114
0115
0116
0117
0118 skb_pull(skb, OCELOT_SHORT_PREFIX_LEN);
0119
0120
0121
0122 extraction = skb->data;
0123
0124 skb_pull(skb, OCELOT_TAG_LEN);
0125
0126 skb_reset_mac_header(skb);
0127 skb_reset_mac_len(skb);
0128
0129 skb_pull(skb, ETH_HLEN);
0130
0131
0132 skb_postpull_rcsum(skb, start, OCELOT_TOTAL_TAG_LEN);
0133
0134 ocelot_xfh_get_src_port(extraction, &src_port);
0135 ocelot_xfh_get_qos_class(extraction, &qos_class);
0136 ocelot_xfh_get_tag_type(extraction, &tag_type);
0137 ocelot_xfh_get_vlan_tci(extraction, &vlan_tci);
0138 ocelot_xfh_get_rew_val(extraction, &rew_val);
0139
0140 skb->dev = dsa_master_find_slave(netdev, 0, src_port);
0141 if (!skb->dev)
0142
0143
0144
0145
0146
0147
0148 return NULL;
0149
0150 dsa_default_offload_fwd_mark(skb);
0151 skb->priority = qos_class;
0152 OCELOT_SKB_CB(skb)->tstamp_lo = rew_val;
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 dp = dsa_slave_to_port(skb->dev);
0170 vlan_tpid = tag_type ? ETH_P_8021AD : ETH_P_8021Q;
0171
0172 if (dsa_port_is_vlan_filtering(dp) &&
0173 eth_hdr(skb)->h_proto == htons(vlan_tpid)) {
0174 u16 dummy_vlan_tci;
0175
0176 skb_push_rcsum(skb, ETH_HLEN);
0177 __skb_vlan_pop(skb, &dummy_vlan_tci);
0178 skb_pull_rcsum(skb, ETH_HLEN);
0179 __vlan_hwaccel_put_tag(skb, htons(vlan_tpid), vlan_tci);
0180 }
0181
0182 return skb;
0183 }
0184
0185 static const struct dsa_device_ops ocelot_netdev_ops = {
0186 .name = "ocelot",
0187 .proto = DSA_TAG_PROTO_OCELOT,
0188 .xmit = ocelot_xmit,
0189 .rcv = ocelot_rcv,
0190 .needed_headroom = OCELOT_TOTAL_TAG_LEN,
0191 .promisc_on_master = true,
0192 };
0193
0194 DSA_TAG_DRIVER(ocelot_netdev_ops);
0195 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_OCELOT);
0196
0197 static const struct dsa_device_ops seville_netdev_ops = {
0198 .name = "seville",
0199 .proto = DSA_TAG_PROTO_SEVILLE,
0200 .xmit = seville_xmit,
0201 .rcv = ocelot_rcv,
0202 .needed_headroom = OCELOT_TOTAL_TAG_LEN,
0203 .promisc_on_master = true,
0204 };
0205
0206 DSA_TAG_DRIVER(seville_netdev_ops);
0207 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_SEVILLE);
0208
0209 static struct dsa_tag_driver *ocelot_tag_driver_array[] = {
0210 &DSA_TAG_DRIVER_NAME(ocelot_netdev_ops),
0211 &DSA_TAG_DRIVER_NAME(seville_netdev_ops),
0212 };
0213
0214 module_dsa_tag_drivers(ocelot_tag_driver_array);
0215
0216 MODULE_LICENSE("GPL v2");