2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief NIC driver based on iPXE
|
|
|
|
* \author Christian Helmuth
|
2015-06-23 13:13:20 +02:00
|
|
|
* \author Sebastian Sumpf
|
2011-12-22 16:19:25 +01:00
|
|
|
* \date 2011-11-17
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-01-13 16:52:53 +01:00
|
|
|
* Copyright (C) 2011-2017 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
2017-02-20 13:23:52 +01:00
|
|
|
* This file is distributed under the terms of the GNU General Public License
|
|
|
|
* version 2.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode */
|
2017-01-13 16:52:53 +01:00
|
|
|
#include <base/component.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <base/env.h>
|
2017-01-13 16:52:53 +01:00
|
|
|
#include <base/heap.h>
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
#include <base/log.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <nic/component.h>
|
2015-06-23 13:13:20 +02:00
|
|
|
#include <nic/root.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-02-08 15:48:28 +01:00
|
|
|
#include <dde_ipxe/support.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <dde_ipxe/nic.h>
|
|
|
|
|
2017-01-13 16:52:53 +01:00
|
|
|
using namespace Genode;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
class Ipxe_session_component : public Nic::Session_component
|
|
|
|
{
|
|
|
|
public:
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
static Ipxe_session_component *instance;
|
2015-03-11 11:33:03 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
private:
|
2015-03-26 13:47:14 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
Nic::Mac_address _mac_addr;
|
2015-03-11 11:33:03 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
static void _rx_callback(unsigned if_index,
|
|
|
|
const char *packet,
|
|
|
|
unsigned packet_len)
|
|
|
|
{
|
|
|
|
if (instance)
|
|
|
|
instance->_receive(packet, packet_len);
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
static void _link_callback()
|
|
|
|
{
|
|
|
|
if (instance)
|
|
|
|
instance->_link_state_changed();
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
bool _send()
|
|
|
|
{
|
|
|
|
using namespace Genode;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
if (!_tx.sink()->ready_to_ack())
|
|
|
|
return false;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
if (!_tx.sink()->packet_avail())
|
|
|
|
return false;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
Packet_descriptor packet = _tx.sink()->get_packet();
|
2016-05-31 18:53:57 +02:00
|
|
|
if (!packet.size()) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::warning("Invalid tx packet");
|
2015-06-23 13:13:20 +02:00
|
|
|
return true;
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
2018-05-27 23:18:47 +02:00
|
|
|
if (link_state()) {
|
|
|
|
if (dde_ipxe_nic_tx(1, _tx.sink()->packet_content(packet), packet.size()))
|
|
|
|
Genode::warning("Sending packet failed!");
|
|
|
|
}
|
2015-03-11 11:33:03 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
_tx.sink()->acknowledge_packet(packet);
|
|
|
|
return true;
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
void _receive(const char *packet, unsigned packet_len)
|
|
|
|
{
|
|
|
|
_handle_packet_stream();
|
2015-03-11 11:33:03 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
if (!_rx.source()->ready_to_submit())
|
|
|
|
return;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
try {
|
|
|
|
Nic::Packet_descriptor p = _rx.source()->alloc_packet(packet_len);
|
|
|
|
Genode::memcpy(_rx.source()->packet_content(p), packet, packet_len);
|
|
|
|
_rx.source()->submit_packet(p);
|
|
|
|
} catch (...) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::warning(__func__, ": failed to process received packet");
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
2015-06-23 13:13:20 +02:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
void _handle_packet_stream() override
|
|
|
|
{
|
|
|
|
while (_rx.source()->ack_avail())
|
|
|
|
_rx.source()->release_packet(_rx.source()->get_acked_packet());
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
while (_send()) ;
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
public:
|
2015-03-26 13:47:14 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
Ipxe_session_component(Genode::size_t const tx_buf_size,
|
|
|
|
Genode::size_t const rx_buf_size,
|
|
|
|
Genode::Allocator &rx_block_md_alloc,
|
2017-02-13 20:51:27 +01:00
|
|
|
Genode::Env &env)
|
2019-04-15 14:59:22 +02:00
|
|
|
: Session_component(tx_buf_size, rx_buf_size, Genode::CACHED,
|
|
|
|
rx_block_md_alloc, env)
|
2015-06-23 13:13:20 +02:00
|
|
|
{
|
|
|
|
instance = this;
|
2015-03-26 13:47:14 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
dde_ipxe_nic_register_callbacks(_rx_callback, _link_callback);
|
2015-03-26 13:47:14 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
dde_ipxe_nic_get_mac_addr(1, _mac_addr.addr);
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
|
|
|
|
Genode::log("MAC address ", _mac_addr);
|
2015-06-23 13:13:20 +02:00
|
|
|
}
|
2015-03-26 13:47:14 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
~Ipxe_session_component()
|
|
|
|
{
|
|
|
|
instance = nullptr;
|
|
|
|
dde_ipxe_nic_unregister_callbacks();
|
|
|
|
}
|
2015-03-26 13:47:14 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
/**************************************
|
|
|
|
** Nic::Session_component interface **
|
|
|
|
**************************************/
|
2015-03-26 13:47:14 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
Nic::Mac_address mac_address() override { return _mac_addr; }
|
2015-03-26 13:47:14 +01:00
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
bool link_state() override
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2015-06-23 13:13:20 +02:00
|
|
|
return dde_ipxe_nic_link_state(1);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
2015-06-23 13:13:20 +02:00
|
|
|
};
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
2015-06-23 13:13:20 +02:00
|
|
|
Ipxe_session_component *Ipxe_session_component::instance;
|
|
|
|
|
|
|
|
|
|
|
|
struct Main
|
|
|
|
{
|
2017-01-13 16:52:53 +01:00
|
|
|
Env &_env;
|
2015-06-23 13:13:20 +02:00
|
|
|
|
2017-01-13 16:52:53 +01:00
|
|
|
Heap _heap { _env.ram(), _env.rm() };
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-01-13 16:52:53 +01:00
|
|
|
Nic::Root<Ipxe_session_component> root {_env, _heap };
|
|
|
|
|
|
|
|
Main(Env &env) : _env(env)
|
2015-03-26 13:47:14 +01:00
|
|
|
{
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::log("--- iPXE NIC driver started ---");
|
2015-06-18 15:16:17 +02:00
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::log("-- init iPXE NIC");
|
2017-02-08 15:48:28 +01:00
|
|
|
|
|
|
|
/* pass Env to backend */
|
|
|
|
dde_support_init(_env, _heap);
|
|
|
|
|
|
|
|
if (!dde_ipxe_nic_init()) {
|
|
|
|
Genode::error("could not find usable NIC device");
|
|
|
|
}
|
2015-06-18 15:16:17 +02:00
|
|
|
|
2017-01-13 16:52:53 +01:00
|
|
|
_env.parent().announce(_env.ep().manage(root));
|
2015-03-26 13:47:14 +01:00
|
|
|
}
|
|
|
|
};
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-03-15 15:40:55 +01:00
|
|
|
void Component::construct(Genode::Env &env)
|
|
|
|
{
|
|
|
|
/* XXX execute constructors of global statics */
|
|
|
|
env.exec_static_constructors();
|
|
|
|
|
|
|
|
static Main main(env);
|
|
|
|
}
|