forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/drivers/net/ethernet/mellanox/mlx4/crdump.c
....@@ -38,8 +38,21 @@
3838 #define CR_ENABLE_BIT_OFFSET 0xF3F04
3939 #define MAX_NUM_OF_DUMPS_TO_STORE (8)
4040
41
-static const char *region_cr_space_str = "cr-space";
42
-static const char *region_fw_health_str = "fw-health";
41
+#define REGION_CR_SPACE "cr-space"
42
+#define REGION_FW_HEALTH "fw-health"
43
+
44
+static const char * const region_cr_space_str = REGION_CR_SPACE;
45
+static const char * const region_fw_health_str = REGION_FW_HEALTH;
46
+
47
+static const struct devlink_region_ops region_cr_space_ops = {
48
+ .name = REGION_CR_SPACE,
49
+ .destructor = &kvfree,
50
+};
51
+
52
+static const struct devlink_region_ops region_fw_health_ops = {
53
+ .name = REGION_FW_HEALTH,
54
+ .destructor = &kvfree,
55
+};
4356
4457 /* Set to true in case cr enable bit was set to true before crdump */
4558 static bool crdump_enbale_bit_set;
....@@ -99,8 +112,7 @@
99112 readl(cr_space + offset);
100113
101114 err = devlink_region_snapshot_create(crdump->region_crspace,
102
- cr_res_size, crspace_data,
103
- id, &kvfree);
115
+ crspace_data, id);
104116 if (err) {
105117 kvfree(crspace_data);
106118 mlx4_warn(dev, "crdump: devlink create %s snapshot id %d err %d\n",
....@@ -139,9 +151,7 @@
139151 readl(health_buf_start + offset);
140152
141153 err = devlink_region_snapshot_create(crdump->region_fw_health,
142
- HEALTH_BUFFER_SIZE,
143
- health_data,
144
- id, &kvfree);
154
+ health_data, id);
145155 if (err) {
146156 kvfree(health_data);
147157 mlx4_warn(dev, "crdump: devlink create %s snapshot id %d err %d\n",
....@@ -162,6 +172,7 @@
162172 struct pci_dev *pdev = dev->persist->pdev;
163173 unsigned long cr_res_size;
164174 u8 __iomem *cr_space;
175
+ int err;
165176 u32 id;
166177
167178 if (!dev->caps.health_buffer_addrs) {
....@@ -182,14 +193,22 @@
182193 return -ENODEV;
183194 }
184195
185
- crdump_enable_crspace_access(dev, cr_space);
186
-
187196 /* Get the available snapshot ID for the dumps */
188
- id = devlink_region_shapshot_id_get(devlink);
197
+ err = devlink_region_snapshot_id_get(devlink, &id);
198
+ if (err) {
199
+ mlx4_err(dev, "crdump: devlink get snapshot id err %d\n", err);
200
+ iounmap(cr_space);
201
+ return err;
202
+ }
203
+
204
+ crdump_enable_crspace_access(dev, cr_space);
189205
190206 /* Try to capture dumps */
191207 mlx4_crdump_collect_crspace(dev, cr_space, id);
192208 mlx4_crdump_collect_fw_health(dev, cr_space, id);
209
+
210
+ /* Release reference on the snapshot id */
211
+ devlink_region_snapshot_id_put(devlink, id);
193212
194213 crdump_disable_crspace_access(dev, cr_space);
195214
....@@ -208,7 +227,7 @@
208227 /* Create cr-space region */
209228 crdump->region_crspace =
210229 devlink_region_create(devlink,
211
- region_cr_space_str,
230
+ &region_cr_space_ops,
212231 MAX_NUM_OF_DUMPS_TO_STORE,
213232 pci_resource_len(pdev, 0));
214233 if (IS_ERR(crdump->region_crspace))
....@@ -219,7 +238,7 @@
219238 /* Create fw-health region */
220239 crdump->region_fw_health =
221240 devlink_region_create(devlink,
222
- region_fw_health_str,
241
+ &region_fw_health_ops,
223242 MAX_NUM_OF_DUMPS_TO_STORE,
224243 HEALTH_BUFFER_SIZE);
225244 if (IS_ERR(crdump->region_fw_health))