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 return; 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 va_end(va); 64 } 65 66 void 67 qedi_dbg_notice(struct qedi_dbg_ctx *qedi, const char *func, u32 line, 68 const char *fmt, ...) 69 { 70 va_list va; 71 struct va_format vaf; 72 char nfunc[32]; 73 74 memset(nfunc, 0, sizeof(nfunc)); 75 memcpy(nfunc, func, sizeof(nfunc) - 1); 76 77 va_start(va, fmt); 78 79 vaf.fmt = fmt; 80 vaf.va = &va; 81 82 if (!(qedi_dbg_log & QEDI_LOG_NOTICE)) 83 return; 84 85 if (likely(qedi) && likely(qedi->pdev)) 86 pr_notice("[%s]:[%s:%d]:%d: %pV", 87 dev_name(&qedi->pdev->dev), nfunc, line, 88 qedi->host_no, &vaf); 89 else 90 pr_notice("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf); 91 92 va_end(va); 93 } 94 95 void 96 qedi_dbg_info(struct qedi_dbg_ctx *qedi, const char *func, u32 line, 97 u32 level, const char *fmt, ...) 98 { 99 va_list va; 100 struct va_format vaf; 101 char nfunc[32]; 102 103 memset(nfunc, 0, sizeof(nfunc)); 104 memcpy(nfunc, func, sizeof(nfunc) - 1); 105 106 va_start(va, fmt); 107 108 vaf.fmt = fmt; 109 vaf.va = &va; 110 111 if (!(qedi_dbg_log & level)) 112 return; 113 114 if (likely(qedi) && likely(qedi->pdev)) 115 pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev), 116 nfunc, line, qedi->host_no, &vaf); 117 else 118 pr_info("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf); 119 120 va_end(va); 121 } 122 123 int 124 qedi_create_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter) 125 { 126 int ret = 0; 127 128 for (; iter->name; iter++) { 129 ret = sysfs_create_bin_file(&shost->shost_gendev.kobj, 130 iter->attr); 131 if (ret) 132 pr_err("Unable to create sysfs %s attr, err(%d).\n", 133 iter->name, ret); 134 } 135 return ret; 136 } 137 138 void 139 qedi_remove_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter) 140 { 141 for (; iter->name; iter++) 142 sysfs_remove_bin_file(&shost->shost_gendev.kobj, iter->attr); 143 } 144