Skip to content

Commit bedc989

Browse files
alexveskerdavem330
authored andcommitted
net/mlx4_core: Add Crdump FW snapshot support
Crdump allows the driver to create a snapshot of the FW PCI crspace and health buffer during a critical FW issue. In case of a FW command timeout, FW getting stuck or a non zero value on the catastrophic buffer, a snapshot will be taken. The snapshot is exposed using devlink, cr-space, fw-health address regions are registered on init and snapshots are attached once a new snapshot is collected by the driver. Signed-off-by: Alex Vesker <valex@mellanox.com> Signed-off-by: Tariq Toukan <tariqt@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 523f9eb commit bedc989

6 files changed

Lines changed: 255 additions & 4 deletions

File tree

‎drivers/net/ethernet/mellanox/mlx4/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ obj-$(CONFIG_MLX4_CORE) += mlx4_core.o
33

44
mlx4_core-y := alloc.o catas.o cmd.o cq.o eq.o fw.o fw_qos.o icm.o intf.o \
55
main.o mcg.o mr.o pd.o port.o profile.o qp.o reset.o sense.o \
6-
srq.o resource_tracker.o
6+
srq.o resource_tracker.o crdump.o
77

88
obj-$(CONFIG_MLX4_EN) += mlx4_en.o
99

‎drivers/net/ethernet/mellanox/mlx4/catas.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,12 @@ void mlx4_enter_error_state(struct mlx4_dev_persistent *persist)
178178

179179
dev = persist->dev;
180180
mlx4_err(dev, "device is going to be reset\n");
181-
if (mlx4_is_slave(dev))
181+
if (mlx4_is_slave(dev)) {
182182
err = mlx4_reset_slave(dev);
183-
else
183+
} else {
184+
mlx4_crdump_collect(dev);
184185
err = mlx4_reset_master(dev);
186+
}
185187

