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 "snpnet.h"
31 #include "nii.h"
32 
33 /** @file
34  *
35  * SNP driver
36  *
37  */
38 
39 /**
40  * Check to see if driver supports a device
41  *
42  * @v device EFI device handle
43  * @ret rc Return status code
44  */
47  EFI_STATUS efirc;
48 
49  /* Check that this is not a device we are providing ourselves */
50  if ( find_snpdev ( device ) != NULL ) {
51  DBGCP ( device, "SNP %s is provided by this binary\n",
52  efi_handle_name ( device ) );
53  return -ENOTTY;
54  }
55 
56  /* Test for presence of simple network protocol */
57  if ( ( efirc = bs->OpenProtocol ( device,
61  DBGCP ( device, "SNP %s is not an SNP device\n",
62  efi_handle_name ( device ) );
63  return -EEFI ( efirc );
64  }
65  DBGC ( device, "SNP %s is an SNP device\n",
66  efi_handle_name ( device ) );
67 
68  return 0;
69 }
70 
71 /**
72  * Check to see if driver supports a device
73  *
74  * @v device EFI device handle
75  * @ret rc Return status code
76  */
79  EFI_STATUS efirc;
80 
81  /* Check that this is not a device we are providing ourselves */
82  if ( find_snpdev ( device ) != NULL ) {
83  DBGCP ( device, "NII %s is provided by this binary\n",
84  efi_handle_name ( device ) );
85  return -ENOTTY;
86  }
87 
88  /* Test for presence of NII protocol */
89  if ( ( efirc = bs->OpenProtocol ( device,
93  DBGCP ( device, "NII %s is not an NII device\n",
94  efi_handle_name ( device ) );
95  return -EEFI ( efirc );
96  }
97  DBGC ( device, "NII %s is an NII device\n",
98  efi_handle_name ( device ) );
99 
100  return 0;
101 }
102 
103 /** EFI SNP driver */
104 struct efi_driver snp_driver __efi_driver ( EFI_DRIVER_NORMAL ) = {
105  .name = "SNP",
106  .supported = snp_supported,
107  .start = snpnet_start,
108  .stop = snpnet_stop,
109 };
110 
111 /** EFI NII driver */
112 struct efi_driver nii_driver __efi_driver ( EFI_DRIVER_NORMAL ) = {
113  .name = "NII",
114  .supported = nii_supported,
115  .start = nii_start,
116  .stop = nii_stop,
117 };
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:212
NII driver.
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:167
EFI driver interface.
Error codes.
int nii_start(struct efi_device *efidev)
Attach driver to device.
Definition: nii.c:1228
void snpnet_stop(struct efi_device *efidev)
Detach driver from device.
Definition: snpnet.c:581
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
Definition: efi_guid.c:236
#define DBGC(...)
Definition: compiler.h:505
void nii_stop(struct efi_device *efidev)
Detach driver from device.
Definition: nii.c:1347
static int snp_supported(EFI_HANDLE device)
Check to see if driver supports a device.
Definition: snp.c:45
int snpnet_start(struct efi_device *efidev)
Attach driver to device.
Definition: snpnet.c:464
#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL
Definition: UefiSpec.h:1272
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:713
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
SNP NIC driver.
static int nii_supported(EFI_HANDLE device)
Check to see if driver supports a device.
Definition: snp.c:77
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:1939
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
const char * name
Name.
Definition: efi_driver.h:33
#define DBGCP(...)
Definition: compiler.h:539
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
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:362
Definition: efi.h:55
#define EFI_DRIVER_NORMAL
Normal drivers.
Definition: efi_driver.h:63