iPXE
snpnet.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19 
20 FILE_LICENCE ( GPL2_OR_LATER );
21 
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <errno.h>
26 #include <ipxe/iobuf.h>
27 #include <ipxe/netdevice.h>
28 #include <ipxe/ethernet.h>
29 #include <ipxe/vsprintf.h>
30 #include <ipxe/timer.h>
31 #include <ipxe/efi/efi.h>
33 #include <ipxe/efi/efi_driver.h>
34 #include <ipxe/efi/efi_utils.h>
35 #include "snpnet.h"
36 
37 /** @file
38  *
39  * SNP NIC driver
40  *
41  */
42 
43 /** An SNP NIC */
44 struct snp_nic {
45  /** EFI device */
46  struct efi_device *efidev;
47  /** Simple network protocol */
49  /** Generic device */
50  struct device dev;
51 
52  /** Maximum packet size
53  *
54  * This is calculated as the sum of MediaHeaderSize and
55  * MaxPacketSize, and may therefore be an overestimate.
56  */
57  size_t mtu;
58 
59  /** Current transmit buffer */
60  struct io_buffer *txbuf;
61  /** Current receive buffer */
62  struct io_buffer *rxbuf;
63 };
64 
65 /** Maximum number of received packets per poll */
66 #define SNP_RX_QUOTA 4
67 
68 /** Maximum initialisation retry count */
69 #define SNP_INITIALIZE_RETRY_MAX 10
70 
71 /** Delay between each initialisation retry */
72 #define SNP_INITIALIZE_RETRY_DELAY_MS 10
73 
74 /**
75  * Format SNP MAC address (for debugging)
76  *
77  * @v mac MAC address
78  * @v len Length of MAC address
79  * @ret text MAC address as text
80  */
81 static const char * snpnet_mac_text ( EFI_MAC_ADDRESS *mac, size_t len ) {
82  static char buf[ sizeof ( *mac ) * 3 /* "xx:" or "xx\0" */ ];
83  size_t used = 0;
84  unsigned int i;
85 
86  for ( i = 0 ; i < len ; i++ ) {
87  used += ssnprintf ( &buf[used], ( sizeof ( buf ) - used ),
88  "%s%02x", ( used ? ":" : "" ),
89  mac->Addr[i] );
90  }
91  return buf;
92 }
93 
94 /**
95  * Dump SNP mode information (for debugging)
96  *
97  * @v netdev Network device
98  */
99 static void snpnet_dump_mode ( struct net_device *netdev ) {
100  struct snp_nic *snp = netdev_priv ( netdev );
101  EFI_SIMPLE_NETWORK_MODE *mode = snp->snp->Mode;
102  size_t mac_len = mode->HwAddressSize;
103  unsigned int i;
104 
105  /* Do nothing unless debugging is enabled */
106  if ( ! DBG_EXTRA )
107  return;
108 
109  DBGC2 ( snp, "SNP %s st %d type %d hdr %d pkt %d rxflt %#x/%#x%s "
110  "nvram %d acc %d mcast %d/%d\n", netdev->name, mode->State,
111  mode->IfType, mode->MediaHeaderSize, mode->MaxPacketSize,
113  ( mode->MultipleTxSupported ? " multitx" : "" ),
114  mode->NvRamSize, mode->NvRamAccessSize,
115  mode->MCastFilterCount, mode->MaxMCastFilterCount );
116  DBGC2 ( snp, "SNP %s hw %s", netdev->name,
117  snpnet_mac_text ( &mode->PermanentAddress, mac_len ) );
118  DBGC2 ( snp, " addr %s%s",
119  snpnet_mac_text ( &mode->CurrentAddress, mac_len ),
120  ( mode->MacAddressChangeable ? "" : "(f)" ) );
121  DBGC2 ( snp, " bcast %s\n",
122  snpnet_mac_text ( &mode->BroadcastAddress, mac_len ) );
123  for ( i = 0 ; i < mode->MCastFilterCount ; i++ ) {
124  DBGC2 ( snp, "SNP %s mcast %s\n", netdev->name,
125  snpnet_mac_text ( &mode->MCastFilter[i], mac_len ) );
126  }
127  DBGC2 ( snp, "SNP %s media %s\n", netdev->name,
128  ( mode->MediaPresentSupported ?
129  ( mode->MediaPresent ? "present" : "not present" ) :
130  "presence not supported" ) );
131 }
132 
133 /**
134  * Check link state
135  *
136  * @v netdev Network device
137  */
138 static void snpnet_check_link ( struct net_device *netdev ) {
139  struct snp_nic *snp = netdev_priv ( netdev );
140  EFI_SIMPLE_NETWORK_MODE *mode = snp->snp->Mode;
141 
142  /* Do nothing unless media presence detection is supported */
143  if ( ! mode->MediaPresentSupported )
144  return;
145 
146  /* Report any link status change */
147  if ( mode->MediaPresent && ( ! netdev_link_ok ( netdev ) ) ) {
149  } else if ( ( ! mode->MediaPresent ) && netdev_link_ok ( netdev ) ) {
151  }
152 }
153 
154 /**
155  * Transmit packet
156  *
157  * @v netdev Network device
158  * @v iobuf I/O buffer
159  * @ret rc Return status code
160  */
161 static int snpnet_transmit ( struct net_device *netdev,
162  struct io_buffer *iobuf ) {
163  struct snp_nic *snp = netdev_priv ( netdev );
164  EFI_STATUS efirc;
165  int rc;
166 
167  /* Do nothing if shutdown is in progress */
169  return -ECANCELED;
170 
171  /* Defer the packet if there is already a transmission in progress */
172  if ( snp->txbuf ) {
173  netdev_tx_defer ( netdev, iobuf );
174  return 0;
175  }
176 
177  /* Transmit packet */
178  if ( ( efirc = snp->snp->Transmit ( snp->snp, 0, iob_len ( iobuf ),
179  iobuf->data, NULL, NULL,
180  NULL ) ) != 0 ) {
181  rc = -EEFI ( efirc );
182  DBGC ( snp, "SNP %s could not transmit: %s\n",
183  netdev->name, strerror ( rc ) );
184  return rc;
185  }
186  snp->txbuf = iobuf;
187 
188  return 0;
189 }
190 
191 /**
192  * Poll for completed packets
193  *
194  * @v netdev Network device
195  */
196 static void snpnet_poll_tx ( struct net_device *netdev ) {
197  struct snp_nic *snp = netdev->priv;
198  struct io_buffer *iobuf;
199  UINT32 irq;
200  VOID *txbuf;
201  EFI_STATUS efirc;
202  int rc;
203 
204  /* Get status */
205  txbuf = NULL;
206  if ( ( efirc = snp->snp->GetStatus ( snp->snp, &irq, &txbuf ) ) != 0 ) {
207  rc = -EEFI ( efirc );
208  DBGC ( snp, "SNP %s could not get status: %s\n",
209  netdev->name, strerror ( rc ) );
210  netdev_rx_err ( netdev, NULL, rc );
211  return;
212  }
213 
214  /* Do nothing unless we have a completion */
215  if ( ! txbuf )
216  return;
217 
218  /* Sanity check */
219  if ( ! snp->txbuf ) {
220  DBGC ( snp, "SNP %s reported spurious TX completion\n",
221  netdev->name );
223  return;
224  }
225 
226  /* Complete transmission */
227  iobuf = snp->txbuf;
228  snp->txbuf = NULL;
229  netdev_tx_complete ( netdev, iobuf );
230 }
231 
232 /**
233  * Poll for received packets
234  *
235  * @v netdev Network device
236  */
237 static void snpnet_poll_rx ( struct net_device *netdev ) {
238  struct snp_nic *snp = netdev->priv;
239  UINTN len;
240  unsigned int quota;
241  EFI_STATUS efirc;
242  int rc;
243 
244  /* Retrieve up to SNP_RX_QUOTA packets */
245  for ( quota = SNP_RX_QUOTA ; quota ; quota-- ) {
246 
247  /* Allocate buffer, if required */
248  if ( ! snp->rxbuf ) {
249  snp->rxbuf = alloc_iob ( snp->mtu );
250  if ( ! snp->rxbuf ) {
251  /* Leave for next poll */
252  break;
253  }
254  }
255 
256  /* Receive packet */
257  len = iob_tailroom ( snp->rxbuf );
258  if ( ( efirc = snp->snp->Receive ( snp->snp, NULL, &len,
259  snp->rxbuf->data, NULL,
260  NULL, NULL ) ) != 0 ) {
261 
262  /* EFI_NOT_READY is just the usual "no packet"
263  * status indication; ignore it.
264  */
265  if ( efirc == EFI_NOT_READY )
266  break;
267 
268  /* Anything else is an error */
269  rc = -EEFI ( efirc );
270  DBGC ( snp, "SNP %s could not receive: %s\n",
271  netdev->name, strerror ( rc ) );
272  netdev_rx_err ( netdev, NULL, rc );
273  break;
274  }
275 
276  /* Hand off to network stack */
277  iob_put ( snp->rxbuf, len );
278  netdev_rx ( netdev, snp->rxbuf );
279  snp->rxbuf = NULL;
280  }
281 }
282 
283 /**
284  * Poll for completed packets
285  *
286  * @v netdev Network device
287  */
288 static void snpnet_poll ( struct net_device *netdev ) {
289 
290  /* Do nothing if shutdown is in progress */
292  return;
293 
294  /* Process any TX completions */
296 
297  /* Process any RX completions */
299 
300  /* Check for link state changes */
302 }
303 
304 /**
305  * Set receive filters
306  *
307  * @v netdev Network device
308  * @ret rc Return status code
309  */
310 static int snpnet_rx_filters ( struct net_device *netdev ) {
311  struct snp_nic *snp = netdev->priv;
312  UINT32 filters[] = {
313  snp->snp->Mode->ReceiveFilterMask,
323  };
324  unsigned int i;
325  EFI_STATUS efirc;
326  int rc;
327 
328  /* Try possible receive filters in turn */
329  for ( i = 0; i < ( sizeof ( filters ) / sizeof ( filters[0] ) ); i++ ) {
330  efirc = snp->snp->ReceiveFilters ( snp->snp, filters[i],
332  0, NULL );
333  if ( efirc == 0 )
334  return 0;
335  rc = -EEFI ( efirc );
336  DBGC ( snp, "SNP %s could not set receive filters %#02x (have "
337  "%#02x): %s\n", netdev->name, filters[i],
338  snp->snp->Mode->ReceiveFilterSetting, strerror ( rc ) );
339  }
340 
341  return rc;
342 }
343 
344 /**
345  * Open network device
346  *
347  * @v netdev Network device
348  * @ret rc Return status code
349  */
350 static int snpnet_open ( struct net_device *netdev ) {
351  struct snp_nic *snp = netdev->priv;
352  EFI_MAC_ADDRESS *mac = ( ( void * ) netdev->ll_addr );
353  EFI_SIMPLE_NETWORK_MODE *mode = snp->snp->Mode;
354  EFI_STATUS efirc;
355  unsigned int retry;
356  int rc;
357 
358  /* Try setting MAC address (before initialising) */
359  if ( ( efirc = snp->snp->StationAddress ( snp->snp, FALSE, mac ) ) !=0){
360  rc = -EEFI ( efirc );
361  DBGC ( snp, "SNP %s could not set station address before "
362  "initialising: %s\n", netdev->name, strerror ( rc ) );
363  /* Ignore error */
364  }
365 
366  /* Initialise NIC, retrying multiple times if link stays down */
367  for ( retry = 0 ; ; ) {
368 
369  /* Initialise NIC */
370  if ( ( efirc = snp->snp->Initialize ( snp->snp,
371  0, 0 ) ) != 0 ) {
372  rc = -EEFI ( efirc );
374  DBGC ( snp, "SNP %s could not initialise: %s\n",
375  netdev->name, strerror ( rc ) );
376  return rc;
377  }
378 
379  /* Stop if we have link up (or no link detection capability) */
380  if ( ( ! mode->MediaPresentSupported ) || mode->MediaPresent )
381  break;
382 
383  /* Stop if we have exceeded our retry count. This is
384  * not a failure; it is plausible that we genuinely do
385  * not have link up.
386  */
387  if ( ++retry >= SNP_INITIALIZE_RETRY_MAX )
388  break;
389  DBGC ( snp, "SNP %s retrying initialisation (retry %d)\n",
390  netdev->name, retry );
391 
392  /* Delay to allow time for link to establish */
394 
395  /* Shut down and retry; this is sometimes necessary in
396  * order to persuade the underlying SNP driver to
397  * actually update the link state.
398  */
399  if ( ( efirc = snp->snp->Shutdown ( snp->snp ) ) != 0 ) {
400  rc = -EEFI ( efirc );
402  DBGC ( snp, "SNP %s could not shut down: %s\n",
403  netdev->name, strerror ( rc ) );
404  return rc;
405  }
406  }
407 
408  /* Try setting MAC address (after initialising) */
409  if ( ( efirc = snp->snp->StationAddress ( snp->snp, FALSE, mac ) ) !=0){
410  rc = -EEFI ( efirc );
411  DBGC ( snp, "SNP %s could not set station address after "
412  "initialising: %s\n", netdev->name, strerror ( rc ) );
413  /* Ignore error */
414  }
415 
416  /* Set receive filters */
417  if ( ( rc = snpnet_rx_filters ( netdev ) ) != 0 ) {
418  /* Ignore error */
419  }
420 
421  /* Dump mode information (for debugging) */
423 
424  return 0;
425 }
426 
427 /**
428  * Close network device
429  *
430  * @v netdev Network device
431  */
432 static void snpnet_close ( struct net_device *netdev ) {
433  struct snp_nic *snp = netdev->priv;
434  EFI_STATUS efirc;
435  int rc;
436 
437  /* Shut down NIC (unless whole system shutdown is in progress) */
438  if ( ( ! efi_shutdown_in_progress ) &&
439  ( ( efirc = snp->snp->Shutdown ( snp->snp ) ) != 0 ) ) {
440  rc = -EEFI ( efirc );
441  DBGC ( snp, "SNP %s could not shut down: %s\n",
442  netdev->name, strerror ( rc ) );
443  /* Nothing we can do about this */
444  }
445 
446  /* Discard transmit buffer, if applicable */
447  if ( snp->txbuf ) {
449  snp->txbuf = NULL;
450  }
451 
452  /* Discard receive buffer, if applicable */
453  if ( snp->rxbuf ) {
454  free_iob ( snp->rxbuf );
455  snp->rxbuf = NULL;
456  }
457 }
458 
459 /** SNP network device operations */
461  .open = snpnet_open,
462  .close = snpnet_close,
463  .transmit = snpnet_transmit,
464  .poll = snpnet_poll,
465 };
466 
467 /**
468  * Attach driver to device
469  *
470  * @v efidev EFI device
471  * @ret rc Return status code
472  */
473 int snpnet_start ( struct efi_device *efidev ) {
475  EFI_HANDLE device = efidev->device;
477  struct net_device *netdev;
478  struct snp_nic *snp;
479  void *interface;
480  EFI_STATUS efirc;
481  int rc;
482 
483  /* Open SNP protocol */
484  if ( ( efirc = bs->OpenProtocol ( device,
489  rc = -EEFI ( efirc );
490  DBGC ( device, "SNP %s cannot open SNP protocol: %s\n",
491  efi_handle_name ( device ), strerror ( rc ) );
494  goto err_open_protocol;
495  }
496 
497  /* Allocate and initialise structure */
498  netdev = alloc_etherdev ( sizeof ( *snp ) );
499  if ( ! netdev ) {
500  rc = -ENOMEM;
501  goto err_alloc;
502  }
504  snp = netdev->priv;
505  snp->efidev = efidev;
506  snp->snp = interface;
507  mode = snp->snp->Mode;
509 
510  /* Populate underlying device information */
511  efi_device_info ( device, "SNP", &snp->dev );
512  snp->dev.driver_name = "SNP";
513  snp->dev.parent = &efidev->dev;
514  list_add ( &snp->dev.siblings, &efidev->dev.children );
515  INIT_LIST_HEAD ( &snp->dev.children );
516  netdev->dev = &snp->dev;
517 
518  /* Bring to the Started state */
519  if ( ( mode->State == EfiSimpleNetworkStopped ) &&
520  ( ( efirc = snp->snp->Start ( snp->snp ) ) != 0 ) ) {
521  rc = -EEFI ( efirc );
522  DBGC ( device, "SNP %s could not start: %s\n",
523  efi_handle_name ( device ), strerror ( rc ) );
524  goto err_start;
525  }
526  if ( ( mode->State == EfiSimpleNetworkInitialized ) &&
527  ( ( efirc = snp->snp->Shutdown ( snp->snp ) ) != 0 ) ) {
528  rc = -EEFI ( efirc );
529  DBGC ( device, "SNP %s could not shut down: %s\n",
530  efi_handle_name ( device ), strerror ( rc ) );
531  goto err_shutdown;
532  }
533 
534  /* Populate network device parameters */
535  if ( mode->HwAddressSize != netdev->ll_protocol->hw_addr_len ) {
536  DBGC ( device, "SNP %s has invalid hardware address length "
537  "%d\n", efi_handle_name ( device ), mode->HwAddressSize);
538  rc = -ENOTSUP;
539  goto err_hw_addr_len;
540  }
543  if ( mode->HwAddressSize != netdev->ll_protocol->ll_addr_len ) {
544  DBGC ( device, "SNP %s has invalid link-layer address length "
545  "%d\n", efi_handle_name ( device ), mode->HwAddressSize);
546  rc = -ENOTSUP;
547  goto err_ll_addr_len;
548  }
549  memcpy ( netdev->ll_addr, &mode->CurrentAddress,
551  snp->mtu = ( snp->snp->Mode->MaxPacketSize +
552  snp->snp->Mode->MediaHeaderSize );
553 
554  /* Register network device */
555  if ( ( rc = register_netdev ( netdev ) ) != 0 )
556  goto err_register_netdev;
557  DBGC ( device, "SNP %s registered as %s\n",
559 
560  /* Set initial link state */
561  if ( snp->snp->Mode->MediaPresentSupported ) {
563  } else {
565  }
566 
567  return 0;
568 
570  err_register_netdev:
571  err_ll_addr_len:
572  err_hw_addr_len:
573  err_shutdown:
574  err_start:
575  list_del ( &snp->dev.siblings );
577  netdev_put ( netdev );
578  err_alloc:
581  err_open_protocol:
582  return rc;
583 }
584 
585 /**
586  * Detach driver from device
587  *
588  * @v efidev EFI device
589  */
590 void snpnet_stop ( struct efi_device *efidev ) {
592  struct net_device *netdev = efidev_get_drvdata ( efidev );
593  struct snp_nic *snp = netdev->priv;
595  EFI_STATUS efirc;
596  int rc;
597 
598  /* Unregister network device */
600 
601  /* Stop SNP protocol (unless whole system shutdown is in progress) */
602  if ( ( ! efi_shutdown_in_progress ) &&
603  ( ( efirc = snp->snp->Stop ( snp->snp ) ) != 0 ) ) {
604  rc = -EEFI ( efirc );
605  DBGC ( device, "SNP %s could not stop: %s\n",
606  efi_handle_name ( device ), strerror ( rc ) );
607  /* Nothing we can do about this */
608  }
609 
610  /* Free network device */
611  list_del ( &snp->dev.siblings );
613  netdev_put ( netdev );
614 
615  /* Close SNP protocol */
618 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
EFI_SIMPLE_NETWORK_STATION_ADDRESS StationAddress
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:578
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:758
UINT32 NvRamSize
The size, in bytes, of the NVRAM device attached to the network interface.
#define iob_put(iobuf, len)
Definition: iobuf.h:120
static void snpnet_dump_mode(struct net_device *netdev)
Dump SNP mode information (for debugging)
Definition: snpnet.c:99
static void snpnet_poll(struct net_device *netdev)
Poll for completed packets.
Definition: snpnet.c:288
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:542
The EFI_SIMPLE_NETWORK_PROTOCOL protocol is used to initialize access to a network adapter.
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
void netdev_tx_defer(struct net_device *netdev, struct io_buffer *iobuf)
Defer transmitted packet.
Definition: netdevice.c:368
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
EFI driver interface.
UINT32 MediaHeaderSize
The size, in bytes, of the network interface's media header.
int(* open)(struct net_device *netdev)
Open network device.
Definition: netdevice.h:222
BOOLEAN MediaPresent
TRUE if media are connected to the network interface; otherwise FALSE.
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
Definition: netdevice.c:396
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
Definition: snpnet.c:48
Error codes.
32-byte buffer containing a network Media Access Control address.
Definition: UefiBaseType.h:102
void snpnet_stop(struct efi_device *efidev)
Detach driver from device.
Definition: snpnet.c:590
I/O buffers.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
static int snpnet_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: snpnet.c:161
#define EPIPE
Broken pipe.
Definition: errno.h:619
printf() and friends
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
Definition: efi_guid.c:236
#define DBGC(...)
Definition: compiler.h:505
#define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST
unsigned int UINT32
Definition: ProcessorBind.h:56
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1274
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1275
BOOLEAN MediaPresentSupported
TRUE if the presence of media can be determined; otherwise FALSE.
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:186
iPXE timers
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:286
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
UINT32 State
Reports the current state of the network interface.
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
struct io_buffer * rxbuf
Current receive buffer.
Definition: snpnet.c:62
#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST
EFI_MAC_ADDRESS CurrentAddress
The current HW MAC address for the network interface.
EFI utilities.
#define ECANCELED
Operation canceled.
Definition: errno.h:343
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
EFI_SIMPLE_NETWORK_MODE * Mode
Pointer to the EFI_SIMPLE_NETWORK_MODE data for the device.
int snpnet_start(struct efi_device *efidev)
Attach driver to device.
Definition: snpnet.c:473
EFI_MAC_ADDRESS MCastFilter[MAX_MCAST_FILTER_CNT]
Array containing the addresses of the current multicast address receive filters.
EFI_MAC_ADDRESS BroadcastAddress
The current HW MAC address for broadcast packets.
static const char * snpnet_mac_text(EFI_MAC_ADDRESS *mac, size_t len)
Format SNP MAC address (for debugging)
Definition: snpnet.c:81
int ssnprintf(char *buf, ssize_t ssize, const char *fmt,...)
Version of vsnprintf() that accepts a signed buffer size.
Definition: vsprintf.c:420
BOOLEAN MultipleTxSupported
TRUE if the network interface can transmit more than one packet at a time.
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:510
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
UINT8 IfType
The interface type of the network interface.
UINT32 MaxPacketSize
The maximum size, in bytes, of the packets supported by the network interface.
#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
FILE_LICENCE(GPL2_OR_LATER)
UINT32 ReceiveFilterSetting
The current multicast receive filter settings.
UINT32 MCastFilterCount
The current number of multicast address receive filters.
EFI_SIMPLE_NETWORK_INITIALIZE Initialize
struct io_buffer * txbuf
Current transmit buffer.
Definition: snpnet.c:60
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:567
Ethernet protocol.
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
EFI_SIMPLE_NETWORK_SHUTDOWN Shutdown
EFI_SIMPLE_NETWORK_GET_STATUS GetStatus
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:780
The EFI_SIMPLE_NETWORK_PROTOCOL provides services to initialize a network interface,...
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:642
static struct net_device * netdev
Definition: gdbudp.c:52
static void snpnet_check_link(struct net_device *netdev)
Check link state.
Definition: snpnet.c:138
EFI_SIMPLE_NETWORK_TRANSMIT Transmit
static void snpnet_close(struct net_device *netdev)
Close network device.
Definition: snpnet.c:432
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:899
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
BOOLEAN MacAddressChangeable
TRUE if the HW MAC address can be changed.
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:722
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:83
A network device.
Definition: netdevice.h:352
An SNP NIC.
Definition: snpnet.c:44
static size_t iob_tailroom(struct io_buffer *iobuf)
Calculate available space at end of an I/O buffer.
Definition: iobuf.h:175
struct device dev
Generic device.
Definition: snpnet.c:50
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:523
UINT32 NvRamAccessSize
The size that must be used for all NVRAM reads and writes.
SNP NIC driver.
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
#define EFI_NOT_READY
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:126
An EFI device.
Definition: efi_driver.h:17
#define SNP_RX_QUOTA
Maximum number of received packets per poll.
Definition: snpnet.c:66
static int snpnet_open(struct net_device *netdev)
Open network device.
Definition: snpnet.c:350
static int snpnet_rx_filters(struct net_device *netdev)
Set receive filters.
Definition: snpnet.c:310
static void snpnet_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition: snpnet.c:196
#define SNP_INITIALIZE_RETRY_MAX
Maximum initialisation retry count.
Definition: snpnet.c:69
EFI_SIMPLE_NETWORK_START Start
#define VOID
Undeclared type.
Definition: Base.h:319
struct efi_device * efidev
EFI device.
Definition: snpnet.c:46
#define TRUE
Definition: tlan.h:46
EFI API.
Network device operations.
Definition: netdevice.h:213
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:504
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
EFI_SIMPLE_NETWORK_RECEIVE Receive
Network device management.
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
#define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:426
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
UINT32 HwAddressSize
The size, in bytes, of the network interface's HW address.
UINT32 MaxMCastFilterCount
The maximum number of multicast address receive filters supported by the driver.
void * data
Start of data.
Definition: iobuf.h:48
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
struct list_head children
Devices attached to this device.
Definition: device.h:83
UINT32 ReceiveFilterMask
The multicast receive filter settings supported by the network interface.
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
static void snpnet_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: snpnet.c:237
#define FALSE
Definition: tlan.h:45
#define SNP_INITIALIZE_RETRY_DELAY_MS
Delay between each initialisation retry.
Definition: snpnet.c:72
EFI_SIMPLE_NETWORK_RECEIVE_FILTERS ReceiveFilters
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
EFI_SIMPLE_NETWORK_STOP Stop
#define DBG_EXTRA
Definition: compiler.h:319
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:72
struct device dev
Generic device.
Definition: efi_driver.h:19
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
String functions.
static struct net_device_operations snpnet_operations
SNP network device operations.
Definition: snpnet.c:460
Definition: efi.h:50
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
size_t mtu
Maximum packet size.
Definition: snpnet.c:57
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
Definition: efi_utils.c:181
EFI_MAC_ADDRESS PermanentAddress
The permanent HW MAC address for the network interface.
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:57
A persistent I/O buffer.
Definition: iobuf.h:33