~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/dsa/tag_qca.c

Version: ~ [ linux-5.1-rc5 ] ~ [ linux-5.0.7 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.34 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.111 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.168 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.178 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.138 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.65 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  3  *
  4  * This program is free software; you can redistribute it and/or modify
  5  * it under the terms of the GNU General Public License version 2 and
  6  * only version 2 as published by the Free Software Foundation.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 11  * GNU General Public License for more details.
 12  */
 13 
 14 #include <linux/etherdevice.h>
 15 
 16 #include "dsa_priv.h"
 17 
 18 #define QCA_HDR_LEN     2
 19 #define QCA_HDR_VERSION 0x2
 20 
 21 #define QCA_HDR_RECV_VERSION_MASK       GENMASK(15, 14)
 22 #define QCA_HDR_RECV_VERSION_S          14
 23 #define QCA_HDR_RECV_PRIORITY_MASK      GENMASK(13, 11)
 24 #define QCA_HDR_RECV_PRIORITY_S         11
 25 #define QCA_HDR_RECV_TYPE_MASK          GENMASK(10, 6)
 26 #define QCA_HDR_RECV_TYPE_S             6
 27 #define QCA_HDR_RECV_FRAME_IS_TAGGED    BIT(3)
 28 #define QCA_HDR_RECV_SOURCE_PORT_MASK   GENMASK(2, 0)
 29 
 30 #define QCA_HDR_XMIT_VERSION_MASK       GENMASK(15, 14)
 31 #define QCA_HDR_XMIT_VERSION_S          14
 32 #define QCA_HDR_XMIT_PRIORITY_MASK      GENMASK(13, 11)
 33 #define QCA_HDR_XMIT_PRIORITY_S         11
 34 #define QCA_HDR_XMIT_CONTROL_MASK       GENMASK(10, 8)
 35 #define QCA_HDR_XMIT_CONTROL_S          8
 36 #define QCA_HDR_XMIT_FROM_CPU           BIT(7)
 37 #define QCA_HDR_XMIT_DP_BIT_MASK        GENMASK(6, 0)
 38 
 39 static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
 40 {
 41         struct dsa_port *dp = dsa_slave_to_port(dev);
 42         u16 *phdr, hdr;
 43 
 44         dev->stats.tx_packets++;
 45         dev->stats.tx_bytes += skb->len;
 46 
 47         if (skb_cow_head(skb, 0) < 0)
 48                 return NULL;
 49 
 50         skb_push(skb, QCA_HDR_LEN);
 51 
 52         memmove(skb->data, skb->data + QCA_HDR_LEN, 2 * ETH_ALEN);
 53         phdr = (u16 *)(skb->data + 2 * ETH_ALEN);
 54 
 55         /* Set the version field, and set destination port information */
 56         hdr = QCA_HDR_VERSION << QCA_HDR_XMIT_VERSION_S |
 57                 QCA_HDR_XMIT_FROM_CPU | BIT(dp->index);
 58 
 59         *phdr = htons(hdr);
 60 
 61         return skb;
 62 }
 63 
 64 static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev,
 65                                    struct packet_type *pt)
 66 {
 67         u8 ver;
 68         int port;
 69         __be16 *phdr, hdr;
 70 
 71         if (unlikely(!pskb_may_pull(skb, QCA_HDR_LEN)))
 72                 return NULL;
 73 
 74         /* The QCA header is added by the switch between src addr and Ethertype
 75          * At this point, skb->data points to ethertype so header should be
 76          * right before
 77          */
 78         phdr = (__be16 *)(skb->data - 2);
 79         hdr = ntohs(*phdr);
 80 
 81         /* Make sure the version is correct */
 82         ver = (hdr & QCA_HDR_RECV_VERSION_MASK) >> QCA_HDR_RECV_VERSION_S;
 83         if (unlikely(ver != QCA_HDR_VERSION))
 84                 return NULL;
 85 
 86         /* Remove QCA tag and recalculate checksum */
 87         skb_pull_rcsum(skb, QCA_HDR_LEN);
 88         memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - QCA_HDR_LEN,
 89                 ETH_HLEN - QCA_HDR_LEN);
 90 
 91         /* Get source port information */
 92         port = (hdr & QCA_HDR_RECV_SOURCE_PORT_MASK);
 93 
 94         skb->dev = dsa_master_find_slave(dev, 0, port);
 95         if (!skb->dev)
 96                 return NULL;
 97 
 98         return skb;
 99 }
100 
101 static int qca_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
102                                 int *offset)
103 {
104         *offset = QCA_HDR_LEN;
105         *proto = ((__be16 *)skb->data)[0];
106 
107         return 0;
108 }
109 
110 const struct dsa_device_ops qca_netdev_ops = {
111         .xmit   = qca_tag_xmit,
112         .rcv    = qca_tag_rcv,
113         .flow_dissect = qca_tag_flow_dissect,
114         .overhead = QCA_HDR_LEN,
115 };
116 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp