1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
3 * Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All rights reserved.
9 #include <linux/delay.h>
10 #include <linux/device.h>
11 #include <linux/dma-mapping.h>
12 #include <linux/semaphore.h>
13 #include <linux/sched.h>
15 #include <rdma/ib_verbs.h>
17 #include "efa_common_defs.h"
18 #include "efa_admin_defs.h"
19 #include "efa_admin_cmds_defs.h"
20 #include "efa_regs_defs.h"
22 #define EFA_MAX_HANDLERS 256
24 struct efa_com_admin_cq
{
25 struct efa_admin_acq_entry
*entries
;
27 spinlock_t lock
; /* Protects ACQ */
29 u16 cc
; /* consumer counter */
33 struct efa_com_admin_sq
{
34 struct efa_admin_aq_entry
*entries
;
36 spinlock_t lock
; /* Protects ASQ */
40 u16 cc
; /* consumer counter */
41 u16 pc
; /* producer counter */
46 /* Don't use anything other than atomic64 */
47 struct efa_com_stats_admin
{
48 atomic64_t submitted_cmd
;
49 atomic64_t completed_cmd
;
50 atomic64_t no_completion
;
54 EFA_AQ_STATE_RUNNING_BIT
= 0,
55 EFA_AQ_STATE_POLLING_BIT
= 1,
58 struct efa_com_admin_queue
{
61 struct efa_comp_ctx
*comp_ctx
;
62 u32 completion_timeout
; /* usecs */
63 u16 poll_interval
; /* msecs */
65 struct efa_com_admin_cq cq
;
66 struct efa_com_admin_sq sq
;
71 /* Count the number of available admin commands */
72 struct semaphore avail_cmds
;
74 struct efa_com_stats_admin stats
;
76 spinlock_t comp_ctx_lock
; /* Protects completion context pool */
78 u16 comp_ctx_pool_next
;
81 struct efa_aenq_handlers
;
84 struct efa_admin_aenq_entry
*entries
;
85 struct efa_aenq_handlers
*aenq_handlers
;
87 u32 cc
; /* consumer counter */
93 struct efa_com_mmio_read
{
94 struct efa_admin_mmio_req_read_less_resp
*read_resp
;
95 dma_addr_t read_resp_dma_addr
;
97 u16 mmio_read_timeout
; /* usecs */
98 /* serializes mmio reads */
103 struct efa_com_admin_queue aq
;
104 struct efa_com_aenq aenq
;
108 u32 supported_features
;
111 struct efa_com_mmio_read mmio_read
;
114 typedef void (*efa_aenq_handler
)(void *data
,
115 struct efa_admin_aenq_entry
*aenq_e
);
117 /* Holds aenq handlers. Indexed by AENQ event group */
118 struct efa_aenq_handlers
{
119 efa_aenq_handler handlers
[EFA_MAX_HANDLERS
];
120 efa_aenq_handler unimplemented_handler
;
123 int efa_com_admin_init(struct efa_com_dev
*edev
,
124 struct efa_aenq_handlers
*aenq_handlers
);
125 void efa_com_admin_destroy(struct efa_com_dev
*edev
);
126 int efa_com_dev_reset(struct efa_com_dev
*edev
,
127 enum efa_regs_reset_reason_types reset_reason
);
128 void efa_com_set_admin_polling_mode(struct efa_com_dev
*edev
, bool polling
);
129 void efa_com_admin_q_comp_intr_handler(struct efa_com_dev
*edev
);
130 int efa_com_mmio_reg_read_init(struct efa_com_dev
*edev
);
131 void efa_com_mmio_reg_read_destroy(struct efa_com_dev
*edev
);
133 int efa_com_validate_version(struct efa_com_dev
*edev
);
134 int efa_com_get_dma_width(struct efa_com_dev
*edev
);
136 int efa_com_cmd_exec(struct efa_com_admin_queue
*aq
,
137 struct efa_admin_aq_entry
*cmd
,
139 struct efa_admin_acq_entry
*comp
,
141 void efa_com_aenq_intr_handler(struct efa_com_dev
*edev
, void *data
);
143 #endif /* _EFA_COM_H_ */