iPXE
Functions | Variables
undi.c File Reference

UNDI PCI driver. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ipxe/pci.h>
#include <undi.h>
#include <undirom.h>
#include <undiload.h>
#include <undinet.h>
#include <undipreload.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
static struct undi_romundipci_find_rom (struct pci_device *pci)
 Find UNDI ROM for PCI device. More...
 
static int undipci_probe (struct pci_device *pci)
 Probe PCI device. More...
 
static void undipci_remove (struct pci_device *pci)
 Remove PCI device. More...
 

Variables

static struct pci_device_id undipci_nics []
 
struct pci_driver undipci_driver __pci_driver_fallback
 

Detailed Description

UNDI PCI driver.

Definition in file undi.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ undipci_find_rom()

static struct undi_rom* undipci_find_rom ( struct pci_device pci)
static

Find UNDI ROM for PCI device.

Parameters
pciPCI device
Return values
undiromUNDI ROM, or NULL

Try to find a driver for this device. Try an exact match on the ROM address first, then fall back to a vendor/device ID match only

Definition at line 48 of file undi.c.

48  {
49  struct undi_rom *undirom;
50  unsigned long rombase;
51 
52  rombase = pci_bar_start ( pci, PCI_ROM_ADDRESS );
53  undirom = undirom_find_pci ( pci->vendor, pci->device, rombase );
54  if ( ! undirom )
55  undirom = undirom_find_pci ( pci->vendor, pci->device, 0 );
56  return undirom;
57 }
#define PCI_ROM_ADDRESS
PCI expansion ROM base address.
Definition: pci.h:80
An UNDI ROM.
Definition: undirom.h:29
uint16_t device
Device ID.
Definition: pci.h:204
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition: pci.c:96
uint16_t vendor
Vendor ID.
Definition: pci.h:202
struct undi_rom * undirom_find_pci(unsigned int vendor_id, unsigned int device_id, unsigned int rombase)
Find UNDI ROM for PCI device.
Definition: undirom.c:211

References pci_device::device, pci_bar_start(), PCI_ROM_ADDRESS, undirom_find_pci(), and pci_device::vendor.

Referenced by undipci_probe().

◆ undipci_probe()

static int undipci_probe ( struct pci_device pci)
static

Probe PCI device.

Parameters
pciPCI device
idPCI ID
Return values
rcReturn status code

Definition at line 66 of file undi.c.

66  {
67  struct undi_device *undi;
68  struct undi_rom *undirom;
69  int rc;
70 
71  /* Allocate UNDI device structure */
72  undi = zalloc ( sizeof ( *undi ) );
73  if ( ! undi )
74  return -ENOMEM;
75  pci_set_drvdata ( pci, undi );
76 
77  /* Find/create our pixie */
78  if ( preloaded_undi.pci_busdevfn == pci->busdevfn ) {
79  /* Claim preloaded UNDI device */
80  DBGC ( undi, "UNDI %p using preloaded UNDI device\n", undi );
81  memcpy ( undi, &preloaded_undi, sizeof ( *undi ) );
82  memset ( &preloaded_undi, 0, sizeof ( preloaded_undi ) );
83  } else {
84  /* Find UNDI ROM for PCI device */
85  if ( ! ( undirom = undipci_find_rom ( pci ) ) ) {
86  rc = -ENODEV;
87  goto err_find_rom;
88  }
89 
90  /* Call UNDI ROM loader to create pixie */
91  if ( ( rc = undi_load_pci ( undi, undirom,
92  pci->busdevfn ) ) != 0 ) {
93  goto err_load_pci;
94  }
95  }
96 
97  /* Create network device */
98  if ( ( rc = undinet_probe ( undi, &pci->dev ) ) != 0 )
99  goto err_undinet_probe;
100 
101  return 0;
102 
103  err_undinet_probe:
104  undi_unload ( undi );
105  err_find_rom:
106  err_load_pci:
107  free ( undi );
108  pci_set_drvdata ( pci, NULL );
109  return rc;
110 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int undinet_probe(struct undi_device *undi, struct device *dev)
Probe UNDI device.
Definition: undinet.c:881
#define DBGC(...)
Definition: compiler.h:505
An UNDI ROM.
Definition: undirom.h:29
struct device dev
Generic device.
Definition: pci.h:189
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:338
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define preloaded_undi
Definition: undipreload.h:16
static struct undi_rom * undipci_find_rom(struct pci_device *pci)
Find UNDI ROM for PCI device.
Definition: undi.c:48
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
#define ENODEV
No such device.
Definition: errno.h:509
int undi_unload(struct undi_device *undi)
Unload a pixie.
Definition: undiload.c:161
An UNDI device.
Definition: undi.h:22
static int undi_load_pci(struct undi_device *undi, struct undi_rom *undirom, unsigned int pci_busdevfn)
Call UNDI loader to create a pixie.
Definition: undiload.h:26
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:210
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
void * memset(void *dest, int character, size_t len) __nonnull

References pci_device::busdevfn, DBGC, pci_device::dev, ENODEV, ENOMEM, free, memcpy(), memset(), NULL, pci_set_drvdata(), preloaded_undi, rc, undi_load_pci(), undi_unload(), undinet_probe(), undipci_find_rom(), and zalloc().

◆ undipci_remove()

static void undipci_remove ( struct pci_device pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 117 of file undi.c.

117  {
118  struct undi_device *undi = pci_get_drvdata ( pci );
119 
120  undinet_remove ( undi );
121  undi_unload ( undi );
122  free ( undi );
123  pci_set_drvdata ( pci, NULL );
124 }
void undinet_remove(struct undi_device *undi)
Remove UNDI device.
Definition: undinet.c:1035
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:338
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
int undi_unload(struct undi_device *undi)
Unload a pixie.
Definition: undiload.c:161
An UNDI device.
Definition: undi.h:22
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:348
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References free, NULL, pci_get_drvdata(), pci_set_drvdata(), undi_unload(), and undinet_remove().

Variable Documentation

◆ undipci_nics

struct pci_device_id undipci_nics[]
static
Initial value:
= {
PCI_ROM ( 0xffff, 0xffff, "undipci", "UNDI (PCI)", 0 ),
}
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:283

Definition at line 126 of file undi.c.

◆ __pci_driver_fallback

struct pci_driver undipci_driver __pci_driver_fallback
Initial value:
= {
.ids = undipci_nics,
.id_count = ( sizeof ( undipci_nics ) / sizeof ( undipci_nics[0] ) ),
.probe = undipci_probe,
.remove = undipci_remove,
}
#define PCI_CLASS_ID(base, sub, progif)
Construct PCI class ID.
Definition: pci.h:179
static int undipci_probe(struct pci_device *pci)
Probe PCI device.
Definition: undi.c:66
static void undipci_remove(struct pci_device *pci)
Remove PCI device.
Definition: undi.c:117
static struct pci_device_id undipci_nics[]
Definition: undi.c:126
#define PCI_CLASS_NETWORK
Definition: Pci22.h:162
#define PCI_ANY_ID
Match-anything ID.
Definition: pci.h:163

Definition at line 130 of file undi.c.