iPXE
efx_common.h
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * GPL common net driver for Solarflare network cards
4  *
5  * Written by Michael Brown <mbrown@fensystems.co.uk>
6  *
7  * Copyright Fen Systems Ltd. 2005
8  * Copyright Level 5 Networks Inc. 2005
9  * Copyright Solarflare Communications Inc. 2013-2017
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of the
14  * License, or any later version.
15  *
16  * You can also choose to distribute this program under the terms of
17  * the Unmodified Binary Distribution Licence (as given in the file
18  * COPYING.UBDL), provided that you have satisfied its requirements.
19  *
20  ***************************************************************************/
21 #ifndef EFX_COMMON_H
22 #define EFX_COMMON_H
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #define __packed __attribute__((__packed__))
27 #define __force /*nothing*/
28 
29 typedef uint16_t __le16;
30 typedef uint32_t __le32;
31 typedef uint64_t __le64;
32 
33 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct{int: -!!(e); }))
34 #define BUILD_BUG_ON(e) ((void)BUILD_BUG_ON_ZERO(e))
35 
36 #include <stdbool.h>
37 #include <ipxe/io.h>
38 #include <ipxe/netdevice.h>
39 #include "efx_bitfield.h"
40 #include "mcdi.h"
41 
42 #ifndef ARRAY_SIZE
43 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
44 #endif
45 
46 /**************************************************************************
47  *
48  * Hardware data structures and sizing
49  *
50  ***************************************************************************/
54 
55 #define EFX_BUF_ALIGN 4096
56 #define EFX_RXD_SIZE 512
57 #define EFX_RXD_MASK (EFX_RXD_SIZE - 1)
58 #define EFX_TXD_SIZE 512
59 #define EFX_TXD_MASK (EFX_TXD_SIZE - 1)
60 #define EFX_EVQ_SIZE 512
61 #define EFX_EVQ_MASK (EFX_EVQ_SIZE - 1)
62 
63 /* There is space for 512 rx descriptors available. This number can be
64  * anything between 1 and 512 in powers of 2. This value will affect the
65  * network performance. During a test we were able to push 239 descriptors
66  * before we ran out of space.
67  */
68 #define EFX_NUM_RX_DESC 64
69 #define EFX_NUM_RX_DESC_MASK (EFX_NUM_RX_DESC - 1)
70 
71 /* The packet size is usually 1500 bytes hence we choose 1600 as the buf size,
72  * which is (1500+metadata)
73  */
74 #define EFX_RX_BUF_SIZE 1600
75 
76 /* Settings for the state field in efx_nic.
77  */
78 #define EFX_STATE_POLLING 1
79 
80 typedef unsigned long long dma_addr_t;
81 
82 /** A buffer table allocation backing a tx dma, rx dma or eventq */
85  int id;
86 };
87 
88 /** A transmit queue */
89 struct efx_tx_queue {
90  /* The hardware ring */
92 
93  /* The software ring storing io_buffers. */
95 
96  /* The buffer table reservation pushed to hardware */
98 
99  /* Software descriptor write ptr */
100  unsigned int write_ptr;
101 
102  /* Hardware descriptor read ptr */
103  unsigned int read_ptr;
104 };
105 
106 /** A receive queue */
107 struct efx_rx_queue {
108  /* The hardware ring */
110 
111  /* The software ring storing io_buffers */
113 
114  /* The buffer table reservation pushed to hardware */
116 
117  /* Descriptor write ptr, into both the hardware and software rings */
118  unsigned int write_ptr;
119 
120  /* Hardware completion ptr */
121  unsigned int read_ptr;
122 
123  /* The value of RX_CONT in the previous RX event */
124  unsigned int rx_cont_prev;
125 };
126 
127 /** An event queue */
128 struct efx_ev_queue {
129  /* The hardware ring to push to hardware.
130  * Must be the first entry in the structure.
131  */
133 
134  /* The buffer table reservation pushed to hardware */
136 
137  /* Pointers into the ring */
138  unsigned int read_ptr;
139 };
140 
141 /* Hardware revisions */
144 };
145 
146 /** Hardware access */
147 struct efx_nic {
150  const struct efx_nic_type *type;
151 
152  int port;
154 
155  /** Memory and IO base */
156  void *membase;
157  unsigned long mmio_start;
158  unsigned long mmio_len;
159 
160  /* Buffer table allocation head */
162 
163  /* Queues */
167 
168  unsigned int rx_prefix_size;
169 
170  /** INT_REG_KER */
171  int int_en;
173 
174  /* Set to true if firmware supports the workaround for bug35388 */
176 
177 };
178 
179 
180 /** Efx device type definition */
181 struct efx_nic_type {
182  int (*mcdi_rpc)(struct efx_nic *efx, unsigned int cmd,
183  const efx_dword_t *inbuf, size_t inlen,
184  efx_dword_t *outbuf, size_t outlen,
185  size_t *outlen_actual, bool quiet);
186 };
187 
188 extern const struct efx_nic_type hunt_nic_type;
189 
190 #define EFX_MAC_FRAME_LEN(_mtu) \
191  (((_mtu) \
192  + /* EtherII already included */ \
193  + 4 /* FCS */ \
194  /* No VLAN supported */ \
195  + 16 /* bug16772 */ \
196  + 7) & ~7)
197 
198 /*******************************************************************************
199  *
200  *
201  * Hardware API
202  *
203  *
204  ******************************************************************************/
205 static inline void _efx_writel(struct efx_nic *efx, uint32_t value,
206  unsigned int reg)
207 {
208  writel((value), (efx)->membase + (reg));
209 }
210 
211 static inline uint32_t _efx_readl(struct efx_nic *efx, unsigned int reg)
212 {
213  return readl((efx)->membase + (reg));
214 }
215 
216 #define efx_writel_table(efx, value, index, reg) \
217  efx_writel(efx, value, (reg) + ((index) * reg##_STEP))
218 
219 #define efx_writel_page(efx, value, index, reg) \
220  efx_writel(efx, value, (reg) + ((index) * 0x2000))
221 
222 /* Hardware access */
223 extern void efx_writel(struct efx_nic *efx, efx_dword_t *value,
224  unsigned int reg);
225 extern void efx_readl(struct efx_nic *efx, efx_dword_t *value,
226  unsigned int reg);
227 
228 /* Initialisation */
229 extern void efx_probe(struct net_device *netdev, enum efx_revision rev);
230 extern void efx_remove(struct net_device *netdev);
231 
232 #endif /* EFX_COMMON_H */
int port
Definition: efx_common.h:152
iPXE I/O API
uint32_t __le32
Definition: efx_common.h:30
unsigned short uint16_t
Definition: stdint.h:11
void efx_readl(struct efx_nic *efx, efx_dword_t *value, unsigned int reg)
Definition: efx_common.c:56
struct efx_special_buffer entry
Definition: efx_common.h:115
dma_addr_t dma_addr
Definition: efx_common.h:84
Hardware access.
Definition: efx_common.h:147
A transmit queue.
Definition: efx_common.h:89
A receive queue.
Definition: efx_common.h:107
unsigned int read_ptr
Definition: efx_common.h:121
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
void efx_probe(struct net_device *netdev, enum efx_revision rev)
Definition: efx_common.c:70
efx_rx_desc_t * ring
Definition: efx_common.h:109
bool workaround_35388
Definition: efx_common.h:175
unsigned long long uint64_t
Definition: stdint.h:13
unsigned long dma_addr_t
Definition: bnx2.h:20
__be32 outlen
Definition: CIB_PRM.h:41
static void _efx_writel(struct efx_nic *efx, uint32_t value, unsigned int reg)
Definition: efx_common.h:205
unsigned int rx_cont_prev
Definition: efx_common.h:124
A doubleword (4 byte) datatype - little-endian in HW.
Definition: efx_bitfield.h:87
unsigned long mmio_len
Definition: efx_common.h:158
int buffer_head
Definition: efx_common.h:161
u32 state
Definition: efx_common.h:153
efx_oword_t int_ker __aligned
Definition: efx_common.h:172
const struct efx_nic_type hunt_nic_type
Definition: sfc_hunt.c:1312
A buffer table allocation backing a tx dma, rx dma or eventq.
Definition: efx_common.h:83
int int_en
INT_REG_KER.
Definition: efx_common.h:171
efx_tx_desc_t * ring
Definition: efx_common.h:91
efx_revision
Definition: efx_common.h:142
int(* mcdi_rpc)(struct efx_nic *efx, unsigned int cmd, const efx_dword_t *inbuf, size_t inlen, efx_dword_t *outbuf, size_t outlen, size_t *outlen_actual, bool quiet)
Definition: efx_common.h:182
Efx bitfield access.
unsigned long long dma_addr_t
Definition: efx_common.h:80
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static struct net_device * netdev
Definition: gdbudp.c:52
efx_qword_t efx_tx_desc_t
Definition: efx_common.h:52
#define EFX_NUM_RX_DESC
Definition: efx_common.h:68
struct efx_special_buffer entry
Definition: efx_common.h:135
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
void efx_writel(struct efx_nic *efx, efx_dword_t *value, unsigned int reg)
Definition: efx_common.c:48
unsigned int read_ptr
Definition: efx_common.h:103
unsigned int write_ptr
Definition: efx_common.h:100
static unsigned int unsigned int reg
Definition: intel.h:245
A network device.
Definition: netdevice.h:348
const struct efx_nic_type * type
Definition: efx_common.h:150
enum efx_revision revision
Definition: efx_common.h:149
unsigned int uint32_t
Definition: stdint.h:12
struct efx_rx_queue rxq
Definition: efx_common.h:164
unsigned int rx_prefix_size
Definition: efx_common.h:168
efx_qword_t efx_rx_desc_t
Definition: efx_common.h:51
efx_qword_t efx_event_t
Definition: efx_common.h:53
void * membase
Memory and IO base.
Definition: efx_common.h:156
efx_event_t * ring
Definition: efx_common.h:132
Network device management.
unsigned long mmio_start
Definition: efx_common.h:157
struct efx_ev_queue evq
Definition: efx_common.h:166
struct efx_tx_queue txq
Definition: efx_common.h:165
struct io_buffer * buf[EFX_TXD_SIZE]
Definition: efx_common.h:94
#define EFX_TXD_SIZE
Definition: efx_common.h:58
void efx_remove(struct net_device *netdev)
Definition: efx_common.c:97
An octword (eight-word, so 16 byte) datatype - little-endian in HW.
Definition: efx_bitfield.h:99
struct io_buffer * buf[EFX_NUM_RX_DESC]
Definition: efx_common.h:112
Efx device type definition.
Definition: efx_common.h:181
unsigned int write_ptr
Definition: efx_common.h:118
An event queue.
Definition: efx_common.h:128
struct efx_special_buffer entry
Definition: efx_common.h:97
__be32 inlen
Definition: CIB_PRM.h:30
unsigned int read_ptr
Definition: efx_common.h:138
static uint32_t _efx_readl(struct efx_nic *efx, unsigned int reg)
Definition: efx_common.h:211
uint64_t __le64
Definition: efx_common.h:31
uint16_t __le16
Definition: efx_common.h:29
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29
A quadword (8 byte) datatype - little-endian in HW.
Definition: efx_bitfield.h:92
struct net_device * netdev
Definition: efx_common.h:148
uint32_t u32
Definition: stdint.h:23
A persistent I/O buffer.
Definition: iobuf.h:32
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)