xref: /openbmc/qemu/hw/net/rocker/rocker.h (revision a3fb4e93a3a7cf2be355c41cd550bef856f5ffe4)
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
DPRINTF(const char * fmt,...)33*9edc6313SMarc-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 
39dc488f88SScott Feldman #define __le16 uint16_t
40dc488f88SScott Feldman #define __le32 uint32_t
41dc488f88SScott Feldman #define __le64 uint64_t
42dc488f88SScott Feldman 
43dc488f88SScott Feldman #define __be16 uint16_t
44dc488f88SScott Feldman #define __be32 uint32_t
45dc488f88SScott Feldman #define __be64 uint64_t
46dc488f88SScott Feldman 
ipv4_addr_is_multicast(__be32 addr)47dc488f88SScott Feldman static inline bool ipv4_addr_is_multicast(__be32 addr)
48dc488f88SScott Feldman {
49dc488f88SScott Feldman     return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
50dc488f88SScott Feldman }
51dc488f88SScott Feldman 
52dc488f88SScott Feldman typedef struct ipv6_addr {
53dc488f88SScott Feldman     union {
54dc488f88SScott Feldman         uint8_t addr8[16];
55dc488f88SScott Feldman         __be16 addr16[8];
56dc488f88SScott Feldman         __be32 addr32[4];
57dc488f88SScott Feldman     };
58dc488f88SScott Feldman } Ipv6Addr;
59dc488f88SScott Feldman 
ipv6_addr_is_multicast(const Ipv6Addr * addr)60dc488f88SScott Feldman static inline bool ipv6_addr_is_multicast(const Ipv6Addr *addr)
61dc488f88SScott Feldman {
62dc488f88SScott Feldman     return (addr->addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000);
63dc488f88SScott Feldman }
64dc488f88SScott Feldman 
65dc488f88SScott Feldman typedef struct world World;
66dc488f88SScott Feldman typedef struct desc_info DescInfo;
67dc488f88SScott Feldman typedef struct desc_ring DescRing;
68dc488f88SScott Feldman 
698eeb6f36SEduardo Habkost #define TYPE_ROCKER "rocker"
708eeb6f36SEduardo Habkost typedef struct rocker Rocker;
718110fa1dSEduardo Habkost DECLARE_INSTANCE_CHECKER(Rocker, ROCKER,
728110fa1dSEduardo Habkost                          TYPE_ROCKER)
738eeb6f36SEduardo Habkost 
74dc488f88SScott Feldman Rocker *rocker_find(const char *name);
75dc488f88SScott Feldman int rocker_event_link_changed(Rocker *r, uint32_t pport, bool link_up);
76dc488f88SScott Feldman int rocker_event_mac_vlan_seen(Rocker *r, uint32_t pport, uint8_t *addr,
77dc488f88SScott Feldman                                uint16_t vlan_id);
78dc488f88SScott Feldman int rx_produce(World *world, uint32_t pport,
79d0d25558SScott Feldman                const struct iovec *iov, int iovcnt, uint8_t copy_to_cpu);
80dc488f88SScott Feldman int rocker_port_eg(Rocker *r, uint32_t pport,
81dc488f88SScott Feldman                    const struct iovec *iov, int iovcnt);
82dc488f88SScott Feldman 
832a6a4076SMarkus Armbruster #endif /* ROCKER_H */
84