Print this page
4031 scsa1394 violates DDI scsi_pkt(9S) allocation rules
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/1394/targets/scsa1394/impl.h
+++ new/usr/src/uts/common/sys/1394/targets/scsa1394/impl.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #ifndef _SYS_1394_TARGETS_SCSA1394_IMPL_H
27 27 #define _SYS_1394_TARGETS_SCSA1394_IMPL_H
28 28
29 -#pragma ident "%Z%%M% %I% %E% SMI"
30 -
31 29 /*
32 30 * scsa1394 definitions
33 31 */
34 32
35 33 #include <sys/1394/t1394.h>
36 34 #include <sys/sbp2/driver.h>
37 35 #include <sys/scsi/scsi.h>
38 36 #include <sys/cdio.h>
39 37 #include <sys/1394/targets/scsa1394/cmd.h>
40 38
41 39 #ifdef __cplusplus
42 40 extern "C" {
43 41 #endif
44 42
45 43 /*
46 44 * each lun uses a worker thread for various deferred processing
47 45 */
48 46 typedef enum {
49 47 SCSA1394_THR_INIT, /* initial state */
50 48 SCSA1394_THR_RUN, /* thread is running */
51 49 SCSA1394_THR_EXIT /* thread exited */
52 50 } scsa1394_thr_state_t;
53 51
54 52 /* thread requests */
55 53 enum {
56 54 SCSA1394_THREQ_EXIT = 0x1, /* thread has to exit */
57 55 SCSA1394_THREQ_TASK_STATUS = 0x2, /* task status received */
58 56 SCSA1394_THREQ_NUDGE = 0x4, /* nudge SBP-2 layer */
59 57 SCSA1394_THREQ_BUS_RESET = 0x8,
60 58 SCSA1394_THREQ_DISCONNECT = 0x10,
61 59 SCSA1394_THREQ_RECONNECT = 0x20
62 60 };
63 61
64 62 typedef struct scsa1394_thread {
65 63 void (*thr_func)(void *); /* function to be run */
66 64 void *thr_arg; /* function argument */
67 65 struct scsa1394_lun *thr_lun; /* lun we belong to */
68 66 scsa1394_thr_state_t thr_state; /* state */
69 67 kcondvar_t thr_cv; /* cv for request wait */
70 68 int thr_req; /* request mask */
71 69 } scsa1394_thread_t;
72 70
73 71
74 72 /* 1394 device state */
75 73 typedef enum {
76 74 SCSA1394_DEV_INIT = 0,
77 75 SCSA1394_DEV_ONLINE,
78 76 SCSA1394_DEV_BUS_RESET,
79 77 SCSA1394_DEV_DISCONNECTED,
80 78 SCSA1394_DEV_PWRED_DOWN,
81 79 SCSA1394_DEV_SUSPENDED
82 80 } scsa1394_dev_state_t;
83 81
84 82 enum { SCSA1394_STAT_NCMD_LAST = 8 };
85 83
86 84 /* per-lun statistics */
87 85 typedef struct scsa1394_lun_stat {
88 86 /*
89 87 * ring buffer of the last N failed commands. stat_cmd_fail_last_idx
90 88 * is an index into stat_cmd_fail_last the array and points to the
91 89 * entry to be written next. The first 16 bytes are CDB bytes,
92 90 * the last 8 bytes are a timestamp (lbolt).
93 91 */
94 92 uint64_t stat_cmd_last_fail[SCSA1394_STAT_NCMD_LAST][3];
95 93 int stat_cmd_last_fail_idx;
96 94
97 95 uint_t stat_cmd_cnt; /* # of commands submitted */
98 96 uint_t stat_cmd_buf_max_nsegs;
99 97 uint_t stat_cmd_buf_dma_partial;
100 98
101 99 /*
102 100 * errors
103 101 */
104 102 uint_t stat_err_pkt_kmem_alloc;
105 103 uint_t stat_err_cmd_cdb_dmem_alloc;
106 104 uint_t stat_err_cmd_cdb_dbind;
107 105 uint_t stat_err_cmd_cdb_addr_alloc;
108 106 uint_t stat_err_cmd_buf_dbind;
109 107 uint_t stat_err_cmd_buf_addr_alloc;
110 108 uint_t stat_err_cmd_pt_kmem_alloc;
111 109 uint_t stat_err_cmd_pt_dmem_alloc;
112 110 uint_t stat_err_cmd_pt_addr_alloc;
113 111 uint_t stat_err_status_tran_err;
114 112 uint_t stat_err_status_conv;
115 113 uint_t stat_err_status_resp;
116 114 } scsa1394_lun_stat_t;
117 115
118 116 /* logical unit */
119 117 typedef struct scsa1394_lun {
120 118 kmutex_t l_mutex; /* structure lock */
121 119 struct scsa1394_state *l_sp; /* soft state */
122 120 sbp2_lun_t *l_lun; /* SBP2 lun */
123 121 sbp2_ses_t *l_ses; /* login session */
124 122 dev_info_t *l_cdip; /* child devinfo */
125 123 scsa1394_thread_t l_worker_thread; /* worker thread */
126 124 ddi_softintr_t l_softintr_id; /* soft interrupt */
127 125 boolean_t l_softintr_triggered; /* trigger indicator */
128 126 int l_softintr_req; /* soft intr request mask */
129 127
130 128 /* workarounds */
131 129 int l_lba_size; /* LBA size */
132 130 int l_dtype_orig; /* original DTYPE value */
133 131 int l_rmb_orig; /* original RMB value */
134 132 int l_start_stop_fail_cnt; /* start/stop failures */
135 133 boolean_t l_start_stop_fake; /* fake start/stop unit */
136 134 int l_mode_sense_fail_cnt; /* mode sense failures */
137 135 boolean_t l_mode_sense_fake; /* fake mode sense command */
138 136 boolean_t l_nosup_tur;
139 137 boolean_t l_nosup_start_stop;
140 138 boolean_t l_nosup_inquiry;
141 139
142 140 struct scsi_inquiry l_fake_inq;
143 141
144 142 scsa1394_lun_stat_t l_stat; /* statistics */
145 143 } scsa1394_lun_t;
146 144
147 145 _NOTE(MUTEX_PROTECTS_DATA(scsa1394_lun::l_mutex, scsa1394_lun))
148 146 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsa1394_lun::{
149 147 l_sp l_lun l_ses l_cdip l_worker_thread l_softintr_id
150 148 l_nosup_tur l_nosup_start_stop l_nosup_inquiry }))
151 149 _NOTE(SCHEME_PROTECTS_DATA("statistics", scsa1394_lun::l_stat))
152 150
153 151 /* l_softintr_req */
154 152 enum {
155 153 SCSA1394_SOFTINTR_STATUS_RCVD = 0x1, /* task status received */
156 154 SCSA1394_SOFTINTR_RECONNECT = 0x2 /* perform reconnect */
157 155 };
158 156
159 157 /* per-instance statistics */
160 158 typedef struct scsa1394_inst_stat {
161 159 uint_t stat_bus_reset_cnt;
162 160 uint_t stat_disconnect_cnt;
163 161 uint_t stat_reconnect_cnt;
164 162 /*
165 163 * errors
166 164 */
167 165 } scsa1394_inst_stat_t;
168 166
169 167 /* per-instance soft state structure */
170 168 typedef struct scsa1394_state {
171 169 kmutex_t s_mutex; /* structure mutex */
172 170 dev_info_t *s_dip; /* device information */
173 171 int s_instance; /* instance number */
174 172 scsa1394_dev_state_t s_dev_state; /* device state */
175 173 t1394_handle_t s_t1394_hdl; /* 1394 handle */
176 174 t1394_attachinfo_t s_attachinfo; /* 1394 attach info */
177 175 t1394_targetinfo_t s_targetinfo; /* 1394 target info */
178 176 ddi_callback_id_t s_reset_cb_id; /* reset event cb id */
179 177 ddi_callback_id_t s_remove_cb_id; /* remove event cb id */
↓ open down ↓ |
139 lines elided |
↑ open up ↑ |
180 178 ddi_callback_id_t s_insert_cb_id; /* insert event cb id */
181 179 boolean_t s_event_entered; /* event serialization */
182 180 kcondvar_t s_event_cv; /* event serialization cv */
183 181 ddi_dma_attr_t s_buf_dma_attr; /* data buffer DMA attrs */
184 182 ddi_dma_attr_t s_pt_dma_attr; /* page table DMA attrs */
185 183 scsi_hba_tran_t *s_tran; /* SCSA HBA tran structure */
186 184 sbp2_tgt_t *s_tgt; /* SBP-2 target */
187 185 sbp2_cfgrom_t *s_cfgrom; /* Config ROM */
188 186 int s_nluns; /* # of logical units */
189 187 scsa1394_lun_t *s_lun; /* logical units */
190 - kmem_cache_t *s_cmd_cache; /* command kmem cache */
191 188 ddi_taskq_t *s_taskq; /* common taskq for all luns */
192 189 boolean_t s_symbios; /* need Symbios workaround? */
193 190 boolean_t s_disconnect_warned; /* disconnect warning */
194 191 size_t s_totalsec; /* total sectors */
195 192 size_t s_secsz; /* sector size */
196 193 scsa1394_inst_stat_t s_stat; /* statistics */
197 194 } scsa1394_state_t;
198 195
199 196 _NOTE(MUTEX_PROTECTS_DATA(scsa1394_state::s_mutex, scsa1394_state))
200 197 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsa1394_state::{
201 198 s_dip s_instance s_t1394_hdl s_attachinfo s_reset_cb_id s_remove_cb_id
202 199 s_insert_cb_id s_buf_dma_attr s_pt_dma_attr s_tran s_tgt s_cfgrom
203 200 s_nluns s_lun s_cmd_cache s_taskq s_symbios s_targetinfo
204 201 s_totalsec s_secsz}))
205 202 _NOTE(SCHEME_PROTECTS_DATA("statistics", scsa1394_state::s_stat))
206 203
207 204 _NOTE(LOCK_ORDER(scsa1394_state::s_mutex scsa1394_lun::l_mutex))
208 205
209 206 /* for sbp2_bus_buf.bb_hdl */
210 207 typedef struct scsa1394_bus_buf {
211 208 scsa1394_state_t *sbb_state; /* soft state */
212 209 t1394_addr_handle_t sbb_addr_hdl; /* 1394 address handle */
213 210 ddi_dma_handle_t sbb_dma_hdl; /* DMA handle */
214 211 ddi_acc_handle_t sbb_acc_hdl; /* access handle */
215 212 } scsa1394_bus_buf_t;
216 213
217 214 _NOTE(SCHEME_PROTECTS_DATA("unique per task", scsa1394_bus_buf))
218 215 _NOTE(SCHEME_PROTECTS_DATA("dev_info::devi_lock", dev_info::devi_state))
219 216
220 217 /* various translation macros */
221 218 #define ADDR2TRAN(ap) ((ap)->a_hba_tran)
222 219 #define TRAN2STATE(hba) ((scsa1394_state_t *)(hba)->tran_hba_private)
223 220 #define ADDR2STATE(ap) (TRAN2STATE(ADDR2TRAN(ap)))
224 221
225 222 #define SCSA1394_NODEID(sp) ((sp)->s_attachinfo.localinfo.local_nodeID)
226 223 #define SCSA1394_BUSGEN(sp) ((sp)->s_attachinfo.localinfo.bus_generation)
227 224
228 225 #define SCSA1394_ORB_SIZE_ROUNDUP(sp, sz) SBP2_ORB_SIZE_ROUNDUP(sp->s_tgt, sz)
229 226 #define SCSA1394_ADDR_SET(sp, var, addr) \
230 227 SBP2_ADDR_SET(var, addr, SCSA1394_NODEID(sp))
231 228
232 229 /* macros to calculate LBA for 6/10/12-byte commands */
233 230 #define SCSA1394_LBA_6BYTE(pkt) \
234 231 (((pkt)->pkt_cdbp[1] & 0x1f) << 16) + \
235 232 ((pkt)->pkt_cdbp[2] << 8) + (pkt)->pkt_cdbp[3]
236 233 #define SCSA1394_LEN_6BYTE(pkt) \
237 234 (pkt)->pkt_cdbp[4]
238 235
239 236 #define SCSA1394_LEN_10BYTE(pkt) \
240 237 ((pkt)->pkt_cdbp[7] << 8) + (pkt)->pkt_cdbp[8]
241 238 #define SCSA1394_LBA_10BYTE(pkt) \
242 239 ((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \
243 240 ((pkt)->pkt_cdbp[4] << 8) + (pkt)->pkt_cdbp[5]
244 241
245 242 #define SCSA1394_LEN_12BYTE(pkt) \
246 243 ((pkt)->pkt_cdbp[6] << 24) + ((pkt)->pkt_cdbp[7] << 16) + \
247 244 ((pkt)->pkt_cdbp[8] << 8) + (pkt)->pkt_cdbp[9]
248 245 #define SCSA1394_LBA_12BYTE(pkt) \
249 246 ((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \
250 247 ((pkt)->pkt_cdbp[4] << 8) + (pkt)->pkt_cdbp[5]
251 248
252 249 /* macro to calculate LEN for SCMD_READ_CD command */
253 250 #define SCSA1394_LEN_READ_CD(pkt) \
254 251 (((pkt)->pkt_cdbp[6] << 16) + ((pkt)->pkt_cdbp[7] << 8) + \
255 252 (pkt)->pkt_cdbp[8])
256 253
257 254 /* calculate block size for CD-RW writes */
258 255 #define SCSA1394_CDRW_BLKSZ(bcount, len) ((bcount) / (len))
259 256 #define SCSA1394_VALID_CDRW_BLKSZ(blksz) \
260 257 (((blksz) == CDROM_BLK_2048) || ((blksz) == CDROM_BLK_2352) || \
261 258 ((blksz) == CDROM_BLK_2336) || ((blksz) == CDROM_BLK_2324))
262 259
263 260 /* black/white list */
264 261 typedef struct scsa1394_bw_list {
265 262 int vid_match;
266 263 int vid;
267 264 } scsa1394_bw_list_t;
268 265
269 266 /* match type */
270 267 enum {
271 268 SCSA1394_BW_ONE,
272 269 SCSA1394_BW_ALL
273 270 };
274 271
275 272 #define NELEM(a) (sizeof (a) / sizeof (*(a)))
276 273
277 274 /* misc constants */
278 275 enum {
279 276 SCSA1394_COMPAT_MAX = 1, /* max @ of compatible names */
280 277 SCSA1394_CLEANUP_LEVEL_MAX = 256,
281 278 SCSA1394_START_STOP_FAIL_MAX = 3, /* max start/stop failures */
282 279 SCSA1394_MODE_SENSE_FAIL_MAX = 3, /* max mode sense failures */
283 280 SCSA1394_START_STOP_TIMEOUT_MAX = 30,
284 281 SCSA1394_MAPIN_SIZE_MAX = 512,
285 282 SCSA1394_PROBE_TIMEOUT = 15, /* in seconds */
286 283
287 284 SCSA1394_DTYPE_RBC = 0x0E
288 285 };
289 286
290 287
291 288 /* SBP-2 routines */
292 289 int scsa1394_sbp2_attach(scsa1394_state_t *);
293 290 void scsa1394_sbp2_detach(scsa1394_state_t *);
294 291 void scsa1394_sbp2_fake_inquiry(scsa1394_state_t *, struct scsi_inquiry *);
295 292 int scsa1394_sbp2_threads_init(scsa1394_state_t *);
296 293 void scsa1394_sbp2_threads_fini(scsa1394_state_t *);
297 294 int scsa1394_sbp2_get_lun_type(scsa1394_lun_t *);
298 295 int scsa1394_sbp2_login(scsa1394_state_t *, int);
299 296 void scsa1394_sbp2_logout(scsa1394_state_t *, int, boolean_t);
300 297 void scsa1394_sbp2_req(scsa1394_state_t *, int, int);
301 298 void scsa1394_sbp2_disconnect(scsa1394_state_t *);
302 299 void scsa1394_sbp2_seg2pt(scsa1394_lun_t *, scsa1394_cmd_t *);
303 300 void scsa1394_sbp2_cmd2orb(scsa1394_lun_t *, scsa1394_cmd_t *);
304 301 int scsa1394_sbp2_start(scsa1394_lun_t *, scsa1394_cmd_t *);
305 302 void scsa1394_sbp2_nudge(scsa1394_lun_t *);
306 303 int scsa1394_sbp2_reset(scsa1394_lun_t *, int, scsa1394_cmd_t *);
307 304 void scsa1394_sbp2_flush_cmds(scsa1394_lun_t *, int, int, int);
308 305
309 306
310 307 /* HBA public routines */
311 308 int scsa1394_thr_dispatch(scsa1394_thread_t *);
312 309 void scsa1394_thr_cancel(scsa1394_thread_t *);
313 310 void scsa1394_thr_wake(scsa1394_thread_t *, int);
314 311 void scsa1394_thr_clear_req(scsa1394_thread_t *, int);
315 312 void scsa1394_cmd_status_proc(scsa1394_lun_t *, scsa1394_cmd_t *);
316 313 boolean_t scsa1394_dev_is_online(scsa1394_state_t *);
317 314 void scsa1394_sbp2_req_bus_reset(scsa1394_lun_t *);
318 315 void scsa1394_sbp2_req_reconnect(scsa1394_lun_t *);
319 316
320 317
321 318 #ifdef __cplusplus
322 319 }
323 320 #endif
324 321
325 322 #endif /* _SYS_1394_TARGETS_SCSA1394_IMPL_H */
↓ open down ↓ |
125 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX