0001
0002
0003 #ifndef _FUNDEV_H
0004 #define _FUNDEV_H
0005
0006 #include <linux/sbitmap.h>
0007 #include <linux/spinlock_types.h>
0008 #include <linux/workqueue.h>
0009 #include "fun_hci.h"
0010
0011 struct pci_dev;
0012 struct fun_dev;
0013 struct fun_queue;
0014 struct fun_cmd_ctx;
0015 struct fun_queue_alloc_req;
0016
0017
0018 enum {
0019 FUN_DB_QIDX_S = 0,
0020 FUN_DB_INTCOAL_ENTRIES_S = 16,
0021 FUN_DB_INTCOAL_ENTRIES_M = 0x7f,
0022 FUN_DB_INTCOAL_USEC_S = 23,
0023 FUN_DB_INTCOAL_USEC_M = 0x7f,
0024 FUN_DB_IRQ_S = 30,
0025 FUN_DB_IRQ_F = 1 << FUN_DB_IRQ_S,
0026 FUN_DB_IRQ_ARM_S = 31,
0027 FUN_DB_IRQ_ARM_F = 1U << FUN_DB_IRQ_ARM_S
0028 };
0029
0030
0031
0032
0033 typedef void (*fun_admin_callback_t)(struct fun_dev *fdev, void *rsp,
0034 void *cb_data);
0035
0036
0037 typedef void (*fun_admin_event_cb)(struct fun_dev *fdev, void *cqe);
0038
0039
0040 typedef void (*fun_serv_cb)(struct fun_dev *fd);
0041
0042
0043 enum {
0044 FUN_SERV_DISABLED,
0045 FUN_SERV_FIRST_AVAIL
0046 };
0047
0048
0049 struct fun_dev {
0050 struct device *dev;
0051
0052 void __iomem *bar;
0053 u32 __iomem *dbs;
0054
0055
0056 struct fun_queue *admin_q;
0057 struct sbitmap_queue admin_sbq;
0058 struct fun_cmd_ctx *cmd_ctx;
0059 fun_admin_event_cb adminq_cb;
0060 bool suppress_cmds;
0061
0062
0063 unsigned int db_stride;
0064
0065
0066 u32 cc_reg;
0067 u64 cap_reg;
0068
0069 unsigned int q_depth;
0070 unsigned int max_qid;
0071 unsigned int kern_end_qid;
0072
0073 unsigned int fw_handle;
0074
0075
0076 unsigned int num_irqs;
0077 unsigned int irqs_avail;
0078 spinlock_t irqmgr_lock;
0079 unsigned long *irq_map;
0080
0081
0082 struct work_struct service_task;
0083 unsigned long service_flags;
0084 fun_serv_cb serv_cb;
0085 };
0086
0087 struct fun_dev_params {
0088 u8 cqe_size_log2;
0089 u8 sqe_size_log2;
0090
0091
0092 u16 cq_depth;
0093 u16 sq_depth;
0094 u16 rq_depth;
0095
0096 u16 min_msix;
0097
0098 fun_admin_event_cb event_cb;
0099 fun_serv_cb serv_cb;
0100 };
0101
0102
0103 static inline u32 __iomem *fun_db_addr(const struct fun_dev *fdev,
0104 unsigned int db_index)
0105 {
0106 return &fdev->dbs[db_index * fdev->db_stride];
0107 }
0108
0109
0110
0111
0112 static inline u32 __iomem *fun_sq_db_addr(const struct fun_dev *fdev,
0113 unsigned int sqid)
0114 {
0115 return fun_db_addr(fdev, sqid * 2);
0116 }
0117
0118 static inline u32 __iomem *fun_cq_db_addr(const struct fun_dev *fdev,
0119 unsigned int cqid)
0120 {
0121 return fun_db_addr(fdev, cqid * 2 + 1);
0122 }
0123
0124 int fun_get_res_count(struct fun_dev *fdev, enum fun_admin_op res);
0125 int fun_res_destroy(struct fun_dev *fdev, enum fun_admin_op res,
0126 unsigned int flags, u32 id);
0127 int fun_bind(struct fun_dev *fdev, enum fun_admin_bind_type type0,
0128 unsigned int id0, enum fun_admin_bind_type type1,
0129 unsigned int id1);
0130
0131 int fun_submit_admin_cmd(struct fun_dev *fdev, struct fun_admin_req_common *cmd,
0132 fun_admin_callback_t cb, void *cb_data, bool wait_ok);
0133 int fun_submit_admin_sync_cmd(struct fun_dev *fdev,
0134 struct fun_admin_req_common *cmd, void *rsp,
0135 size_t rspsize, unsigned int timeout);
0136
0137 int fun_dev_enable(struct fun_dev *fdev, struct pci_dev *pdev,
0138 const struct fun_dev_params *areq, const char *name);
0139 void fun_dev_disable(struct fun_dev *fdev);
0140
0141 int fun_reserve_irqs(struct fun_dev *fdev, unsigned int nirqs,
0142 u16 *irq_indices);
0143 void fun_release_irqs(struct fun_dev *fdev, unsigned int nirqs,
0144 u16 *irq_indices);
0145
0146 void fun_serv_stop(struct fun_dev *fd);
0147 void fun_serv_restart(struct fun_dev *fd);
0148 void fun_serv_sched(struct fun_dev *fd);
0149
0150 #endif