xref: /linux/drivers/scsi/ibmvscsi_tgt/libsrp.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
288a678bbSBryant G. Ly #ifndef __LIBSRP_H__
388a678bbSBryant G. Ly #define __LIBSRP_H__
488a678bbSBryant G. Ly 
588a678bbSBryant G. Ly #include <linux/list.h>
688a678bbSBryant G. Ly #include <linux/kfifo.h>
788a678bbSBryant G. Ly #include <scsi/srp.h>
888a678bbSBryant G. Ly 
988a678bbSBryant G. Ly enum srp_valid {
1088a678bbSBryant G. Ly 	INVALIDATE_CMD_RESP_EL = 0,
1188a678bbSBryant G. Ly 	VALID_CMD_RESP_EL = 0x80,
1288a678bbSBryant G. Ly 	VALID_INIT_MSG = 0xC0,
1388a678bbSBryant G. Ly 	VALID_TRANS_EVENT = 0xFF
1488a678bbSBryant G. Ly };
1588a678bbSBryant G. Ly 
1688a678bbSBryant G. Ly enum srp_format {
1788a678bbSBryant G. Ly 	SRP_FORMAT = 1,
1888a678bbSBryant G. Ly 	MAD_FORMAT = 2,
1988a678bbSBryant G. Ly 	OS400_FORMAT = 3,
2088a678bbSBryant G. Ly 	AIX_FORMAT = 4,
2188a678bbSBryant G. Ly 	LINUX_FORMAT = 5,
2288a678bbSBryant G. Ly 	MESSAGE_IN_CRQ = 6
2388a678bbSBryant G. Ly };
2488a678bbSBryant G. Ly 
2588a678bbSBryant G. Ly enum srp_init_msg {
2688a678bbSBryant G. Ly 	INIT_MSG = 1,
2788a678bbSBryant G. Ly 	INIT_COMPLETE_MSG = 2
2888a678bbSBryant G. Ly };
2988a678bbSBryant G. Ly 
3088a678bbSBryant G. Ly enum srp_trans_event {
3188a678bbSBryant G. Ly 	UNUSED_FORMAT = 0,
3288a678bbSBryant G. Ly 	PARTNER_FAILED = 1,
3388a678bbSBryant G. Ly 	PARTNER_DEREGISTER = 2,
34464fd641SMichael Cyr 	MIGRATED = 6,
35464fd641SMichael Cyr 	PREPARE_FOR_SUSPEND = 9,
36464fd641SMichael Cyr 	RESUME_FROM_SUSP = 0xA
3788a678bbSBryant G. Ly };
3888a678bbSBryant G. Ly 
3988a678bbSBryant G. Ly enum srp_status {
40464fd641SMichael Cyr 	CRQ_ENTRY_OVERWRITTEN = 0x20,
4188a678bbSBryant G. Ly 	HEADER_DESCRIPTOR = 0xF1,
4288a678bbSBryant G. Ly 	PING = 0xF5,
4388a678bbSBryant G. Ly 	PING_RESPONSE = 0xF6
4488a678bbSBryant G. Ly };
4588a678bbSBryant G. Ly 
4688a678bbSBryant G. Ly enum srp_mad_version {
4788a678bbSBryant G. Ly 	MAD_VERSION_1 = 1
4888a678bbSBryant G. Ly };
4988a678bbSBryant G. Ly 
5088a678bbSBryant G. Ly enum srp_os_type {
5188a678bbSBryant G. Ly 	OS400 = 1,
5288a678bbSBryant G. Ly 	LINUX = 2,
5388a678bbSBryant G. Ly 	AIX = 3,
5488a678bbSBryant G. Ly 	OFW = 4
5588a678bbSBryant G. Ly };
5688a678bbSBryant G. Ly 
5788a678bbSBryant G. Ly enum srp_task_attributes {
5888a678bbSBryant G. Ly 	SRP_SIMPLE_TASK = 0,
5988a678bbSBryant G. Ly 	SRP_HEAD_TASK = 1,
6088a678bbSBryant G. Ly 	SRP_ORDERED_TASK = 2,
6188a678bbSBryant G. Ly 	SRP_ACA_TASK = 4
6288a678bbSBryant G. Ly };
6388a678bbSBryant G. Ly 
6488a678bbSBryant G. Ly enum {
6588a678bbSBryant G. Ly 	SRP_TASK_MANAGEMENT_FUNCTION_COMPLETE           = 0,
6688a678bbSBryant G. Ly 	SRP_REQUEST_FIELDS_INVALID                      = 2,
6788a678bbSBryant G. Ly 	SRP_TASK_MANAGEMENT_FUNCTION_NOT_SUPPORTED      = 4,
6888a678bbSBryant G. Ly 	SRP_TASK_MANAGEMENT_FUNCTION_FAILED             = 5
6988a678bbSBryant G. Ly };
7088a678bbSBryant G. Ly 
7188a678bbSBryant G. Ly struct srp_buf {
7288a678bbSBryant G. Ly 	dma_addr_t dma;
7388a678bbSBryant G. Ly 	void *buf;
7488a678bbSBryant G. Ly };
7588a678bbSBryant G. Ly 
7688a678bbSBryant G. Ly struct srp_queue {
7788a678bbSBryant G. Ly 	void *pool;
7888a678bbSBryant G. Ly 	void *items;
7988a678bbSBryant G. Ly 	struct kfifo queue;
8088a678bbSBryant G. Ly 	spinlock_t lock;
8188a678bbSBryant G. Ly };
8288a678bbSBryant G. Ly 
8388a678bbSBryant G. Ly struct srp_target {
8488a678bbSBryant G. Ly 	struct device *dev;
8588a678bbSBryant G. Ly 
8688a678bbSBryant G. Ly 	spinlock_t lock;
8788a678bbSBryant G. Ly 	struct list_head cmd_queue;
8888a678bbSBryant G. Ly 
8988a678bbSBryant G. Ly 	size_t srp_iu_size;
9088a678bbSBryant G. Ly 	struct srp_queue iu_queue;
9188a678bbSBryant G. Ly 	size_t rx_ring_size;
9288a678bbSBryant G. Ly 	struct srp_buf **rx_ring;
9388a678bbSBryant G. Ly 
9488a678bbSBryant G. Ly 	void *ldata;
9588a678bbSBryant G. Ly };
9688a678bbSBryant G. Ly 
9788a678bbSBryant G. Ly struct iu_entry {
9888a678bbSBryant G. Ly 	struct srp_target *target;
9988a678bbSBryant G. Ly 
10088a678bbSBryant G. Ly 	struct list_head ilist;
10188a678bbSBryant G. Ly 	dma_addr_t remote_token;
10288a678bbSBryant G. Ly 	unsigned long flags;
10388a678bbSBryant G. Ly 
10488a678bbSBryant G. Ly 	struct srp_buf *sbuf;
10588a678bbSBryant G. Ly 	u16 iu_len;
10688a678bbSBryant G. Ly };
10788a678bbSBryant G. Ly 
10888a678bbSBryant G. Ly struct ibmvscsis_cmd;
10988a678bbSBryant G. Ly 
11088a678bbSBryant G. Ly typedef int (srp_rdma_t)(struct ibmvscsis_cmd *, struct scatterlist *, int,
11188a678bbSBryant G. Ly 			 struct srp_direct_buf *, int,
11288a678bbSBryant G. Ly 			 enum dma_data_direction, unsigned int);
11388a678bbSBryant G. Ly int srp_target_alloc(struct srp_target *, struct device *, size_t, size_t);
11488a678bbSBryant G. Ly void srp_target_free(struct srp_target *);
11588a678bbSBryant G. Ly struct iu_entry *srp_iu_get(struct srp_target *);
11688a678bbSBryant G. Ly void srp_iu_put(struct iu_entry *);
11788a678bbSBryant G. Ly int srp_transfer_data(struct ibmvscsis_cmd *, struct srp_cmd *,
11888a678bbSBryant G. Ly 		      srp_rdma_t, int, int);
11988a678bbSBryant G. Ly u64 srp_data_length(struct srp_cmd *cmd, enum dma_data_direction dir);
12088a678bbSBryant G. Ly int srp_get_desc_table(struct srp_cmd *srp_cmd, enum dma_data_direction *dir,
12188a678bbSBryant G. Ly 		       u64 *data_len);
srp_cmd_direction(struct srp_cmd * cmd)12288a678bbSBryant G. Ly static inline int srp_cmd_direction(struct srp_cmd *cmd)
12388a678bbSBryant G. Ly {
12488a678bbSBryant G. Ly 	return (cmd->buf_fmt >> 4) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
12588a678bbSBryant G. Ly }
12688a678bbSBryant G. Ly 
12788a678bbSBryant G. Ly #endif
128