blob: f7d170bffc826db7c3e23b0c217499ab54e6abed [file] [log] [blame]
Dupuis, Chad61d86582017-02-15 06:28:23 -08001/*
2 * QLogic FCoE Offload Driver
Chad Dupuis5d1c8b52018-04-25 06:09:04 -07003 * Copyright (c) 2016-2018 Cavium Inc.
Dupuis, Chad61d86582017-02-15 06:28:23 -08004 *
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
12void
13qedf_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;
Dupuis, Chad61d86582017-02-15 06:28:23 -080018
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)),
Colin Ian King65b1dc92019-04-12 10:48:29 +010026 func, line, qedf->host_no, &vaf);
Dupuis, Chad61d86582017-02-15 06:28:23 -080027 else
Colin Ian King65b1dc92019-04-12 10:48:29 +010028 pr_err("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
Dupuis, Chad61d86582017-02-15 06:28:23 -080029
30 va_end(va);
31}
32
33void
34qedf_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;
Dupuis, Chad61d86582017-02-15 06:28:23 -080039
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)),
Colin Ian King65b1dc92019-04-12 10:48:29 +010050 func, line, qedf->host_no, &vaf);
Dupuis, Chad61d86582017-02-15 06:28:23 -080051 else
Colin Ian King65b1dc92019-04-12 10:48:29 +010052 pr_warn("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
Dupuis, Chad61d86582017-02-15 06:28:23 -080053
54ret:
55 va_end(va);
56}
57
58void
59qedf_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;
Dupuis, Chad61d86582017-02-15 06:28:23 -080064
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",
Colin Ian King65b1dc92019-04-12 10:48:29 +010075 dev_name(&(qedf->pdev->dev)), func, line,
Dupuis, Chad61d86582017-02-15 06:28:23 -080076 qedf->host_no, &vaf);
77 else
Colin Ian King65b1dc92019-04-12 10:48:29 +010078 pr_notice("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
Dupuis, Chad61d86582017-02-15 06:28:23 -080079
80ret:
81 va_end(va);
82}
83
84void
85qedf_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;
Dupuis, Chad61d86582017-02-15 06:28:23 -080090
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)),
Colin Ian King65b1dc92019-04-12 10:48:29 +0100101 func, line, qedf->host_no, &vaf);
Dupuis, Chad61d86582017-02-15 06:28:23 -0800102 else
Colin Ian King65b1dc92019-04-12 10:48:29 +0100103 pr_info("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
Dupuis, Chad61d86582017-02-15 06:28:23 -0800104
105ret:
106 va_end(va);
107}
108
109int
110qedf_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
120void
121qedf_free_grc_dump_buf(uint8_t **buf)
122{
123 vfree(*buf);
124 *buf = NULL;
125}
126
127int
128qedf_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
Chad Dupuis4b9b7fa2018-04-25 06:08:58 -0700134 return common->dbg_all_data(cdev, *buf);
Dupuis, Chad61d86582017-02-15 06:28:23 -0800135}
136
137void
138qedf_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)
Arnd Bergmanna8db6142018-02-02 14:12:20 +0100147 strscpy(event_string, msg, sizeof(event_string));
Dupuis, Chad61d86582017-02-15 06:28:23 -0800148 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
159int
160qedf_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
174void
175qedf_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}