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 QLogic Corporation. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
29 */
30
31 #ifndef _QLT_DMA_H
32 #define _QLT_DMA_H
33
34 #include <sys/stmf.h>
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /*
41 * DMA memory object.
42 */
43 #define QLT_DMA_SG_LIST_LENGTH 1270
44 #define CMD7_2400_DATA_SEGMENTS 1
45 #define CONT_A64_DATA_SEGMENTS 5
46
47
48 /*
49 * Container for ddi_dma_handle
50 *
51 * These elements are either linked to an active dbuf or in the free list.
52 */
53 struct qlt_dma_handle {
54 struct qlt_dma_handle *next;
55 ddi_dma_handle_t dma_handle;
56 ddi_dma_cookie_t first_cookie;
57 uint_t num_cookies;
58 uint_t num_cookies_fetched;
59 };
60
61 typedef struct qlt_dma_handle qlt_dma_handle_t;
62
63 /*
64 * The dbuf private data when using a scatter/gather list.
65 */
66 struct qlt_dma_sgl {
67 uint16_t handle_count;
68 uint16_t cookie_count;
69 uint16_t cookie_next_fetch;
70 uint16_t cookie_prefetched;
71 qlt_dma_handle_t *handle_list;
72 qlt_dma_handle_t *handle_next_fetch;
73 size_t qsize;
74 ddi_dma_cookie_t cookie[1];
75 };
76
77 typedef struct qlt_dma_sgl qlt_dma_sgl_t;
78
79 /*
80 * Structure to maintain ddi_dma_handle free pool.
81 */
82 struct qlt_dma_handle_pool {
83 kmutex_t pool_lock; /* protects all fields */
84 qlt_dma_handle_t *free_list;
85 int num_free;
86 int num_total;
87 };
88
89 typedef struct qlt_dma_handle_pool qlt_dma_handle_pool_t;
90
91 struct qlt_dmem_bucket;
92
93 typedef struct qlt_dmem_bctl {
94 struct qlt_dmem_bucket *bctl_bucket;
95 struct qlt_dmem_bctl *bctl_next;
96 uint64_t bctl_dev_addr;
97 uint8_t bctl_task_ndx; /* notused */
98 stmf_data_buf_t *bctl_buf;
99 } qlt_dmem_bctl_t;
100
101 typedef struct qlt_dmem_bucket {
102 uint32_t dmem_buf_size;
103 uint32_t dmem_nbufs;
104 uint32_t dmem_nbufs_free;
105 uint8_t *dmem_host_addr;
106 uint64_t dmem_dev_addr;
107 ddi_dma_handle_t dmem_dma_handle;
108 ddi_acc_handle_t dmem_acc_handle;
109 kmutex_t dmem_lock;
110 qlt_dmem_bctl_t *dmem_bctl_free_list;
111 void *dmem_bctls_mem;
112 } qlt_dmem_bucket_t;
113
114 fct_status_t qlt_dmem_init(qlt_state_t *qlt);
115 void qlt_dmem_fini(qlt_state_t *qlt);
116 void qlt_dma_handle_pool_init(qlt_state_t *qlt);
117 void qlt_dma_handle_pool_fini(qlt_state_t *qlt);
118 stmf_data_buf_t *qlt_dmem_alloc(fct_local_port_t *port, uint32_t size,
119 uint32_t *pminsize, uint32_t flags);
120 stmf_data_buf_t *qlt_i_dmem_alloc(qlt_state_t *qlt, uint32_t size,
121 uint32_t *pminsize, uint32_t flags);
122 void qlt_dmem_free(fct_dbuf_store_t *fds, stmf_data_buf_t *dbuf);
123 void qlt_i_dmem_free(qlt_state_t *qlt, stmf_data_buf_t *dbuf);
124 stmf_status_t qlt_dma_setup_dbuf(fct_local_port_t *port,
125 stmf_data_buf_t *dbuf, uint32_t flags);
126 void qlt_dma_teardown_dbuf(fct_dbuf_store_t *fds, stmf_data_buf_t *dbuf);
127 void qlt_dmem_dma_sync(stmf_data_buf_t *dbuf, uint_t sync_type);
128 uint8_t qlt_get_iocb_count(uint32_t cookie_cnt);
129 uint64_t qlt_ddi_vtop(caddr_t vaddr);
130 /*
131 * XXX move the following into the fct layer
132 */
133 uint16_t qlt_get_cookie_count(stmf_data_buf_t *dbuf);
134 void qlt_ddi_dma_nextcookie(stmf_data_buf_t *dbuf, ddi_dma_cookie_t *cookie_p);
135 ddi_dma_cookie_t *qlt_get_cookie_array(stmf_data_buf_t *dbuf);
136
137
138 #ifdef __cplusplus
139 }
140 #endif
141
142 #endif /* _QLT_DMA_H */