blob: 832606ae2908cf1a600d357e8d8450b40a423c83 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Bryant G. Ly88a678b2016-06-28 17:05:35 -05002#ifndef __LIBSRP_H__
3#define __LIBSRP_H__
4
5#include <linux/list.h>
6#include <linux/kfifo.h>
7#include <scsi/srp.h>
8
9enum 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
16enum 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
25enum srp_init_msg {
26 INIT_MSG = 1,
27 INIT_COMPLETE_MSG = 2
28};
29
30enum srp_trans_event {
31 UNUSED_FORMAT = 0,
32 PARTNER_FAILED = 1,
33 PARTNER_DEREGISTER = 2,
Michael Cyr464fd642017-05-16 17:49:21 -050034 MIGRATED = 6,
35 PREPARE_FOR_SUSPEND = 9,
36 RESUME_FROM_SUSP = 0xA
Bryant G. Ly88a678b2016-06-28 17:05:35 -050037};
38
39enum srp_status {
Michael Cyr464fd642017-05-16 17:49:21 -050040 CRQ_ENTRY_OVERWRITTEN = 0x20,
Bryant G. Ly88a678b2016-06-28 17:05:35 -050041 HEADER_DESCRIPTOR = 0xF1,
42 PING = 0xF5,
43 PING_RESPONSE = 0xF6
44};
45
46enum srp_mad_version {
47 MAD_VERSION_1 = 1
48};
49
50enum srp_os_type {
51 OS400 = 1,
52 LINUX = 2,
53 AIX = 3,
54 OFW = 4
55};
56
57enum 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
64enum {
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
71struct srp_buf {
72 dma_addr_t dma;
73 void *buf;
74};
75
76struct srp_queue {
77 void *pool;
78 void *items;
79 struct kfifo queue;
80 spinlock_t lock;
81};
82
83struct 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
97struct 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
108struct ibmvscsis_cmd;
109
110typedef int (srp_rdma_t)(struct ibmvscsis_cmd *, struct scatterlist *, int,
111 struct srp_direct_buf *, int,
112 enum dma_data_direction, unsigned int);
113int srp_target_alloc(struct srp_target *, struct device *, size_t, size_t);
114void srp_target_free(struct srp_target *);
115struct iu_entry *srp_iu_get(struct srp_target *);
116void srp_iu_put(struct iu_entry *);
117int srp_transfer_data(struct ibmvscsis_cmd *, struct srp_cmd *,
118 srp_rdma_t, int, int);
119u64 srp_data_length(struct srp_cmd *cmd, enum dma_data_direction dir);
120int srp_get_desc_table(struct srp_cmd *srp_cmd, enum dma_data_direction *dir,
121 u64 *data_len);
122static 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