forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/net/wireless/ath/ath10k/bmi.c
....@@ -1,18 +1,7 @@
1
+// SPDX-License-Identifier: ISC
12 /*
23 * Copyright (c) 2005-2011 Atheros Communications Inc.
34 * Copyright (c) 2011-2014,2016-2017 Qualcomm Atheros, Inc.
4
- *
5
- * Permission to use, copy, modify, and/or distribute this software for any
6
- * purpose with or without fee is hereby granted, provided that the above
7
- * copyright notice and this permission notice appear in all copies.
8
- *
9
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
165 */
176
187 #include "bmi.h"
....@@ -23,18 +12,11 @@
2312
2413 void ath10k_bmi_start(struct ath10k *ar)
2514 {
26
- int ret;
27
-
2815 ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi start\n");
2916
3017 ar->bmi.done_sent = false;
31
-
32
- /* Enable hardware clock to speed up firmware download */
33
- if (ar->hw_params.hw_ops->enable_pll_clk) {
34
- ret = ar->hw_params.hw_ops->enable_pll_clk(ar);
35
- ath10k_dbg(ar, ATH10K_DBG_BMI, "bmi enable pll ret %d\n", ret);
36
- }
3718 }
19
+EXPORT_SYMBOL(ath10k_bmi_start);
3820
3921 int ath10k_bmi_done(struct ath10k *ar)
4022 {
....@@ -208,6 +190,7 @@
208190
209191 return 0;
210192 }
193
+EXPORT_SYMBOL(ath10k_bmi_read_memory);
211194
212195 int ath10k_bmi_write_soc_reg(struct ath10k *ar, u32 address, u32 reg_val)
213196 {
....@@ -357,6 +340,53 @@
357340 return 0;
358341 }
359342
343
+static int ath10k_bmi_lz_data_large(struct ath10k *ar, const void *buffer, u32 length)
344
+{
345
+ struct bmi_cmd *cmd;
346
+ u32 hdrlen = sizeof(cmd->id) + sizeof(cmd->lz_data);
347
+ u32 txlen;
348
+ int ret;
349
+ size_t buf_len;
350
+
351
+ ath10k_dbg(ar, ATH10K_DBG_BMI, "large bmi lz data buffer 0x%pK length %d\n",
352
+ buffer, length);
353
+
354
+ if (ar->bmi.done_sent) {
355
+ ath10k_warn(ar, "command disallowed\n");
356
+ return -EBUSY;
357
+ }
358
+
359
+ buf_len = sizeof(*cmd) + BMI_MAX_LARGE_DATA_SIZE - BMI_MAX_DATA_SIZE;
360
+ cmd = kzalloc(buf_len, GFP_KERNEL);
361
+ if (!cmd)
362
+ return -ENOMEM;
363
+
364
+ while (length) {
365
+ txlen = min(length, BMI_MAX_LARGE_DATA_SIZE - hdrlen);
366
+
367
+ WARN_ON_ONCE(txlen & 3);
368
+
369
+ cmd->id = __cpu_to_le32(BMI_LZ_DATA);
370
+ cmd->lz_data.len = __cpu_to_le32(txlen);
371
+ memcpy(cmd->lz_data.payload, buffer, txlen);
372
+
373
+ ret = ath10k_hif_exchange_bmi_msg(ar, cmd, hdrlen + txlen,
374
+ NULL, NULL);
375
+ if (ret) {
376
+ ath10k_warn(ar, "unable to write to the device\n");
377
+ kfree(cmd);
378
+ return ret;
379
+ }
380
+
381
+ buffer += txlen;
382
+ length -= txlen;
383
+ }
384
+
385
+ kfree(cmd);
386
+
387
+ return 0;
388
+}
389
+
360390 int ath10k_bmi_lz_data(struct ath10k *ar, const void *buffer, u32 length)
361391 {
362392 struct bmi_cmd cmd;
....@@ -441,7 +471,11 @@
441471 if (trailer_len > 0)
442472 memcpy(trailer, buffer + head_len, trailer_len);
443473
444
- ret = ath10k_bmi_lz_data(ar, buffer, head_len);
474
+ if (ar->hw_params.bmi_large_size_download)
475
+ ret = ath10k_bmi_lz_data_large(ar, buffer, head_len);
476
+ else
477
+ ret = ath10k_bmi_lz_data(ar, buffer, head_len);
478
+
445479 if (ret)
446480 return ret;
447481
....@@ -459,3 +493,26 @@
459493
460494 return ret;
461495 }
496
+
497
+int ath10k_bmi_set_start(struct ath10k *ar, u32 address)
498
+{
499
+ struct bmi_cmd cmd;
500
+ u32 cmdlen = sizeof(cmd.id) + sizeof(cmd.set_app_start);
501
+ int ret;
502
+
503
+ if (ar->bmi.done_sent) {
504
+ ath10k_warn(ar, "bmi set start command disallowed\n");
505
+ return -EBUSY;
506
+ }
507
+
508
+ cmd.id = __cpu_to_le32(BMI_SET_APP_START);
509
+ cmd.set_app_start.addr = __cpu_to_le32(address);
510
+
511
+ ret = ath10k_hif_exchange_bmi_msg(ar, &cmd, cmdlen, NULL, NULL);
512
+ if (ret) {
513
+ ath10k_warn(ar, "unable to set start to the device:%d\n", ret);
514
+ return ret;
515
+ }
516
+
517
+ return 0;
518
+}