Linux 4.18.10
[linux/fpc-iii.git] / drivers / scsi / qedf / qedf_dbg.c
blobf2397ee9ba690d71a0454352bd8b9b1cb928362f
1 /*
2 * QLogic FCoE Offload Driver
3 * Copyright (c) 2016-2018 Cavium Inc.
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>
12 void
13 qedf_dbg_err(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
14 const char *fmt, ...)
16 va_list va;
17 struct va_format vaf;
18 char nfunc[32];
20 memset(nfunc, 0, sizeof(nfunc));
21 memcpy(nfunc, func, sizeof(nfunc) - 1);
23 va_start(va, fmt);
25 vaf.fmt = fmt;
26 vaf.va = &va;
28 if (likely(qedf) && likely(qedf->pdev))
29 pr_err("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
30 nfunc, line, qedf->host_no, &vaf);
31 else
32 pr_err("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
34 va_end(va);
37 void
38 qedf_dbg_warn(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
39 const char *fmt, ...)
41 va_list va;
42 struct va_format vaf;
43 char nfunc[32];
45 memset(nfunc, 0, sizeof(nfunc));
46 memcpy(nfunc, func, sizeof(nfunc) - 1);
48 va_start(va, fmt);
50 vaf.fmt = fmt;
51 vaf.va = &va;
53 if (!(qedf_debug & QEDF_LOG_WARN))
54 goto ret;
56 if (likely(qedf) && likely(qedf->pdev))
57 pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
58 nfunc, line, qedf->host_no, &vaf);
59 else
60 pr_warn("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
62 ret:
63 va_end(va);
66 void
67 qedf_dbg_notice(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
68 const char *fmt, ...)
70 va_list va;
71 struct va_format vaf;
72 char nfunc[32];
74 memset(nfunc, 0, sizeof(nfunc));
75 memcpy(nfunc, func, sizeof(nfunc) - 1);
77 va_start(va, fmt);
79 vaf.fmt = fmt;
80 vaf.va = &va;
82 if (!(qedf_debug & QEDF_LOG_NOTICE))
83 goto ret;
85 if (likely(qedf) && likely(qedf->pdev))
86 pr_notice("[%s]:[%s:%d]:%d: %pV",
87 dev_name(&(qedf->pdev->dev)), nfunc, line,
88 qedf->host_no, &vaf);
89 else
90 pr_notice("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
92 ret:
93 va_end(va);
96 void
97 qedf_dbg_info(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
98 u32 level, const char *fmt, ...)
100 va_list va;
101 struct va_format vaf;
102 char nfunc[32];
104 memset(nfunc, 0, sizeof(nfunc));
105 memcpy(nfunc, func, sizeof(nfunc) - 1);
107 va_start(va, fmt);
109 vaf.fmt = fmt;
110 vaf.va = &va;
112 if (!(qedf_debug & level))
113 goto ret;
115 if (likely(qedf) && likely(qedf->pdev))
116 pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
117 nfunc, line, qedf->host_no, &vaf);
118 else
119 pr_info("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
121 ret:
122 va_end(va);
126 qedf_alloc_grc_dump_buf(u8 **buf, uint32_t len)
128 *buf = vmalloc(len);
129 if (!(*buf))
130 return -ENOMEM;
132 memset(*buf, 0, len);
133 return 0;
136 void
137 qedf_free_grc_dump_buf(uint8_t **buf)
139 vfree(*buf);
140 *buf = NULL;
144 qedf_get_grc_dump(struct qed_dev *cdev, const struct qed_common_ops *common,
145 u8 **buf, uint32_t *grcsize)
147 if (!*buf)
148 return -EINVAL;
150 return common->dbg_all_data(cdev, *buf);
153 void
154 qedf_uevent_emit(struct Scsi_Host *shost, u32 code, char *msg)
156 char event_string[40];
157 char *envp[] = {event_string, NULL};
159 memset(event_string, 0, sizeof(event_string));
160 switch (code) {
161 case QEDF_UEVENT_CODE_GRCDUMP:
162 if (msg)
163 strscpy(event_string, msg, sizeof(event_string));
164 else
165 sprintf(event_string, "GRCDUMP=%u", shost->host_no);
166 break;
167 default:
168 /* do nothing */
169 break;
172 kobject_uevent_env(&shost->shost_gendev.kobj, KOBJ_CHANGE, envp);
176 qedf_create_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
178 int ret = 0;
180 for (; iter->name; iter++) {
181 ret = sysfs_create_bin_file(&shost->shost_gendev.kobj,
182 iter->attr);
183 if (ret)
184 pr_err("Unable to create sysfs %s attr, err(%d).\n",
185 iter->name, ret);
187 return ret;
190 void
191 qedf_remove_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
193 for (; iter->name; iter++)
194 sysfs_remove_bin_file(&shost->shost_gendev.kobj, iter->attr);