lan9118 nic_drv: transition to new base API

* get rid of the Irq_handler and Irq_activation usage

Ref #1987
Ref #2072
This commit is contained in:
Stefan Kalkowski 2016-08-24 14:16:47 +02:00 committed by Christian Helmuth
parent 5aee80ee32
commit 855e2c4b17
3 changed files with 75 additions and 93 deletions

View File

@ -1,11 +1,12 @@
/* /*
* \brief LAN9118 NIC driver * \brief LAN9118 NIC driver
* \author Norman Feske * \author Norman Feske
* \author Stefan Kalkowski
* \date 2011-05-21 * \date 2011-05-21
*/ */
/* /*
* Copyright (C) 2011-2013 Genode Labs GmbH * Copyright (C) 2011-2016 Genode Labs GmbH
* *
* This file is part of the Genode OS framework, which is distributed * This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2. * under the terms of the GNU General Public License version 2.
@ -14,15 +15,14 @@
#ifndef _DRIVERS__NIC__SPEC__LAN9118__LAN9118_H_ #ifndef _DRIVERS__NIC__SPEC__LAN9118__LAN9118_H_
#define _DRIVERS__NIC__SPEC__LAN9118__LAN9118_H_ #define _DRIVERS__NIC__SPEC__LAN9118__LAN9118_H_
#include <base/attached_io_mem_dataspace.h>
#include <base/log.h> #include <base/log.h>
#include <util/misc_math.h> #include <util/misc_math.h>
#include <os/attached_io_mem_dataspace.h> #include <irq_session/connection.h>
#include <os/irq_activation.h>
#include <timer_session/connection.h> #include <timer_session/connection.h>
#include <nic/component.h> #include <nic/component.h>
class Lan9118 : public Nic::Session_component, class Lan9118 : public Nic::Session_component
public Genode::Irq_handler
{ {
private: private:
@ -72,9 +72,8 @@ class Lan9118 : public Nic::Session_component,
volatile Genode::uint32_t *_reg_base; volatile Genode::uint32_t *_reg_base;
Timer::Connection _timer; Timer::Connection _timer;
Nic::Mac_address _mac_addr; Nic::Mac_address _mac_addr;
Genode::Irq_connection _irq;
enum { IRQ_STACK_SIZE = 4096 }; Genode::Signal_handler<Lan9118> _irq_handler;
Genode::Irq_activation _irq_activation;
/** /**
* Information about a received packet, used internally * Information about a received packet, used internally
@ -249,6 +248,43 @@ class Lan9118 : public Nic::Session_component,
while (_send()) ; while (_send()) ;
} }
void _handle_irq()
{
using namespace Genode;
_handle_packet_stream();
while (_rx_packet_avail() && _rx.source()->ready_to_submit()) {
/* read packet from NIC, copy to client buffer */
Rx_packet_info packet = _rx_packet_info();
/* align size to 32-bit boundary */
size_t const size = align_addr(packet.size, 2);
/* allocate rx packet buffer */
Nic::Packet_descriptor p;
try {
p = _rx.source()->alloc_packet(size);
} catch (Session::Rx::Source::Packet_alloc_failed) { return; }
uint32_t *dst = (uint32_t *)_rx.source()->packet_content(p);
/* calculate number of words to be read from rx fifo */
size_t count = min(size, _rx_data_pending()) >> 2;
/* copy payload from rx fifo to client buffer */
for (; count--; )
*dst++ = _reg_read(RX_DATA_FIFO);
_rx.source()->submit_packet(p);
}
/* acknowledge all pending irqs */
_reg_write(INT_STS, ~0);
_irq.ack_irq();
}
public: public:
@ -266,13 +302,17 @@ class Lan9118 : public Nic::Session_component,
Genode::size_t const tx_buf_size, Genode::size_t const tx_buf_size,
Genode::size_t const rx_buf_size, Genode::size_t const rx_buf_size,
Genode::Allocator &rx_block_md_alloc, Genode::Allocator &rx_block_md_alloc,
Genode::Ram_session &ram_session, Genode::Env &env)
Server::Entrypoint &ep) : Session_component(tx_buf_size, rx_buf_size, rx_block_md_alloc,
: Session_component(tx_buf_size, rx_buf_size, rx_block_md_alloc, ram_session, ep), env.ram(), env.ep()),
_mmio(mmio_base, mmio_size), _mmio(env, mmio_base, mmio_size),
_reg_base(_mmio.local_addr<Genode::uint32_t>()), _reg_base(_mmio.local_addr<Genode::uint32_t>()),
_irq_activation(irq, *this, IRQ_STACK_SIZE) _irq(env, irq),
_irq_handler(env.ep(), *this, &Lan9118::_handle_irq)
{ {
_irq.sigh(_irq_handler);
_irq.ack_irq();
unsigned long const id_rev = _reg_read(ID_REV), unsigned long const id_rev = _reg_read(ID_REV),
byte_order = _reg_read(BYTE_TEST); byte_order = _reg_read(BYTE_TEST);
@ -367,47 +407,6 @@ class Lan9118 : public Nic::Session_component,
/* XXX always return true for now */ /* XXX always return true for now */
return true; return true;
} }
/******************************
** Irq_activation interface **
******************************/
void handle_irq(int)
{
using namespace Genode;
_handle_packet_stream();
while (_rx_packet_avail() && _rx.source()->ready_to_submit()) {
/* read packet from NIC, copy to client buffer */
Rx_packet_info packet = _rx_packet_info();
/* align size to 32-bit boundary */
size_t const size = align_addr(packet.size, 2);
/* allocate rx packet buffer */
Nic::Packet_descriptor p;
try {
p = _rx.source()->alloc_packet(size);
} catch (Session::Rx::Source::Packet_alloc_failed) { return; }
uint32_t *dst = (uint32_t *)_rx.source()->packet_content(p);
/* calculate number of words to be read from rx fifo */
size_t count = min(size, _rx_data_pending()) >> 2;
/* copy payload from rx fifo to client buffer */
for (; count--; )
*dst++ = _reg_read(RX_DATA_FIFO);
_rx.source()->submit_packet(p);
}
/* acknowledge all pending irqs */
_reg_write(INT_STS, ~0);
}
}; };
#endif /* _DRIVERS__NIC__SPEC__LAN9118__LAN9118_H_ */ #endif /* _DRIVERS__NIC__SPEC__LAN9118__LAN9118_H_ */

