fec_nic_drv: remove nic_server mode

Issue #4133
This commit is contained in:
Stefan Kalkowski 2021-05-31 12:58:16 +02:00 committed by Christian Helmuth
parent 73d87073af
commit 8408bf6ac0
9 changed files with 11 additions and 272 deletions

View File

@ -33,7 +33,6 @@
<start name="nic_drv" caps="130">
<binary name="fec_nic_drv"/>
<resource name="RAM" quantum="20M"/>
<config mode="uplink_client"/>
<route>
<service name="Uplink"><parent/> </service>
<service name="ROM"> <parent/> </service>

View File

@ -34,7 +34,6 @@
<start name="nic_drv" caps="130">
<binary name="fec_nic_drv"/>
<resource name="RAM" quantum="20M"/>
<config mode="uplink_client"/>
<route>
<service name="Uplink"><parent/> </service>
<service name="ROM"> <parent/> </service>

View File

@ -41,7 +41,7 @@
<start name="nic_drv" caps="150">
<binary name="fec_nic_drv"/>
<resource name="RAM" quantum="20M"/>
<config mode="uplink_client" uplink_label="fec0"/>
<config uplink_label="fec0"/>
<route>
<service name="Uplink"> <parent/> </service>
<service name="ROM"> <parent/> </service>

View File

@ -33,7 +33,6 @@
<start name="nic_drv" caps="130">
<binary name="fec_nic_drv"/>
<resource name="RAM" quantum="20M"/>
<config mode="uplink_client"/>
<route>
<service name="ROM"> <parent/> </service>
<service name="PD"> <parent/> </service>

View File

@ -1,127 +0,0 @@
/*
* \brief Freescale ethernet driver component
* \author Stefan Kalkowski
* \date 2017-11-01
*/
/*
* Copyright (C) 2017 Genode Labs GmbH
*
* This file is distributed under the terms of the GNU General Public License
* version 2.
*/
#include <component.h>
#include <lx_emul.h>
extern "C" {
#include <lxc.h>
};
bool Session_component::_send()
{
using namespace Genode;
/*
* We must not be called from another task, just from the
* packet stream dispatcher.
*/
if (Lx::scheduler().active()) {
warning("scheduler active");
return false;
}
if (!_tx.sink()->ready_to_ack()) { return false; }
if (!_tx.sink()->packet_avail()) { return false; }
Packet_descriptor packet = _tx.sink()->get_packet();
if (!packet.size() || !_tx.sink()->packet_valid(packet)) {
warning("invalid tx packet");
return true;
}
struct sk_buff *skb = lxc_alloc_skb(packet.size() + HEAD_ROOM, HEAD_ROOM);
unsigned char *data = lxc_skb_put(skb, packet.size());
Genode::memcpy(data, _tx.sink()->packet_content(packet), packet.size());
_tx_data.ndev = _ndev;
_tx_data.skb = skb;
_tx_task.unblock();
Lx::scheduler().schedule();
_tx.sink()->acknowledge_packet(packet);
return true;
}
void Session_component::_handle_rx()
{
while (_rx.source()->ack_avail())
_rx.source()->release_packet(_rx.source()->get_acked_packet());
}
void Session_component::_handle_packet_stream()
{
_handle_rx();
while (_send()) continue;
}
Nic::Mac_address Session_component::mac_address()
{
return _ndev ? Nic::Mac_address(_ndev->dev_addr) : Nic::Mac_address();
}
void Session_component::receive(struct sk_buff *skb)
{
_handle_rx();
if (!_rx.source()->ready_to_submit()) {
Genode::warning("not ready to receive packet");
return;
}
Skb s = skb_helper(skb);
try {
Nic::Packet_descriptor p = _rx.source()->alloc_packet(s.packet_size + s.frag_size);
void *buffer = _rx.source()->packet_content(p);
memcpy(buffer, s.packet, s.packet_size);
if (s.frag_size)
memcpy((char *)buffer + s.packet_size, s.frag, s.frag_size);
_rx.source()->submit_packet(p);
} catch (...) {
Genode::warning("failed to process received packet");
}
}
void Session_component::link_state(bool link)
{
if (link == _has_link) return;
_has_link = link;
_link_state_changed();
}
Session_component::Session_component(Genode::size_t const tx_buf_size,
Genode::size_t const rx_buf_size,
Genode::Allocator &rx_block_md_alloc,
Genode::Env &env,
Genode::Session_label const &label)
:
Nic::Session_component { tx_buf_size, rx_buf_size, Genode::CACHED,
rx_block_md_alloc, env },
Linux_network_session_base { label },
_has_link { _read_link_state_from_ndev() }
{ }

View File

