forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/wl_cfg_btcoex.c
....@@ -1,15 +1,16 @@
1
-/* SPDX-License-Identifier: GPL-2.0 */
21 /*
32 * Linux cfg80211 driver - Dongle Host Driver (DHD) related
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: wl_cfg_btcoex.c 709309 2019-01-17 09:04:00Z $
29
+ * $Id: wl_cfg_btcoex.c 814554 2019-04-11 23:06:22Z $
2930 */
3031
3132 #include <net/rtnetlink.h>
....@@ -43,10 +44,10 @@
4344 extern uint dhd_pkt_filter_enable;
4445 extern uint dhd_master_mode;
4546 extern void dhd_pktfilter_offload_enable(dhd_pub_t * dhd, char *arg, int enable, int master_mode);
46
-#endif
47
+#endif // endif
4748
4849 struct btcoex_info {
49
- struct timer_list timer;
50
+ timer_list_compat_t timer;
5051 u32 timer_ms;
5152 u32 timer_on;
5253 u32 ts_dhcp_start; /* ms ts ecord time stats */
....@@ -59,6 +60,7 @@
5960 struct net_device *dev;
6061 };
6162
63
+#if defined(OEM_ANDROID)
6264 static struct btcoex_info *btcoex_info_loc = NULL;
6365
6466 /* TODO: clean up the BT-Coex code, it still have some legacy ioctl/iovar functions */
....@@ -71,6 +73,9 @@
7173 #define BT_DHCP_OPPR_WIN_TIME 2500
7274 /* T2 turn off SCO/SCO supperesion is (timeout) */
7375 #define BT_DHCP_FLAG_FORCE_TIME 5500
76
+
77
+#define BTCOEXMODE "BTCOEXMODE"
78
+#define POWERMODE "POWERMODE"
7479
7580 enum wl_cfg80211_btcoex_status {
7681 BT_DHCP_IDLE,
....@@ -93,9 +98,12 @@
9398 } var;
9499 int error;
95100
96
- bcm_mkiovar(name, (char *)(&reg), sizeof(reg),
97
- (char *)(&var), sizeof(var.buf));
98
- error = wldev_ioctl(dev, WLC_GET_VAR, (char *)(&var), sizeof(var.buf), false);
101
+ bzero(&var, sizeof(var));
102
+ error = bcm_mkiovar(name, (char *)(&reg), sizeof(reg), (char *)(&var), sizeof(var.buf));
103
+ if (error == 0) {
104
+ return BCME_BUFTOOSHORT;
105
+ }
106
+ error = wldev_ioctl_get(dev, WLC_GET_VAR, (char *)(&var), sizeof(var.buf));
99107
100108 *retval = dtoh32(var.val);
101109 return (error);
....@@ -104,16 +112,15 @@
104112 static int
105113 dev_wlc_bufvar_set(struct net_device *dev, char *name, char *buf, int len)
106114 {
107
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
108
- char ioctlbuf_local[1024];
109
-#else
110
- static char ioctlbuf_local[1024];
111
-#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) */
115
+ char ioctlbuf_local[WLC_IOCTL_SMLEN];
116
+ int ret;
112117
113
- bcm_mkiovar(name, buf, len, ioctlbuf_local, sizeof(ioctlbuf_local));
114
-
115
- return (wldev_ioctl(dev, WLC_SET_VAR, ioctlbuf_local, sizeof(ioctlbuf_local), true));
118
+ ret = bcm_mkiovar(name, buf, len, ioctlbuf_local, sizeof(ioctlbuf_local));
119
+ if (ret == 0)
120
+ return BCME_BUFTOOSHORT;
121
+ return (wldev_ioctl_set(dev, WLC_SET_VAR, ioctlbuf_local, ret));
116122 }
123
+
117124 /*
118125 get named driver variable to uint register value and return error indication
119126 calling example: dev_wlc_intvar_set_reg(dev, "btc_params",66, value)
....@@ -123,7 +130,7 @@
123130 {
124131 char reg_addr[8];
125132
126
- memset(reg_addr, 0, sizeof(reg_addr));
133
+ bzero(reg_addr, sizeof(reg_addr));
127134 memcpy((char *)&reg_addr[0], (char *)addr, 4);
128135 memcpy((char *)&reg_addr[4], (char *)val, 4);
129136
....@@ -276,13 +283,12 @@
276283 #if defined(BT_DHCP_USE_FLAGS)
277284 char buf_flag7_dhcp_on[8] = { 7, 00, 00, 00, 0x1, 0x0, 0x00, 0x00 };
278285 char buf_flag7_default[8] = { 7, 00, 00, 00, 0x0, 0x00, 0x00, 0x00};
279
-#endif
280
-
286
+#endif // endif
281287
282288 #if defined(BT_DHCP_eSCO_FIX)
283289 /* set = 1, save & turn on 0 - off & restore prev settings */
284290 set_btc_esco_params(dev, set);
285
-#endif
291
+#endif // endif
286292
287293 #if defined(BT_DHCP_USE_FLAGS)
288294 WL_TRACE(("WI-FI priority boost via bt flags, set:%d\n", set));
....@@ -296,18 +302,12 @@
296302 dev_wlc_bufvar_set(dev, "btc_flags",
297303 (char *)&buf_flag7_default[0],
298304 sizeof(buf_flag7_default));
299
-#endif
305
+#endif // endif
300306 }
301307
302
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0))
303
-static void wl_cfg80211_bt_timerfunc(struct timer_list *t)
304
-{
305
- struct btcoex_info *bt_local = from_timer(bt_local, t, timer);
306
-#else
307308 static void wl_cfg80211_bt_timerfunc(ulong data)
308309 {
309310 struct btcoex_info *bt_local = (struct btcoex_info *)data;
310
-#endif
311311 WL_TRACE(("Enter\n"));
312312 bt_local->timer_on = 0;
313313 schedule_work(&bt_local->work);
....@@ -317,7 +317,9 @@
317317 {
318318 struct btcoex_info *btcx_inf;
319319
320
+ GCC_DIAGNOSTIC_PUSH_SUPPRESS_CAST();
320321 btcx_inf = container_of(work, struct btcoex_info, work);
322
+ GCC_DIAGNOSTIC_POP();
321323
322324 if (btcx_inf->timer_on) {
323325 btcx_inf->timer_on = 0;
....@@ -397,13 +399,7 @@
397399 btco_inf->ts_dhcp_ok = 0;
398400 /* Set up timer for BT */
399401 btco_inf->timer_ms = 10;
400
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0))
401
- timer_setup(&btco_inf->timer, wl_cfg80211_bt_timerfunc, 0);
402
-#else
403
- init_timer(&btco_inf->timer);
404
- btco_inf->timer.data = (ulong)btco_inf;
405
- btco_inf->timer.function = wl_cfg80211_bt_timerfunc;
406
-#endif
402
+ init_timer_compat(&btco_inf->timer, wl_cfg80211_bt_timerfunc, btco_inf);
407403
408404 btco_inf->dev = ndev;
409405
....@@ -431,8 +427,13 @@
431427 int wl_cfg80211_set_btcoex_dhcp(struct net_device *dev, dhd_pub_t *dhd, char *command)
432428 {
433429
430
+#ifndef OEM_ANDROID
431
+ static int pm = PM_FAST;
432
+ int pm_local = PM_OFF;
433
+#endif /* OEM_ANDROID */
434434 struct btcoex_info *btco_inf = btcoex_info_loc;
435435 char powermode_val = 0;
436
+ uint8 cmd_len = 0;
436437 char buf_reg66va_dhcp_on[8] = { 66, 00, 00, 00, 0x10, 0x27, 0x00, 0x00 };
437438 char buf_reg41va_dhcp_on[8] = { 41, 00, 00, 00, 0x33, 0x00, 0x00, 0x00 };
438439 char buf_reg68va_dhcp_on[8] = { 68, 00, 00, 00, 0x90, 0x01, 0x00, 0x00 };
....@@ -446,23 +447,38 @@
446447 char buf_flag7_default[8] = { 7, 00, 00, 00, 0x0, 0x00, 0x00, 0x00};
447448
448449 /* Figure out powermode 1 or o command */
449
- strncpy((char *)&powermode_val, command + strlen("BTCOEXMODE") +1, 1);
450
+#ifdef OEM_ANDROID
451
+ cmd_len = sizeof(BTCOEXMODE);
452
+#else
453
+ cmd_len = sizeof(POWERMODE);
454
+#endif // endif
455
+ powermode_val = command[cmd_len];
450456
451
- if (strnicmp((char *)&powermode_val, "1", strlen("1")) == 0) {
457
+ if (powermode_val == '1') {
452458 WL_TRACE_HW4(("DHCP session starts\n"));
453
-
454459
455460 #ifdef PKT_FILTER_SUPPORT
456461 dhd->dhcp_in_progress = 1;
457462
463
+#if defined(APSTA_BLOCK_ARP_DURING_DHCP)
464
+ if (DHD_OPMODE_STA_SOFTAP_CONCURR(dhd)) {
465
+ /* Block ARP frames while DHCP of STA interface is in
466
+ * progress in case of STA/SoftAP concurrent mode
467
+ */
468
+ wl_cfg80211_block_arp(dev, TRUE);
469
+ } else
470
+#endif /* APSTA_BLOCK_ARP_DURING_DHCP */
458471 if (dhd->early_suspended) {
459472 WL_TRACE_HW4(("DHCP in progressing , disable packet filter!!!\n"));
460473 dhd_enable_packet_filter(0, dhd);
461474 }
462
-#endif
475
+#endif /* PKT_FILTER_SUPPORT */
463476
464477 /* Retrieve and saved orig regs value */
465478 if ((saved_status == FALSE) &&
479
+#ifndef OEM_ANDROID
480
+ (!dev_wlc_ioctl(dev, WLC_GET_PM, &pm, sizeof(pm))) &&
481
+#endif // endif
466482 (!dev_wlc_intvar_get_reg(dev, "btc_params", 66, &saved_reg66)) &&
467483 (!dev_wlc_intvar_get_reg(dev, "btc_params", 41, &saved_reg41)) &&
468484 (!dev_wlc_intvar_get_reg(dev, "btc_params", 68, &saved_reg68))) {
....@@ -471,6 +487,9 @@
471487 saved_reg66, saved_reg41, saved_reg68));
472488
473489 /* Disable PM mode during dhpc session */
490
+#ifndef OEM_ANDROID
491
+ dev_wlc_ioctl(dev, WLC_SET_PM, &pm_local, sizeof(pm_local));
492
+#endif // endif
474493
475494 /* Disable PM mode during dhpc session */
476495 /* Start BT timer only for SCO connection */
....@@ -491,7 +510,8 @@
491510
492511 btco_inf->bt_state = BT_DHCP_START;
493512 btco_inf->timer_on = 1;
494
- mod_timer(&btco_inf->timer, btco_inf->timer.expires);
513
+ mod_timer(&btco_inf->timer,
514
+ timer_expires(&btco_inf->timer));
495515 WL_TRACE(("enable BT DHCP Timer\n"));
496516 }
497517 }
....@@ -499,22 +519,33 @@
499519 WL_ERR(("was called w/o DHCP OFF. Continue\n"));
500520 }
501521 }
502
- else if (strnicmp((char *)&powermode_val, "2", strlen("2")) == 0) {
503
-
504
-
522
+#ifdef OEM_ANDROID
523
+ else if (powermode_val == '2') {
524
+#else
525
+ else if (powermode_val == '0') {
526
+#endif // endif
505527
506528 #ifdef PKT_FILTER_SUPPORT
507529 dhd->dhcp_in_progress = 0;
508530 WL_TRACE_HW4(("DHCP is complete \n"));
509531
510
- /* Enable packet filtering */
532
+#if defined(APSTA_BLOCK_ARP_DURING_DHCP)
533
+ if (DHD_OPMODE_STA_SOFTAP_CONCURR(dhd)) {
534
+ /* Unblock ARP frames */
535
+ wl_cfg80211_block_arp(dev, FALSE);
536
+ } else
537
+#endif /* APSTA_BLOCK_ARP_DURING_DHCP */
511538 if (dhd->early_suspended) {
539
+ /* Enable packet filtering */
512540 WL_TRACE_HW4(("DHCP is complete , enable packet filter!!!\n"));
513541 dhd_enable_packet_filter(1, dhd);
514542 }
515543 #endif /* PKT_FILTER_SUPPORT */
516544
517545 /* Restoring PM mode */
546
+#ifndef OEM_ANDROID
547
+ dev_wlc_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm));
548
+#endif // endif
518549
519550 /* Stop any bt timer because DHCP session is done */
520551 WL_TRACE(("disable BT DHCP Timer\n"));
....@@ -557,7 +588,6 @@
557588 WL_ERR(("Unkwown yet power setting, ignored\n"));
558589 }
559590
560
- snprintf(command, 3, "OK");
561
-
562
- return (strlen("OK"));
591
+ return (snprintf(command, sizeof("OK"), "OK") + 1);
563592 }
593
+#endif /* defined(OEM_ANDROID) */