1 /*
2  * Copyright (c) 2013-2017, 2019 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _HIF_USB_INTERNAL_H
20 #define _HIF_USB_INTERNAL_H
21 
22 #include <qdf_nbuf.h>
23 #include "a_types.h"
24 #include "athdefs.h"
25 #include "a_osapi.h"
26 #include "a_usb_defs.h"
27 #include <ol_if_athvar.h>
28 #include <linux/usb.h>
29 #include "hif.h"
30 #include "if_usb.h"
31 
32 #ifdef QCN7605_SUPPORT
33 #define TX_URB_COUNT    64
34 #else
35 #define TX_URB_COUNT    32
36 #endif
37 
38 #define RX_URB_COUNT    32
39 
40 #define HIF_USB_RX_BUFFER_SIZE  (1792 + 8)
41 #define HIF_USB_RX_BUNDLE_ONE_PKT_SIZE  (1792 + 8)
42 
43 #ifdef HIF_USB_TASKLET
44 #define HIF_USB_SCHEDULE_WORK(pipe)\
45 	tasklet_schedule(&pipe->io_complete_tasklet)
46 
47 #define HIF_USB_INIT_WORK(pipe)\
48 		tasklet_init(&pipe->io_complete_tasklet,\
49 				usb_hif_io_comp_tasklet,\
50 				(unsigned long)pipe)
51 
52 #define HIF_USB_FLUSH_WORK(pipe) flush_work(&pipe->io_complete_work)
53 #else
54 #define HIF_USB_SCHEDULE_WORK(pipe) queue_work(system_highpri_wq,\
55 		&(pipe)->io_complete_work)
56 #define HIF_USB_INIT_WORK(pipe)\
57 		INIT_WORK(&pipe->io_complete_work,\
58 				usb_hif_io_comp_work)
59 #define HIF_USB_FLUSH_WORK(pipe)
60 #endif
61 
62 /* debug masks */
63 #define USB_HIF_DEBUG_CTRL_TRANS            ATH_DEBUG_MAKE_MODULE_MASK(0)
64 #define USB_HIF_DEBUG_BULK_IN               ATH_DEBUG_MAKE_MODULE_MASK(1)
65 #define USB_HIF_DEBUG_BULK_OUT              ATH_DEBUG_MAKE_MODULE_MASK(2)
66 #define USB_HIF_DEBUG_ENUM                  ATH_DEBUG_MAKE_MODULE_MASK(3)
67 #define USB_HIF_DEBUG_DUMP_DATA             ATH_DEBUG_MAKE_MODULE_MASK(4)
68 #define USB_HIF_SUSPEND                     ATH_DEBUG_MAKE_MODULE_MASK(5)
69 #define USB_HIF_ISOC_SUPPORT                ATH_DEBUG_MAKE_MODULE_MASK(6)
70 
71 struct HIF_USB_PIPE;
72 
73 struct HIF_URB_CONTEXT {
74 	DL_LIST link;
75 	struct HIF_USB_PIPE *pipe;
76 	qdf_nbuf_t buf;
77 	struct urb *urb;
78 	struct hif_usb_send_context *send_context;
79 };
80 
81 #define HIF_USB_PIPE_FLAG_TX    (1 << 0)
82 
83 /*
84  * Data structure to record required sending context data
85  */
86 struct hif_usb_send_context {
87 	A_BOOL new_alloc;
88 	struct HIF_DEVICE_USB *hif_usb_device;
89 	qdf_nbuf_t netbuf;
90 	unsigned int transfer_id;
91 	unsigned int head_data_len;
92 };
93 
94 extern unsigned int hif_usb_disable_rxdata2;
95 
96 extern QDF_STATUS usb_hif_submit_ctrl_in(struct HIF_DEVICE_USB *macp,
97 				uint8_t req,
98 				uint16_t value,
99 				uint16_t index,
100 				void *data, uint32_t size);
101 
102 extern QDF_STATUS usb_hif_submit_ctrl_out(struct HIF_DEVICE_USB *macp,
103 					uint8_t req,
104 					uint16_t value,
105 					uint16_t index,
106 					void *data, uint32_t size);
107 
108 QDF_STATUS usb_hif_setup_pipe_resources(struct HIF_DEVICE_USB *device);
109 void usb_hif_cleanup_pipe_resources(struct HIF_DEVICE_USB *device);
110 void usb_hif_prestart_recv_pipes(struct HIF_DEVICE_USB *device);
111 void usb_hif_start_recv_pipes(struct HIF_DEVICE_USB *device);
112 void usb_hif_flush_all(struct HIF_DEVICE_USB *device);
113 void usb_hif_cleanup_transmit_urb(struct HIF_URB_CONTEXT *urb_context);
114 void usb_hif_enqueue_pending_transfer(struct HIF_USB_PIPE *pipe,
115 					struct HIF_URB_CONTEXT *urb_context);
116 void usb_hif_remove_pending_transfer(struct HIF_URB_CONTEXT *urb_context);
117 struct HIF_URB_CONTEXT *usb_hif_alloc_urb_from_pipe(struct HIF_USB_PIPE *pipe);
118 void hif_usb_device_deinit(struct hif_usb_softc *sc);
119 QDF_STATUS hif_usb_device_init(struct hif_usb_softc *sc);
120 #ifdef HIF_USB_TASKLET
121 void usb_hif_io_comp_tasklet(unsigned long context);
122 #else
123 void usb_hif_io_comp_work(struct work_struct *work);
124 #endif
125 QDF_STATUS hif_diag_write_warm_reset(struct usb_interface *interface,
126 			uint32_t address, uint32_t data);
127 #endif
128