xref: /linux/drivers/scsi/qedi/qedi_dbg.c (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*3287e96aSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2ace7f46bSManish Rangankar /*
3ace7f46bSManish Rangankar  * QLogic iSCSI Offload Driver
4ace7f46bSManish Rangankar  * Copyright (c) 2016 Cavium Inc.
5ace7f46bSManish Rangankar  */
6ace7f46bSManish Rangankar 
7ace7f46bSManish Rangankar #include "qedi_dbg.h"
8ace7f46bSManish Rangankar #include <linux/vmalloc.h>
9ace7f46bSManish Rangankar 
10ace7f46bSManish Rangankar void
qedi_dbg_err(struct qedi_dbg_ctx * qedi,const char * func,u32 line,const char * fmt,...)11ace7f46bSManish Rangankar qedi_dbg_err(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
12ace7f46bSManish Rangankar 	     const char *fmt, ...)
13ace7f46bSManish Rangankar {
14ace7f46bSManish Rangankar 	va_list va;
15ace7f46bSManish Rangankar 	struct va_format vaf;
16ace7f46bSManish Rangankar 
17ace7f46bSManish Rangankar 	va_start(va, fmt);
18ace7f46bSManish Rangankar 
19ace7f46bSManish Rangankar 	vaf.fmt = fmt;
20ace7f46bSManish Rangankar 	vaf.va = &va;
21ace7f46bSManish Rangankar 
22ace7f46bSManish Rangankar 	if (likely(qedi) && likely(qedi->pdev))
23ace7f46bSManish Rangankar 		pr_err("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
24c09581a5SYueHaibing 		       func, line, qedi->host_no, &vaf);
25ace7f46bSManish Rangankar 	else
26c09581a5SYueHaibing 		pr_err("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
27ace7f46bSManish Rangankar 
28ace7f46bSManish Rangankar 	va_end(va);
29ace7f46bSManish Rangankar }
30ace7f46bSManish Rangankar 
31ace7f46bSManish Rangankar void
qedi_dbg_warn(struct qedi_dbg_ctx * qedi,const char * func,u32 line,const char * fmt,...)32ace7f46bSManish Rangankar qedi_dbg_warn(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
33ace7f46bSManish Rangankar 	      const char *fmt, ...)
34ace7f46bSManish Rangankar {
35ace7f46bSManish Rangankar 	va_list va;
36ace7f46bSManish Rangankar 	struct va_format vaf;
37ace7f46bSManish Rangankar 
38ace7f46bSManish Rangankar 	va_start(va, fmt);
39ace7f46bSManish Rangankar 
40ace7f46bSManish Rangankar 	vaf.fmt = fmt;
41ace7f46bSManish Rangankar 	vaf.va = &va;
42ace7f46bSManish Rangankar 
43ace7f46bSManish Rangankar 	if (!(qedi_dbg_log & QEDI_LOG_WARN))
44703e747aSColin Ian King 		goto ret;
45ace7f46bSManish Rangankar 
46ace7f46bSManish Rangankar 	if (likely(qedi) && likely(qedi->pdev))
47ace7f46bSManish Rangankar 		pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
48c09581a5SYueHaibing 			func, line, qedi->host_no, &vaf);
49ace7f46bSManish Rangankar 	else
50c09581a5SYueHaibing 		pr_warn("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
51ace7f46bSManish Rangankar 
52703e747aSColin Ian King ret:
53ace7f46bSManish Rangankar 	va_end(va);
54ace7f46bSManish Rangankar }
55ace7f46bSManish Rangankar 
56ace7f46bSManish Rangankar void
qedi_dbg_notice(struct qedi_dbg_ctx * qedi,const char * func,u32 line,const char * fmt,...)57ace7f46bSManish Rangankar qedi_dbg_notice(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
58ace7f46bSManish Rangankar 		const char *fmt, ...)
59ace7f46bSManish Rangankar {
60ace7f46bSManish Rangankar 	va_list va;
61ace7f46bSManish Rangankar 	struct va_format vaf;
62ace7f46bSManish Rangankar 
63ace7f46bSManish Rangankar 	va_start(va, fmt);
64ace7f46bSManish Rangankar 
65ace7f46bSManish Rangankar 	vaf.fmt = fmt;
66ace7f46bSManish Rangankar 	vaf.va = &va;
67ace7f46bSManish Rangankar 
68ace7f46bSManish Rangankar 	if (!(qedi_dbg_log & QEDI_LOG_NOTICE))
69703e747aSColin Ian King 		goto ret;
70ace7f46bSManish Rangankar 
71ace7f46bSManish Rangankar 	if (likely(qedi) && likely(qedi->pdev))
72ace7f46bSManish Rangankar 		pr_notice("[%s]:[%s:%d]:%d: %pV",
73c09581a5SYueHaibing 			  dev_name(&qedi->pdev->dev), func, line,
74ace7f46bSManish Rangankar 			  qedi->host_no, &vaf);
75ace7f46bSManish Rangankar 	else
76c09581a5SYueHaibing 		pr_notice("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
77ace7f46bSManish Rangankar 
78703e747aSColin Ian King ret:
79ace7f46bSManish Rangankar 	va_end(va);
80ace7f46bSManish Rangankar }
81ace7f46bSManish Rangankar 
82ace7f46bSManish Rangankar void
qedi_dbg_info(struct qedi_dbg_ctx * qedi,const char * func,u32 line,u32 level,const char * fmt,...)83ace7f46bSManish Rangankar qedi_dbg_info(struct qedi_dbg_ctx *qedi, const char *func, u32 line,
84ace7f46bSManish Rangankar 	      u32 level, const char *fmt, ...)
85ace7f46bSManish Rangankar {
86ace7f46bSManish Rangankar 	va_list va;
87ace7f46bSManish Rangankar 	struct va_format vaf;
88ace7f46bSManish Rangankar 
89ace7f46bSManish Rangankar 	va_start(va, fmt);
90ace7f46bSManish Rangankar 
91ace7f46bSManish Rangankar 	vaf.fmt = fmt;
92ace7f46bSManish Rangankar 	vaf.va = &va;
93ace7f46bSManish Rangankar 
94ace7f46bSManish Rangankar 	if (!(qedi_dbg_log & level))
95703e747aSColin Ian King 		goto ret;
96ace7f46bSManish Rangankar 
97ace7f46bSManish Rangankar 	if (likely(qedi) && likely(qedi->pdev))
98ace7f46bSManish Rangankar 		pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
99c09581a5SYueHaibing 			func, line, qedi->host_no, &vaf);
100ace7f46bSManish Rangankar 	else
101c09581a5SYueHaibing 		pr_info("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf);
102ace7f46bSManish Rangankar 
103703e747aSColin Ian King ret:
104ace7f46bSManish Rangankar 	va_end(va);
105ace7f46bSManish Rangankar }
106ace7f46bSManish Rangankar 
107ace7f46bSManish Rangankar int
qedi_create_sysfs_attr(struct Scsi_Host * shost,struct sysfs_bin_attrs * iter)108ace7f46bSManish Rangankar qedi_create_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
109ace7f46bSManish Rangankar {
110ace7f46bSManish Rangankar 	int ret = 0;
111ace7f46bSManish Rangankar 
112ace7f46bSManish Rangankar 	for (; iter->name; iter++) {
113ace7f46bSManish Rangankar 		ret = sysfs_create_bin_file(&shost->shost_gendev.kobj,
114ace7f46bSManish Rangankar 					    iter->attr);
115ace7f46bSManish Rangankar 		if (ret)
116ace7f46bSManish Rangankar 			pr_err("Unable to create sysfs %s attr, err(%d).\n",
117ace7f46bSManish Rangankar 			       iter->name, ret);
118ace7f46bSManish Rangankar 	}
119ace7f46bSManish Rangankar 	return ret;
120ace7f46bSManish Rangankar }
121ace7f46bSManish Rangankar 
122ace7f46bSManish Rangankar void
qedi_remove_sysfs_attr(struct Scsi_Host * shost,struct sysfs_bin_attrs * iter)123ace7f46bSManish Rangankar qedi_remove_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
124ace7f46bSManish Rangankar {
125ace7f46bSManish Rangankar 	for (; iter->name; iter++)
126ace7f46bSManish Rangankar 		sysfs_remove_bin_file(&shost->shost_gendev.kobj, iter->attr);
127ace7f46bSManish Rangankar }
128