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" 23*db1015e9SEduardo Habkost #include "qom/object.h" 24dc488f88SScott Feldman 25dc488f88SScott Feldman #if defined(DEBUG_ROCKER) 26dc488f88SScott Feldman # define DPRINTF(fmt, ...) \ 277db161f6SDavid Ahern do { \ 287db161f6SDavid Ahern struct timeval tv; \ 297db161f6SDavid Ahern char timestr[64]; \ 307db161f6SDavid Ahern time_t now; \ 317db161f6SDavid Ahern gettimeofday(&tv, NULL); \ 327db161f6SDavid Ahern now = tv.tv_sec; \ 337db161f6SDavid Ahern strftime(timestr, sizeof(timestr), "%T", localtime(&now)); \ 347db161f6SDavid Ahern fprintf(stderr, "%s.%06ld ", timestr, tv.tv_usec); \ 357db161f6SDavid Ahern fprintf(stderr, "ROCKER: " fmt, ## __VA_ARGS__); \ 367db161f6SDavid Ahern } while (0) 37dc488f88SScott Feldman #else 38dc488f88SScott Feldman static inline GCC_FMT_ATTR(1, 2) int DPRINTF(const char *fmt, ...) 39dc488f88SScott Feldman { 40dc488f88SScott Feldman return 0; 41dc488f88SScott Feldman } 42dc488f88SScott Feldman #endif 43dc488f88SScott Feldman 44dc488f88SScott Feldman #define __le16 uint16_t 45dc488f88SScott Feldman #define __le32 uint32_t 46dc488f88SScott Feldman #define __le64 uint64_t 47dc488f88SScott Feldman 48dc488f88SScott Feldman #define __be16 uint16_t 49dc488f88SScott Feldman #define __be32 uint32_t 50dc488f88SScott Feldman #define __be64 uint64_t 51dc488f88SScott Feldman 52dc488f88SScott Feldman static inline bool ipv4_addr_is_multicast(__be32 addr) 53dc488f88SScott Feldman { 54dc488f88SScott Feldman return (addr & htonl(0xf0000000)) == htonl(0xe0000000); 55dc488f88SScott Feldman } 56dc488f88SScott Feldman 57dc488f88SScott Feldman typedef struct ipv6_addr { 58dc488f88SScott Feldman union { 59dc488f88SScott Feldman uint8_t addr8[16]; 60dc488f88SScott Feldman __be16 addr16[8]; 61dc488f88SScott Feldman __be32 addr32[4]; 62dc488f88SScott Feldman }; 63dc488f88SScott Feldman } Ipv6Addr; 64dc488f88SScott Feldman 65dc488f88SScott Feldman static inline bool ipv6_addr_is_multicast(const Ipv6Addr *addr) 66dc488f88SScott Feldman { 67dc488f88SScott Feldman return (addr->addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000); 68dc488f88SScott Feldman } 69dc488f88SScott Feldman 70dc488f88SScott Feldman typedef struct world World; 71dc488f88SScott Feldman typedef struct desc_info DescInfo; 72dc488f88SScott Feldman typedef struct desc_ring DescRing; 73dc488f88SScott Feldman 748eeb6f36SEduardo Habkost #define TYPE_ROCKER "rocker" 758eeb6f36SEduardo Habkost typedef struct rocker Rocker; 768eeb6f36SEduardo Habkost #define ROCKER(obj) \ 778eeb6f36SEduardo Habkost OBJECT_CHECK(Rocker, (obj), TYPE_ROCKER) 788eeb6f36SEduardo Habkost 79dc488f88SScott Feldman Rocker *rocker_find(const char *name); 80dc488f88SScott Feldman uint32_t rocker_fp_ports(Rocker *r); 81dc488f88SScott Feldman int rocker_event_link_changed(Rocker *r, uint32_t pport, bool link_up); 82dc488f88SScott Feldman int rocker_event_mac_vlan_seen(Rocker *r, uint32_t pport, uint8_t *addr, 83dc488f88SScott Feldman uint16_t vlan_id); 84dc488f88SScott Feldman int rx_produce(World *world, uint32_t pport, 85d0d25558SScott Feldman const struct iovec *iov, int iovcnt, uint8_t copy_to_cpu); 86dc488f88SScott Feldman int rocker_port_eg(Rocker *r, uint32_t pport, 87dc488f88SScott Feldman const struct iovec *iov, int iovcnt); 88dc488f88SScott Feldman 892a6a4076SMarkus Armbruster #endif /* ROCKER_H */ 90