Print this page
10805 Fix for 10687 can be improved
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/usb/scsa2usb/scsa2usb.h
+++ new/usr/src/uts/common/sys/usb/scsa2usb/scsa2usb.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 *
19 19 * CDDL HEADER END
20 20 *
21 21 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
22 22 * Use is subject to license terms.
23 23 *
24 24 * Copyright 2019, Joyent, Inc.
25 25 */
26 26
27 27 #ifndef _SYS_USB_SCSA2USB_H
28 28 #define _SYS_USB_SCSA2USB_H
29 29
30 30
31 31 #ifdef __cplusplus
32 32 extern "C" {
33 33 #endif
34 34
35 35 #include <sys/usb/usba/usbai_private.h>
36 36
37 37 /*
38 38 * SCSA2USB: This header file contains the internal structures
39 39 * and variable definitions used in USB mass storage disk driver.
40 40 */
41 41
42 42
43 43 #define SCSA2USB_MAX_CLONE 256
44 44 #define SCSA2USB_INITIAL_ALLOC 4 /* initial soft space alloc */
45 45
46 46 #define MAX_COMPAT_NAMES 1 /* max compatible names for children */
47 47 #define SERIAL_NUM_LEN 64 /* for reading string descriptor */
48 48 #define SCSA2USB_SERIAL_LEN 12 /* len of serial no in scsi_inquiry */
49 49
50 50 #define SCSA2USB_MAX_LUNS 0x10 /* maximum luns supported. */
51 51
52 52 /*
53 53 * limit the max transfer size to under <= 64K. Some devices
54 54 * have problems with large transfers
55 55 */
56 56 #define SCSA2USB_MAX_BULK_XFER_SIZE (64 * 1024)
57 57
58 58 /* Blacklist some vendors whose devices could cause problems */
59 59 #define MS_HAGIWARA_SYS_COM_VID 0x693 /* VendorId of Hagiwara Sys-Com */
60 60 #define MS_HAGIWARA_SYSCOM_PID1 0x1 /* PID for SmartMedia(SM) device */
61 61 #define MS_HAGIWARA_SYSCOM_PID2 0x3 /* PID for CompactFlash(CF) device */
62 62 #define MS_HAGIWARA_SYSCOM_PID3 0x5 /* PID for SM/CF Combo device */
63 63 #define MS_HAGIWARA_SYSCOM_PID4 0x2 /* PID for new SM device */
64 64 #define MS_HAGIWARA_SYSCOM_PID5 0x4 /* PID for new CF device */
65 65
66 66 #define MS_IOMEGA_VID 0x59b /* VendorId of Iomega */
67 67 #define MS_IOMEGA_PID1_ZIP100 0x1 /* PID of an Older Iomega Zip100 */
68 68 #define MS_IOMEGA_PID2_ZIP100 0x2 /* PID of Newer Iomega Zip100 */
69 69 #define MS_IOMEGA_PID3_ZIP100 0x31 /* PID of Newer Iomega Zip100 */
70 70 #define MS_IOMEGA_PID_ZIP250 0x30 /* PID of Newer Iomega Zip250 */
71 71 #define MS_IOMEGA_PID_CLIK 0x60 /* PID of Iomega Clik! drive */
72 72
73 73 #define MS_MITSUMI_VID 0x3ee /* VendorId of Mitsumi Inc */
74 74 #define MS_MITSUMI_DEVICE_242 0x242 /* bcdDevice of Mitsumi CR-4804TU */
75 75 #define MS_MITSUMI_DEVICE_24 0x24 /* bcdDevice of Mitsumi CR-4802TU */
76 76
77 77 #define MS_YEDATA_VID 0x57b /* VendorId of Y-E Data Corp */
78 78 #define MS_SMSC_VID 0x424 /* Vendor Id of SMSC */
79 79 #define MS_SMSC_PID0 0xfdc /* floppy from SMSC */
80 80
81 81 #define MS_NEODIO_VID 0xaec /* Neodio Technologies Corporation */
82 82 #define MS_NEODIO_DEVICE_3050 0x3050 /* PID of ND3050/Soyo BayOne */
83 83 /* SM/CF/MS/SD */
84 84 #define MS_SONY_FLASH_VID 0x54c /* sony flash device */
85 85 #define MS_SONY_FLASH_PID 0x8b
86 86
87 87 #define MS_TREK_FLASH_VID 0xa16 /* Trek flash device */
88 88 #define MS_TREK_FLASH_PID 0x9988
89 89
90 90 #define MS_PENN_FLASH_VID 0xd7d /* Penn flash device */
91 91 #define MS_PENN_FLASH_PID 0x1320
92 92
93 93 #define MS_SIMPLETECH_VID 0x7c4 /* VendorId of Simpltech */
94 94 #define MS_SIMPLETECH_PID1 0xa400 /* PID for UCF-100 device */
95 95
96 96 #define MS_ADDONICS_CARD_READER_VID 0x7cc /* addonics */
97 97 #define MS_ADDONICS_CARD_READER_PID 0x320
98 98
99 99 #define MS_ACOMDATA_VID 0xc0b /* VendorId of DMI (Acomdata) */
100 100 #define MS_ACOMDATA_PID1 0x5fab /* PID for 80GB USB/1394 disk */
101 101
102 102 #define MS_OTI_VID 0xea0 /* VendorID of OTI */
103 103 #define MS_OTI_DEVICE_6828 0x6828 /* PID for 6828 flash disk */
104 104
105 105 #define MS_SCANLOGIC_VID 0x04ce /* VendorID of ScanLogic */
106 106 #define MS_SCANLOGIC_PID1 0x0002 /* SL USB Storage Device */
107 107
108 108 #define MS_SUPERTOP_VID 0x14cd /* Super Top USB 2.0 IDE enclosure */
109 109 #define MS_SUPERTOP_DEVICE_6600 0x6600
110 110
111 111 #define MS_AIGO_VID 0xed1 /* VendorID of Aigo */
112 112 #define MS_AIGO_DEVICE_6981 0x6981 /* Aigo Miniking Device NEHFSP14 */
113 113
114 114 #define MS_ALCOR_VID 0x58f /* Vendor ID of Alcor Micro Corp */
115 115 #define MS_ALCOR_PID0 0x6387 /* PID for 6387 flash disk */
116 116
117 117 #define MS_TOSHIBA_VID 0x930 /* Vendor ID of Toshiba Corp */
118 118 #define MS_TOSHIBA_PID0 0x6545 /* Kingston DataTraveler / PNY Attache Stick */
119 119
120 120 #define MS_PNY_VID 0x154b /* Vendor ID of PNY Corp */
121 121 #define MS_PNY_PID0 0x16 /* PNY floppy drive */
122 122
123 123 #define MS_WD_VID 0x1058 /* Vendor ID of Western Digital */
124 124 #define MS_WD_PID 0x1001 /* PID for Western Digital USB External HDD */
125 125
126 126 /*
127 127 * The AMI virtual floppy device is not a real USB storage device, but
128 128 * emulated by the SP firmware shipped together with important Sun x86
129 129 * products such as Galaxy and Thumper platforms. The device causes
130 130 * very long delay in boot process of these platforms which is a big
131 131 * performance issue. Improvement in firmware may solve the issue, but
132 132 * before the firmware is fixed, it needs to be taken care of by software
133 133 * to avoid the huge impact on user experience.
134 134 *
135 135 * The long boot delay is caused by timeouts and retries of READ CAPACITY
136 136 * command issued to the device. The device is a USB ufi subclass device
137 137 * using CBI protocol. When READ CAPACITY command is issued, the device
138 138 * returns STALL on the bulk endpoint during the data stage, however, it
139 139 * doesn't return status on the intr pipe during status stage, so the intr
140 140 * pipe can only fail with timeout.
141 141 *
142 142 * Reducing timeout value to 1 second can help a little bit, but the delay
143 143 * is still noticeable, because the target driver would make many retries
144 144 * for this command. It is not desirable to mess with the target driver
145 145 * for a broken USB device. So adding the device to the scsa2usb blacklist
146 146 * is the best choice we have.
147 147 *
148 148 * It is found that the READ CAPACITY failure only happens when there is
149 149 * no media in the floppy drive. When there is a media, the device works
150 150 * just fine. So READ CAPACITY command cannot be arbitrarily disabled.
151 151 * Media status needs to be checked before issuing the command by sending
152 152 * an additional TEST UNIT READY command. If TEST UNIT READY command
153 153 * return STATUS_GOOD, it means the media is ready and then READ CAPACITY
154 154 * can be issued.
155 155 *
156 156 * SCSA2USB_ATTRS_NO_MEDIA_CHECK is added below for this purpose. It is
157 157 * overrided in scsa2usb.c for the AMI virtual floppy device to take care
158 158 * of the special need.
159 159 */
160 160 #define MS_AMI_VID 0x46b /* VendorId of AMI */
161 161 #define MS_AMI_VIRTUAL_FLOPPY 0xff40 /* PID for AMI virtual floppy */
162 162
163 163 /*
164 164 * List the attributes that need special case in the driver
165 165 * SCSA2USB_ATTRS_GET_LUN: Bulk Only Transport Get_Max_Lun class specific
166 166 * command is not implemented by these devices
167 167 * SCSA2USB_ATTRS_PM: Some devices don't like being power managed.
168 168 * SCSA2USB_ATTRS_START_STOP: Some devices don't do anything with
169 169 * SCMD_START_STOP opcode (for e.g. SmartMedia/CompactFlash/
170 170 * Clik!/MemoryStick/MMC USB readers/writers.
171 171 * SCSA2USB_ATTRS_GET_CONF: SCMD_GET_CONFIGURATION is not supported
172 172 * SCMD_TEST_UNIT_READY: for floppies this needs to be converted to
173 173 * SCMD_START_STOP as floppies don't support this
174 174 * SCSA2USB_ATTRS_GET_PERF: SCMD_GET_PERFORMANCE not supported by
175 175 * Mitsumi's CD-RW devices.
176 176 * SCSA2USB_ATTRS_BIG_TIMEOUT: Mitsumi's CD-RW devices need large
177 177 * timeout with SCMD_START_STOP cmd
178 178 * SCSA2USB_ATTRS_RMB: Pay attention to the device's RMB setting,
179 179 * instead of automatically treating it as removable
180 180 * SCSA2USB_ATTRS_USE_CSW_RESIDUE: Some devices report false residue in
181 181 * the CSW of bulk-only transfer status stage though data
182 182 * was successfully transfered, so need to ignore residue.
183 183 * SCSA2USB_ATTRS_NO_MEDIA_CHECK: AMI Virtual Floppy devices need to
184 184 * check if media is ready before issuing READ CAPACITY.
185 185 * SCSA2USB_ATTRS_NO_CAP_ADJUST: Some devices return total logical block number
186 186 * instead of highest logical block address on READ_CAPACITY cmd.
187 187 *
188 188 * NOTE: If a device simply STALLs the GET_MAX_LUN BO class-specific command
189 189 * and recovers then it will not be added to the scsa2usb_blacklist[] table
190 190 * in scsa2usb.c. The other attributes will not be taken of the table unless
191 191 * their inclusion causes a recovery and retries (thus seriously affecting
192 192 * the driver performance).
193 193 */
194 194 #define SCSA2USB_ATTRS_GET_LUN 0x01 /* GET_MAX_LUN (Bulk Only) */
195 195 #define SCSA2USB_ATTRS_PM 0x02 /* Some don't support PM */
196 196 #define SCSA2USB_ATTRS_START_STOP 0x04 /* SCMD_START_STOP */
197 197 #define SCSA2USB_ATTRS_GET_CONF 0x08 /* SCMD_GET_CONFIGURATION */
198 198 #define SCSA2USB_ATTRS_GET_PERF 0x10 /* SCMD_GET_PERFORMANCE */
199 199 #define SCSA2USB_ATTRS_BIG_TIMEOUT 0x40 /* for SCMD_START_STOP */
200 200 #define SCSA2USB_ATTRS_DOORLOCK 0x80 /* for SCMD_DOORLOCK */
201 201 #define SCSA2USB_ATTRS_RMB 0x100 /* Pay attention to RMB */
202 202 #define SCSA2USB_ATTRS_MODE_SENSE 0x200 /* SCMD_MODE_SENSE */
203 203 #define SCSA2USB_ATTRS_INQUIRY 0x400 /* SCMD_INQUIRY */
204 204 #define SCSA2USB_ATTRS_USE_CSW_RESIDUE 0x800 /* for residue checking */
205 205 #define SCSA2USB_ATTRS_NO_MEDIA_CHECK 0x1000 /* for media checking */
206 206 #define SCSA2USB_ATTRS_NO_CAP_ADJUST 0x2000 /* for CAPACITY adjusting */
207 207 #define SCSA2USB_ATTRS_INQUIRY_EVPD 0x4000 /* SCMD_INQUIRY with evpd */
208 208 #define SCSA2USB_ATTRS_REDUCED_CMD \
209 209 (SCSA2USB_ATTRS_DOORLOCK|SCSA2USB_ATTRS_MODE_SENSE| \
210 210 SCSA2USB_ATTRS_START_STOP|SCSA2USB_ATTRS_INQUIRY| \
211 211 SCSA2USB_ATTRS_USE_CSW_RESIDUE)
212 212
213 213 #define SCSA2USB_ALL_ATTRS 0xFFFF /* All of the above */
214 214
215 215 /* max inquiry length */
216 216 #define SCSA2USB_MAX_INQ_LEN (offsetof(struct scsi_inquiry, inq_serial))
217 217
218 218 /* page code of scsi mode page */
219 219 #ifndef SD_MODE_SENSE_PAGE3_CODE
220 220 #define SD_MODE_SENSE_PAGE3_CODE 0x03
221 221 #endif
222 222
223 223 #ifndef SD_MODE_SENSE_PAGE4_CODE
224 224 #define SD_MODE_SENSE_PAGE4_CODE 0x04
225 225 #endif
226 226
227 227 #define SD_MODE_SENSE_PAGE_MASK 0x3F
228 228
229 229 /*
230 230 * PM support
231 231 */
232 232 typedef struct scsa2usb_power {
233 233 /* device busy accounting */
234 234 int scsa2usb_pm_busy;
235 235 /* this is the bit mask of the power states that device has */
236 236 uint8_t scsa2usb_pwr_states;
237 237
238 238 uint8_t scsa2usb_wakeup_enabled;
239 239
240 240 /* current power level the device is in */
241 241 uint8_t scsa2usb_current_power;
242 242 } scsa2usb_power_t;
243 243
244 244 /*
245 245 * CPR support:
246 246 * keep track of the last command issued to the drive. If it
247 247 * was TUR or EJECT then allow issuing a CPR suspend.
248 248 */
249 249 #define LOEJECT 2 /* eject bit in start/stop cmd */
250 250
251 251 typedef struct scsa2usb_last_cmd {
252 252 /* this is the cdb of the last command issued */
253 253 uchar_t cdb[SCSI_CDB_SIZE];
254 254
255 255 /* this is the status of the last command issued */
256 256 uint_t status;
257 257 } scsa2usb_last_cmd_t;
258 258
259 259 /*
260 260 * override values
261 261 * These values may be set in scsa2usb.conf for particular devices
262 262 */
263 263 typedef struct scsa2usb_ov {
264 264 int vid; /* vendor id */
265 265 int pid; /* product id */
266 266 int rev; /* revision */
267 267 int subclass; /* subclass override */
268 268 int protocol; /* protocol override */
269 269 int pmoff; /* power management override */
270 270 int fake_removable; /* removable device override */
271 271 int no_modesense; /* no mode sense */
272 272 /* no modesense, doorlock, PM, start/stop */
273 273 int reduced_cmd_support;
274 274 } scsa2usb_ov_t;
275 275
276 276
277 277 /*
278 278 * Per bulk device "state" data structure.
279 279 */
280 280 typedef struct scsa2usb_state {
281 281 int scsa2usb_instance; /* Instance number */
282 282 int scsa2usb_dev_state; /* USB device state */
283 283 int scsa2usb_flags; /* Per instance flags */
284 284 int scsa2usb_intfc_num; /* Interface number */
285 285 dev_info_t *scsa2usb_dip; /* Per device. info */
286 286 scsa2usb_power_t *scsa2usb_pm; /* PM state info */
287 287
288 288 int scsa2usb_transport_busy; /* ugen/sd traffic */
289 289 int scsa2usb_ugen_open_count;
290 290 kcondvar_t scsa2usb_transport_busy_cv;
291 291 struct proc *scsa2usb_busy_proc; /* owner of the hardware */
292 292
293 293 kmutex_t scsa2usb_mutex; /* Per instance lock */
294 294
295 295 struct scsi_hba_tran *scsa2usb_tran; /* SCSI transport ptr */
296 296 struct scsi_pkt *scsa2usb_cur_pkt; /* SCSI packet ptr */
297 297
298 298 usba_list_entry_t scsa2usb_waitQ[SCSA2USB_MAX_LUNS];
299 299 /* waitQ list */
300 300 struct scsa2usb_cmd *scsa2usb_arq_cmd; /* ARQ cmd */
301 301 struct buf *scsa2usb_arq_bp; /* ARQ buf */
302 302
303 303 dev_info_t *scsa2usb_lun_dip[SCSA2USB_MAX_LUNS];
304 304 /* store devinfo per LUN */
305 305 struct scsi_inquiry scsa2usb_lun_inquiry[SCSA2USB_MAX_LUNS];
306 306 /* store inquiry per LUN */
307 307 usb_if_descr_t scsa2usb_intfc_descr; /* Interface descr */
308 308 usb_ep_xdescr_t scsa2usb_bulkin_xept; /* Bulk In descriptor */
309 309 usb_ep_xdescr_t scsa2usb_bulkout_xept; /* Bulkout descriptor */
310 310 usb_ep_xdescr_t scsa2usb_intr_xept; /* Intr ept descr */
311 311
312 312 usb_pipe_handle_t scsa2usb_default_pipe; /* Default pipe Hndle */
313 313 usb_pipe_handle_t scsa2usb_intr_pipe; /* Intr polling Hndle */
314 314 usb_pipe_handle_t scsa2usb_bulkin_pipe; /* Bulk Inpipe Handle */
315 315 usb_pipe_handle_t scsa2usb_bulkout_pipe; /* Bulk Outpipe Hndle */
316 316
317 317 uint_t scsa2usb_pipe_state; /* resetting state */
318 318 uint_t scsa2usb_tag; /* current tag */
319 319 uint_t scsa2usb_pkt_state; /* packet state */
320 320 uint_t scsa2usb_n_luns; /* number of luns */
321 321
322 322 usb_log_handle_t scsa2usb_log_handle; /* log handle */
323 323 struct scsa2usb_cpr *scsa2usb_panic_info; /* for cpr info */
324 324
325 325 size_t scsa2usb_lbasize[SCSA2USB_MAX_LUNS];
326 326 /* sector size */
327 327 size_t scsa2usb_totalsec[SCSA2USB_MAX_LUNS];
328 328 /* total sectors */
329 329 size_t scsa2usb_secsz[SCSA2USB_MAX_LUNS];
330 330 /* sector size */
331 331 size_t scsa2usb_max_bulk_xfer_size; /* from HCD */
332 332
333 333 usb_client_dev_data_t *scsa2usb_dev_data; /* USB registration */
334 334 scsa2usb_last_cmd_t scsa2usb_last_cmd; /* last/prev command */
335 335
336 336 uint_t scsa2usb_attrs; /* for bad devices */
337 337 uint_t scsa2usb_cmd_protocol; /* CMD protocol used */
338 338 kthread_t *scsa2usb_work_thread_id; /* handle commands */
339 339
340 340 /* conf file override values */
341 341 uint_t scsa2usb_subclass_override;
342 342 uint_t scsa2usb_protocol_override;
343 343 char *scsa2usb_override_str;
344 344
345 345 /* suppress repetitive disconnect warnings */
346 346 boolean_t scsa2usb_warning_given;
347 347
348 348 boolean_t scsa2usb_rcvd_not_ready; /* received NOT */
349 349 /* READY sense data */
350 350
351 351 usb_ugen_hdl_t scsa2usb_ugen_hdl; /* ugen support */
352 352
353 353 uint8_t scsa2usb_clones[SCSA2USB_MAX_CLONE];
354 354 } scsa2usb_state_t;
355 355
356 356 /*
357 357 * These macros were added as part of updating scsa2usb to support USB 3.0 and
358 358 * newer devices to minimize driver changes. There's no reason these can't be
359 359 * expanded by someone who wants to.
360 360 */
361 361 #define scsa2usb_bulkin_ept scsa2usb_bulkin_xept.uex_ep
362 362 #define scsa2usb_bulkout_ept scsa2usb_bulkout_xept.uex_ep
363 363 #define scsa2usb_intr_ept scsa2usb_intr_xept.uex_ep
364 364
365 365
366 366 /* for warlock */
367 367 _NOTE(MUTEX_PROTECTS_DATA(scsa2usb_state::scsa2usb_mutex, scsa2usb_state))
368 368 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_instance))
369 369 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_dip))
370 370 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_arq_cmd))
371 371 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_arq_bp))
372 372 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intr_ept))
373 373 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_default_pipe))
374 374 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intr_pipe))
375 375 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_bulkin_pipe))
376 376 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_log_handle))
377 377 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_intfc_num))
378 378 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_dev_data))
379 379 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_ugen_hdl))
380 380 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_state::scsa2usb_pm))
381 381 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsa2usb_power_t))
382 382 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_hba_tran_t))
383 383 _NOTE(SCHEME_PROTECTS_DATA("unshared data", usb_bulk_req_t))
384 384
385 385 /* scsa2usb_pipe_state values */
386 386 #define SCSA2USB_PIPE_NORMAL 0x00 /* no reset or clearing */
387 387 #define SCSA2USB_PIPE_CLOSING 0x01 /* closing all pipes */
388 388 #define SCSA2USB_PIPE_DEV_RESET 0x02 /* device specific reset */
389 389
390 390 /* pkt xfer state machine */
391 391 #define SCSA2USB_PKT_NONE 0 /* device is idle */
392 392 #define SCSA2USB_PKT_PROCESS_CSW 1 /* device doing status again */
393 393 #define SCSA2USB_PKT_DO_COMP 2 /* device is done xfer */
394 394
395 395 /* scsa2usb_flags values */
396 396 #define SCSA2USB_FLAGS_PIPES_OPENED 0x001 /* usb pipes are open */
397 397 #define SCSA2USB_FLAGS_HBA_ATTACH_SETUP 0x002 /* scsi hba setup done */
398 398 #define SCSA2USB_FLAGS_LOCKS_INIT 0x004 /* basic inits done */
399 399
400 400 /* scsa2usb_cmd_protocol values */
401 401 #define SCSA2USB_UNKNOWN_PROTOCOL 0x0000 /* unknown wire protocol */
402 402 #define SCSA2USB_CB_PROTOCOL 0x0001 /* CBI wire protocol */
403 403 #define SCSA2USB_CBI_PROTOCOL 0x0002 /* CBI w/ intr wire protocol */
404 404 #define SCSA2USB_BULK_ONLY_PROTOCOL 0x0004 /* Bulk Only wire protocol */
405 405
406 406 #define SCSA2USB_SCSI_CMDSET 0x1000 /* SCSI command set followed */
407 407 #define SCSA2USB_ATAPI_CMDSET 0x2000 /* ATAPI command set followed */
408 408 #define SCSA2USB_UFI_CMDSET 0x4000 /* UFI command set followed */
409 409 #define SCSA2USB_CMDSET_MASK 0x7000 /* OR al the above */
410 410
411 411 #define SCSA2USB_IS_UFI_CMDSET(s) \
412 412 (((s)->scsa2usb_cmd_protocol & SCSA2USB_UFI_CMDSET))
413 413 #define SCSA2USB_IS_SCSI_CMDSET(s) \
414 414 (((s)->scsa2usb_cmd_protocol & SCSA2USB_SCSI_CMDSET))
415 415 #define SCSA2USB_IS_ATAPI_CMDSET(s) \
416 416 (((s)->scsa2usb_cmd_protocol & SCSA2USB_ATAPI_CMDSET))
417 417
418 418 #define SCSA2USB_IS_CB(s) \
419 419 (((s)->scsa2usb_cmd_protocol & SCSA2USB_CB_PROTOCOL))
420 420
421 421 #define SCSA2USB_IS_CBI(s) \
422 422 (((s)->scsa2usb_cmd_protocol & SCSA2USB_CBI_PROTOCOL))
423 423
424 424 #define SCSA2USB_IS_BULK_ONLY(s) \
425 425 (((s)->scsa2usb_cmd_protocol & SCSA2USB_BULK_ONLY_PROTOCOL))
426 426
427 427 /* check if it is ok to access the device and send command to it */
428 428 #define SCSA2USB_DEVICE_ACCESS_OK(s) \
429 429 ((s)->scsa2usb_dev_state == USB_DEV_ONLINE)
430 430
431 431 /* check if we are in any reset */
432 432 #define SCSA2USB_IN_RESET(s) \
433 433 (((s)->scsa2usb_pipe_state & SCSA2USB_PIPE_DEV_RESET) != 0)
434 434
435 435 /* check if the device is busy */
436 436 #define SCSA2USB_BUSY(s) \
437 437 (((s)->scsa2usb_cur_pkt) || \
438 438 ((s)->scsa2usb_pipe_state != SCSA2USB_PIPE_NORMAL) || \
439 439 ((s)->scsa2usb_pkt_state != SCSA2USB_PKT_NONE))
440 440
441 441 /* check if we're doing cpr */
442 442 #define SCSA2USB_CHK_CPR(s) \
443 443 (((s)->scsa2usb_dev_state == USB_DEV_SUSPENDED))
444 444
445 445 /* check if we're either paniced or in cpr state */
446 446 #define SCSA2USB_CHK_PANIC_CPR(s) \
447 447 (ddi_in_panic() || SCSA2USB_CHK_CPR(s))
448 448
449 449 /* reset scsa2usb state after pkt_comp is called */
450 450 #define SCSA2USB_RESET_CUR_PKT(s) \
451 451 (s)->scsa2usb_cur_pkt = NULL; \
452 452 (s)->scsa2usb_pkt_state = SCSA2USB_PKT_NONE;
453 453
454 454 /* print a panic sync message to the console */
455 455 #define SCSA2USB_PRINT_SYNC_MSG(m, s) \
456 456 if ((m) == B_TRUE) { \
457 457 USB_DPRINTF_L1(DPRINT_MASK_SCSA, (s)->scsa2usb_log_handle, \
458 458 "syncing not supported"); \
459 459 (m) = B_FALSE; \
460 460 }
461 461
462 462 /* Cancel callbacks registered during attach time */
463 463 #define SCSA2USB_CANCEL_CB(id) \
464 464 if ((id)) { \
465 465 (void) callb_delete((id)); \
466 466 (id) = 0; \
467 467 }
468 468
469 469 /* Set SCSA2USB_PKT_DO_COMP state if there is active I/O */
470 470 #define SCSA2USB_SET_PKT_DO_COMP_STATE(s) \
471 471 if ((s)->scsa2usb_cur_pkt) { \
472 472 (s)->scsa2usb_pkt_state = SCSA2USB_PKT_DO_COMP; \
473 473 }
474 474
475 475 #define SCSA2USB_FREE_MSG(data) \
476 476 if ((data)) { \
477 477 freemsg((data)); \
478 478 }
479 479
480 480 #define SCSA2USB_FREE_BULK_REQ(req) \
481 481 if ((req)) { \
482 482 usb_free_bulk_req((req)); /* Free request */ \
483 483 }
484 484
485 485
486 486 /* SCSA related */
487 487 #define ADDR2TRAN(ap) ((ap)->a_hba_tran)
488 488 #define TRAN2SCSA2USB(tran) ((scsa2usb_state_t *)(tran)->tran_hba_private)
489 489 #define ADDR2SCSA2USB(ap) (TRAN2SCSA2USB(ADDR2TRAN(ap)))
490 490
491 491 #define PKT_PRIV_LEN 16
492 492
493 493 #define PKT_DEFAULT_TIMEOUT 5
494 494
495 495 /*
496 496 * auto request sense
497 497 */
498 498 #define RQ_MAKECOM_COMMON(pktp, flag, cmd) \
499 499 (pktp)->pkt_flags = (flag), \
500 500 ((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_cmd = (cmd), \
501 501 ((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_lun = \
502 502 (pktp)->pkt_address.a_lun
503 503
504 504 #define RQ_MAKECOM_G0(pktp, flag, cmd, addr, cnt) \
505 505 RQ_MAKECOM_COMMON((pktp), (flag), (cmd)), \
506 506 FORMG0ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \
507 507 FORMG0COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt))
508 508
509 509
510 510 /* transport related */
511 511 #define SCSA2USB_JUST_ACCEPT 0
512 512 #define SCSA2USB_TRANSPORT 1
513 513 #define SCSA2USB_REJECT -1
514 514
515 515 /*
516 516 * The scsa2usb_cpr_info data structure is used for cpr related
517 517 * callbacks. It is used for panic callbacks as well.
518 518 */
519 519 typedef struct scsa2usb_cpr {
520 520 callb_cpr_t cpr; /* for cpr related info */
521 521 struct scsa2usb_state *statep; /* for scsa2usb state info */
522 522 kmutex_t lockp; /* mutex used by cpr_info_t */
523 523 } scsa2usb_cpr_t;
524 524
525 525 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_cpr_t::cpr))
526 526 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsa2usb_cpr_t::statep))
527 527
528 528 /*
529 529 * The scsa2usb_cmd data structure is defined here. It gets
530 530 * initialized per command that is sent to the device.
531 531 */
532 532 typedef struct scsa2usb_cmd {
533 533 struct scsi_pkt *cmd_pkt; /* copy of pkt ptr */
534 534 struct buf *cmd_bp; /* copy of bp ptr */
535 535 size_t cmd_xfercount; /* current xfer count */
536 536 size_t cmd_resid_xfercount; /* last xfer resid */
537 537 int cmd_scblen; /* status length */
538 538 int cmd_tag; /* tag */
539 539 int cmd_timeout; /* copy of pkt_time */
540 540 uchar_t cmd_cdb[SCSI_CDB_SIZE]; /* CDB */
541 541 uchar_t cmd_dir; /* direction */
542 542 uchar_t cmd_actual_len; /* cdb len */
543 543 uchar_t cmd_cdblen; /* requested cdb len */
544 544 struct scsi_arq_status cmd_scb; /* status, w/ arq */
545 545
546 546 /* used in multiple xfers */
547 547 size_t cmd_total_xfercount; /* total xfer val */
548 548 size_t cmd_offset; /* offset into buf */
549 549 int cmd_lba; /* current xfer lba */
550 550 int cmd_done; /* command done? */
551 551 int cmd_blksize; /* block size */
552 552 usba_list_entry_t cmd_waitQ; /* waitQ element */
553 553 } scsa2usb_cmd_t;
554 554
555 555 /* for warlock */
556 556 _NOTE(SCHEME_PROTECTS_DATA("unique per packet or safe sharing",
557 557 scsi_cdb scsi_status scsi_pkt buf scsa2usb_cmd scsi_arq_status))
558 558 _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_device scsi_address))
559 559
560 560 /* scsa2usb_cdb position of fields in CDB */
561 561 #define SCSA2USB_OPCODE 0 /* Opcode field */
562 562 #define SCSA2USB_LUN 1 /* LUN field */
563 563 #define SCSA2USB_LBA_0 2 /* LBA[0] field */
564 564 #define SCSA2USB_LBA_1 3 /* LBA[1] field */
565 565 #define SCSA2USB_LBA_2 4 /* LBA[2] field */
566 566 #define SCSA2USB_LBA_3 5 /* LBA[3] field */
567 567 #define SCSA2USB_LEN_0 7 /* LEN[0] field */
568 568 #define SCSA2USB_LEN_1 8 /* LEN[1] field */
569 569
570 570 /* macros to calculate LBA for 6/10/12-byte commands */
571 571 #define SCSA2USB_LBA_6BYTE(pkt) \
572 572 (((pkt)->pkt_cdbp[1] & 0x1f) << 16) + \
573 573 ((pkt)->pkt_cdbp[2] << 8) + (pkt)->pkt_cdbp[3]
574 574 #define SCSA2USB_LEN_6BYTE(pkt) (pkt)->pkt_cdbp[4]
575 575
576 576 #define SCSA2USB_LEN_10BYTE(pkt) \
577 577 ((pkt)->pkt_cdbp[7] << 8) + (pkt)->pkt_cdbp[8]
578 578 #define SCSA2USB_LBA_10BYTE(pkt) \
579 579 ((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \
580 580 ((pkt)->pkt_cdbp[4] << 8) + (pkt)->pkt_cdbp[5]
581 581
582 582 #define SCSA2USB_LEN_12BYTE(pkt) \
583 583 ((pkt)->pkt_cdbp[6] << 24) + ((pkt)->pkt_cdbp[7] << 16) + \
584 584 ((pkt)->pkt_cdbp[8] << 8) + (pkt)->pkt_cdbp[9]
585 585 #define SCSA2USB_LBA_12BYTE(pkt) \
586 586 ((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + \
587 587 ((pkt)->pkt_cdbp[4] << 8) + (pkt)->pkt_cdbp[5]
588 588
589 589 /* macros to convert a pkt to cmd and vice-versa */
590 590 #define PKT2CMD(pkt) ((scsa2usb_cmd_t *)(pkt)->pkt_ha_private)
591 591 #define CMD2PKT(sp) ((sp)->cmd_pkt
592 592
593 593 /* bulk pipe default timeout value - how long the command to be tried? */
594 594 #define SCSA2USB_BULK_PIPE_TIMEOUT (2 * USB_PIPE_TIMEOUT)
595 595
596 596 /* drain timeout in seconds on the work thread */
597 597 #define SCSA2USB_DRAIN_TIMEOUT 60
598 598
599 599 /* scsa2usb pkt xfer status phase retry times */
600 600 #define SCSA2USB_STATUS_RETRIES 3
601 601
602 602 /*
603 603 * limit on the number of requests that can be queued per LUN:
604 604 * 3 for untagged queueing, 1 for scsiwatch and a margin of 2
605 605 */
606 606 #define SCSA2USB_MAX_REQ_PER_LUN 6
607 607
608 608 /*
609 609 * The following data structure is used to save the values returned
610 610 * by the READ_CAPACITY command. lba is the max allowed logical block
611 611 * address and blen is max allowed block size.
612 612 */
613 613 typedef struct scsa2usb_read_cap {
614 614 uchar_t scsa2usb_read_cap_lba3; /* Max lba supported */
615 615 uchar_t scsa2usb_read_cap_lba2;
616 616 uchar_t scsa2usb_read_cap_lba1;
617 617 uchar_t scsa2usb_read_cap_lba0;
618 618 uchar_t scsa2usb_read_cap_blen3; /* Max block size supported */
619 619 uchar_t scsa2usb_read_cap_blen2;
620 620 uchar_t scsa2usb_read_cap_blen1;
621 621 uchar_t scsa2usb_read_cap_blen0;
622 622 } scsa2usb_read_cap_t;
623 623
624 624 #define SCSA2USB_MK_32BIT(a, b, c, d) \
625 625 (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
626 626
627 627 /* position of fields for SCMD_READ_CD CDB */
628 628 #define SCSA2USB_READ_CD_LEN_0 6 /* LEN[0] of SCMD_READ_CD */
629 629 #define SCSA2USB_READ_CD_LEN_1 7 /* LEN[1] of SCMD_READ_CD */
630 630 #define SCSA2USB_READ_CD_LEN_2 8 /* LEN[2] of SCMD_READ_CD */
631 631
632 632 /* macro to calculate LEN for SCMD_READ_CD command */
633 633 #define SCSA2USB_LEN_READ_CD(pkt) \
634 634 (((pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_0] << 16) +\
635 635 ((pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_1] << 8) +\
636 636 (pkt)->pkt_cdbp[SCSA2USB_READ_CD_LEN_2])
637 637
638 638 /* Figure out Block Size before issuing a WRITE to CD-RW device */
639 639 #define SCSA2USB_CDRW_BLKSZ(bcount, len) ((bcount) / (len));
640 640 #define SCSA2USB_VALID_CDRW_BLKSZ(blksz) \
641 641 (((blksz) == CDROM_BLK_2048) || ((blksz) == CDROM_BLK_2352) || \
642 642 ((blksz) == CDROM_BLK_2336) || ((blksz) == CDROM_BLK_2324) || \
643 643 ((blksz) == 0))
644 644
645 645 /* debug and error msg logging */
646 646 #define DPRINT_MASK_SCSA 0x0001 /* for SCSA */
647 647 #define DPRINT_MASK_ATTA 0x0002 /* for ATTA */
↓ open down ↓ |
647 lines elided |
↑ open up ↑ |
648 648 #define DPRINT_MASK_EVENTS 0x0004 /* for event handling */
649 649 #define DPRINT_MASK_CALLBACKS 0x0008 /* for callbacks */
650 650 #define DPRINT_MASK_TIMEOUT 0x0010 /* for timeouts */
651 651 #define DPRINT_MASK_DUMPING 0x0020 /* for dumping */
652 652 #define DPRINT_MASK_PM 0x0040 /* for pwr mgmt */
653 653 #define DPRINT_MASK_ALL 0xffffffff /* for everything */
654 654
655 655 #ifdef DEBUG
656 656 #define SCSA2USB_PRINT_CDB scsa2usb_print_cdb
657 657 #else
658 -#define SCSA2USB_PRINT_CDB(...)
658 +#define SCSA2USB_PRINT_CDB(...) (void)(0)
659 659 #endif
660 660
661 661 /* ugen support */
662 662 #define SCSA2USB_MINOR_UGEN_BITS_MASK 0xff
663 663 #define SCSA2USB_MINOR_INSTANCE_MASK ~SCSA2USB_MINOR_UGEN_BITS_MASK
664 664 #define SCSA2USB_MINOR_INSTANCE_SHIFT 8
665 665
666 666 #define SCSA2USB_MINOR_TO_INSTANCE(minor) \
667 667 (((minor) & SCSA2USB_MINOR_INSTANCE_MASK) >> \
668 668 SCSA2USB_MINOR_INSTANCE_SHIFT)
669 669
670 670 #ifdef __cplusplus
671 671 }
672 672 #endif
673 673
674 674 #endif /* _SYS_USB_SCSA2USB_H */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX