This source file includes following definitions.
- crdump_enable_crspace_access
- crdump_disable_crspace_access
- mlx4_crdump_collect_crspace
- mlx4_crdump_collect_fw_health
- mlx4_crdump_collect
- mlx4_crdump_init
- mlx4_crdump_end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #include "mlx4.h"
34
35 #define BAD_ACCESS 0xBADACCE5
36 #define HEALTH_BUFFER_SIZE 0x40
37 #define CR_ENABLE_BIT swab32(BIT(6))
38 #define CR_ENABLE_BIT_OFFSET 0xF3F04
39 #define MAX_NUM_OF_DUMPS_TO_STORE (8)
40
41 static const char *region_cr_space_str = "cr-space";
42 static const char *region_fw_health_str = "fw-health";
43
44
45 static bool crdump_enbale_bit_set;
46
47 static void crdump_enable_crspace_access(struct mlx4_dev *dev,
48 u8 __iomem *cr_space)
49 {
50
51 crdump_enbale_bit_set =
52 readl(cr_space + CR_ENABLE_BIT_OFFSET) & CR_ENABLE_BIT;
53
54
55 if (crdump_enbale_bit_set)
56 writel(readl(cr_space + CR_ENABLE_BIT_OFFSET) & ~CR_ENABLE_BIT,
57 cr_space + CR_ENABLE_BIT_OFFSET);
58
59
60 writel(swab32(1), cr_space + dev->caps.health_buffer_addrs +
61 HEALTH_BUFFER_SIZE);
62 }
63
64 static void crdump_disable_crspace_access(struct mlx4_dev *dev,
65 u8 __iomem *cr_space)
66 {
67
68 writel(0, cr_space + dev->caps.health_buffer_addrs +
69 HEALTH_BUFFER_SIZE);
70
71
72 if (crdump_enbale_bit_set)
73 writel(readl(cr_space + CR_ENABLE_BIT_OFFSET) | CR_ENABLE_BIT,
74 cr_space + CR_ENABLE_BIT_OFFSET);
75 }
76
77 static void mlx4_crdump_collect_crspace(struct mlx4_dev *dev,
78 u8 __iomem *cr_space,
79 u32 id)
80 {
81 struct mlx4_fw_crdump *crdump = &dev->persist->crdump;
82 struct pci_dev *pdev = dev->persist->pdev;
83 unsigned long cr_res_size;
84 u8 *crspace_data;
85 int offset;
86 int err;
87
88 if (!crdump->region_crspace) {
89 mlx4_err(dev, "crdump: cr-space region is NULL\n");
90 return;
91 }
92
93
94 cr_res_size = pci_resource_len(pdev, 0);
95 crspace_data = kvmalloc(cr_res_size, GFP_KERNEL);
96 if (crspace_data) {
97 for (offset = 0; offset < cr_res_size; offset += 4)
98 *(u32 *)(crspace_data + offset) =
99 readl(cr_space + offset);
100
101 err = devlink_region_snapshot_create(crdump->region_crspace,
102 crspace_data, id, &kvfree);
103 if (err) {
104 kvfree(crspace_data);
105 mlx4_warn(dev, "crdump: devlink create %s snapshot id %d err %d\n",
106 region_cr_space_str, id, err);
107 } else {
108 mlx4_info(dev, "crdump: added snapshot %d to devlink region %s\n",
109 id, region_cr_space_str);
110 }
111 } else {
112 mlx4_err(dev, "crdump: Failed to allocate crspace buffer\n");
113 }
114 }
115
116 static void mlx4_crdump_collect_fw_health(struct mlx4_dev *dev,
117 u8 __iomem *cr_space,
118 u32 id)
119 {
120 struct mlx4_fw_crdump *crdump = &dev->persist->crdump;
121 u8 *health_data;
122 int offset;
123 int err;
124
125 if (!crdump->region_fw_health) {
126 mlx4_err(dev, "crdump: fw-health region is NULL\n");
127 return;
128 }
129
130
131 health_data = kvmalloc(HEALTH_BUFFER_SIZE, GFP_KERNEL);
132 if (health_data) {
133 u8 __iomem *health_buf_start =
134 cr_space + dev->caps.health_buffer_addrs;
135
136 for (offset = 0; offset < HEALTH_BUFFER_SIZE; offset += 4)
137 *(u32 *)(health_data + offset) =
138 readl(health_buf_start + offset);
139
140 err = devlink_region_snapshot_create(crdump->region_fw_health,
141 health_data, id, &kvfree);
142 if (err) {
143 kvfree(health_data);
144 mlx4_warn(dev, "crdump: devlink create %s snapshot id %d err %d\n",
145 region_fw_health_str, id, err);
146 } else {
147 mlx4_info(dev, "crdump: added snapshot %d to devlink region %s\n",
148 id, region_fw_health_str);
149 }
150 } else {
151 mlx4_err(dev, "crdump: Failed to allocate health buffer\n");
152 }
153 }
154
155 int mlx4_crdump_collect(struct mlx4_dev *dev)
156 {
157 struct devlink *devlink = priv_to_devlink(mlx4_priv(dev));
158 struct mlx4_fw_crdump *crdump = &dev->persist->crdump;
159 struct pci_dev *pdev = dev->persist->pdev;
160 unsigned long cr_res_size;
161 u8 __iomem *cr_space;
162 u32 id;
163
164 if (!dev->caps.health_buffer_addrs) {
165 mlx4_info(dev, "crdump: FW doesn't support health buffer access, skipping\n");
166 return 0;
167 }
168
169 if (!crdump->snapshot_enable) {
170 mlx4_info(dev, "crdump: devlink snapshot disabled, skipping\n");
171 return 0;
172 }
173
174 cr_res_size = pci_resource_len(pdev, 0);
175
176 cr_space = ioremap(pci_resource_start(pdev, 0), cr_res_size);
177 if (!cr_space) {
178 mlx4_err(dev, "crdump: Failed to map pci cr region\n");
179 return -ENODEV;
180 }
181
182 crdump_enable_crspace_access(dev, cr_space);
183
184
185 id = devlink_region_shapshot_id_get(devlink);
186
187
188 mlx4_crdump_collect_crspace(dev, cr_space, id);
189 mlx4_crdump_collect_fw_health(dev, cr_space, id);
190
191 crdump_disable_crspace_access(dev, cr_space);
192
193 iounmap(cr_space);
194 return 0;
195 }
196
197 int mlx4_crdump_init(struct mlx4_dev *dev)
198 {
199 struct devlink *devlink = priv_to_devlink(mlx4_priv(dev));
200 struct mlx4_fw_crdump *crdump = &dev->persist->crdump;
201 struct pci_dev *pdev = dev->persist->pdev;
202
203 crdump->snapshot_enable = false;
204
205
206 crdump->region_crspace =
207 devlink_region_create(devlink,
208 region_cr_space_str,
209 MAX_NUM_OF_DUMPS_TO_STORE,
210 pci_resource_len(pdev, 0));
211 if (IS_ERR(crdump->region_crspace))
212 mlx4_warn(dev, "crdump: create devlink region %s err %ld\n",
213 region_cr_space_str,
214 PTR_ERR(crdump->region_crspace));
215
216
217 crdump->region_fw_health =
218 devlink_region_create(devlink,
219 region_fw_health_str,
220 MAX_NUM_OF_DUMPS_TO_STORE,
221 HEALTH_BUFFER_SIZE);
222 if (IS_ERR(crdump->region_fw_health))
223 mlx4_warn(dev, "crdump: create devlink region %s err %ld\n",
224 region_fw_health_str,
225 PTR_ERR(crdump->region_fw_health));
226
227 return 0;
228 }
229
230 void mlx4_crdump_end(struct mlx4_dev *dev)
231 {
232 struct mlx4_fw_crdump *crdump = &dev->persist->crdump;
233
234 devlink_region_destroy(crdump->region_fw_health);
235 devlink_region_destroy(crdump->region_crspace);
236 }