xref: /qemu/hw/net/rocker/rocker.h (revision 5150004ccf5fe72c35b3263fbed6f4d06ed3cc6a)
1dc488f88SScott Feldman /*
2dc488f88SScott Feldman  * QEMU rocker switch emulation
3dc488f88SScott Feldman  *
4dc488f88SScott Feldman  * Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
5dc488f88SScott Feldman  * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
6dc488f88SScott Feldman  * Copyright (c) 2014 Neil Horman <nhorman@tuxdriver.com>
7dc488f88SScott Feldman  *
8dc488f88SScott Feldman  * This program is free software; you can redistribute it and/or modify
9dc488f88SScott Feldman  * it under the terms of the GNU General Public License as published by
10dc488f88SScott Feldman  * the Free Software Foundation; either version 2 of the License, or
11dc488f88SScott Feldman  * (at your option) any later version.
12dc488f88SScott Feldman  *
13dc488f88SScott Feldman  * This program is distributed in the hope that it will be useful,
14dc488f88SScott Feldman  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15dc488f88SScott Feldman  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16dc488f88SScott Feldman  * GNU General Public License for more details.
17dc488f88SScott Feldman  */
18dc488f88SScott Feldman 
192a6a4076SMarkus Armbruster #ifndef ROCKER_H
202a6a4076SMarkus Armbruster #define ROCKER_H
21dc488f88SScott Feldman 
22dc488f88SScott Feldman #include "qemu/sockets.h"
23db1015e9SEduardo Habkost #include "qom/object.h"
24dc488f88SScott Feldman 
25dc488f88SScott Feldman #if defined(DEBUG_ROCKER)
26dc488f88SScott Feldman #  define DPRINTF(fmt, ...) \
277db161f6SDavid Ahern     do {                                                           \
2896916f36SDaniel P. Berrangé         g_autoptr(GDateTime) now = g_date_time_new_now_local();    \
2996916f36SDaniel P. Berrangé         g_autofree char *nowstr = g_date_time_format(now, "%T.%f");\
3096916f36SDaniel P. Berrangé         fprintf(stderr, "%s ROCKER: " fmt, nowstr, ## __VA_ARGS__);\
317db161f6SDavid Ahern     } while (0)
32dc488f88SScott Feldman #else
339edc6313SMarc-André Lureau static inline G_GNUC_PRINTF(1, 2) int DPRINTF(const char *fmt, ...)
34dc488f88SScott Feldman {
35dc488f88SScott Feldman     return 0;
36dc488f88SScott Feldman }
37dc488f88SScott Feldman #endif
38dc488f88SScott Feldman 
39*5150004cSPaolo Bonzini static inline bool ipv4_addr_is_multicast(uint32_t addr)
40dc488f88SScott Feldman {
41dc488f88SScott Feldman     return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
42dc488f88SScott Feldman }
43dc488f88SScott Feldman 
44dc488f88SScott Feldman typedef struct ipv6_addr {
45dc488f88SScott Feldman     union {
46dc488f88SScott Feldman         uint8_t addr8[16];
47*5150004cSPaolo Bonzini         uint16_t addr16[8];
48*5150004cSPaolo Bonzini         uint32_t addr32[4];
49dc488f88SScott Feldman     };
50dc488f88SScott Feldman } Ipv6Addr;
51dc488f88SScott Feldman 
52dc488f88SScott Feldman static inline bool ipv6_addr_is_multicast(const Ipv6Addr *addr)
53dc488f88SScott Feldman {
54dc488f88SScott Feldman     return (addr->addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000);
55dc488f88SScott Feldman }
56dc488f88SScott Feldman 
57dc488f88SScott Feldman typedef struct world World;
58dc488f88SScott Feldman typedef struct desc_info DescInfo;
59dc488f88SScott Feldman typedef struct desc_ring DescRing;
60dc488f88SScott Feldman 
618eeb6f36SEduardo Habkost #define TYPE_ROCKER "rocker"
628eeb6f36SEduardo Habkost typedef struct rocker Rocker;
638110fa1dSEduardo Habkost DECLARE_INSTANCE_CHECKER(Rocker, ROCKER,
648110fa1dSEduardo Habkost                          TYPE_ROCKER)
658eeb6f36SEduardo Habkost 
66dc488f88SScott Feldman Rocker *rocker_find(const char *name);
67dc488f88SScott Feldman int rocker_event_link_changed(Rocker *r, uint32_t pport, bool link_up);
68dc488f88SScott Feldman int rocker_event_mac_vlan_seen(Rocker *r, uint32_t pport, uint8_t *addr,
69dc488f88SScott Feldman                                uint16_t vlan_id);
70dc488f88SScott Feldman int rx_produce(World *world, uint32_t pport,
71d0d25558SScott Feldman                const struct iovec *iov, int iovcnt, uint8_t copy_to_cpu);
72dc488f88SScott Feldman int rocker_port_eg(Rocker *r, uint32_t pport,
73dc488f88SScott Feldman                    const struct iovec *iov, int iovcnt);
74dc488f88SScott Feldman 
752a6a4076SMarkus Armbruster #endif /* ROCKER_H */
76