* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "hw.h"
#endif
#ifdef DEBUG_SONIC
-#define DPRINTF(fmt, args...) \
-do { printf("sonic: " fmt , ##args); } while (0)
+#define DPRINTF(fmt, ...) \
+do { printf("sonic: " fmt , ## __VA_ARGS__); } while (0)
static const char* reg_names[] = {
"CR", "DCR", "RCR", "TCR", "IMR", "ISR", "UTDA", "CTDA",
"TPS", "TFC", "TSA0", "TSA1", "TFS", "URDA", "CRDA", "CRBA0",
"0x30", "0x31", "0x32", "0x33", "0x34", "0x35", "0x36", "0x37",
"0x38", "0x39", "0x3a", "0x3b", "0x3c", "0x3d", "0x3e", "DCR2" };
#else
-#define DPRINTF(fmt, args...) do {} while (0)
+#define DPRINTF(fmt, ...) do {} while (0)
#endif
-#define SONIC_ERROR(fmt, args...) \
-do { printf("sonic ERROR: %s: " fmt, __func__ , ##args); } while (0)
+#define SONIC_ERROR(fmt, ...) \
+do { printf("sonic ERROR: %s: " fmt, __func__ , ## __VA_ARGS__); } while (0)
#define SONIC_CR 0x00
#define SONIC_DCR 0x01
#endif
QEMUTimer *watchdog;
int64_t wt_last_update;
- VLANClientState *vc;
+ NICConf conf;
+ NICState *nic;
int mmio_index;
/* Registers */
ticks = s->regs[SONIC_WT1] << 16 | s->regs[SONIC_WT0];
s->wt_last_update = qemu_get_clock(vm_clock);
- delay = ticks_per_sec * ticks / 5000000;
+ delay = get_ticks_per_sec() * ticks / 5000000;
qemu_mod_timer(s->watchdog, s->wt_last_update + delay);
}
if (s->regs[SONIC_RCR] & (SONIC_RCR_LB1 | SONIC_RCR_LB0)) {
/* Loopback */
s->regs[SONIC_TCR] |= SONIC_TCR_CRSL;
- if (s->vc->fd_can_read(s)) {
+ if (s->nic->nc.info->can_receive(&s->nic->nc)) {
s->loopback_packet = 1;
- s->vc->fd_read(s, s->tx_buffer, tx_len);
+ s->nic->nc.info->receive(&s->nic->nc, s->tx_buffer, tx_len);
}
} else {
/* Transmit packet */
- qemu_send_packet(s->vc, s->tx_buffer, tx_len);
+ qemu_send_packet(&s->nic->nc, s->tx_buffer, tx_len);
}
s->regs[SONIC_TCR] |= SONIC_TCR_PTX;
dp8393x_writew(opaque, addr + 2, (val >> 16) & 0xffff);
}
-static CPUReadMemoryFunc *dp8393x_read[3] = {
+static CPUReadMemoryFunc * const dp8393x_read[3] = {
dp8393x_readb,
dp8393x_readw,
dp8393x_readl,
};
-static CPUWriteMemoryFunc *dp8393x_write[3] = {
+static CPUWriteMemoryFunc * const dp8393x_write[3] = {
dp8393x_writeb,
dp8393x_writew,
dp8393x_writel,
};
-static int nic_can_receive(void *opaque)
+static int nic_can_receive(VLANClientState *nc)
{
- dp8393xState *s = opaque;
+ dp8393xState *s = DO_UPCAST(NICState, nc, nc)->opaque;
if (!(s->regs[SONIC_CR] & SONIC_CR_RXEN))
return 0;
return -1;
}
-static void nic_receive(void *opaque, const uint8_t * buf, int size)
+static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size)
{
+ dp8393xState *s = DO_UPCAST(NICState, nc, nc)->opaque;
uint16_t data[10];
- dp8393xState *s = opaque;
int packet_type;
uint32_t available, address;
int width, rx_len = size;
packet_type = receive_filter(s, buf, size);
if (packet_type < 0) {
DPRINTF("packet not for netcard\n");
- return;
+ return -1;
}
/* XXX: Check byte ordering */
s->memory_rw(s->mem_opaque, address, (uint8_t*)data, size, 0);
if (data[0 * width] & 0x1) {
/* Still EOL ; stop reception */
- return;
+ return -1;
} else {
s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA];
}
/* Done */
dp8393x_update_irq(s);
+
+ return size;
}
static void nic_reset(void *opaque)
dp8393x_update_irq(s);
}
-static void nic_cleanup(VLANClientState *vc)
+static void nic_cleanup(VLANClientState *nc)
{
- dp8393xState *s = vc->opaque;
+ dp8393xState *s = DO_UPCAST(NICState, nc, nc)->opaque;
cpu_unregister_io_memory(s->mmio_index);
qemu_free(s);
}
+static NetClientInfo net_dp83932_info = {
+ .type = NET_CLIENT_TYPE_NIC,
+ .size = sizeof(NICState),
+ .can_receive = nic_can_receive,
+ .receive = nic_receive,
+ .cleanup = nic_cleanup,
+};
+
void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift,
qemu_irq irq, void* mem_opaque,
void (*memory_rw)(void *opaque, target_phys_addr_t addr, uint8_t *buf, int len, int is_write))
s->watchdog = qemu_new_timer(vm_clock, dp8393x_watchdog, s);
s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */
- s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
- nic_receive, nic_can_receive, nic_cleanup, s);
+ memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(s->conf.macaddr));
+ s->conf.vlan = nd->vlan;
+ s->conf.peer = nd->netdev;
+
+ s->nic = qemu_new_nic(&net_dp83932_info, &s->conf, nd->model, nd->name, s);
- qemu_format_nic_info_str(s->vc, nd->macaddr);
+ qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
qemu_register_reset(nic_reset, s);
nic_reset(s);
- s->mmio_index = cpu_register_io_memory(0, dp8393x_read, dp8393x_write, s);
+ s->mmio_index = cpu_register_io_memory(dp8393x_read, dp8393x_write, s);
cpu_register_physical_memory(base, 0x40 << it_shift, s->mmio_index);
}