2004-01-13 22:21:21 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2004-01-13 22:21:21 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2003 Fen Systems Ltd.
|
|
|
|
// http://www.fensystems.co.uk/
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2009-02-08 12:05:52 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2008-02-16 01:05:43 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2004-01-13 22:21:21 +03:00
|
|
|
|
|
|
|
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
|
2008-01-27 01:24:03 +03:00
|
|
|
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
|
2004-01-13 22:21:21 +03:00
|
|
|
// is used to know when we are exporting symbols and when we are importing.
|
2006-04-26 04:04:49 +04:00
|
|
|
|
2004-01-13 22:21:21 +03:00
|
|
|
#define BX_PLUGGABLE
|
|
|
|
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev.h"
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_PCI && BX_SUPPORT_PCIPNIC
|
2004-01-13 22:21:21 +03:00
|
|
|
|
2009-01-13 21:56:35 +03:00
|
|
|
#include "pci.h"
|
2011-08-16 21:27:27 +04:00
|
|
|
#include "netmod.h"
|
2008-12-30 18:33:38 +03:00
|
|
|
#include "pcipnic.h"
|
2004-10-03 23:30:36 +04:00
|
|
|
|
2004-01-13 22:21:21 +03:00
|
|
|
#define LOG_THIS thePNICDevice->
|
|
|
|
|
|
|
|
bx_pcipnic_c* thePNICDevice = NULL;
|
|
|
|
|
2005-06-04 11:58:02 +04:00
|
|
|
const Bit8u pnic_iomask[16] = {2, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
2004-07-13 21:45:34 +04:00
|
|
|
|
2006-09-10 21:18:44 +04:00
|
|
|
int libpcipnic_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[])
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
2006-09-10 21:18:44 +04:00
|
|
|
thePNICDevice = new bx_pcipnic_c();
|
2004-01-13 22:21:21 +03:00
|
|
|
BX_REGISTER_DEVICE_DEVMODEL(plugin, type, thePNICDevice, BX_PLUGIN_PCIPNIC);
|
|
|
|
return 0; // Success
|
|
|
|
}
|
|
|
|
|
2006-09-10 21:18:44 +04:00
|
|
|
void libpcipnic_LTX_plugin_fini(void)
|
|
|
|
{
|
|
|
|
delete thePNICDevice;
|
|
|
|
}
|
2004-01-13 22:21:21 +03:00
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
bx_pcipnic_c::bx_pcipnic_c()
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
|
|
|
put("PNIC");
|
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
bx_pcipnic_c::~bx_pcipnic_c()
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
2006-09-10 21:18:44 +04:00
|
|
|
BX_DEBUG(("Exit"));
|
2004-01-13 22:21:21 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_pcipnic_c::init(void)
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
2006-04-26 04:04:49 +04:00
|
|
|
bx_list_c *base;
|
2004-01-13 22:21:21 +03:00
|
|
|
|
2006-03-02 23:13:14 +03:00
|
|
|
// Read in values from config interface
|
|
|
|
base = (bx_list_c*) SIM->get_param(BXPN_PNIC);
|
2006-04-26 04:04:49 +04:00
|
|
|
memcpy(BX_PNIC_THIS s.macaddr, SIM->get_param_string("macaddr", base)->getptr(), 6);
|
2004-01-13 22:21:21 +03:00
|
|
|
|
2004-07-13 21:45:34 +04:00
|
|
|
BX_PNIC_THIS s.devfunc = 0x00;
|
2006-03-08 00:11:20 +03:00
|
|
|
DEV_register_pci_handlers(this, &BX_PNIC_THIS s.devfunc, BX_PLUGIN_PCIPNIC,
|
2004-01-13 22:21:21 +03:00
|
|
|
"Experimental PCI Pseudo NIC");
|
|
|
|
|
|
|
|
for (unsigned i=0; i<256; i++) {
|
2011-06-23 19:56:02 +04:00
|
|
|
BX_PNIC_THIS pci_conf[i] = 0x0;
|
2004-01-13 22:21:21 +03:00
|
|
|
}
|
|
|
|
|
2011-08-16 21:27:27 +04:00
|
|
|
// Attach to the selected ethernet module
|
|
|
|
BX_PNIC_THIS ethdev = DEV_net_init_module(base, rx_handler, this);
|
2004-01-13 22:21:21 +03:00
|
|
|
|
2011-06-25 16:43:27 +04:00
|
|
|
BX_PNIC_THIS pci_base_address[4] = 0;
|
2004-07-13 21:45:34 +04:00
|
|
|
|
2005-09-23 01:12:26 +04:00
|
|
|
BX_INFO(("PCI Pseudo NIC initialized - I/O base and IRQ assigned by PCI BIOS"));
|
2004-01-13 22:21:21 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_pcipnic_c::reset(unsigned type)
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
static const struct reset_vals_t {
|
|
|
|
unsigned addr;
|
|
|
|
unsigned char val;
|
|
|
|
} reset_vals[] = {
|
|
|
|
{ 0x00, PNIC_PCI_VENDOR & 0xff },
|
|
|
|
{ 0x01, PNIC_PCI_VENDOR >> 8 },
|
|
|
|
{ 0x02, PNIC_PCI_DEVICE & 0xff },
|
|
|
|
{ 0x03, PNIC_PCI_DEVICE >> 8 },
|
|
|
|
{ 0x04, 0x05 }, { 0x05, 0x00 }, // command_io
|
|
|
|
{ 0x06, 0x80 }, { 0x07, 0x02 }, // status
|
|
|
|
{ 0x08, 0x01 }, // revision number
|
|
|
|
{ 0x09, 0x00 }, // interface
|
2004-03-24 21:16:27 +03:00
|
|
|
{ 0x0a, 0x00 }, // class_sub
|
|
|
|
{ 0x0b, 0x02 }, // class_base Network Controller
|
2004-01-13 22:21:21 +03:00
|
|
|
{ 0x0D, 0x20 }, // bus latency
|
|
|
|
{ 0x0e, 0x00 }, // header_type_generic
|
|
|
|
// address space 0x20 - 0x23
|
2005-09-23 01:12:26 +04:00
|
|
|
{ 0x20, 0x01 }, { 0x21, 0x00 },
|
2004-01-13 22:21:21 +03:00
|
|
|
{ 0x22, 0x00 }, { 0x23, 0x00 },
|
2004-09-26 02:15:02 +04:00
|
|
|
{ 0x3c, 0x00, }, // IRQ
|
|
|
|
{ 0x3d, BX_PCI_INTA }, // INT
|
2004-01-13 22:21:21 +03:00
|
|
|
{ 0x6a, 0x01 }, // PNIC clock
|
|
|
|
{ 0xc1, 0x20 } // PIRQ enable
|
|
|
|
|
|
|
|
};
|
|
|
|
for (i = 0; i < sizeof(reset_vals) / sizeof(*reset_vals); ++i) {
|
2011-06-23 19:56:02 +04:00
|
|
|
BX_PNIC_THIS pci_conf[reset_vals[i].addr] = reset_vals[i].val;
|
2004-01-13 22:21:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set up initial register values
|
|
|
|
BX_PNIC_THIS s.rCmd = PNIC_CMD_NOOP;
|
|
|
|
BX_PNIC_THIS s.rStatus = PNIC_STATUS_OK;
|
|
|
|
BX_PNIC_THIS s.rLength = 0;
|
|
|
|
BX_PNIC_THIS s.rDataCursor = 0;
|
|
|
|
BX_PNIC_THIS s.recvIndex = 0;
|
|
|
|
BX_PNIC_THIS s.recvQueueLength = 0;
|
2004-03-26 06:22:46 +03:00
|
|
|
BX_PNIC_THIS s.irqEnabled = 0;
|
|
|
|
|
|
|
|
// Deassert IRQ
|
2004-07-13 21:45:34 +04:00
|
|
|
set_irq_level(0);
|
|
|
|
}
|
|
|
|
|
2006-05-27 19:54:49 +04:00
|
|
|
void bx_pcipnic_c::register_state(void)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
char name[6];
|
|
|
|
|
2007-09-28 23:52:08 +04:00
|
|
|
bx_list_c *list = new bx_list_c(SIM->get_bochs_root(), "pcipnic", "PCI Pseudo NIC State", 11);
|
2006-05-27 19:54:49 +04:00
|
|
|
new bx_shadow_num_c(list, "irqEnabled", &BX_PNIC_THIS s.irqEnabled);
|
|
|
|
new bx_shadow_num_c(list, "rCmd", &BX_PNIC_THIS s.rCmd);
|
|
|
|
new bx_shadow_num_c(list, "rStatus", &BX_PNIC_THIS s.rStatus);
|
|
|
|
new bx_shadow_num_c(list, "rLength", &BX_PNIC_THIS s.rLength);
|
|
|
|
new bx_shadow_num_c(list, "rDataCursor", &BX_PNIC_THIS s.rDataCursor);
|
|
|
|
new bx_shadow_num_c(list, "recvIndex", &BX_PNIC_THIS s.recvIndex);
|
|
|
|
new bx_shadow_num_c(list, "recvQueueLength", &BX_PNIC_THIS s.recvQueueLength);
|
|
|
|
bx_list_c *recvRL = new bx_list_c(list, "recvRingLength", PNIC_RECV_RINGS);
|
|
|
|
for (i=0; i<PNIC_RECV_RINGS; i++) {
|
|
|
|
sprintf(name, "%d", i);
|
2006-05-30 02:33:38 +04:00
|
|
|
new bx_shadow_num_c(recvRL, name, &BX_PNIC_THIS s.recvRingLength[i]);
|
2006-05-27 19:54:49 +04:00
|
|
|
}
|
|
|
|
new bx_shadow_data_c(list, "rData", BX_PNIC_THIS s.rData, PNIC_DATA_SIZE);
|
|
|
|
new bx_shadow_data_c(list, "recvRing", (Bit8u*)BX_PNIC_THIS s.recvRing, PNIC_RECV_RINGS*PNIC_DATA_SIZE);
|
2011-06-23 19:56:02 +04:00
|
|
|
register_pci_state(list);
|
2006-05-27 19:54:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void bx_pcipnic_c::after_restore_state(void)
|
|
|
|
{
|
|
|
|
if (DEV_pci_set_base_io(BX_PNIC_THIS_PTR, read_handler, write_handler,
|
2011-06-25 16:43:27 +04:00
|
|
|
&BX_PNIC_THIS pci_base_address[4],
|
2011-06-23 19:56:02 +04:00
|
|
|
&BX_PNIC_THIS pci_conf[0x10],
|
2006-05-27 19:54:49 +04:00
|
|
|
16, &pnic_iomask[0], "PNIC")) {
|
2011-06-25 16:43:27 +04:00
|
|
|
BX_INFO(("new base address: 0x%04x", BX_PNIC_THIS pci_base_address[4]));
|
2006-05-27 19:54:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_pcipnic_c::set_irq_level(bx_bool level)
|
2004-07-13 21:45:34 +04:00
|
|
|
{
|
2011-06-23 19:56:02 +04:00
|
|
|
DEV_pci_set_irq(BX_PNIC_THIS s.devfunc, BX_PNIC_THIS pci_conf[0x3d], level);
|
2004-01-13 22:21:21 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
// static IO port read callback handler
|
|
|
|
// redirects to non-static class handler to avoid virtual functions
|
2004-01-13 22:21:21 +03:00
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
Bit32u bx_pcipnic_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len)
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
|
|
|
#if !BX_USE_PCIPNIC_SMF
|
|
|
|
bx_pcipnic_c *class_ptr = (bx_pcipnic_c *) this_ptr;
|
2006-03-08 00:11:20 +03:00
|
|
|
return class_ptr->read(address, io_len);
|
2004-01-13 22:21:21 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
Bit32u bx_pcipnic_c::read(Bit32u address, unsigned io_len)
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
#endif // !BX_USE_PCIPNIC_SMF
|
|
|
|
Bit32u val = 0x0;
|
2004-07-13 21:45:34 +04:00
|
|
|
Bit8u offset;
|
2004-01-13 22:21:21 +03:00
|
|
|
|
|
|
|
BX_DEBUG(("register read from address 0x%04x - ", (unsigned) address));
|
|
|
|
|
2011-06-25 16:43:27 +04:00
|
|
|
offset = address - BX_PNIC_THIS pci_base_address[4];
|
2004-01-13 22:21:21 +03:00
|
|
|
|
|
|
|
switch (offset) {
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_REG_STAT:
|
2004-01-13 22:21:21 +03:00
|
|
|
val = BX_PNIC_THIS s.rStatus;
|
|
|
|
break;
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_REG_LEN:
|
2004-01-13 22:21:21 +03:00
|
|
|
val = BX_PNIC_THIS s.rLength;
|
|
|
|
break;
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_REG_DATA:
|
|
|
|
if (BX_PNIC_THIS s.rDataCursor >= BX_PNIC_THIS s.rLength)
|
2004-01-13 22:21:21 +03:00
|
|
|
BX_PANIC(("PNIC read at %u, beyond end of data register array",
|
|
|
|
BX_PNIC_THIS s.rDataCursor));
|
2008-02-16 01:05:43 +03:00
|
|
|
val = BX_PNIC_THIS s.rData[BX_PNIC_THIS s.rDataCursor++];
|
2004-01-13 22:21:21 +03:00
|
|
|
break;
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2004-01-13 22:21:21 +03:00
|
|
|
default :
|
|
|
|
val = 0; // keep compiler happy
|
|
|
|
BX_PANIC(("unsupported io read from address=0x%04x!", (unsigned) address));
|
|
|
|
break;
|
|
|
|
}
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2004-01-13 22:21:21 +03:00
|
|
|
BX_DEBUG(("val = 0x%04x", (Bit16u) val));
|
|
|
|
|
|
|
|
return(val);
|
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
// static IO port write callback handler
|
|
|
|
// redirects to non-static class handler to avoid virtual functions
|
2004-01-13 22:21:21 +03:00
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_pcipnic_c::write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len)
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
|
|
|
#if !BX_USE_PCIPNIC_SMF
|
|
|
|
bx_pcipnic_c *class_ptr = (bx_pcipnic_c *) this_ptr;
|
|
|
|
|
|
|
|
class_ptr->write(address, value, io_len);
|
|
|
|
}
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_pcipnic_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
#endif // !BX_USE_PCIPNIC_SMF
|
2004-07-13 21:45:34 +04:00
|
|
|
Bit8u offset;
|
2004-01-13 22:21:21 +03:00
|
|
|
|
|
|
|
BX_DEBUG(("register write to address 0x%04x - ", (unsigned) address));
|
|
|
|
|
2011-06-25 16:43:27 +04:00
|
|
|
offset = address - BX_PNIC_THIS pci_base_address[4];
|
2004-01-13 22:21:21 +03:00
|
|
|
|
|
|
|
switch (offset) {
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_REG_CMD:
|
2004-01-13 22:21:21 +03:00
|
|
|
BX_PNIC_THIS s.rCmd = value;
|
|
|
|
BX_PNIC_THIS exec_command();
|
|
|
|
break;
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_REG_LEN:
|
|
|
|
if (value > PNIC_DATA_SIZE)
|
2004-01-13 22:21:21 +03:00
|
|
|
BX_PANIC(("PNIC bad length %u written to length register, max is %u",
|
|
|
|
value, PNIC_DATA_SIZE));
|
|
|
|
BX_PNIC_THIS s.rLength = value;
|
|
|
|
BX_PNIC_THIS s.rDataCursor = 0;
|
|
|
|
break;
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_REG_DATA:
|
|
|
|
if (BX_PNIC_THIS s.rDataCursor >= BX_PNIC_THIS s.rLength)
|
2004-01-13 22:21:21 +03:00
|
|
|
BX_PANIC(("PNIC write at %u, beyond end of data register array",
|
|
|
|
BX_PNIC_THIS s.rDataCursor));
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_PNIC_THIS s.rData[BX_PNIC_THIS s.rDataCursor++] = value;
|
2004-01-13 22:21:21 +03:00
|
|
|
break;
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2004-01-13 22:21:21 +03:00
|
|
|
default:
|
|
|
|
BX_PANIC(("unsupported io write to address=0x%04x!", (unsigned) address));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_pcipnic_c::pnic_timer_handler(void *this_ptr)
|
|
|
|
{
|
|
|
|
bx_pcipnic_c *class_ptr = (bx_pcipnic_c *) this_ptr;
|
|
|
|
class_ptr->pnic_timer();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called once every 1ms
|
|
|
|
void bx_pcipnic_c::pnic_timer(void)
|
|
|
|
{
|
|
|
|
// Do nothing atm
|
|
|
|
|
|
|
|
}
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
// pci configuration space read callback handler
|
|
|
|
Bit32u bx_pcipnic_c::pci_read_handler(Bit8u address, unsigned io_len)
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
|
|
|
Bit32u value = 0;
|
|
|
|
|
|
|
|
for (unsigned i=0; i<io_len; i++) {
|
2011-06-23 19:56:02 +04:00
|
|
|
value |= (BX_PNIC_THIS pci_conf[address+i] << (i*8));
|
2004-01-13 22:21:21 +03:00
|
|
|
}
|
2009-04-22 23:11:01 +04:00
|
|
|
|
|
|
|
if (io_len == 1)
|
2009-04-23 19:52:53 +04:00
|
|
|
BX_DEBUG(("read PCI register 0x%02x value 0x%02x", address, value));
|
2009-04-22 23:11:01 +04:00
|
|
|
else if (io_len == 2)
|
2009-04-23 19:52:53 +04:00
|
|
|
BX_DEBUG(("read PCI register 0x%02x value 0x%04x", address, value));
|
2009-04-22 23:11:01 +04:00
|
|
|
else if (io_len == 4)
|
2009-04-23 19:52:53 +04:00
|
|
|
BX_DEBUG(("read PCI register 0x%02x value 0x%08x", address, value));
|
2009-04-22 23:11:01 +04:00
|
|
|
|
2004-01-13 22:21:21 +03:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
// pci configuration space write callback handler
|
|
|
|
void bx_pcipnic_c::pci_write_handler(Bit8u address, Bit32u value, unsigned io_len)
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
2004-07-13 21:45:34 +04:00
|
|
|
Bit8u value8, oldval;
|
|
|
|
bx_bool baseaddr_change = 0;
|
|
|
|
|
|
|
|
if (((address >= 0x10) && (address < 0x20)) ||
|
|
|
|
((address > 0x23) && (address < 0x34)))
|
2004-01-13 22:21:21 +03:00
|
|
|
return;
|
2004-07-13 21:45:34 +04:00
|
|
|
|
2009-04-21 21:53:29 +04:00
|
|
|
for (unsigned i=0; i<io_len; i++) {
|
|
|
|
value8 = (value >> (i*8)) & 0xFF;
|
2011-06-23 19:56:02 +04:00
|
|
|
oldval = BX_PNIC_THIS pci_conf[address+i];
|
2009-04-21 21:53:29 +04:00
|
|
|
switch (address+i) {
|
|
|
|
case 0x3d: //
|
|
|
|
case 0x05: // disallowing write to command hi-byte
|
|
|
|
case 0x06: // disallowing write to status lo-byte (is that expected?)
|
|
|
|
break;
|
|
|
|
case 0x3c:
|
|
|
|
if (value8 != oldval) {
|
|
|
|
BX_INFO(("new irq line = %d", value8));
|
2011-06-23 19:56:02 +04:00
|
|
|
BX_PNIC_THIS pci_conf[address+i] = value8;
|
2009-04-21 21:53:29 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x20:
|
|
|
|
value8 = (value8 & 0xfc) | 0x01;
|
|
|
|
case 0x21:
|
|
|
|
case 0x22:
|
|
|
|
case 0x23:
|
|
|
|
baseaddr_change = (value8 != oldval);
|
|
|
|
default:
|
2011-06-23 19:56:02 +04:00
|
|
|
BX_PNIC_THIS pci_conf[address+i] = value8;
|
2004-07-13 21:45:34 +04:00
|
|
|
}
|
2009-04-21 21:53:29 +04:00
|
|
|
}
|
|
|
|
if (baseaddr_change) {
|
|
|
|
if (DEV_pci_set_base_io(BX_PNIC_THIS_PTR, read_handler, write_handler,
|
2011-06-25 16:43:27 +04:00
|
|
|
&BX_PNIC_THIS pci_base_address[4],
|
2011-06-23 19:56:02 +04:00
|
|
|
&BX_PNIC_THIS pci_conf[0x20],
|
2009-04-21 21:53:29 +04:00
|
|
|
16, &pnic_iomask[0], "PNIC")) {
|
2011-06-25 16:43:27 +04:00
|
|
|
BX_INFO(("new base address: 0x%04x", BX_PNIC_THIS pci_base_address[4]));
|
2004-01-13 22:21:21 +03:00
|
|
|
}
|
|
|
|
}
|
2009-04-23 19:52:53 +04:00
|
|
|
|
|
|
|
if (io_len == 1)
|
|
|
|
BX_DEBUG(("write PCI register 0x%02x value 0x%02x", address, value));
|
|
|
|
else if (io_len == 2)
|
|
|
|
BX_DEBUG(("write PCI register 0x%02x value 0x%04x", address, value));
|
|
|
|
else if (io_len == 4)
|
|
|
|
BX_DEBUG(("write PCI register 0x%02x value 0x%08x", address, value));
|
2004-01-13 22:21:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Execute a hardware command.
|
|
|
|
*/
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_pcipnic_c::exec_command(void)
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
|
|
|
Bit16u command = BX_PNIC_THIS s.rCmd;
|
|
|
|
Bit16u ilength = BX_PNIC_THIS s.rLength;
|
|
|
|
Bit8u *data = BX_PNIC_THIS s.rData;
|
|
|
|
// Default return values
|
|
|
|
Bit16u status = PNIC_STATUS_UNKNOWN_CMD;
|
|
|
|
Bit16u olength = 0;
|
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
if (ilength != BX_PNIC_THIS s.rDataCursor)
|
2004-01-13 22:21:21 +03:00
|
|
|
BX_PANIC(("PNIC command issued with incomplete data (should be %u, is %u)",
|
2008-02-16 01:05:43 +03:00
|
|
|
ilength, BX_PNIC_THIS s.rDataCursor));
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
switch (command) {
|
|
|
|
case PNIC_CMD_NOOP:
|
2004-01-13 22:21:21 +03:00
|
|
|
status = PNIC_STATUS_OK;
|
|
|
|
break;
|
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_CMD_API_VER:
|
2004-01-13 22:21:21 +03:00
|
|
|
Bit16u api_version;
|
|
|
|
|
|
|
|
api_version = PNIC_API_VERSION;
|
|
|
|
olength = sizeof(api_version);
|
2008-02-16 01:05:43 +03:00
|
|
|
memcpy (data, &api_version, sizeof(api_version));
|
2004-01-13 22:21:21 +03:00
|
|
|
status = PNIC_STATUS_OK;
|
|
|
|
break;
|
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_CMD_READ_MAC:
|
|
|
|
olength = sizeof (BX_PNIC_THIS s.macaddr);
|
|
|
|
memcpy (data, BX_PNIC_THIS s.macaddr, olength);
|
2004-01-13 22:21:21 +03:00
|
|
|
status = PNIC_STATUS_OK;
|
|
|
|
break;
|
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_CMD_RESET:
|
2004-01-13 22:21:21 +03:00
|
|
|
/* Flush the receive queue */
|
|
|
|
BX_PNIC_THIS s.recvQueueLength = 0;
|
|
|
|
status = PNIC_STATUS_OK;
|
|
|
|
break;
|
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_CMD_XMIT:
|
2006-05-27 19:54:49 +04:00
|
|
|
BX_PNIC_THIS ethdev->sendpkt(data, ilength);
|
|
|
|
if (BX_PNIC_THIS s.irqEnabled) {
|
2006-04-26 04:04:49 +04:00
|
|
|
set_irq_level(1);
|
|
|
|
}
|
2004-01-13 22:21:21 +03:00
|
|
|
status = PNIC_STATUS_OK;
|
|
|
|
break;
|
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_CMD_RECV:
|
|
|
|
if (BX_PNIC_THIS s.recvQueueLength > 0) {
|
|
|
|
int idx = (BX_PNIC_THIS s.recvIndex - BX_PNIC_THIS s.recvQueueLength
|
|
|
|
+ PNIC_RECV_RINGS) % PNIC_RECV_RINGS;
|
2004-01-13 22:21:21 +03:00
|
|
|
olength = BX_PNIC_THIS s.recvRingLength[idx];
|
2008-02-16 01:05:43 +03:00
|
|
|
memcpy (data, BX_PNIC_THIS s.recvRing[idx], olength);
|
|
|
|
BX_PNIC_THIS s.recvQueueLength--;
|
2004-01-13 22:21:21 +03:00
|
|
|
}
|
2008-02-16 01:05:43 +03:00
|
|
|
if (! BX_PNIC_THIS s.recvQueueLength) {
|
2004-07-13 21:45:34 +04:00
|
|
|
set_irq_level(0);
|
2004-03-26 06:22:46 +03:00
|
|
|
}
|
|
|
|
status = PNIC_STATUS_OK;
|
|
|
|
break;
|
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_CMD_RECV_QLEN:
|
2004-03-26 06:22:46 +03:00
|
|
|
Bit16u qlen;
|
|
|
|
|
|
|
|
qlen = BX_PNIC_THIS s.recvQueueLength;
|
|
|
|
olength = sizeof(qlen);
|
2008-02-16 01:05:43 +03:00
|
|
|
memcpy (data, &qlen, sizeof(qlen));
|
2004-03-26 06:22:46 +03:00
|
|
|
status = PNIC_STATUS_OK;
|
|
|
|
break;
|
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_CMD_MASK_IRQ:
|
2004-03-26 06:22:46 +03:00
|
|
|
Bit8u enabled;
|
|
|
|
|
|
|
|
enabled = *((Bit8u*)data);
|
|
|
|
BX_PNIC_THIS s.irqEnabled = enabled;
|
2008-02-16 01:05:43 +03:00
|
|
|
if (enabled && BX_PNIC_THIS s.recvQueueLength) {
|
2004-07-13 21:45:34 +04:00
|
|
|
set_irq_level(1);
|
2004-03-26 06:22:46 +03:00
|
|
|
} else {
|
2004-07-13 21:45:34 +04:00
|
|
|
set_irq_level(0);
|
2004-03-26 06:22:46 +03:00
|
|
|
}
|
|
|
|
status = PNIC_STATUS_OK;
|
|
|
|
break;
|
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
case PNIC_CMD_FORCE_IRQ:
|
2004-07-13 21:45:34 +04:00
|
|
|
set_irq_level(1);
|
2004-01-13 22:21:21 +03:00
|
|
|
status = PNIC_STATUS_OK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_ERROR(("Unknown PNIC command %x (data length %u)", command, ilength));
|
2004-01-13 22:21:21 +03:00
|
|
|
status = PNIC_STATUS_UNKNOWN_CMD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set registers
|
|
|
|
BX_PNIC_THIS s.rStatus = status;
|
|
|
|
BX_PNIC_THIS s.rLength = olength;
|
|
|
|
BX_PNIC_THIS s.rDataCursor = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback from the eth system driver when a frame has arrived
|
|
|
|
*/
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_pcipnic_c::rx_handler(void *arg, const void *buf, unsigned len)
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
|
|
|
// BX_DEBUG(("rx_handler with length %d", len));
|
|
|
|
bx_pcipnic_c *class_ptr = (bx_pcipnic_c *) arg;
|
|
|
|
class_ptr->rx_frame(buf, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rx_frame() - called by the platform-specific code when an
|
|
|
|
* ethernet frame has been received. The destination address
|
|
|
|
* is tested to see if it should be accepted, and if the
|
|
|
|
* rx ring has enough room, it is copied into it and
|
|
|
|
* the receive process is updated
|
|
|
|
*/
|
2006-03-08 00:11:20 +03:00
|
|
|
void bx_pcipnic_c::rx_frame(const void *buf, unsigned io_len)
|
2004-01-13 22:21:21 +03:00
|
|
|
{
|
|
|
|
// Check packet length
|
2008-02-16 01:05:43 +03:00
|
|
|
if (io_len > PNIC_DATA_SIZE) {
|
|
|
|
BX_PANIC(("PNIC receive: data size %u exceeded buffer size %u",
|
|
|
|
io_len, PNIC_DATA_SIZE));
|
2004-01-13 22:21:21 +03:00
|
|
|
// Truncate if user continues
|
|
|
|
io_len = PNIC_DATA_SIZE;
|
|
|
|
}
|
|
|
|
// Check receive ring is not full
|
2008-02-16 01:05:43 +03:00
|
|
|
if (BX_PNIC_THIS s.recvQueueLength == PNIC_RECV_RINGS) {
|
|
|
|
BX_ERROR(("PNIC receive: receive ring full, discarding packet"));
|
2004-01-13 22:21:21 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Copy data to receive ring and record length
|
2008-02-16 01:05:43 +03:00
|
|
|
memcpy (BX_PNIC_THIS s.recvRing[BX_PNIC_THIS s.recvIndex], buf, io_len);
|
|
|
|
BX_PNIC_THIS s.recvRingLength[BX_PNIC_THIS s.recvIndex] = io_len;
|
2004-01-13 22:21:21 +03:00
|
|
|
// Move to next ring entry
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_PNIC_THIS s.recvIndex = (BX_PNIC_THIS s.recvIndex + 1) % PNIC_RECV_RINGS;
|
|
|
|
BX_PNIC_THIS s.recvQueueLength++;
|
2004-03-26 06:22:46 +03:00
|
|
|
|
|
|
|
// Generate interrupt if enabled
|
2008-02-16 01:05:43 +03:00
|
|
|
if (BX_PNIC_THIS s.irqEnabled) {
|
2004-07-13 21:45:34 +04:00
|
|
|
set_irq_level(1);
|
2004-03-26 06:22:46 +03:00
|
|
|
}
|
2004-01-13 22:21:21 +03:00
|
|
|
}
|
|
|
|
|
2004-08-06 19:49:55 +04:00
|
|
|
#endif // BX_SUPPORT_PCI && BX_SUPPORT_PCIPNIC
|