1 /* 2 * QLogic FCoE 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 #include "qedf_dbg.h" 10 #include <linux/vmalloc.h> 11 12 void 13 qedf_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; 18 char nfunc[32]; 19 20 memset(nfunc, 0, sizeof(nfunc)); 21 memcpy(nfunc, func, sizeof(nfunc) - 1); 22 23 va_start(va, fmt); 24 25 vaf.fmt = fmt; 26 vaf.va = &va; 27 28 if (likely(qedf) && likely(qedf->pdev)) 29 pr_err("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)), 30 nfunc, line, qedf->host_no, &vaf); 31 else 32 pr_err("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf); 33 34 va_end(va); 35 } 36 37 void 38 qedf_dbg_warn(struct qedf_dbg_ctx *qedf, const char *func, u32 line, 39 const char *fmt, ...) 40 { 41 va_list va; 42 struct va_format vaf; 43 char nfunc[32]; 44 45 memset(nfunc, 0, sizeof(nfunc)); 46 memcpy(nfunc, func, sizeof(nfunc) - 1); 47 48 va_start(va, fmt); 49 50 vaf.fmt = fmt; 51 vaf.va = &va; 52 53 if (!(qedf_debug & QEDF_LOG_WARN)) 54 goto ret; 55 56 if (likely(qedf) && likely(qedf->pdev)) 57 pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)), 58 nfunc, line, qedf->host_no, &vaf); 59 else 60 pr_warn("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf); 61 62 ret: 63 va_end(va); 64 } 65 66 void 67 qedf_dbg_notice(struct qedf_dbg_ctx *qedf, 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 (!(qedf_debug & QEDF_LOG_NOTICE)) 83 goto ret; 84 85 if (likely(qedf) && likely(qedf->pdev)) 86 pr_notice("[%s]:[%s:%d]:%d: %pV", 87 dev_name(&(qedf->pdev->dev)), nfunc, line, 88 qedf->host_no, &vaf); 89 else 90 pr_notice("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf); 91 92 ret: 93 va_end(va); 94 } 95 96 void 97 qedf_dbg_info(struct qedf_dbg_ctx *qedf, const char *func, u32 line, 98 u32 level, const char *fmt, ...) 99 { 100 va_list va; 101 struct va_format vaf; 102 char nfunc[32]; 103 104 memset(nfunc, 0, sizeof(nfunc)); 105 memcpy(nfunc, func, sizeof(nfunc) - 1); 106 107 va_start(va, fmt); 108 109 vaf.fmt = fmt; 110 vaf.va = &va; 111 112 if (!(qedf_debug & level)) 113 goto ret; 114 115 if (likely(qedf) && likely(qedf->pdev)) 116 pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)), 117 nfunc, line, qedf->host_no, &vaf); 118 else 119 pr_info("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf); 120 121 ret: 122 va_end(va); 123 } 124 125 int 126 qedf_alloc_grc_dump_buf(u8 **buf, uint32_t len) 127 { 128 *buf = vmalloc(len); 129 if (!(*buf)) 130 return -ENOMEM; 131 132 memset(*buf, 0, len); 133 return 0; 134 } 135 136 void 137 qedf_free_grc_dump_buf(uint8_t **buf) 138 { 139 vfree(*buf); 140 *buf = NULL; 141 } 142 143 int 144 qedf_get_grc_dump(struct qed_dev *cdev, const struct qed_common_ops *common, 145 u8 **buf, uint32_t *grcsize) 146 { 147 if (!*buf) 148 return -EINVAL; 149 150 return common->dbg_grc(cdev, *buf, grcsize); 151 } 152 153 void 154 qedf_uevent_emit(struct Scsi_Host *shost, u32 code, char *msg) 155 { 156 char event_string[40]; 157 char *envp[] = {event_string, NULL}; 158 159 memset(event_string, 0, sizeof(event_string)); 160 switch (code) { 161 case QEDF_UEVENT_CODE_GRCDUMP: 162 if (msg) 163 strscpy(event_string, msg, sizeof(event_string)); 164 else 165 sprintf(event_string, "GRCDUMP=%u", shost->host_no); 166 break; 167 default: 168 /* do nothing */ 169 break; 170 } 171 172 kobject_uevent_env(&shost->shost_gendev.kobj, KOBJ_CHANGE, envp); 173 } 174 175 int 176 qedf_create_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter) 177 { 178 int ret = 0; 179 180 for (; iter->name; iter++) { 181 ret = sysfs_create_bin_file(&shost->shost_gendev.kobj, 182 iter->attr); 183 if (ret) 184 pr_err("Unable to create sysfs %s attr, err(%d).\n", 185 iter->name, ret); 186 } 187 return ret; 188 } 189 190 void 191 qedf_remove_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter) 192 { 193 for (; iter->name; iter++) 194 sysfs_remove_bin_file(&shost->shost_gendev.kobj, iter->attr); 195 } 196