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)  * IBM Accelerator Family 'GenWQE'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * (C) Copyright IBM Corp. 2013
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author: Frank Haverkamp <haver@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Author: Joerg-Stephan Vogt <jsvogt@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Author: Michael Jung <mijung@gmx.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Author: Michael Ruettger <michael@ibmra.de>
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Sysfs interfaces for the GenWQE card. There are attributes to query
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * the version of the bitstream as well as some for the driver. For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * debugging, please also see the debugfs interfaces of this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "card_base.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "card_ddcb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static const char * const genwqe_types[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	[GENWQE_TYPE_ALTERA_230] = "GenWQE4-230",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	[GENWQE_TYPE_ALTERA_530] = "GenWQE4-530",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	[GENWQE_TYPE_ALTERA_A4]  = "GenWQE5-A4",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	[GENWQE_TYPE_ALTERA_A7]  = "GenWQE5-A7",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static ssize_t status_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 			   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct genwqe_dev *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	const char *cs[GENWQE_CARD_STATE_MAX] = { "unused", "used", "error" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return sprintf(buf, "%s\n", cs[cd->card_state]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static DEVICE_ATTR_RO(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static ssize_t appid_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	char app_name[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct genwqe_dev *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	genwqe_read_app_id(cd, app_name, sizeof(app_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return sprintf(buf, "%s\n", app_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static DEVICE_ATTR_RO(appid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static ssize_t version_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	u64 slu_id, app_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct genwqe_dev *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	slu_id = __genwqe_readq(cd, IO_SLU_UNITCFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	app_id = __genwqe_readq(cd, IO_APP_UNITCFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	return sprintf(buf, "%016llx.%016llx\n", slu_id, app_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static DEVICE_ATTR_RO(version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static ssize_t type_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	u8 card_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct genwqe_dev *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	card_type = genwqe_card_type(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return sprintf(buf, "%s\n", (card_type >= ARRAY_SIZE(genwqe_types)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		       "invalid" : genwqe_types[card_type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static DEVICE_ATTR_RO(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static ssize_t tempsens_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			     char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	u64 tempsens;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct genwqe_dev *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	tempsens = __genwqe_readq(cd, IO_SLU_TEMPERATURE_SENSOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return sprintf(buf, "%016llx\n", tempsens);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static DEVICE_ATTR_RO(tempsens);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) static ssize_t freerunning_timer_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 				      char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	u64 t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct genwqe_dev *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	t = __genwqe_readq(cd, IO_SLC_FREE_RUNNING_TIMER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	return sprintf(buf, "%016llx\n", t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static DEVICE_ATTR_RO(freerunning_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static ssize_t queue_working_time_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 				       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 				       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	u64 t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct genwqe_dev *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	t = __genwqe_readq(cd, IO_SLC_QUEUE_WTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	return sprintf(buf, "%016llx\n", t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static DEVICE_ATTR_RO(queue_working_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static ssize_t base_clock_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	u64 base_clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct genwqe_dev *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	base_clock = genwqe_base_clock_frequency(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return sprintf(buf, "%lld\n", base_clock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static DEVICE_ATTR_RO(base_clock);
^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)  * curr_bitstream_show() - Show the current bitstream id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * There is a bug in some old versions of the CPLD which selects the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * bitstream, which causes the IO_SLU_BITSTREAM register to report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * unreliable data in very rare cases. This makes this sysfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * unreliable up to the point were a new CPLD version is being used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * Unfortunately there is no automatic way yet to query the CPLD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * version, such that you need to manually ensure via programming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * tools that you have a recent version of the CPLD software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * The proposed circumvention is to use a special recovery bitstream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * on the backup partition (0) to identify problems while loading the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * image.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static ssize_t curr_bitstream_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 				   struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	int curr_bitstream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct genwqe_dev *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	curr_bitstream = __genwqe_readq(cd, IO_SLU_BITSTREAM) & 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return sprintf(buf, "%d\n", curr_bitstream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static DEVICE_ATTR_RO(curr_bitstream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * next_bitstream_show() - Show the next activated bitstream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * IO_SLC_CFGREG_SOFTRESET: This register can only be accessed by the PF.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static ssize_t next_bitstream_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 				   struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	int next_bitstream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct genwqe_dev *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	switch ((cd->softreset & 0xc) >> 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	case 0x2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		next_bitstream =  0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	case 0x3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		next_bitstream =  1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		next_bitstream = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		break;		/* error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	return sprintf(buf, "%d\n", next_bitstream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static ssize_t next_bitstream_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 				    struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 				    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	int partition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct genwqe_dev *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (kstrtoint(buf, 0, &partition) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	switch (partition) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	case 0x0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		cd->softreset = 0x78;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	case 0x1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		cd->softreset = 0x7c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	__genwqe_writeq(cd, IO_SLC_CFGREG_SOFTRESET, cd->softreset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static DEVICE_ATTR_RW(next_bitstream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static ssize_t reload_bitstream_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 				struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 				const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	int reload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	struct genwqe_dev *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (kstrtoint(buf, 0, &reload) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (reload == 0x1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		if (cd->card_state == GENWQE_CARD_UNUSED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		    cd->card_state == GENWQE_CARD_USED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			cd->card_state = GENWQE_CARD_RELOAD_BITSTREAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static DEVICE_ATTR_WO(reload_bitstream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * Create device_attribute structures / params: name, mode, show, store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * additional flag if valid in VF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static struct attribute *genwqe_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	&dev_attr_tempsens.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	&dev_attr_next_bitstream.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	&dev_attr_curr_bitstream.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	&dev_attr_base_clock.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	&dev_attr_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	&dev_attr_version.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	&dev_attr_appid.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	&dev_attr_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	&dev_attr_freerunning_timer.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	&dev_attr_queue_working_time.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	&dev_attr_reload_bitstream.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static struct attribute *genwqe_normal_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	&dev_attr_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	&dev_attr_version.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	&dev_attr_appid.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	&dev_attr_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	&dev_attr_freerunning_timer.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	&dev_attr_queue_working_time.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * genwqe_is_visible() - Determine if sysfs attribute should be visible or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * VFs have restricted mmio capabilities, so not all sysfs entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * are allowed in VFs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static umode_t genwqe_is_visible(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				 struct attribute *attr, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	unsigned int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct device *dev = kobj_to_dev(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	struct genwqe_dev *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	umode_t mode = attr->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (genwqe_is_privileged(cd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		return mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	for (j = 0; genwqe_normal_attributes[j] != NULL;  j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		if (genwqe_normal_attributes[j] == attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			return mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static struct attribute_group genwqe_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	.is_visible = genwqe_is_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	.attrs      = genwqe_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) const struct attribute_group *genwqe_attribute_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	&genwqe_attribute_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) };