xref: /openbmc/linux/drivers/scsi/qedf/qedf_dbg.c (revision 7ff836f0)
1 /*
2  *  QLogic FCoE Offload Driver
3  *  Copyright (c) 2016-2018 Cavium Inc.
4  *
5  *  This software is available under the terms of the GNU General Public License
6  *  (GPL) Version 2, available from the file COPYING in the main directory of
7  *  this source tree.
8  */
9 #include "qedf_dbg.h"
10 #include <linux/vmalloc.h>
11 
12 void
13 qedf_dbg_err(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
14 	      const char *fmt, ...)
15 {
16 	va_list va;
17 	struct va_format vaf;
18 
19 	va_start(va, fmt);
20 
21 	vaf.fmt = fmt;
22 	vaf.va = &va;
23 
24 	if (likely(qedf) && likely(qedf->pdev))
25 		pr_err("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
26 			func, line, qedf->host_no, &vaf);
27 	else
28 		pr_err("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
29 
30 	va_end(va);
31 }
32 
33 void
34 qedf_dbg_warn(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
35 	       const char *fmt, ...)
36 {
37 	va_list va;
38 	struct va_format vaf;
39 
40 	va_start(va, fmt);
41 
42 	vaf.fmt = fmt;
43 	vaf.va = &va;
44 
45 	if (!(qedf_debug & QEDF_LOG_WARN))
46 		goto ret;
47 
48 	if (likely(qedf) && likely(qedf->pdev))
49 		pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
50 			func, line, qedf->host_no, &vaf);
51 	else
52 		pr_warn("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
53 
54 ret:
55 	va_end(va);
56 }
57 
58 void
59 qedf_dbg_notice(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
60 		 const char *fmt, ...)
61 {
62 	va_list va;
63 	struct va_format vaf;
64 
65 	va_start(va, fmt);
66 
67 	vaf.fmt = fmt;
68 	vaf.va = &va;
69 
70 	if (!(qedf_debug & QEDF_LOG_NOTICE))
71 		goto ret;
72 
73 	if (likely(qedf) && likely(qedf->pdev))
74 		pr_notice("[%s]:[%s:%d]:%d: %pV",
75 			  dev_name(&(qedf->pdev->dev)), func, line,
76 			  qedf->host_no, &vaf);
77 	else
78 		pr_notice("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
79 
80 ret:
81 	va_end(va);
82 }
83 
84 void
85 qedf_dbg_info(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
86 	       u32 level, const char *fmt, ...)
87 {
88 	va_list va;
89 	struct va_format vaf;
90 
91 	va_start(va, fmt);
92 
93 	vaf.fmt = fmt;
94 	vaf.va = &va;
95 
96 	if (!(qedf_debug & level))
97 		goto ret;
98 
99 	if (likely(qedf) && likely(qedf->pdev))
100 		pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
101 			func, line, qedf->host_no, &vaf);
102 	else
103 		pr_info("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
104 
105 ret:
106 	va_end(va);
107 }
108 
109 int
110 qedf_alloc_grc_dump_buf(u8 **buf, uint32_t len)
111 {
112 		*buf = vmalloc(len);
113 		if (!(*buf))
114 			return -ENOMEM;
115 
116 		memset(*buf, 0, len);
117 		return 0;
118 }
119 
120 void
121 qedf_free_grc_dump_buf(uint8_t **buf)
122 {
123 		vfree(*buf);
124 		*buf = NULL;
125 }
126 
127 int
128 qedf_get_grc_dump(struct qed_dev *cdev, const struct qed_common_ops *common,
129 		   u8 **buf, uint32_t *grcsize)
130 {
131 	if (!*buf)
132 		return -EINVAL;
133 
134 	return common->dbg_all_data(cdev, *buf);
135 }
136 
137 void
138 qedf_uevent_emit(struct Scsi_Host *shost, u32 code, char *msg)
139 {
140 	char event_string[40];
141 	char *envp[] = {event_string, NULL};
142 
143 	memset(event_string, 0, sizeof(event_string));
144 	switch (code) {
145 	case QEDF_UEVENT_CODE_GRCDUMP:
146 		if (msg)
147 			strscpy(event_string, msg, sizeof(event_string));
148 		else
149 			sprintf(event_string, "GRCDUMP=%u", shost->host_no);
150 		break;
151 	default:
152 		/* do nothing */
153 		break;
154 	}
155 
156 	kobject_uevent_env(&shost->shost_gendev.kobj, KOBJ_CHANGE, envp);
157 }
158 
159 int
160 qedf_create_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
161 {
162 	int ret = 0;
163 
164 	for (; iter->name; iter++) {
165 		ret = sysfs_create_bin_file(&shost->shost_gendev.kobj,
166 					    iter->attr);
167 		if (ret)
168 			pr_err("Unable to create sysfs %s attr, err(%d).\n",
169 			       iter->name, ret);
170 	}
171 	return ret;
172 }
173 
174 void
175 qedf_remove_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
176 {
177 	for (; iter->name; iter++)
178 		sysfs_remove_bin_file(&shost->shost_gendev.kobj, iter->attr);
179 }
180