xref: /wlan-dirver/qca-wifi-host-cmn/hif/src/usb/if_usb.h (revision c8e2987f9325baadee03d0265544a08c4a0217b0)
1 /*
2  * Copyright (c) 2013-2018 The Linux Foundation. All rights reserved.
3  *
4  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5  *
6  *
7  * Permission to use, copy, modify, and/or distribute this software for
8  * any purpose with or without fee is hereby granted, provided that the
9  * above copyright notice and this permission notice appear in all
10  * copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19  * PERFORMANCE OF THIS SOFTWARE.
20  */
21 
22 /*
23  * This file was originally distributed by Qualcomm Atheros, Inc.
24  * under proprietary terms before Copyright ownership was assigned
25  * to the Linux Foundation.
26  */
27 #ifndef __ATH_USB_H__
28 #define __ATH_USB_H__
29 
30 #include <linux/reboot.h>
31 
32 /*
33  * There may be some pending tx frames during platform suspend.
34  * Suspend operation should be delayed until those tx frames are
35  * transfered from the host to target. This macro specifies how
36  * long suspend thread has to sleep before checking pending tx
37  * frame count.
38  */
39 #define OL_ATH_TX_DRAIN_WAIT_DELAY     50	/* ms */
40 /*
41  * Wait time (in unit of OL_ATH_TX_DRAIN_WAIT_DELAY) for pending
42  * tx frame completion before suspend. Refer: hif_pci_suspend()
43  */
44 #define OL_ATH_TX_DRAIN_WAIT_CNT       10
45 
46 #define CONFIG_COPY_ENGINE_SUPPORT	/* TBDXXX: here for now */
47 #define ATH_DBG_DEFAULT   0
48 #include <osdep.h>
49 #include <ol_if_athvar.h>
50 #include <athdefs.h>
51 #include "osapi_linux.h"
52 #include "hif_main.h"
53 #include "hif.h"
54 
55 #define FW_REG_DUMP_CNT       60
56 
57 /* Magic patterns for FW to report crash information (Rome USB) */
58 #define FW_ASSERT_PATTERN       0x0000c600
59 #define FW_REG_PATTERN          0x0000d600
60 #define FW_REG_END_PATTERN      0x0000e600
61 #define FW_RAMDUMP_PATTERN      0x0000f600
62 #define FW_RAMDUMP_END_PATTERN  0x0000f601
63 #define FW_RAMDUMP_PATTERN_MASK 0xfffffff0
64 #define FW_RAMDUMP_DRAMSIZE     0x00098000
65 #define FW_RAMDUMP_IRAMSIZE     0x000C0000
66 #define FW_RAMDUMP_AXISIZE      0x00020000
67 
68 /* FW RAM segments (Rome USB) */
69 enum {
70 	FW_RAM_SEG_DRAM,
71 	FW_RAM_SEG_IRAM,
72 	FW_RAM_SEG_AXI,
73 	FW_RAM_SEG_CNT
74 };
75 
76 /* Allocate 384K memory to save each segment of ram dump */
77 #define FW_RAMDUMP_SEG_SIZE     393216
78 
79 /* structure to save RAM dump information */
80 struct fw_ramdump {
81 	uint32_t start_addr;
82 	uint32_t length;
83 	uint8_t *mem;
84 };
85 
86 /* USB Endpoint definition */
87 enum HIF_USB_PIPE_ID {
88 	HIF_TX_CTRL_PIPE = 0,
89 	HIF_TX_DATA_LP_PIPE,
90 	HIF_TX_DATA_MP_PIPE,
91 	HIF_TX_DATA_HP_PIPE,
92 	HIF_RX_CTRL_PIPE,
93 	HIF_RX_DATA_PIPE,
94 	HIF_RX_DATA2_PIPE,
95 	HIF_RX_INT_PIPE,
96 	HIF_USB_PIPE_MAX
97 };
98 
99 #define HIF_USB_PIPE_INVALID HIF_USB_PIPE_MAX
100 
101 struct HIF_USB_PIPE {
102 	DL_LIST urb_list_head;
103 	DL_LIST urb_pending_list;
104 	int32_t urb_alloc;
105 	int32_t urb_cnt;
106 	int32_t urb_cnt_thresh;
107 	unsigned int usb_pipe_handle;
108 	uint32_t flags;
109 	uint8_t ep_address;
110 	uint8_t logical_pipe_num;
111 	struct HIF_DEVICE_USB *device;
112 	uint16_t max_packet_size;
113 #ifdef HIF_USB_TASKLET
114 	struct tasklet_struct io_complete_tasklet;
115 #else
116 	struct work_struct io_complete_work;
117 #endif
118 	struct sk_buff_head io_comp_queue;
119 	struct usb_endpoint_descriptor *ep_desc;
120 	int32_t urb_prestart_cnt;
121 };
122 
123 struct HIF_DEVICE_USB {
124 	struct hif_softc ol_sc;
125 	qdf_spinlock_t cs_lock;
126 	qdf_spinlock_t tx_lock;
127 	qdf_spinlock_t rx_lock;
128 	struct hif_msg_callbacks htc_callbacks;
129 	struct usb_device *udev;
130 	struct usb_interface *interface;
131 	struct HIF_USB_PIPE pipes[HIF_USB_PIPE_MAX];
132 	uint8_t *diag_cmd_buffer;
133 	uint8_t *diag_resp_buffer;
134 	void *claimed_context;
135 	A_BOOL is_bundle_enabled;
136 	uint16_t rx_bundle_cnt;
137 	uint32_t rx_bundle_buf_len;
138 };
139 
140 struct hif_usb_softc {
141 	struct HIF_DEVICE_USB hif_hdl;
142 	/* For efficiency, should be first in struct */
143 	struct device *dev;
144 	struct usb_dev *pdev;
145 	/*
146 	 * Guard changes to Target HW state and to software
147 	 * structures that track hardware state.
148 	 */
149 	u16 devid;
150 	struct usb_interface *interface;
151 	struct notifier_block reboot_notifier;  /* default mode before reboot */
152 	u8 suspend_state;
153 	u8 *fw_data;
154 	u32 fw_data_len;
155 	/* structure to save FW RAM dump (Rome USB) */
156 	struct fw_ramdump *ramdump[FW_RAM_SEG_CNT];
157 	uint8_t ramdump_index;
158 	bool fw_ram_dumping;
159 	/* enable FW self-recovery for Rome USB */
160 	bool enable_self_recovery;
161 };
162 
163 /**
164  * hif_dump_info() - dump info about all HIF pipes and endpoints
165  * @scn: pointer to hif_opaque_softc
166  *
167  * Return: none
168  */
169 void hif_dump_info(struct hif_opaque_softc *scn);
170 
171 /**
172  * hif_suspend_wow() - Send wow suspend command
173  * @scn: pointer to hif_opaque_softc
174  *
175  * Return: none
176  */
177 void hif_suspend_wow(struct hif_opaque_softc *scn);
178 #endif /* __ATH_USB_H__ */
179