diff options
author | Hariprasad Shenai <hariprasad@chelsio.com> | 2014-11-06 23:05:23 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-11-10 12:57:10 -0500 |
commit | fd88b31a1d49f08911ed291e46e5bc6e8afabdfa (patch) | |
tree | 4950e9ea00a8fffe5726cc88395f8deec4526d98 /drivers/net/ethernet/chelsio | |
parent | 1a2881728211f0915c0fa1364770b9c73a67a073 (diff) |
cxgb4: Add cxgb4_debugfs.c, move all debugfs code to new file
Signed-off-by: Hariprasad Shenai <hariprasad@chelsio.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/chelsio')
-rw-r--r-- | drivers/net/ethernet/chelsio/cxgb4/Makefile | 1 | ||||
-rw-r--r-- | drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 1 | ||||
-rw-r--r-- | drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 158 | ||||
-rw-r--r-- | drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.h | 52 | ||||
-rw-r--r-- | drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 97 |
5 files changed, 217 insertions, 92 deletions
diff --git a/drivers/net/ethernet/chelsio/cxgb4/Makefile b/drivers/net/ethernet/chelsio/cxgb4/Makefile index 1df65c915b99..b85280775997 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/Makefile +++ b/drivers/net/ethernet/chelsio/cxgb4/Makefile | |||
@@ -6,3 +6,4 @@ obj-$(CONFIG_CHELSIO_T4) += cxgb4.o | |||
6 | 6 | ||
7 | cxgb4-objs := cxgb4_main.o l2t.o t4_hw.o sge.o | 7 | cxgb4-objs := cxgb4_main.o l2t.o t4_hw.o sge.o |
8 | cxgb4-$(CONFIG_CHELSIO_T4_DCB) += cxgb4_dcb.o | 8 | cxgb4-$(CONFIG_CHELSIO_T4_DCB) += cxgb4_dcb.o |
9 | cxgb4-$(CONFIG_DEBUG_FS) += cxgb4_debugfs.o | ||
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h b/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h index 3c481b260745..dad1ea930e05 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | |||
@@ -1085,4 +1085,5 @@ void t4_db_dropped(struct adapter *adapter); | |||
1085 | int t4_fwaddrspace_write(struct adapter *adap, unsigned int mbox, | 1085 | int t4_fwaddrspace_write(struct adapter *adap, unsigned int mbox, |
1086 | u32 addr, u32 val); | 1086 | u32 addr, u32 val); |
1087 | void t4_sge_decode_idma_state(struct adapter *adapter, int state); | 1087 | void t4_sge_decode_idma_state(struct adapter *adapter, int state); |
1088 | void t4_free_mem(void *addr); | ||
1088 | #endif /* __CXGB4_H__ */ | 1089 | #endif /* __CXGB4_H__ */ |
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c new file mode 100644 index 000000000000..e86b5fe334e6 --- /dev/null +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c | |||
@@ -0,0 +1,158 @@ | |||
1 | /* | ||
2 | * This file is part of the Chelsio T4 Ethernet driver for Linux. | ||
3 | * | ||
4 | * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved. | ||
5 | * | ||
6 | * This software is available to you under a choice of one of two | ||
7 | * licenses. You may choose to be licensed under the terms of the GNU | ||
8 | * General Public License (GPL) Version 2, available from the file | ||
9 | * COPYING in the main directory of this source tree, or the | ||
10 | * OpenIB.org BSD license below: | ||
11 | * | ||
12 | * Redistribution and use in source and binary forms, with or | ||
13 | * without modification, are permitted provided that the following | ||
14 | * conditions are met: | ||
15 | * | ||
16 | * - Redistributions of source code must retain the above | ||
17 | * copyright notice, this list of conditions and the following | ||
18 | * disclaimer. | ||
19 | * | ||
20 | * - Redistributions in binary form must reproduce the above | ||
21 | * copyright notice, this list of conditions and the following | ||
22 | * disclaimer in the documentation and/or other materials | ||
23 | * provided with the distribution. | ||
24 | * | ||
25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
29 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
30 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
31 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
32 | * SOFTWARE. | ||
33 | */ | ||
34 | |||
35 | #include <linux/seq_file.h> | ||
36 | #include <linux/debugfs.h> | ||
37 | #include <linux/string_helpers.h> | ||
38 | #include <linux/sort.h> | ||
39 | |||
40 | #include "cxgb4.h" | ||
41 | #include "t4_regs.h" | ||
42 | #include "t4fw_api.h" | ||
43 | #include "cxgb4_debugfs.h" | ||
44 | #include "l2t.h" | ||
45 | |||
46 | static ssize_t mem_read(struct file *file, char __user *buf, size_t count, | ||
47 | loff_t *ppos) | ||
48 | { | ||
49 | loff_t pos = *ppos; | ||
50 | loff_t avail = file_inode(file)->i_size; | ||
51 | unsigned int mem = (uintptr_t)file->private_data & 3; | ||
52 | struct adapter *adap = file->private_data - mem; | ||
53 | __be32 *data; | ||
54 | int ret; | ||
55 | |||
56 | if (pos < 0) | ||
57 | return -EINVAL; | ||
58 | if (pos >= avail) | ||
59 | return 0; | ||
60 | if (count > avail - pos) | ||
61 | count = avail - pos; | ||
62 | |||
63 | data = t4_alloc_mem(count); | ||
64 | if (!data) | ||
65 | return -ENOMEM; | ||
66 | |||
67 | spin_lock(&adap->win0_lock); | ||
68 | ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ); | ||
69 | spin_unlock(&adap->win0_lock); | ||
70 | if (ret) { | ||
71 | t4_free_mem(data); | ||
72 | return ret; | ||
73 | } | ||
74 | ret = copy_to_user(buf, data, count); | ||
75 | |||
76 | t4_free_mem(data); | ||
77 | if (ret) | ||
78 | return -EFAULT; | ||
79 | |||
80 | *ppos = pos + count; | ||
81 | return count; | ||
82 | } | ||
83 | |||
84 | static const struct file_operations mem_debugfs_fops = { | ||
85 | .owner = THIS_MODULE, | ||
86 | .open = simple_open, | ||
87 | .read = mem_read, | ||
88 | .llseek = default_llseek, | ||
89 | }; | ||
90 | |||
91 | static void add_debugfs_mem(struct adapter *adap, const char *name, | ||
92 | unsigned int idx, unsigned int size_mb) | ||
93 | { | ||
94 | struct dentry *de; | ||
95 | |||
96 | de = debugfs_create_file(name, S_IRUSR, adap->debugfs_root, | ||
97 | (void *)adap + idx, &mem_debugfs_fops); | ||
98 | if (de && de->d_inode) | ||
99 | de->d_inode->i_size = size_mb << 20; | ||
100 | } | ||
101 | |||
102 | /* Add an array of Debug FS files. | ||
103 | */ | ||
104 | void add_debugfs_files(struct adapter *adap, | ||
105 | struct t4_debugfs_entry *files, | ||
106 | unsigned int nfiles) | ||
107 | { | ||
108 | int i; | ||
109 | |||
110 | /* debugfs support is best effort */ | ||
111 | for (i = 0; i < nfiles; i++) | ||
112 | debugfs_create_file(files[i].name, files[i].mode, | ||
113 | adap->debugfs_root, | ||
114 | (void *)adap + files[i].data, | ||
115 | files[i].ops); | ||
116 | } | ||
117 | |||
118 | int t4_setup_debugfs(struct adapter *adap) | ||
119 | { | ||
120 | int i; | ||
121 | u32 size; | ||
122 | |||
123 | static struct t4_debugfs_entry t4_debugfs_files[] = { | ||
124 | { "l2t", &t4_l2t_fops, S_IRUSR, 0}, | ||
125 | }; | ||
126 | |||
127 | add_debugfs_files(adap, | ||
128 | t4_debugfs_files, | ||
129 | ARRAY_SIZE(t4_debugfs_files)); | ||
130 | |||
131 | i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE); | ||
132 | if (i & EDRAM0_ENABLE) { | ||
133 | size = t4_read_reg(adap, MA_EDRAM0_BAR); | ||
134 | add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM_SIZE_GET(size)); | ||
135 | } | ||
136 | if (i & EDRAM1_ENABLE) { | ||
137 | size = t4_read_reg(adap, MA_EDRAM1_BAR); | ||
138 | add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM_SIZE_GET(size)); | ||
139 | } | ||
140 | if (is_t4(adap->params.chip)) { | ||
141 | size = t4_read_reg(adap, MA_EXT_MEMORY_BAR); | ||
142 | if (i & EXT_MEM_ENABLE) | ||
143 | add_debugfs_mem(adap, "mc", MEM_MC, | ||
144 | EXT_MEM_SIZE_GET(size)); | ||
145 | } else { | ||
146 | if (i & EXT_MEM_ENABLE) { | ||
147 | size = t4_read_reg(adap, MA_EXT_MEMORY_BAR); | ||
148 | add_debugfs_mem(adap, "mc0", MEM_MC0, | ||
149 | EXT_MEM_SIZE_GET(size)); | ||
150 | } | ||
151 | if (i & EXT_MEM1_ENABLE) { | ||
152 | size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR); | ||
153 | add_debugfs_mem(adap, "mc1", MEM_MC1, | ||
154 | EXT_MEM_SIZE_GET(size)); | ||
155 | } | ||
156 | } | ||
157 | return 0; | ||
158 | } | ||
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.h b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.h new file mode 100644 index 000000000000..a3d8867efd3d --- /dev/null +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.h | |||
@@ -0,0 +1,52 @@ | |||
1 | /* | ||
2 | * This file is part of the Chelsio T4 Ethernet driver for Linux. | ||
3 | * | ||
4 | * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved. | ||
5 | * | ||
6 | * This software is available to you under a choice of one of two | ||
7 | * licenses. You may choose to be licensed under the terms of the GNU | ||
8 | * General Public License (GPL) Version 2, available from the file | ||
9 | * COPYING in the main directory of this source tree, or the | ||
10 | * OpenIB.org BSD license below: | ||
11 | * | ||
12 | * Redistribution and use in source and binary forms, with or | ||
13 | * without modification, are permitted provided that the following | ||
14 | * conditions are met: | ||
15 | * | ||
16 | * - Redistributions of source code must retain the above | ||
17 | * copyright notice, this list of conditions and the following | ||
18 | * disclaimer. | ||
19 | * | ||
20 | * - Redistributions in binary form must reproduce the above | ||
21 | * copyright notice, this list of conditions and the following | ||
22 | * disclaimer in the documentation and/or other materials | ||
23 | * provided with the distribution. | ||
24 | * | ||
25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
29 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
30 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
31 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
32 | * SOFTWARE. | ||
33 | */ | ||
34 | |||
35 | #ifndef __CXGB4_DEBUGFS_H | ||
36 | #define __CXGB4_DEBUGFS_H | ||
37 | |||
38 | #include <linux/export.h> | ||
39 | |||
40 | struct t4_debugfs_entry { | ||
41 | const char *name; | ||
42 | const struct file_operations *ops; | ||
43 | mode_t mode; | ||
44 | unsigned char data; | ||
45 | }; | ||
46 | |||
47 | int t4_setup_debugfs(struct adapter *adap); | ||
48 | void add_debugfs_files(struct adapter *adap, | ||
49 | struct t4_debugfs_entry *files, | ||
50 | unsigned int nfiles); | ||
51 | |||
52 | #endif | ||
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c index 8520d5529df8..172f68b6d592 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | |||
@@ -68,6 +68,7 @@ | |||
68 | #include "t4_msg.h" | 68 | #include "t4_msg.h" |
69 | #include "t4fw_api.h" | 69 | #include "t4fw_api.h" |
70 | #include "cxgb4_dcb.h" | 70 | #include "cxgb4_dcb.h" |
71 | #include "cxgb4_debugfs.h" | ||
71 | #include "l2t.h" | 72 | #include "l2t.h" |
72 | 73 | ||
73 | #include <../drivers/net/bonding/bonding.h> | 74 | #include <../drivers/net/bonding/bonding.h> |
@@ -1287,7 +1288,7 @@ void *t4_alloc_mem(size_t size) | |||
1287 | /* | 1288 | /* |
1288 | * Free memory allocated through alloc_mem(). | 1289 | * Free memory allocated through alloc_mem(). |
1289 | */ | 1290 | */ |
1290 | static void t4_free_mem(void *addr) | 1291 | void t4_free_mem(void *addr) |
1291 | { | 1292 | { |
1292 | if (is_vmalloc_addr(addr)) | 1293 | if (is_vmalloc_addr(addr)) |
1293 | vfree(addr); | 1294 | vfree(addr); |
@@ -3127,102 +3128,14 @@ static const struct ethtool_ops cxgb_ethtool_ops = { | |||
3127 | .flash_device = set_flash, | 3128 | .flash_device = set_flash, |
3128 | }; | 3129 | }; |
3129 | 3130 | ||
3130 | /* | ||
3131 | * debugfs support | ||
3132 | */ | ||
3133 | static ssize_t mem_read(struct file *file, char __user *buf, size_t count, | ||
3134 | loff_t *ppos) | ||
3135 | { | ||
3136 | loff_t pos = *ppos; | ||
3137 | loff_t avail = file_inode(file)->i_size; | ||
3138 | unsigned int mem = (uintptr_t)file->private_data & 3; | ||
3139 | struct adapter *adap = file->private_data - mem; | ||
3140 | __be32 *data; | ||
3141 | int ret; | ||
3142 | |||
3143 | if (pos < 0) | ||
3144 | return -EINVAL; | ||
3145 | if (pos >= avail) | ||
3146 | return 0; | ||
3147 | if (count > avail - pos) | ||
3148 | count = avail - pos; | ||
3149 | |||
3150 | data = t4_alloc_mem(count); | ||
3151 | if (!data) | ||
3152 | return -ENOMEM; | ||
3153 | |||
3154 | spin_lock(&adap->win0_lock); | ||
3155 | ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ); | ||
3156 | spin_unlock(&adap->win0_lock); | ||
3157 | if (ret) { | ||
3158 | t4_free_mem(data); | ||
3159 | return ret; | ||
3160 | } | ||
3161 | ret = copy_to_user(buf, data, count); | ||
3162 | |||
3163 | t4_free_mem(data); | ||
3164 | if (ret) | ||
3165 | return -EFAULT; | ||
3166 | |||
3167 | *ppos = pos + count; | ||
3168 | return count; | ||
3169 | } | ||
3170 | |||
3171 | static const struct file_operations mem_debugfs_fops = { | ||
3172 | .owner = THIS_MODULE, | ||
3173 | .open = simple_open, | ||
3174 | .read = mem_read, | ||
3175 | .llseek = default_llseek, | ||
3176 | }; | ||
3177 | |||
3178 | static void add_debugfs_mem(struct adapter *adap, const char *name, | ||
3179 | unsigned int idx, unsigned int size_mb) | ||
3180 | { | ||
3181 | struct dentry *de; | ||
3182 | |||
3183 | de = debugfs_create_file(name, S_IRUSR, adap->debugfs_root, | ||
3184 | (void *)adap + idx, &mem_debugfs_fops); | ||
3185 | if (de && de->d_inode) | ||
3186 | de->d_inode->i_size = size_mb << 20; | ||
3187 | } | ||
3188 | |||
3189 | static int setup_debugfs(struct adapter *adap) | 3131 | static int setup_debugfs(struct adapter *adap) |
3190 | { | 3132 | { |
3191 | int i; | ||
3192 | u32 size; | ||
3193 | |||
3194 | if (IS_ERR_OR_NULL(adap->debugfs_root)) | 3133 | if (IS_ERR_OR_NULL(adap->debugfs_root)) |
3195 | return -1; | 3134 | return -1; |
3196 | 3135 | ||
3197 | i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE); | 3136 | #ifdef CONFIG_DEBUG_FS |
3198 | if (i & EDRAM0_ENABLE) { | 3137 | t4_setup_debugfs(adap); |
3199 | size = t4_read_reg(adap, MA_EDRAM0_BAR); | 3138 | #endif |
3200 | add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM_SIZE_GET(size)); | ||
3201 | } | ||
3202 | if (i & EDRAM1_ENABLE) { | ||
3203 | size = t4_read_reg(adap, MA_EDRAM1_BAR); | ||
3204 | add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM_SIZE_GET(size)); | ||
3205 | } | ||
3206 | if (is_t4(adap->params.chip)) { | ||
3207 | size = t4_read_reg(adap, MA_EXT_MEMORY_BAR); | ||
3208 | if (i & EXT_MEM_ENABLE) | ||
3209 | add_debugfs_mem(adap, "mc", MEM_MC, | ||
3210 | EXT_MEM_SIZE_GET(size)); | ||
3211 | } else { | ||
3212 | if (i & EXT_MEM_ENABLE) { | ||
3213 | size = t4_read_reg(adap, MA_EXT_MEMORY_BAR); | ||
3214 | add_debugfs_mem(adap, "mc0", MEM_MC0, | ||
3215 | EXT_MEM_SIZE_GET(size)); | ||
3216 | } | ||
3217 | if (i & EXT_MEM1_ENABLE) { | ||
3218 | size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR); | ||
3219 | add_debugfs_mem(adap, "mc1", MEM_MC1, | ||
3220 | EXT_MEM_SIZE_GET(size)); | ||
3221 | } | ||
3222 | } | ||
3223 | if (adap->l2t) | ||
3224 | debugfs_create_file("l2t", S_IRUSR, adap->debugfs_root, adap, | ||
3225 | &t4_l2t_fops); | ||
3226 | return 0; | 3139 | return 0; |
3227 | } | 3140 | } |
3228 | 3141 | ||