Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / scsi / qedf / qedf_dbg.c
blobe0387e4952617cb5766e631211e3d5389e4c8cb1
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * QLogic FCoE Offload Driver
4 * Copyright (c) 2016-2018 Cavium Inc.
5 */
6 #include "qedf_dbg.h"
7 #include <linux/vmalloc.h>
9 void
10 qedf_dbg_err(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
11 const char *fmt, ...)
13 va_list va;
14 struct va_format vaf;
16 va_start(va, fmt);
18 vaf.fmt = fmt;
19 vaf.va = &va;
21 if (likely(qedf) && likely(qedf->pdev))
22 pr_err("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
23 func, line, qedf->host_no, &vaf);
24 else
25 pr_err("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
27 va_end(va);
30 void
31 qedf_dbg_warn(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
32 const char *fmt, ...)
34 va_list va;
35 struct va_format vaf;
37 va_start(va, fmt);
39 vaf.fmt = fmt;
40 vaf.va = &va;
42 if (!(qedf_debug & QEDF_LOG_WARN))
43 goto ret;
45 if (likely(qedf) && likely(qedf->pdev))
46 pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
47 func, line, qedf->host_no, &vaf);
48 else
49 pr_warn("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
51 ret:
52 va_end(va);
55 void
56 qedf_dbg_notice(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
57 const char *fmt, ...)
59 va_list va;
60 struct va_format vaf;
62 va_start(va, fmt);
64 vaf.fmt = fmt;
65 vaf.va = &va;
67 if (!(qedf_debug & QEDF_LOG_NOTICE))
68 goto ret;
70 if (likely(qedf) && likely(qedf->pdev))
71 pr_notice("[%s]:[%s:%d]:%d: %pV",
72 dev_name(&(qedf->pdev->dev)), func, line,
73 qedf->host_no, &vaf);
74 else
75 pr_notice("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
77 ret:
78 va_end(va);
81 void
82 qedf_dbg_info(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
83 u32 level, const char *fmt, ...)
85 va_list va;
86 struct va_format vaf;
88 va_start(va, fmt);
90 vaf.fmt = fmt;
91 vaf.va = &va;
93 if (!(qedf_debug & level))
94 goto ret;
96 if (likely(qedf) && likely(qedf->pdev))
97 pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)),
98 func, line, qedf->host_no, &vaf);
99 else
100 pr_info("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
102 ret:
103 va_end(va);
107 qedf_alloc_grc_dump_buf(u8 **buf, uint32_t len)
109 *buf = vmalloc(len);
110 if (!(*buf))
111 return -ENOMEM;
113 memset(*buf, 0, len);
114 return 0;
117 void
118 qedf_free_grc_dump_buf(uint8_t **buf)
120 vfree(*buf);
121 *buf = NULL;
125 qedf_get_grc_dump(struct qed_dev *cdev, const struct qed_common_ops *common,
126 u8 **buf, uint32_t *grcsize)
128 if (!*buf)
129 return -EINVAL;
131 return common->dbg_all_data(cdev, *buf);
134 void
135 qedf_uevent_emit(struct Scsi_Host *shost, u32 code, char *msg)
137 char event_string[40];
138 char *envp[] = {event_string, NULL};
140 memset(event_string, 0, sizeof(event_string));
141 switch (code) {
142 case QEDF_UEVENT_CODE_GRCDUMP:
143 if (msg)
144 strscpy(event_string, msg, sizeof(event_string));
145 else
146 sprintf(event_string, "GRCDUMP=%u", shost->host_no);
147 break;
148 default:
149 /* do nothing */
150 break;
153 kobject_uevent_env(&shost->shost_gendev.kobj, KOBJ_CHANGE, envp);
157 qedf_create_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
159 int ret = 0;
161 for (; iter->name; iter++) {
162 ret = sysfs_create_bin_file(&shost->shost_gendev.kobj,
163 iter->attr);
164 if (ret)
165 pr_err("Unable to create sysfs %s attr, err(%d).\n",
166 iter->name, ret);
168 return ret;
171 void
172 qedf_remove_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
174 for (; iter->name; iter++)
175 sysfs_remove_bin_file(&shost->shost_gendev.kobj, iter->attr);