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