@ -1,109 +0,0 @@
/*
* \brief Freescale ethernet driver component
* \author Stefan Kalkowski
* \date 2017-11-01
*/
/*
* Copyright (C) 2017 Genode Labs GmbH
*
* This file is distributed under the terms of the GNU General Public License
* version 2.
*/
#ifndef _SRC__DRIVERS__NIC__FEC__COMPONENT_H_
#define _SRC__DRIVERS__NIC__FEC__COMPONENT_H_
/* Genode includes */
#include <nic/component.h>
#include <root/component.h>
/* local includes */
#include <linux_network_session_base.h>
class Session_component : public Nic::Session_component,
public Linux_network_session_base
{
private:
bool _has_link = false;
bool _send();
void _handle_rx();
void _handle_packet_stream() override;
public:
Session_component(Genode::size_t const tx_buf_size,
Genode::size_t const rx_buf_size,
Genode::Allocator &rx_block_md_alloc,
Genode::Env &env,
Genode::Session_label const &label);
/****************************
** Nic::Session_component **
****************************/
Nic::Mac_address mac_address() override;
bool link_state() override { return _has_link; }
/********************************
** Linux_network_session_base **
********************************/
void link_state(bool link) override;
void receive(struct sk_buff *skb) override;
};
class Root : public Genode::Root_component<Session_component>
{
private:
Genode::Env &_env;
Genode::Allocator &_md_alloc;
protected:
Session_component *_create_session(const char *args)
{
using namespace Genode;
Session_label const label = label_from_args(args);
size_t ram_quota = Arg_string::find_arg(args, "ram_quota" ).ulong_value(0);
size_t tx_buf_size = Arg_string::find_arg(args, "tx_buf_size").ulong_value(0);
size_t rx_buf_size = Arg_string::find_arg(args, "rx_buf_size").ulong_value(0);
/* deplete ram quota by the memory needed for the session structure */
size_t session_size = max(4096UL, (unsigned long)sizeof(Session_component));
/*
* Check if donated ram quota suffices for both communication
* buffers and check for overflow
*/
if ((ram_quota < session_size) ||
(tx_buf_size + rx_buf_size < tx_buf_size ||
tx_buf_size + rx_buf_size > ram_quota - session_size)) {
Genode::error("insufficient 'ram_quota', got ", ram_quota, ", "
"need ", tx_buf_size + rx_buf_size + session_size);
throw Genode::Insufficient_ram_quota();
}
return new (Root::md_alloc())
Session_component(tx_buf_size, rx_buf_size,
_md_alloc, _env, label);
}
public:
Root(Genode::Env &env, Genode::Allocator &md_alloc)
: Genode::Root_component<Session_component>(&env.ep().rpc_ep(), &md_alloc),
_env(env), _md_alloc(md_alloc)
{ }
};
#endif /* _SRC__DRIVERS__NIC__FEC__COMPONENT_H_ */

View File

@ -23,7 +23,7 @@
#include <irq_session/client.h>
#include <platform_session/device.h>
#include <component.h>
#include <uplink_client.h>
#include <lx_emul.h>
#if DEBUG

View File

@ -17,12 +17,8 @@
#include <base/component.h>
#include <base/heap.h>
/* NIC driver includes */
#include <drivers/nic/mode.h>
/* local includes */
#include <uplink_client.h>
#include <component.h>
/* Linux emulation environment includes */
#include <lx_emul.h>
@ -48,13 +44,11 @@ unsigned long jiffies;
struct Main
{
Genode::Env &env;
Genode::Entrypoint &ep { env.ep() };
Genode::Attached_rom_dataspace config_rom { env, "config" };
Genode::Nic_driver_mode const mode { read_nic_driver_mode(config_rom.xml()) };
Genode::Heap heap { env.ram(), env.rm() };
Genode::Constructible<Root> root { };
Genode::Constructible<Genode::Uplink_client> uplink_client { };
Genode::Env & env;
Genode::Entrypoint & ep { env.ep() };
Genode::Attached_rom_dataspace config_rom { env, "config" };
Genode::Heap heap { env.ram(), env.rm() };
Genode::Constructible<Genode::Uplink_client> uplink_client { };
/* Linux task that handles the initialization */
Genode::Constructible<Lx::Task> linux;
@ -63,11 +57,6 @@ struct Main
{
Genode::log("--- freescale ethernet driver ---");
if (mode == Genode::Nic_driver_mode::NIC_SERVER) {
root.construct(env, heap);
}
Lx_kit::construct_env(env);
LX_MUTEX_INIT(mdio_board_lock);
@ -96,20 +85,9 @@ struct Main
void announce()
{
switch (mode) {
case Genode::Nic_driver_mode::NIC_SERVER:
env.parent().announce(ep.manage(*root));
break;
case Genode::Nic_driver_mode::UPLINK_CLIENT:
uplink_client.construct(
env, heap,
config_rom.xml().attribute_value(
"uplink_label", Genode::Session_label::String { "" }));
break;
}
uplink_client.construct( env, heap,
config_rom.xml().attribute_value(
"uplink_label", Genode::Session_label::String { "" }));
}
Lx::Task &linux_task() { return *linux; }

View File

@ -1,6 +1,6 @@
TARGET = fec_nic_drv
LIBS = base lx_kit_setjmp fec_nic_include nic_driver
SRC_CC += main.cc platform.cc lx_emul.cc component.cc uplink_client.cc
SRC_CC += main.cc platform.cc lx_emul.cc uplink_client.cc
SRC_CC += linux_network_session_base.cc
SRC_C += dummy.c lxc.c
INC_DIR += $(PRG_DIR)/../..