1 /* $OpenBSD: ldcvar.h,v 1.6 2014/09/29 17:43:29 kettenis Exp $ */ 2 /* 3 * Copyright (c) 2009 Mark Kettenis 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 /* 19 * LDC queues. 20 */ 21 22 #include <sys/mutex.h> 23 24 struct ldc_queue { 25 struct mutex lq_mtx; 26 bus_dmamap_t lq_map; 27 bus_dma_segment_t lq_seg; 28 caddr_t lq_va; 29 int lq_nentries; 30 }; 31 32 struct ldc_queue *ldc_queue_alloc(bus_dma_tag_t, int); 33 void ldc_queue_free(bus_dma_tag_t, struct ldc_queue *); 34 35 /* 36 * LDC virtual link layer protocol. 37 */ 38 39 #define LDC_VERSION_MAJOR 1 40 #define LDC_VERSION_MINOR 0 41 42 #define LDC_PKT_PAYLOAD 56 43 44 struct ldc_pkt { 45 uint8_t type; 46 uint8_t stype; 47 uint8_t ctrl; 48 uint8_t env; 49 uint32_t seqid; 50 51 uint16_t major; 52 uint16_t minor; 53 uint32_t _reserved[13]; 54 }; 55 56 /* Packet types. */ 57 #define LDC_CTRL 0x01 58 #define LDC_DATA 0x02 59 #define LDC_ERR 0x10 60 61 /* Packet subtypes. */ 62 #define LDC_INFO 0x01 63 #define LDC_ACK 0x02 64 #define LDC_NACK 0x04 65 66 /* Control info values. */ 67 #define LDC_VERS 0x01 68 #define LDC_RTS 0x02 69 #define LDC_RTR 0x03 70 #define LDC_RDX 0x04 71 72 /* Packet envelope. */ 73 #define LDC_MODE_RAW 0x00 74 #define LDC_MODE_UNRELIABLE 0x01 75 #define LDC_MODE_RELIABLE 0x03 76 77 #define LDC_LEN_MASK 0x3f 78 #define LDC_FRAG_MASK 0xc0 79 #define LDC_FRAG_START 0x40 80 #define LDC_FRAG_STOP 0x80 81 82 /* 83 * XXX Get rid of the +8 once we no longer need to store the header of 84 * the first packet. 85 */ 86 #define LDC_MSG_MAX (128 + 8) 87 88 struct ldc_conn { 89 uint64_t lc_id; 90 91 struct ldc_queue *lc_txq; 92 struct ldc_queue *lc_rxq; 93 uint64_t lc_tx_state; 94 uint64_t lc_rx_state; 95 96 uint32_t lc_tx_seqid; 97 uint8_t lc_state; 98 #define LDC_SND_VERS 1 99 #define LDC_RCV_VERS 2 100 #define LDC_SND_RTS 3 101 #define LDC_SND_RTR 4 102 #define LDC_SND_RDX 5 103 104 uint64_t lc_msg[LDC_MSG_MAX / 8]; 105 size_t lc_len; 106 107 void *lc_sc; 108 void (*lc_reset)(struct ldc_conn *); 109 void (*lc_start)(struct ldc_conn *); 110 void (*lc_rx_data)(struct ldc_conn *, struct ldc_pkt *); 111 }; 112 113 void ldc_rx_ctrl(struct ldc_conn *, struct ldc_pkt *); 114 void ldc_rx_data(struct ldc_conn *, struct ldc_pkt *); 115 116 void ldc_send_vers(struct ldc_conn *); 117 int ldc_send_unreliable(struct ldc_conn *, void *, size_t); 118 119 void ldc_reset(struct ldc_conn *); 120 121 /* 122 * LDC map tables. 123 */ 124 125 struct ldc_map_slot { 126 uint64_t entry; 127 uint64_t cookie; 128 }; 129 130 #define LDC_MTE_R 0x0000000000000010ULL 131 #define LDC_MTE_W 0x0000000000000020ULL 132 #define LDC_MTE_X 0x0000000000000040ULL 133 #define LDC_MTE_IOR 0x0000000000000080ULL 134 #define LDC_MTE_IOW 0x0000000000000100ULL 135 #define LDC_MTE_CPR 0x0000000000000200ULL 136 #define LDC_MTE_CPW 0x0000000000000400ULL 137 #define LDC_MTE_RA_MASK 0x007fffffffffe000ULL 138 139 struct ldc_map { 140 bus_dmamap_t lm_map; 141 bus_dma_segment_t lm_seg; 142 struct ldc_map_slot *lm_slot; 143 int lm_nentries; 144 int lm_next; 145 int lm_count; 146 }; 147 148 struct ldc_map *ldc_map_alloc(bus_dma_tag_t, int); 149 void ldc_map_free(bus_dma_tag_t, struct ldc_map *); 150 151 struct ldc_cookie { 152 uint64_t addr; 153 uint64_t size; 154 }; 155