186188
if (!err) {
187189
mlx4_err(dev, "device was reset successfully\n");
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
/*
2+
* Copyright (c) 2018, Mellanox Technologies. All rights reserved.
3+
*
4+
* This software is available to you under a choice of one of two
5+
* licenses. You may choose to be licensed under the terms of the GNU
6+
* General Public License (GPL) Version 2, available from the file
7+
* COPYING in the main directory of this source tree, or the
8+
* OpenIB.org BSD license below:
9+
*
10+
* Redistribution and use in source and binary forms, with or
11+
* without modification, are permitted provided that the following
12+
* conditions are met:
13+
*
14+
* - Redistributions of source code must retain the above
15+
* copyright notice, this list of conditions and the following
16+
* disclaimer.
17+
*
18+
* - Redistributions in binary form must reproduce the above
19+
* copyright notice, this list of conditions and the following
20+
* disclaimer in the documentation and/or other materials
21+
* provided with the distribution.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
* SOFTWARE.
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+
/* Set to true in case cr enable bit was set to true before crdump */
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+
/* Get current enable bit value */
51+
crdump_enbale_bit_set =
52+
readl(cr_space + CR_ENABLE_BIT_OFFSET) & CR_ENABLE_BIT;
53+
54+
/* Enable FW CR filter (set bit6 to 0) */
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+
/* Enable block volatile crspace accesses */
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+
/* Disable block volatile crspace accesses */
68+
writel(0, cr_space + dev->caps.health_buffer_addrs +
69+
HEALTH_BUFFER_SIZE);
70+
71+
/* Restore FW CR filter value (set bit6 to original value) */
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+
/* Try to collect CR space */
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+
cr_res_size, crspace_data,
103+
id, &kvfree);
104+
if (err) {
105+
kvfree(crspace_data);
106+
mlx4_warn(dev, "crdump: devlink create %s snapshot id %d err %d\n",
107+
region_cr_space_str, id, err);
108+
} else {
109+
mlx4_info(dev, "crdump: added snapshot %d to devlink region %s\n",
110+
id, region_cr_space_str);
111+
}
112+
} else {
113+
mlx4_err(dev, "crdump: Failed to allocate crspace buffer\n");
114+
}
115+
}
116+
117+
static void mlx4_crdump_collect_fw_health(struct mlx4_dev *dev,
118+
u8 __iomem *cr_space,
119+
u32 id)
120+
{
121+
struct mlx4_fw_crdump *crdump = &dev->persist->crdump;
122+
u8 *health_data;
123+
int offset;
124+
int err;
125+
126+
if (!crdump->region_fw_health) {
127+
mlx4_err(dev, "crdump: fw-health region is NULL\n");
128+
return;
129+
}
130+
131+
/* Try to collect health buffer */
132+
health_data = kvmalloc(HEALTH_BUFFER_SIZE, GFP_KERNEL);
133+
if (health_data) {
134+
u8 __iomem *health_buf_start =
135+
cr_space + dev->caps.health_buffer_addrs;
136+
137+
for (offset = 0; offset < HEALTH_BUFFER_SIZE; offset += 4)
138+
*(u32 *)(health_data + offset) =
139+
readl(health_buf_start + offset);
140+
141+
err = devlink_region_snapshot_create(crdump->region_fw_health,
142+
HEALTH_BUFFER_SIZE,
143+
health_data,
144+
id, &kvfree);
145+
if (err) {
146+
kvfree(health_data);
147+
mlx4_warn(dev, "crdump: devlink create %s snapshot id %d err %d\n",
148+
region_fw_health_str, id, err);
149+
} else {
150+
mlx4_info(dev, "crdump: added snapshot %d to devlink region %s\n",
151+
id, region_fw_health_str);
152+
}
153+
} else {
154+
mlx4_err(dev, "crdump: Failed to allocate health buffer\n");
155+
}
156+
}
157+
158+
int mlx4_crdump_collect(struct mlx4_dev *dev)
159+
{
160+
struct devlink *devlink = priv_to_devlink(mlx4_priv(dev));
161+
struct pci_dev *pdev = dev->persist->pdev;
162+
unsigned long cr_res_size;
163+
u8 __iomem *cr_space;
164+
u32 id;
165+
166+
if (!dev->caps.health_buffer_addrs) {
167+
mlx4_info(dev, "crdump: FW doesn't support health buffer access, skipping\n");
168+
return 0;
169+
}
170+
171+
cr_res_size = pci_resource_len(pdev, 0);
172+
173+
cr_space = ioremap(pci_resource_start(pdev, 0), cr_res_size);
174+
if (!cr_space) {
175+
mlx4_err(dev, "crdump: Failed to map pci cr region\n");
176+
return -ENODEV;
177+
}
178+
179+
crdump_enable_crspace_access(dev, cr_space);
180+
181+
/* Get the available snapshot ID for the dumps */
182+
id = devlink_region_shapshot_id_get(devlink);
183+
184+
/* Try to capture dumps */
185+
mlx4_crdump_collect_crspace(dev, cr_space, id);
186+
mlx4_crdump_collect_fw_health(dev, cr_space, id);
187+
188+
crdump_disable_crspace_access(dev, cr_space);
189+
190+
iounmap(cr_space);
191+
return 0;
192+
}
193+
194+
int mlx4_crdump_init(struct mlx4_dev *dev)
195+
{
196+
struct devlink *devlink = priv_to_devlink(mlx4_priv(dev));
197+
struct mlx4_fw_crdump *crdump = &dev->persist->crdump;
198+
struct pci_dev *pdev = dev->persist->pdev;
199+
200+
/* Create cr-space region */
201+
crdump->region_crspace =
202+
devlink_region_create(devlink,
203+
region_cr_space_str,
204+
MAX_NUM_OF_DUMPS_TO_STORE,
205+
pci_resource_len(pdev, 0));
206+
if (IS_ERR(crdump->region_crspace))
207+
mlx4_warn(dev, "crdump: create devlink region %s err %ld\n",
208+
region_cr_space_str,
209+
PTR_ERR(crdump->region_crspace));
210+
211+
/* Create fw-health region */
212+
crdump->region_fw_health =
213+
devlink_region_create(devlink,
214+
region_fw_health_str,
215+
MAX_NUM_OF_DUMPS_TO_STORE,
216+
HEALTH_BUFFER_SIZE);
217+
if (IS_ERR(crdump->region_fw_health))
218+
mlx4_warn(dev, "crdump: create devlink region %s err %ld\n",
219+
region_fw_health_str,
220+
PTR_ERR(crdump->region_fw_health));
221+
222+
return 0;
223+
}
224+
225+
void mlx4_crdump_end(struct mlx4_dev *dev)
226+
{
227+
struct mlx4_fw_crdump *crdump = &dev->persist->crdump;
228+
229+
devlink_region_destroy(crdump->region_fw_health);
230+
devlink_region_destroy(crdump->region_crspace);
231+
}

