FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 1 | #ifndef __LIBSRP_H__ |
| 2 | #define __LIBSRP_H__ |
| 3 | |
| 4 | #include <linux/list.h> |
James Bottomley | 75c85a0 | 2009-12-30 13:21:06 -0600 | [diff] [blame] | 5 | #include <linux/kfifo.h> |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 6 | #include <scsi/scsi_cmnd.h> |
| 7 | #include <scsi/scsi_host.h> |
| 8 | #include <scsi/srp.h> |
| 9 | |
| 10 | enum iue_flags { |
| 11 | V_DIOVER, |
| 12 | V_WRITE, |
| 13 | V_LINKED, |
| 14 | V_FLYING, |
| 15 | }; |
| 16 | |
| 17 | struct srp_buf { |
| 18 | dma_addr_t dma; |
| 19 | void *buf; |
| 20 | }; |
| 21 | |
| 22 | struct srp_queue { |
| 23 | void *pool; |
| 24 | void *items; |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 25 | struct kfifo queue; |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 26 | spinlock_t lock; |
| 27 | }; |
| 28 | |
| 29 | struct srp_target { |
| 30 | struct Scsi_Host *shost; |
| 31 | struct device *dev; |
| 32 | |
| 33 | spinlock_t lock; |
| 34 | struct list_head cmd_queue; |
| 35 | |
| 36 | size_t srp_iu_size; |
| 37 | struct srp_queue iu_queue; |
| 38 | size_t rx_ring_size; |
| 39 | struct srp_buf **rx_ring; |
| 40 | |
| 41 | void *ldata; |
| 42 | }; |
| 43 | |
| 44 | struct iu_entry { |
| 45 | struct srp_target *target; |
| 46 | |
| 47 | struct list_head ilist; |
| 48 | dma_addr_t remote_token; |
| 49 | unsigned long flags; |
| 50 | |
| 51 | struct srp_buf *sbuf; |
| 52 | }; |
| 53 | |
| 54 | typedef int (srp_rdma_t)(struct scsi_cmnd *, struct scatterlist *, int, |
| 55 | struct srp_direct_buf *, int, |
| 56 | enum dma_data_direction, unsigned int); |
| 57 | extern int srp_target_alloc(struct srp_target *, struct device *, size_t, size_t); |
| 58 | extern void srp_target_free(struct srp_target *); |
| 59 | |
| 60 | extern struct iu_entry *srp_iu_get(struct srp_target *); |
| 61 | extern void srp_iu_put(struct iu_entry *); |
| 62 | |
FUJITA Tomonori | 17b0bcf | 2007-07-11 15:08:21 +0900 | [diff] [blame] | 63 | extern int srp_cmd_queue(struct Scsi_Host *, struct srp_cmd *, void *, u64, u64); |
FUJITA Tomonori | 26b1482 | 2006-12-01 03:00:50 +0900 | [diff] [blame] | 64 | extern int srp_transfer_data(struct scsi_cmnd *, struct srp_cmd *, |
| 65 | srp_rdma_t, int, int); |
| 66 | |
| 67 | |
| 68 | static inline struct srp_target *host_to_srp_target(struct Scsi_Host *host) |
| 69 | { |
| 70 | return (struct srp_target *) host->hostdata; |
| 71 | } |
| 72 | |
| 73 | static inline int srp_cmd_direction(struct srp_cmd *cmd) |
| 74 | { |
| 75 | return (cmd->buf_fmt >> 4) ? DMA_TO_DEVICE : DMA_FROM_DEVICE; |
| 76 | } |
| 77 | |
| 78 | #endif |