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