usb_modem_drv: remove nic_server mode

genodelabs/genode#4201
This commit is contained in:
Johannes Schlatow 2021-06-17 11:10:47 +02:00 committed by Christian Helmuth
parent dff1df0b49
commit 7346defc26
6 changed files with 7 additions and 264 deletions

View File

@ -23,11 +23,11 @@ Configuration snippet:
! <provides>
! <service name="Terminal"/>
! </provides>
! <config mac="02:00:00:00:01:01" mode="uplink_client"/>
! <config mac="02:00:00:00:01:01"/>
!</start>
The driver offers two Genode sessions: The first one is a terminal session where
raw packet data, for example, MBIM packets can be send to the device via CDC WDM
(wireless communication device class). An example can be found in Genode World
(_src/app/mbimcli_). Once a data connection is established via the Terminal
session, the NIC session can be used to transfer ethernet frames.
session, the Uplink session can be used to transfer Ethernet frames.

View File

@ -1,128 +0,0 @@
/*
* \brief Ethernet driver component
* \author Stefan Kalkowski
* \author Sebastian Sumpf
* \date 2017-11-01
*/
/*
* Copyright (C) 2020 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 },
Fec_nic { label },
_has_link { _read_link_state_from_ndev() }
{ }

View File

@ -1,110 +0,0 @@
/*
* \brief Freescale ethernet driver component
* \author Stefan Kalkowski
* \author Sebastian Sumpf
* \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 <fec_nic.h>
class Session_component : public Nic::Session_component,
public Fec_nic
{
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; }
/*************
** Fec_nic **
*************/
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

@ -24,7 +24,6 @@
/* local includes */
#include <uplink_client.h>
#include <component.h>
#include <terminal.h>
/* Linux emulation environment includes */
@ -34,9 +33,6 @@
#include <linux/usb.h>
#include <lx_emul/extern_c_end.h>
/* NIC driver includes */
#include <drivers/nic/mode.h>
struct usb_device_id;
struct usb_interface;
struct usb_device;
@ -156,10 +152,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 { };
Terminal::Root terminal_root { env, heap };
Genode::Constructible<Task> main_task;
@ -169,20 +163,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;
}
uplink_client.construct(
env, heap,
config_rom.xml().attribute_value(
"uplink_label", Genode::Session_label::String { "" }));
}
static void main_task_entry(void *);

View File

@ -226,9 +226,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);

View File

@ -1,6 +1,6 @@
TARGET := usb_modem_drv
SRC_C := dummies.c lxc.c
SRC_CC := main.cc lx_emul.cc component.cc terminal.cc fec_nic.cc
SRC_CC := main.cc lx_emul.cc terminal.cc fec_nic.cc
SRC_CC += printf.cc bug.cc timer.cc scheduler.cc malloc.cc env.cc work.cc
SRC_CC += uplink_client.cc