iPXE
Data Structures | Functions | Variables
mnpnet.c File Reference

MNP NIC driver. More...

#include <string.h>
#include <errno.h>
#include <ipxe/iobuf.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/cachedhcp.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_service.h>
#include <ipxe/efi/efi_utils.h>
#include <ipxe/efi/mnpnet.h>
#include <ipxe/efi/Protocol/ManagedNetwork.h>

Go to the source code of this file.

Data Structures

struct  mnp_token
 An MNP transmit or receive token. More...
 
struct  mnp_nic
 An MNP NIC. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static VOID EFIAPI mnpnet_event (EFI_EVENT event __unused, VOID *context)
 Transmit or receive token event. More...
 
static int mnpnet_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void mnpnet_refill_rx (struct net_device *netdev)
 Refill receive token. More...
 
static void mnpnet_poll_tx (struct net_device *netdev)
 Poll for completed packets. More...
 
static void mnpnet_poll_rx (struct net_device *netdev)
 Poll for received packets. More...
 
static void mnpnet_poll (struct net_device *netdev)
 Poll for completed packets. More...
 
static int mnpnet_open (struct net_device *netdev)
 Open network device. More...
 
static void mnpnet_close (struct net_device *netdev)
 Close network device. More...
 
int mnpnet_start (struct efi_device *efidev)
 Attach driver to device. More...
 
void mnpnet_stop (struct efi_device *efidev)
 Detach driver from device. More...
 
int mnptemp_create (EFI_HANDLE handle, struct net_device **netdev)
 Create temporary MNP network device. More...
 
void mnptemp_destroy (struct net_device *netdev)
 Destroy temporary MNP network device. More...
 

Variables

static struct net_device_operations mnpnet_operations
 MNP network device operations. More...
 

Detailed Description

MNP NIC driver.

Definition in file mnpnet.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ mnpnet_event()

static VOID EFIAPI mnpnet_event ( EFI_EVENT event  __unused,
VOID context 
)
static

Transmit or receive token event.

Parameters
eventEvent
contextEvent context

Definition at line 79 of file mnpnet.c.

79  {
80  struct mnp_token *token = context;
81 
82  /* Sanity check */
83  assert ( token->busy );
84 
85  /* Mark token as no longer owned by MNP */
86  token->busy = 0;
87 }
An MNP transmit or receive token.
Definition: mnpnet.c:46
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
u8 token
Definition: CIB_PRM.h:42

References assert(), and token.

Referenced by mnpnet_open().

◆ mnpnet_transmit()

