cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

qedf_dbg.c (3401B)


      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
      9void
     10qedf_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
     30void
     31qedf_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
     51ret:
     52	va_end(va);
     53}
     54
     55void
     56qedf_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
     77ret:
     78	va_end(va);
     79}
     80
     81void
     82qedf_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
    102ret:
    103	va_end(va);
    104}
    105
    106int
    107qedf_alloc_grc_dump_buf(u8 **buf, uint32_t len)
    108{
    109		*buf = vzalloc(len);
    110		if (!(*buf))
    111			return -ENOMEM;
    112
    113		return 0;
    114}
    115
    116void
    117qedf_free_grc_dump_buf(uint8_t **buf)
    118{
    119		vfree(*buf);
    120		*buf = NULL;
    121}
    122
    123int
    124qedf_get_grc_dump(struct qed_dev *cdev, const struct qed_common_ops *common,
    125		   u8 **buf, uint32_t *grcsize)
    126{
    127	if (!*buf)
    128		return -EINVAL;
    129
    130	return common->dbg_all_data(cdev, *buf);
    131}
    132
    133void
    134qedf_uevent_emit(struct Scsi_Host *shost, u32 code, char *msg)
    135{
    136	char event_string[40];
    137	char *envp[] = {event_string, NULL};
    138
    139	memset(event_string, 0, sizeof(event_string));
    140	switch (code) {
    141	case QEDF_UEVENT_CODE_GRCDUMP:
    142		if (msg)
    143			strscpy(event_string, msg, sizeof(event_string));
    144		else
    145			sprintf(event_string, "GRCDUMP=%u", shost->host_no);
    146		break;
    147	default:
    148		/* do nothing */
    149		break;
    150	}
    151
    152	kobject_uevent_env(&shost->shost_gendev.kobj, KOBJ_CHANGE, envp);
    153}
    154
    155int
    156qedf_create_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
    157{
    158	int ret = 0;
    159
    160	for (; iter->name; iter++) {
    161		ret = sysfs_create_bin_file(&shost->shost_gendev.kobj,
    162					    iter->attr);
    163		if (ret)
    164			pr_err("Unable to create sysfs %s attr, err(%d).\n",
    165			       iter->name, ret);
    166	}
    167	return ret;
    168}
    169
    170void
    171qedf_remove_sysfs_attr(struct Scsi_Host *shost, struct sysfs_bin_attrs *iter)
    172{
    173	for (; iter->name; iter++)
    174		sysfs_remove_bin_file(&shost->shost_gendev.kobj, iter->attr);
    175}