Skip to content

Commit 00f481b

Browse files
Chaya Rachel Ivgiegrumbach
authored andcommitted
iwlwifi: mvm: add ctdp operations to debugfs
Add debugfs entries to get the ctdp budget average and to stop ctdp. Signed-off-by: Chaya Rachel Ivgi <[email protected]> Signed-off-by: Emmanuel Grumbach <[email protected]>
1 parent 7c70fee commit 00f481b

File tree

2 files changed

+86
-34
lines changed

2 files changed

+86
-34
lines changed

drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,44 @@
7373
#include "debugfs.h"
7474
#include "iwl-fw-error-dump.h"
7575

76+
static ssize_t iwl_dbgfs_ctdp_budget_read(struct file *file,
77+
char __user *user_buf,
78+
size_t count, loff_t *ppos)
79+
{
80+
struct iwl_mvm *mvm = file->private_data;
81+
char buf[16];
82+
int pos, budget;
83+
84+
if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
85+
return -EIO;
86+
87+
mutex_lock(&mvm->mutex);
88+
budget = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_REPORT, 0);
89+
mutex_unlock(&mvm->mutex);
90+
91+
if (budget < 0)
92+
return budget;
93+
94+
pos = scnprintf(buf, sizeof(buf), "%d\n", budget);
95+
96+
return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
97+
}
98+
99+
static ssize_t iwl_dbgfs_stop_ctdp_write(struct iwl_mvm *mvm, char *buf,
100+
size_t count, loff_t *ppos)
101+
{
102+
int ret;
103+
104+
if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
105+
return -EIO;
106+
107+
mutex_lock(&mvm->mutex);
108+
ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_STOP, 0);
109+
mutex_unlock(&mvm->mutex);
110+
111+
return ret ?: count;
112+
}
113+
76114
static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
77115
size_t count, loff_t *ppos)
78116
{
@@ -1493,6 +1531,8 @@ iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
14931531
MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
14941532

14951533
/* Device wide debugfs entries */
1534+
MVM_DEBUGFS_READ_FILE_OPS(ctdp_budget);
1535+
MVM_DEBUGFS_WRITE_FILE_OPS(stop_ctdp, 8);
14961536
MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
14971537
MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
14981538
MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8);
@@ -1542,6 +1582,8 @@ int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
15421582
MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir,
15431583
S_IWUSR | S_IRUSR);
15441584
MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR);
1585+
MVM_DEBUGFS_ADD_FILE(ctdp_budget, dbgfs_dir, S_IRUSR);
1586+
MVM_DEBUGFS_ADD_FILE(stop_ctdp, dbgfs_dir, S_IWUSR);
15451587
MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
15461588
MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
15471589
MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);

drivers/net/wireless/intel/iwlwifi/mvm/tt.c

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,50 @@ static const struct iwl_tt_params iwl_mvm_default_tt_params = {
510510
.support_tx_backoff = true,
511511
};
512512

513+
int iwl_mvm_ctdp_command(struct iwl_mvm *mvm, u32 op, u32 budget)
514+
{
515+
struct iwl_mvm_ctdp_cmd cmd = {
516+
.operation = cpu_to_le32(op),
517+
.budget = cpu_to_le32(budget),
518+
.window_size = 0,
519+
};
520+
int ret;
521+
u32 status;
522+
523+
lockdep_assert_held(&mvm->mutex);
524+
525+
ret = iwl_mvm_send_cmd_pdu_status(mvm, WIDE_ID(PHY_OPS_GROUP,
526+
CTDP_CONFIG_CMD),
527+
sizeof(cmd), &cmd, &status);
528+
529+
if (ret) {
530+
IWL_ERR(mvm, "cTDP command failed (err=%d)\n", ret);
531+
return ret;
532+
}
533+
534+
switch (op) {
535+
case CTDP_CMD_OPERATION_START:
536+
#ifdef CONFIG_THERMAL
537+
mvm->cooling_dev.cur_state = budget;
538+
#endif /* CONFIG_THERMAL */
539+
break;
540+
case CTDP_CMD_OPERATION_REPORT:
541+
IWL_DEBUG_TEMP(mvm, "cTDP avg energy in mWatt = %d\n", status);
542+
/* when the function is called with CTDP_CMD_OPERATION_REPORT
543+
* option the function should return the average budget value
544+
* that is received from the FW.
545+
* The budget can't be less or equal to 0, so it's possible
546+
* to distinguish between error values and budgets.
547+
*/
548+
return status;
549+
case CTDP_CMD_OPERATION_STOP:
550+
IWL_DEBUG_TEMP(mvm, "cTDP stopped successfully\n");
551+
break;
552+
}
553+
554+
return 0;
555+
}
556+
513557
#ifdef CONFIG_THERMAL
514558
static int compare_temps(const void *a, const void *b)
515559
{
@@ -738,40 +782,6 @@ static const u32 iwl_mvm_cdev_budgets[] = {
738782
150, /* cooling state 19 */
739783
};
740784

741-
int iwl_mvm_ctdp_command(struct iwl_mvm *mvm, u32 op, u32 budget)
742-
{
743-
struct iwl_mvm_ctdp_cmd cmd = {
744-
.operation = cpu_to_le32(op),
745-
.budget = cpu_to_le32(budget),
746-
.window_size = 0,
747-
};
748-
int ret;
749-
u32 status;
750-
751-
lockdep_assert_held(&mvm->mutex);
752-
753-
ret = iwl_mvm_send_cmd_pdu_status(mvm, WIDE_ID(PHY_OPS_GROUP,
754-
CTDP_CONFIG_CMD),
755-
sizeof(cmd), &cmd, &status);
756-
757-
if (ret) {
758-
IWL_ERR(mvm, "cTDP command failed (err=%d)\n", ret);
759-
return ret;
760-
}
761-
762-
/* can happen if the registration failed */
763-
if (!mvm->cooling_dev.cdev)
764-
return -EINVAL;
765-
766-
if (op == CTDP_CMD_OPERATION_START)
767-
mvm->cooling_dev.cur_state = budget;
768-
769-
else if (op == CTDP_CMD_OPERATION_REPORT)
770-
IWL_DEBUG_TEMP(mvm, "cTDP avg energy in mWatt = %d\n", status);
771-
772-
return 0;
773-
}
774-
775785
static int iwl_mvm_tcool_get_max_state(struct thermal_cooling_device *cdev,
776786
unsigned long *state)
777787
{

0 commit comments

Comments
 (0)