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)
 
 FILE_SECBOOT (PERMITTED)
 
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  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ 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 80 of file mnpnet.c.

80  {
81  struct mnp_token *token = context;
82 
83  /* Sanity check */
84  assert ( token->busy );
85 
86  /* Mark token as no longer owned by MNP */
87  token->busy = 0;
88 }
An MNP transmit or receive token.
Definition: mnpnet.c:47
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 97 of file mnpnet.c.

98  {
99  struct mnp_nic *mnp = netdev->priv;
101  EFI_STATUS efirc;
102  int rc;
103 
104  /* Do nothing if shutdown is in progress */
106  return -ECANCELED;
107 
108  /* Defer the packet if there is already a transmission in progress */
109  if ( mnp->txbuf ) {
110  netdev_tx_defer ( netdev, iobuf );
111  return 0;
112  }
113 
114  /* Construct transmit token */
115  mnp->txdata.DataLength =
116  ( iob_len ( iobuf ) - ll_protocol->ll_header_len );
118  mnp->txdata.FragmentCount = 1;
119  mnp->txdata.FragmentTable[0].FragmentLength = iob_len ( iobuf );
120  mnp->txdata.FragmentTable[0].FragmentBuffer = iobuf->data;
121  mnp->tx.token.Packet.TxData = &mnp->txdata;
122 
123  /* Record as in use */
124  mnp->tx.busy = 1;
125 
126  /* Transmit packet */
127  if ( ( efirc = mnp->mnp->Transmit ( mnp->mnp, &mnp->tx.token ) ) != 0 ){
128  rc = -EEFI ( efirc );
129  DBGC ( mnp, "MNP %s could not transmit: %s\n",
130  netdev->name, strerror ( rc ) );
131  mnp->tx.busy = 0;
132  return rc;
133  }
134 
135  /* Record I/O buffer */
136  mnp->txbuf = iobuf;
137 
138  return 0;
139 }
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:175
void netdev_tx_defer(struct net_device *netdev, struct io_buffer *iobuf)
Defer transmitted packet.
Definition: netdevice.c:413
EFI_MANAGED_NETWORK_TRANSMIT Transmit
union EFI_MANAGED_NETWORK_COMPLETION_TOKEN::@586 Packet
uint8_t ll_header_len
Link-layer header length.
Definition: netdevice.h:201
struct mnp_token tx
Transmit token.
Definition: mnpnet.c:64
#define DBGC(...)
Definition: compiler.h:505
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:59
A link-layer protocol.
Definition: netdevice.h:115
An MNP NIC.
Definition: mnpnet.c:55
#define ECANCELED
Operation canceled.
Definition: errno.h:344
void * priv
Driver private data.
Definition: netdevice.h:432
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:363
EFI_MANAGED_NETWORK_FRAGMENT_DATA FragmentTable[1]
void * data
Start of data.
Definition: iobuf.h:53
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
int busy
Token is owned by MNP.
Definition: mnpnet.c:51
struct io_buffer * txbuf
Transmit I/O buffer.
Definition: mnpnet.c:68
EFI_MANAGED_NETWORK_COMPLETION_TOKEN token
MNP completion token.
Definition: mnpnet.c:49
EFI_MANAGED_NETWORK_TRANSMIT_DATA txdata
Transmit descriptor.
Definition: mnpnet.c:66
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:373
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:60

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 146 of file mnpnet.c.

146  {
147  struct mnp_nic *mnp = netdev->priv;
148  EFI_STATUS efirc;
149  int rc;
150 
151  /* Do nothing if receive token is still in use */
152  if ( mnp->rx.busy )
153  return;
154 
155  /* Mark as in use */
156  mnp->rx.busy = 1;
157 
158  /* Queue receive token */
159  if ( ( efirc = mnp->mnp->Receive ( mnp->mnp, &mnp->rx.token ) ) != 0 ) {
160  rc = -EEFI ( efirc );
161  DBGC ( mnp, "MNP %s could not receive: %s\n",
162  netdev->name, strerror ( rc ) );
163  /* Wait for next refill */
164  mnp->rx.busy = 0;
165  return;
166  }
167 }
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:175
#define DBGC(...)
Definition: compiler.h:505
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:59
An MNP NIC.
Definition: mnpnet.c:55
void * priv
Driver private data.
Definition: netdevice.h:432
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:363
EFI_MANAGED_NETWORK_RECEIVE Receive
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32

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 174 of file mnpnet.c.

