Commit | Line | Data |
---|---|---|
01ef09ca KK |
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 | ||
8551fad6 | 11 | #include <linux/skbuff.h> |
01ef09ca KK |
12 | #include <net/dsa.h> |
13 | ||
bd954b82 | 14 | #include "tag.h" |
01ef09ca | 15 | |
94793a56 VO |
16 | #define HELLCREEK_NAME "hellcreek" |
17 | ||
01ef09ca KK |
18 | #define HELLCREEK_TAG_LEN 1 |
19 | ||
20 | static struct sk_buff *hellcreek_xmit(struct sk_buff *skb, | |
21 | struct net_device *dev) | |
22 | { | |
6ca80638 | 23 | struct dsa_port *dp = dsa_user_to_port(dev); |
01ef09ca KK |
24 | u8 *tag; |
25 | ||
0763120b KK |
26 | /* Calculate checksums (if required) before adding the trailer tag to |
27 | * avoid including it in calculations. That would lead to wrong | |
28 | * checksums after the switch strips the tag. | |
29 | */ | |
30 | if (skb->ip_summed == CHECKSUM_PARTIAL && | |
31 | skb_checksum_help(skb)) | |
32 | return NULL; | |
33 | ||
01ef09ca KK |
34 | /* Tag encoding */ |
35 | tag = skb_put(skb, HELLCREEK_TAG_LEN); | |
36 | *tag = BIT(dp->index); | |
37 | ||
38 | return skb; | |
39 | } | |
40 | ||
41 | static struct sk_buff *hellcreek_rcv(struct sk_buff *skb, | |
29a097b7 | 42 | struct net_device *dev) |
01ef09ca KK |
43 | { |
44 | /* Tag decoding */ | |
45 | u8 *tag = skb_tail_pointer(skb) - HELLCREEK_TAG_LEN; | |
46 | unsigned int port = tag[0] & 0x03; | |
47 | ||
6ca80638 | 48 | skb->dev = dsa_conduit_find_user(dev, 0, port); |
01ef09ca | 49 | if (!skb->dev) { |
52267ce2 | 50 | netdev_warn_once(dev, "Failed to get source port: %d\n", port); |
01ef09ca KK |
51 | return NULL; |
52 | } | |
53 | ||
d4edb506 AC |
54 | if (pskb_trim_rcsum(skb, skb->len - HELLCREEK_TAG_LEN)) |
55 | return NULL; | |
01ef09ca | 56 | |
bea79078 | 57 | dsa_default_offload_fwd_mark(skb); |
01ef09ca KK |
58 | |
59 | return skb; | |
60 | } | |
61 | ||
62 | static const struct dsa_device_ops hellcreek_netdev_ops = { | |
94793a56 | 63 | .name = HELLCREEK_NAME, |
01ef09ca KK |
64 | .proto = DSA_TAG_PROTO_HELLCREEK, |
65 | .xmit = hellcreek_xmit, | |
66 | .rcv = hellcreek_rcv, | |
4e500251 | 67 | .needed_tailroom = HELLCREEK_TAG_LEN, |
01ef09ca KK |
68 | }; |
69 | ||
0ed6e952 | 70 | MODULE_DESCRIPTION("DSA tag driver for Hirschmann Hellcreek TSN switches"); |
01ef09ca | 71 | MODULE_LICENSE("Dual MIT/GPL"); |
94793a56 | 72 | MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_HELLCREEK, HELLCREEK_NAME); |
01ef09ca KK |
73 | |
74 | module_dsa_tag_driver(hellcreek_netdev_ops); |