static int mnpnet_transmit ( struct net_device netdev,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
netdevNetwork device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 96 of file mnpnet.c.

97  {
98  struct mnp_nic *mnp = netdev->priv;
100  EFI_STATUS efirc;
101  int rc;
102 
103  /* Do nothing if shutdown is in progress */
105  return -ECANCELED;
106 
107  /* Defer the packet if there is already a transmission in progress */
108  if ( mnp->txbuf ) {
109  netdev_tx_defer ( netdev, iobuf );
110  return 0;
111  }
112 
113  /* Construct transmit token */
114  mnp->txdata.DataLength =
115  ( iob_len ( iobuf ) - ll_protocol->ll_header_len );
117  mnp->txdata.FragmentCount = 1;
118  mnp->txdata.FragmentTable[0].FragmentLength = iob_len ( iobuf );
119  mnp->txdata.FragmentTable[0].FragmentBuffer = iobuf->data;
120  mnp->tx.token.Packet.TxData = &mnp->txdata;
121 
122  /* Record as in use */
123  mnp->tx.busy = 1;
124 
125  /* Transmit packet */
126  if ( ( efirc = mnp->mnp->Transmit ( mnp->mnp, &mnp->tx.token ) ) != 0 ){
127  rc = -EEFI ( efirc );
128  DBGC ( mnp, "MNP %s could not transmit: %s\n",
129  netdev->name, strerror ( rc ) );
130  mnp->tx.busy = 0;
131  return rc;
132  }
133 
134  /* Record I/O buffer */
135  mnp->txbuf = iobuf;
136 
137  return 0;
138 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
void netdev_tx_defer(struct net_device *netdev, struct io_buffer *iobuf)
Defer transmitted packet.
Definition: netdevice.c:412
EFI_MANAGED_NETWORK_TRANSMIT Transmit
uint8_t ll_header_len
Link-layer header length.
Definition: netdevice.h:200
struct mnp_token tx
Transmit token.
Definition: mnpnet.c:63
#define DBGC(...)
Definition: compiler.h:505
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:58
A link-layer protocol.
Definition: netdevice.h:114
An MNP NIC.
Definition: mnpnet.c:54
#define ECANCELED
Operation canceled.
Definition: errno.h:343
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
union EFI_MANAGED_NETWORK_COMPLETION_TOKEN::@523 Packet
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
EFI_MANAGED_NETWORK_FRAGMENT_DATA FragmentTable[1]
void * data
Start of data.
Definition: iobuf.h:48
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
int busy
Token is owned by MNP.
Definition: mnpnet.c:50
struct io_buffer * txbuf
Transmit I/O buffer.
Definition: mnpnet.c:67
EFI_MANAGED_NETWORK_COMPLETION_TOKEN token
MNP completion token.
Definition: mnpnet.c:48
EFI_MANAGED_NETWORK_TRANSMIT_DATA txdata
Transmit descriptor.
Definition: mnpnet.c:65
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
EFI_MANAGED_NETWORK_TRANSMIT_DATA * TxData
When this token is used for transmitting, TxData is a pointer to the EFI_MANAGED_NETWORK_TRANSMIT_DAT...
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:58

References mnp_token::busy, io_buffer::data, EFI_MANAGED_NETWORK_TRANSMIT_DATA::DataLength, DBGC, ECANCELED, EEFI, efi_shutdown_in_progress, EFI_MANAGED_NETWORK_FRAGMENT_DATA::FragmentBuffer, EFI_MANAGED_NETWORK_TRANSMIT_DATA::FragmentCount, EFI_MANAGED_NETWORK_FRAGMENT_DATA::FragmentLength, EFI_MANAGED_NETWORK_TRANSMIT_DATA::FragmentTable, EFI_MANAGED_NETWORK_TRANSMIT_DATA::HeaderLength, iob_len(), ll_protocol::ll_header_len, net_device::ll_protocol, mnp_nic::mnp, net_device::name, netdev, netdev_tx_defer(), EFI_MANAGED_NETWORK_COMPLETION_TOKEN::Packet, net_device::priv, rc, strerror(), mnp_token::token, _EFI_MANAGED_NETWORK_PROTOCOL::Transmit, mnp_nic::tx, mnp_nic::txbuf, mnp_nic::txdata, and EFI_MANAGED_NETWORK_COMPLETION_TOKEN::TxData.

◆ mnpnet_refill_rx()

static void mnpnet_refill_rx ( struct net_device netdev)
static

Refill receive token.

Parameters
netdevNetwork device

Definition at line 145 of file mnpnet.c.

145  {
146  struct mnp_nic *mnp = netdev->priv;
147  EFI_STATUS efirc;
148  int rc;
149 
150  /* Do nothing if receive token is still in use */
151  if ( mnp->rx.busy )
152  return;
153 
154  /* Mark as in use */
155  mnp->rx.busy = 1;
156 
157  /* Queue receive token */
158  if ( ( efirc = mnp->mnp->Receive ( mnp->mnp, &mnp->rx.token ) ) != 0 ) {
159  rc = -EEFI ( efirc );
160  DBGC ( mnp, "MNP %s could not receive: %s\n",
161  netdev->name, strerror ( rc ) );
162  /* Wait for next refill */
163  mnp->rx.busy = 0;
164  return;
165  }
166 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
#define DBGC(...)
Definition: compiler.h:505
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:58
An MNP NIC.
Definition: mnpnet.c:54
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
EFI_MANAGED_NETWORK_RECEIVE Receive
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31

References DBGC, EEFI, mnp_nic::mnp, net_device::name, netdev, net_device::priv, rc, _EFI_MANAGED_NETWORK_PROTOCOL::Receive, and strerror().

Referenced by mnpnet_open(), and mnpnet_poll().

◆ mnpnet_poll_tx()

static void mnpnet_poll_tx ( struct net_device netdev)
static

Poll for completed packets.

Parameters
netdevNetwork device

Definition at line 173 of file mnpnet.c.

173  {
174  struct mnp_nic *mnp = netdev->priv;
175  struct io_buffer *iobuf;
176  EFI_STATUS efirc;
177  int rc;
178 
179  /* Do nothing if transmit token is still in use */
180  if ( mnp->tx.busy )
181  return;
182 
183  /* Do nothing unless we have a completion */
184  if ( ! mnp->txbuf )
185  return;
186 
187  /* Get completion status */
188  efirc = mnp->tx.token.Status;
189  rc = ( efirc ? -EEFI ( efirc ) : 0 );
190 
191  /* Complete transmission */
192  iobuf = mnp->txbuf;
193  mnp->txbuf = NULL;
194  netdev_tx_complete_err ( netdev, iobuf, rc );
195 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
struct mnp_token tx
Transmit token.
Definition: mnpnet.c:63
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:58
An MNP NIC.
Definition: mnpnet.c:54
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:470
EFI_STATUS Status
The status that is returned to the caller at the end of the operation to indicate whether this operat...
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
int busy
Token is owned by MNP.
Definition: mnpnet.c:50
struct io_buffer * txbuf
Transmit I/O buffer.
Definition: mnpnet.c:67
EFI_MANAGED_NETWORK_COMPLETION_TOKEN token
MNP completion token.
Definition: mnpnet.c:48
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A persistent I/O buffer.
Definition: iobuf.h:33

References mnp_token::busy, EEFI, mnp_nic::mnp, netdev, netdev_tx_complete_err(), NULL, net_device::priv, rc, EFI_MANAGED_NETWORK_COMPLETION_TOKEN::Status, mnp_token::token, mnp_nic::tx, and mnp_nic::txbuf.

Referenced by mnpnet_poll().

◆ mnpnet_poll_rx()

static void mnpnet_poll_rx ( struct net_device netdev)
static

Poll for received packets.

Parameters
netdevNetwork device

Definition at line 202 of file mnpnet.c.

202  {
204  struct mnp_nic *mnp = netdev->priv;
206  struct io_buffer *iobuf;
207  size_t len;
208  EFI_STATUS efirc;
209  int rc;
210 
211  /* Do nothing unless we have a completion */
212  if ( mnp->rx.busy )
213  return;
214  rxdata = mnp->rx.token.Packet.RxData;
215 
216  /* Get completion status */
217  if ( ( efirc = mnp->rx.token.Status ) != 0 ) {
218  rc = -EEFI ( efirc );
219  netdev_rx_err ( netdev, NULL, rc );
220  goto recycle;
221  }
222 
223  /* Allocate and fill I/O buffer */
224  len = rxdata->PacketLength;
225  iobuf = alloc_iob ( len );
226  if ( ! iobuf ) {
228  goto recycle;
229  }
230  memcpy ( iob_put ( iobuf, len ), rxdata->MediaHeader, len );
231 
232  /* Hand off to network stack */
233  netdev_rx ( netdev, iobuf );
234 
235  recycle:
236  /* Recycle token */
237  bs->SignalEvent ( rxdata->RecycleEvent );
238 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:120
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:58
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
An MNP NIC.
Definition: mnpnet.c:54
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct mnp_token rx
Receive token.
Definition: mnpnet.c:70
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
union EFI_MANAGED_NETWORK_COMPLETION_TOKEN::@523 Packet
EFI_SIGNAL_EVENT SignalEvent
Definition: UefiSpec.h:1944
EFI Boot Services Table.
Definition: UefiSpec.h:1917
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:548
EFI_STATUS Status
The status that is returned to the caller at the end of the operation to indicate whether this operat...
uint32_t len
Length.
Definition: ena.h:14
EFI_MANAGED_NETWORK_RECEIVE_DATA * RxData
When this token is used for receiving, RxData is a pointer to the EFI_MANAGED_NETWORK_RECEIVE_DATA.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
int busy
Token is owned by MNP.
Definition: mnpnet.c:50
EFI_MANAGED_NETWORK_COMPLETION_TOKEN token
MNP completion token.
Definition: mnpnet.c:48
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A persistent I/O buffer.
Definition: iobuf.h:33

References alloc_iob(), EFI_SYSTEM_TABLE::BootServices, mnp_token::busy, EEFI, efi_systab, ENOMEM, iob_put, len, EFI_MANAGED_NETWORK_RECEIVE_DATA::MediaHeader, memcpy(), mnp_nic::mnp, netdev, netdev_rx(), netdev_rx_err(), NULL, EFI_MANAGED_NETWORK_COMPLETION_TOKEN::Packet, EFI_MANAGED_NETWORK_RECEIVE_DATA::PacketLength, net_device::priv, rc, EFI_MANAGED_NETWORK_RECEIVE_DATA::RecycleEvent, mnp_nic::rx, EFI_MANAGED_NETWORK_COMPLETION_TOKEN::RxData, EFI_BOOT_SERVICES::SignalEvent, EFI_MANAGED_NETWORK_COMPLETION_TOKEN::Status, and mnp_token::token.

Referenced by mnpnet_poll().

◆ mnpnet_poll()

static void mnpnet_poll ( struct net_device netdev)
static

Poll for completed packets.

Parameters
netdevNetwork device

Definition at line 245 of file mnpnet.c.

245  {
246  struct mnp_nic *mnp = netdev->priv;
247 
248  /* Do nothing if shutdown is in progress */
250  return;
251 
252  /* Poll interface */
253  mnp->mnp->Poll ( mnp->mnp );
254 
255  /* Process any transmit completions */
257 
258  /* Process any receive completions */
260 
261  /* Refill receive token */
263 }
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:58
EFI_MANAGED_NETWORK_POLL Poll
An MNP NIC.
Definition: mnpnet.c:54
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
static void mnpnet_refill_rx(struct net_device *netdev)
Refill receive token.
Definition: mnpnet.c:145
static void mnpnet_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition: mnpnet.c:173
static void mnpnet_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: mnpnet.c:202
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:58

References efi_shutdown_in_progress, mnp_nic::mnp, mnpnet_poll_rx(), mnpnet_poll_tx(), mnpnet_refill_rx(), netdev, _EFI_MANAGED_NETWORK_PROTOCOL::Poll, and net_device::priv.

◆ mnpnet_open()

static int mnpnet_open ( struct net_device netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 271 of file mnpnet.c.

271  {
273  static EFI_MANAGED_NETWORK_CONFIG_DATA config = {
275  .EnableMulticastReceive = TRUE,
276  .EnableBroadcastReceive = TRUE,
277  .EnablePromiscuousReceive = TRUE,
278  .FlushQueuesOnReset = TRUE,
279  .DisableBackgroundPolling = TRUE,
280  };
281  struct mnp_nic *mnp = netdev->priv;
282  EFI_STATUS efirc;
283  int rc;
284 
285  /* Create transmit event */
286  if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_SIGNAL, TPL_NOTIFY,
287  mnpnet_event, &mnp->tx,
288  &mnp->tx.token.Event ) ) != 0 ) {
289  rc = -EEFI ( efirc );
290  DBGC ( mnp, "MNP %s could not create TX event: %s\n",
291  netdev->name, strerror ( rc ) );
292  goto err_tx_event;
293  }
294 
295  /* Create receive event */
296  if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_SIGNAL, TPL_NOTIFY,
297  mnpnet_event, &mnp->rx,
298  &mnp->rx.token.Event ) ) != 0 ) {
299  rc = -EEFI ( efirc );
300  DBGC ( mnp, "MNP %s could not create RX event: %s\n",
301  netdev->name, strerror ( rc ) );
302  goto err_rx_event;
303  }
304 
305  /* Configure MNP */
306  if ( ( efirc = mnp->mnp->Configure ( mnp->mnp, &config ) ) != 0 ) {
307  rc = -EEFI ( efirc );
308  DBGC ( mnp, "MNP %s could not configure: %s\n",
309  netdev->name, strerror ( rc ) );
310  goto err_configure;
311  }
312 
313  /* Refill receive token */
315 
316  return 0;
317 
318  mnp->mnp->Configure ( mnp->mnp, NULL );
319  err_configure:
320  bs->CloseEvent ( mnp->rx.token.Event );
321  err_rx_event:
322  bs->CloseEvent ( mnp->tx.token.Event );
323  err_tx_event:
324  return rc;
325 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_EVENT CloseEvent
Definition: UefiSpec.h:1945
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:58
#define TPL_NOTIFY
Definition: UefiSpec.h:639
An MNP NIC.
Definition: mnpnet.c:54
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
EFI_CREATE_EVENT CreateEvent
Definition: UefiSpec.h:1941
static VOID EFIAPI mnpnet_event(EFI_EVENT event __unused, VOID *context)
Transmit or receive token event.
Definition: mnpnet.c:79
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void mnpnet_refill_rx(struct net_device *netdev)
Refill receive token.
Definition: mnpnet.c:145
EFI Boot Services Table.
Definition: UefiSpec.h:1917
#define EVT_NOTIFY_SIGNAL
Definition: UefiSpec.h:443
#define TRUE
Definition: tlan.h:46
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
EFI_MANAGED_NETWORK_CONFIGURE Configure
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
BOOLEAN EnableUnicastReceive
Set to TRUE to receive packets that are sent to the network device MAC address.

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseEvent, _EFI_MANAGED_NETWORK_PROTOCOL::Configure, EFI_BOOT_SERVICES::CreateEvent, DBGC, EEFI, efi_systab, EFI_MANAGED_NETWORK_CONFIG_DATA::EnableUnicastReceive, EVT_NOTIFY_SIGNAL, mnp_nic::mnp, mnpnet_event(), mnpnet_refill_rx(), net_device::name, netdev, NULL, net_device::priv, rc, strerror(), TPL_NOTIFY, and TRUE.

◆ mnpnet_close()

static void mnpnet_close ( struct net_device netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 332 of file mnpnet.c.

332  {
334  struct mnp_nic *mnp = netdev->priv;
335 
336  /* Reset MNP (unless whole system shutdown is in progress) */
337  if ( ! efi_shutdown_in_progress )
338  mnp->mnp->Configure ( mnp->mnp, NULL );
339 
340  /* Close events */
341  bs->CloseEvent ( mnp->rx.token.Event );
342  bs->CloseEvent ( mnp->tx.token.Event );
343 
344  /* Reset tokens */
345  mnp->tx.busy = 0;
346  mnp->rx.busy = 0;
347 
348  /* Discard any incomplete I/O buffer */
349  if ( mnp->txbuf ) {
351  mnp->txbuf = NULL;
352  }
353 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
EFI_CLOSE_EVENT CloseEvent
Definition: UefiSpec.h:1945
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:58
An MNP NIC.
Definition: mnpnet.c:54
#define ECANCELED
Operation canceled.
Definition: errno.h:343
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
EFI Boot Services Table.
Definition: UefiSpec.h:1917
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:470
EFI_MANAGED_NETWORK_CONFIGURE Configure
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:58

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseEvent, _EFI_MANAGED_NETWORK_PROTOCOL::Configure, ECANCELED, efi_shutdown_in_progress, efi_systab, mnp_nic::mnp, netdev, netdev_tx_complete_err(), NULL, and net_device::priv.

◆ mnpnet_start()

int mnpnet_start ( struct efi_device efidev)

Attach driver to device.

Parameters
efidevEFI device
Return values
rcReturn status code

Definition at line 369 of file mnpnet.c.

369  {
374  union {
376  void *interface;
377  } u;
378  struct net_device *netdev;
379  struct mnp_nic *mnp;
380  EFI_STATUS efirc;
381  int rc;
382 
383  /* Allocate and initalise structure */
384  netdev = alloc_etherdev ( sizeof ( *mnp ) );
385  if ( ! netdev ) {
386  rc = -ENOMEM;
387  goto err_alloc;
388  }
390  mnp = netdev->priv;
391  mnp->efidev = efidev;
393 
394  /* Populate underlying device information */
395  efi_device_info ( device, "MNP", &mnp->dev );
396  mnp->dev.driver_name = "MNP";
397  mnp->dev.parent = &efidev->dev;
398  list_add ( &mnp->dev.siblings, &efidev->dev.children );
399  INIT_LIST_HEAD ( &mnp->dev.children );
400  netdev->dev = &mnp->dev;
401 
402  /* Create MNP child */
403  if ( ( rc = efi_service_add ( device, binding,
404  &efidev->child ) ) != 0 ) {
405  DBGC ( mnp, "MNP %s could not create child: %s\n",
406  efi_handle_name ( device ), strerror ( rc ) );
407  goto err_service;
408  }
409 
410  /* Open MNP protocol */
411  if ( ( efirc = bs->OpenProtocol ( efidev->child,
413  &u.interface, efi_image_handle,
414  efidev->child,
417  rc = -EEFI ( efirc );
418  DBGC ( mnp, "MNP %s could not open MNP protocol: %s\n",
419  efi_handle_name ( device ), strerror ( rc ) );
420  goto err_open;
421  }
422  mnp->mnp = u.mnp;
423 
424  /* Get configuration */
425  efirc = mnp->mnp->GetModeData ( mnp->mnp, NULL, &mode );
426  if ( ( efirc != 0 ) && ( efirc != EFI_NOT_STARTED ) ) {
427  rc = -EEFI ( efirc );
428  DBGC ( mnp, "MNP %s could not get mode data: %s\n",
429  efi_handle_name ( device ), strerror ( rc ) );
430  goto err_mode;
431  }
432 
433  /* Populate network device parameters */
434  if ( mode.HwAddressSize != netdev->ll_protocol->hw_addr_len ) {
435  DBGC ( device, "MNP %s has invalid hardware address length "
436  "%d\n", efi_handle_name ( device ), mode.HwAddressSize );
437  rc = -ENOTSUP;
438  goto err_hw_addr_len;
439  }
442  if ( mode.HwAddressSize != netdev->ll_protocol->ll_addr_len ) {
443  DBGC ( device, "MNP %s has invalid link-layer address length "
444  "%d\n", efi_handle_name ( device ), mode.HwAddressSize );
445  rc = -ENOTSUP;
446  goto err_ll_addr_len;
447  }
450 
451  /* Register network device */
452  if ( ( rc = register_netdev ( netdev ) ) != 0 )
453  goto err_register;
454  DBGC ( mnp, "MNP %s registered as %s\n",
456 
457  /* Mark as link up: we don't handle link state */
459 
460  return 0;
461 
463  err_register:
464  err_ll_addr_len:
465  err_hw_addr_len:
466  err_mode:
469  err_open:
470  efi_service_del ( device, binding, efidev->child );
471  err_service:
472  list_del ( &mnp->dev.siblings );
474  netdev_put ( netdev );
475  err_alloc:
476  return rc;
477 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
The MNP is used by network applications (and drivers) to perform raw (unformatted) asynchronous netwo...
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
128 bit buffer containing a unique identifier value.
Definition: Base.h:215
int efi_service_del(EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE handle)
Remove service from child handle.
Definition: efi_service.c:96
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1347
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1348
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
EFI_GUID efi_managed_network_service_binding_protocol_guid
Managed network service binding protocol GUID.
Definition: efi_guid.c:255
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:58
EFI_MAC_ADDRESS CurrentAddress
The current HW MAC address for the network interface.
An MNP NIC.
Definition: mnpnet.c:54
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:515
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
EFI_HANDLE child
EFI child device handle (if present)
Definition: efi_driver.h:23
#define ENOMEM
Not enough space.
Definition: errno.h:534
A hardware device.
Definition: device.h:73
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
An object interface.
Definition: interface.h:124
uint8_t hw_addr_len
Hardware address length.
Definition: netdevice.h:196
void * priv
Driver private data.
Definition: netdevice.h:431
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:774
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
#define EFI_NOT_STARTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:133
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1917
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:759
A network device.
Definition: netdevice.h:352
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
int efi_service_add(EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE *handle)
Add service to child handle.
Definition: efi_service.c:46
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
static struct net_device_operations mnpnet_operations
MNP network device operations.
Definition: mnpnet.c:356
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
UINT32 HwAddressSize
The size, in bytes, of the network interface's HW address.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
struct list_head children
Devices attached to this device.
Definition: device.h:83
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
union @17 u
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1986
EFI_MANAGED_NETWORK_GET_MODE_DATA GetModeData
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:74
struct device dev
Generic device.
Definition: efi_driver.h:19
struct efi_device * efidev
EFI device.
Definition: mnpnet.c:56
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
Definition: efi.h:59
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
Definition: efi_utils.c:209
EFI_MAC_ADDRESS PermanentAddress
The permanent HW MAC address for the network interface.
EFI_GUID efi_managed_network_protocol_guid
Managed network protocol GUID.
Definition: efi_guid.c:251

References alloc_etherdev(), EFI_SYSTEM_TABLE::BootServices, efi_device::child, device::children, EFI_BOOT_SERVICES::CloseProtocol, EFI_SIMPLE_NETWORK_MODE::CurrentAddress, DBGC, efi_device::dev, net_device::dev, efi_device::device, EEFI, efi_device_info(), efi_handle_name(), efi_image_handle, efi_managed_network_protocol_guid, efi_managed_network_service_binding_protocol_guid, EFI_NOT_STARTED, EFI_OPEN_PROTOCOL_BY_DRIVER, EFI_OPEN_PROTOCOL_EXCLUSIVE, efi_service_add(), efi_service_del(), efi_systab, mnp_nic::efidev, efidev_set_drvdata(), ENOMEM, ENOTSUP, _EFI_MANAGED_NETWORK_PROTOCOL::GetModeData, net_device::hw_addr, ll_protocol::hw_addr_len, EFI_SIMPLE_NETWORK_MODE::HwAddressSize, INIT_LIST_HEAD, list_add, list_del, net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, memcpy(), mnp_nic::mnp, mnpnet_operations, net_device::name, netdev, netdev_init(), netdev_link_up(), netdev_nullify(), netdev_put(), NULL, EFI_BOOT_SERVICES::OpenProtocol, EFI_SIMPLE_NETWORK_MODE::PermanentAddress, net_device::priv, rc, register_netdev(), strerror(), u, and unregister_netdev().

Referenced by mnptemp_create().

◆ mnpnet_stop()

void mnpnet_stop ( struct efi_device efidev)

Detach driver from device.

Parameters
efidevEFI device

Definition at line 484 of file mnpnet.c.

484  {
487  struct net_device *netdev = efidev_get_drvdata ( efidev );
488  struct mnp_nic *mnp = netdev->priv;
489 
490  /* Unregister network device */
492 
493  /* Close MNP protocol */
496 
497  /* Remove MNP child (unless whole system shutdown is in progress) */
498  if ( ! efi_shutdown_in_progress )
499  efi_service_del ( efidev->device, binding, efidev->child );
500 
501  /* Free network device */
502  list_del ( &mnp->dev.siblings );
504  netdev_put ( netdev );
505 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
128 bit buffer containing a unique identifier value.
Definition: Base.h:215
int efi_service_del(EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE handle)
Remove service from child handle.
Definition: efi_service.c:96
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
EFI_GUID efi_managed_network_service_binding_protocol_guid
Managed network service binding protocol GUID.
Definition: efi_guid.c:255
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:58
An MNP NIC.
Definition: mnpnet.c:54
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
EFI_HANDLE child
EFI child device handle (if present)
Definition: efi_driver.h:23
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
EFI Boot Services Table.
Definition: UefiSpec.h:1917
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:85
A network device.
Definition: netdevice.h:352
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
EFI_SYSTEM_TABLE * efi_systab
struct efi_device * efidev
EFI device.
Definition: mnpnet.c:56
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:58
EFI_GUID efi_managed_network_protocol_guid
Managed network protocol GUID.
Definition: efi_guid.c:251

References EFI_SYSTEM_TABLE::BootServices, efi_device::child, EFI_BOOT_SERVICES::CloseProtocol, efi_device::device, efi_image_handle, efi_managed_network_protocol_guid, efi_managed_network_service_binding_protocol_guid, efi_service_del(), efi_shutdown_in_progress, efi_systab, mnp_nic::efidev, efidev_get_drvdata(), list_del, mnp_nic::mnp, netdev, netdev_nullify(), netdev_put(), net_device::priv, and unregister_netdev().

Referenced by mnptemp_create(), and mnptemp_destroy().

◆ mnptemp_create()

int mnptemp_create ( EFI_HANDLE  handle,
struct net_device **  netdev 
)

Create temporary MNP network device.

Parameters
handleMNP service binding handle
netdevNetwork device to fill in
Return values
rcReturn status code

Definition at line 514 of file mnpnet.c.

514  {
515  struct efi_device *efidev;
516  int rc;
517 
518  /* Create temporary EFI device */
519  efidev = efidev_alloc ( handle );
520  if ( ! efidev ) {
521  DBGC ( handle, "MNP %s could not create temporary device\n",
522  efi_handle_name ( handle ) );
523  rc = -ENOMEM;
524  goto err_alloc;
525  }
526 
527  /* Start temporary network device */
528  if ( ( rc = mnpnet_start ( efidev ) ) != 0 ) {
529  DBGC ( handle, "MNP %s could not start MNP: %s\n",
530  efi_handle_name ( handle ), strerror ( rc ) );
531  goto err_start;
532  }
533 
534  /* Fill in network device */
535  *netdev = efidev_get_drvdata ( efidev );
536 
537  return 0;
538 
539  mnpnet_stop ( efidev );
540  err_start:
541  efidev_free ( efidev );
542  err_alloc:
543  return rc;
544 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void efidev_free(struct efi_device *efidev)
Free EFI device.
Definition: efi_driver.c:118
#define DBGC(...)
Definition: compiler.h:505
#define ENOMEM
Not enough space.
Definition: errno.h:534
static struct net_device * netdev
Definition: gdbudp.c:52
struct efi_device * efidev_alloc(EFI_HANDLE device)
Allocate new EFI device.
Definition: efi_driver.c:70
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:85
An EFI device.
Definition: efi_driver.h:17
void mnpnet_stop(struct efi_device *efidev)
Detach driver from device.
Definition: mnpnet.c:484
uint16_t handle
Handle.
Definition: smbios.h:16
int mnpnet_start(struct efi_device *efidev)
Attach driver to device.
Definition: mnpnet.c:369

References DBGC, efi_handle_name(), efidev_alloc(), efidev_free(), efidev_get_drvdata(), ENOMEM, handle, mnpnet_start(), mnpnet_stop(), netdev, rc, and strerror().

Referenced by efi_autoexec_network().

◆ mnptemp_destroy()

void mnptemp_destroy ( struct net_device netdev)

Destroy temporary MNP network device.

Parameters
netdevNetwork device

Definition at line 551 of file mnpnet.c.

551  {
552  struct mnp_nic *mnp = netdev->priv;
553  struct efi_device *efidev = mnp->efidev;
554 
555  /* Recycle any cached DHCP packet */
557 
558  /* Stop temporary network device */
559  mnpnet_stop ( efidev );
560 
561  /* Free temporary EFI device */
562  efidev_free ( efidev );
563 }
void efidev_free(struct efi_device *efidev)
Free EFI device.
Definition: efi_driver.c:118
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:58
An MNP NIC.
Definition: mnpnet.c:54
void cachedhcp_recycle(struct net_device *netdev)
Recycle cached DHCPACK.
Definition: cachedhcp.c:352
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
An EFI device.
Definition: efi_driver.h:17
void mnpnet_stop(struct efi_device *efidev)
Detach driver from device.
Definition: mnpnet.c:484
struct efi_device * efidev
EFI device.
Definition: mnpnet.c:56

References cachedhcp_recycle(), mnp_nic::efidev, efidev_free(), mnp_nic::mnp, mnpnet_stop(), netdev, and net_device::priv.

Referenced by efi_autoexec_network().

Variable Documentation

◆ mnpnet_operations

struct net_device_operations mnpnet_operations
static
Initial value:
= {
.open = mnpnet_open,
.close = mnpnet_close,
.transmit = mnpnet_transmit,
.poll = mnpnet_poll,
}
static int mnpnet_open(struct net_device *netdev)
Open network device.
Definition: mnpnet.c:271
static void mnpnet_close(struct net_device *netdev)
Close network device.
Definition: mnpnet.c:332
static void mnpnet_poll(struct net_device *netdev)
Poll for completed packets.
Definition: mnpnet.c:245
static int mnpnet_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: mnpnet.c:96

MNP network device operations.

Definition at line 356 of file mnpnet.c.

Referenced by mnpnet_start().