174  {
175  struct mnp_nic *mnp = netdev->priv;
176  struct io_buffer *iobuf;
177  EFI_STATUS efirc;
178  int rc;
179 
180  /* Do nothing if transmit token is still in use */
181  if ( mnp->tx.busy )
182  return;
183 
184  /* Do nothing unless we have a completion */
185  if ( ! mnp->txbuf )
186  return;
187 
188  /* Get completion status */
189  efirc = mnp->tx.token.Status;
190  rc = ( efirc ? -EEFI ( efirc ) : 0 );
191 
192  /* Complete transmission */
193  iobuf = mnp->txbuf;
194  mnp->txbuf = NULL;
195  netdev_tx_complete_err ( netdev, iobuf, rc );
196 }
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:175
struct mnp_token tx
Transmit token.
Definition: mnpnet.c:64
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:59
An MNP NIC.
Definition: mnpnet.c:55
void * priv
Driver private data.
Definition: netdevice.h:432
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:471
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:32
int busy
Token is owned by MNP.
Definition: mnpnet.c:51
struct io_buffer * txbuf
Transmit I/O buffer.
Definition: mnpnet.c:68
EFI_MANAGED_NETWORK_COMPLETION_TOKEN token
MNP completion token.
Definition: mnpnet.c:49
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A persistent I/O buffer.
Definition: iobuf.h:38

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 203 of file mnpnet.c.

203  {
205  struct mnp_nic *mnp = netdev->priv;
207  struct io_buffer *iobuf;
208  size_t len;
209  EFI_STATUS efirc;
210  int rc;
211 
212  /* Do nothing unless we have a completion */
213  if ( mnp->rx.busy )
214  return;
215  rxdata = mnp->rx.token.Packet.RxData;
216 
217  /* Get completion status */
218  if ( ( efirc = mnp->rx.token.Status ) != 0 ) {
219  rc = -EEFI ( efirc );
220  netdev_rx_err ( netdev, NULL, rc );
221  goto recycle;
222  }
223 
224  /* Allocate and fill I/O buffer */
225  len = rxdata->PacketLength;
226  iobuf = alloc_iob ( len );
227  if ( ! iobuf ) {
229  goto recycle;
230  }
231  memcpy ( iob_put ( iobuf, len ), rxdata->MediaHeader, len );
232 
233  /* Hand off to network stack */
234  netdev_rx ( netdev, iobuf );
235 
236  recycle:
237  /* Recycle token */
238  bs->SignalEvent ( rxdata->RecycleEvent );
239 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2099
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:125
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:587
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
union EFI_MANAGED_NETWORK_COMPLETION_TOKEN::@586 Packet
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:59
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:131
An MNP NIC.
Definition: mnpnet.c:55
#define ENOMEM
Not enough space.
Definition: errno.h:535
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct mnp_token rx
Receive token.
Definition: mnpnet.c:71
void * priv
Driver private data.
Definition: netdevice.h:432
ring len
Length.
Definition: dwmac.h:231
static struct net_device * netdev
Definition: gdbudp.c:52
EFI_SIGNAL_EVENT SignalEvent
Definition: UefiSpec.h:1958
EFI Boot Services Table.
Definition: UefiSpec.h:1931
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:549
EFI_STATUS Status
The status that is returned to the caller at the end of the operation to indicate whether this operat...
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:32
int busy
Token is owned by MNP.
Definition: mnpnet.c:51
EFI_MANAGED_NETWORK_COMPLETION_TOKEN token
MNP completion token.
Definition: mnpnet.c:49
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A persistent I/O buffer.
Definition: iobuf.h:38

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 246 of file mnpnet.c.

246  {
247  struct mnp_nic *mnp = netdev->priv;
248 
249  /* Do nothing if shutdown is in progress */
251  return;
252 
253  /* Poll interface */
254  mnp->mnp->Poll ( mnp->mnp );
255 
256  /* Process any transmit completions */
258 
259  /* Process any receive completions */
261 
262  /* Refill receive token */
264 }
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:59
EFI_MANAGED_NETWORK_POLL Poll
An MNP NIC.
Definition: mnpnet.c:55
void * priv
Driver private data.
Definition: netdevice.h:432
static struct net_device * netdev
Definition: gdbudp.c:52
static void mnpnet_refill_rx(struct net_device *netdev)
Refill receive token.
Definition: mnpnet.c:146
static void mnpnet_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition: mnpnet.c:174
static void mnpnet_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: mnpnet.c:203
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:60

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 272 of file mnpnet.c.

272  {
274  static EFI_MANAGED_NETWORK_CONFIG_DATA config = {
276  .EnableMulticastReceive = TRUE,
277  .EnableBroadcastReceive = TRUE,
278  .EnablePromiscuousReceive = TRUE,
279  .FlushQueuesOnReset = TRUE,
280  .DisableBackgroundPolling = TRUE,
281  };
282  struct mnp_nic *mnp = netdev->priv;
283  EFI_STATUS efirc;
284  int rc;
285 
286  /* Create transmit event */
287  if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_SIGNAL, TPL_NOTIFY,
288  mnpnet_event, &mnp->tx,
289  &mnp->tx.token.Event ) ) != 0 ) {
290  rc = -EEFI ( efirc );
291  DBGC ( mnp, "MNP %s could not create TX event: %s\n",
292  netdev->name, strerror ( rc ) );
293  goto err_tx_event;
294  }
295 
296  /* Create receive event */
297  if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_SIGNAL, TPL_NOTIFY,
298  mnpnet_event, &mnp->rx,
299  &mnp->rx.token.Event ) ) != 0 ) {
300  rc = -EEFI ( efirc );
301  DBGC ( mnp, "MNP %s could not create RX event: %s\n",
302  netdev->name, strerror ( rc ) );
303  goto err_rx_event;
304  }
305 
306  /* Configure MNP */
307  if ( ( efirc = mnp->mnp->Configure ( mnp->mnp, &config ) ) != 0 ) {
308  rc = -EEFI ( efirc );
309  DBGC ( mnp, "MNP %s could not configure: %s\n",
310  netdev->name, strerror ( rc ) );
311  goto err_configure;
312  }
313 
314  /* Refill receive token */
316 
317  return 0;
318 
319  mnp->mnp->Configure ( mnp->mnp, NULL );
320  err_configure:
321  bs->CloseEvent ( mnp->rx.token.Event );
322  err_rx_event:
323  bs->CloseEvent ( mnp->tx.token.Event );
324  err_tx_event:
325  return rc;
326 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2099
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:175
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_EVENT CloseEvent
Definition: UefiSpec.h:1959
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:59
#define TPL_NOTIFY
Definition: UefiSpec.h:650
An MNP NIC.
Definition: mnpnet.c:55
void * priv
Driver private data.
Definition: netdevice.h:432
static struct net_device * netdev
Definition: gdbudp.c:52
EFI_CREATE_EVENT CreateEvent
Definition: UefiSpec.h:1955
static VOID EFIAPI mnpnet_event(EFI_EVENT event __unused, VOID *context)
Transmit or receive token event.
Definition: mnpnet.c:80
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static void mnpnet_refill_rx(struct net_device *netdev)
Refill receive token.
Definition: mnpnet.c:146
EFI Boot Services Table.
Definition: UefiSpec.h:1931
#define EVT_NOTIFY_SIGNAL
Definition: UefiSpec.h:454
#define TRUE
Definition: tlan.h:46
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:363
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
EFI_MANAGED_NETWORK_CONFIGURE Configure
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
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 333 of file mnpnet.c.

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

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 370 of file mnpnet.c.

