iPXE
efx_common.c
Go to the documentation of this file.
1/**************************************************************************
2 *
3 * Driver datapath common code for Solarflare network cards
4 *
5 * Written by Shradha Shah, maintained by <pre-boot-drivers@xilinx.com>
6 *
7 * Copyright Fen Systems Ltd. 2005
8 * Copyright Level 5 Networks Inc. 2005
9 * Copyright 2006-2019 Solarflare Communications Inc.
10 * Copyright 2019-2020 Xilinx Inc.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or any later version.
16 *
17 * You can also choose to distribute this program under the terms of
18 * the Unmodified Binary Distribution Licence (as given in the file
19 * COPYING.UBDL), provided that you have satisfied its requirements.
20 *
21 ***************************************************************************/
22#include <stdint.h>
23#include <stdlib.h>
24#include <stdio.h>
25#include <unistd.h>
26#include <errno.h>
27#include <assert.h>
28#include <byteswap.h>
29#include <ipxe/io.h>
30#include <ipxe/pci.h>
31#include <ipxe/malloc.h>
32#include <ipxe/iobuf.h>
33#include <ipxe/netdevice.h>
34#include "efx_common.h"
35#include "efx_bitfield.h"
36#include "mc_driver_pcol.h"
37
38FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
39
40/*******************************************************************************
41 *
42 *
43 * Low-level hardware access
44 *
45 *
46 ******************************************************************************/
47
48void
49efx_writel(struct efx_nic *efx, efx_dword_t *value, unsigned int reg)
50{
51 DBGCIO(efx, "Writing partial register %x with " EFX_DWORD_FMT "\n",
53 _efx_writel(efx, value->u32[0], reg);
54}
55
56void
57efx_readl(struct efx_nic *efx, efx_dword_t *value, unsigned int reg)
58{
59 value->u32[0] = _efx_readl(efx, reg);
60 DBGCIO(efx, "Read from register %x, got " EFX_DWORD_FMT "\n",
62}
63
64/*******************************************************************************
65 *
66 *
67 * Inititialization and Close
68 *
69 *
70 ******************************************************************************/
72{
73 struct efx_nic *efx = netdev->priv;
74 struct pci_device *pci = container_of(netdev->dev,
75 struct pci_device, dev);
76 unsigned int reg = PCI_BASE_ADDRESS_0;
77 uint32_t bar_low;
78
79 efx->netdev = netdev;
80 efx->revision = revision;
81
82 /* Find the memory bar to use */
83 pci_read_config_dword(pci, reg, &bar_low);
86
87 efx->mmio_start = pci_bar_start(pci, reg);
88 efx->mmio_len = pci_bar_size(pci, reg);
89 efx->membase = pci_ioremap(pci, efx->mmio_start, efx->mmio_len);
90
91 DBGCP(efx, "BAR of %lx bytes at phys %lx mapped at %p\n",
92 efx->mmio_len, efx->mmio_start, efx->membase);
93
94 /* Enable PCI access */
96}
97
99{
100 struct efx_nic *efx = netdev->priv;
101
102 iounmap(efx->membase);
103 efx->membase = NULL;
104}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
pseudo_bit_t value[0x00020]
Definition arbel.h:2
unsigned int uint32_t
Definition stdint.h:12
Assertions.
Efx bitfield access.
#define EFX_DWORD_VAL(dword)
union efx_dword efx_dword_t
A doubleword (4 byte) datatype - little-endian in HW.
#define EFX_DWORD_FMT
void efx_remove(struct net_device *netdev)
Definition efx_common.c:98
void efx_probe(struct net_device *netdev, enum efx_revision revision)
Definition efx_common.c:71
void efx_writel(struct efx_nic *efx, efx_dword_t *value, unsigned int reg)
Definition efx_common.c:49
void efx_readl(struct efx_nic *efx, efx_dword_t *value, unsigned int reg)
Definition efx_common.c:57
static void _efx_writel(struct efx_nic *efx, uint32_t value, unsigned int reg)
Definition efx_common.h:205
static uint32_t _efx_readl(struct efx_nic *efx, unsigned int reg)
Definition efx_common.h:211
efx_revision
Definition efx_common.h:142
Error codes.
static struct net_device * netdev
Definition gdbudp.c:53
#define DBGCP(...)
Definition compiler.h:539
#define DBGCIO(...)
Definition compiler.h:556
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
uint32_t revision
Entry point revision.
Definition ib_mad.h:9
iPXE I/O API
void iounmap(volatile const void *io_addr)
Unmap I/O address.
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
I/O buffers.
Dynamic memory allocation.
This file is a subset of the MCDI headers generated from the yml files.
static unsigned int unsigned int reg
Definition myson.h:162
Network device management.
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Get the size of a PCI BAR.
Definition pci.c:164
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition pci.c:241
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition pci.c:97
PCI bus.
#define PCI_BASE_ADDRESS_SPACE_IO
I/O BAR.
Definition pci.h:69
#define PCI_BASE_ADDRESS_2
Definition pci.h:65
#define PCI_BASE_ADDRESS_0
Definition pci.h:63
#define PCI_BASE_ADDRESS_IO_MASK
I/O BAR mask.
Definition pci.h:70
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
Hardware access.
Definition efx_common.h:147
struct net_device * netdev
Definition efx_common.h:148
unsigned long mmio_start
Definition efx_common.h:157
unsigned long mmio_len
Definition efx_common.h:158
enum efx_revision revision
Definition efx_common.h:149
void * membase
Memory and IO base.
Definition efx_common.h:156
A network device.
Definition netdevice.h:353
A PCI device.
Definition pci.h:211
struct device dev
Generic device.
Definition pci.h:213