iPXE
Functions | Variables
ena.c File Reference

Amazon ENA 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 "ena.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static const char * ena_direction (unsigned int direction)
 Get direction name (for debugging) More...
 
static int ena_reset_wait (struct ena_nic *ena, uint32_t expected)
 Wait for reset operation to be acknowledged. More...
 
static int ena_reset (struct ena_nic *ena)
 Reset hardware. More...
 
static void ena_set_base (struct ena_nic *ena, unsigned int offset, void *base)
 Set queue base address. More...
 
static void ena_set_caps (struct ena_nic *ena, unsigned int offset, unsigned int count, size_t size)
 Set queue capabilities. More...
 
static void ena_clear_caps (struct ena_nic *ena, unsigned int offset)
 Clear queue capabilities. More...
 
static int ena_create_admin (struct ena_nic *ena)
 Create admin queues. More...
 
static void ena_destroy_admin (struct ena_nic *ena)
 Destroy admin queues. More...
 
static union ena_aq_reqena_admin_req (struct ena_nic *ena)
 Get next available admin queue request. More...
 
static int ena_admin (struct ena_nic *ena, union ena_aq_req *req, union ena_acq_rsp **rsp)
 Issue admin queue request. More...
 
static int ena_create_sq (struct ena_nic *ena, struct ena_sq *sq, struct ena_cq *cq)
 Create submission queue. More...
 
static int ena_destroy_sq (struct ena_nic *ena, struct ena_sq *sq)
 Destroy submission queue. More...
 
static int ena_create_cq (struct ena_nic *ena, struct ena_cq *cq)
 Create completion queue. More...
 
static int ena_destroy_cq (struct ena_nic *ena, struct ena_cq *cq)
 Destroy completion queue. More...
 
static int ena_create_qp (struct ena_nic *ena, struct ena_qp *qp)
 Create queue pair. More...
 
static int ena_destroy_qp (struct ena_nic *ena, struct ena_qp *qp)
 Destroy queue pair. More...
 
static int ena_get_device_attributes (struct net_device *netdev)
 Get device attributes. More...
 
static int ena_get_stats (struct ena_nic *ena)
 Get statistics (for debugging) More...
 
static void ena_refill_rx (struct net_device *netdev)
 Refill receive queue. More...
 
static void ena_empty_rx (struct ena_nic *ena)
 Discard unused receive I/O buffers. More...
 
static int ena_open (struct net_device *netdev)
 Open network device. More...
 
static void ena_close (struct net_device *netdev)
 Close network device. More...
 
static int ena_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void ena_poll_tx (struct net_device *netdev)
 Poll for completed transmissions. More...
 
static void ena_poll_rx (struct net_device *netdev)
 Poll for received packets. More...
 
static void ena_poll (struct net_device *netdev)
 Poll for completed and received packets. More...
 
static int ena_probe (struct pci_device *pci)
 Probe PCI device. More...
 
static void ena_remove (struct pci_device *pci)
 Remove PCI device. More...
 

Variables

static struct net_device_operations ena_operations
 ENA network device operations. More...
 
static struct pci_device_id ena_nics []
 ENA PCI device IDs. More...
 
struct pci_driver ena_driver __pci_driver
 ENA PCI driver. More...
 

Detailed Description

Amazon ENA network driver.

Definition in file ena.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ena_direction()

static const char* ena_direction ( unsigned int  direction)
static

Get direction name (for debugging)

Parameters
directionDirection
Return values
nameDirection name

Definition at line 51 of file ena.c.

51  {
52 
53  switch ( direction ) {
54  case ENA_SQ_TX: return "TX";
55  case ENA_SQ_RX: return "RX";
56  default: return "<UNKNOWN>";
57  }
58 }
uint8_t direction
Direction.
Definition: ena.h:14
Transmit.
Definition: ena.h:139
Receive.
Definition: ena.h:141

References direction, ENA_SQ_RX, and ENA_SQ_TX.

Referenced by ena_create_sq(), and ena_destroy_sq().

◆ ena_reset_wait()

static int ena_reset_wait ( struct ena_nic ena,
uint32_t  expected 
)
static

Wait for reset operation to be acknowledged.

Parameters
enaENA device
expectedExpected reset state
Return values
rcReturn status code

Definition at line 74 of file ena.c.

74  {
75  uint32_t stat;
76  unsigned int i;
77 
78  /* Wait for reset to complete */
79  for ( i = 0 ; i < ENA_RESET_MAX_WAIT_MS ; i++ ) {
80 
81  /* Check if device is ready */
82  stat = readl ( ena->regs + ENA_STAT );
83  if ( ( stat & ENA_STAT_RESET ) == expected )
84  return 0;
85 
86  /* Delay */
87  mdelay ( 1 );
88  }
89 
90  DBGC ( ena, "ENA %p timed out waiting for reset status %#08x "
91  "(got %#08x)\n", ena, expected, stat );
92  return -ETIMEDOUT;
93 }
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
void * regs
Registers.
Definition: ena.h:575
#define ENA_STAT_RESET
Reset in progress.
Definition: ena.h:69
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define ENA_RESET_MAX_WAIT_MS
Maximum time to wait for reset.
Definition: ena.h:65
#define ENA_STAT
Device status register.
Definition: ena.h:68
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

References DBGC, ENA_RESET_MAX_WAIT_MS, ENA_STAT, ENA_STAT_RESET, ETIMEDOUT, mdelay(), readl(), and ena_nic::regs.

Referenced by ena_reset().

◆ ena_reset()

static int ena_reset ( struct ena_nic ena)
static

Reset hardware.

Parameters
enaENA device
Return values
rcReturn status code

Definition at line 101 of file ena.c.

101  {
102  int rc;
103 
104  /* Trigger reset */
105  writel ( ENA_CTRL_RESET, ( ena->regs + ENA_CTRL ) );
106 
107  /* Wait for reset to take effect */
108  if ( ( rc = ena_reset_wait ( ena, ENA_STAT_RESET ) ) != 0 )
109  return rc;
110 
111  /* Clear reset */
112  writel ( 0, ( ena->regs + ENA_CTRL ) );
113 
114  /* Wait for reset to clear */
115  if ( ( rc = ena_reset_wait ( ena, 0 ) ) != 0 )
116  return rc;
117 
118  return 0;
119 }
#define ENA_CTRL
Device control register.
Definition: ena.h:61
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define ENA_CTRL_RESET
Reset.
Definition: ena.h:62
void * regs
Registers.
Definition: ena.h:575
static int ena_reset_wait(struct ena_nic *ena, uint32_t expected)
Wait for reset operation to be acknowledged.
Definition: ena.c:74
#define ENA_STAT_RESET
Reset in progress.
Definition: ena.h:69
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.

References ENA_CTRL, ENA_CTRL_RESET, ena_reset_wait(), ENA_STAT_RESET, rc, ena_nic::regs, and writel().

Referenced by ena_probe(), and ena_remove().

◆ ena_set_base()

static void ena_set_base ( struct ena_nic ena,
unsigned int  offset,
void *  base 
)
inlinestatic

Set queue base address.

Parameters
enaENA device
offsetRegister offset
addressBase address

Definition at line 135 of file ena.c.

136  {
138 
139  /* Program base address registers */
140  writel ( ( phys & 0xffffffffUL ),
141  ( ena->regs + offset + ENA_BASE_LO ) );
142  if ( sizeof ( phys ) > sizeof ( uint32_t ) ) {
143  writel ( ( ( ( uint64_t ) phys ) >> 32 ),
144  ( ena->regs + offset + ENA_BASE_HI ) );
145  } else {
146  writel ( 0, ( ena->regs + offset + ENA_BASE_HI ) );
147  }
148 }
#define ENA_BASE_HI
Base address high register offset.
Definition: ena.h:37
unsigned long long uint64_t
Definition: stdint.h:13
void * regs
Registers.
Definition: ena.h:575
static signed char phys[4]
Definition: epic100.c:88
#define ENA_BASE_LO
Base address low register offset.
Definition: ena.h:34
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
unsigned int uint32_t
Definition: stdint.h:12
uint16_t base
Base address.
Definition: edd.h:14
unsigned long physaddr_t
Definition: stdint.h:20

References base, ENA_BASE_HI, ENA_BASE_LO, offset, phys, ena_nic::regs, virt_to_bus(), and writel().

Referenced by ena_create_admin().

◆ ena_set_caps()

static void ena_set_caps ( struct ena_nic ena,
unsigned int  offset,
unsigned int  count,
size_t  size 
)
inlinestatic

Set queue capabilities.

Parameters
enaENA device
offsetRegister offset
countNumber of entries
sizeSize of each entry

Definition at line 159 of file ena.c.

160  {
161 
162  /* Program capabilities register */
163  writel ( ENA_CAPS ( count, size ), ( ena->regs + offset ) );
164 }
void * regs
Registers.
Definition: ena.h:575
#define ENA_CAPS(count, size)
Capability register value.
Definition: ena.h:40
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
uint16_t count
Number of entries.
Definition: ena.h:22
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16

References count, ENA_CAPS, offset, ena_nic::regs, size, and writel().

Referenced by ena_create_admin().

◆ ena_clear_caps()

static void ena_clear_caps ( struct ena_nic ena,
unsigned int  offset 
)
inlinestatic

Clear queue capabilities.

Parameters
enaENA device
offsetRegister offset

Definition at line 173 of file ena.c.

173  {
174 
175  /* Clear capabilities register */
176  writel ( 0, ( ena->regs + offset ) );
177 }
void * regs
Registers.
Definition: ena.h:575
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259

References offset, ena_nic::regs, and writel().

Referenced by ena_create_admin(), and ena_destroy_admin().

◆ ena_create_admin()

static int ena_create_admin ( struct ena_nic ena)
static

Create admin queues.

Parameters
enaENA device
Return values
rcReturn status code

Definition at line 185 of file ena.c.

