GNU Linux-libre 4.19.286-gnu1
[releases.git] / drivers / net / wireless / rsi / rsi_hal.h
1 /**
2  * Copyright (c) 2017 Redpine Signals Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef __RSI_HAL_H__
18 #define __RSI_HAL_H__
19
20 /* Device Operating modes */
21 #define DEV_OPMODE_WIFI_ALONE           1
22 #define DEV_OPMODE_BT_ALONE             4
23 #define DEV_OPMODE_BT_LE_ALONE          8
24 #define DEV_OPMODE_BT_DUAL              12
25 #define DEV_OPMODE_STA_BT               5
26 #define DEV_OPMODE_STA_BT_LE            9
27 #define DEV_OPMODE_STA_BT_DUAL          13
28 #define DEV_OPMODE_AP_BT                6
29 #define DEV_OPMODE_AP_BT_DUAL           14
30
31 #define DEV_OPMODE_PARAM_DESC           \
32         __stringify(DEV_OPMODE_WIFI_ALONE)      "[Wi-Fi alone], "       \
33         __stringify(DEV_OPMODE_BT_ALONE)        "[BT classic alone], "  \
34         __stringify(DEV_OPMODE_BT_LE_ALONE)     "[BT LE alone], "       \
35         __stringify(DEV_OPMODE_BT_DUAL)         "[BT classic + BT LE alone], " \
36         __stringify(DEV_OPMODE_STA_BT)          "[Wi-Fi STA + BT classic], " \
37         __stringify(DEV_OPMODE_STA_BT_LE)       "[Wi-Fi STA + BT LE], " \
38         __stringify(DEV_OPMODE_STA_BT_DUAL)     "[Wi-Fi STA + BT classic + BT LE], " \
39         __stringify(DEV_OPMODE_AP_BT)           "[Wi-Fi AP + BT classic], "     \
40         __stringify(DEV_OPMODE_AP_BT_DUAL)      "[Wi-Fi AP + BT classic + BT LE]"
41
42 #define FLASH_WRITE_CHUNK_SIZE          (4 * 1024)
43 #define FLASH_SECTOR_SIZE               (4 * 1024)
44
45 #define FLASH_SIZE_ADDR                 0x04000016
46 #define PING_BUFFER_ADDRESS             0x19000
47 #define PONG_BUFFER_ADDRESS             0x1a000
48 #define SWBL_REGIN                      0x41050034
49 #define SWBL_REGOUT                     0x4105003c
50 #define PING_WRITE                      0x1
51 #define PONG_WRITE                      0x2
52
53 #define BL_CMD_TIMEOUT                  2000
54 #define BL_BURN_TIMEOUT                 (50 * 1000)
55
56 #define REGIN_VALID                     0xA
57 #define REGIN_INPUT                     0xA0
58 #define REGOUT_VALID                    0xAB
59 #define REGOUT_INVALID                  (~0xAB)
60 #define CMD_PASS                        0xAA
61 #define CMD_FAIL                        0xCC
62
63 #define LOAD_HOSTED_FW                  'A'
64 #define BURN_HOSTED_FW                  'B'
65 #define PING_VALID                      'I'
66 #define PONG_VALID                      'O'
67 #define PING_AVAIL                      'I'
68 #define PONG_AVAIL                      'O'
69 #define EOF_REACHED                     'E'
70 #define CHECK_CRC                       'K'
71 #define POLLING_MODE                    'P'
72 #define CONFIG_AUTO_READ_MODE           'R'
73 #define JUMP_TO_ZERO_PC                 'J'
74 #define FW_LOADING_SUCCESSFUL           'S'
75 #define LOADING_INITIATED               '1'
76
77 #define RSI_ULP_RESET_REG               0x161
78 #define RSI_WATCH_DOG_TIMER_1           0x16c
79 #define RSI_WATCH_DOG_TIMER_2           0x16d
80 #define RSI_WATCH_DOG_DELAY_TIMER_1             0x16e
81 #define RSI_WATCH_DOG_DELAY_TIMER_2             0x16f
82 #define RSI_WATCH_DOG_TIMER_ENABLE              0x170
83
84 #define RSI_ULP_WRITE_0                 00
85 #define RSI_ULP_WRITE_2                 02
86 #define RSI_ULP_WRITE_50                50
87
88 #define RSI_RESTART_WDT                 BIT(11)
89 #define RSI_BYPASS_ULP_ON_WDT           BIT(1)
90
91 #define RSI_ULP_TIMER_ENABLE            ((0xaa000) | RSI_RESTART_WDT |  \
92                                          RSI_BYPASS_ULP_ON_WDT)
93 #define RSI_RF_SPI_PROG_REG_BASE_ADDR   0x40080000
94
95 #define RSI_GSPI_CTRL_REG0              (RSI_RF_SPI_PROG_REG_BASE_ADDR)
96 #define RSI_GSPI_CTRL_REG1              (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x2)
97 #define RSI_GSPI_DATA_REG0              (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x4)
98 #define RSI_GSPI_DATA_REG1              (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x6)
99 #define RSI_GSPI_DATA_REG2              (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x8)
100
101 #define RSI_GSPI_CTRL_REG0_VALUE                0x340
102
103 #define RSI_GSPI_DMA_MODE                       BIT(13)
104
105 #define RSI_GSPI_2_ULP                  BIT(12)
106 #define RSI_GSPI_TRIG                   BIT(7)
107 #define RSI_GSPI_READ                   BIT(6)
108 #define RSI_GSPI_RF_SPI_ACTIVE          BIT(8)
109
110 /* Boot loader commands */
111 #define SEND_RPS_FILE                   '2'
112
113 #define FW_IMAGE_MIN_ADDRESS            (68 * 1024)
114 #define MAX_FLASH_FILE_SIZE             (400 * 1024) //400K
115 #define FLASH_START_ADDRESS             16
116
117 #define COMMON_HAL_CARD_READY_IND       0x0
118
119 #define COMMAN_HAL_WAIT_FOR_CARD_READY  1
120
121 #define RSI_DEV_OPMODE_WIFI_ALONE       1
122 #define RSI_DEV_COEX_MODE_WIFI_ALONE    1
123
124 #define BBP_INFO_40MHZ 0x6
125
126 #define FW_FLASH_OFFSET                 0x820
127 #define LMAC_VER_OFFSET                 (FW_FLASH_OFFSET + 0x200)
128 #define MAX_DWORD_ALIGN_BYTES           64
129 #define RSI_COMMON_REG_SIZE             2
130
131 struct bl_header {
132         __le32 flags;
133         __le32 image_no;
134         __le32 check_sum;
135         __le32 flash_start_address;
136         __le32 flash_len;
137 } __packed;
138
139 struct ta_metadata {
140         char *name;
141         unsigned int address;
142 };
143
144 struct rsi_mgmt_desc {
145         __le16 len_qno;
146         u8 frame_type;
147         u8 misc_flags;
148         u8 xtend_desc_size;
149         u8 header_len;
150         __le16 frame_info;
151         __le16 rate_info;
152         __le16 bbp_info;
153         __le16 seq_ctrl;
154         u8 reserved2;
155         u8 sta_id;
156 } __packed;
157
158 struct rsi_data_desc {
159         __le16 len_qno;
160         u8 cfm_frame_type;
161         u8 misc_flags;
162         u8 xtend_desc_size;
163         u8 header_len;
164         __le16 frame_info;
165         __le16 rate_info;
166         __le16 bbp_info;
167         __le16 mac_flags;
168         u8 qid_tid;
169         u8 sta_id;
170 } __packed;
171
172 struct rsi_bt_desc {
173         __le16 len_qno;
174         __le16 reserved1;
175         __le32 reserved2;
176         __le32 reserved3;
177         __le16 reserved4;
178         __le16 bt_pkt_type;
179 } __packed;
180
181 int rsi_hal_device_init(struct rsi_hw *adapter);
182 int rsi_prepare_mgmt_desc(struct rsi_common *common, struct sk_buff *skb);
183 int rsi_prepare_data_desc(struct rsi_common *common, struct sk_buff *skb);
184 int rsi_prepare_beacon(struct rsi_common *common, struct sk_buff *skb);
185 int rsi_send_pkt_to_bus(struct rsi_common *common, struct sk_buff *skb);
186 int rsi_send_bt_pkt(struct rsi_common *common, struct sk_buff *skb);
187
188 #endif