162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  Parallel SCSI (SPI) transport specific attributes exported to sysfs.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci *  Copyright (c) 2003 Silicon Graphics, Inc.  All rights reserved.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci#ifndef SCSI_TRANSPORT_SPI_H
862306a36Sopenharmony_ci#define SCSI_TRANSPORT_SPI_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/transport_class.h>
1162306a36Sopenharmony_ci#include <linux/mutex.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistruct scsi_transport_template;
1462306a36Sopenharmony_cistruct scsi_target;
1562306a36Sopenharmony_cistruct scsi_device;
1662306a36Sopenharmony_cistruct Scsi_Host;
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistruct spi_transport_attrs {
1962306a36Sopenharmony_ci	int period;		/* value in the PPR/SDTR command */
2062306a36Sopenharmony_ci	int min_period;
2162306a36Sopenharmony_ci	int offset;
2262306a36Sopenharmony_ci	int max_offset;
2362306a36Sopenharmony_ci	unsigned int width:1;	/* 0 - narrow, 1 - wide */
2462306a36Sopenharmony_ci	unsigned int max_width:1;
2562306a36Sopenharmony_ci	unsigned int iu:1;	/* Information Units enabled */
2662306a36Sopenharmony_ci	unsigned int max_iu:1;
2762306a36Sopenharmony_ci	unsigned int dt:1;	/* DT clocking enabled */
2862306a36Sopenharmony_ci	unsigned int qas:1;	/* Quick Arbitration and Selection enabled */
2962306a36Sopenharmony_ci	unsigned int max_qas:1;
3062306a36Sopenharmony_ci	unsigned int wr_flow:1;	/* Write Flow control enabled */
3162306a36Sopenharmony_ci	unsigned int rd_strm:1;	/* Read streaming enabled */
3262306a36Sopenharmony_ci	unsigned int rti:1;	/* Retain Training Information */
3362306a36Sopenharmony_ci	unsigned int pcomp_en:1;/* Precompensation enabled */
3462306a36Sopenharmony_ci	unsigned int hold_mcs:1;/* Hold Margin Control Settings */
3562306a36Sopenharmony_ci	unsigned int initial_dv:1; /* DV done to this target yet  */
3662306a36Sopenharmony_ci	unsigned long flags;	/* flags field for drivers to use */
3762306a36Sopenharmony_ci	/* Device Properties fields */
3862306a36Sopenharmony_ci	unsigned int support_sync:1; /* synchronous support */
3962306a36Sopenharmony_ci	unsigned int support_wide:1; /* wide support */
4062306a36Sopenharmony_ci	unsigned int support_dt:1; /* allows DT phases */
4162306a36Sopenharmony_ci	unsigned int support_dt_only; /* disallows ST phases */
4262306a36Sopenharmony_ci	unsigned int support_ius; /* support Information Units */
4362306a36Sopenharmony_ci	unsigned int support_qas; /* supports quick arbitration and selection */
4462306a36Sopenharmony_ci	/* Private Fields */
4562306a36Sopenharmony_ci	unsigned int dv_pending:1; /* Internal flag: DV Requested */
4662306a36Sopenharmony_ci	unsigned int dv_in_progress:1;	/* Internal: DV started */
4762306a36Sopenharmony_ci	struct mutex dv_mutex; /* semaphore to serialise dv */
4862306a36Sopenharmony_ci};
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_cienum spi_signal_type {
5162306a36Sopenharmony_ci	SPI_SIGNAL_UNKNOWN = 1,
5262306a36Sopenharmony_ci	SPI_SIGNAL_SE,
5362306a36Sopenharmony_ci	SPI_SIGNAL_LVD,
5462306a36Sopenharmony_ci	SPI_SIGNAL_HVD,
5562306a36Sopenharmony_ci};
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_cistruct spi_host_attrs {
5862306a36Sopenharmony_ci	enum spi_signal_type signalling;
5962306a36Sopenharmony_ci};
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci/* accessor functions */
6262306a36Sopenharmony_ci#define spi_period(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->period)
6362306a36Sopenharmony_ci#define spi_min_period(x) (((struct spi_transport_attrs *)&(x)->starget_data)->min_period)
6462306a36Sopenharmony_ci#define spi_offset(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->offset)
6562306a36Sopenharmony_ci#define spi_max_offset(x) (((struct spi_transport_attrs *)&(x)->starget_data)->max_offset)
6662306a36Sopenharmony_ci#define spi_width(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->width)
6762306a36Sopenharmony_ci#define spi_max_width(x) (((struct spi_transport_attrs *)&(x)->starget_data)->max_width)
6862306a36Sopenharmony_ci#define spi_iu(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->iu)
6962306a36Sopenharmony_ci#define spi_max_iu(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->max_iu)
7062306a36Sopenharmony_ci#define spi_dt(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->dt)
7162306a36Sopenharmony_ci#define spi_qas(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->qas)
7262306a36Sopenharmony_ci#define spi_max_qas(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->max_qas)
7362306a36Sopenharmony_ci#define spi_wr_flow(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->wr_flow)
7462306a36Sopenharmony_ci#define spi_rd_strm(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->rd_strm)
7562306a36Sopenharmony_ci#define spi_rti(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->rti)
7662306a36Sopenharmony_ci#define spi_pcomp_en(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->pcomp_en)
7762306a36Sopenharmony_ci#define spi_hold_mcs(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->hold_mcs)
7862306a36Sopenharmony_ci#define spi_initial_dv(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->initial_dv)
7962306a36Sopenharmony_ci#define spi_dv_pending(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_pending)
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#define spi_support_sync(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->support_sync)
8262306a36Sopenharmony_ci#define spi_support_wide(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->support_wide)
8362306a36Sopenharmony_ci#define spi_support_dt(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->support_dt)
8462306a36Sopenharmony_ci#define spi_support_dt_only(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->support_dt_only)
8562306a36Sopenharmony_ci#define spi_support_ius(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->support_ius)
8662306a36Sopenharmony_ci#define spi_support_qas(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->support_qas)
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci#define spi_flags(x)	(((struct spi_transport_attrs *)&(x)->starget_data)->flags)
8962306a36Sopenharmony_ci#define spi_signalling(h)	(((struct spi_host_attrs *)(h)->shost_data)->signalling)
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci/* The functions by which the transport class and the driver communicate */
9462306a36Sopenharmony_cistruct spi_function_template {
9562306a36Sopenharmony_ci	void	(*get_period)(struct scsi_target *);
9662306a36Sopenharmony_ci	void	(*set_period)(struct scsi_target *, int);
9762306a36Sopenharmony_ci	void	(*get_offset)(struct scsi_target *);
9862306a36Sopenharmony_ci	void	(*set_offset)(struct scsi_target *, int);
9962306a36Sopenharmony_ci	void	(*get_width)(struct scsi_target *);
10062306a36Sopenharmony_ci	void	(*set_width)(struct scsi_target *, int);
10162306a36Sopenharmony_ci	void	(*get_iu)(struct scsi_target *);
10262306a36Sopenharmony_ci	void	(*set_iu)(struct scsi_target *, int);
10362306a36Sopenharmony_ci	void	(*get_dt)(struct scsi_target *);
10462306a36Sopenharmony_ci	void	(*set_dt)(struct scsi_target *, int);
10562306a36Sopenharmony_ci	void	(*get_qas)(struct scsi_target *);
10662306a36Sopenharmony_ci	void	(*set_qas)(struct scsi_target *, int);
10762306a36Sopenharmony_ci	void	(*get_wr_flow)(struct scsi_target *);
10862306a36Sopenharmony_ci	void	(*set_wr_flow)(struct scsi_target *, int);
10962306a36Sopenharmony_ci	void	(*get_rd_strm)(struct scsi_target *);
11062306a36Sopenharmony_ci	void	(*set_rd_strm)(struct scsi_target *, int);
11162306a36Sopenharmony_ci	void	(*get_rti)(struct scsi_target *);
11262306a36Sopenharmony_ci	void	(*set_rti)(struct scsi_target *, int);
11362306a36Sopenharmony_ci	void	(*get_pcomp_en)(struct scsi_target *);
11462306a36Sopenharmony_ci	void	(*set_pcomp_en)(struct scsi_target *, int);
11562306a36Sopenharmony_ci	void	(*get_hold_mcs)(struct scsi_target *);
11662306a36Sopenharmony_ci	void	(*set_hold_mcs)(struct scsi_target *, int);
11762306a36Sopenharmony_ci	void	(*get_signalling)(struct Scsi_Host *);
11862306a36Sopenharmony_ci	void	(*set_signalling)(struct Scsi_Host *, enum spi_signal_type);
11962306a36Sopenharmony_ci	int	(*deny_binding)(struct scsi_target *);
12062306a36Sopenharmony_ci	/* The driver sets these to tell the transport class it
12162306a36Sopenharmony_ci	 * wants the attributes displayed in sysfs.  If the show_ flag
12262306a36Sopenharmony_ci	 * is not set, the attribute will be private to the transport
12362306a36Sopenharmony_ci	 * class */
12462306a36Sopenharmony_ci	unsigned long	show_period:1;
12562306a36Sopenharmony_ci	unsigned long	show_offset:1;
12662306a36Sopenharmony_ci	unsigned long	show_width:1;
12762306a36Sopenharmony_ci	unsigned long	show_iu:1;
12862306a36Sopenharmony_ci	unsigned long	show_dt:1;
12962306a36Sopenharmony_ci	unsigned long	show_qas:1;
13062306a36Sopenharmony_ci	unsigned long	show_wr_flow:1;
13162306a36Sopenharmony_ci	unsigned long	show_rd_strm:1;
13262306a36Sopenharmony_ci	unsigned long	show_rti:1;
13362306a36Sopenharmony_ci	unsigned long	show_pcomp_en:1;
13462306a36Sopenharmony_ci	unsigned long	show_hold_mcs:1;
13562306a36Sopenharmony_ci};
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_cistruct scsi_transport_template *spi_attach_transport(struct spi_function_template *);
13862306a36Sopenharmony_civoid spi_release_transport(struct scsi_transport_template *);
13962306a36Sopenharmony_civoid spi_schedule_dv_device(struct scsi_device *);
14062306a36Sopenharmony_civoid spi_dv_device(struct scsi_device *);
14162306a36Sopenharmony_civoid spi_display_xfer_agreement(struct scsi_target *);
14262306a36Sopenharmony_ciint spi_print_msg(const unsigned char *);
14362306a36Sopenharmony_ciint spi_populate_width_msg(unsigned char *msg, int width);
14462306a36Sopenharmony_ciint spi_populate_sync_msg(unsigned char *msg, int period, int offset);
14562306a36Sopenharmony_ciint spi_populate_ppr_msg(unsigned char *msg, int period, int offset, int width,
14662306a36Sopenharmony_ci		int options);
14762306a36Sopenharmony_ciint spi_populate_tag_msg(unsigned char *msg, struct scsi_cmnd *cmd);
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci#endif /* SCSI_TRANSPORT_SPI_H */
150