185  {
186  size_t aq_len = ( ENA_AQ_COUNT * sizeof ( ena->aq.req[0] ) );
187  size_t acq_len = ( ENA_ACQ_COUNT * sizeof ( ena->acq.rsp[0] ) );
188  int rc;
189 
190  /* Allocate admin completion queue */
191  ena->acq.rsp = malloc_phys ( acq_len, acq_len );
192  if ( ! ena->acq.rsp ) {
193  rc = -ENOMEM;
194  goto err_alloc_acq;
195  }
196  memset ( ena->acq.rsp, 0, acq_len );
197 
198  /* Allocate admin queue */
199  ena->aq.req = malloc_phys ( aq_len, aq_len );
200  if ( ! ena->aq.req ) {
201  rc = -ENOMEM;
202  goto err_alloc_aq;
203  }
204  memset ( ena->aq.req, 0, aq_len );
205 
206  /* Program queue addresses and capabilities */
207  ena_set_base ( ena, ENA_ACQ_BASE, ena->acq.rsp );
209  sizeof ( ena->acq.rsp[0] ) );
210  ena_set_base ( ena, ENA_AQ_BASE, ena->aq.req );
212  sizeof ( ena->aq.req[0] ) );
213 
214  DBGC ( ena, "ENA %p AQ [%08lx,%08lx) ACQ [%08lx,%08lx)\n",
215  ena, virt_to_phys ( ena->aq.req ),
216  ( virt_to_phys ( ena->aq.req ) + aq_len ),
217  virt_to_phys ( ena->acq.rsp ),
218  ( virt_to_phys ( ena->acq.rsp ) + acq_len ) );
219  return 0;
220 
221  ena_clear_caps ( ena, ENA_AQ_CAPS );
222  ena_clear_caps ( ena, ENA_ACQ_CAPS );
223  free_phys ( ena->aq.req, aq_len );
224  err_alloc_aq:
225  free_phys ( ena->acq.rsp, acq_len );
226  err_alloc_acq:
227  return rc;
228 }
struct ena_aq aq
Admin queue.
Definition: ena.h:577
#define ENA_ACQ_COUNT
Number of admin completion queue entries.
Definition: ena.h:25
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define ENA_AQ_COUNT
Number of admin queue entries.
Definition: ena.h:22
#define ENA_ACQ_BASE
Admin completion queue base address register.
Definition: ena.h:49
#define DBGC(...)
Definition: compiler.h:505
static void *__malloc malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition: malloc.h:62
#define ENA_AQ_BASE
Admin queue base address register.
Definition: ena.h:43
#define ENA_ACQ_CAPS
Admin completion queue capabilities register.
Definition: ena.h:52
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
#define ENOMEM
Not enough space.
Definition: errno.h:534
static void ena_set_caps(struct ena_nic *ena, unsigned int offset, unsigned int count, size_t size)
Set queue capabilities.
Definition: ena.c:159
union ena_aq_req * req
Requests.
Definition: ena.h:384
#define ENA_AQ_CAPS
Admin queue capabilities register.
Definition: ena.h:46
struct ena_acq acq
Admin completion queue.
Definition: ena.h:579
union ena_acq_rsp * rsp
Responses.
Definition: ena.h:392
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
static void ena_set_base(struct ena_nic *ena, unsigned int offset, void *base)
Set queue base address.
Definition: ena.c:135
static void ena_clear_caps(struct ena_nic *ena, unsigned int offset)
Clear queue capabilities.
Definition: ena.c:173
void * memset(void *dest, int character, size_t len) __nonnull

References ena_nic::acq, ena_nic::aq, DBGC, ENA_ACQ_BASE, ENA_ACQ_CAPS, ENA_ACQ_COUNT, ENA_AQ_BASE, ENA_AQ_CAPS, ENA_AQ_COUNT, ena_clear_caps(), ena_set_base(), ena_set_caps(), ENOMEM, free_phys(), malloc_phys(), memset(), rc, ena_aq::req, ena_acq::rsp, and virt_to_phys().

Referenced by ena_probe().

◆ ena_destroy_admin()

static void ena_destroy_admin ( struct ena_nic ena)
static

Destroy admin queues.

Parameters
enaENA device

Definition at line 235 of file ena.c.

235  {
236  size_t aq_len = ( ENA_AQ_COUNT * sizeof ( ena->aq.req[0] ) );
237  size_t acq_len = ( ENA_ACQ_COUNT * sizeof ( ena->acq.rsp[0] ) );
238 
239  /* Clear queue capabilities */
240  ena_clear_caps ( ena, ENA_AQ_CAPS );
241  ena_clear_caps ( ena, ENA_ACQ_CAPS );
242  wmb();
243 
244  /* Free queues */
245  free_phys ( ena->aq.req, aq_len );
246  free_phys ( ena->acq.rsp, acq_len );
247  DBGC ( ena, "ENA %p AQ and ACQ destroyed\n", ena );
248 }
struct ena_aq aq
Admin queue.
Definition: ena.h:577
#define ENA_ACQ_COUNT
Number of admin completion queue entries.
Definition: ena.h:25
wmb()
#define ENA_AQ_COUNT
Number of admin queue entries.
Definition: ena.h:22
#define DBGC(...)
Definition: compiler.h:505
#define ENA_ACQ_CAPS
Admin completion queue capabilities register.
Definition: ena.h:52
union ena_aq_req * req
Requests.
Definition: ena.h:384
#define ENA_AQ_CAPS
Admin queue capabilities register.
Definition: ena.h:46
struct ena_acq acq
Admin completion queue.
Definition: ena.h:579
union ena_acq_rsp * rsp
Responses.
Definition: ena.h:392
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
static void ena_clear_caps(struct ena_nic *ena, unsigned int offset)
Clear queue capabilities.
Definition: ena.c:173

References ena_nic::acq, ena_nic::aq, DBGC, ENA_ACQ_CAPS, ENA_ACQ_COUNT, ENA_AQ_CAPS, ENA_AQ_COUNT, ena_clear_caps(), free_phys(), ena_aq::req, ena_acq::rsp, and wmb().

Referenced by ena_probe(), and ena_remove().

◆ ena_admin_req()

static union ena_aq_req* ena_admin_req ( struct ena_nic ena)
static

Get next available admin queue request.

Parameters
enaENA device
Return values
reqAdmin queue request

Definition at line 256 of file ena.c.

256  {
257  union ena_aq_req *req;
258  unsigned int index;
259 
260  /* Get next request */
261  index = ( ena->aq.prod % ENA_AQ_COUNT );
262  req = &ena->aq.req[index];
263 
264  /* Initialise request */
265  memset ( ( ( ( void * ) req ) + sizeof ( req->header ) ), 0,
266  ( sizeof ( *req ) - sizeof ( req->header ) ) );
267  req->header.id = ena->aq.prod;
268 
269  /* Increment producer counter */
270  ena->aq.prod++;
271 
272  return req;
273 }
struct ena_aq aq
Admin queue.
Definition: ena.h:577
#define ENA_AQ_COUNT
Number of admin queue entries.
Definition: ena.h:22
union ena_aq_req * req
Requests.
Definition: ena.h:384
Admin queue request.
Definition: ena.h:342
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
unsigned int prod
Producer counter.
Definition: ena.h:386
void * memset(void *dest, int character, size_t len) __nonnull

References ena_nic::aq, ENA_AQ_COUNT, index, memset(), ena_aq::prod, and ena_aq::req.

Referenced by ena_create_cq(), ena_create_sq(), ena_destroy_cq(), ena_destroy_sq(), ena_get_device_attributes(), and ena_get_stats().

◆ ena_admin()

static int ena_admin ( struct ena_nic ena,
union ena_aq_req req,
union ena_acq_rsp **  rsp 
)
static

Issue admin queue request.

Parameters
enaENA device
reqAdmin queue request
rspAdmin queue response to fill in
Return values
rcReturn status code

Definition at line 283 of file ena.c.

