cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

tag_hellcreek.c (1686B)


      1// SPDX-License-Identifier: (GPL-2.0 OR MIT)
      2/*
      3 * net/dsa/tag_hellcreek.c - Hirschmann Hellcreek switch tag format handling
      4 *
      5 * Copyright (C) 2019,2020 Linutronix GmbH
      6 * Author Kurt Kanzenbach <kurt@linutronix.de>
      7 *
      8 * Based on tag_ksz.c.
      9 */
     10
     11#include <linux/skbuff.h>
     12#include <net/dsa.h>
     13
     14#include "dsa_priv.h"
     15
     16#define HELLCREEK_TAG_LEN	1
     17
     18static struct sk_buff *hellcreek_xmit(struct sk_buff *skb,
     19				      struct net_device *dev)
     20{
     21	struct dsa_port *dp = dsa_slave_to_port(dev);
     22	u8 *tag;
     23
     24	/* Calculate checksums (if required) before adding the trailer tag to
     25	 * avoid including it in calculations. That would lead to wrong
     26	 * checksums after the switch strips the tag.
     27	 */
     28	if (skb->ip_summed == CHECKSUM_PARTIAL &&
     29	    skb_checksum_help(skb))
     30		return NULL;
     31
     32	/* Tag encoding */
     33	tag  = skb_put(skb, HELLCREEK_TAG_LEN);
     34	*tag = BIT(dp->index);
     35
     36	return skb;
     37}
     38
     39static struct sk_buff *hellcreek_rcv(struct sk_buff *skb,
     40				     struct net_device *dev)
     41{
     42	/* Tag decoding */
     43	u8 *tag = skb_tail_pointer(skb) - HELLCREEK_TAG_LEN;
     44	unsigned int port = tag[0] & 0x03;
     45
     46	skb->dev = dsa_master_find_slave(dev, 0, port);
     47	if (!skb->dev) {
     48		netdev_warn(dev, "Failed to get source port: %d\n", port);
     49		return NULL;
     50	}
     51
     52	pskb_trim_rcsum(skb, skb->len - HELLCREEK_TAG_LEN);
     53
     54	dsa_default_offload_fwd_mark(skb);
     55
     56	return skb;
     57}
     58
     59static const struct dsa_device_ops hellcreek_netdev_ops = {
     60	.name	  = "hellcreek",
     61	.proto	  = DSA_TAG_PROTO_HELLCREEK,
     62	.xmit	  = hellcreek_xmit,
     63	.rcv	  = hellcreek_rcv,
     64	.needed_tailroom = HELLCREEK_TAG_LEN,
     65};
     66
     67MODULE_LICENSE("Dual MIT/GPL");
     68MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_HELLCREEK);
     69
     70module_dsa_tag_driver(hellcreek_netdev_ops);