1 /* $OpenBSD: ldcvar.h,v 1.4 2009/12/26 21:21:10 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 struct ldc_queue { 23 bus_dmamap_t lq_map; 24 bus_dma_segment_t lq_seg; 25 caddr_t lq_va; 26 int lq_nentries; 27 }; 28 29 struct ldc_queue *ldc_queue_alloc(bus_dma_tag_t, int); 30 void ldc_queue_free(bus_dma_tag_t, struct ldc_queue *); 31 32 /* 33 * LDC virtual link layer protocol. 34 */ 35 36 #define LDC_VERSION_MAJOR 1 37 #define LDC_VERSION_MINOR 0 38 39 #define LDC_PKT_PAYLOAD 56 40 41 struct ldc_pkt { 42 uint8_t type; 43 uint8_t stype; 44 uint8_t ctrl; 45 uint8_t env; 46 uint32_t seqid; 47 48 uint16_t major; 49 uint16_t minor; 50 uint32_t _reserved[13]; 51 }; 52 53 /* Packet types. */ 54 #define LDC_CTRL 0x01 55 #define LDC_DATA 0x02 56 #define LDC_ERR 0x10 57 58 /* Packet subtypes. */ 59 #define LDC_INFO 0x01 60 #define LDC_ACK 0x02 61 #define LDC_NACK 0x04 62 63 /* Control info values. */ 64 #define LDC_VERS 0x01 65 #define LDC_RTS 0x02 66 #define LDC_RTR 0x03 67 #define LDC_RDX 0x04 68 69 /* Packet envelope. */ 70 #define LDC_MODE_RAW 0x00 71 #define LDC_MODE_UNRELIABLE 0x01 72 #define LDC_MODE_RELIABLE 0x03 73 74 #define LDC_LEN_MASK 0x3f 75 #define LDC_FRAG_MASK 0xc0 76 #define LDC_FRAG_START 0x40 77 #define LDC_FRAG_STOP 0x80 78 79 /* 80 * XXX Get rid of the +8 once we no longer need to store the header of 81 * the first packet. 82 */ 83 #define LDC_MSG_MAX (128 + 8) 84 85 struct ldc_conn { 86 uint64_t lc_id; 87 88 struct ldc_queue *lc_txq; 89 struct ldc_queue *lc_rxq; 90 uint64_t lc_tx_state; 91 uint64_t lc_rx_state; 92 93 uint32_t lc_tx_seqid; 94 uint8_t lc_state; 95 #define LDC_SND_VERS 1 96 #define LDC_RCV_VERS 2 97 #define LDC_SND_RTS 3 98 #define LDC_SND_RTR 4 99 #define LDC_SND_RDX 5 100 101 uint64_t lc_msg[LDC_MSG_MAX / 8]; 102 size_t lc_len; 103 104 void *lc_sc; 105 void (*lc_reset)(struct ldc_conn *); 106 void (*lc_start)(struct ldc_conn *); 107 void (*lc_rx_data)(struct ldc_conn *, struct ldc_pkt *); 108 }; 109 110 void ldc_rx_ctrl(struct ldc_conn *, struct ldc_pkt *); 111 void ldc_rx_data(struct ldc_conn *, struct ldc_pkt *); 112 113 void ldc_send_vers(struct ldc_conn *); 114 115 void ldc_reset(struct ldc_conn *); 116 117 /* 118 * LDC map tables. 119 */ 120 121 struct ldc_map_slot { 122 uint64_t entry; 123 uint64_t cookie; 124 }; 125 126 #define LDC_MTE_R 0x0000000000000010ULL 127 #define LDC_MTE_W 0x0000000000000020ULL 128 #define LDC_MTE_X 0x0000000000000040ULL 129 #define LDC_MTE_IOR 0x0000000000000080ULL 130 #define LDC_MTE_IOW 0x0000000000000100ULL 131 #define LDC_MTE_CPR 0x0000000000000200ULL 132 #define LDC_MTE_CPW 0x0000000000000400ULL 133 #define LDC_MTE_RA_MASK 0x007fffffffffe000ULL 134 135 struct ldc_map { 136 bus_dmamap_t lm_map; 137 bus_dma_segment_t lm_seg; 138 struct ldc_map_slot *lm_slot; 139 int lm_nentries; 140 int lm_next; 141 int lm_count; 142 }; 143 144 struct ldc_map *ldc_map_alloc(bus_dma_tag_t, int); 145 void ldc_map_free(bus_dma_tag_t, struct ldc_map *); 146 147 struct ldc_cookie { 148 uint64_t addr; 149 uint64_t size; 150 }; 151