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