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