284  {
285  unsigned int index;
286  unsigned int i;
287  int rc;
288 
289  /* Locate response */
290  index = ( ena->acq.cons % ENA_ACQ_COUNT );
291  *rsp = &ena->acq.rsp[index];
292 
293  /* Mark request as ready */
294  req->header.flags ^= ENA_AQ_PHASE;
295  wmb();
296  DBGC2 ( ena, "ENA %p admin request %#x:\n",
297  ena, le16_to_cpu ( req->header.id ) );
298  DBGC2_HDA ( ena, virt_to_phys ( req ), req, sizeof ( *req ) );
299 
300  /* Ring doorbell */
301  writel ( ena->aq.prod, ( ena->regs + ENA_AQ_DB ) );
302 
303  /* Wait for response */
304  for ( i = 0 ; i < ENA_ADMIN_MAX_WAIT_MS ; i++ ) {
305 
306  /* Check for response */
307  if ( ( (*rsp)->header.flags ^ ena->acq.phase ) & ENA_ACQ_PHASE){
308  mdelay ( 1 );
309  continue;
310  }
311  DBGC2 ( ena, "ENA %p admin response %#x:\n",
312  ena, le16_to_cpu ( (*rsp)->header.id ) );
313  DBGC2_HDA ( ena, virt_to_phys ( *rsp ), *rsp, sizeof ( **rsp ));
314 
315  /* Increment consumer counter */
316  ena->acq.cons++;
317  if ( ( ena->acq.cons % ENA_ACQ_COUNT ) == 0 )
318  ena->acq.phase ^= ENA_ACQ_PHASE;
319 
320  /* Check command identifier */
321  if ( (*rsp)->header.id != req->header.id ) {
322  DBGC ( ena, "ENA %p admin response %#x mismatch:\n",
323  ena, le16_to_cpu ( (*rsp)->header.id ) );
324  rc = -EILSEQ;
325  goto err;
326  }
327 
328  /* Check status */
329  if ( (*rsp)->header.status != 0 ) {
330  DBGC ( ena, "ENA %p admin response %#x status %d:\n",
331  ena, le16_to_cpu ( (*rsp)->header.id ),
332  (*rsp)->header.status );
333  rc = -EIO;
334  goto err;
335  }
336 
337  /* Success */
338  return 0;
339  }
340 
341  rc = -ETIMEDOUT;
342  DBGC ( ena, "ENA %p timed out waiting for admin request %#x:\n",
343  ena, le16_to_cpu ( req->header.id ) );
344  err:
345  DBGC_HDA ( ena, virt_to_phys ( req ), req, sizeof ( *req ) );
346  DBGC_HDA ( ena, virt_to_phys ( *rsp ), *rsp, sizeof ( **rsp ) );
347  return rc;
348 }
struct ena_aq aq
Admin queue.
Definition: ena.h:577
#define ENA_ACQ_COUNT
Number of admin completion queue entries.
Definition: ena.h:25
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
wmb()
#define DBGC(...)
Definition: compiler.h:505
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
void * regs
Registers.
Definition: ena.h:575
#define EILSEQ
Illegal byte sequence.
Definition: errno.h:413
#define DBGC_HDA(...)
Definition: compiler.h:506
unsigned int cons
Consumer counter.
Definition: ena.h:394
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
uint8_t flags
Flags.
Definition: ena.h:80
#define DBGC2_HDA(...)
Definition: compiler.h:523
uint64_t rsp
Definition: librm.h:267
#define ENA_ACQ_PHASE
Admin completion queue ownership phase flag.
Definition: ena.h:103
#define ENA_AQ_DB
Admin queue doorbell register.
Definition: ena.h:55
#define ENA_AQ_PHASE
Admin queue ownership phase flag.
Definition: ena.h:84
#define le16_to_cpu(value)
Definition: byteswap.h:112
struct ena_acq acq
Admin completion queue.
Definition: ena.h:579
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define DBGC2(...)
Definition: compiler.h:522
#define EIO
Input/output error.
Definition: errno.h:433
union ena_acq_rsp * rsp
Responses.
Definition: ena.h:392
#define ENA_ADMIN_MAX_WAIT_MS
Maximum time to wait for admin requests.
Definition: ena.h:58
uint8_t id
Request identifier.
Definition: ena.h:74
struct ena_aq_header header
Header.
Definition: ena.h:344
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
unsigned int prod
Producer counter.
Definition: ena.h:386
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
unsigned int phase
Phase.
Definition: ena.h:396

References ena_nic::acq, ena_nic::aq, ena_acq::cons, DBGC, DBGC2, DBGC2_HDA, DBGC_HDA, EILSEQ, EIO, ENA_ACQ_COUNT, ENA_ACQ_PHASE, ENA_ADMIN_MAX_WAIT_MS, ENA_AQ_DB, ENA_AQ_PHASE, ETIMEDOUT, ena_aq_header::flags, ena_aq_req::header, ena_aq_header::id, index, le16_to_cpu, mdelay(), ena_acq::phase, ena_aq::prod, rc, ena_nic::regs, rsp, ena_acq::rsp, virt_to_phys(), wmb(), and writel().

Referenced by ena_create_cq(), ena_create_sq(), ena_destroy_cq(), ena_destroy_sq(), ena_get_device_attributes(), and ena_get_stats().

◆ ena_create_sq()

static int ena_create_sq ( struct ena_nic ena,
struct ena_sq sq,
struct ena_cq cq 
)
static

Create submission queue.

Parameters
enaENA device
sqSubmission queue
cqCorresponding completion queue
Return values
rcReturn status code

Definition at line 358 of file ena.c.