370  {
374  struct net_device *netdev;
375  struct mnp_nic *mnp;
376  EFI_STATUS efirc;
377  int rc;
378 
379  /* Allocate and initalise structure */
380  netdev = alloc_etherdev ( sizeof ( *mnp ) );
381  if ( ! netdev ) {
382  rc = -ENOMEM;
383  goto err_alloc;
384  }
386  mnp = netdev->priv;
387  mnp->efidev = efidev;
389 
390  /* Populate underlying device information */
391  efi_device_info ( device, "MNP", &mnp->dev );
392  mnp->dev.driver_name = "MNP";
393  mnp->dev.parent = &efidev->dev;
394  list_add ( &mnp->dev.siblings, &efidev->dev.children );
395  INIT_LIST_HEAD ( &mnp->dev.children );
396  netdev->dev = &mnp->dev;
397 
398  /* Create MNP child */
399  if ( ( rc = efi_service_add ( device, binding,
400  &efidev->child ) ) != 0 ) {
401  DBGC ( mnp, "MNP %s could not create child: %s\n",
402  efi_handle_name ( device ), strerror ( rc ) );
403  goto err_service;
404  }
405 
406  /* Open MNP protocol */
407  if ( ( rc = efi_open_by_driver ( efidev->child,
409  &mnp->mnp ) ) != 0 ) {
410  DBGC ( mnp, "MNP %s could not open MNP protocol: %s\n",
411  efi_handle_name ( device ), strerror ( rc ) );
412  goto err_open;
413  }
414 
415  /* Get configuration */
416  efirc = mnp->mnp->GetModeData ( mnp->mnp, NULL, &mode );
417  if ( ( efirc != 0 ) && ( efirc != EFI_NOT_STARTED ) ) {
418  rc = -EEFI ( efirc );
419  DBGC ( mnp, "MNP %s could not get mode data: %s\n",
420  efi_handle_name ( device ), strerror ( rc ) );
421  goto err_mode;
422  }
423 
424  /* Populate network device parameters */
425  if ( mode.HwAddressSize != netdev->ll_protocol->hw_addr_len ) {
426  DBGC ( device, "MNP %s has invalid hardware address length "
427  "%d\n", efi_handle_name ( device ), mode.HwAddressSize );
428  rc = -ENOTSUP;
429  goto err_hw_addr_len;
430  }
431  memcpy ( netdev->hw_addr, &mode.PermanentAddress,
433  if ( mode.HwAddressSize != netdev->ll_protocol->ll_addr_len ) {
434  DBGC ( device, "MNP %s has invalid link-layer address length "
435  "%d\n", efi_handle_name ( device ), mode.HwAddressSize );
436  rc = -ENOTSUP;
437  goto err_ll_addr_len;
438  }
439  memcpy ( netdev->ll_addr, &mode.CurrentAddress,
441 
442  /* Register network device */
443  if ( ( rc = register_netdev ( netdev ) ) != 0 )
444  goto err_register;
445  DBGC ( mnp, "MNP %s registered as %s\n",
447 
448  /* Mark as link up: we don't handle link state */
450 
451  return 0;
452 
454  err_register:
455  err_ll_addr_len:
456  err_hw_addr_len:
457  err_mode:
460  err_open:
461  efi_service_del ( device, binding, efidev->child );
462  err_service:
463  list_del ( &mnp->dev.siblings );
465  netdev_put ( netdev );
466  err_alloc:
467  return rc;
468 }
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:175
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:199
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:70
128 bit buffer containing a unique identifier value.
Definition: Base.h:216
uint16_t mode
Acceleration mode.
Definition: ena.h:26
int efi_service_del(EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE handle)
Remove service from child handle.
Definition: efi_service.c:84
#define DBGC(...)
Definition: compiler.h:505
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:22
EFI_GUID efi_managed_network_service_binding_protocol_guid
Managed network service binding protocol GUID.
Definition: efi_guid.c:285
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:59
An MNP NIC.
Definition: mnpnet.c:55
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:519
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
EFI_HANDLE child
EFI child device handle (if present)
Definition: efi_driver.h:24
#define ENOMEM
Not enough space.
Definition: errno.h:535
A hardware device.
Definition: device.h:77
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:576
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition: efi_open.c:279
uint8_t hw_addr_len
Hardware address length.
Definition: netdevice.h:197
void * priv
Driver private data.
Definition: netdevice.h:432
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
Definition: efi.h:474
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:789
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:942
#define EFI_NOT_STARTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:134
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:760
A network device.
Definition: netdevice.h:353
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:532
int efi_service_add(EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE *handle)
Add service to child handle.
Definition: efi_service.c:47
struct device * dev
Underlying hardware device.
Definition: netdevice.h:365
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
static struct net_device_operations mnpnet_operations
MNP network device operations.
Definition: mnpnet.c:357
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:363
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
struct list_head children
Devices attached to this device.
Definition: device.h:87
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:265
EFI_MANAGED_NETWORK_GET_MODE_DATA GetModeData
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:388
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:84
struct device dev
Generic device.
Definition: efi_driver.h:20
struct efi_device * efidev
EFI device.
Definition: mnpnet.c:57
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:382
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
Definition: efi.h:62
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:373
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
Definition: efi_utils.c:189
EFI_GUID efi_managed_network_protocol_guid
Managed network protocol GUID.
Definition: efi_guid.c:281

References alloc_etherdev(), efi_device::child, device::children, DBGC, efi_device::dev, net_device::dev, efi_device::device, EEFI, efi_close_by_driver(), efi_device_info(), efi_handle_name(), efi_managed_network_protocol_guid, efi_managed_network_service_binding_protocol_guid, EFI_NOT_STARTED, efi_open_by_driver, efi_service_add(), efi_service_del(), mnp_nic::efidev, efidev_set_drvdata(), ENOMEM, ENOTSUP, _EFI_MANAGED_NETWORK_PROTOCOL::GetModeData, net_device::hw_addr, ll_protocol::hw_addr_len, 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, mode, net_device::name, netdev, netdev_init(), netdev_link_up(), netdev_nullify(), netdev_put(), NULL, net_device::priv, rc, register_netdev(), strerror(), 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 475 of file mnpnet.c.

475  {
477  struct net_device *netdev = efidev_get_drvdata ( efidev );
478  struct mnp_nic *mnp = netdev->priv;
479 
480  /* Unregister network device */
482 
483  /* Close MNP protocol */
486 
487  /* Remove MNP child (unless whole system shutdown is in progress) */
488  if ( ! efi_shutdown_in_progress )
489  efi_service_del ( efidev->device, binding, efidev->child );
490 
491  /* Free network device */
492  list_del ( &mnp->dev.siblings );
494  netdev_put ( netdev );
495 }
128 bit buffer containing a unique identifier value.
Definition: Base.h:216
int efi_service_del(EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE handle)
Remove service from child handle.
Definition: efi_service.c:84
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:22
EFI_GUID efi_managed_network_service_binding_protocol_guid
Managed network service binding protocol GUID.
Definition: efi_guid.c:285
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:59
An MNP NIC.
Definition: mnpnet.c:55
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
EFI_HANDLE child
EFI child device handle (if present)
Definition: efi_driver.h:24
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:576
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition: efi_open.c:279
void * priv
Driver private data.
Definition: netdevice.h:432
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:942
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:95
A network device.
Definition: netdevice.h:353
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:532
struct efi_device * efidev
EFI device.
Definition: mnpnet.c:57
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:60
EFI_GUID efi_managed_network_protocol_guid
Managed network protocol GUID.
Definition: efi_guid.c:281

References efi_device::child, efi_device::device, efi_close_by_driver(), efi_managed_network_protocol_guid, efi_managed_network_service_binding_protocol_guid, efi_service_del(), efi_shutdown_in_progress, 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 504 of file mnpnet.c.

504  {
505  struct efi_device *efidev;
506  int rc;
507 
508  /* Create temporary EFI device */
509  efidev = efidev_alloc ( handle );
510  if ( ! efidev ) {
511  DBGC ( handle, "MNP %s could not create temporary device\n",
512  efi_handle_name ( handle ) );
513  rc = -ENOMEM;
514  goto err_alloc;
515  }
516 
517  /* Start temporary network device */
518  if ( ( rc = mnpnet_start ( efidev ) ) != 0 ) {
519  DBGC ( handle, "MNP %s could not start MNP: %s\n",
520  efi_handle_name ( handle ), strerror ( rc ) );
521  goto err_start;
522  }
523 
524  /* Fill in network device */
525  *netdev = efidev_get_drvdata ( efidev );
526 
527  return 0;
528 
529  mnpnet_stop ( efidev );
530  err_start:
531  efidev_free ( efidev );
532  err_alloc:
533  return rc;
534 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void efidev_free(struct efi_device *efidev)
Free EFI device.
Definition: efi_driver.c:92
#define DBGC(...)
Definition: compiler.h:505
#define ENOMEM
Not enough space.
Definition: errno.h:535
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:57
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:95
An EFI device.
Definition: efi_driver.h:18
void mnpnet_stop(struct efi_device *efidev)
Detach driver from device.
Definition: mnpnet.c:475
uint16_t handle
Handle.
Definition: smbios.h:17
int mnpnet_start(struct efi_device *efidev)
Attach driver to device.
Definition: mnpnet.c:370

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 541 of file mnpnet.c.

541  {
542  struct mnp_nic *mnp = netdev->priv;
543  struct efi_device *efidev = mnp->efidev;
544 
545  /* Recycle any cached DHCP packet */
547 
548  /* Stop temporary network device */
549  mnpnet_stop ( efidev );
550 
551  /* Free temporary EFI device */
552  efidev_free ( efidev );
553 }
void efidev_free(struct efi_device *efidev)
Free EFI device.
Definition: efi_driver.c:92
EFI_MANAGED_NETWORK_PROTOCOL * mnp
Managed network protocol.
Definition: mnpnet.c:59
An MNP NIC.
Definition: mnpnet.c:55
void cachedhcp_recycle(struct net_device *netdev)
Recycle cached DHCPACK.
Definition: cachedhcp.c:355
void * priv
Driver private data.
Definition: netdevice.h:432
static struct net_device * netdev
Definition: gdbudp.c:52
An EFI device.
Definition: efi_driver.h:18
void mnpnet_stop(struct efi_device *efidev)
Detach driver from device.
Definition: mnpnet.c:475
struct efi_device * efidev
EFI device.
Definition: mnpnet.c:57

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:272
static void mnpnet_close(struct net_device *netdev)
Close network device.
Definition: mnpnet.c:333
static void mnpnet_poll(struct net_device *netdev)
Poll for completed packets.
Definition: mnpnet.c:246
static int mnpnet_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: mnpnet.c:97

MNP network device operations.

Definition at line 357 of file mnpnet.c.

Referenced by mnpnet_start().