Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  QLogic FCoE Offload Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Copyright (c) 2016-2018 Cavium Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include "qedf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) inline bool qedf_is_vport(struct qedf_ctx *qedf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 	return qedf->lport->vport != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) /* Get base qedf for physical port from vport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static struct qedf_ctx *qedf_get_base_qedf(struct qedf_ctx *qedf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	struct fc_lport *lport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	struct fc_lport *base_lport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	if (!(qedf_is_vport(qedf)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	lport = qedf->lport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	base_lport = shost_priv(vport_to_shost(lport->vport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	return lport_priv(base_lport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) qedf_fcoe_mac_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct fc_lport *lport = shost_priv(class_to_shost(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	u32 port_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	u8 lport_src_id[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	u8 fcoe_mac[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	port_id = fc_host_port_id(lport->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	lport_src_id[2] = (port_id & 0x000000FF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	lport_src_id[1] = (port_id & 0x0000FF00) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	lport_src_id[0] = (port_id & 0x00FF0000) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	fc_fcoe_set_mac(fcoe_mac, lport_src_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	return scnprintf(buf, PAGE_SIZE, "%pM\n", fcoe_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) qedf_fka_period_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct fc_lport *lport = shost_priv(class_to_shost(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct qedf_ctx *qedf = lport_priv(lport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	int fka_period = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (qedf_is_vport(qedf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		qedf = qedf_get_base_qedf(qedf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (qedf->ctlr.sel_fcf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		fka_period = qedf->ctlr.sel_fcf->fka_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	return scnprintf(buf, PAGE_SIZE, "%d\n", fka_period);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static DEVICE_ATTR(fcoe_mac, S_IRUGO, qedf_fcoe_mac_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static DEVICE_ATTR(fka_period, S_IRUGO, qedf_fka_period_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) struct device_attribute *qedf_host_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	&dev_attr_fcoe_mac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	&dev_attr_fka_period,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) extern const struct qed_fcoe_ops *qed_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) void qedf_capture_grc_dump(struct qedf_ctx *qedf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct qedf_ctx *base_qedf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	/* Make sure we use the base qedf to take the GRC dump */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (qedf_is_vport(qedf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		base_qedf = qedf_get_base_qedf(qedf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		base_qedf = qedf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (test_bit(QEDF_GRCDUMP_CAPTURE, &base_qedf->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		QEDF_INFO(&(base_qedf->dbg_ctx), QEDF_LOG_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		    "GRC Dump already captured.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	qedf_get_grc_dump(base_qedf->cdev, qed_ops->common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	    &base_qedf->grcdump, &base_qedf->grcdump_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	QEDF_ERR(&(base_qedf->dbg_ctx), "GRC Dump captured.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	set_bit(QEDF_GRCDUMP_CAPTURE, &base_qedf->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	qedf_uevent_emit(base_qedf->lport->host, QEDF_UEVENT_CODE_GRCDUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	    NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) qedf_sysfs_read_grcdump(struct file *filep, struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			struct bin_attribute *ba, char *buf, loff_t off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	ssize_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct fc_lport *lport = shost_priv(dev_to_shost(container_of(kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 							struct device, kobj)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct qedf_ctx *qedf = lport_priv(lport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (test_bit(QEDF_GRCDUMP_CAPTURE, &qedf->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		ret = memory_read_from_buffer(buf, count, &off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		    qedf->grcdump, qedf->grcdump_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		QEDF_ERR(&(qedf->dbg_ctx), "GRC Dump not captured!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) qedf_sysfs_write_grcdump(struct file *filep, struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			struct bin_attribute *ba, char *buf, loff_t off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct fc_lport *lport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct qedf_ctx *qedf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	long reading;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	char msg[40];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (off != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	lport = shost_priv(dev_to_shost(container_of(kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	    struct device, kobj)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	qedf = lport_priv(lport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	buf[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	ret = kstrtol(buf, 10, &reading);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		QEDF_ERR(&(qedf->dbg_ctx), "Invalid input, err(%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	memset(msg, 0, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	switch (reading) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		memset(qedf->grcdump, 0, qedf->grcdump_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		clear_bit(QEDF_GRCDUMP_CAPTURE, &qedf->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		qedf_capture_grc_dump(qedf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static struct bin_attribute sysfs_grcdump_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	.attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		.name = "grcdump",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		.mode = S_IRUSR | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	.size = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	.read = qedf_sysfs_read_grcdump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	.write = qedf_sysfs_write_grcdump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static struct sysfs_bin_attrs bin_file_entries[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	{"grcdump", &sysfs_grcdump_attr},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	{NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) void qedf_create_sysfs_ctx_attr(struct qedf_ctx *qedf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	qedf_create_sysfs_attr(qedf->lport->host, bin_file_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) void qedf_remove_sysfs_ctx_attr(struct qedf_ctx *qedf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	qedf_remove_sysfs_attr(qedf->lport->host, bin_file_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }