iPXE
Functions | Variables
skeleton.c File Reference

Skeleton network driver. More...

#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/iobuf.h>
#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include "skeleton.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int skeleton_reset (struct skeleton_nic *skel)
 Reset hardware. More...
 
static void skeleton_check_link (struct net_device *netdev)
 Check link state. More...
 
static int skeleton_open (struct net_device *netdev)
 Open network device. More...
 
static void skeleton_close (struct net_device *netdev)
 Close network device. More...
 
static int skeleton_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void skeleton_poll (struct net_device *netdev)
 Poll for completed and received packets. More...
 
static void skeleton_irq (struct net_device *netdev, int enable)
 Enable or disable interrupts. More...
 
static int skeleton_probe (struct pci_device *pci)
 Probe PCI device. More...
 
static void skeleton_remove (struct pci_device *pci)
 Remove PCI device. More...
 

Variables

static struct net_device_operations skeleton_operations
 Skeleton network device operations. More...
 
static struct pci_device_id skeleton_nics []
 Skeleton PCI device IDs. More...
 
struct pci_driver skeleton_driver __pci_driver
 Skeleton PCI driver. More...
 

Detailed Description

Skeleton network driver.

Definition in file skeleton.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ skeleton_reset()

static int skeleton_reset ( struct skeleton_nic skel)
static

Reset hardware.

Parameters
skelSkeleton device
Return values
rcReturn status code

Definition at line 58 of file skeleton.c.

58  {
59 
60  DBGC ( skel, "SKELETON %p does not yet support reset\n", skel );
61  return -ENOTSUP;
62 }
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:589

References DBGC, and ENOTSUP.

Referenced by skeleton_probe(), and skeleton_remove().

◆ skeleton_check_link()

static void skeleton_check_link ( struct net_device netdev)
static

Check link state.

Parameters
netdevNetwork device

Definition at line 76 of file skeleton.c.

76  {
77  struct skeleton_nic *skel = netdev->priv;
78 
79  DBGC ( skel, "SKELETON %p does not yet support link state\n", skel );
81 }
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
A skeleton network card.
Definition: skeleton.h:16
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
Definition: netdevice.c:207

References DBGC, ENOTSUP, netdev, netdev_link_err(), and net_device::priv.

Referenced by skeleton_probe().

◆ skeleton_open()

