1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2009 Emulex. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* 28 * Header file defining the driver buffer management interface 29 */ 30 31 #ifndef _OCE_BUF_H_ 32 #define _OCE_BUF_H_ 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 #include <sys/ddidmareq.h> 39 #include <oce_io.h> 40 #include <oce_utils.h> 41 42 #define GET_Q_NEXT(_START, _STEP, _END) \ 43 (((_START) + (_STEP)) < (_END) ? ((_START) + (_STEP)) \ 44 : (((_START) + (_STEP)) - (_END))) 45 46 #define OCE_MAX_TX_HDL 8 47 #define OCE_MAX_TXDMA_COOKIES 16 48 #define OCE_TXMAP_ALIGN 1 49 #define OCE_TX_MAX_FRAGS (OCE_MAX_TX_HDL * OCE_MAX_TXDMA_COOKIES) 50 #define OCE_TX_LO_WM OCE_TX_MAX_FRAGS 51 52 /* helper structure to access OS addresses */ 53 typedef union oce_addr_s { 54 uint64_t addr64; 55 struct { 56 #ifdef _BIG_ENDIAN 57 uint32_t addr_hi; 58 uint32_t addr_lo; 59 #else 60 uint32_t addr_lo; 61 uint32_t addr_hi; 62 #endif 63 }dw; 64 }oce_addr64_t; 65 66 typedef struct oce_dma_buf_s { 67 caddr_t base; 68 uint64_t addr; 69 ddi_acc_handle_t acc_handle; 70 ddi_dma_handle_t dma_handle; 71 /* size of the memory */ 72 size_t size; 73 size_t off; 74 size_t len; 75 uint32_t num_pages; 76 }oce_dma_buf_t; 77 78 #define DBUF_PA(obj) (((oce_dma_buf_t *)(obj))->addr) 79 #define DBUF_VA(obj) (((oce_dma_buf_t *)(obj))->base) 80 #define DBUF_DHDL(obj) (((oce_dma_buf_t *)(obj))->dma_handle) 81 #define DBUF_AHDL(obj) (((oce_dma_buf_t *)obj))->acc_handle) 82 83 typedef struct oce_ring_buffer_s { 84 uint16_t cidx; /* Get ptr */ 85 uint16_t pidx; /* Put Ptr */ 86 size_t item_size; /* Size */ 87 size_t num_items; /* count */ 88 uint32_t num_used; 89 oce_dma_buf_t *dbuf; /* dma buffer */ 90 }oce_ring_buffer_t; 91 92 typedef struct oce_rq_bdesc_s { 93 OCE_LIST_NODE_T link; 94 oce_dma_buf_t *rqb; 95 struct oce_rq *rq; 96 oce_addr64_t frag_addr; 97 mblk_t *mp; 98 frtn_t fr_rtn; 99 }oce_rq_bdesc_t; 100 101 typedef struct oce_wq_bdesc_s { 102 OCE_LIST_NODE_T link; 103 oce_dma_buf_t *wqb; 104 oce_addr64_t frag_addr; 105 } oce_wq_bdesc_t; 106 107 typedef struct oce_wq_mdesc_s { 108 OCE_LIST_NODE_T link; 109 ddi_dma_handle_t dma_handle; 110 } oce_wq_mdesc_t; 111 112 enum entry_type { 113 HEADER_WQE = 0x1, /* arbitrary value */ 114 MAPPED_WQE, 115 COPY_WQE, 116 DUMMY_WQE 117 }; 118 119 typedef struct _oce_handle_s { 120 void *hdl; /* opaque handle */ 121 }oce_handle_t; 122 123 typedef struct _oce_wqe_desc_s { 124 OCE_LIST_NODE_T link; 125 oce_handle_t hdesc[OCE_MAX_TX_HDL]; 126 struct oce_nic_frag_wqe frag[OCE_TX_MAX_FRAGS]; 127 struct oce_wq *wq; 128 mblk_t *mp; 129 enum entry_type type; 130 uint16_t wq_start_idx; 131 uint16_t wq_end_idx; 132 uint16_t wqe_cnt; 133 uint16_t pkt_len; /* 64K MAX */ 134 uint32_t frag_cnt; 135 uint32_t nhdl; 136 }oce_wqe_desc_t; 137 138 #pragma pack(1) 139 /* Always keep it 2 mod 4 */ 140 typedef struct _oce_rq_buf_hdr_s { 141 void *datap; 142 uint8_t pad[18]; 143 /* ether_vlan_header_t vhdr; */ 144 } oce_rq_buf_hdr_t; 145 #pragma pack() 146 147 #define OCE_RQE_BUF_HEADROOM sizeof (oce_rq_buf_hdr_t) 148 #define MAX_POOL_NAME 32 149 150 #define RING_NUM_PENDING(ring) ring->num_used 151 152 #define RING_NUM_FREE(ring) \ 153 (uint32_t)(ring->num_items - ring->num_used) 154 155 #define RING_FULL(ring) (ring->num_used == ring->num_items) 156 157 #define RING_EMPTY(ring) (ring->num_used == 0) 158 159 #define RING_GET(ring, n) \ 160 ring->cidx = GET_Q_NEXT(ring->cidx, n, ring->num_items) 161 162 #define RING_PUT(ring, n) \ 163 ring->pidx = GET_Q_NEXT(ring->pidx, n, ring->num_items) 164 165 #define RING_GET_CONSUMER_ITEM_VA(ring, type) \ 166 (void*)(((type *)DBUF_VA(ring->dbuf)) + ring->cidx) 167 168 #define RING_GET_CONSUMER_ITEM_PA(ring, type) \ 169 (uint64_t)(((type *)DBUF_PA(ring->dbuf)) + ring->cidx) 170 171 #define RING_GET_PRODUCER_ITEM_VA(ring, type) \ 172 (void *)(((type *)DBUF_VA(ring->dbuf)) + ring->pidx) 173 174 #define RING_GET_PRODUCER_ITEM_PA(ring, type) \ 175 (uint64_t)(((type *)DBUF_PA(ring->dbuf)) + ring->pidx) 176 177 /* Rq cache */ 178 int oce_rqb_cache_create(struct oce_rq *rq, size_t buf_size); 179 void oce_rqb_cache_destroy(struct oce_rq *rq); 180 181 /* Wq Cache */ 182 int oce_wqe_desc_ctor(void *buf, void *arg, int kmflags); 183 void oce_wqe_desc_dtor(void *buf, void *arg); 184 185 int oce_wqb_cache_create(struct oce_wq *wq, size_t buf_size); 186 void oce_wqb_cache_destroy(struct oce_wq *wq); 187 188 void oce_wqm_cache_destroy(struct oce_wq *wq); 189 int oce_wqm_cache_create(struct oce_wq *wq); 190 191 void oce_page_list(oce_dma_buf_t *dbuf, 192 struct phys_addr *pa_list, int list_size); 193 194 195 #ifdef __cplusplus 196 } 197 #endif 198 199 #endif /* _OCE_BUF_H_ */ 200