2 * Copyright (C) 2015-2017 Netronome Systems, Inc.
4 * This software is dual licensed under the GNU General License Version 2,
5 * June 1991 as shown in the file COPYING in the top-level directory of this
6 * source tree or the BSD 2-Clause License provided below. You have the
7 * option to license this software under the complete terms of either license.
9 * The BSD 2-Clause License:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * 2. Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/bitfield.h>
35 #include <linux/netdevice.h>
36 #include <linux/skbuff.h>
37 #include <net/dst_metadata.h>
40 #include "../nfpcore/nfp_cpp.h"
41 #include "../nfp_net_repr.h"
44 #define nfp_flower_cmsg_warn(app, fmt, args...) \
46 if (net_ratelimit()) \
47 nfp_warn((app)->cpp, fmt, ## args); \
50 static struct nfp_flower_cmsg_hdr
*
51 nfp_flower_cmsg_get_hdr(struct sk_buff
*skb
)
53 return (struct nfp_flower_cmsg_hdr
*)skb
->data
;
57 nfp_flower_cmsg_alloc(struct nfp_app
*app
, unsigned int size
,
58 enum nfp_flower_cmsg_type_port type
)
60 struct nfp_flower_cmsg_hdr
*ch
;
63 size
+= NFP_FLOWER_CMSG_HLEN
;
65 skb
= nfp_app_ctrl_msg_alloc(app
, size
, GFP_KERNEL
);
69 ch
= nfp_flower_cmsg_get_hdr(skb
);
71 ch
->version
= NFP_FLOWER_CMSG_VER1
;
78 int nfp_flower_cmsg_portmod(struct nfp_repr
*repr
, bool carrier_ok
)
80 struct nfp_flower_cmsg_portmod
*msg
;
83 skb
= nfp_flower_cmsg_alloc(repr
->app
, sizeof(*msg
),
84 NFP_FLOWER_CMSG_TYPE_PORT_MOD
);
88 msg
= nfp_flower_cmsg_get_data(skb
);
89 msg
->portnum
= cpu_to_be32(repr
->dst
->u
.port_info
.port_id
);
91 msg
->info
= carrier_ok
;
92 msg
->mtu
= cpu_to_be16(repr
->netdev
->mtu
);
94 nfp_ctrl_tx(repr
->app
->ctrl
, skb
);
100 nfp_flower_cmsg_portmod_rx(struct nfp_app
*app
, struct sk_buff
*skb
)
102 struct nfp_flower_cmsg_portmod
*msg
;
103 struct net_device
*netdev
;
106 msg
= nfp_flower_cmsg_get_data(skb
);
107 link
= msg
->info
& NFP_FLOWER_CMSG_PORTMOD_INFO_LINK
;
110 netdev
= nfp_app_repr_get(app
, be32_to_cpu(msg
->portnum
));
112 nfp_flower_cmsg_warn(app
, "ctrl msg for unknown port 0x%08x\n",
113 be32_to_cpu(msg
->portnum
));
119 netif_carrier_on(netdev
);
121 netif_carrier_off(netdev
);
125 void nfp_flower_cmsg_rx(struct nfp_app
*app
, struct sk_buff
*skb
)
127 struct nfp_flower_cmsg_hdr
*cmsg_hdr
;
128 enum nfp_flower_cmsg_type_port type
;
130 cmsg_hdr
= nfp_flower_cmsg_get_hdr(skb
);
132 if (unlikely(cmsg_hdr
->version
!= NFP_FLOWER_CMSG_VER1
)) {
133 nfp_flower_cmsg_warn(app
, "Cannot handle repr control version %u\n",
138 type
= cmsg_hdr
->type
;
140 case NFP_FLOWER_CMSG_TYPE_PORT_MOD
:
141 nfp_flower_cmsg_portmod_rx(app
, skb
);
143 case NFP_FLOWER_CMSG_TYPE_FLOW_STATS
:
144 nfp_flower_rx_flow_stats(app
, skb
);
147 nfp_flower_cmsg_warn(app
, "Cannot handle invalid repr control type %u\n",
152 dev_kfree_skb_any(skb
);