summaryrefslogtreecommitdiffstats
path: root/src/drivers/net/sfc/efx_common.c
blob: 79a994355d02b6524db7ce60ab99348796d26b24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**************************************************************************
 *
 * Driver datapath common code for Solarflare network cards
 *
 * Written by Shradha Shah <sshah@solarflare.com>
 *
 * Copyright Fen Systems Ltd. 2005
 * Copyright Level 5 Networks Inc. 2005
 * Copyright 2006-2017 Solarflare Communications Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or any later version.
 *
 * You can also choose to distribute this program under the terms of
 * the Unmodified Binary Distribution Licence (as given in the file
 * COPYING.UBDL), provided that you have satisfied its requirements.
 *
 ***************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <byteswap.h>
#include <ipxe/io.h>
#include <ipxe/pci.h>
#include <ipxe/malloc.h>
#include <ipxe/iobuf.h>
#include <ipxe/netdevice.h>
#include "efx_common.h"
#include "efx_bitfield.h"
#include "mc_driver_pcol.h"

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

/*******************************************************************************
 *
 *
 * Low-level hardware access
 *
 *
 ******************************************************************************/

void
efx_writel(struct efx_nic *efx, efx_dword_t *value, unsigned int reg)
{
	DBGCIO(efx, "Writing partial register %x with " EFX_DWORD_FMT "\n",
	       reg, EFX_DWORD_VAL(*value));
	_efx_writel(efx, value->u32[0], reg);
}

void
efx_readl(struct efx_nic *efx, efx_dword_t *value, unsigned int reg)
{
	value->u32[0] = _efx_readl(efx, reg);
	DBGCIO(efx, "Read from register %x, got " EFX_DWORD_FMT "\n",
	       reg, EFX_DWORD_VAL(*value));
}

/*******************************************************************************
 *
 *
 * Inititialization and Close
 *
 *
 ******************************************************************************/
void efx_probe(struct net_device *netdev, enum efx_revision revision)
{
	struct efx_nic *efx = netdev_priv(netdev);
	struct pci_device *pci = container_of(netdev->dev,
					      struct pci_device, dev);

	efx->netdev = netdev;
	efx->revision = revision;

	/* MMIO bar */
	efx->mmio_start = pci_bar_start(pci, PCI_BASE_ADDRESS_2);
	efx->mmio_len = pci_bar_size(pci, PCI_BASE_ADDRESS_2);
	efx->membase = ioremap(efx->mmio_start, efx->mmio_len);

	DBGCP(efx, "BAR of %lx bytes at phys %lx mapped at %p\n",
	      efx->mmio_len, efx->mmio_start, efx->membase);

	/* Enable PCI access */
	adjust_pci_device(pci);
}

void efx_remove(struct net_device *netdev)
{
	struct efx_nic *efx = netdev_priv(netdev);

	iounmap(efx->membase);
	efx->membase = NULL;
}