359  {
360  union ena_aq_req *req;
361  union ena_acq_rsp *rsp;
362  int rc;
363 
364  /* Allocate submission queue entries */
365  sq->sqe.raw = malloc_phys ( sq->len, ENA_ALIGN );
366  if ( ! sq->sqe.raw ) {
367  rc = -ENOMEM;
368  goto err_alloc;
369  }
370  memset ( sq->sqe.raw, 0, sq->len );
371 
372  /* Construct request */
373  req = ena_admin_req ( ena );
374  req->header.opcode = ENA_CREATE_SQ;
375  req->create_sq.direction = sq->direction;
378  req->create_sq.cq_id = cpu_to_le16 ( cq->id );
379  req->create_sq.count = cpu_to_le16 ( sq->count );
380  req->create_sq.address = cpu_to_le64 ( virt_to_bus ( sq->sqe.raw ) );
381 
382  /* Issue request */
383  if ( ( rc = ena_admin ( ena, req, &rsp ) ) != 0 )
384  goto err_admin;
385 
386  /* Parse response */
387  sq->id = le16_to_cpu ( rsp->create_sq.id );
388  sq->doorbell = le32_to_cpu ( rsp->create_sq.doorbell );
389 
390  /* Reset producer counter and phase */
391  sq->prod = 0;
392  sq->phase = ENA_SQE_PHASE;
393 
394  DBGC ( ena, "ENA %p %s SQ%d at [%08lx,%08lx) db +%04x CQ%d\n",
395  ena, ena_direction ( sq->direction ), sq->id,
396  virt_to_phys ( sq->sqe.raw ),
397  ( virt_to_phys ( sq->sqe.raw ) + sq->len ),
398  sq->doorbell, cq->id );
399  return 0;
400 
401  err_admin:
402  free_phys ( sq->sqe.raw, sq->len );
403  err_alloc:
404  return rc;
405 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
size_t len
Total length of entries.
Definition: ena.h:488
unsigned int doorbell
Doorbell register offset.
Definition: ena.h:486
uint8_t count
Number of entries.
Definition: ena.h:498
#define le32_to_cpu(value)
Definition: byteswap.h:113
unsigned int prod
Producer counter.
Definition: ena.h:490
#define DBGC(...)
Definition: compiler.h:505
uint16_t count
Number of entries.
Definition: ena.h:160
union ena_sq::@39 sqe
Entries.
static void *__malloc malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition: malloc.h:62
#define cpu_to_le64(value)
Definition: byteswap.h:108
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
#define ENOMEM
Not enough space.
Definition: errno.h:534
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
uint64_t address
Base address.
Definition: ena.h:162
uint16_t cq_id
Completion queue identifier.
Definition: ena.h:158
uint16_t policy
Policy.
Definition: ena.h:156
unsigned int phase
Phase.
Definition: ena.h:492
uint8_t direction
Direction.
Definition: ena.h:152
uint64_t rsp
Definition: librm.h:267
static int ena_admin(struct ena_nic *ena, union ena_aq_req *req, union ena_acq_rsp **rsp)
Issue admin queue request.
Definition: ena.c:283
#define ENA_ALIGN
Queue alignment.
Definition: ena.h:19
uint16_t id
Completion queue identifier.
Definition: ena.h:538
#define ENA_CREATE_SQ
Create submission queue.
Definition: ena.h:145
#define le16_to_cpu(value)
Definition: byteswap.h:112
Use host memory.
Definition: ena.h:172
Memory is contiguous.
Definition: ena.h:174
Admin completion queue response.
Definition: ena.h:362
uint8_t opcode
Opcode.
Definition: ena.h:78
#define cpu_to_le16(value)
Definition: byteswap.h:106
#define ENA_SQE_PHASE
Submission queue ownership phase flag.
Definition: ena.h:432
uint16_t id
Submission queue identifier.
Definition: ena.h:494
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
static union ena_aq_req * ena_admin_req(struct ena_nic *ena)
Get next available admin queue request.
Definition: ena.c:256
Admin queue request.
Definition: ena.h:342
static const char * ena_direction(unsigned int direction)
Get direction name (for debugging)
Definition: ena.c:51
struct ena_aq_header header
Header.
Definition: ena.h:344
uint8_t direction
Direction.
Definition: ena.h:496
void * raw
Raw data.
Definition: ena.h:483
struct ena_create_sq_req create_sq
Create submission queue.
Definition: ena.h:346
void * memset(void *dest, int character, size_t len) __nonnull

References ena_create_sq_req::address, ena_create_sq_req::count, ena_sq::count, cpu_to_le16, cpu_to_le64, ena_create_sq_req::cq_id, ena_aq_req::create_sq, DBGC, ena_create_sq_req::direction, ena_sq::direction, ena_sq::doorbell, ena_admin(), ena_admin_req(), ENA_ALIGN, ENA_CREATE_SQ, ena_direction(), ENA_SQ_CONTIGUOUS, ENA_SQ_HOST_MEMORY, ENA_SQE_PHASE, ENOMEM, free_phys(), ena_aq_req::header, ena_sq::id, ena_cq::id, le16_to_cpu, le32_to_cpu, ena_sq::len, malloc_phys(), memset(), ena_aq_header::opcode, ena_sq::phase, ena_create_sq_req::policy, ena_sq::prod, ena_sq::raw, rc, rsp, ena_sq::sqe, virt_to_bus(), and virt_to_phys().

Referenced by ena_create_qp().

◆ ena_destroy_sq()

static int ena_destroy_sq ( struct ena_nic ena,
struct ena_sq sq 
)
static

Destroy submission queue.

Parameters
enaENA device
sqSubmission queue
Return values
rcReturn status code

Definition at line 414 of file ena.c.

414  {
415  union ena_aq_req *req;
416  union ena_acq_rsp *rsp;
417  int rc;
418 
419  /* Construct request */
420  req = ena_admin_req ( ena );
422  req->destroy_sq.id = cpu_to_le16 ( sq->id );
423  req->destroy_sq.direction = sq->direction;
424 
425  /* Issue request */
426  if ( ( rc = ena_admin ( ena, req, &rsp ) ) != 0 )
427  return rc;
428 
429  /* Free submission queue entries */
430  free_phys ( sq->sqe.raw, sq->len );
431 
432  DBGC ( ena, "ENA %p %s SQ%d destroyed\n",
433  ena, ena_direction ( sq->direction ), sq->id );
434  return 0;
435 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
size_t len
Total length of entries.
Definition: ena.h:488
#define DBGC(...)
Definition: compiler.h:505
union ena_sq::@39 sqe
Entries.
uint64_t rsp
Definition: librm.h:267
static int ena_admin(struct ena_nic *ena, union ena_aq_req *req, union ena_acq_rsp **rsp)
Issue admin queue request.
Definition: ena.c:283
uint16_t id
Submission queue identifier.
Definition: ena.h:201
uint8_t direction
Direction.
Definition: ena.h:203
Admin completion queue response.
Definition: ena.h:362
uint8_t opcode
Opcode.
Definition: ena.h:78
#define cpu_to_le16(value)
Definition: byteswap.h:106
uint16_t id
Submission queue identifier.
Definition: ena.h:494
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
static union ena_aq_req * ena_admin_req(struct ena_nic *ena)
Get next available admin queue request.
Definition: ena.c:256
struct ena_destroy_sq_req destroy_sq
Destroy submission queue.
Definition: ena.h:348
Admin queue request.
Definition: ena.h:342
static const char * ena_direction(unsigned int direction)
Get direction name (for debugging)
Definition: ena.c:51
struct ena_aq_header header
Header.
Definition: ena.h:344
#define ENA_DESTROY_SQ
Destroy submission queue.
Definition: ena.h:194
uint8_t direction
Direction.
Definition: ena.h:496
void * raw
Raw data.
Definition: ena.h:483

References cpu_to_le16, DBGC, ena_aq_req::destroy_sq, ena_destroy_sq_req::direction, ena_sq::direction, ena_admin(), ena_admin_req(), ENA_DESTROY_SQ, ena_direction(), free_phys(), ena_aq_req::header, ena_destroy_sq_req::id, ena_sq::id, ena_sq::len, ena_aq_header::opcode, ena_sq::raw, rc, rsp, and ena_sq::sqe.

Referenced by ena_create_qp(), and ena_destroy_qp().

◆ ena_create_cq()

static int ena_create_cq ( struct ena_nic ena,
struct ena_cq cq 
)
static

Create completion queue.

Parameters
enaENA device
cqCompletion queue
Return values
rcReturn status code

Definition at line 444 of file ena.c.

444  {
445  union ena_aq_req *req;
446  union ena_acq_rsp *rsp;
447  int rc;
448 
449  /* Allocate completion queue entries */
450  cq->cqe.raw = malloc_phys ( cq->len, ENA_ALIGN );
451  if ( ! cq->cqe.raw ) {
452  rc = -ENOMEM;
453  goto err_alloc;
454  }
455  memset ( cq->cqe.raw, 0, cq->len );
456 
457  /* Construct request */
458  req = ena_admin_req ( ena );
459  req->header.opcode = ENA_CREATE_CQ;
460  req->create_cq.size = cq->size;
461  req->create_cq.count = cpu_to_le16 ( cq->requested );
462  req->create_cq.address = cpu_to_le64 ( virt_to_bus ( cq->cqe.raw ) );
463 
464  /* Issue request */
465  if ( ( rc = ena_admin ( ena, req, &rsp ) ) != 0 )
466  goto err_admin;
467 
468  /* Parse response */
469  cq->id = le16_to_cpu ( rsp->create_cq.id );
470  cq->actual = le16_to_cpu ( rsp->create_cq.count );
471  cq->doorbell = le32_to_cpu ( rsp->create_cq.doorbell );
472  cq->mask = ( cq->actual - 1 );
473  if ( cq->actual != cq->requested ) {
474  DBGC ( ena, "ENA %p CQ%d requested %d actual %d\n",
475  ena, cq->id, cq->requested, cq->actual );
476  }
477 
478  /* Reset consumer counter and phase */
479  cq->cons = 0;
480  cq->phase = ENA_CQE_PHASE;
481 
482  DBGC ( ena, "ENA %p CQ%d at [%08lx,%08lx) db +%04x\n",
483  ena, cq->id, virt_to_phys ( cq->cqe.raw ),
484  ( virt_to_phys ( cq->cqe.raw ) + cq->len ), cq->doorbell );
485  return 0;
486 
487  err_admin:
488  free_phys ( cq->cqe.raw, cq->len );
489  err_alloc:
490  return rc;
491 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * raw
Raw data.
Definition: ena.h:527
uint8_t mask
Actual number of entries minus one.
Definition: ena.h:546
#define le32_to_cpu(value)
Definition: byteswap.h:113
#define ENA_CREATE_CQ
Create completion queue.
Definition: ena.h:215
#define DBGC(...)
Definition: compiler.h:505
static void *__malloc malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition: malloc.h:62
union ena_cq::@40 cqe
Entries.
#define cpu_to_le64(value)
Definition: byteswap.h:108
uint16_t count
Number of entries.
Definition: ena.h:226
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:540
unsigned int phase
Phase.
Definition: ena.h:536
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
uint64_t address
Base address.
Definition: ena.h:230
unsigned int doorbell
Doorbell register offset.
Definition: ena.h:530
size_t len
Total length of entries.
Definition: ena.h:532
#define ENOMEM
Not enough space.
Definition: errno.h:534
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
unsigned int cons
Consumer counter.
Definition: ena.h:534
#define ENA_CQE_PHASE
Completion queue ownership phase flag.
Definition: ena.h:472
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:224
struct ena_create_cq_req create_cq
Create completion queue.
Definition: ena.h:350
uint64_t rsp
Definition: librm.h:267
static int ena_admin(struct ena_nic *ena, union ena_aq_req *req, union ena_acq_rsp **rsp)
Issue admin queue request.
Definition: ena.c:283
#define ENA_ALIGN
Queue alignment.
Definition: ena.h:19
uint16_t id
Completion queue identifier.
Definition: ena.h:538
uint8_t actual
Actual number of entries.
Definition: ena.h:544
#define le16_to_cpu(value)
Definition: byteswap.h:112
uint8_t requested
Requested number of entries.
Definition: ena.h:542
Admin completion queue response.
Definition: ena.h:362
uint8_t opcode
Opcode.
Definition: ena.h:78
#define cpu_to_le16(value)
Definition: byteswap.h:106
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
static union ena_aq_req * ena_admin_req(struct ena_nic *ena)
Get next available admin queue request.
Definition: ena.c:256
Admin queue request.
Definition: ena.h:342
struct ena_aq_header header
Header.
Definition: ena.h:344
void * memset(void *dest, int character, size_t len) __nonnull

References ena_cq::actual, ena_create_cq_req::address, ena_cq::cons, ena_create_cq_req::count, cpu_to_le16, cpu_to_le64, ena_cq::cqe, ena_aq_req::create_cq, DBGC, ena_cq::doorbell, ena_admin(), ena_admin_req(), ENA_ALIGN, ENA_CQE_PHASE, ENA_CREATE_CQ, ENOMEM, free_phys(), ena_aq_req::header, ena_cq::id, le16_to_cpu, le32_to_cpu, ena_cq::len, malloc_phys(), ena_cq::mask, memset(), ena_aq_header::opcode, ena_cq::phase, ena_cq::raw, rc, ena_cq::requested, rsp, ena_create_cq_req::size, ena_cq::size, virt_to_bus(), and virt_to_phys().

Referenced by ena_create_qp().

◆ ena_destroy_cq()

static int ena_destroy_cq ( struct ena_nic ena,
struct ena_cq cq 
)
static

Destroy completion queue.

Parameters
enaENA device
cqCompletion queue
Return values
rcReturn status code

Definition at line 500 of file ena.c.

500  {
501  union ena_aq_req *req;
502  union ena_acq_rsp *rsp;
503  int rc;
504 
505  /* Construct request */
506  req = ena_admin_req ( ena );
508  req->destroy_cq.id = cpu_to_le16 ( cq->id );
509 
510  /* Issue request */
511  if ( ( rc = ena_admin ( ena, req, &rsp ) ) != 0 )
512  return rc;
513 
514  /* Free completion queue entries */
515  free_phys ( cq->cqe.raw, cq->len );
516 
517  DBGC ( ena, "ENA %p CQ%d destroyed\n", ena, cq->id );
518  return 0;
519 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * raw
Raw data.
Definition: ena.h:527
uint16_t id
Completion queue identifier.
Definition: ena.h:257
#define DBGC(...)
Definition: compiler.h:505
union ena_cq::@40 cqe
Entries.
size_t len
Total length of entries.
Definition: ena.h:532
struct ena_destroy_cq_req destroy_cq
Destroy completion queue.
Definition: ena.h:352
uint64_t rsp
Definition: librm.h:267
static int ena_admin(struct ena_nic *ena, union ena_aq_req *req, union ena_acq_rsp **rsp)
Issue admin queue request.
Definition: ena.c:283
uint16_t id
Completion queue identifier.
Definition: ena.h:538
#define ENA_DESTROY_CQ
Destroy completion queue.
Definition: ena.h:250
Admin completion queue response.
Definition: ena.h:362
uint8_t opcode
Opcode.
Definition: ena.h:78
#define cpu_to_le16(value)
Definition: byteswap.h:106
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
static union ena_aq_req * ena_admin_req(struct ena_nic *ena)
Get next available admin queue request.
Definition: ena.c:256
Admin queue request.
Definition: ena.h:342
struct ena_aq_header header
Header.
Definition: ena.h:344

References cpu_to_le16, ena_cq::cqe, DBGC, ena_aq_req::destroy_cq, ena_admin(), ena_admin_req(), ENA_DESTROY_CQ, free_phys(), ena_aq_req::header, ena_destroy_cq_req::id, ena_cq::id, ena_cq::len, ena_aq_header::opcode, ena_cq::raw, rc, and rsp.

Referenced by ena_create_qp(), and ena_destroy_qp().

◆ ena_create_qp()

static int ena_create_qp ( struct ena_nic ena,
struct ena_qp qp 
)
static

Create queue pair.

Parameters
enaENA device
qpQueue pair
Return values
rcReturn status code

Definition at line 528 of file ena.c.

528  {
529  int rc;
530 
531  /* Create completion queue */
532  if ( ( rc = ena_create_cq ( ena, &qp->cq ) ) != 0 )
533  goto err_create_cq;
534 
535  /* Create submission queue */
536  if ( ( rc = ena_create_sq ( ena, &qp->sq, &qp->cq ) ) != 0 )
537  goto err_create_sq;
538 
539  return 0;
540 
541  ena_destroy_sq ( ena, &qp->sq );
542  err_create_sq:
543  ena_destroy_cq ( ena, &qp->cq );
544  err_create_cq:
545  return rc;
546 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int ena_destroy_sq(struct ena_nic *ena, struct ena_sq *sq)
Destroy submission queue.
Definition: ena.c:414
static int ena_create_cq(struct ena_nic *ena, struct ena_cq *cq)
Create completion queue.
Definition: ena.c:444
struct arbelprm_qp_db_record qp
Definition: arbel.h:13
static int ena_destroy_cq(struct ena_nic *ena, struct ena_cq *cq)
Destroy completion queue.
Definition: ena.c:500
static int ena_create_sq(struct ena_nic *ena, struct ena_sq *sq, struct ena_cq *cq)
Create submission queue.
Definition: ena.c:358

References ena_create_cq(), ena_create_sq(), ena_destroy_cq(), ena_destroy_sq(), qp, and rc.

Referenced by ena_open().

◆ ena_destroy_qp()

static int ena_destroy_qp ( struct ena_nic ena,
struct ena_qp qp 
)
static

Destroy queue pair.

Parameters
enaENA device
qpQueue pair
Return values
rcReturn status code

Definition at line 555 of file ena.c.

555  {
556 
557  /* Destroy submission queue */
558  ena_destroy_sq ( ena, &qp->sq );
559 
560  /* Destroy completion queue */
561  ena_destroy_cq ( ena, &qp->cq );
562 
563  return 0;
564 }
static int ena_destroy_sq(struct ena_nic *ena, struct ena_sq *sq)
Destroy submission queue.
Definition: ena.c:414
struct arbelprm_qp_db_record qp
Definition: arbel.h:13
static int ena_destroy_cq(struct ena_nic *ena, struct ena_cq *cq)
Destroy completion queue.
Definition: ena.c:500

References ena_destroy_cq(), ena_destroy_sq(), and qp.

Referenced by ena_close(), and ena_open().

◆ ena_get_device_attributes()

static int ena_get_device_attributes ( struct net_device netdev)
static

Get device attributes.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 572 of file ena.c.

572  {
573  struct ena_nic *ena = netdev->priv;
574  union ena_aq_req *req;
575  union ena_acq_rsp *rsp;
576  union ena_feature *feature;
577  int rc;
578 
579  /* Construct request */
580  req = ena_admin_req ( ena );
583 
584  /* Issue request */
585  if ( ( rc = ena_admin ( ena, req, &rsp ) ) != 0 )
586  return rc;
587 
588  /* Parse response */
589  feature = &rsp->get_feature.feature;
590  memcpy ( netdev->hw_addr, feature->device.mac, ETH_ALEN );
591  netdev->max_pkt_len = le32_to_cpu ( feature->device.mtu );
593 
594  DBGC ( ena, "ENA %p MAC %s MTU %zd\n",
595  ena, eth_ntoa ( netdev->hw_addr ), netdev->max_pkt_len );
596  return 0;
597 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define le32_to_cpu(value)
Definition: byteswap.h:113
#define ENA_GET_FEATURE
Get feature.
Definition: ena.h:269
size_t mtu
Maximum transmission unit length.
Definition: netdevice.h:415
#define DBGC(...)
Definition: compiler.h:505
union ena_feature feature
Feature.
Definition: ena.h:14
Feature.
Definition: ena.h:131
#define ENA_DEVICE_ATTRIBUTES
Device attributes.
Definition: ena.h:106
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint8_t id
Feature identifier.
Definition: ena.h:282
#define ETH_HLEN
Definition: if_ether.h:9
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
uint64_t rsp
Definition: librm.h:267
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
static int ena_admin(struct ena_nic *ena, union ena_aq_req *req, union ena_acq_rsp **rsp)
Issue admin queue request.
Definition: ena.c:283
#define ETH_ALEN
Definition: if_ether.h:8
A named feature.
Definition: features.h:78
struct ena_get_feature_req get_feature
Get feature.
Definition: ena.h:354
Admin completion queue response.
Definition: ena.h:362
uint8_t opcode
Opcode.
Definition: ena.h:78
static union ena_aq_req * ena_admin_req(struct ena_nic *ena)
Get next available admin queue request.
Definition: ena.c:256
An ENA network card.
Definition: ena.h:573
Admin queue request.
Definition: ena.h:342
struct ena_aq_header header
Header.
Definition: ena.h:344
size_t max_pkt_len
Maximum packet length.
Definition: netdevice.h:409
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381

References DBGC, ena_admin(), ena_admin_req(), ENA_DEVICE_ATTRIBUTES, ENA_GET_FEATURE, ETH_ALEN, ETH_HLEN, eth_ntoa(), feature, ena_aq_req::get_feature, ena_aq_req::header, net_device::hw_addr, ena_get_feature_req::id, le32_to_cpu, net_device::max_pkt_len, memcpy(), net_device::mtu, netdev, ena_aq_header::opcode, net_device::priv, rc, and rsp.

Referenced by ena_probe().

◆ ena_get_stats()

static int ena_get_stats ( struct ena_nic ena)
static

Get statistics (for debugging)

Parameters
enaENA device
Return values
rcReturn status code

Definition at line 605 of file ena.c.

605  {
606  union ena_aq_req *req;
607  union ena_acq_rsp *rsp;
608  struct ena_get_stats_rsp *stats;
609  int rc;
610 
611  /* Do nothing unless debug messages are enabled */
612  if ( ! DBG_LOG )
613  return 0;
614 
615  /* Construct request */
616  req = ena_admin_req ( ena );
617  req->header.opcode = ENA_GET_STATS;
621 
622  /* Issue request */
623  if ( ( rc = ena_admin ( ena, req, &rsp ) ) != 0 )
624  return rc;
625 
626  /* Parse response */
627  stats = &rsp->get_stats;
628  DBGC ( ena, "ENA %p TX bytes %#llx packets %#llx\n", ena,
629  ( ( unsigned long long ) le64_to_cpu ( stats->tx_bytes ) ),
630  ( ( unsigned long long ) le64_to_cpu ( stats->tx_packets ) ) );
631  DBGC ( ena, "ENA %p RX bytes %#llx packets %#llx drops %#llx\n", ena,
632  ( ( unsigned long long ) le64_to_cpu ( stats->rx_bytes ) ),
633  ( ( unsigned long long ) le64_to_cpu ( stats->rx_packets ) ),
634  ( ( unsigned long long ) le64_to_cpu ( stats->rx_drops ) ) );
635 
636  return 0;
637 }
uint8_t type
Type.
Definition: ena.h:305
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
uint64_t rx_drops
Receive drop count.
Definition: ena.h:338
#define ENA_GET_STATS
Get statistics.
Definition: ena.h:296
uint64_t tx_packets
Transmit packet count.
Definition: ena.h:332
#define ENA_STATS_TYPE_BASIC
Basic statistics.
Definition: ena.h:317
struct ena_get_stats_req get_stats
Get statistics.
Definition: ena.h:356
uint64_t rsp
Definition: librm.h:267
static int ena_admin(struct ena_nic *ena, union ena_aq_req *req, union ena_acq_rsp **rsp)
Issue admin queue request.
Definition: ena.c:283
#define ENA_STATS_SCOPE_ETH
Ethernet statistics.
Definition: ena.h:320
Get statistics response.
Definition: ena.h:326
uint64_t rx_bytes
Receive byte count.
Definition: ena.h:334
#define ENA_DEVICE_MINE
My device.
Definition: ena.h:323
Admin completion queue response.
Definition: ena.h:362
uint8_t opcode
Opcode.
Definition: ena.h:78
uint64_t tx_bytes
Transmit byte count.
Definition: ena.h:330
uint8_t scope
Scope.
Definition: ena.h:307
static union ena_aq_req * ena_admin_req(struct ena_nic *ena)
Get next available admin queue request.
Definition: ena.c:256
Admin queue request.
Definition: ena.h:342
struct ena_aq_header header
Header.
Definition: ena.h:344
#define le64_to_cpu(value)
Definition: byteswap.h:114
uint64_t rx_packets
Receive packet count.
Definition: ena.h:336
#define DBG_LOG
Definition: compiler.h:317
uint16_t device
Device ID.
Definition: ena.h:313

References DBG_LOG, DBGC, ena_get_stats_req::device, ena_admin(), ena_admin_req(), ENA_DEVICE_MINE, ENA_GET_STATS, ENA_STATS_SCOPE_ETH, ENA_STATS_TYPE_BASIC, ena_aq_req::get_stats, ena_aq_req::header, le64_to_cpu, ena_aq_header::opcode, rc, rsp, ena_get_stats_rsp::rx_bytes, ena_get_stats_rsp::rx_drops, ena_get_stats_rsp::rx_packets, ena_get_stats_req::scope, ena_get_stats_rsp::tx_bytes, ena_get_stats_rsp::tx_packets, and ena_get_stats_req::type.

Referenced by ena_close().

◆ ena_refill_rx()

static void ena_refill_rx ( struct net_device netdev)
static

Refill receive queue.

Parameters
netdevNetwork device

Definition at line 651 of file ena.c.

651  {
652  struct ena_nic *ena = netdev->priv;
653  struct io_buffer *iobuf;
654  struct ena_rx_sqe *sqe;
655  unsigned int index;
657  size_t len = netdev->max_pkt_len;
658  unsigned int refilled = 0;
659 
660  /* Refill queue */
661  while ( ( ena->rx.sq.prod - ena->rx.cq.cons ) < ENA_RX_COUNT ) {
662 
663  /* Allocate I/O buffer */
664  iobuf = alloc_iob ( len );
665  if ( ! iobuf ) {
666  /* Wait for next refill */
667  break;
668  }
669 
670  /* Get next submission queue entry */
671  index = ( ena->rx.sq.prod % ENA_RX_COUNT );
672  sqe = &ena->rx.sq.sqe.rx[index];
673 
674  /* Construct submission queue entry */
675  address = virt_to_bus ( iobuf->data );
676  sqe->len = cpu_to_le16 ( len );
677  sqe->id = cpu_to_le16 ( ena->rx.sq.prod );
678  sqe->address = cpu_to_le64 ( address );
679  wmb();
681  ena->rx.sq.phase );
682 
683  /* Increment producer counter */
684  ena->rx.sq.prod++;
685  if ( ( ena->rx.sq.prod % ENA_RX_COUNT ) == 0 )
686  ena->rx.sq.phase ^= ENA_SQE_PHASE;
687 
688  /* Record I/O buffer */
689  assert ( ena->rx_iobuf[index] == NULL );
690  ena->rx_iobuf[index] = iobuf;
691 
692  DBGC2 ( ena, "ENA %p RX %d at [%08llx,%08llx)\n", ena, sqe->id,
693  ( ( unsigned long long ) address ),
694  ( ( unsigned long long ) address + len ) );
695  refilled++;
696  }
697 
698  /* Ring doorbell, if applicable */
699  if ( refilled ) {
700  wmb();
701  writel ( ena->rx.sq.prod, ( ena->regs + ena->rx.sq.doorbell ) );
702  }
703 }
struct ena_qp rx
Receive queue.
Definition: ena.h:583
wmb()
#define ENA_RX_COUNT
Number of receive queue entries.
Definition: ena.h:31
unsigned int doorbell
Doorbell register offset.
Definition: ena.h:486
unsigned int prod
Producer counter.
Definition: ena.h:490
uint64_t address
Base address.
Definition: ena.h:24
union ena_sq::@39 sqe
Entries.
#define ENA_SQE_CPL
Request completion.
Definition: ena.h:441
#define cpu_to_le64(value)
Definition: byteswap.h:108
uint16_t len
Length.
Definition: ena.h:418
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
uint64_t address
Address.
Definition: ena.h:428
void * regs
Registers.
Definition: ena.h:575
uint16_t id
Request identifier.
Definition: ena.h:424
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void * priv
Driver private data.
Definition: netdevice.h:431
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
unsigned int cons
Consumer counter.
Definition: ena.h:534
static struct net_device * netdev
Definition: gdbudp.c:52
#define ENA_SQE_FIRST
This is the first descriptor.
Definition: ena.h:435
unsigned int phase
Phase.
Definition: ena.h:492
struct ena_cq cq
Completion queue.
Definition: ena.h:569
#define ENA_SQE_LAST
This is the last descriptor.
Definition: ena.h:438
struct io_buffer * rx_iobuf[ENA_RX_COUNT]
Receive I/O buffers.
Definition: ena.h:585
unsigned long physaddr_t
Definition: stdint.h:20
struct ena_sq sq
Submission queue.
Definition: ena.h:567
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
Receive submission queue entry.
Definition: ena.h:416
void * data
Start of data.
Definition: iobuf.h:48
#define cpu_to_le16(value)
Definition: byteswap.h:106
uint8_t flags
Flags.
Definition: ena.h:422
#define ENA_SQE_PHASE
Submission queue ownership phase flag.
Definition: ena.h:432
struct ena_rx_sqe * rx
Receive submission queue entries.
Definition: ena.h:481
An ENA network card.
Definition: ena.h:573
size_t max_pkt_len
Maximum packet length.
Definition: netdevice.h:409
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:33

References address, ena_rx_sqe::address, alloc_iob(), assert(), ena_cq::cons, cpu_to_le16, cpu_to_le64, ena_qp::cq, io_buffer::data, DBGC2, ena_sq::doorbell, ENA_RX_COUNT, ENA_SQE_CPL, ENA_SQE_FIRST, ENA_SQE_LAST, ENA_SQE_PHASE, ena_rx_sqe::flags, ena_rx_sqe::id, index, len, ena_rx_sqe::len, net_device::max_pkt_len, netdev, NULL, ena_sq::phase, net_device::priv, ena_sq::prod, ena_nic::regs, ena_sq::rx, ena_nic::rx, ena_nic::rx_iobuf, ena_qp::sq, ena_sq::sqe, virt_to_bus(), wmb(), and writel().

Referenced by ena_open(), and ena_poll().

◆ ena_empty_rx()

static void ena_empty_rx ( struct ena_nic ena)
static

Discard unused receive I/O buffers.

Parameters
enaENA device

Definition at line 710 of file ena.c.

710  {
711  unsigned int i;
712 
713  for ( i = 0 ; i < ENA_RX_COUNT ; i++ ) {
714  if ( ena->rx_iobuf[i] )
715  free_iob ( ena->rx_iobuf[i] );
716  ena->rx_iobuf[i] = NULL;
717  }
718 }
#define ENA_RX_COUNT
Number of receive queue entries.
Definition: ena.h:31
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
struct io_buffer * rx_iobuf[ENA_RX_COUNT]
Receive I/O buffers.
Definition: ena.h:585
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References ENA_RX_COUNT, free_iob(), NULL, and ena_nic::rx_iobuf.

Referenced by ena_close().

◆ ena_open()

static int ena_open ( struct net_device netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 726 of file ena.c.

726  {
727  struct ena_nic *ena = netdev->priv;
728  int rc;
729 
730  /* Create transmit queue pair */
731  if ( ( rc = ena_create_qp ( ena, &ena->tx ) ) != 0 )
732  goto err_create_tx;
733 
734  /* Create receive queue pair */
735  if ( ( rc = ena_create_qp ( ena, &ena->rx ) ) != 0 )
736  goto err_create_rx;
737 
738  /* Refill receive queue */
739  ena_refill_rx ( netdev );
740 
741  return 0;
742 
743  ena_destroy_qp ( ena, &ena->rx );
744  err_create_rx:
745  ena_destroy_qp ( ena, &ena->tx );
746  err_create_tx:
747  return rc;
748 }
static void ena_refill_rx(struct net_device *netdev)
Refill receive queue.
Definition: ena.c:651
struct ena_qp rx
Receive queue.
Definition: ena.h:583
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct ena_qp tx
Transmit queue.
Definition: ena.h:581
static int ena_create_qp(struct ena_nic *ena, struct ena_qp *qp)
Create queue pair.
Definition: ena.c:528
static int ena_destroy_qp(struct ena_nic *ena, struct ena_qp *qp)
Destroy queue pair.
Definition: ena.c:555
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
An ENA network card.
Definition: ena.h:573

References ena_create_qp(), ena_destroy_qp(), ena_refill_rx(), netdev, net_device::priv, rc, ena_nic::rx, and ena_nic::tx.

◆ ena_close()

static void ena_close ( struct net_device netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 755 of file ena.c.

755  {
756  struct ena_nic *ena = netdev->priv;
757 
758  /* Dump statistics (for debugging) */
759  ena_get_stats ( ena );
760 
761  /* Destroy receive queue pair */
762  ena_destroy_qp ( ena, &ena->rx );
763 
764  /* Discard any unused receive buffers */
765  ena_empty_rx ( ena );
766 
767  /* Destroy transmit queue pair */
768  ena_destroy_qp ( ena, &ena->tx );
769 }
struct ena_qp rx
Receive queue.
Definition: ena.h:583
static int ena_get_stats(struct ena_nic *ena)
Get statistics (for debugging)
Definition: ena.c:605
struct ena_qp tx
Transmit queue.
Definition: ena.h:581
static int ena_destroy_qp(struct ena_nic *ena, struct ena_qp *qp)
Destroy queue pair.
Definition: ena.c:555
static void ena_empty_rx(struct ena_nic *ena)
Discard unused receive I/O buffers.
Definition: ena.c:710
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
An ENA network card.
Definition: ena.h:573

References ena_destroy_qp(), ena_empty_rx(), ena_get_stats(), netdev, net_device::priv, ena_nic::rx, and ena_nic::tx.

◆ ena_transmit()

static int ena_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 778 of file ena.c.

778  {
779  struct ena_nic *ena = netdev->priv;
780  struct ena_tx_sqe *sqe;
781  unsigned int index;
783  size_t len;
784 
785  /* Get next submission queue entry */
786  if ( ( ena->tx.sq.prod - ena->tx.cq.cons ) >= ENA_TX_COUNT ) {
787  DBGC ( ena, "ENA %p out of transmit descriptors\n", ena );
788  return -ENOBUFS;
789  }
790  index = ( ena->tx.sq.prod % ENA_TX_COUNT );
791  sqe = &ena->tx.sq.sqe.tx[index];
792 
793  /* Construct submission queue entry */
794  address = virt_to_bus ( iobuf->data );
795  len = iob_len ( iobuf );
796  sqe->len = cpu_to_le16 ( len );
797  sqe->id = ena->tx.sq.prod;
798  sqe->address = cpu_to_le64 ( address );
799  wmb();
801  ena->tx.sq.phase );
802  wmb();
803 
804  /* Increment producer counter */
805  ena->tx.sq.prod++;
806  if ( ( ena->tx.sq.prod % ENA_TX_COUNT ) == 0 )
807  ena->tx.sq.phase ^= ENA_SQE_PHASE;
808 
809  /* Ring doorbell */
810  writel ( ena->tx.sq.prod, ( ena->regs + ena->tx.sq.doorbell ) );
811 
812  DBGC2 ( ena, "ENA %p TX %d at [%08llx,%08llx)\n", ena, sqe->id,
813  ( ( unsigned long long ) address ),
814  ( ( unsigned long long ) address + len ) );
815  return 0;
816 }
struct ena_tx_sqe * tx
Transmit submission queue entries.
Definition: ena.h:479
wmb()
unsigned int doorbell
Doorbell register offset.
Definition: ena.h:486
unsigned int prod
Producer counter.
Definition: ena.h:490
uint64_t address
Base address.
Definition: ena.h:24
Transmit submission queue entry.
Definition: ena.h:400
struct ena_qp tx
Transmit queue.
Definition: ena.h:581
#define DBGC(...)
Definition: compiler.h:505
union ena_sq::@39 sqe
Entries.
#define ENA_SQE_CPL
Request completion.
Definition: ena.h:441
uint8_t id
Request identifier.
Definition: ena.h:410
#define cpu_to_le64(value)
Definition: byteswap.h:108
#define ENA_TX_COUNT
Number of transmit queue entries.
Definition: ena.h:28
void * regs
Registers.
Definition: ena.h:575
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
void * priv
Driver private data.
Definition: netdevice.h:431
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
unsigned int cons
Consumer counter.
Definition: ena.h:534
static struct net_device * netdev
Definition: gdbudp.c:52
#define ENA_SQE_FIRST
This is the first descriptor.
Definition: ena.h:435
unsigned int phase
Phase.
Definition: ena.h:492
struct ena_cq cq
Completion queue.
Definition: ena.h:569
uint8_t flags
Flags.
Definition: ena.h:406
#define ENA_SQE_LAST
This is the last descriptor.
Definition: ena.h:438
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
unsigned long physaddr_t
Definition: stdint.h:20
struct ena_sq sq
Submission queue.
Definition: ena.h:567
uint32_t len
Length.
Definition: ena.h:14
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
#define DBGC2(...)
Definition: compiler.h:522
uint64_t address
Address.
Definition: ena.h:412
void * data
Start of data.
Definition: iobuf.h:48
#define cpu_to_le16(value)
Definition: byteswap.h:106
#define ENA_SQE_PHASE
Submission queue ownership phase flag.
Definition: ena.h:432
uint16_t len
Length.
Definition: ena.h:402
An ENA network card.
Definition: ena.h:573
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21

References address, ena_tx_sqe::address, ena_cq::cons, cpu_to_le16, cpu_to_le64, ena_qp::cq, io_buffer::data, DBGC, DBGC2, ena_sq::doorbell, ENA_SQE_CPL, ENA_SQE_FIRST, ENA_SQE_LAST, ENA_SQE_PHASE, ENA_TX_COUNT, ENOBUFS, ena_tx_sqe::flags, ena_tx_sqe::id, index, iob_len(), len, ena_tx_sqe::len, netdev, ena_sq::phase, net_device::priv, ena_sq::prod, ena_nic::regs, ena_qp::sq, ena_sq::sqe, ena_sq::tx, ena_nic::tx, virt_to_bus(), wmb(), and writel().

◆ ena_poll_tx()

static void ena_poll_tx ( struct net_device netdev)
static

Poll for completed transmissions.

Parameters
netdevNetwork device

Definition at line 823 of file ena.c.

823  {
824  struct ena_nic *ena = netdev->priv;
825  struct ena_tx_cqe *cqe;
826  unsigned int index;
827 
828  /* Check for completed packets */
829  while ( ena->tx.cq.cons != ena->tx.sq.prod ) {
830 
831  /* Get next completion queue entry */
832  index = ( ena->tx.cq.cons & ena->tx.cq.mask );
833  cqe = &ena->tx.cq.cqe.tx[index];
834 
835  /* Stop if completion queue entry is empty */
836  if ( ( cqe->flags ^ ena->tx.cq.phase ) & ENA_CQE_PHASE )
837  return;
838  DBGC2 ( ena, "ENA %p TX %d complete\n", ena,
839  ( le16_to_cpu ( cqe->id ) >> 2 /* Don't ask */ ) );
840 
841  /* Increment consumer counter */
842  ena->tx.cq.cons++;
843  if ( ! ( ena->tx.cq.cons & ena->tx.cq.mask ) )
844  ena->tx.cq.phase ^= ENA_CQE_PHASE;
845 
846  /* Complete transmit */
848  }
849 }
uint8_t mask
Actual number of entries minus one.
Definition: ena.h:546
unsigned int prod
Producer counter.
Definition: ena.h:490
static void netdev_tx_complete_next(struct net_device *netdev)
Complete network transmission.
Definition: netdevice.h:770
struct ena_tx_cqe * tx
Transmit completion queue entries.
Definition: ena.h:523
struct ena_qp tx
Transmit queue.
Definition: ena.h:581
Transmit completion queue entry.
Definition: ena.h:444
union ena_cq::@40 cqe
Entries.
unsigned int phase
Phase.
Definition: ena.h:536
uint16_t id
Request identifier.
Definition: ena.h:446
void * priv
Driver private data.
Definition: netdevice.h:431
uint8_t flags
Flags.
Definition: ena.h:450
unsigned int cons
Consumer counter.
Definition: ena.h:534
#define ENA_CQE_PHASE
Completion queue ownership phase flag.
Definition: ena.h:472
static struct net_device * netdev
Definition: gdbudp.c:52
struct ena_cq cq
Completion queue.
Definition: ena.h:569
#define le16_to_cpu(value)
Definition: byteswap.h:112
struct ena_sq sq
Submission queue.
Definition: ena.h:567
#define DBGC2(...)
Definition: compiler.h:522
An ENA network card.
Definition: ena.h:573
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21

References ena_cq::cons, ena_qp::cq, ena_cq::cqe, DBGC2, ENA_CQE_PHASE, ena_tx_cqe::flags, ena_tx_cqe::id, index, le16_to_cpu, ena_cq::mask, netdev, netdev_tx_complete_next(), ena_cq::phase, net_device::priv, ena_sq::prod, ena_qp::sq, ena_cq::tx, and ena_nic::tx.

Referenced by ena_poll().

◆ ena_poll_rx()

static void ena_poll_rx ( struct net_device netdev)
static

Poll for received packets.

Parameters
netdevNetwork device

Definition at line 856 of file ena.c.

856  {
857  struct ena_nic *ena = netdev->priv;
858  struct ena_rx_cqe *cqe;
859  struct io_buffer *iobuf;
860  unsigned int index;
861  size_t len;
862 
863  /* Check for received packets */
864  while ( ena->rx.cq.cons != ena->rx.sq.prod ) {
865 
866  /* Get next completion queue entry */
867  index = ( ena->rx.cq.cons % ENA_RX_COUNT );
868  cqe = &ena->rx.cq.cqe.rx[index];
869 
870  /* Stop if completion queue entry is empty */
871  if ( ( cqe->flags ^ ena->rx.cq.phase ) & ENA_CQE_PHASE )
872  return;
873 
874  /* Increment consumer counter */
875  ena->rx.cq.cons++;
876  if ( ! ( ena->rx.cq.cons & ena->rx.cq.mask ) )
877  ena->rx.cq.phase ^= ENA_CQE_PHASE;
878 
879  /* Populate I/O buffer */
880  iobuf = ena->rx_iobuf[index];
881  ena->rx_iobuf[index] = NULL;
882  len = le16_to_cpu ( cqe->len );
883  iob_put ( iobuf, len );
884 
885  /* Hand off to network stack */
886  DBGC2 ( ena, "ENA %p RX %d complete (length %zd)\n",
887  ena, le16_to_cpu ( cqe->id ), len );
888  netdev_rx ( netdev, iobuf );
889  }
890 }
struct ena_qp rx
Receive queue.
Definition: ena.h:583
#define iob_put(iobuf, len)
Definition: iobuf.h:120
#define ENA_RX_COUNT
Number of receive queue entries.
Definition: ena.h:31
uint8_t mask
Actual number of entries minus one.
Definition: ena.h:546
unsigned int prod
Producer counter.
Definition: ena.h:490
union ena_cq::@40 cqe
Entries.
unsigned int phase
Phase.
Definition: ena.h:536
void * priv
Driver private data.
Definition: netdevice.h:431
unsigned int cons
Consumer counter.
Definition: ena.h:534
#define ENA_CQE_PHASE
Completion queue ownership phase flag.
Definition: ena.h:472
static struct net_device * netdev
Definition: gdbudp.c:52
struct ena_rx_cqe * rx
Receive completion queue entries.
Definition: ena.h:525
struct ena_cq cq
Completion queue.
Definition: ena.h:569
uint8_t flags
Flags.
Definition: ena.h:462
#define le16_to_cpu(value)
Definition: byteswap.h:112
struct io_buffer * rx_iobuf[ENA_RX_COUNT]
Receive I/O buffers.
Definition: ena.h:585
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:504
struct ena_sq sq
Submission queue.
Definition: ena.h:567
uint32_t len
Length.
Definition: ena.h:14
uint16_t len
Length.
Definition: ena.h:464
uint16_t id
Request identifier.
Definition: ena.h:466
#define DBGC2(...)
Definition: compiler.h:522
Receive completion queue entry.
Definition: ena.h:458
An ENA network card.
Definition: ena.h:573
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:33

References ena_cq::cons, ena_qp::cq, ena_cq::cqe, DBGC2, ENA_CQE_PHASE, ENA_RX_COUNT, ena_rx_cqe::flags, ena_rx_cqe::id, index, iob_put, le16_to_cpu, len, ena_rx_cqe::len, ena_cq::mask, netdev, netdev_rx(), NULL, ena_cq::phase, net_device::priv, ena_sq::prod, ena_cq::rx, ena_nic::rx, ena_nic::rx_iobuf, and ena_qp::sq.

Referenced by ena_poll().

◆ ena_poll()

static void ena_poll ( struct net_device netdev)
static

Poll for completed and received packets.

Parameters
netdevNetwork device

Definition at line 897 of file ena.c.

897  {
898 
899  /* Poll for transmit completions */
900  ena_poll_tx ( netdev );
901 
902  /* Poll for receive completions */
903  ena_poll_rx ( netdev );
904 
905  /* Refill receive ring */
906  ena_refill_rx ( netdev );
907 }
static void ena_refill_rx(struct net_device *netdev)
Refill receive queue.
Definition: ena.c:651
static void ena_poll_tx(struct net_device *netdev)
Poll for completed transmissions.
Definition: ena.c:823
static struct net_device * netdev
Definition: gdbudp.c:52
static void ena_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: ena.c:856

References ena_poll_rx(), ena_poll_tx(), ena_refill_rx(), and netdev.

◆ ena_probe()

static int ena_probe ( struct pci_device pci)
static

Probe PCI device.

Parameters
pciPCI device
Return values
rcReturn status code

Definition at line 930 of file ena.c.

930  {
931  struct net_device *netdev;
932  struct ena_nic *ena;
933  int rc;
934 
935  /* Allocate and initialise net device */
936  netdev = alloc_etherdev ( sizeof ( *ena ) );
937  if ( ! netdev ) {
938  rc = -ENOMEM;
939  goto err_alloc;
940  }
942  ena = netdev->priv;
943  pci_set_drvdata ( pci, netdev );
944  netdev->dev = &pci->dev;
945  memset ( ena, 0, sizeof ( *ena ) );
946  ena->acq.phase = ENA_ACQ_PHASE;
947  ena_cq_init ( &ena->tx.cq, ENA_TX_COUNT,
948  sizeof ( ena->tx.cq.cqe.tx[0] ) );
949  ena_sq_init ( &ena->tx.sq, ENA_SQ_TX, ENA_TX_COUNT,
950  sizeof ( ena->tx.sq.sqe.tx[0] ) );
951  ena_cq_init ( &ena->rx.cq, ENA_RX_COUNT,
952  sizeof ( ena->rx.cq.cqe.rx[0] ) );
953  ena_sq_init ( &ena->rx.sq, ENA_SQ_RX, ENA_RX_COUNT,
954  sizeof ( ena->rx.sq.sqe.rx[0] ) );
955 
956  /* Fix up PCI device */
957  adjust_pci_device ( pci );
958 
959  /* Map registers */
960  ena->regs = pci_ioremap ( pci, pci->membase, ENA_BAR_SIZE );
961  if ( ! ena->regs ) {
962  rc = -ENODEV;
963  goto err_ioremap;
964  }
965 
966  /* Reset the NIC */
967  if ( ( rc = ena_reset ( ena ) ) != 0 )
968  goto err_reset;
969 
970  /* Create admin queues */
971  if ( ( rc = ena_create_admin ( ena ) ) != 0 )
972  goto err_create_admin;
973 
974  /* Fetch MAC address */
975  if ( ( rc = ena_get_device_attributes ( netdev ) ) != 0 )
976  goto err_get_device_attributes;
977 
978  /* Register network device */
979  if ( ( rc = register_netdev ( netdev ) ) != 0 )
980  goto err_register_netdev;
981 
982  /* Mark as link up, since we have no way to test link state on
983  * this hardware.
984  */
986 
987  return 0;
988 
990  err_register_netdev:
991  err_get_device_attributes:
992  ena_destroy_admin ( ena );
993  err_create_admin:
994  ena_reset ( ena );
995  err_reset:
996  iounmap ( ena->regs );
997  err_ioremap:
999  netdev_put ( netdev );
1000  err_alloc:
1001  return rc;
1002 }
struct ena_tx_sqe * tx
Transmit submission queue entries.
Definition: ena.h:479
static void ena_destroy_admin(struct ena_nic *ena)
Destroy admin queues.
Definition: ena.c:235
struct ena_qp rx
Receive queue.
Definition: ena.h:583
unsigned long membase
Memory base.
Definition: pci.h:200
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define ENA_RX_COUNT
Number of receive queue entries.
Definition: ena.h:31
struct ena_tx_cqe * tx
Transmit completion queue entries.
Definition: ena.h:523
static int ena_get_device_attributes(struct net_device *netdev)
Get device attributes.
Definition: ena.c:572
struct ena_qp tx
Transmit queue.
Definition: ena.h:581
union ena_sq::@39 sqe
Entries.
union ena_cq::@40 cqe
Entries.
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:149
struct device dev
Generic device.
Definition: pci.h:193
#define ENA_TX_COUNT
Number of transmit queue entries.
Definition: ena.h:28
void * regs
Registers.
Definition: ena.h:575
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:510
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:344
#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:567
Transmit.
Definition: ena.h:139
void * priv
Driver private data.
Definition: netdevice.h:431
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:780
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:899
static struct net_device_operations ena_operations
ENA network device operations.
Definition: ena.c:910
struct ena_rx_cqe * rx
Receive completion queue entries.
Definition: ena.h:525
struct ena_cq cq
Completion queue.
Definition: ena.h:569
static int ena_create_admin(struct ena_nic *ena)
Create admin queues.
Definition: ena.c:185
#define ENA_ACQ_PHASE
Admin completion queue ownership phase flag.
Definition: ena.h:103
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:722
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:523
#define ENA_BAR_SIZE
BAR size.
Definition: ena.h:16
struct ena_acq acq
Admin completion queue.
Definition: ena.h:579
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
struct ena_sq sq
Submission queue.
Definition: ena.h:567
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.
struct ena_rx_sqe * rx
Receive submission queue entries.
Definition: ena.h:481
An ENA network card.
Definition: ena.h:573
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
Receive.
Definition: ena.h:141
static int ena_reset(struct ena_nic *ena)
Reset hardware.
Definition: ena.c:101
unsigned int phase
Phase.
Definition: ena.h:396
void * memset(void *dest, int character, size_t len) __nonnull

References ena_nic::acq, adjust_pci_device(), alloc_etherdev(), ena_qp::cq, ena_cq::cqe, pci_device::dev, net_device::dev, ENA_ACQ_PHASE, ENA_BAR_SIZE, ena_create_admin(), ena_destroy_admin(), ena_get_device_attributes(), ena_operations, ena_reset(), ENA_RX_COUNT, ENA_SQ_RX, ENA_SQ_TX, ENA_TX_COUNT, ENODEV, ENOMEM, iounmap(), pci_device::membase, memset(), netdev, netdev_init(), netdev_link_up(), netdev_nullify(), netdev_put(), pci_ioremap(), pci_set_drvdata(), ena_acq::phase, net_device::priv, rc, register_netdev(), ena_nic::regs, ena_sq::rx, ena_cq::rx, ena_nic::rx, ena_qp::sq, ena_sq::sqe, ena_sq::tx, ena_cq::tx, ena_nic::tx, and unregister_netdev().

◆ ena_remove()

static void ena_remove ( struct pci_device pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 1009 of file ena.c.

1009  {
1010  struct net_device *netdev = pci_get_drvdata ( pci );
1011  struct ena_nic *ena = netdev->priv;
1012 
1013  /* Unregister network device */
1015 
1016  /* Destroy admin queues */
1017  ena_destroy_admin ( ena );
1018 
1019  /* Reset card */
1020  ena_reset ( ena );
1021 
1022  /* Free network device */
1023  iounmap ( ena->regs );
1024  netdev_nullify ( netdev );
1025  netdev_put ( netdev );
1026 }
static void ena_destroy_admin(struct ena_nic *ena)
Destroy admin queues.
Definition: ena.c:235
void * regs
Registers.
Definition: ena.h:575
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:567
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:899
A network device.
Definition: netdevice.h:352
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:523
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:354
void iounmap(volatile const void *io_addr)
Unmap I/O address.
An ENA network card.
Definition: ena.h:573
static int ena_reset(struct ena_nic *ena)
Reset hardware.
Definition: ena.c:101

References ena_destroy_admin(), ena_reset(), iounmap(), netdev, netdev_nullify(), netdev_put(), pci_get_drvdata(), net_device::priv, ena_nic::regs, and unregister_netdev().

Variable Documentation

◆ ena_operations

struct net_device_operations ena_operations
static
Initial value:
= {
.open = ena_open,
.close = ena_close,
.transmit = ena_transmit,
.poll = ena_poll,
}
static int ena_open(struct net_device *netdev)
Open network device.
Definition: ena.c:726
static void ena_close(struct net_device *netdev)
Close network device.
Definition: ena.c:755
static int ena_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: ena.c:778
static void ena_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: ena.c:897

ENA network device operations.

Definition at line 910 of file ena.c.

Referenced by ena_probe().

◆ ena_nics

struct pci_device_id ena_nics[]
static
Initial value:
= {
PCI_ROM ( 0x1d0f, 0xec20, "ena-vf", "ENA VF", 0 ),
PCI_ROM ( 0x1d0f, 0xec21, "ena-vf-llq", "ENA VF (LLQ)", 0 ),
}
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:289

ENA PCI device IDs.

Definition at line 1029 of file ena.c.

◆ __pci_driver

struct pci_driver ena_driver __pci_driver
Initial value:
= {
.ids = ena_nics,
.id_count = ( sizeof ( ena_nics ) / sizeof ( ena_nics[0] ) ),
.probe = ena_probe,
}
static void ena_remove(struct pci_device *pci)
Remove PCI device.
Definition: ena.c:1009
static int ena_probe(struct pci_device *pci)
Probe PCI device.
Definition: ena.c:930
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
static struct pci_device_id ena_nics[]
ENA PCI device IDs.
Definition: ena.c:1029

ENA PCI driver.

Definition at line 1035 of file ena.c.