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