View File

@ -1,6 +1,7 @@
/* /*
* \brief LAN9118 NIC driver * \brief LAN9118 NIC driver
* \author Norman Feske * \author Norman Feske
* \author Stefan Kalkowski
* \date 2011-05-19 * \date 2011-05-19
* *
* Note, this driver is only tested on Qemu. At the current stage, it is not * Note, this driver is only tested on Qemu. At the current stage, it is not
@ -8,17 +9,17 @@
*/ */
/* /*
* Copyright (C) 2011-2013 Genode Labs GmbH * Copyright (C) 2011-2016 Genode Labs GmbH
* *
* This file is part of the Genode OS framework, which is distributed * This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2. * under the terms of the GNU General Public License version 2.
*/ */
/* Genode includes */ /* Genode includes */
#include <base/sleep.h> #include <base/component.h>
#include <cap_session/connection.h> #include <base/env.h>
#include <base/heap.h>
#include <nic/component.h> #include <nic/component.h>
#include <os/server.h>
#include <root/component.h> #include <root/component.h>
/* device definitions */ /* device definitions */
@ -27,13 +28,11 @@
/* driver code */ /* driver code */
#include <lan9118.h> #include <lan9118.h>
namespace Server { struct Main; }
class Root : public Genode::Root_component<Lan9118, Genode::Single_client> class Root : public Genode::Root_component<Lan9118, Genode::Single_client>
{ {
private: private:
Server::Entrypoint &_ep; Genode::Env &_env;
protected: protected:
@ -63,42 +62,26 @@ class Root : public Genode::Root_component<Lan9118, Genode::Single_client>
return new (Root::md_alloc()) return new (Root::md_alloc())
Lan9118(LAN9118_PHYS, LAN9118_SIZE, LAN9118_IRQ, Lan9118(LAN9118_PHYS, LAN9118_SIZE, LAN9118_IRQ,
tx_buf_size, rx_buf_size, tx_buf_size, rx_buf_size, *md_alloc(), _env);
*env()->heap(),
*env()->ram_session(),
_ep);
} }
public: public:
Root(Server::Entrypoint &ep, Genode::Allocator &md_alloc) Root(Genode::Env &env, Genode::Allocator &md_alloc)
: Genode::Root_component<Lan9118, Genode::Single_client>(&ep.rpc_ep(), &md_alloc), : Genode::Root_component<Lan9118,
_ep(ep) Genode::Single_client>(env.ep(), md_alloc),
{ } _env(env) { }
}; };
struct Server::Main
Genode::size_t Component::stack_size() { return 2*1024*sizeof(long); }
void Component::construct(Genode::Env &env)
{ {
Entrypoint &ep; static Genode::Heap heap(env.ram(), env.rm());
::Root nic_root{ ep, *Genode::env()->heap() }; static Root nic_root(env, heap);
Genode::log("--- LAN9118 NIC driver started ---");
Main(Entrypoint &ep) : ep(ep) env.parent().announce(env.ep().manage(nic_root));
{
log("--- LAN9118 NIC driver started ---");
Genode::env()->parent()->announce(ep.manage(nic_root));
}
};
namespace Server {
char const *name() { return "nic_ep"; }
size_t stack_size() { return 2*1024*sizeof(long); }
void construct(Entrypoint &ep)
{
static Main main(ep);
}
} }

View File

@ -1,5 +1,5 @@
REQUIRES = lan9118 REQUIRES = lan9118
TARGET = nic_drv TARGET = nic_drv
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base server LIBS = base
INC_DIR += $(PRG_DIR) INC_DIR += $(PRG_DIR)