mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-30 02:28:54 +00:00
parent
0ba911bf12
commit
56831a247f
@ -77,7 +77,7 @@ append config {
|
||||
|
||||
<start name="usb_net_drv">
|
||||
<resource name="RAM" quantum="20M"/>
|
||||
<config mode="uplink_client" mac="02:00:00:00:01:01" />
|
||||
<config mac="02:00:00:00:01:01" />
|
||||
<route>
|
||||
<service name="Uplink"><child name="nic_router"/></service>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
|
@ -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() }
|
||||
{ }
|
@ -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_ */
|
@ -23,14 +23,10 @@
|
||||
|
||||
/* local includes */
|
||||
#include <uplink_client.h>
|
||||
#include <component.h>
|
||||
|
||||
/* Linux emulation environment includes */
|
||||
#include <legacy/lx_kit/scheduler.h>
|
||||
|
||||
/* NIC driver includes */
|
||||
#include <drivers/nic/mode.h>
|
||||
|
||||
struct usb_device_id;
|
||||
struct usb_interface;
|
||||
struct usb_device;
|
||||
@ -101,10 +97,8 @@ struct Driver
|
||||
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::Allocator_avl alloc { &heap };
|
||||
Genode::Constructible<Root> root { };
|
||||
Genode::Constructible<Genode::Uplink_client> uplink_client { };
|
||||
Genode::Constructible<Task> main_task;
|
||||
Genode::Constructible<Genode::Attached_rom_dataspace> report_rom;
|
||||
@ -113,20 +107,10 @@ struct Driver
|
||||
|
||||
void activate_network_session()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
static void main_task_entry(void *);
|
||||
|
@ -195,9 +195,6 @@ Driver::Driver(Genode::Env &env) : env(env)
|
||||
{
|
||||
Genode::log("--- USB net driver ---");
|
||||
|
||||
if (mode == Genode::Nic_driver_mode::NIC_SERVER) {
|
||||
root.construct(env, heap);
|
||||
}
|
||||
Lx_kit::construct_env(env);
|
||||
Lx::scheduler(&env);
|
||||
Lx::malloc_init(env, heap);
|
||||
|
@ -1,6 +1,6 @@
|
||||
TARGET := usb_net_drv
|
||||
SRC_C := dummies.c lxc.c
|
||||
SRC_CC := main.cc lx_emul.cc component.cc linux_network_session_base.cc
|
||||
SRC_CC := main.cc lx_emul.cc linux_network_session_base.cc
|
||||
SRC_CC += printf.cc bug.cc timer.cc scheduler.cc malloc.cc env.cc work.cc
|
||||
SRC_CC += uplink_client.cc
|
||||
|
||||
|
@ -305,7 +305,7 @@ append config { </wifi_config>
|
||||
<start name="nic_drv" caps="200">
|
||||
<binary name="usb_net_drv"/>
|
||||
<resource name="RAM" quantum="20M"/>
|
||||
<config mode="uplink_client" mac="02:00:00:00:01:01" />
|
||||
<config mac="02:00:00:00:01:01" />
|
||||
<route>
|
||||
<service name="Uplink"><child name="nic_router"/></service>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
|
Loading…
Reference in New Issue
Block a user