18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Parallel SCSI (SPI) transport specific attributes exported to sysfs.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (c) 2003 Silicon Graphics, Inc.  All rights reserved.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci#ifndef SCSI_TRANSPORT_SPI_H
88c2ecf20Sopenharmony_ci#define SCSI_TRANSPORT_SPI_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/transport_class.h>
118c2ecf20Sopenharmony_ci#include <linux/mutex.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_cistruct scsi_transport_template;
148c2ecf20Sopenharmony_cistruct scsi_target;
158c2ecf20Sopenharmony_cistruct scsi_device;
168c2ecf20Sopenharmony_cistruct Scsi_Host;
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistruct spi_transport_attrs {
198c2ecf20Sopenharmony_ci	int period;		/* value in the PPR/SDTR command */
208c2ecf20Sopenharmony_ci	int min_period;
218c2ecf20Sopenharmony_ci	int offset;
228c2ecf20Sopenharmony_ci	int max_offset;
238c2ecf20Sopenharmony_ci	unsigned int width:1;	/* 0 - narrow, 1 - wide */
248c2ecf20Sopenharmony_ci	unsigned int max_width:1;
258c2ecf20Sopenharmony_ci	unsigned int iu:1;	/* Information Units enabled */
268c2ecf20Sopenharmony_ci	unsigned int max_iu:1;
278c2ecf20Sopenharmony_ci	unsigned int dt:1;	/* DT clocking enabled */
288c2ecf20Sopenharmony_ci	unsigned int qas:1;	/* Quick Arbitration and Selection enabled */
298c2ecf20Sopenharmony_ci	unsigned int max_qas:1;
308c2ecf20Sopenharmony_ci	unsigned int wr_flow:1;	/* Write Flow control enabled */
318c2ecf20Sopenharmony_ci	unsigned int rd_strm:1;	/* Read streaming enabled */
328c2ecf20Sopenharmony_ci	unsigned int rti:1;	/* Retain Training Information */
338c2ecf20Sopenharmony_ci	unsigned int pcomp_en:1;/* Precompensation enabled */
348c2ecf20Sopenharmony_ci	unsigned int hold_mcs:1;/* Hold Margin Control Settings */
358c2ecf20Sopenharmony_ci	unsigned int initial_dv:1; /* DV done to this target yet  */
368c2ecf20Sopenharmony_ci	unsigned long flags;	/* flags field for drivers to use */
378c2ecf20Sopenharmony_ci	/* Device Properties fields */
388c2ecf20Sopenharmony_ci	unsigned int support_sync:1; /* synchronous support */
398c2ecf20Sopenharmony_ci	unsigned int support_wide:1; /* wide support */
408c2ecf20Sopenharmony_ci	unsigned int support_dt:1; /* allows DT phases */
418c2ecf20Sopenharmony_ci	unsigned int support_dt_only; /* disallows ST phases */
428c2ecf20Sopenharmony_ci	unsigned int support_ius; /* support Information Units */
438c2ecf20Sopenharmony_ci	unsigned int support_qas; /* supports quick arbitration and selection */
448c2ecf20Sopenharmony_ci	/* Private Fields */
458c2ecf20Sopenharmony_ci	unsigned int dv_pending:1; /* Internal flag: DV Requested */
468c2ecf20Sopenharmony_ci	unsigned int dv_in_progress:1;	/* Internal: DV started */
478c2ecf20Sopenharmony_ci	struct mutex dv_mutex; /* semaphore to serialise dv */
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cienum spi_signal_type {
518c2ecf20Sopenharmony_ci	SPI_SIGNAL_UNKNOWN = 1,
528c2ecf20Sopenharmony_ci	SPI_SIGNAL_SE,
538c2ecf20Sopenharmony_ci	SPI_SIGNAL_LVD,
548c2ecf20Sopenharmony_ci	SPI_SIGNAL_HVD,
558c2ecf20Sopenharmony_ci};
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistruct spi_host_attrs {
588c2ecf20Sopenharmony_ci	enum spi_signal_type signalling;
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci/* accessor functions */
628c2ecf20Sopenharmony_ci#define spi_period(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->period)
638c2ecf20Sopenharmony_ci#define spi_min_period(x) (((struct spi_transport_attrs *)&(x)->starget_data)->min_period)
648c2ecf20Sopenharmony_ci#define spi_offset(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->offset)
658c2ecf20Sopenharmony_ci#define spi_max_offset(x) (((struct spi_transport_attrs *)&(x)->starget_data)->max_offset)
668c2ecf20Sopenharmony_ci#define spi_width(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->width)
678c2ecf20Sopenharmony_ci#define spi_max_width(x) (((struct spi_transport_attrs *)&(x)->starget_data)->max_width)
688c2ecf20Sopenharmony_ci#define spi_iu(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->iu)
698c2ecf20Sopenharmony_ci#define spi_max_iu(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->max_iu)
708c2ecf20Sopenharmony_ci#define spi_dt(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->dt)
718c2ecf20Sopenharmony_ci#define spi_qas(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->qas)
728c2ecf20Sopenharmony_ci#define spi_max_qas(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->max_qas)
738c2ecf20Sopenharmony_ci#define spi_wr_flow(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->wr_flow)
748c2ecf20Sopenharmony_ci#define spi_rd_strm(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->rd_strm)
758c2ecf20Sopenharmony_ci#define spi_rti(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->rti)
768c2ecf20Sopenharmony_ci#define spi_pcomp_en(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->pcomp_en)
778c2ecf20Sopenharmony_ci#define spi_hold_mcs(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->hold_mcs)
788c2ecf20Sopenharmony_ci#define spi_initial_dv(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->initial_dv)
798c2ecf20Sopenharmony_ci#define spi_dv_pending(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_pending)
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#define spi_support_sync(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->support_sync)
828c2ecf20Sopenharmony_ci#define spi_support_wide(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->support_wide)
838c2ecf20Sopenharmony_ci#define spi_support_dt(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->support_dt)
848c2ecf20Sopenharmony_ci#define spi_support_dt_only(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->support_dt_only)
858c2ecf20Sopenharmony_ci#define spi_support_ius(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->support_ius)
868c2ecf20Sopenharmony_ci#define spi_support_qas(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->support_qas)
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#define spi_flags(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->flags)
898c2ecf20Sopenharmony_ci#define spi_signalling(h)	(((struct spi_host_attrs *)(h)->shost_data)->signalling)
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/* The functions by which the transport class and the driver communicate */
948c2ecf20Sopenharmony_cistruct spi_function_template {
958c2ecf20Sopenharmony_ci	void	(*get_period)(struct scsi_target *);
968c2ecf20Sopenharmony_ci	void	(*set_period)(struct scsi_target *, int);
978c2ecf20Sopenharmony_ci	void	(*get_offset)(struct scsi_target *);
988c2ecf20Sopenharmony_ci	void	(*set_offset)(struct scsi_target *, int);
998c2ecf20Sopenharmony_ci	void	(*get_width)(struct scsi_target *);
1008c2ecf20Sopenharmony_ci	void	(*set_width)(struct scsi_target *, int);
1018c2ecf20Sopenharmony_ci	void	(*get_iu)(struct scsi_target *);
1028c2ecf20Sopenharmony_ci	void	(*set_iu)(struct scsi_target *, int);
1038c2ecf20Sopenharmony_ci	void	(*get_dt)(struct scsi_target *);
1048c2ecf20Sopenharmony_ci	void	(*set_dt)(struct scsi_target *, int);
1058c2ecf20Sopenharmony_ci	void	(*get_qas)(struct scsi_target *);
1068c2ecf20Sopenharmony_ci	void	(*set_qas)(struct scsi_target *, int);
1078c2ecf20Sopenharmony_ci	void	(*get_wr_flow)(struct scsi_target *);
1088c2ecf20Sopenharmony_ci	void	(*set_wr_flow)(struct scsi_target *, int);
1098c2ecf20Sopenharmony_ci	void	(*get_rd_strm)(struct scsi_target *);
1108c2ecf20Sopenharmony_ci	void	(*set_rd_strm)(struct scsi_target *, int);
1118c2ecf20Sopenharmony_ci	void	(*get_rti)(struct scsi_target *);
1128c2ecf20Sopenharmony_ci	void	(*set_rti)(struct scsi_target *, int);
1138c2ecf20Sopenharmony_ci	void	(*get_pcomp_en)(struct scsi_target *);
1148c2ecf20Sopenharmony_ci	void	(*set_pcomp_en)(struct scsi_target *, int);
1158c2ecf20Sopenharmony_ci	void	(*get_hold_mcs)(struct scsi_target *);
1168c2ecf20Sopenharmony_ci	void	(*set_hold_mcs)(struct scsi_target *, int);
1178c2ecf20Sopenharmony_ci	void	(*get_signalling)(struct Scsi_Host *);
1188c2ecf20Sopenharmony_ci	void	(*set_signalling)(struct Scsi_Host *, enum spi_signal_type);
1198c2ecf20Sopenharmony_ci	int	(*deny_binding)(struct scsi_target *);
1208c2ecf20Sopenharmony_ci	/* The driver sets these to tell the transport class it
1218c2ecf20Sopenharmony_ci	 * wants the attributes displayed in sysfs.  If the show_ flag
1228c2ecf20Sopenharmony_ci	 * is not set, the attribute will be private to the transport
1238c2ecf20Sopenharmony_ci	 * class */
1248c2ecf20Sopenharmony_ci	unsigned long	show_period:1;
1258c2ecf20Sopenharmony_ci	unsigned long	show_offset:1;
1268c2ecf20Sopenharmony_ci	unsigned long	show_width:1;
1278c2ecf20Sopenharmony_ci	unsigned long	show_iu:1;
1288c2ecf20Sopenharmony_ci	unsigned long	show_dt:1;
1298c2ecf20Sopenharmony_ci	unsigned long	show_qas:1;
1308c2ecf20Sopenharmony_ci	unsigned long	show_wr_flow:1;
1318c2ecf20Sopenharmony_ci	unsigned long	show_rd_strm:1;
1328c2ecf20Sopenharmony_ci	unsigned long	show_rti:1;
1338c2ecf20Sopenharmony_ci	unsigned long	show_pcomp_en:1;
1348c2ecf20Sopenharmony_ci	unsigned long	show_hold_mcs:1;
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistruct scsi_transport_template *spi_attach_transport(struct spi_function_template *);
1388c2ecf20Sopenharmony_civoid spi_release_transport(struct scsi_transport_template *);
1398c2ecf20Sopenharmony_civoid spi_schedule_dv_device(struct scsi_device *);
1408c2ecf20Sopenharmony_civoid spi_dv_device(struct scsi_device *);
1418c2ecf20Sopenharmony_civoid spi_display_xfer_agreement(struct scsi_target *);
1428c2ecf20Sopenharmony_ciint spi_print_msg(const unsigned char *);
1438c2ecf20Sopenharmony_ciint spi_populate_width_msg(unsigned char *msg, int width);
1448c2ecf20Sopenharmony_ciint spi_populate_sync_msg(unsigned char *msg, int period, int offset);
1458c2ecf20Sopenharmony_ciint spi_populate_ppr_msg(unsigned char *msg, int period, int offset, int width,
1468c2ecf20Sopenharmony_ci		int options);
1478c2ecf20Sopenharmony_ciint spi_populate_tag_msg(unsigned char *msg, struct scsi_cmnd *cmd);
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci#endif /* SCSI_TRANSPORT_SPI_H */
150