1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LIBSRP_H__
3 #define __LIBSRP_H__
4 
5 #include <linux/list.h>
6 #include <linux/kfifo.h>
7 #include <scsi/srp.h>
8 
9 enum srp_valid {
10 	INVALIDATE_CMD_RESP_EL = 0,
11 	VALID_CMD_RESP_EL = 0x80,
12 	VALID_INIT_MSG = 0xC0,
13 	VALID_TRANS_EVENT = 0xFF
14 };
15 
16 enum srp_format {
17 	SRP_FORMAT = 1,
18 	MAD_FORMAT = 2,
19 	OS400_FORMAT = 3,
20 	AIX_FORMAT = 4,
21 	LINUX_FORMAT = 5,
22 	MESSAGE_IN_CRQ = 6
23 };
24 
25 enum srp_init_msg {
26 	INIT_MSG = 1,
27 	INIT_COMPLETE_MSG = 2
28 };
29 
30 enum srp_trans_event {
31 	UNUSED_FORMAT = 0,
32 	PARTNER_FAILED = 1,
33 	PARTNER_DEREGISTER = 2,
34 	MIGRATED = 6,
35 	PREPARE_FOR_SUSPEND = 9,
36 	RESUME_FROM_SUSP = 0xA
37 };
38 
39 enum srp_status {
40 	CRQ_ENTRY_OVERWRITTEN = 0x20,
41 	HEADER_DESCRIPTOR = 0xF1,
42 	PING = 0xF5,
43 	PING_RESPONSE = 0xF6
44 };
45 
46 enum srp_mad_version {
47 	MAD_VERSION_1 = 1
48 };
49 
50 enum srp_os_type {
51 	OS400 = 1,
52 	LINUX = 2,
53 	AIX = 3,
54 	OFW = 4
55 };
56 
57 enum srp_task_attributes {
58 	SRP_SIMPLE_TASK = 0,
59 	SRP_HEAD_TASK = 1,
60 	SRP_ORDERED_TASK = 2,
61 	SRP_ACA_TASK = 4
62 };
63 
64 enum {
65 	SRP_TASK_MANAGEMENT_FUNCTION_COMPLETE           = 0,
66 	SRP_REQUEST_FIELDS_INVALID                      = 2,
67 	SRP_TASK_MANAGEMENT_FUNCTION_NOT_SUPPORTED      = 4,
68 	SRP_TASK_MANAGEMENT_FUNCTION_FAILED             = 5
69 };
70 
71 struct srp_buf {
72 	dma_addr_t dma;
73 	void *buf;
74 };
75 
76 struct srp_queue {
77 	void *pool;
78 	void *items;
79 	struct kfifo queue;
80 	spinlock_t lock;
81 };
82 
83 struct srp_target {
84 	struct device *dev;
85 
86 	spinlock_t lock;
87 	struct list_head cmd_queue;
88 
89 	size_t srp_iu_size;
90 	struct srp_queue iu_queue;
91 	size_t rx_ring_size;
92 	struct srp_buf **rx_ring;
93 
94 	void *ldata;
95 };
96 
97 struct iu_entry {
98 	struct srp_target *target;
99 
100 	struct list_head ilist;
101 	dma_addr_t remote_token;
102 	unsigned long flags;
103 
104 	struct srp_buf *sbuf;
105 	u16 iu_len;
106 };
107 
108 struct ibmvscsis_cmd;
109 
110 typedef int (srp_rdma_t)(struct ibmvscsis_cmd *, struct scatterlist *, int,
111 			 struct srp_direct_buf *, int,
112 			 enum dma_data_direction, unsigned int);
113 int srp_target_alloc(struct srp_target *, struct device *, size_t, size_t);
114 void srp_target_free(struct srp_target *);
115 struct iu_entry *srp_iu_get(struct srp_target *);
116 void srp_iu_put(struct iu_entry *);
117 int srp_transfer_data(struct ibmvscsis_cmd *, struct srp_cmd *,
118 		      srp_rdma_t, int, int);
119 u64 srp_data_length(struct srp_cmd *cmd, enum dma_data_direction dir);
120 int srp_get_desc_table(struct srp_cmd *srp_cmd, enum dma_data_direction *dir,
121 		       u64 *data_len);
122 static inline int srp_cmd_direction(struct srp_cmd *cmd)
123 {
124 	return (cmd->buf_fmt >> 4) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
125 }
126 
127 #endif
128