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