USB: add SPDX identifiers to all remaining files in drivers/usb/
[linux-2.6-block.git] / drivers / usb / host / whci / whcd.h
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Wireless Host Controller (WHC) private header.
4  *
5  * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License version
9  * 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 #ifndef __WHCD_H
22 #define __WHCD_H
23
24 #include <linux/uwb/whci.h>
25 #include <linux/uwb/umc.h>
26 #include <linux/workqueue.h>
27
28 #include "whci-hc.h"
29
30 /* Generic command timeout. */
31 #define WHC_GENCMD_TIMEOUT_MS 100
32
33 struct whc_dbg;
34
35 struct whc {
36         struct wusbhc wusbhc;
37         struct umc_dev *umc;
38
39         resource_size_t base_phys;
40         void __iomem *base;
41         int irq;
42
43         u8 n_devices;
44         u8 n_keys;
45         u8 n_mmc_ies;
46
47         u64 *pz_list;
48         struct dn_buf_entry *dn_buf;
49         struct di_buf_entry *di_buf;
50         dma_addr_t pz_list_dma;
51         dma_addr_t dn_buf_dma;
52         dma_addr_t di_buf_dma;
53
54         spinlock_t   lock;
55         struct mutex mutex;
56
57         void *            gen_cmd_buf;
58         dma_addr_t        gen_cmd_buf_dma;
59         wait_queue_head_t cmd_wq;
60
61         struct workqueue_struct *workqueue;
62         struct work_struct       dn_work;
63
64         struct dma_pool *qset_pool;
65
66         struct list_head async_list;
67         struct list_head async_removed_list;
68         wait_queue_head_t async_list_wq;
69         struct work_struct async_work;
70
71         struct list_head periodic_list[5];
72         struct list_head periodic_removed_list;
73         wait_queue_head_t periodic_list_wq;
74         struct work_struct periodic_work;
75
76         struct whc_dbg *dbg;
77 };
78
79 #define wusbhc_to_whc(w) (container_of((w), struct whc, wusbhc))
80
81 /**
82  * struct whc_std - a software TD.
83  * @urb: the URB this sTD is for.
84  * @offset: start of the URB's data for this TD.
85  * @len: the length of data in the associated TD.
86  * @ntds_remaining: number of TDs (starting from this one) in this transfer.
87  *
88  * @bounce_buf: a bounce buffer if the std was from an urb with a sg
89  * list that could not be mapped to qTDs directly.
90  * @bounce_sg: the first scatterlist element bounce_buf is for.
91  * @bounce_offset: the offset into bounce_sg for the start of bounce_buf.
92  *
93  * Queued URBs may require more TDs than are available in a qset so we
94  * use a list of these "software TDs" (sTDs) to hold per-TD data.
95  */
96 struct whc_std {
97         struct urb *urb;
98         size_t len;
99         int    ntds_remaining;
100         struct whc_qtd *qtd;
101
102         struct list_head list_node;
103         int num_pointers;
104         dma_addr_t dma_addr;
105         struct whc_page_list_entry *pl_virt;
106
107         void *bounce_buf;
108         struct scatterlist *bounce_sg;
109         unsigned bounce_offset;
110 };
111
112 /**
113  * struct whc_urb - per URB host controller structure.
114  * @urb: the URB this struct is for.
115  * @qset: the qset associated to the URB.
116  * @dequeue_work: the work to remove the URB when dequeued.
117  * @is_async: the URB belongs to async sheduler or not.
118  * @status: the status to be returned when calling wusbhc_giveback_urb.
119  */
120 struct whc_urb {
121         struct urb *urb;
122         struct whc_qset *qset;
123         struct work_struct dequeue_work;
124         bool is_async;
125         int status;
126 };
127
128 /**
129  * whc_std_last - is this sTD the URB's last?
130  * @std: the sTD to check.
131  */
132 static inline bool whc_std_last(struct whc_std *std)
133 {
134         return std->ntds_remaining <= 1;
135 }
136
137 enum whc_update {
138         WHC_UPDATE_ADDED   = 0x01,
139         WHC_UPDATE_REMOVED = 0x02,
140         WHC_UPDATE_UPDATED = 0x04,
141 };
142
143 /* init.c */
144 int whc_init(struct whc *whc);
145 void whc_clean_up(struct whc *whc);
146
147 /* hw.c */
148 void whc_write_wusbcmd(struct whc *whc, u32 mask, u32 val);
149 int whc_do_gencmd(struct whc *whc, u32 cmd, u32 params, void *addr, size_t len);
150 void whc_hw_error(struct whc *whc, const char *reason);
151
152 /* wusb.c */
153 int whc_wusbhc_start(struct wusbhc *wusbhc);
154 void whc_wusbhc_stop(struct wusbhc *wusbhc, int delay);
155 int whc_mmcie_add(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt,
156                   u8 handle, struct wuie_hdr *wuie);
157 int whc_mmcie_rm(struct wusbhc *wusbhc, u8 handle);
158 int whc_bwa_set(struct wusbhc *wusbhc, s8 stream_index, const struct uwb_mas_bm *mas_bm);
159 int whc_dev_info_set(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev);
160 int whc_set_num_dnts(struct wusbhc *wusbhc, u8 interval, u8 slots);
161 int whc_set_ptk(struct wusbhc *wusbhc, u8 port_idx, u32 tkid,
162                 const void *ptk, size_t key_size);
163 int whc_set_gtk(struct wusbhc *wusbhc, u32 tkid,
164                 const void *gtk, size_t key_size);
165 int whc_set_cluster_id(struct whc *whc, u8 bcid);
166
167 /* int.c */
168 irqreturn_t whc_int_handler(struct usb_hcd *hcd);
169 void whc_dn_work(struct work_struct *work);
170
171 /* asl.c */
172 void asl_start(struct whc *whc);
173 void asl_stop(struct whc *whc);
174 int  asl_init(struct whc *whc);
175 void asl_clean_up(struct whc *whc);
176 int  asl_urb_enqueue(struct whc *whc, struct urb *urb, gfp_t mem_flags);
177 int  asl_urb_dequeue(struct whc *whc, struct urb *urb, int status);
178 void asl_qset_delete(struct whc *whc, struct whc_qset *qset);
179 void scan_async_work(struct work_struct *work);
180
181 /* pzl.c */
182 int  pzl_init(struct whc *whc);
183 void pzl_clean_up(struct whc *whc);
184 void pzl_start(struct whc *whc);
185 void pzl_stop(struct whc *whc);
186 int  pzl_urb_enqueue(struct whc *whc, struct urb *urb, gfp_t mem_flags);
187 int  pzl_urb_dequeue(struct whc *whc, struct urb *urb, int status);
188 void pzl_qset_delete(struct whc *whc, struct whc_qset *qset);
189 void scan_periodic_work(struct work_struct *work);
190
191 /* qset.c */
192 struct whc_qset *qset_alloc(struct whc *whc, gfp_t mem_flags);
193 void qset_free(struct whc *whc, struct whc_qset *qset);
194 struct whc_qset *get_qset(struct whc *whc, struct urb *urb, gfp_t mem_flags);
195 void qset_delete(struct whc *whc, struct whc_qset *qset);
196 void qset_clear(struct whc *whc, struct whc_qset *qset);
197 void qset_reset(struct whc *whc, struct whc_qset *qset);
198 int qset_add_urb(struct whc *whc, struct whc_qset *qset, struct urb *urb,
199                  gfp_t mem_flags);
200 void qset_free_std(struct whc *whc, struct whc_std *std);
201 void qset_remove_urb(struct whc *whc, struct whc_qset *qset,
202                             struct urb *urb, int status);
203 void process_halted_qtd(struct whc *whc, struct whc_qset *qset,
204                                struct whc_qtd *qtd);
205 void process_inactive_qtd(struct whc *whc, struct whc_qset *qset,
206                                  struct whc_qtd *qtd);
207 enum whc_update qset_add_qtds(struct whc *whc, struct whc_qset *qset);
208 void qset_remove_complete(struct whc *whc, struct whc_qset *qset);
209 void pzl_update(struct whc *whc, uint32_t wusbcmd);
210 void asl_update(struct whc *whc, uint32_t wusbcmd);
211
212 /* debug.c */
213 void whc_dbg_init(struct whc *whc);
214 void whc_dbg_clean_up(struct whc *whc);
215
216 #endif /* #ifndef __WHCD_H */