1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
6 #include <linux/sbitmap.h>
7 #include <linux/spinlock_types.h>
8 #include <linux/workqueue.h>
15 struct fun_queue_alloc_req;
20 FUN_DB_INTCOAL_ENTRIES_S = 16,
21 FUN_DB_INTCOAL_ENTRIES_M = 0x7f,
22 FUN_DB_INTCOAL_USEC_S = 23,
23 FUN_DB_INTCOAL_USEC_M = 0x7f,
25 FUN_DB_IRQ_F = 1 << FUN_DB_IRQ_S,
26 FUN_DB_IRQ_ARM_S = 31,
27 FUN_DB_IRQ_ARM_F = 1U << FUN_DB_IRQ_ARM_S
30 /* Callback for asynchronous admin commands.
31 * Invoked on reception of command response.
33 typedef void (*fun_admin_callback_t)(struct fun_dev *fdev, void *rsp,
36 /* Callback for events/notifications received by an admin queue. */
37 typedef void (*fun_admin_event_cb)(struct fun_dev *fdev, void *cqe);
39 /* Callback for pending work handled by the service task. */
40 typedef void (*fun_serv_cb)(struct fun_dev *fd);
42 /* service task flags */
44 FUN_SERV_DISABLED, /* service task is disabled */
48 /* Driver state associated with a PCI function. */
52 void __iomem *bar; /* start of BAR0 mapping */
53 u32 __iomem *dbs; /* start of doorbells in BAR0 mapping */
56 struct fun_queue *admin_q;
57 struct sbitmap_queue admin_sbq;
58 struct fun_cmd_ctx *cmd_ctx;
59 fun_admin_event_cb adminq_cb;
60 bool suppress_cmds; /* if set don't write commands to SQ */
62 /* address increment between consecutive doorbells, in 4B units */
63 unsigned int db_stride;
65 /* SW versions of device registers */
66 u32 cc_reg; /* CC register */
67 u64 cap_reg; /* CAPability register */
69 unsigned int q_depth; /* max queue depth supported by device */
70 unsigned int max_qid; /* = #queues - 1, separately for SQs and CQs */
71 unsigned int kern_end_qid; /* last qid in the kernel range + 1 */
73 unsigned int fw_handle;
76 unsigned int num_irqs;
77 unsigned int irqs_avail;
78 spinlock_t irqmgr_lock;
79 unsigned long *irq_map;
81 /* The service task handles work that needs a process context */
82 struct work_struct service_task;
83 unsigned long service_flags;
87 struct fun_dev_params {
88 u8 cqe_size_log2; /* admin q CQE size */
89 u8 sqe_size_log2; /* admin q SQE size */
96 u16 min_msix; /* min vectors needed by requesting driver */
98 fun_admin_event_cb event_cb;
102 /* Return the BAR address of a doorbell. */
103 static inline u32 __iomem *fun_db_addr(const struct fun_dev *fdev,
104 unsigned int db_index)
106 return &fdev->dbs[db_index * fdev->db_stride];
109 /* Return the BAR address of an SQ doorbell. SQ and CQ DBs alternate,
110 * SQs have even DB indices.
112 static inline u32 __iomem *fun_sq_db_addr(const struct fun_dev *fdev,
115 return fun_db_addr(fdev, sqid * 2);
118 static inline u32 __iomem *fun_cq_db_addr(const struct fun_dev *fdev,
121 return fun_db_addr(fdev, cqid * 2 + 1);
124 int fun_get_res_count(struct fun_dev *fdev, enum fun_admin_op res);
125 int fun_res_destroy(struct fun_dev *fdev, enum fun_admin_op res,
126 unsigned int flags, u32 id);
127 int fun_bind(struct fun_dev *fdev, enum fun_admin_bind_type type0,
128 unsigned int id0, enum fun_admin_bind_type type1,
131 int fun_submit_admin_cmd(struct fun_dev *fdev, struct fun_admin_req_common *cmd,
132 fun_admin_callback_t cb, void *cb_data, bool wait_ok);
133 int fun_submit_admin_sync_cmd(struct fun_dev *fdev,
134 struct fun_admin_req_common *cmd, void *rsp,
135 size_t rspsize, unsigned int timeout);
137 int fun_dev_enable(struct fun_dev *fdev, struct pci_dev *pdev,
138 const struct fun_dev_params *areq, const char *name);
139 void fun_dev_disable(struct fun_dev *fdev);
141 int fun_reserve_irqs(struct fun_dev *fdev, unsigned int nirqs,
143 void fun_release_irqs(struct fun_dev *fdev, unsigned int nirqs,
146 void fun_serv_stop(struct fun_dev *fd);
147 void fun_serv_restart(struct fun_dev *fd);
148 void fun_serv_sched(struct fun_dev *fd);
150 #endif /* _FUNDEV_H */