forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/dhd_cdc.c
....@@ -1,15 +1,16 @@
1
-/* SPDX-License-Identifier: GPL-2.0 */
21 /*
32 * DHD Protocol Module for CDC and BDC.
43 *
5
- * Copyright (C) 1999-2019, Broadcom Corporation
6
- *
4
+ * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation
5
+ *
6
+ * Copyright (C) 1999-2017, Broadcom Corporation
7
+ *
78 * Unless you and Broadcom execute a separate written software license
89 * agreement governing use of this software, this software is licensed to you
910 * under the terms of the GNU General Public License version 2 (the "GPL"),
1011 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
1112 * following added to such license:
12
- *
13
+ *
1314 * As a special exception, the copyright holders of this software give you
1415 * permission to link this software with independent modules, and to copy and
1516 * distribute the resulting executable under terms of your choice, provided that
....@@ -17,7 +18,7 @@
1718 * the license of that module. An independent module is a module which is not
1819 * derived from this software. The special exception does not apply to any
1920 * modifications of the software.
20
- *
21
+ *
2122 * Notwithstanding the above, under no circumstances may you combine this
2223 * software in any way with any other Broadcom software provided under a license
2324 * other than the GPL, without Broadcom's express prior written consent.
....@@ -25,7 +26,7 @@
2526 *
2627 * <<Broadcom-WL-IPTag/Open:>>
2728 *
28
- * $Id: dhd_cdc.c 708487 2018-10-31 05:33:14Z $
29
+ * $Id: dhd_cdc.c 692135 2017-03-26 17:19:39Z $
2930 *
3031 * BDC is like CDC, except it includes a header for data packets to convey
3132 * packet priority over the bus, and flags (e.g. to indicate checksum status
....@@ -42,27 +43,17 @@
4243 #include <dngl_stats.h>
4344 #include <dhd.h>
4445 #include <dhd_proto.h>
45
-#ifdef BCMDBUS
46
-#include <dbus.h>
47
-#else
4846 #include <dhd_bus.h>
49
-#endif /* BCMDBUS */
5047 #include <dhd_dbg.h>
51
-
5248
5349 #ifdef PROP_TXSTATUS
5450 #include <wlfc_proto.h>
5551 #include <dhd_wlfc.h>
56
-#endif
57
-
58
-#ifdef LOAD_DHD_WITH_FW_ALIVE
59
-#include <dhd_chip_info.h>
60
-#endif
52
+#endif // endif
6153
6254 #ifdef DHD_ULP
6355 #include <dhd_ulp.h>
6456 #endif /* DHD_ULP */
65
-
6657
6758 #define RETRIES 2 /* # of retries to retrieve matching ioctl response */
6859 #define BUS_HEADER_LEN (24+DHD_SDALIGN) /* Must be at least SDPCM_RESERVE
....@@ -77,24 +68,21 @@
7768 uint16 reqid;
7869 uint8 pending;
7970 uint32 lastcmd;
80
-#ifdef BCMDBUS
81
- uint ctl_completed;
82
-#endif
8371 uint8 bus_header[BUS_HEADER_LEN];
8472 cdc_ioctl_t msg;
8573 unsigned char buf[WLC_IOCTL_MAXLEN + ROUND_UP_MARGIN];
8674 } dhd_prot_t;
8775
88
-#if defined(BCMDBUS)
89
-extern int dhd_dbus_txdata(dhd_pub_t *dhdp, void *pktbuf);
90
-#endif
76
+uint16
77
+dhd_prot_get_ioctl_trans_id(dhd_pub_t *dhdp)
78
+{
79
+ /* SDIO does not have ioctl_trans_id yet, so return -1 */
80
+ return -1;
81
+}
9182
9283 static int
9384 dhdcdc_msg(dhd_pub_t *dhd)
9485 {
95
-#ifdef BCMDBUS
96
- int timeout = 0;
97
-#endif /* BCMDBUS */
9886 int err = 0;
9987 dhd_prot_t *prot = dhd->prot;
10088 int len = ltoh32(prot->msg.len) + sizeof(cdc_ioctl_t);
....@@ -111,51 +99,8 @@
11199 len = CDC_MAX_MSG_SIZE;
112100
113101 /* Send request */
114
-#ifdef BCMDBUS
115
- DHD_OS_IOCTL_RESP_LOCK(dhd);
116
- prot->ctl_completed = FALSE;
117
- err = dbus_send_ctl(dhd->dbus, (void *)&prot->msg, len);
118
- if (err) {
119
- DHD_ERROR(("dbus_send_ctl error=0x%x\n", err));
120
- DHD_OS_IOCTL_RESP_UNLOCK(dhd);
121
- DHD_OS_WAKE_UNLOCK(dhd);
122
- return err;
123
- }
124
-#else
125102 err = dhd_bus_txctl(dhd->bus, (uchar*)&prot->msg, len);
126
-#endif
127103
128
-#ifdef BCMDBUS
129
- timeout = dhd_os_ioctl_resp_wait(dhd, &prot->ctl_completed);
130
- if ((!timeout) || (!prot->ctl_completed)) {
131
- DHD_ERROR(("Txctl timeout %d ctl_completed %d\n",
132
- timeout, prot->ctl_completed));
133
- DHD_ERROR(("Txctl wait timed out\n"));
134
- err = -1;
135
- }
136
- DHD_OS_IOCTL_RESP_UNLOCK(dhd);
137
-#endif
138
-#if defined(BCMDBUS) && defined(INTR_EP_ENABLE)
139
- /* If the ctl write is successfully completed, wait for an acknowledgement
140
- * that indicates that it is now ok to do ctl read from the dongle
141
- */
142
- if (err != -1) {
143
- DHD_OS_IOCTL_RESP_LOCK(dhd);
144
- prot->ctl_completed = FALSE;
145
- if (dbus_poll_intr(dhd->dbus)) {
146
- DHD_ERROR(("dbus_poll_intr not submitted\n"));
147
- } else {
148
- /* interrupt polling is sucessfully submitted. Wait for dongle to send
149
- * interrupt
150
- */
151
- timeout = dhd_os_ioctl_resp_wait(dhd, &prot->ctl_completed);
152
- if (!timeout) {
153
- DHD_ERROR(("intr poll wait timed out\n"));
154
- }
155
- }
156
- DHD_OS_IOCTL_RESP_UNLOCK(dhd);
157
- }
158
-#endif /* defined(BCMDBUS) && defined(INTR_EP_ENABLE) */
159104 DHD_OS_WAKE_UNLOCK(dhd);
160105 return err;
161106 }
....@@ -163,49 +108,18 @@
163108 static int
164109 dhdcdc_cmplt(dhd_pub_t *dhd, uint32 id, uint32 len)
165110 {
166
-#ifdef BCMDBUS
167
- int timeout = 0;
168
-#endif /* BCMDBUS */
169111 int ret;
170112 int cdc_len = len + sizeof(cdc_ioctl_t);
171113 dhd_prot_t *prot = dhd->prot;
172114
173115 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
174116
175
-
176117 do {
177
-#ifdef BCMDBUS
178
- DHD_OS_IOCTL_RESP_LOCK(dhd);
179
- prot->ctl_completed = FALSE;
180
- ret = dbus_recv_ctl(dhd->dbus, (uchar*)&prot->msg, cdc_len);
181
- if (ret) {
182
- DHD_ERROR(("dbus_recv_ctl error=0x%x(%d)\n", ret, ret));
183
- DHD_OS_IOCTL_RESP_UNLOCK(dhd);
184
- goto done;
185
- }
186
- timeout = dhd_os_ioctl_resp_wait(dhd, &prot->ctl_completed);
187
- if ((!timeout) || (!prot->ctl_completed)) {
188
- DHD_ERROR(("Rxctl timeout %d ctl_completed %d\n",
189
- timeout, prot->ctl_completed));
190
- ret = -1;
191
- DHD_OS_IOCTL_RESP_UNLOCK(dhd);
192
-
193
- goto done;
194
- }
195
- DHD_OS_IOCTL_RESP_UNLOCK(dhd);
196
-
197
- ret = cdc_len;
198
-#else
199118 ret = dhd_bus_rxctl(dhd->bus, (uchar*)&prot->msg, cdc_len);
200
-#endif /* BCMDBUS */
201119 if (ret < 0)
202120 break;
203121 } while (CDC_IOC_ID(ltoh32(prot->msg.flags)) != id);
204122
205
-
206
-#ifdef BCMDBUS
207
-done:
208
-#endif /* BCMDBUS */
209123 return ret;
210124 }
211125
....@@ -219,7 +133,6 @@
219133
220134 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
221135 DHD_CTL(("%s: cmd %d len %d\n", __FUNCTION__, cmd, len));
222
-
223136
224137 /* Respond "bcmerror" and "bcmerrorstr" with local cache */
225138 if (cmd == WLC_GET_VAR && buf)
....@@ -238,6 +151,24 @@
238151
239152 memset(msg, 0, sizeof(cdc_ioctl_t));
240153
154
+#ifdef BCMSPI
155
+ /* 11bit gSPI bus allows 2048bytes of max-data. We restrict 'len'
156
+ * value which is 8Kbytes for various 'get' commands to 2000. 48 bytes are
157
+ * left for sw headers and misc.
158
+ */
159
+
160
+ if (len > 2000) {
161
+ DHD_ERROR(("dhdcdc_query_ioctl: len is truncated to 2000 bytes\n"));
162
+ len = 2000;
163
+ }
164
+#ifdef BCMQT
165
+ /* WAR: packet length limited for SPI host issue in FIFO mode on Zebu */
166
+ if (len > 460) {
167
+ DHD_ERROR(("len is truncated to 460 bytes on Zebu\n"));
168
+ len = 460;
169
+ }
170
+#endif /* BCMQT */
171
+#endif /* BCMSPI */
241172 msg->cmd = htol32(cmd);
242173 msg->len = htol32(len);
243174 msg->flags = (++prot->reqid << CDCF_IOC_ID_SHIFT);
....@@ -293,6 +224,9 @@
293224 return ret;
294225 }
295226
227
+#ifdef DHD_PM_CONTROL_FROM_FILE
228
+extern bool g_pm_control;
229
+#endif /* DHD_PM_CONTROL_FROM_FILE */
296230
297231 static int
298232 dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len, uint8 action)
....@@ -317,6 +251,24 @@
317251 return -EIO;
318252 }
319253
254
+ if (cmd == WLC_SET_PM) {
255
+#ifdef DHD_PM_CONTROL_FROM_FILE
256
+ if (g_pm_control == TRUE) {
257
+ DHD_ERROR(("%s: SET PM ignored!(Requested:%d)\n",
258
+ __FUNCTION__, buf ? *(char *)buf : 0));
259
+ goto done;
260
+ }
261
+#endif /* DHD_PM_CONTROL_FROM_FILE */
262
+#if defined(WLAIBSS)
263
+ if (dhd->op_mode == DHD_FLAG_IBSS_MODE) {
264
+ DHD_ERROR(("%s: SET PM ignored for IBSS!(Requested:%d)\n",
265
+ __FUNCTION__, buf ? *(char *)buf : 0));
266
+ goto done;
267
+ }
268
+#endif /* WLAIBSS */
269
+ DHD_TRACE_HW4(("%s: SET PM to %d\n", __FUNCTION__, buf ? *(char *)buf : 0));
270
+ }
271
+
320272 memset(msg, 0, sizeof(cdc_ioctl_t));
321273
322274 msg->cmd = htol32(cmd);
....@@ -332,8 +284,7 @@
332284 memcpy(prot->buf, buf, len);
333285
334286 #ifdef DHD_ULP
335
- if (buf && (!strncmp(buf, "wowl_force", sizeof("wowl_force")) ||
336
- !strncmp(buf, "ulp", sizeof("ulp")))) {
287
+ if (buf && (!strncmp(buf, "ulp", sizeof("ulp")))) {
337288 /* force all the writes after this point to NOT to use cached sbwad value */
338289 dhd_ulp_disable_cached_sbwad(dhd);
339290 }
....@@ -375,26 +326,6 @@
375326 return ret;
376327 }
377328
378
-#ifdef BCMDBUS
379
-int
380
-dhd_prot_ctl_complete(dhd_pub_t *dhd)
381
-{
382
- dhd_prot_t *prot;
383
-
384
- if (dhd == NULL)
385
- return BCME_ERROR;
386
-
387
- prot = dhd->prot;
388
-
389
- ASSERT(prot);
390
- DHD_OS_IOCTL_RESP_LOCK(dhd);
391
- prot->ctl_completed = TRUE;
392
- dhd_os_ioctl_resp_wake(dhd);
393
- DHD_OS_IOCTL_RESP_UNLOCK(dhd);
394
- return 0;
395
-}
396
-#endif /* BCMDBUS */
397
-
398329 int
399330 dhd_prot_ioctl(dhd_pub_t *dhd, int ifidx, wl_ioctl_t * ioc, void * buf, int len)
400331 {
....@@ -403,7 +334,8 @@
403334 uint8 action;
404335
405336 if ((dhd->busstate == DHD_BUS_DOWN) || dhd->hang_was_sent) {
406
- DHD_ERROR(("%s : bus is down. we have nothing to do\n", __FUNCTION__));
337
+ DHD_ERROR(("%s : bus is down. we have nothing to do - bs: %d, has: %d\n",
338
+ __FUNCTION__, dhd->busstate, dhd->hang_was_sent));
407339 goto done;
408340 }
409341
....@@ -419,7 +351,7 @@
419351 ioc->cmd, (unsigned long)ioc->cmd, prot->lastcmd,
420352 (unsigned long)prot->lastcmd));
421353 if ((ioc->cmd == WLC_SET_VAR) || (ioc->cmd == WLC_GET_VAR)) {
422
- DHD_TRACE(("iovar cmd=%s\n", (char*)buf));
354
+ DHD_TRACE(("iovar cmd=%s\n", buf ? (char*)buf : "\0"));
423355 }
424356 goto done;
425357 }
....@@ -477,7 +409,7 @@
477409 bcm_bprintf(strbuf, "Protocol CDC: reqid %d\n", dhdp->prot->reqid);
478410 #ifdef PROP_TXSTATUS
479411 dhd_wlfc_dump(dhdp, strbuf);
480
-#endif
412
+#endif // endif
481413 }
482414
483415 /* The FreeBSD PKTPUSH could change the packet buf pinter
....@@ -504,7 +436,6 @@
504436 if (PKTSUMNEEDED(PKTBUF))
505437 h->flags |= BDC_FLAG_SUM_NEEDED;
506438
507
-
508439 h->priority = (PKTPRIO(PKTBUF) & BDC_PRIORITY_MASK);
509440 h->flags2 = 0;
510441 h->dataOffset = 0;
....@@ -520,7 +451,7 @@
520451 #ifdef BDC
521452 /* Length of BDC(+WLFC) headers pushed */
522453 hdrlen = BDC_HEADER_LEN + (((struct bdc_header *)PKTBUF)->dataOffset * 4);
523
-#endif
454
+#endif // endif
524455 return hdrlen;
525456 }
526457
....@@ -530,7 +461,7 @@
530461 {
531462 #ifdef BDC
532463 struct bdc_header *h;
533
-#endif
464
+#endif // endif
534465 uint8 data_offset = 0;
535466
536467 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
....@@ -577,7 +508,6 @@
577508 PKTPULL(dhd->osh, pktbuf, BDC_HEADER_LEN);
578509 #endif /* BDC */
579510
580
-
581511 #ifdef PROP_TXSTATUS
582512 if (!DHD_PKTTAG_PKTDIR(PKTTAG(pktbuf))) {
583513 /*
....@@ -586,12 +516,6 @@
586516 dhd_wlfc_parse_header_info(dhd, pktbuf, (data_offset << 2),
587517 reorder_buf_info, reorder_info_len);
588518
589
-#ifdef BCMDBUS
590
-#ifndef DHD_WLFC_THREAD
591
- dhd_wlfc_commit_packets(dhd,
592
- (f_commitpkt_t)dhd_dbus_txdata, (void *)dhd, NULL, FALSE);
593
-#endif /* DHD_WLFC_THREAD */
594
-#endif /* BCMDBUS */
595519 }
596520 #endif /* PROP_TXSTATUS */
597521
....@@ -599,7 +523,6 @@
599523 PKTPULL(dhd->osh, pktbuf, (data_offset << 2));
600524 return 0;
601525 }
602
-
603526
604527 int
605528 dhd_prot_attach(dhd_pub_t *dhd)
....@@ -621,7 +544,7 @@
621544 dhd->prot = cdc;
622545 #ifdef BDC
623546 dhd->hdrlen += BDC_HEADER_LEN;
624
-#endif
547
+#endif // endif
625548 dhd->maxctl = WLC_IOCTL_MAXLEN + sizeof(cdc_ioctl_t) + ROUND_UP_MARGIN;
626549 return 0;
627550
....@@ -637,7 +560,7 @@
637560 {
638561 #ifdef PROP_TXSTATUS
639562 dhd_wlfc_deinit(dhd);
640
-#endif
563
+#endif // endif
641564 DHD_OS_PREFREE(dhd, dhd->prot, sizeof(dhd_prot_t));
642565 dhd->prot = NULL;
643566 }
....@@ -661,30 +584,39 @@
661584 {
662585 int ret = 0;
663586 wlc_rev_info_t revinfo;
587
+#ifndef OEM_ANDROID
588
+ char buf[128];
589
+#endif /* OEM_ANDROID */
664590 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
665591
666
-#ifdef LOAD_DHD_WITH_FW_ALIVE
667
- if(alive == FW_ALIVE_MAGIC) {
668
- ret = dhd_preinit_ioctls_alive(dhd);
669
- } else
670
-#endif /* LOAD_DHD_WITH_FW_ALIVE */
671
- {
672
- /* Get the device rev info */
673
- memset(&revinfo, 0, sizeof(revinfo));
674
- ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_REVINFO, &revinfo, sizeof(revinfo), FALSE, 0);
675
- if (ret < 0)
676
- goto done;
592
+#ifndef OEM_ANDROID
593
+ /* Get the device MAC address */
594
+ strcpy(buf, "cur_etheraddr");
595
+ ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, buf, sizeof(buf), FALSE, 0);
596
+ if (ret < 0)
597
+ goto done;
598
+ memcpy(dhd->mac.octet, buf, ETHER_ADDR_LEN);
599
+#endif /* OEM_ANDROID */
600
+#ifdef DHD_FW_COREDUMP
601
+ /* Check the memdump capability */
602
+ dhd_get_memdump_info(dhd);
603
+#endif /* DHD_FW_COREDUMP */
677604
678
-#if defined(BCMDBUS) && defined(BCMDHDUSB)
679
- /* dbus_set_revinfo(dhd->dbus, revinfo.chipnum, revinfo.chiprev); */
680
-#endif /* BCMDBUS && BCMDHDUSB */
605
+#ifdef BCMASSERT_LOG
606
+ dhd_get_assert_info(dhd);
607
+#endif /* BCMASSERT_LOG */
681608
682
- dhd_process_cid_mac(dhd, TRUE);
609
+ /* Get the device rev info */
610
+ memset(&revinfo, 0, sizeof(revinfo));
611
+ ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_REVINFO, &revinfo, sizeof(revinfo), FALSE, 0);
612
+ if (ret < 0)
613
+ goto done;
683614
684
- ret = dhd_preinit_ioctls(dhd);
685
- if (!ret)
686
- dhd_process_cid_mac(dhd, FALSE);
687
- }
615
+ DHD_SSSR_DUMP_INIT(dhd);
616
+
617
+ dhd_process_cid_mac(dhd, TRUE);
618
+ ret = dhd_preinit_ioctls(dhd);
619
+ dhd_process_cid_mac(dhd, FALSE);
688620
689621 /* Always assumes wl for now */
690622 dhd->iswl = TRUE;
....@@ -703,7 +635,6 @@
703635 {
704636 /* Nothing to do for CDC */
705637 }
706
-
707638
708639 static void
709640 dhd_get_hostreorder_pkts(void *osh, struct reorder_info *ptr, void **pkt,
....@@ -849,7 +780,6 @@
849780 else if (flags & WLHOST_REORDERDATA_CURIDX_VALID) {
850781 cur_idx = reorder_info_buf[WLHOST_REORDERDATA_CURIDX_OFFSET];
851782 exp_idx = reorder_info_buf[WLHOST_REORDERDATA_EXPIDX_OFFSET];
852
-
853783
854784 if ((exp_idx == ptr->exp_idx) && (cur_idx != ptr->exp_idx)) {
855785 /* still in the current hole */