‎drivers/net/ethernet/mellanox/mlx4/main.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3807,10 +3807,14 @@ static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data,
38073807
}
38083808
}
38093809

3810-
err = mlx4_catas_init(&priv->dev);
3810+
err = mlx4_crdump_init(&priv->dev);
38113811
if (err)
38123812
goto err_release_regions;
38133813

3814+
err = mlx4_catas_init(&priv->dev);
3815+
if (err)
3816+
goto err_crdump;
3817+
38143818
err = mlx4_load_one(pdev, pci_dev_data, total_vfs, nvfs, priv, 0);
38153819
if (err)
38163820
goto err_catas;
@@ -3820,6 +3824,9 @@ static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data,
38203824
err_catas:
38213825
mlx4_catas_end(&priv->dev);
38223826

3827+
err_crdump:
3828+
mlx4_crdump_end(&priv->dev);
3829+
38233830
err_release_regions:
38243831
pci_release_regions(pdev);
38253832

@@ -4081,6 +4088,7 @@ static void mlx4_remove_one(struct pci_dev *pdev)
40814088
else
40824089
mlx4_info(dev, "%s: interface is down\n", __func__);
40834090
mlx4_catas_end(dev);
4091+
mlx4_crdump_end(dev);
40844092
if (dev->flags & MLX4_FLAG_SRIOV && !active_vfs) {
40854093
mlx4_warn(dev, "Disabling SR-IOV\n");
40864094
pci_disable_sriov(pdev);

‎drivers/net/ethernet/mellanox/mlx4/mlx4.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,8 @@ void mlx4_start_catas_poll(struct mlx4_dev *dev);
10421042
void mlx4_stop_catas_poll(struct mlx4_dev *dev);
10431043
int mlx4_catas_init(struct mlx4_dev *dev);
10441044
void mlx4_catas_end(struct mlx4_dev *dev);
1045+
int mlx4_crdump_init(struct mlx4_dev *dev);
1046+
void mlx4_crdump_end(struct mlx4_dev *dev);
10451047
int mlx4_restart_one(struct pci_dev *pdev, bool reload,
10461048
struct devlink *devlink);
10471049
int mlx4_register_device(struct mlx4_dev *dev);
@@ -1228,6 +1230,8 @@ void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
12281230
void mlx4_enter_error_state(struct mlx4_dev_persistent *persist);
12291231
int mlx4_comm_internal_err(u32 slave_read);
12301232

1233+
int mlx4_crdump_collect(struct mlx4_dev *dev);
1234+
12311235
int mlx4_SENSE_PORT(struct mlx4_dev *dev, int port,
12321236
enum mlx4_port_type *type);
12331237
void mlx4_do_sense_ports(struct mlx4_dev *dev,

‎include/linux/mlx4/device.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,11 @@ struct mlx4_vf_dev {
852852
u8 n_ports;
853853
};
854854

855+
struct mlx4_fw_crdump {
856+
struct devlink_region *region_crspace;
857+
struct devlink_region *region_fw_health;
858+
};
859+
855860
enum mlx4_pci_status {
856861
MLX4_PCI_STATUS_DISABLED,
857862
MLX4_PCI_STATUS_ENABLED,
@@ -872,6 +877,7 @@ struct mlx4_dev_persistent {
872877
u8 interface_state;
873878
struct mutex pci_status_mutex; /* sync pci state */
874879
enum mlx4_pci_status pci_status;
880+
struct mlx4_fw_crdump crdump;
875881
};
876882

877883
struct mlx4_dev {

0 commit comments

Comments
 (0)