Move packet stream to Genode namespace, fix #1455

This commit is contained in:
Norman Feske 2015-03-16 17:33:26 +01:00 committed by Christian Helmuth
parent 001b069509
commit 560a58e5c6
17 changed files with 125 additions and 80 deletions

View File

@ -19,7 +19,12 @@
#include <nic_session/connection.h>
namespace Net {
class Packet_handler;
using Nic::Packet_stream_sink;
using Nic::Packet_stream_source;
using Nic::Packet_descriptor;
}

View File

@ -133,8 +133,8 @@ void net_mac(void* mac, unsigned long size)
int net_tx(void* addr, unsigned long len)
{
try {
Packet_descriptor packet = Net::Nic::n()->tx()->alloc_packet(len);
void* content = Net::Nic::n()->tx()->packet_content(packet);
Net::Packet_descriptor packet = Net::Nic::n()->tx()->alloc_packet(len);
void* content = Net::Nic::n()->tx()->packet_content(packet);
Genode::memcpy((char *)content, addr, len);
Net::Nic::n()->tx()->submit_packet(packet);

View File

@ -40,6 +40,8 @@ class Nic_receiver_thread : public Genode::Thread<8192>
{
private:
typedef Nic::Packet_descriptor Packet_descriptor;
Nic::Connection *_nic; /* nic-session */
Packet_descriptor _rx_packet; /* actual packet received */
struct netif *_netif; /* LwIP network interface structure */
@ -119,8 +121,8 @@ extern "C" {
#if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif
Packet_descriptor tx_packet = th->alloc_tx_packet(p->tot_len);
char *tx_content = th->content(tx_packet);
Nic::Packet_descriptor tx_packet = th->alloc_tx_packet(p->tot_len);
char *tx_content = th->content(tx_packet);
/*
* Iterate through all pbufs and
@ -154,11 +156,11 @@ extern "C" {
static struct pbuf *
low_level_input(struct netif *netif)
{
Nic_receiver_thread *th = reinterpret_cast<Nic_receiver_thread*>(netif->state);
Nic::Connection *nic = th->nic();
Packet_descriptor rx_packet = th->rx_packet();
char *rx_content = nic->rx()->packet_content(rx_packet);
u16_t len = rx_packet.size();
Nic_receiver_thread *th = reinterpret_cast<Nic_receiver_thread*>(netif->state);
Nic::Connection *nic = th->nic();
Nic::Packet_descriptor rx_packet = th->rx_packet();
char *rx_content = nic->rx()->packet_content(rx_packet);
u16_t len = rx_packet.size();
#if ETH_PAD_SIZE
len += ETH_PAD_SIZE; /* allow room for Ethernet padding */

View File

@ -46,7 +46,7 @@ namespace Block {
* the data read from or written to the block indicated by
* its number.
*/
class Block::Packet_descriptor : public ::Packet_descriptor
class Block::Packet_descriptor : public Genode::Packet_descriptor
{
public:
@ -65,18 +65,22 @@ class Block::Packet_descriptor : public ::Packet_descriptor
/**
* Constructor
*/
Packet_descriptor(Genode::off_t offset=0, Genode::size_t size=0)
: ::Packet_descriptor(offset, size),
_op(READ), _block_number(0), _block_count(0), _success(false) { }
Packet_descriptor(Genode::off_t offset=0, Genode::size_t size = 0)
:
Genode::Packet_descriptor(offset, size),
_op(READ), _block_number(0), _block_count(0), _success(false)
{ }
/**
* Constructor
*/
Packet_descriptor(Packet_descriptor p, Opcode op,
sector_t blk_nr, Genode::size_t blk_count = 1)
: ::Packet_descriptor(p.offset(), p.size()),
_op(op), _block_number(blk_nr),
_block_count(blk_count), _success(false) { }
:
Genode::Packet_descriptor(p.offset(), p.size()),
_op(op), _block_number(blk_nr),
_block_count(blk_count), _success(false)
{ }
Opcode operation() const { return _op; }
sector_t block_number() const { return _block_number; }
@ -113,9 +117,9 @@ struct Block::Session : public Genode::Session
};
typedef Packet_stream_policy<Block::Packet_descriptor,
TX_QUEUE_SIZE, TX_QUEUE_SIZE,
char> Tx_policy;
typedef Genode::Packet_stream_policy<Block::Packet_descriptor,
TX_QUEUE_SIZE, TX_QUEUE_SIZE,
char> Tx_policy;
typedef Packet_stream_tx::Channel<Tx_policy> Tx;

View File

@ -106,7 +106,7 @@ struct File_system::Symlink_handle : Node_handle
};
class File_system::Packet_descriptor : public ::Packet_descriptor
class File_system::Packet_descriptor : public Genode::Packet_descriptor
{
public:
@ -129,7 +129,7 @@ class File_system::Packet_descriptor : public ::Packet_descriptor
*/
Packet_descriptor(off_t offset = 0, size_t size = 0)
:
::Packet_descriptor(offset, size), _handle(-1),
Genode::Packet_descriptor(offset, size), _handle(-1),
_op(READ), _position(0), _length(0), _success(false) { }
/**
@ -141,7 +141,7 @@ class File_system::Packet_descriptor : public ::Packet_descriptor
Node_handle handle, Opcode op, size_t length,
seek_off_t position = ~0)
:
::Packet_descriptor(p.offset(), p.size()),
Genode::Packet_descriptor(p.offset(), p.size()),
_handle(handle), _op(op),
_position(position), _length(length), _success(false),
_ref(ref)

View File

@ -47,7 +47,7 @@ class Nic::Session_component : public Genode::Allocator_avl,
Driver &_driver;
/* rx packet descriptor */
Packet_descriptor _curr_rx_packet;
Genode::Packet_descriptor _curr_rx_packet;
enum { TX_STACK_SIZE = 8*1024 };
class Tx_thread : public Genode::Thread<TX_STACK_SIZE>
@ -155,7 +155,7 @@ class Nic::Session_component : public Genode::Allocator_avl,
{
/* check for acknowledgements from the client */
while (_rx.source()->ack_avail()) {
Packet_descriptor packet = _rx.source()->get_acked_packet();
Genode::Packet_descriptor packet = _rx.source()->get_acked_packet();
/* free packet buffer */
_rx.source()->release_packet(packet);

View File

@ -37,6 +37,11 @@ namespace Nic {
struct Mac_address;
struct Session;
using Genode::Packet_stream_sink;
using Genode::Packet_stream_source;
typedef Genode::Packet_descriptor Packet_descriptor;
}
@ -53,8 +58,8 @@ struct Nic::Session : Genode::Session
* The acknowledgement queue has always the same size as the submit
* queue. We access the packet content as a char pointer.
*/
typedef Packet_stream_policy<Packet_descriptor, QUEUE_SIZE, QUEUE_SIZE,
char> Policy;
typedef Genode::Packet_stream_policy<Genode::Packet_descriptor,
QUEUE_SIZE, QUEUE_SIZE, char> Policy;
typedef Packet_stream_tx::Channel<Policy> Tx;
typedef Packet_stream_rx::Channel<Policy> Rx;

View File

@ -81,6 +81,32 @@
#include <dataspace/client.h>
#include <util/string.h>
namespace Genode {
class Packet_descriptor;
template <typename, int> class Packet_descriptor_queue;
template <typename> class Packet_descriptor_transmitter;
template <typename> class Packet_descriptor_receiver;
class Packet_stream_base;
template <typename, unsigned, unsigned, typename>
struct Packet_stream_policy;
/**
* Default configuration for packet-descriptor queues
*/
typedef Packet_stream_policy<Packet_descriptor, 64, 64, char>
Default_packet_stream_policy;
template <typename POLICY = Default_packet_stream_policy>
class Packet_stream_source;
template <typename POLICY = Default_packet_stream_policy>
class Packet_stream_sink;
}
/**
* Default packet descriptor
@ -88,7 +114,7 @@
* A class used as 'PACKET_DESCRIPTOR' arguments to the 'Packet_stream_policy'
* template must implement the interface of this class.
*/
class Packet_descriptor
class Genode::Packet_descriptor
{
private:
@ -127,7 +153,7 @@ class Packet_descriptor
* This class is private to the packet-stream interface.
*/
template <typename PACKET_DESCRIPTOR, int QUEUE_SIZE>
class Packet_descriptor_queue
class Genode::Packet_descriptor_queue
{
private:
@ -221,7 +247,7 @@ class Packet_descriptor_queue
* This class is private to the packet-stream interface.
*/
template <typename TX_QUEUE>
class Packet_descriptor_transmitter
class Genode::Packet_descriptor_transmitter
{
private:
@ -310,7 +336,7 @@ class Packet_descriptor_transmitter
* This class is private to the packet-stream interface.
*/
template <typename RX_QUEUE>
class Packet_descriptor_receiver
class Genode::Packet_descriptor_receiver
{
private:
@ -386,7 +412,7 @@ class Packet_descriptor_receiver
*
* This class is private to the packet-stream interface.
*/
class Packet_stream_base
class Genode::Packet_stream_base
{
public:
@ -475,7 +501,7 @@ template <typename PACKET_DESCRIPTOR,
unsigned SUBMIT_QUEUE_SIZE,
unsigned ACK_QUEUE_SIZE,
typename CONTENT_TYPE>
struct Packet_stream_policy
struct Genode::Packet_stream_policy
{
typedef CONTENT_TYPE Content_type;
@ -489,13 +515,6 @@ struct Packet_stream_policy
};
/**
* Default configuration for packet-descriptor queues
*/
typedef Packet_stream_policy<Packet_descriptor, 64, 64, char>
Default_packet_stream_policy;
/**
* Placement new operator for constructing packet-descriptor queues
*
@ -504,14 +523,15 @@ typedef Packet_stream_policy<Packet_descriptor, 64, 64, char>
*
* This operator should not be used outside the packet-stream interface.
*/
inline void *operator new(Genode::size_t size, void *addr, Packet_stream_base *) { return addr; }
inline void *operator new(Genode::size_t size, void *addr,
Genode::Packet_stream_base *) { return addr; }
/**
* Originator of a packet stream
*/
template <typename POLICY = Default_packet_stream_policy>
class Packet_stream_source : private Packet_stream_base
template <typename POLICY>
class Genode::Packet_stream_source : private Packet_stream_base
{
public:
@ -694,8 +714,8 @@ class Packet_stream_source : private Packet_stream_base
/**
* Receiver of a packet stream
*/
template <typename POLICY = Default_packet_stream_policy>
class Packet_stream_sink : private Packet_stream_base
template <typename POLICY>
class Genode::Packet_stream_sink : private Packet_stream_base
{
public:

View File

@ -23,8 +23,8 @@ namespace Packet_stream_rx { template <typename> struct Channel; }
template <typename PACKET_STREAM_POLICY>
struct Packet_stream_rx::Channel
{
typedef ::Packet_stream_source<PACKET_STREAM_POLICY> Source;
typedef ::Packet_stream_sink<PACKET_STREAM_POLICY> Sink;
typedef Genode::Packet_stream_source<PACKET_STREAM_POLICY> Source;
typedef Genode::Packet_stream_sink<PACKET_STREAM_POLICY> Sink;
/**
* Request reception interface

View File

@ -23,8 +23,8 @@ namespace Packet_stream_tx { template <typename> struct Channel; }
template <typename PACKET_STREAM_POLICY>
struct Packet_stream_tx::Channel
{
typedef Packet_stream_source<PACKET_STREAM_POLICY> Source;
typedef Packet_stream_sink<PACKET_STREAM_POLICY> Sink;
typedef Genode::Packet_stream_source<PACKET_STREAM_POLICY> Source;
typedef Genode::Packet_stream_sink<PACKET_STREAM_POLICY> Sink;
/**
* Request transmission interface

View File

@ -20,16 +20,18 @@
namespace Usb {
using namespace Genode;
class Session;
struct Packet_descriptor;
struct Completion;
}
/**
* USB packet type
*/
struct Usb::Packet_descriptor : ::Packet_descriptor
struct Usb::Packet_descriptor : Genode::Packet_descriptor
{
enum Type { STRING, CTRL, BULK, IRQ, ALT_SETTING, CONFIG, RELEASE_IF };
@ -41,17 +43,17 @@ struct Usb::Packet_descriptor : ::Packet_descriptor
{
struct
{
uint8_t index;
unsigned length;
uint8_t index;
unsigned length;
} string;
struct
{
uint8_t request;
uint8_t request_type;
uint16_t value;
uint16_t index;
int timeout;
uint8_t request;
uint8_t request_type;
uint16_t value;
uint16_t index;
int timeout;
} control;
struct
@ -63,8 +65,8 @@ struct Usb::Packet_descriptor : ::Packet_descriptor
struct
{
uint8_t number;
uint8_t alt_setting;
uint8_t number;
uint8_t alt_setting;
} interface;
struct
@ -76,12 +78,13 @@ struct Usb::Packet_descriptor : ::Packet_descriptor
bool is_read_transfer() { return transfer.ep & ENDPOINT_IN; }
Packet_descriptor(off_t offset = 0, size_t size = 0)
: ::Packet_descriptor(offset, size) { }
: Genode::Packet_descriptor(offset, size) { }
Packet_descriptor(::Packet_descriptor p, Type type, Completion *completion = nullptr)
: ::Packet_descriptor(p.offset(), p.size()), type(type), completion(completion) { }
Packet_descriptor(Genode::Packet_descriptor p, Type type, Completion *completion = nullptr)
: Genode::Packet_descriptor(p.offset(), p.size()), type(type), completion(completion) { }
};
/**
* Completion for asynchronous communication
*/
@ -90,6 +93,7 @@ struct Usb::Completion
virtual void complete(Usb::Packet_descriptor &p) = 0;
};
struct Usb::Session : public Genode::Session
{
/****************

View File

@ -22,7 +22,12 @@
#include <net/ipv4.h>
namespace Net {
class Packet_handler;
using ::Nic::Packet_stream_sink;
using ::Nic::Packet_stream_source;
typedef ::Nic::Packet_descriptor Packet_descriptor;
}
/**

View File

@ -25,14 +25,14 @@
* Note that the ack queue size is smaller than the submit queue
* size.
*/
typedef Packet_stream_policy<Packet_descriptor, 8, 4, char>
typedef Genode::Packet_stream_policy<Genode::Packet_descriptor, 8, 4, char>
Test_packet_stream_policy;
enum { STACK_SIZE = 4096 };
void Packet_stream_base::_debug_print_buffers()
void Genode::Packet_stream_base::_debug_print_buffers()
{
Genode::printf("_ds_local_base = 0x%p\n", _ds_local_base);
Genode::printf("_submit_queue_offset = 0x%lx\n", _submit_queue_offset);
@ -47,7 +47,7 @@ void Packet_stream_base::_debug_print_buffers()
*/
class Source : private Genode::Thread<STACK_SIZE>,
private Genode::Allocator_avl,
public Packet_stream_source<Test_packet_stream_policy>
public Genode::Packet_stream_source<Test_packet_stream_policy>
{
private:
@ -169,7 +169,7 @@ class Source : private Genode::Thread<STACK_SIZE>,
class Sink : private Genode::Thread<STACK_SIZE>,
public Packet_stream_sink<Test_packet_stream_policy>
public Genode::Packet_stream_sink<Test_packet_stream_policy>
{
private:

View File

@ -180,8 +180,8 @@ extern "C" {
static Counter counter;
try {
Packet_descriptor packet = nic()->tx()->alloc_packet(len);
void* content = nic()->tx()->packet_content(packet);
Nic::Packet_descriptor packet = nic()->tx()->alloc_packet(len);
void* content = nic()->tx()->packet_content(packet);
Genode::memcpy((char *)content, addr, len);
nic()->tx()->submit_packet(packet);
@ -204,7 +204,7 @@ extern "C" {
{
Linux::Irq_guard guard;
Packet_descriptor packet = nic()->tx()->get_acked_packet();
Nic::Packet_descriptor packet = nic()->tx()->get_acked_packet();
nic()->tx()->release_packet(packet);
}
@ -216,7 +216,7 @@ extern "C" {
if (nic()) {
while(nic()->rx()->packet_avail()) {
Packet_descriptor p = nic()->rx()->get_packet();
Nic::Packet_descriptor p = nic()->rx()->get_packet();
if (receive_packet && net_device)
receive_packet(net_device, nic()->rx()->packet_content(p), p.size());

View File

@ -1163,7 +1163,7 @@ class Machine : public StaticReceiver<Machine>
}
/* allocate transmit packet */
Packet_descriptor tx_packet;
Nic::Packet_descriptor tx_packet;
try {
tx_packet = _nic->tx()->alloc_packet(msg.len);
} catch (Nic::Session::Tx::Source::Packet_alloc_failed) {
@ -1180,7 +1180,7 @@ class Machine : public StaticReceiver<Machine>
_nic->tx()->submit_packet(tx_packet);
/* wait for acknowledgement */
Packet_descriptor ack_tx_packet = _nic->tx()->get_acked_packet();
Nic::Packet_descriptor ack_tx_packet = _nic->tx()->get_acked_packet();
if (ack_tx_packet.size() != tx_packet.size()
|| ack_tx_packet.offset() != tx_packet.offset()) {

View File

@ -34,7 +34,7 @@ Vancouver_network::Vancouver_network(Synced_motherboard &mb, Nic::Session *nic)
void Vancouver_network::entry()
{
while (true) {
Packet_descriptor rx_packet = _nic->rx()->get_packet();
Nic::Packet_descriptor rx_packet = _nic->rx()->get_packet();
/* send it to the network bus */
char * rx_content = _nic->rx()->packet_content(rx_packet);

View File

@ -81,7 +81,7 @@ typedef struct DRVTAP
static int net_send_packet(void * packet, uint32_t packet_len, Nic::Session * nic) {
/* allocate transmit packet */
Packet_descriptor tx_packet;
Nic::Packet_descriptor tx_packet;
try {
tx_packet = nic->tx()->alloc_packet(packet_len);
} catch (Nic::Session::Tx::Source::Packet_alloc_failed) {
@ -96,7 +96,7 @@ static int net_send_packet(void * packet, uint32_t packet_len, Nic::Session * ni
nic->tx()->submit_packet(tx_packet);
/* wait for acknowledgement */
Packet_descriptor ack_tx_packet = nic->tx()->get_acked_packet();
Nic::Packet_descriptor ack_tx_packet = nic->tx()->get_acked_packet();
if (ack_tx_packet.size() != tx_packet.size() ||
ack_tx_packet.offset() != tx_packet.offset())
@ -292,17 +292,17 @@ static DECLCALLBACK(int) drvGetMac(PPDMINETWORKCONFIG pInterface, PRTMAC pMac)
*/
static DECLCALLBACK(int) drvTAPAsyncIoThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
{
PDRVTAP pThis = PDMINS_2_DATA(pDrvIns, PDRVTAP);
LogFlow(("drvTAPAsyncIoThread: pThis=%p\n", pThis));
PDRVTAP pThis = PDMINS_2_DATA(pDrvIns, PDRVTAP);
LogFlow(("drvTAPAsyncIoThread: pThis=%p\n", pThis));
if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
return VINF_SUCCESS;
if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
return VINF_SUCCESS;
Nic::Session * nic = pThis->nic_session;
while (pThread->enmState == PDMTHREADSTATE_RUNNING)
while (pThread->enmState == PDMTHREADSTATE_RUNNING)
{
Packet_descriptor rx_packet = nic->rx()->get_packet();
Nic::Packet_descriptor rx_packet = nic->rx()->get_packet();
/* send it to the network bus */
char * rx_content = nic->rx()->packet_content(rx_packet);