Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Debugfs interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2020, Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Authors: Gil Fine <gil.fine@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	    Mika Westerberg <mika.westerberg@linux.intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "tb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define PORT_CAP_PCIE_LEN	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define PORT_CAP_POWER_LEN	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define PORT_CAP_LANE_LEN	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define PORT_CAP_USB3_LEN	5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define PORT_CAP_DP_LEN		8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define PORT_CAP_TMU_LEN	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define PORT_CAP_BASIC_LEN	9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define PORT_CAP_USB4_LEN	20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define SWITCH_CAP_TMU_LEN	26
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define SWITCH_CAP_BASIC_LEN	27
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define PATH_LEN		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define COUNTER_SET_LEN		3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define DEBUGFS_ATTR(__space, __write)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static int __space ## _open(struct inode *inode, struct file *file)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return single_open(file, __space ## _show, inode->i_private);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static const struct file_operations __space ## _fops = {		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	.owner = THIS_MODULE,						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	.open = __space ## _open,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	.release = single_release,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	.read  = seq_read,						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	.write = __write,						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	.llseek = seq_lseek,						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define DEBUGFS_ATTR_RO(__space)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	DEBUGFS_ATTR(__space, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define DEBUGFS_ATTR_RW(__space)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	DEBUGFS_ATTR(__space, __space ## _write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static struct dentry *tb_debugfs_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static void *validate_and_copy_from_user(const void __user *user_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 					 size_t *count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	size_t nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	void *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	if (!*count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (!access_ok(user_buf, *count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return ERR_PTR(-EFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	buf = (void *)get_zeroed_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	nbytes = min_t(size_t, *count, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (copy_from_user(buf, user_buf, nbytes)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		free_page((unsigned long)buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		return ERR_PTR(-EFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	*count = nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static bool parse_line(char **line, u32 *offs, u32 *val, int short_fmt_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		       int long_fmt_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	char *token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	u32 v[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	token = strsep(line, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (!token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	 * For Adapter/Router configuration space:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	 * Short format is: offset value\n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	 *		    v[0]   v[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	 * Long format as produced from the read side:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	 * offset relative_offset cap_id vs_cap_id value\n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	 * v[0]   v[1]            v[2]   v[3]      v[4]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	 * For Counter configuration space:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	 * Short format is: offset\n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	 *		    v[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	 * Long format as produced from the read side:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	 * offset relative_offset counter_id value\n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	 * v[0]   v[1]            v[2]       v[3]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	ret = sscanf(token, "%i %i %i %i %i", &v[0], &v[1], &v[2], &v[3], &v[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	/* In case of Counters, clear counter, "val" content is NA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (ret == short_fmt_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		*offs = v[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		*val = v[short_fmt_len - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	} else if (ret == long_fmt_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		*offs = v[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		*val = v[long_fmt_len - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #if IS_ENABLED(CONFIG_USB4_DEBUGFS_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static ssize_t regs_write(struct tb_switch *sw, struct tb_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			  const char __user *user_buf, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			  loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct tb *tb = sw->tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	char *line, *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	u32 val, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	buf = validate_and_copy_from_user(user_buf, &count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (IS_ERR(buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return PTR_ERR(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	pm_runtime_get_sync(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (mutex_lock_interruptible(&tb->lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		ret = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/* User did hardware changes behind the driver's back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	add_taint(TAINT_USER, LOCKDEP_STILL_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	line = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	while (parse_line(&line, &offset, &val, 2, 5)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		if (port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			ret = tb_port_write(port, &val, TB_CFG_PORT, offset, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, offset, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	mutex_unlock(&tb->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	pm_runtime_mark_last_busy(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	pm_runtime_put_autosuspend(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	free_page((unsigned long)buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return ret < 0 ? ret : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static ssize_t port_regs_write(struct file *file, const char __user *user_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			       size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct seq_file *s = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct tb_port *port = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	return regs_write(port->sw, port, user_buf, count, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static ssize_t switch_regs_write(struct file *file, const char __user *user_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 				 size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	struct seq_file *s = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct tb_switch *sw = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	return regs_write(sw, NULL, user_buf, count, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #define DEBUGFS_MODE		0600
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #define port_regs_write		NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #define switch_regs_write	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #define DEBUGFS_MODE		0400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static int port_clear_all_counters(struct tb_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	u32 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	buf = kcalloc(COUNTER_SET_LEN * port->config.max_counters, sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		      GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	ret = tb_port_write(port, buf, TB_CFG_COUNTERS, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			    COUNTER_SET_LEN * port->config.max_counters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static ssize_t counters_write(struct file *file, const char __user *user_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			      size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	struct seq_file *s = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	struct tb_port *port = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	struct tb_switch *sw = port->sw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	struct tb *tb = port->sw->tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	buf = validate_and_copy_from_user(user_buf, &count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (IS_ERR(buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return PTR_ERR(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	pm_runtime_get_sync(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (mutex_lock_interruptible(&tb->lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		ret = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	/* If written delimiter only, clear all counters in one shot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (buf[0] == '\n') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		ret = port_clear_all_counters(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	} else  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		char *line = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		u32 val, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		while (parse_line(&line, &offset, &val, 1, 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			ret = tb_port_write(port, &val, TB_CFG_COUNTERS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 					    offset, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	mutex_unlock(&tb->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	pm_runtime_mark_last_busy(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	pm_runtime_put_autosuspend(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	free_page((unsigned long)buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return ret < 0 ? ret : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static void cap_show(struct seq_file *s, struct tb_switch *sw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		     struct tb_port *port, unsigned int cap, u8 cap_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		     u8 vsec_id, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	int ret, offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	while (length > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		int i, dwords = min(length, TB_MAX_CONFIG_RW_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		u32 data[TB_MAX_CONFIG_RW_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		if (port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			ret = tb_port_read(port, data, TB_CFG_PORT, cap + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 					   dwords);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			ret = tb_sw_read(sw, data, TB_CFG_SWITCH, cap + offset, dwords);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			seq_printf(s, "0x%04x <not accessible>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 				   cap + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			if (dwords > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				seq_printf(s, "0x%04x ...\n", cap + offset + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		for (i = 0; i < dwords; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			seq_printf(s, "0x%04x %4d 0x%02x 0x%02x 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 				   cap + offset + i, offset + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 				   cap_id, vsec_id, data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		length -= dwords;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		offset += dwords;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static void port_cap_show(struct tb_port *port, struct seq_file *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			  unsigned int cap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	struct tb_cap_any header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	u8 vsec_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	size_t length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	ret = tb_port_read(port, &header, TB_CFG_PORT, cap, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		seq_printf(s, "0x%04x <capability read failed>\n", cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	switch (header.basic.cap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	case TB_PORT_CAP_PHY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		length = PORT_CAP_LANE_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	case TB_PORT_CAP_TIME1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		length = PORT_CAP_TMU_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	case TB_PORT_CAP_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		length = PORT_CAP_POWER_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	case TB_PORT_CAP_ADAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		if (tb_port_is_pcie_down(port) || tb_port_is_pcie_up(port)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			length = PORT_CAP_PCIE_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		} else if (tb_port_is_dpin(port) || tb_port_is_dpout(port)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			length = PORT_CAP_DP_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		} else if (tb_port_is_usb3_down(port) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			   tb_port_is_usb3_up(port)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			length = PORT_CAP_USB3_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			seq_printf(s, "0x%04x <unsupported capability 0x%02x>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 				   cap, header.basic.cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	case TB_PORT_CAP_VSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		if (!header.extended_short.length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			ret = tb_port_read(port, (u32 *)&header + 1, TB_CFG_PORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 					   cap + 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 				seq_printf(s, "0x%04x <capability read failed>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 					   cap + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			length = header.extended_long.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			vsec_id = header.extended_short.vsec_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			length = header.extended_short.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			vsec_id = header.extended_short.vsec_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			 * Ice Lake and Tiger Lake do not implement the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			 * full length of the capability, only first 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			 * dwords so hard-code it here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			if (!vsec_id &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 			    (tb_switch_is_ice_lake(port->sw) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			     tb_switch_is_tiger_lake(port->sw)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 				length = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	case TB_PORT_CAP_USB4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		length = PORT_CAP_USB4_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		seq_printf(s, "0x%04x <unsupported capability 0x%02x>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			   cap, header.basic.cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	cap_show(s, NULL, port, cap, header.basic.cap, vsec_id, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static void port_caps_show(struct tb_port *port, struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	int cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	cap = tb_port_next_cap(port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	while (cap > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		port_cap_show(port, s, cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		cap = tb_port_next_cap(port, cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static int port_basic_regs_show(struct tb_port *port, struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	u32 data[PORT_CAP_BASIC_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	ret = tb_port_read(port, data, TB_CFG_PORT, 0, ARRAY_SIZE(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	for (i = 0; i < ARRAY_SIZE(data); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		seq_printf(s, "0x%04x %4d 0x00 0x00 0x%08x\n", i, i, data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) static int port_regs_show(struct seq_file *s, void *not_used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	struct tb_port *port = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct tb_switch *sw = port->sw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	struct tb *tb = sw->tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	pm_runtime_get_sync(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	if (mutex_lock_interruptible(&tb->lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		ret = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		goto out_rpm_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	seq_puts(s, "# offset relative_offset cap_id vs_cap_id value\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	ret = port_basic_regs_show(port, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	port_caps_show(port, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	mutex_unlock(&tb->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) out_rpm_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	pm_runtime_mark_last_busy(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	pm_runtime_put_autosuspend(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) DEBUGFS_ATTR_RW(port_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static void switch_cap_show(struct tb_switch *sw, struct seq_file *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			    unsigned int cap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	struct tb_cap_any header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	int ret, length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	u8 vsec_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	ret = tb_sw_read(sw, &header, TB_CFG_SWITCH, cap, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		seq_printf(s, "0x%04x <capability read failed>\n", cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	if (header.basic.cap == TB_SWITCH_CAP_VSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		if (!header.extended_short.length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 			ret = tb_sw_read(sw, (u32 *)&header + 1, TB_CFG_SWITCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 					 cap + 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 				seq_printf(s, "0x%04x <capability read failed>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 					   cap + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 			length = header.extended_long.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 			length = header.extended_short.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		vsec_id = header.extended_short.vsec_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		if (header.basic.cap == TB_SWITCH_CAP_TMU) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 			length = SWITCH_CAP_TMU_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		} else  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 			seq_printf(s, "0x%04x <unknown capability 0x%02x>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 				   cap, header.basic.cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	cap_show(s, sw, NULL, cap, header.basic.cap, vsec_id, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static void switch_caps_show(struct tb_switch *sw, struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	int cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	cap = tb_switch_next_cap(sw, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	while (cap > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		switch_cap_show(sw, s, cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		cap = tb_switch_next_cap(sw, cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static int switch_basic_regs_show(struct tb_switch *sw, struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	u32 data[SWITCH_CAP_BASIC_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	size_t dwords;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	/* Only USB4 has the additional registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	if (tb_switch_is_usb4(sw))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		dwords = ARRAY_SIZE(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		dwords = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	ret = tb_sw_read(sw, data, TB_CFG_SWITCH, 0, dwords);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	for (i = 0; i < dwords; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		seq_printf(s, "0x%04x %4d 0x00 0x00 0x%08x\n", i, i, data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static int switch_regs_show(struct seq_file *s, void *not_used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	struct tb_switch *sw = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	struct tb *tb = sw->tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	pm_runtime_get_sync(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	if (mutex_lock_interruptible(&tb->lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		ret = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		goto out_rpm_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	seq_puts(s, "# offset relative_offset cap_id vs_cap_id value\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	ret = switch_basic_regs_show(sw, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	switch_caps_show(sw, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	mutex_unlock(&tb->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) out_rpm_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	pm_runtime_mark_last_busy(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	pm_runtime_put_autosuspend(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) DEBUGFS_ATTR_RW(switch_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) static int path_show_one(struct tb_port *port, struct seq_file *s, int hopid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	u32 data[PATH_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	ret = tb_port_read(port, data, TB_CFG_HOPS, hopid * PATH_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 			   ARRAY_SIZE(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		seq_printf(s, "0x%04x <not accessible>\n", hopid * PATH_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	for (i = 0; i < ARRAY_SIZE(data); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		seq_printf(s, "0x%04x %4d 0x%02x 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 			   hopid * PATH_LEN + i, i, hopid, data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) static int path_show(struct seq_file *s, void *not_used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	struct tb_port *port = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	struct tb_switch *sw = port->sw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	struct tb *tb = sw->tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	int start, i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	pm_runtime_get_sync(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	if (mutex_lock_interruptible(&tb->lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		ret = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 		goto out_rpm_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	seq_puts(s, "# offset relative_offset in_hop_id value\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	/* NHI and lane adapters have entry for path 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	if (tb_port_is_null(port) || tb_port_is_nhi(port)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		ret = path_show_one(port, s, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	start = tb_port_is_nhi(port) ? 1 : TB_PATH_MIN_HOPID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	for (i = start; i <= port->config.max_in_hop_id; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		ret = path_show_one(port, s, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	mutex_unlock(&tb->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) out_rpm_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	pm_runtime_mark_last_busy(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	pm_runtime_put_autosuspend(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) DEBUGFS_ATTR_RO(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) static int counter_set_regs_show(struct tb_port *port, struct seq_file *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 				 int counter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	u32 data[COUNTER_SET_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	ret = tb_port_read(port, data, TB_CFG_COUNTERS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 			   counter * COUNTER_SET_LEN, ARRAY_SIZE(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		seq_printf(s, "0x%04x <not accessible>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 			   counter * COUNTER_SET_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	for (i = 0; i < ARRAY_SIZE(data); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 		seq_printf(s, "0x%04x %4d 0x%02x 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 			   counter * COUNTER_SET_LEN + i, i, counter, data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) static int counters_show(struct seq_file *s, void *not_used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	struct tb_port *port = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	struct tb_switch *sw = port->sw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	struct tb *tb = sw->tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	int i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	pm_runtime_get_sync(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	if (mutex_lock_interruptible(&tb->lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		ret = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	seq_puts(s, "# offset relative_offset counter_id value\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	for (i = 0; i < port->config.max_counters; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		ret = counter_set_regs_show(port, s, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	mutex_unlock(&tb->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	pm_runtime_mark_last_busy(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	pm_runtime_put_autosuspend(&sw->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) DEBUGFS_ATTR_RW(counters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)  * tb_switch_debugfs_init() - Add debugfs entries for router
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)  * @sw: Pointer to the router
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)  * Adds debugfs directories and files for given router.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) void tb_switch_debugfs_init(struct tb_switch *sw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	struct dentry *debugfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	struct tb_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	debugfs_dir = debugfs_create_dir(dev_name(&sw->dev), tb_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	sw->debugfs_dir = debugfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	debugfs_create_file("regs", DEBUGFS_MODE, debugfs_dir, sw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 			    &switch_regs_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	tb_switch_for_each_port(sw, port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 		struct dentry *debugfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		char dir_name[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 		if (port->disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 		if (port->config.type == TB_TYPE_INACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 		snprintf(dir_name, sizeof(dir_name), "port%d", port->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		debugfs_dir = debugfs_create_dir(dir_name, sw->debugfs_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 		debugfs_create_file("regs", DEBUGFS_MODE, debugfs_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 				    port, &port_regs_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 		debugfs_create_file("path", 0400, debugfs_dir, port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 				    &path_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		if (port->config.counters_support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 			debugfs_create_file("counters", 0600, debugfs_dir, port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 					    &counters_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)  * tb_switch_debugfs_remove() - Remove all router debugfs entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)  * @sw: Pointer to the router
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)  * Removes all previously added debugfs entries under this router.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) void tb_switch_debugfs_remove(struct tb_switch *sw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	debugfs_remove_recursive(sw->debugfs_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) void tb_debugfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	tb_debugfs_root = debugfs_create_dir("thunderbolt", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) void tb_debugfs_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	debugfs_remove_recursive(tb_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) }