1 /* 2 * Copyright (c) 2013-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 __ATH_USB_H__ 20 #define __ATH_USB_H__ 21 22 #include <linux/reboot.h> 23 24 /* 25 * There may be some pending tx frames during platform suspend. 26 * Suspend operation should be delayed until those tx frames are 27 * transferred from the host to target. This macro specifies how 28 * long suspend thread has to sleep before checking pending tx 29 * frame count. 30 */ 31 #define OL_ATH_TX_DRAIN_WAIT_DELAY 50 /* ms */ 32 /* 33 * Wait time (in unit of OL_ATH_TX_DRAIN_WAIT_DELAY) for pending 34 * tx frame completion before suspend. Refer: hif_pci_suspend() 35 */ 36 #define OL_ATH_TX_DRAIN_WAIT_CNT 10 37 38 #define CONFIG_COPY_ENGINE_SUPPORT /* TBDXXX: here for now */ 39 #define ATH_DBG_DEFAULT 0 40 #include <osdep.h> 41 #include <ol_if_athvar.h> 42 #include <athdefs.h> 43 #include "osapi_linux.h" 44 #include "hif_main.h" 45 #include "hif.h" 46 47 #define FW_REG_DUMP_CNT 60 48 49 /* Magic patterns for FW to report crash information (Rome USB) */ 50 #define FW_ASSERT_PATTERN 0x0000c600 51 #define FW_REG_PATTERN 0x0000d600 52 #define FW_REG_END_PATTERN 0x0000e600 53 #define FW_RAMDUMP_PATTERN 0x0000f600 54 #define FW_RAMDUMP_END_PATTERN 0x0000f601 55 #define FW_RAMDUMP_PATTERN_MASK 0xfffffff0 56 #define FW_RAMDUMP_DRAMSIZE 0x00098000 57 #define FW_RAMDUMP_IRAMSIZE 0x000C0000 58 #define FW_RAMDUMP_AXISIZE 0x00020000 59 60 /* FW RAM segments (Rome USB) */ 61 enum { 62 FW_RAM_SEG_DRAM, 63 FW_RAM_SEG_IRAM, 64 FW_RAM_SEG_AXI, 65 FW_RAM_SEG_CNT 66 }; 67 68 /* Allocate 384K memory to save each segment of ram dump */ 69 #define FW_RAMDUMP_SEG_SIZE 393216 70 71 /* structure to save RAM dump information */ 72 struct fw_ramdump { 73 uint32_t start_addr; 74 uint32_t length; 75 uint8_t *mem; 76 }; 77 78 /* USB Endpoint definition */ 79 enum HIF_USB_PIPE_ID { 80 HIF_TX_CTRL_PIPE = 0, 81 HIF_TX_DATA_LP_PIPE, 82 HIF_TX_DATA_MP_PIPE, 83 HIF_TX_DATA_HP_PIPE, 84 HIF_RX_CTRL_PIPE, 85 HIF_RX_DATA_PIPE, 86 HIF_RX_DATA2_PIPE, 87 HIF_RX_INT_PIPE, 88 HIF_USB_PIPE_MAX 89 }; 90 91 #define HIF_USB_PIPE_INVALID HIF_USB_PIPE_MAX 92 93 struct HIF_USB_PIPE { 94 DL_LIST urb_list_head; 95 DL_LIST urb_pending_list; 96 int32_t urb_alloc; 97 int32_t urb_cnt; 98 int32_t urb_cnt_thresh; 99 unsigned int usb_pipe_handle; 100 uint32_t flags; 101 uint8_t ep_address; 102 uint8_t logical_pipe_num; 103 struct HIF_DEVICE_USB *device; 104 uint16_t max_packet_size; 105 #ifdef HIF_USB_TASKLET 106 struct tasklet_struct io_complete_tasklet; 107 #else 108 struct work_struct io_complete_work; 109 #endif 110 struct sk_buff_head io_comp_queue; 111 struct usb_endpoint_descriptor *ep_desc; 112 int32_t urb_prestart_cnt; 113 }; 114 115 struct HIF_DEVICE_USB { 116 struct hif_softc ol_sc; 117 qdf_spinlock_t cs_lock; 118 qdf_spinlock_t tx_lock; 119 qdf_spinlock_t rx_lock; 120 qdf_spinlock_t rx_prestart_lock; 121 struct hif_msg_callbacks htc_callbacks; 122 struct usb_device *udev; 123 struct usb_interface *interface; 124 struct HIF_USB_PIPE pipes[HIF_USB_PIPE_MAX]; 125 uint8_t *diag_cmd_buffer; 126 uint8_t *diag_resp_buffer; 127 void *claimed_context; 128 A_BOOL is_bundle_enabled; 129 uint16_t rx_bundle_cnt; 130 uint32_t rx_bundle_buf_len; 131 bool rx_ctrl_pipe_supported; 132 }; 133 134 struct hif_usb_softc { 135 struct HIF_DEVICE_USB hif_hdl; 136 /* For efficiency, should be first in struct */ 137 struct device *dev; 138 struct usb_dev *pdev; 139 /* 140 * Guard changes to Target HW state and to software 141 * structures that track hardware state. 142 */ 143 u16 devid; 144 struct usb_interface *interface; 145 struct notifier_block reboot_notifier; /* default mode before reboot */ 146 u8 suspend_state; 147 u8 *fw_data; 148 u32 fw_data_len; 149 /* structure to save FW RAM dump (Rome USB) */ 150 struct fw_ramdump *ramdump[FW_RAM_SEG_CNT]; 151 uint8_t ramdump_index; 152 bool fw_ram_dumping; 153 /* enable FW self-recovery for Rome USB */ 154 bool enable_self_recovery; 155 }; 156 157 /** 158 * hif_dump_info() - dump info about all HIF pipes and endpoints 159 * @scn: pointer to hif_opaque_softc 160 * 161 * Return: none 162 */ 163 void hif_dump_info(struct hif_opaque_softc *scn); 164 165 /** 166 * hif_suspend_wow() - Send wow suspend command 167 * @scn: pointer to hif_opaque_softc 168 * 169 * Return: none 170 */ 171 void hif_suspend_wow(struct hif_opaque_softc *scn); 172 #endif /* __ATH_USB_H__ */ 173