Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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 "tag.h"
15
16#define HELLCREEK_NAME "hellcreek"
17
18#define HELLCREEK_TAG_LEN 1
19
20static struct sk_buff *hellcreek_xmit(struct sk_buff *skb,
21 struct net_device *dev)
22{
23 u8 *tag;
24
25 /* Calculate checksums (if required) before adding the trailer tag to
26 * avoid including it in calculations. That would lead to wrong
27 * checksums after the switch strips the tag.
28 */
29 if (skb->ip_summed == CHECKSUM_PARTIAL &&
30 skb_checksum_help(skb))
31 return NULL;
32
33 /* Tag encoding */
34 tag = skb_put(skb, HELLCREEK_TAG_LEN);
35 *tag = dsa_xmit_port_mask(skb, dev);
36
37 return skb;
38}
39
40static struct sk_buff *hellcreek_rcv(struct sk_buff *skb,
41 struct net_device *dev)
42{
43 /* Tag decoding */
44 u8 *tag = skb_tail_pointer(skb) - HELLCREEK_TAG_LEN;
45 unsigned int port = tag[0] & 0x03;
46
47 skb->dev = dsa_conduit_find_user(dev, 0, port);
48 if (!skb->dev) {
49 netdev_warn_once(dev, "Failed to get source port: %d\n", port);
50 return NULL;
51 }
52
53 if (pskb_trim_rcsum(skb, skb->len - HELLCREEK_TAG_LEN))
54 return NULL;
55
56 dsa_default_offload_fwd_mark(skb);
57
58 return skb;
59}
60
61static const struct dsa_device_ops hellcreek_netdev_ops = {
62 .name = HELLCREEK_NAME,
63 .proto = DSA_TAG_PROTO_HELLCREEK,
64 .xmit = hellcreek_xmit,
65 .rcv = hellcreek_rcv,
66 .needed_tailroom = HELLCREEK_TAG_LEN,
67};
68
69MODULE_DESCRIPTION("DSA tag driver for Hirschmann Hellcreek TSN switches");
70MODULE_LICENSE("Dual MIT/GPL");
71MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_HELLCREEK, HELLCREEK_NAME);
72
73module_dsa_tag_driver(hellcreek_netdev_ops);