static int skeleton_open ( struct net_device netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 96 of file skeleton.c.

96  {
97  struct skeleton_nic *skel = netdev->priv;
98 
99  DBGC ( skel, "SKELETON %p does not yet support open\n", skel );
100  return -ENOTSUP;
101 }
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
A skeleton network card.
Definition: skeleton.h:16
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52

References DBGC, ENOTSUP, netdev, and net_device::priv.

◆ skeleton_close()

static void skeleton_close ( struct net_device netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 108 of file skeleton.c.

108  {
109  struct skeleton_nic *skel = netdev->priv;
110 
111  DBGC ( skel, "SKELETON %p does not yet support close\n", skel );
112 }
#define DBGC(...)
Definition: compiler.h:505
A skeleton network card.
Definition: skeleton.h:16
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52

References DBGC, netdev, and net_device::priv.

◆ skeleton_transmit()

static int skeleton_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 121 of file skeleton.c.

122  {
123  struct skeleton_nic *skel = netdev->priv;
124 
125  DBGC ( skel, "SKELETON %p does not yet support transmit\n", skel );
126  ( void ) iobuf;
127  return -ENOTSUP;
128 }
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
A skeleton network card.
Definition: skeleton.h:16
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52

References DBGC, ENOTSUP, netdev, and net_device::priv.

◆ skeleton_poll()

static void skeleton_poll ( struct net_device netdev)
static

Poll for completed and received packets.

Parameters
netdevNetwork device

Definition at line 135 of file skeleton.c.

135  {
136  struct skeleton_nic *skel = netdev->priv;
137 
138  /* Not yet implemented */
139  ( void ) skel;
140 }
A skeleton network card.
Definition: skeleton.h:16
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52

References netdev, and net_device::priv.

◆ skeleton_irq()

static void skeleton_irq ( struct net_device netdev,
int  enable 
)
static

Enable or disable interrupts.

Parameters
netdevNetwork device
enableInterrupts should be enabled

Definition at line 148 of file skeleton.c.

148  {
149  struct skeleton_nic *skel = netdev->priv;
150 
151  DBGC ( skel, "SKELETON %p does not yet support interrupts\n", skel );
152  ( void ) enable;
153 }
#define DBGC(...)
Definition: compiler.h:505
A skeleton network card.
Definition: skeleton.h:16
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52

References DBGC, netdev, and net_device::priv.

◆ skeleton_probe()

static int skeleton_probe ( struct pci_device pci)
static

Probe PCI device.

Parameters
pciPCI device
Return values
rcReturn status code

Definition at line 177 of file skeleton.c.

177  {
178  struct net_device *netdev;
179  struct skeleton_nic *skel;
180  int rc;
181 
182  /* Allocate and initialise net device */
183  netdev = alloc_etherdev ( sizeof ( *skel ) );
184  if ( ! netdev ) {
185  rc = -ENOMEM;
186  goto err_alloc;
187  }
189  skel = netdev->priv;
190  pci_set_drvdata ( pci, netdev );
191  netdev->dev = &pci->dev;
192  memset ( skel, 0, sizeof ( *skel ) );
193 
194  /* Fix up PCI device */
195  adjust_pci_device ( pci );
196 
197  /* Map registers */
198  skel->regs = pci_ioremap ( pci, pci->membase, SKELETON_BAR_SIZE );
199  if ( ! skel->regs ) {
200  rc = -ENODEV;
201  goto err_ioremap;
202  }
203 
204  /* Reset the NIC */
205  if ( ( rc = skeleton_reset ( skel ) ) != 0 )
206  goto err_reset;
207 
208  /* Register network device */
209  if ( ( rc = register_netdev ( netdev ) ) != 0 )
210  goto err_register_netdev;
211 
212  /* Set initial link state */
214 
215  return 0;
216 
218  err_register_netdev:
219  skeleton_reset ( skel );
220  err_reset:
221  iounmap ( skel->regs );
222  err_ioremap:
224  netdev_put ( netdev );
225  err_alloc:
226  return rc;
227 }
unsigned long membase
Memory base.
Definition: pci.h:215
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:154
#define SKELETON_BAR_SIZE
Skeleton BAR size.
Definition: skeleton.h:13
struct device dev
Generic device.
Definition: pci.h:208
A skeleton network card.
Definition: skeleton.h:16
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:515
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:359
#define ENOMEM
Not enough space.
Definition: errno.h:534
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
void * priv
Driver private data.
Definition: netdevice.h:431
static void skeleton_check_link(struct net_device *netdev)
Check link state.
Definition: skeleton.c:76
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:759
A network device.
Definition: netdevice.h:352
#define ENODEV
No such device.
Definition: errno.h:509
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
static struct net_device_operations skeleton_operations
Skeleton network device operations.
Definition: skeleton.c:156
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
static int skeleton_reset(struct skeleton_nic *skel)
Reset hardware.
Definition: skeleton.c:58
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
void iounmap(volatile const void *io_addr)
Unmap I/O address.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
void * regs
Registers.
Definition: skeleton.h:18
void * memset(void *dest, int character, size_t len) __nonnull

References adjust_pci_device(), alloc_etherdev(), pci_device::dev, net_device::dev, ENODEV, ENOMEM, iounmap(), pci_device::membase, memset(), netdev, netdev_init(), netdev_nullify(), netdev_put(), pci_ioremap(), pci_set_drvdata(), net_device::priv, rc, register_netdev(), skeleton_nic::regs, SKELETON_BAR_SIZE, skeleton_check_link(), skeleton_operations, skeleton_reset(), and unregister_netdev().

◆ skeleton_remove()

static void skeleton_remove ( struct pci_device pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 234 of file skeleton.c.

234  {
235  struct net_device *netdev = pci_get_drvdata ( pci );
236  struct skeleton_nic *skel = netdev->priv;
237 
238  /* Unregister network device */
240 
241  /* Reset card */
242  skeleton_reset ( skel );
243 
244  /* Free network device */
245  iounmap ( skel->regs );
247  netdev_put ( netdev );
248 }
A skeleton network card.
Definition: skeleton.h:16
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
A network device.
Definition: netdevice.h:352
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:369
static int skeleton_reset(struct skeleton_nic *skel)
Reset hardware.
Definition: skeleton.c:58
void iounmap(volatile const void *io_addr)
Unmap I/O address.
void * regs
Registers.
Definition: skeleton.h:18

References iounmap(), netdev, netdev_nullify(), netdev_put(), pci_get_drvdata(), net_device::priv, skeleton_nic::regs, skeleton_reset(), and unregister_netdev().

Variable Documentation

◆ skeleton_operations

struct net_device_operations skeleton_operations
static
Initial value:
= {
.open = skeleton_open,
.close = skeleton_close,
.transmit = skeleton_transmit,
.poll = skeleton_poll,
.irq = skeleton_irq,
}
static void skeleton_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: skeleton.c:135
static int skeleton_open(struct net_device *netdev)
Open network device.
Definition: skeleton.c:96
static void skeleton_close(struct net_device *netdev)
Close network device.
Definition: skeleton.c:108
static void skeleton_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition: skeleton.c:148
static int skeleton_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: skeleton.c:121

Skeleton network device operations.

Definition at line 156 of file skeleton.c.

Referenced by skeleton_probe().

◆ skeleton_nics

struct pci_device_id skeleton_nics[]
static
Initial value:
= {
PCI_ROM ( 0x5ce1, 0x5ce1, "skel", "Skeleton", 0 ),
}
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:303

Skeleton PCI device IDs.

Definition at line 251 of file skeleton.c.

◆ __pci_driver

struct pci_driver skeleton_driver __pci_driver
Initial value:
= {
.ids = skeleton_nics,
.id_count = ( sizeof ( skeleton_nics ) / sizeof ( skeleton_nics[0] ) ),
.probe = skeleton_probe,
}
static void skeleton_remove(struct pci_device *pci)
Remove PCI device.
Definition: skeleton.c:234
static struct pci_device_id skeleton_nics[]
Skeleton PCI device IDs.
Definition: skeleton.c:251
static int skeleton_probe(struct pci_device *pci)
Probe PCI device.
Definition: skeleton.c:177
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39

Skeleton PCI driver.

Definition at line 256 of file skeleton.c.