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>
39 #include "../nfpcore/nfp_cpp.h"
40 #include "../nfp_net_repr.h"
43 #define nfp_flower_cmsg_warn(app, fmt, args...) \
45 if (net_ratelimit()) \
46 nfp_warn((app)->cpp, fmt, ## args); \
49 static struct nfp_flower_cmsg_hdr
*
50 nfp_flower_cmsg_get_hdr(struct sk_buff
*skb
)
52 return (struct nfp_flower_cmsg_hdr
*)skb
->data
;
55 static void *nfp_flower_cmsg_get_data(struct sk_buff
*skb
)
57 return (unsigned char *)skb
->data
+ NFP_FLOWER_CMSG_HLEN
;
60 static struct sk_buff
*
61 nfp_flower_cmsg_alloc(struct nfp_app
*app
, unsigned int size
,
62 enum nfp_flower_cmsg_type_port type
)
64 struct nfp_flower_cmsg_hdr
*ch
;
67 size
+= NFP_FLOWER_CMSG_HLEN
;
69 skb
= nfp_app_ctrl_msg_alloc(app
, size
, GFP_KERNEL
);
73 ch
= nfp_flower_cmsg_get_hdr(skb
);
75 ch
->version
= NFP_FLOWER_CMSG_VER1
;
82 int nfp_flower_cmsg_portmod(struct nfp_repr
*repr
, bool carrier_ok
)
84 struct nfp_flower_cmsg_portmod
*msg
;
87 skb
= nfp_flower_cmsg_alloc(repr
->app
, sizeof(*msg
),
88 NFP_FLOWER_CMSG_TYPE_PORT_MOD
);
92 msg
= nfp_flower_cmsg_get_data(skb
);
93 msg
->portnum
= cpu_to_be32(repr
->dst
->u
.port_info
.port_id
);
95 msg
->info
= carrier_ok
;
96 msg
->mtu
= cpu_to_be16(repr
->netdev
->mtu
);
98 nfp_ctrl_tx(repr
->app
->ctrl
, skb
);
104 nfp_flower_cmsg_portmod_rx(struct nfp_app
*app
, struct sk_buff
*skb
)
106 struct nfp_flower_cmsg_portmod
*msg
;
107 struct net_device
*netdev
;
110 msg
= nfp_flower_cmsg_get_data(skb
);
111 link
= msg
->info
& NFP_FLOWER_CMSG_PORTMOD_INFO_LINK
;
114 netdev
= nfp_app_repr_get(app
, be32_to_cpu(msg
->portnum
));
116 nfp_flower_cmsg_warn(app
, "ctrl msg for unknown port 0x%08x\n",
117 be32_to_cpu(msg
->portnum
));
123 netif_carrier_on(netdev
);
125 dev_set_mtu(netdev
, be16_to_cpu(msg
->mtu
));
128 netif_carrier_off(netdev
);
133 void nfp_flower_cmsg_rx(struct nfp_app
*app
, struct sk_buff
*skb
)
135 struct nfp_flower_cmsg_hdr
*cmsg_hdr
;
136 enum nfp_flower_cmsg_type_port type
;
138 cmsg_hdr
= nfp_flower_cmsg_get_hdr(skb
);
140 if (unlikely(cmsg_hdr
->version
!= NFP_FLOWER_CMSG_VER1
)) {
141 nfp_flower_cmsg_warn(app
, "Cannot handle repr control version %u\n",
146 type
= cmsg_hdr
->type
;
148 case NFP_FLOWER_CMSG_TYPE_PORT_MOD
:
149 nfp_flower_cmsg_portmod_rx(app
, skb
);
152 nfp_flower_cmsg_warn(app
, "Cannot handle invalid repr control type %u\n",
157 dev_kfree_skb_any(skb
);