iPXE
snp.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  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <errno.h>
27 #include <ipxe/efi/efi.h>
28 #include <ipxe/efi/efi_driver.h>
29 #include <ipxe/efi/efi_snp.h>
30 #include <ipxe/efi/efi_utils.h>
31 #include "snpnet.h"
32 #include "nii.h"
33 
34 /** @file
35  *
36  * SNP driver
37  *
38  */
39 
40 /**
41  * Check to see if driver supports a device
42  *
43  * @v device EFI device handle
44  * @v protocol Protocol GUID
45  * @ret rc Return status code
46  */
49  EFI_HANDLE parent;
50  EFI_STATUS efirc;
51  int rc;
52 
53  /* Check that this is not a device we are providing ourselves */
54  if ( find_snpdev ( device ) != NULL ) {
55  DBGCP ( device, "HANDLE %s is provided by this binary\n",
56  efi_handle_name ( device ) );
57  return -ENOTTY;
58  }
59 
60  /* Test for presence of protocol */
61  if ( ( efirc = bs->OpenProtocol ( device, protocol,
64  DBGCP ( device, "HANDLE %s is not a %s device\n",
66  efi_guid_ntoa ( protocol ) );
67  return -EEFI ( efirc );
68  }
69 
70  /* Check that there are no instances of this protocol further
71  * up this device path.
72  */
73  if ( ( rc = efi_locate_device ( device, protocol,
74  &parent, 1 ) ) == 0 ) {
75  DBGC2 ( device, "HANDLE %s has %s-supporting parent ",
77  efi_guid_ntoa ( protocol ) );
78  DBGC2 ( device, "%s\n", efi_handle_name ( parent ) );
79  return -ENOTTY;
80  }
81 
82  DBGC ( device, "HANDLE %s is a %s device\n",
84  return 0;
85 }
86 
87 /**
88  * Check to see if driver supports a device
89  *
90  * @v device EFI device handle
91  * @ret rc Return status code
92  */
94 
96 }
97 
98 /**
99  * Check to see if driver supports a device
100  *
101  * @v device EFI device handle
102  * @ret rc Return status code
103  */
105 
107 }
108 
109 /** EFI SNP driver */
110 struct efi_driver snp_driver __efi_driver ( EFI_DRIVER_NORMAL ) = {
111  .name = "SNP",
112  .supported = snp_supported,
113  .start = snpnet_start,
114  .stop = snpnet_stop,
115 };
116 
117 /** EFI NII driver */
118 struct efi_driver nii_driver __efi_driver ( EFI_DRIVER_NORMAL ) = {
119  .name = "NII",
120  .supported = nii_supported,
121  .start = nii_start,
122  .stop = nii_stop,
123 };
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:213
NII driver.
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2030
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:162
EFI driver interface.
128 bit buffer containing a unique identifier value.
Definition: Base.h:215
Error codes.
int nii_start(struct efi_device *efidev)
Attach driver to device.
Definition: nii.c:1265
void snpnet_stop(struct efi_device *efidev)
Detach driver from device.
Definition: snpnet.c:590
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
Definition: efi_guid.c:241
#define DBGC(...)
Definition: compiler.h:505
void nii_stop(struct efi_device *efidev)
Detach driver from device.
Definition: nii.c:1384
static int snp_supported(EFI_HANDLE device)
Check to see if driver supports a device.
Definition: snp.c:93
EFI utilities.
int snpnet_start(struct efi_device *efidev)
Attach driver to device.
Definition: snpnet.c:473
#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL
Definition: UefiSpec.h:1300
A hardware device.
Definition: device.h:73
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:724
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:194
EFI Boot Services Table.
Definition: UefiSpec.h:1866
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
SNP NIC driver.
int efi_locate_device(EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent, unsigned int skip)
Locate parent device supporting a given protocol.
Definition: efi_utils.c:45
static int nii_supported(EFI_HANDLE device)
Check to see if driver supports a device.
Definition: snp.c:104
EFI API.
An EFI driver.
Definition: efi_driver.h:31
struct efi_snp_device * find_snpdev(EFI_HANDLE handle)
Find SNP device by EFI device handle.
Definition: efi_snp.c:2115
#define DBGC2(...)
Definition: compiler.h:522
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
const char * name
Name.
Definition: efi_driver.h:33
static int snp_nii_supported(EFI_HANDLE device, EFI_GUID *protocol)
Check to see if driver supports a device.
Definition: snp.c:47
#define DBGCP(...)
Definition: compiler.h:539
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1935
uint16_t protocol
Protocol ID.
Definition: stp.h:18
iPXE EFI SNP interface
struct efi_driver snp_driver __efi_driver(EFI_DRIVER_NORMAL)
EFI SNP driver.
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
Definition: efi.h:50
#define EFI_DRIVER_NORMAL
Normal drivers.
Definition: efi_driver.h:63