18e99ea8dSJohannes Berg // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
28e99ea8dSJohannes Berg /*
38e99ea8dSJohannes Berg * Copyright (C) 2012-2014, 2018-2020 Intel Corporation
48e99ea8dSJohannes Berg * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
58e99ea8dSJohannes Berg * Copyright (C) 2016-2017 Intel Deutschland GmbH
68e99ea8dSJohannes Berg */
793b167c1SMordechay Goodstein #include "api/commands.h"
893b167c1SMordechay Goodstein #include "debugfs.h"
9422b5dd4SHaim Dreyfuss #include "dbg.h"
1036dfe9acSMordechay Goodstein #include <linux/seq_file.h>
1193b167c1SMordechay Goodstein
12dd269057SNaftali Goldstein #define FWRT_DEBUGFS_OPEN_WRAPPER(name, buflen, argtype) \
13dd269057SNaftali Goldstein struct dbgfs_##name##_data { \
14dd269057SNaftali Goldstein argtype *arg; \
15dd269057SNaftali Goldstein bool read_done; \
16dd269057SNaftali Goldstein ssize_t rlen; \
17dd269057SNaftali Goldstein char rbuf[buflen]; \
18dd269057SNaftali Goldstein }; \
19dd269057SNaftali Goldstein static int _iwl_dbgfs_##name##_open(struct inode *inode, \
20dd269057SNaftali Goldstein struct file *file) \
21dd269057SNaftali Goldstein { \
22dd269057SNaftali Goldstein struct dbgfs_##name##_data *data; \
23dd269057SNaftali Goldstein \
24dd269057SNaftali Goldstein data = kzalloc(sizeof(*data), GFP_KERNEL); \
25dd269057SNaftali Goldstein if (!data) \
26dd269057SNaftali Goldstein return -ENOMEM; \
27dd269057SNaftali Goldstein \
28dd269057SNaftali Goldstein data->read_done = false; \
29dd269057SNaftali Goldstein data->arg = inode->i_private; \
30dd269057SNaftali Goldstein file->private_data = data; \
31dd269057SNaftali Goldstein \
32dd269057SNaftali Goldstein return 0; \
3393b167c1SMordechay Goodstein }
3493b167c1SMordechay Goodstein
35dd269057SNaftali Goldstein #define FWRT_DEBUGFS_READ_WRAPPER(name) \
36dd269057SNaftali Goldstein static ssize_t _iwl_dbgfs_##name##_read(struct file *file, \
37dd269057SNaftali Goldstein char __user *user_buf, \
38dd269057SNaftali Goldstein size_t count, loff_t *ppos) \
39dd269057SNaftali Goldstein { \
40dd269057SNaftali Goldstein struct dbgfs_##name##_data *data = file->private_data; \
41dd269057SNaftali Goldstein \
42dd269057SNaftali Goldstein if (!data->read_done) { \
43dd269057SNaftali Goldstein data->read_done = true; \
44dd269057SNaftali Goldstein data->rlen = iwl_dbgfs_##name##_read(data->arg, \
45dd269057SNaftali Goldstein sizeof(data->rbuf),\
46dd269057SNaftali Goldstein data->rbuf); \
47dd269057SNaftali Goldstein } \
48dd269057SNaftali Goldstein \
49dd269057SNaftali Goldstein if (data->rlen < 0) \
50dd269057SNaftali Goldstein return data->rlen; \
51dd269057SNaftali Goldstein return simple_read_from_buffer(user_buf, count, ppos, \
52dd269057SNaftali Goldstein data->rbuf, data->rlen); \
53dd269057SNaftali Goldstein }
54dd269057SNaftali Goldstein
_iwl_dbgfs_release(struct inode * inode,struct file * file)55dd269057SNaftali Goldstein static int _iwl_dbgfs_release(struct inode *inode, struct file *file)
56dd269057SNaftali Goldstein {
57dd269057SNaftali Goldstein kfree(file->private_data);
58dd269057SNaftali Goldstein
59dd269057SNaftali Goldstein return 0;
60dd269057SNaftali Goldstein }
61dd269057SNaftali Goldstein
62dd269057SNaftali Goldstein #define _FWRT_DEBUGFS_READ_FILE_OPS(name, buflen, argtype) \
63dd269057SNaftali Goldstein FWRT_DEBUGFS_OPEN_WRAPPER(name, buflen, argtype) \
64dd269057SNaftali Goldstein FWRT_DEBUGFS_READ_WRAPPER(name) \
65dd269057SNaftali Goldstein static const struct file_operations iwl_dbgfs_##name##_ops = { \
66dd269057SNaftali Goldstein .read = _iwl_dbgfs_##name##_read, \
67dd269057SNaftali Goldstein .open = _iwl_dbgfs_##name##_open, \
68dd269057SNaftali Goldstein .llseek = generic_file_llseek, \
69dd269057SNaftali Goldstein .release = _iwl_dbgfs_release, \
70dd269057SNaftali Goldstein }
71dd269057SNaftali Goldstein
72dd269057SNaftali Goldstein #define FWRT_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype) \
7393b167c1SMordechay Goodstein static ssize_t _iwl_dbgfs_##name##_write(struct file *file, \
7493b167c1SMordechay Goodstein const char __user *user_buf, \
7593b167c1SMordechay Goodstein size_t count, loff_t *ppos) \
7693b167c1SMordechay Goodstein { \
77dd269057SNaftali Goldstein argtype *arg = \
78dd269057SNaftali Goldstein ((struct dbgfs_##name##_data *)file->private_data)->arg;\
7993b167c1SMordechay Goodstein char buf[buflen] = {}; \
8093b167c1SMordechay Goodstein size_t buf_size = min(count, sizeof(buf) - 1); \
8193b167c1SMordechay Goodstein \
8293b167c1SMordechay Goodstein if (copy_from_user(buf, user_buf, buf_size)) \
8393b167c1SMordechay Goodstein return -EFAULT; \
8493b167c1SMordechay Goodstein \
85dd269057SNaftali Goldstein return iwl_dbgfs_##name##_write(arg, buf, buf_size); \
8693b167c1SMordechay Goodstein }
8793b167c1SMordechay Goodstein
88dd269057SNaftali Goldstein #define _FWRT_DEBUGFS_READ_WRITE_FILE_OPS(name, buflen, argtype) \
89dd269057SNaftali Goldstein FWRT_DEBUGFS_OPEN_WRAPPER(name, buflen, argtype) \
90dd269057SNaftali Goldstein FWRT_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype) \
91dd269057SNaftali Goldstein FWRT_DEBUGFS_READ_WRAPPER(name) \
9293b167c1SMordechay Goodstein static const struct file_operations iwl_dbgfs_##name##_ops = { \
9393b167c1SMordechay Goodstein .write = _iwl_dbgfs_##name##_write, \
94dd269057SNaftali Goldstein .read = _iwl_dbgfs_##name##_read, \
95dd269057SNaftali Goldstein .open = _iwl_dbgfs_##name##_open, \
9693b167c1SMordechay Goodstein .llseek = generic_file_llseek, \
97dd269057SNaftali Goldstein .release = _iwl_dbgfs_release, \
9893b167c1SMordechay Goodstein }
9993b167c1SMordechay Goodstein
100dd269057SNaftali Goldstein #define _FWRT_DEBUGFS_WRITE_FILE_OPS(name, buflen, argtype) \
101dd269057SNaftali Goldstein FWRT_DEBUGFS_OPEN_WRAPPER(name, buflen, argtype) \
102dd269057SNaftali Goldstein FWRT_DEBUGFS_WRITE_WRAPPER(name, buflen, argtype) \
10393b167c1SMordechay Goodstein static const struct file_operations iwl_dbgfs_##name##_ops = { \
10493b167c1SMordechay Goodstein .write = _iwl_dbgfs_##name##_write, \
105dd269057SNaftali Goldstein .open = _iwl_dbgfs_##name##_open, \
10693b167c1SMordechay Goodstein .llseek = generic_file_llseek, \
107dd269057SNaftali Goldstein .release = _iwl_dbgfs_release, \
10893b167c1SMordechay Goodstein }
10993b167c1SMordechay Goodstein
110dd269057SNaftali Goldstein #define FWRT_DEBUGFS_READ_FILE_OPS(name, bufsz) \
111dd269057SNaftali Goldstein _FWRT_DEBUGFS_READ_FILE_OPS(name, bufsz, struct iwl_fw_runtime)
112dd269057SNaftali Goldstein
113dd269057SNaftali Goldstein #define FWRT_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
114dd269057SNaftali Goldstein _FWRT_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_fw_runtime)
115dd269057SNaftali Goldstein
116dd269057SNaftali Goldstein #define FWRT_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
117dd269057SNaftali Goldstein _FWRT_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_fw_runtime)
118dd269057SNaftali Goldstein
11993b167c1SMordechay Goodstein #define FWRT_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1205987dfdeSGreg Kroah-Hartman debugfs_create_file(alias, mode, parent, fwrt, \
1215987dfdeSGreg Kroah-Hartman &iwl_dbgfs_##name##_ops); \
12293b167c1SMordechay Goodstein } while (0)
12393b167c1SMordechay Goodstein #define FWRT_DEBUGFS_ADD_FILE(name, parent, mode) \
12493b167c1SMordechay Goodstein FWRT_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
12593b167c1SMordechay Goodstein
iwl_dbgfs_enabled_severities_write(struct iwl_fw_runtime * fwrt,char * buf,size_t count)12687f1283bSMordechay Goodstein static int iwl_dbgfs_enabled_severities_write(struct iwl_fw_runtime *fwrt,
12787f1283bSMordechay Goodstein char *buf, size_t count)
12887f1283bSMordechay Goodstein {
12987f1283bSMordechay Goodstein struct iwl_dbg_host_event_cfg_cmd event_cfg;
13087f1283bSMordechay Goodstein struct iwl_host_cmd hcmd = {
131f0c86427SJohannes Berg .id = WIDE_ID(DEBUG_GROUP, HOST_EVENT_CFG),
13287f1283bSMordechay Goodstein .flags = CMD_ASYNC,
13387f1283bSMordechay Goodstein .data[0] = &event_cfg,
13487f1283bSMordechay Goodstein .len[0] = sizeof(event_cfg),
13587f1283bSMordechay Goodstein };
13687f1283bSMordechay Goodstein u32 enabled_severities;
13787f1283bSMordechay Goodstein int ret = kstrtou32(buf, 10, &enabled_severities);
13887f1283bSMordechay Goodstein
13987f1283bSMordechay Goodstein if (ret < 0)
14087f1283bSMordechay Goodstein return ret;
14187f1283bSMordechay Goodstein
14287f1283bSMordechay Goodstein event_cfg.enabled_severities = cpu_to_le32(enabled_severities);
14387f1283bSMordechay Goodstein
1440a1a3c11SMukesh Sisodiya if (fwrt->ops && fwrt->ops->send_hcmd)
1450a1a3c11SMukesh Sisodiya ret = fwrt->ops->send_hcmd(fwrt->ops_ctx, &hcmd);
1460a1a3c11SMukesh Sisodiya else
1470a1a3c11SMukesh Sisodiya ret = -EPERM;
1480a1a3c11SMukesh Sisodiya
14987f1283bSMordechay Goodstein IWL_INFO(fwrt,
15087f1283bSMordechay Goodstein "sent host event cfg with enabled_severities: %u, ret: %d\n",
15187f1283bSMordechay Goodstein enabled_severities, ret);
15287f1283bSMordechay Goodstein
15387f1283bSMordechay Goodstein return ret ?: count;
15487f1283bSMordechay Goodstein }
15587f1283bSMordechay Goodstein
15687f1283bSMordechay Goodstein FWRT_DEBUGFS_WRITE_FILE_OPS(enabled_severities, 16);
15787f1283bSMordechay Goodstein
iwl_fw_timestamp_marker_wk(struct work_struct * work)15893b167c1SMordechay Goodstein static void iwl_fw_timestamp_marker_wk(struct work_struct *work)
15993b167c1SMordechay Goodstein {
16093b167c1SMordechay Goodstein int ret;
16193b167c1SMordechay Goodstein struct iwl_fw_runtime *fwrt =
16293b167c1SMordechay Goodstein container_of(work, struct iwl_fw_runtime, timestamp.wk.work);
16393b167c1SMordechay Goodstein unsigned long delay = fwrt->timestamp.delay;
16493b167c1SMordechay Goodstein
16593b167c1SMordechay Goodstein ret = iwl_fw_send_timestamp_marker_cmd(fwrt);
16693b167c1SMordechay Goodstein if (!ret && delay)
16793b167c1SMordechay Goodstein schedule_delayed_work(&fwrt->timestamp.wk,
16893b167c1SMordechay Goodstein round_jiffies_relative(delay));
16993b167c1SMordechay Goodstein else
17093b167c1SMordechay Goodstein IWL_INFO(fwrt,
17193b167c1SMordechay Goodstein "stopping timestamp_marker, ret: %d, delay: %u\n",
17293b167c1SMordechay Goodstein ret, jiffies_to_msecs(delay) / 1000);
17393b167c1SMordechay Goodstein }
17493b167c1SMordechay Goodstein
iwl_fw_trigger_timestamp(struct iwl_fw_runtime * fwrt,u32 delay)175759931c7SMordechay Goodstein void iwl_fw_trigger_timestamp(struct iwl_fw_runtime *fwrt, u32 delay)
176759931c7SMordechay Goodstein {
177759931c7SMordechay Goodstein IWL_INFO(fwrt,
178759931c7SMordechay Goodstein "starting timestamp_marker trigger with delay: %us\n",
179759931c7SMordechay Goodstein delay);
180759931c7SMordechay Goodstein
181759931c7SMordechay Goodstein iwl_fw_cancel_timestamp(fwrt);
182759931c7SMordechay Goodstein
183759931c7SMordechay Goodstein fwrt->timestamp.delay = msecs_to_jiffies(delay * 1000);
184759931c7SMordechay Goodstein
185759931c7SMordechay Goodstein schedule_delayed_work(&fwrt->timestamp.wk,
186759931c7SMordechay Goodstein round_jiffies_relative(fwrt->timestamp.delay));
187759931c7SMordechay Goodstein }
188759931c7SMordechay Goodstein
iwl_dbgfs_timestamp_marker_write(struct iwl_fw_runtime * fwrt,char * buf,size_t count)18993b167c1SMordechay Goodstein static ssize_t iwl_dbgfs_timestamp_marker_write(struct iwl_fw_runtime *fwrt,
190dd269057SNaftali Goldstein char *buf, size_t count)
19193b167c1SMordechay Goodstein {
19293b167c1SMordechay Goodstein int ret;
19393b167c1SMordechay Goodstein u32 delay;
19493b167c1SMordechay Goodstein
19593b167c1SMordechay Goodstein ret = kstrtou32(buf, 10, &delay);
19693b167c1SMordechay Goodstein if (ret < 0)
19793b167c1SMordechay Goodstein return ret;
19893b167c1SMordechay Goodstein
199759931c7SMordechay Goodstein iwl_fw_trigger_timestamp(fwrt, delay);
20093b167c1SMordechay Goodstein
20193b167c1SMordechay Goodstein return count;
20293b167c1SMordechay Goodstein }
20393b167c1SMordechay Goodstein
iwl_dbgfs_timestamp_marker_read(struct iwl_fw_runtime * fwrt,size_t size,char * buf)20475e9947eSMordechay Goodstein static ssize_t iwl_dbgfs_timestamp_marker_read(struct iwl_fw_runtime *fwrt,
20575e9947eSMordechay Goodstein size_t size, char *buf)
20675e9947eSMordechay Goodstein {
20775e9947eSMordechay Goodstein u32 delay_secs = jiffies_to_msecs(fwrt->timestamp.delay) / 1000;
20875e9947eSMordechay Goodstein
20975e9947eSMordechay Goodstein return scnprintf(buf, size, "%d\n", delay_secs);
21075e9947eSMordechay Goodstein }
21175e9947eSMordechay Goodstein
21275e9947eSMordechay Goodstein FWRT_DEBUGFS_READ_WRITE_FILE_OPS(timestamp_marker, 16);
21393b167c1SMordechay Goodstein
214755384b3SShahar S Matityahu struct hcmd_write_data {
215755384b3SShahar S Matityahu __be32 cmd_id;
216755384b3SShahar S Matityahu __be32 flags;
217755384b3SShahar S Matityahu __be16 length;
21845c21a0eSGustavo A. R. Silva u8 data[];
219755384b3SShahar S Matityahu } __packed;
220755384b3SShahar S Matityahu
iwl_dbgfs_send_hcmd_write(struct iwl_fw_runtime * fwrt,char * buf,size_t count)221755384b3SShahar S Matityahu static ssize_t iwl_dbgfs_send_hcmd_write(struct iwl_fw_runtime *fwrt, char *buf,
222755384b3SShahar S Matityahu size_t count)
223755384b3SShahar S Matityahu {
224755384b3SShahar S Matityahu size_t header_size = (sizeof(u32) * 2 + sizeof(u16)) * 2;
225755384b3SShahar S Matityahu size_t data_size = (count - 1) / 2;
226755384b3SShahar S Matityahu int ret;
227755384b3SShahar S Matityahu struct hcmd_write_data *data;
228755384b3SShahar S Matityahu struct iwl_host_cmd hcmd = {
229755384b3SShahar S Matityahu .len = { 0, },
230755384b3SShahar S Matityahu .data = { NULL, },
231755384b3SShahar S Matityahu };
232755384b3SShahar S Matityahu
233*0bd1be7eSShahar S Matityahu if (!iwl_trans_fw_running(fwrt->trans))
234755384b3SShahar S Matityahu return -EIO;
235755384b3SShahar S Matityahu
236755384b3SShahar S Matityahu if (count < header_size + 1 || count > 1024 * 4)
237755384b3SShahar S Matityahu return -EINVAL;
238755384b3SShahar S Matityahu
239755384b3SShahar S Matityahu data = kmalloc(data_size, GFP_KERNEL);
240755384b3SShahar S Matityahu if (!data)
241755384b3SShahar S Matityahu return -ENOMEM;
242755384b3SShahar S Matityahu
243755384b3SShahar S Matityahu ret = hex2bin((u8 *)data, buf, data_size);
244755384b3SShahar S Matityahu if (ret)
245755384b3SShahar S Matityahu goto out;
246755384b3SShahar S Matityahu
247755384b3SShahar S Matityahu hcmd.id = be32_to_cpu(data->cmd_id);
248755384b3SShahar S Matityahu hcmd.flags = be32_to_cpu(data->flags);
249755384b3SShahar S Matityahu hcmd.len[0] = be16_to_cpu(data->length);
250755384b3SShahar S Matityahu hcmd.data[0] = data->data;
251755384b3SShahar S Matityahu
252755384b3SShahar S Matityahu if (count != header_size + hcmd.len[0] * 2 + 1) {
253755384b3SShahar S Matityahu IWL_ERR(fwrt,
254755384b3SShahar S Matityahu "host command data size does not match header length\n");
255755384b3SShahar S Matityahu ret = -EINVAL;
256755384b3SShahar S Matityahu goto out;
257755384b3SShahar S Matityahu }
258755384b3SShahar S Matityahu
259755384b3SShahar S Matityahu if (fwrt->ops && fwrt->ops->send_hcmd)
260755384b3SShahar S Matityahu ret = fwrt->ops->send_hcmd(fwrt->ops_ctx, &hcmd);
261755384b3SShahar S Matityahu else
262755384b3SShahar S Matityahu ret = -EPERM;
263755384b3SShahar S Matityahu
264755384b3SShahar S Matityahu if (ret < 0)
265755384b3SShahar S Matityahu goto out;
266755384b3SShahar S Matityahu
267755384b3SShahar S Matityahu if (hcmd.flags & CMD_WANT_SKB)
268755384b3SShahar S Matityahu iwl_free_resp(&hcmd);
269755384b3SShahar S Matityahu out:
270755384b3SShahar S Matityahu kfree(data);
271755384b3SShahar S Matityahu return ret ?: count;
272755384b3SShahar S Matityahu }
273755384b3SShahar S Matityahu
274755384b3SShahar S Matityahu FWRT_DEBUGFS_WRITE_FILE_OPS(send_hcmd, 512);
275755384b3SShahar S Matityahu
iwl_dbgfs_fw_dbg_domain_read(struct iwl_fw_runtime * fwrt,size_t size,char * buf)276068893b7SShahar S Matityahu static ssize_t iwl_dbgfs_fw_dbg_domain_read(struct iwl_fw_runtime *fwrt,
277068893b7SShahar S Matityahu size_t size, char *buf)
278068893b7SShahar S Matityahu {
279068893b7SShahar S Matityahu return scnprintf(buf, size, "0x%08x\n",
280068893b7SShahar S Matityahu fwrt->trans->dbg.domains_bitmap);
281068893b7SShahar S Matityahu }
282068893b7SShahar S Matityahu
28310137f07SLuca Coelho FWRT_DEBUGFS_READ_FILE_OPS(fw_dbg_domain, 20);
284068893b7SShahar S Matityahu
28536dfe9acSMordechay Goodstein struct iwl_dbgfs_fw_info_priv {
28636dfe9acSMordechay Goodstein struct iwl_fw_runtime *fwrt;
28736dfe9acSMordechay Goodstein };
28836dfe9acSMordechay Goodstein
28936dfe9acSMordechay Goodstein struct iwl_dbgfs_fw_info_state {
29036dfe9acSMordechay Goodstein loff_t pos;
29136dfe9acSMordechay Goodstein };
29236dfe9acSMordechay Goodstein
iwl_dbgfs_fw_info_seq_next(struct seq_file * seq,void * v,loff_t * pos)29336dfe9acSMordechay Goodstein static void *iwl_dbgfs_fw_info_seq_next(struct seq_file *seq,
29436dfe9acSMordechay Goodstein void *v, loff_t *pos)
29536dfe9acSMordechay Goodstein {
29636dfe9acSMordechay Goodstein struct iwl_dbgfs_fw_info_state *state = v;
29736dfe9acSMordechay Goodstein struct iwl_dbgfs_fw_info_priv *priv = seq->private;
29836dfe9acSMordechay Goodstein const struct iwl_fw *fw = priv->fwrt->fw;
29936dfe9acSMordechay Goodstein
30036dfe9acSMordechay Goodstein *pos = ++state->pos;
3013d90d2f4SJohannes Berg if (*pos >= fw->ucode_capa.n_cmd_versions) {
3023d90d2f4SJohannes Berg kfree(state);
30336dfe9acSMordechay Goodstein return NULL;
3043d90d2f4SJohannes Berg }
30536dfe9acSMordechay Goodstein
30636dfe9acSMordechay Goodstein return state;
30736dfe9acSMordechay Goodstein }
30836dfe9acSMordechay Goodstein
iwl_dbgfs_fw_info_seq_stop(struct seq_file * seq,void * v)30936dfe9acSMordechay Goodstein static void iwl_dbgfs_fw_info_seq_stop(struct seq_file *seq,
31036dfe9acSMordechay Goodstein void *v)
31136dfe9acSMordechay Goodstein {
31236dfe9acSMordechay Goodstein kfree(v);
31336dfe9acSMordechay Goodstein }
31436dfe9acSMordechay Goodstein
iwl_dbgfs_fw_info_seq_start(struct seq_file * seq,loff_t * pos)31536dfe9acSMordechay Goodstein static void *iwl_dbgfs_fw_info_seq_start(struct seq_file *seq, loff_t *pos)
31636dfe9acSMordechay Goodstein {
31736dfe9acSMordechay Goodstein struct iwl_dbgfs_fw_info_priv *priv = seq->private;
31836dfe9acSMordechay Goodstein const struct iwl_fw *fw = priv->fwrt->fw;
31936dfe9acSMordechay Goodstein struct iwl_dbgfs_fw_info_state *state;
32036dfe9acSMordechay Goodstein
32136dfe9acSMordechay Goodstein if (*pos >= fw->ucode_capa.n_cmd_versions)
32236dfe9acSMordechay Goodstein return NULL;
32336dfe9acSMordechay Goodstein
32436dfe9acSMordechay Goodstein state = kzalloc(sizeof(*state), GFP_KERNEL);
32536dfe9acSMordechay Goodstein if (!state)
32636dfe9acSMordechay Goodstein return NULL;
32736dfe9acSMordechay Goodstein state->pos = *pos;
32836dfe9acSMordechay Goodstein return state;
32936dfe9acSMordechay Goodstein };
33036dfe9acSMordechay Goodstein
iwl_dbgfs_fw_info_seq_show(struct seq_file * seq,void * v)33136dfe9acSMordechay Goodstein static int iwl_dbgfs_fw_info_seq_show(struct seq_file *seq, void *v)
33236dfe9acSMordechay Goodstein {
33336dfe9acSMordechay Goodstein struct iwl_dbgfs_fw_info_state *state = v;
33436dfe9acSMordechay Goodstein struct iwl_dbgfs_fw_info_priv *priv = seq->private;
33536dfe9acSMordechay Goodstein const struct iwl_fw *fw = priv->fwrt->fw;
33636dfe9acSMordechay Goodstein const struct iwl_fw_cmd_version *ver;
33736dfe9acSMordechay Goodstein u32 cmd_id;
338a114c4f5SAlon Giladi int has_capa;
33936dfe9acSMordechay Goodstein
340a114c4f5SAlon Giladi if (!state->pos) {
341a114c4f5SAlon Giladi seq_puts(seq, "fw_capa:\n");
342a114c4f5SAlon Giladi has_capa = fw_has_capa(&fw->ucode_capa,
343a114c4f5SAlon Giladi IWL_UCODE_TLV_CAPA_PPAG_CHINA_BIOS_SUPPORT) ? 1 : 0;
344a114c4f5SAlon Giladi seq_printf(seq,
345a114c4f5SAlon Giladi " %d: %d\n",
346a114c4f5SAlon Giladi IWL_UCODE_TLV_CAPA_PPAG_CHINA_BIOS_SUPPORT,
347a114c4f5SAlon Giladi has_capa);
34836dfe9acSMordechay Goodstein seq_puts(seq, "fw_api_ver:\n");
349a114c4f5SAlon Giladi }
35036dfe9acSMordechay Goodstein
35136dfe9acSMordechay Goodstein ver = &fw->ucode_capa.cmd_versions[state->pos];
35236dfe9acSMordechay Goodstein
353f0c86427SJohannes Berg cmd_id = WIDE_ID(ver->group, ver->cmd);
35436dfe9acSMordechay Goodstein
35536dfe9acSMordechay Goodstein seq_printf(seq, " 0x%04x:\n", cmd_id);
35636dfe9acSMordechay Goodstein seq_printf(seq, " name: %s\n",
35736dfe9acSMordechay Goodstein iwl_get_cmd_string(priv->fwrt->trans, cmd_id));
35836dfe9acSMordechay Goodstein seq_printf(seq, " cmd_ver: %d\n", ver->cmd_ver);
35936dfe9acSMordechay Goodstein seq_printf(seq, " notif_ver: %d\n", ver->notif_ver);
36036dfe9acSMordechay Goodstein return 0;
36136dfe9acSMordechay Goodstein }
36236dfe9acSMordechay Goodstein
36336dfe9acSMordechay Goodstein static const struct seq_operations iwl_dbgfs_info_seq_ops = {
36436dfe9acSMordechay Goodstein .start = iwl_dbgfs_fw_info_seq_start,
36536dfe9acSMordechay Goodstein .next = iwl_dbgfs_fw_info_seq_next,
36636dfe9acSMordechay Goodstein .stop = iwl_dbgfs_fw_info_seq_stop,
36736dfe9acSMordechay Goodstein .show = iwl_dbgfs_fw_info_seq_show,
36836dfe9acSMordechay Goodstein };
36936dfe9acSMordechay Goodstein
iwl_dbgfs_fw_info_open(struct inode * inode,struct file * filp)37036dfe9acSMordechay Goodstein static int iwl_dbgfs_fw_info_open(struct inode *inode, struct file *filp)
37136dfe9acSMordechay Goodstein {
37236dfe9acSMordechay Goodstein struct iwl_dbgfs_fw_info_priv *priv;
37336dfe9acSMordechay Goodstein
37436dfe9acSMordechay Goodstein priv = __seq_open_private(filp, &iwl_dbgfs_info_seq_ops,
37536dfe9acSMordechay Goodstein sizeof(*priv));
37636dfe9acSMordechay Goodstein
37736dfe9acSMordechay Goodstein if (!priv)
37836dfe9acSMordechay Goodstein return -ENOMEM;
37936dfe9acSMordechay Goodstein
38036dfe9acSMordechay Goodstein priv->fwrt = inode->i_private;
38136dfe9acSMordechay Goodstein return 0;
38236dfe9acSMordechay Goodstein }
38336dfe9acSMordechay Goodstein
38436dfe9acSMordechay Goodstein static const struct file_operations iwl_dbgfs_fw_info_ops = {
38536dfe9acSMordechay Goodstein .owner = THIS_MODULE,
38636dfe9acSMordechay Goodstein .open = iwl_dbgfs_fw_info_open,
38736dfe9acSMordechay Goodstein .read = seq_read,
38836dfe9acSMordechay Goodstein .llseek = seq_lseek,
38936dfe9acSMordechay Goodstein .release = seq_release_private,
39036dfe9acSMordechay Goodstein };
39136dfe9acSMordechay Goodstein
iwl_fwrt_dbgfs_register(struct iwl_fw_runtime * fwrt,struct dentry * dbgfs_dir)3925987dfdeSGreg Kroah-Hartman void iwl_fwrt_dbgfs_register(struct iwl_fw_runtime *fwrt,
39393b167c1SMordechay Goodstein struct dentry *dbgfs_dir)
39493b167c1SMordechay Goodstein {
39593b167c1SMordechay Goodstein INIT_DELAYED_WORK(&fwrt->timestamp.wk, iwl_fw_timestamp_marker_wk);
3962ef00c53SJoe Perches FWRT_DEBUGFS_ADD_FILE(timestamp_marker, dbgfs_dir, 0200);
39736dfe9acSMordechay Goodstein FWRT_DEBUGFS_ADD_FILE(fw_info, dbgfs_dir, 0200);
398755384b3SShahar S Matityahu FWRT_DEBUGFS_ADD_FILE(send_hcmd, dbgfs_dir, 0200);
39987f1283bSMordechay Goodstein FWRT_DEBUGFS_ADD_FILE(enabled_severities, dbgfs_dir, 0200);
40010137f07SLuca Coelho FWRT_DEBUGFS_ADD_FILE(fw_dbg_domain, dbgfs_dir, 0400);
40193b167c1SMordechay Goodstein }
402