aiclib.h 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  1. /*
  2. * Largely written by Julian Elischer (julian@tfs.com)
  3. * for TRW Financial Systems.
  4. *
  5. * TRW Financial Systems, in accordance with their agreement with Carnegie
  6. * Mellon University, makes this software available to CMU to distribute
  7. * or use in any manner that they see fit as long as this message is kept with
  8. * the software. For this reason TFS also grants any other persons or
  9. * organisations permission to use or modify this software.
  10. *
  11. * TFS supplies this software to be publicly redistributed
  12. * on the understanding that TFS is not responsible for the correct
  13. * functioning of this software in any circumstances.
  14. *
  15. * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
  16. *
  17. * $FreeBSD: src/sys/cam/scsi/scsi_all.h,v 1.21 2002/10/08 17:12:44 ken Exp $
  18. *
  19. * Copyright (c) 2003 Adaptec Inc.
  20. * All rights reserved.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the above copyright
  26. * notice, this list of conditions, and the following disclaimer,
  27. * without modification.
  28. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  29. * substantially similar to the "NO WARRANTY" disclaimer below
  30. * ("Disclaimer") and any redistribution must be conditioned upon
  31. * including a substantially similar Disclaimer requirement for further
  32. * binary redistribution.
  33. * 3. Neither the names of the above-listed copyright holders nor the names
  34. * of any contributors may be used to endorse or promote products derived
  35. * from this software without specific prior written permission.
  36. *
  37. * Alternatively, this software may be distributed under the terms of the
  38. * GNU General Public License ("GPL") version 2 as published by the Free
  39. * Software Foundation.
  40. *
  41. * NO WARRANTY
  42. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  43. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  45. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  46. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  47. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  48. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  49. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  50. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  51. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  52. * POSSIBILITY OF SUCH DAMAGES.
  53. *
  54. * $Id$
  55. */
  56. #ifndef _AICLIB_H
  57. #define _AICLIB_H
  58. /*
  59. * Linux Interrupt Support.
  60. */
  61. #ifndef IRQ_RETVAL
  62. typedef void irqreturn_t;
  63. #define IRQ_RETVAL(x)
  64. #endif
  65. /*
  66. * SCSI command format
  67. */
  68. /*
  69. * Define dome bits that are in ALL (or a lot of) scsi commands
  70. */
  71. #define SCSI_CTL_LINK 0x01
  72. #define SCSI_CTL_FLAG 0x02
  73. #define SCSI_CTL_VENDOR 0xC0
  74. #define SCSI_CMD_LUN 0xA0 /* these two should not be needed */
  75. #define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */
  76. #define SCSI_MAX_CDBLEN 16 /*
  77. * 16 byte commands are in the
  78. * SCSI-3 spec
  79. */
  80. /* 6byte CDBs special case 0 length to be 256 */
  81. #define SCSI_CDB6_LEN(len) ((len) == 0 ? 256 : len)
  82. /*
  83. * This type defines actions to be taken when a particular sense code is
  84. * received. Right now, these flags are only defined to take up 16 bits,
  85. * but can be expanded in the future if necessary.
  86. */
  87. typedef enum {
  88. SS_NOP = 0x000000, /* Do nothing */
  89. SS_RETRY = 0x010000, /* Retry the command */
  90. SS_FAIL = 0x020000, /* Bail out */
  91. SS_START = 0x030000, /* Send a Start Unit command to the device,
  92. * then retry the original command.
  93. */
  94. SS_TUR = 0x040000, /* Send a Test Unit Ready command to the
  95. * device, then retry the original command.
  96. */
  97. SS_REQSENSE = 0x050000, /* Send a RequestSense command to the
  98. * device, then retry the original command.
  99. */
  100. SS_INQ_REFRESH = 0x060000,
  101. SS_MASK = 0xff0000
  102. } aic_sense_action;
  103. typedef enum {
  104. SSQ_NONE = 0x0000,
  105. SSQ_DECREMENT_COUNT = 0x0100, /* Decrement the retry count */
  106. SSQ_MANY = 0x0200, /* send lots of recovery commands */
  107. SSQ_RANGE = 0x0400, /*
  108. * This table entry represents the
  109. * end of a range of ASCQs that
  110. * have identical error actions
  111. * and text.
  112. */
  113. SSQ_PRINT_SENSE = 0x0800,
  114. SSQ_DELAY = 0x1000, /* Delay before retry. */
  115. SSQ_DELAY_RANDOM = 0x2000, /* Randomized delay before retry. */
  116. SSQ_FALLBACK = 0x4000, /* Do a speed fallback to recover */
  117. SSQ_MASK = 0xff00
  118. } aic_sense_action_qualifier;
  119. /* Mask for error status values */
  120. #define SS_ERRMASK 0xff
  121. /* The default, retyable, error action */
  122. #define SS_RDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO
  123. /* The retyable, error action, with table specified error code */
  124. #define SS_RET SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
  125. /* Fatal error action, with table specified error code */
  126. #define SS_FATAL SS_FAIL|SSQ_PRINT_SENSE
  127. struct scsi_generic
  128. {
  129. uint8_t opcode;
  130. uint8_t bytes[11];
  131. };
  132. struct scsi_request_sense
  133. {
  134. uint8_t opcode;
  135. uint8_t byte2;
  136. uint8_t unused[2];
  137. uint8_t length;
  138. uint8_t control;
  139. };
  140. struct scsi_test_unit_ready
  141. {
  142. uint8_t opcode;
  143. uint8_t byte2;
  144. uint8_t unused[3];
  145. uint8_t control;
  146. };
  147. struct scsi_send_diag
  148. {
  149. uint8_t opcode;
  150. uint8_t byte2;
  151. #define SSD_UOL 0x01
  152. #define SSD_DOL 0x02
  153. #define SSD_SELFTEST 0x04
  154. #define SSD_PF 0x10
  155. uint8_t unused[1];
  156. uint8_t paramlen[2];
  157. uint8_t control;
  158. };
  159. struct scsi_sense
  160. {
  161. uint8_t opcode;
  162. uint8_t byte2;
  163. uint8_t unused[2];
  164. uint8_t length;
  165. uint8_t control;
  166. };
  167. struct scsi_inquiry
  168. {
  169. uint8_t opcode;
  170. uint8_t byte2;
  171. #define SI_EVPD 0x01
  172. uint8_t page_code;
  173. uint8_t reserved;
  174. uint8_t length;
  175. uint8_t control;
  176. };
  177. struct scsi_mode_sense_6
  178. {
  179. uint8_t opcode;
  180. uint8_t byte2;
  181. #define SMS_DBD 0x08
  182. uint8_t page;
  183. #define SMS_PAGE_CODE 0x3F
  184. #define SMS_VENDOR_SPECIFIC_PAGE 0x00
  185. #define SMS_DISCONNECT_RECONNECT_PAGE 0x02
  186. #define SMS_PERIPHERAL_DEVICE_PAGE 0x09
  187. #define SMS_CONTROL_MODE_PAGE 0x0A
  188. #define SMS_ALL_PAGES_PAGE 0x3F
  189. #define SMS_PAGE_CTRL_MASK 0xC0
  190. #define SMS_PAGE_CTRL_CURRENT 0x00
  191. #define SMS_PAGE_CTRL_CHANGEABLE 0x40
  192. #define SMS_PAGE_CTRL_DEFAULT 0x80
  193. #define SMS_PAGE_CTRL_SAVED 0xC0
  194. uint8_t unused;
  195. uint8_t length;
  196. uint8_t control;
  197. };
  198. struct scsi_mode_sense_10
  199. {
  200. uint8_t opcode;
  201. uint8_t byte2; /* same bits as small version */
  202. uint8_t page; /* same bits as small version */
  203. uint8_t unused[4];
  204. uint8_t length[2];
  205. uint8_t control;
  206. };
  207. struct scsi_mode_select_6
  208. {
  209. uint8_t opcode;
  210. uint8_t byte2;
  211. #define SMS_SP 0x01
  212. #define SMS_PF 0x10
  213. uint8_t unused[2];
  214. uint8_t length;
  215. uint8_t control;
  216. };
  217. struct scsi_mode_select_10
  218. {
  219. uint8_t opcode;
  220. uint8_t byte2; /* same bits as small version */
  221. uint8_t unused[5];
  222. uint8_t length[2];
  223. uint8_t control;
  224. };
  225. /*
  226. * When sending a mode select to a tape drive, the medium type must be 0.
  227. */
  228. struct scsi_mode_hdr_6
  229. {
  230. uint8_t datalen;
  231. uint8_t medium_type;
  232. uint8_t dev_specific;
  233. uint8_t block_descr_len;
  234. };
  235. struct scsi_mode_hdr_10
  236. {
  237. uint8_t datalen[2];
  238. uint8_t medium_type;
  239. uint8_t dev_specific;
  240. uint8_t reserved[2];
  241. uint8_t block_descr_len[2];
  242. };
  243. struct scsi_mode_block_descr
  244. {
  245. uint8_t density_code;
  246. uint8_t num_blocks[3];
  247. uint8_t reserved;
  248. uint8_t block_len[3];
  249. };
  250. struct scsi_log_sense
  251. {
  252. uint8_t opcode;
  253. uint8_t byte2;
  254. #define SLS_SP 0x01
  255. #define SLS_PPC 0x02
  256. uint8_t page;
  257. #define SLS_PAGE_CODE 0x3F
  258. #define SLS_ALL_PAGES_PAGE 0x00
  259. #define SLS_OVERRUN_PAGE 0x01
  260. #define SLS_ERROR_WRITE_PAGE 0x02
  261. #define SLS_ERROR_READ_PAGE 0x03
  262. #define SLS_ERROR_READREVERSE_PAGE 0x04
  263. #define SLS_ERROR_VERIFY_PAGE 0x05
  264. #define SLS_ERROR_NONMEDIUM_PAGE 0x06
  265. #define SLS_ERROR_LASTN_PAGE 0x07
  266. #define SLS_PAGE_CTRL_MASK 0xC0
  267. #define SLS_PAGE_CTRL_THRESHOLD 0x00
  268. #define SLS_PAGE_CTRL_CUMULATIVE 0x40
  269. #define SLS_PAGE_CTRL_THRESH_DEFAULT 0x80
  270. #define SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0
  271. uint8_t reserved[2];
  272. uint8_t paramptr[2];
  273. uint8_t length[2];
  274. uint8_t control;
  275. };
  276. struct scsi_log_select
  277. {
  278. uint8_t opcode;
  279. uint8_t byte2;
  280. /* SLS_SP 0x01 */
  281. #define SLS_PCR 0x02
  282. uint8_t page;
  283. /* SLS_PAGE_CTRL_MASK 0xC0 */
  284. /* SLS_PAGE_CTRL_THRESHOLD 0x00 */
  285. /* SLS_PAGE_CTRL_CUMULATIVE 0x40 */
  286. /* SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 */
  287. /* SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 */
  288. uint8_t reserved[4];
  289. uint8_t length[2];
  290. uint8_t control;
  291. };
  292. struct scsi_log_header
  293. {
  294. uint8_t page;
  295. uint8_t reserved;
  296. uint8_t datalen[2];
  297. };
  298. struct scsi_log_param_header {
  299. uint8_t param_code[2];
  300. uint8_t param_control;
  301. #define SLP_LP 0x01
  302. #define SLP_LBIN 0x02
  303. #define SLP_TMC_MASK 0x0C
  304. #define SLP_TMC_ALWAYS 0x00
  305. #define SLP_TMC_EQUAL 0x04
  306. #define SLP_TMC_NOTEQUAL 0x08
  307. #define SLP_TMC_GREATER 0x0C
  308. #define SLP_ETC 0x10
  309. #define SLP_TSD 0x20
  310. #define SLP_DS 0x40
  311. #define SLP_DU 0x80
  312. uint8_t param_len;
  313. };
  314. struct scsi_control_page {
  315. uint8_t page_code;
  316. uint8_t page_length;
  317. uint8_t rlec;
  318. #define SCB_RLEC 0x01 /*Report Log Exception Cond*/
  319. uint8_t queue_flags;
  320. #define SCP_QUEUE_ALG_MASK 0xF0
  321. #define SCP_QUEUE_ALG_RESTRICTED 0x00
  322. #define SCP_QUEUE_ALG_UNRESTRICTED 0x10
  323. #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/
  324. #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/
  325. uint8_t eca_and_aen;
  326. #define SCP_EECA 0x80 /*Enable Extended CA*/
  327. #define SCP_RAENP 0x04 /*Ready AEN Permission*/
  328. #define SCP_UAAENP 0x02 /*UA AEN Permission*/
  329. #define SCP_EAENP 0x01 /*Error AEN Permission*/
  330. uint8_t reserved;
  331. uint8_t aen_holdoff_period[2];
  332. };
  333. struct scsi_reserve
  334. {
  335. uint8_t opcode;
  336. uint8_t byte2;
  337. uint8_t unused[2];
  338. uint8_t length;
  339. uint8_t control;
  340. };
  341. struct scsi_release
  342. {
  343. uint8_t opcode;
  344. uint8_t byte2;
  345. uint8_t unused[2];
  346. uint8_t length;
  347. uint8_t control;
  348. };
  349. struct scsi_prevent
  350. {
  351. uint8_t opcode;
  352. uint8_t byte2;
  353. uint8_t unused[2];
  354. uint8_t how;
  355. uint8_t control;
  356. };
  357. #define PR_PREVENT 0x01
  358. #define PR_ALLOW 0x00
  359. struct scsi_sync_cache
  360. {
  361. uint8_t opcode;
  362. uint8_t byte2;
  363. uint8_t begin_lba[4];
  364. uint8_t reserved;
  365. uint8_t lb_count[2];
  366. uint8_t control;
  367. };
  368. struct scsi_changedef
  369. {
  370. uint8_t opcode;
  371. uint8_t byte2;
  372. uint8_t unused1;
  373. uint8_t how;
  374. uint8_t unused[4];
  375. uint8_t datalen;
  376. uint8_t control;
  377. };
  378. struct scsi_read_buffer
  379. {
  380. uint8_t opcode;
  381. uint8_t byte2;
  382. #define RWB_MODE 0x07
  383. #define RWB_MODE_HDR_DATA 0x00
  384. #define RWB_MODE_DATA 0x02
  385. #define RWB_MODE_DOWNLOAD 0x04
  386. #define RWB_MODE_DOWNLOAD_SAVE 0x05
  387. uint8_t buffer_id;
  388. uint8_t offset[3];
  389. uint8_t length[3];
  390. uint8_t control;
  391. };
  392. struct scsi_write_buffer
  393. {
  394. uint8_t opcode;
  395. uint8_t byte2;
  396. uint8_t buffer_id;
  397. uint8_t offset[3];
  398. uint8_t length[3];
  399. uint8_t control;
  400. };
  401. struct scsi_rw_6
  402. {
  403. uint8_t opcode;
  404. uint8_t addr[3];
  405. /* only 5 bits are valid in the MSB address byte */
  406. #define SRW_TOPADDR 0x1F
  407. uint8_t length;
  408. uint8_t control;
  409. };
  410. struct scsi_rw_10
  411. {
  412. uint8_t opcode;
  413. #define SRW10_RELADDR 0x01
  414. #define SRW10_FUA 0x08
  415. #define SRW10_DPO 0x10
  416. uint8_t byte2;
  417. uint8_t addr[4];
  418. uint8_t reserved;
  419. uint8_t length[2];
  420. uint8_t control;
  421. };
  422. struct scsi_rw_12
  423. {
  424. uint8_t opcode;
  425. #define SRW12_RELADDR 0x01
  426. #define SRW12_FUA 0x08
  427. #define SRW12_DPO 0x10
  428. uint8_t byte2;
  429. uint8_t addr[4];
  430. uint8_t length[4];
  431. uint8_t reserved;
  432. uint8_t control;
  433. };
  434. struct scsi_start_stop_unit
  435. {
  436. uint8_t opcode;
  437. uint8_t byte2;
  438. #define SSS_IMMED 0x01
  439. uint8_t reserved[2];
  440. uint8_t how;
  441. #define SSS_START 0x01
  442. #define SSS_LOEJ 0x02
  443. uint8_t control;
  444. };
  445. #define SC_SCSI_1 0x01
  446. #define SC_SCSI_2 0x03
  447. /*
  448. * Opcodes
  449. */
  450. #define TEST_UNIT_READY 0x00
  451. #define REQUEST_SENSE 0x03
  452. #define READ_6 0x08
  453. #define WRITE_6 0x0a
  454. #define INQUIRY 0x12
  455. #define MODE_SELECT_6 0x15
  456. #define MODE_SENSE_6 0x1a
  457. #define START_STOP_UNIT 0x1b
  458. #define START_STOP 0x1b
  459. #define RESERVE 0x16
  460. #define RELEASE 0x17
  461. #define RECEIVE_DIAGNOSTIC 0x1c
  462. #define SEND_DIAGNOSTIC 0x1d
  463. #define PREVENT_ALLOW 0x1e
  464. #define READ_CAPACITY 0x25
  465. #define READ_10 0x28
  466. #define WRITE_10 0x2a
  467. #define POSITION_TO_ELEMENT 0x2b
  468. #define SYNCHRONIZE_CACHE 0x35
  469. #define WRITE_BUFFER 0x3b
  470. #define READ_BUFFER 0x3c
  471. #define CHANGE_DEFINITION 0x40
  472. #define LOG_SELECT 0x4c
  473. #define LOG_SENSE 0x4d
  474. #ifdef XXXCAM
  475. #define MODE_SENSE_10 0x5A
  476. #endif
  477. #define MODE_SELECT_10 0x55
  478. #define MOVE_MEDIUM 0xa5
  479. #define READ_12 0xa8
  480. #define WRITE_12 0xaa
  481. #define READ_ELEMENT_STATUS 0xb8
  482. /*
  483. * Device Types
  484. */
  485. #define T_DIRECT 0x00
  486. #define T_SEQUENTIAL 0x01
  487. #define T_PRINTER 0x02
  488. #define T_PROCESSOR 0x03
  489. #define T_WORM 0x04
  490. #define T_CDROM 0x05
  491. #define T_SCANNER 0x06
  492. #define T_OPTICAL 0x07
  493. #define T_CHANGER 0x08
  494. #define T_COMM 0x09
  495. #define T_ASC0 0x0a
  496. #define T_ASC1 0x0b
  497. #define T_STORARRAY 0x0c
  498. #define T_ENCLOSURE 0x0d
  499. #define T_RBC 0x0e
  500. #define T_OCRW 0x0f
  501. #define T_NODEVICE 0x1F
  502. #define T_ANY 0xFF /* Used in Quirk table matches */
  503. #define T_REMOV 1
  504. #define T_FIXED 0
  505. /*
  506. * This length is the initial inquiry length used by the probe code, as
  507. * well as the legnth necessary for aic_print_inquiry() to function
  508. * correctly. If either use requires a different length in the future,
  509. * the two values should be de-coupled.
  510. */
  511. #define SHORT_INQUIRY_LENGTH 36
  512. struct scsi_inquiry_data
  513. {
  514. uint8_t device;
  515. #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
  516. #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
  517. #define SID_QUAL_LU_CONNECTED 0x00 /*
  518. * The specified peripheral device
  519. * type is currently connected to
  520. * logical unit. If the target cannot
  521. * determine whether or not a physical
  522. * device is currently connected, it
  523. * shall also use this peripheral
  524. * qualifier when returning the INQUIRY
  525. * data. This peripheral qualifier
  526. * does not mean that the device is
  527. * ready for access by the initiator.
  528. */
  529. #define SID_QUAL_LU_OFFLINE 0x01 /*
  530. * The target is capable of supporting
  531. * the specified peripheral device type
  532. * on this logical unit; however, the
  533. * physical device is not currently
  534. * connected to this logical unit.
  535. */
  536. #define SID_QUAL_RSVD 0x02
  537. #define SID_QUAL_BAD_LU 0x03 /*
  538. * The target is not capable of
  539. * supporting a physical device on
  540. * this logical unit. For this
  541. * peripheral qualifier the peripheral
  542. * device type shall be set to 1Fh to
  543. * provide compatibility with previous
  544. * versions of SCSI. All other
  545. * peripheral device type values are
  546. * reserved for this peripheral
  547. * qualifier.
  548. */
  549. #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
  550. uint8_t dev_qual2;
  551. #define SID_QUAL2 0x7F
  552. #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
  553. uint8_t version;
  554. #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
  555. #define SCSI_REV_0 0
  556. #define SCSI_REV_CCS 1
  557. #define SCSI_REV_2 2
  558. #define SCSI_REV_SPC 3
  559. #define SCSI_REV_SPC2 4
  560. #define SID_ECMA 0x38
  561. #define SID_ISO 0xC0
  562. uint8_t response_format;
  563. #define SID_AENC 0x80
  564. #define SID_TrmIOP 0x40
  565. uint8_t additional_length;
  566. uint8_t reserved[2];
  567. uint8_t flags;
  568. #define SID_SftRe 0x01
  569. #define SID_CmdQue 0x02
  570. #define SID_Linked 0x08
  571. #define SID_Sync 0x10
  572. #define SID_WBus16 0x20
  573. #define SID_WBus32 0x40
  574. #define SID_RelAdr 0x80
  575. #define SID_VENDOR_SIZE 8
  576. char vendor[SID_VENDOR_SIZE];
  577. #define SID_PRODUCT_SIZE 16
  578. char product[SID_PRODUCT_SIZE];
  579. #define SID_REVISION_SIZE 4
  580. char revision[SID_REVISION_SIZE];
  581. /*
  582. * The following fields were taken from SCSI Primary Commands - 2
  583. * (SPC-2) Revision 14, Dated 11 November 1999
  584. */
  585. #define SID_VENDOR_SPECIFIC_0_SIZE 20
  586. uint8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
  587. /*
  588. * An extension of SCSI Parallel Specific Values
  589. */
  590. #define SID_SPI_IUS 0x01
  591. #define SID_SPI_QAS 0x02
  592. #define SID_SPI_CLOCK_ST 0x00
  593. #define SID_SPI_CLOCK_DT 0x04
  594. #define SID_SPI_CLOCK_DT_ST 0x0C
  595. #define SID_SPI_MASK 0x0F
  596. uint8_t spi3data;
  597. uint8_t reserved2;
  598. /*
  599. * Version Descriptors, stored 2 byte values.
  600. */
  601. uint8_t version1[2];
  602. uint8_t version2[2];
  603. uint8_t version3[2];
  604. uint8_t version4[2];
  605. uint8_t version5[2];
  606. uint8_t version6[2];
  607. uint8_t version7[2];
  608. uint8_t version8[2];
  609. uint8_t reserved3[22];
  610. #define SID_VENDOR_SPECIFIC_1_SIZE 160
  611. uint8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
  612. };
  613. struct scsi_vpd_unit_serial_number
  614. {
  615. uint8_t device;
  616. uint8_t page_code;
  617. #define SVPD_UNIT_SERIAL_NUMBER 0x80
  618. uint8_t reserved;
  619. uint8_t length; /* serial number length */
  620. #define SVPD_SERIAL_NUM_SIZE 251
  621. uint8_t serial_num[SVPD_SERIAL_NUM_SIZE];
  622. };
  623. struct scsi_read_capacity
  624. {
  625. uint8_t opcode;
  626. uint8_t byte2;
  627. uint8_t addr[4];
  628. uint8_t unused[3];
  629. uint8_t control;
  630. };
  631. struct scsi_read_capacity_data
  632. {
  633. uint8_t addr[4];
  634. uint8_t length[4];
  635. };
  636. struct scsi_report_luns
  637. {
  638. uint8_t opcode;
  639. uint8_t byte2;
  640. uint8_t unused[3];
  641. uint8_t addr[4];
  642. uint8_t control;
  643. };
  644. struct scsi_report_luns_data {
  645. uint8_t length[4]; /* length of LUN inventory, in bytes */
  646. uint8_t reserved[4]; /* unused */
  647. /*
  648. * LUN inventory- we only support the type zero form for now.
  649. */
  650. struct {
  651. uint8_t lundata[8];
  652. } luns[1];
  653. };
  654. #define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */
  655. #define RPL_LUNDATA_T0LUN 1 /* @ lundata[1] */
  656. struct scsi_sense_data
  657. {
  658. uint8_t error_code;
  659. #define SSD_ERRCODE 0x7F
  660. #define SSD_CURRENT_ERROR 0x70
  661. #define SSD_DEFERRED_ERROR 0x71
  662. #define SSD_ERRCODE_VALID 0x80
  663. uint8_t segment;
  664. uint8_t flags;
  665. #define SSD_KEY 0x0F
  666. #define SSD_KEY_NO_SENSE 0x00
  667. #define SSD_KEY_RECOVERED_ERROR 0x01
  668. #define SSD_KEY_NOT_READY 0x02
  669. #define SSD_KEY_MEDIUM_ERROR 0x03
  670. #define SSD_KEY_HARDWARE_ERROR 0x04
  671. #define SSD_KEY_ILLEGAL_REQUEST 0x05
  672. #define SSD_KEY_UNIT_ATTENTION 0x06
  673. #define SSD_KEY_DATA_PROTECT 0x07
  674. #define SSD_KEY_BLANK_CHECK 0x08
  675. #define SSD_KEY_Vendor_Specific 0x09
  676. #define SSD_KEY_COPY_ABORTED 0x0a
  677. #define SSD_KEY_ABORTED_COMMAND 0x0b
  678. #define SSD_KEY_EQUAL 0x0c
  679. #define SSD_KEY_VOLUME_OVERFLOW 0x0d
  680. #define SSD_KEY_MISCOMPARE 0x0e
  681. #define SSD_KEY_RESERVED 0x0f
  682. #define SSD_ILI 0x20
  683. #define SSD_EOM 0x40
  684. #define SSD_FILEMARK 0x80
  685. uint8_t info[4];
  686. uint8_t extra_len;
  687. uint8_t cmd_spec_info[4];
  688. uint8_t add_sense_code;
  689. uint8_t add_sense_code_qual;
  690. uint8_t fru;
  691. uint8_t sense_key_spec[3];
  692. #define SSD_SCS_VALID 0x80
  693. #define SSD_FIELDPTR_CMD 0x40
  694. #define SSD_BITPTR_VALID 0x08
  695. #define SSD_BITPTR_VALUE 0x07
  696. #define SSD_MIN_SIZE 18
  697. uint8_t extra_bytes[14];
  698. #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
  699. };
  700. struct scsi_mode_header_6
  701. {
  702. uint8_t data_length; /* Sense data length */
  703. uint8_t medium_type;
  704. uint8_t dev_spec;
  705. uint8_t blk_desc_len;
  706. };
  707. struct scsi_mode_header_10
  708. {
  709. uint8_t data_length[2];/* Sense data length */
  710. uint8_t medium_type;
  711. uint8_t dev_spec;
  712. uint8_t unused[2];
  713. uint8_t blk_desc_len[2];
  714. };
  715. struct scsi_mode_page_header
  716. {
  717. uint8_t page_code;
  718. uint8_t page_length;
  719. };
  720. struct scsi_mode_blk_desc
  721. {
  722. uint8_t density;
  723. uint8_t nblocks[3];
  724. uint8_t reserved;
  725. uint8_t blklen[3];
  726. };
  727. #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
  728. #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
  729. /*
  730. * Status Byte
  731. */
  732. #define SCSI_STATUS_OK 0x00
  733. #define SCSI_STATUS_CHECK_COND 0x02
  734. #define SCSI_STATUS_COND_MET 0x04
  735. #define SCSI_STATUS_BUSY 0x08
  736. #define SCSI_STATUS_INTERMED 0x10
  737. #define SCSI_STATUS_INTERMED_COND_MET 0x14
  738. #define SCSI_STATUS_RESERV_CONFLICT 0x18
  739. #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
  740. #define SCSI_STATUS_QUEUE_FULL 0x28
  741. #define SCSI_STATUS_ACA_ACTIVE 0x30
  742. #define SCSI_STATUS_TASK_ABORTED 0x40
  743. struct scsi_inquiry_pattern {
  744. uint8_t type;
  745. uint8_t media_type;
  746. #define SIP_MEDIA_REMOVABLE 0x01
  747. #define SIP_MEDIA_FIXED 0x02
  748. const char *vendor;
  749. const char *product;
  750. const char *revision;
  751. };
  752. struct scsi_static_inquiry_pattern {
  753. uint8_t type;
  754. uint8_t media_type;
  755. char vendor[SID_VENDOR_SIZE+1];
  756. char product[SID_PRODUCT_SIZE+1];
  757. char revision[SID_REVISION_SIZE+1];
  758. };
  759. struct scsi_sense_quirk_entry {
  760. struct scsi_inquiry_pattern inq_pat;
  761. int num_sense_keys;
  762. int num_ascs;
  763. struct sense_key_table_entry *sense_key_info;
  764. struct asc_table_entry *asc_info;
  765. };
  766. struct sense_key_table_entry {
  767. uint8_t sense_key;
  768. uint32_t action;
  769. const char *desc;
  770. };
  771. struct asc_table_entry {
  772. uint8_t asc;
  773. uint8_t ascq;
  774. uint32_t action;
  775. const char *desc;
  776. };
  777. struct op_table_entry {
  778. uint8_t opcode;
  779. uint16_t opmask;
  780. const char *desc;
  781. };
  782. struct scsi_op_quirk_entry {
  783. struct scsi_inquiry_pattern inq_pat;
  784. int num_ops;
  785. struct op_table_entry *op_table;
  786. };
  787. typedef enum {
  788. SSS_FLAG_NONE = 0x00,
  789. SSS_FLAG_PRINT_COMMAND = 0x01
  790. } scsi_sense_string_flags;
  791. extern const char *scsi_sense_key_text[];
  792. /************************* Large Disk Handling ********************************/
  793. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
  794. static __inline int aic_sector_div(u_long capacity, int heads, int sectors);
  795. static __inline int
  796. aic_sector_div(u_long capacity, int heads, int sectors)
  797. {
  798. return (capacity / (heads * sectors));
  799. }
  800. #else
  801. static __inline int aic_sector_div(sector_t capacity, int heads, int sectors);
  802. static __inline int
  803. aic_sector_div(sector_t capacity, int heads, int sectors)
  804. {
  805. /* ugly, ugly sector_div calling convention.. */
  806. sector_div(capacity, (heads * sectors));
  807. return (int)capacity;
  808. }
  809. #endif
  810. /**************************** Module Library Hack *****************************/
  811. /*
  812. * What we'd like to do is have a single "scsi library" module that both the
  813. * aic7xxx and aic79xx drivers could load and depend on. A cursory examination
  814. * of implementing module dependencies in Linux (handling the install and
  815. * initrd cases) does not look promissing. For now, we just duplicate this
  816. * code in both drivers using a simple symbol renaming scheme that hides this
  817. * hack from the drivers.
  818. */
  819. #define AIC_LIB_ENTRY_CONCAT(x, prefix) prefix ## x
  820. #define AIC_LIB_ENTRY_EXPAND(x, prefix) AIC_LIB_ENTRY_CONCAT(x, prefix)
  821. #define AIC_LIB_ENTRY(x) AIC_LIB_ENTRY_EXPAND(x, AIC_LIB_PREFIX)
  822. #define aic_sense_desc AIC_LIB_ENTRY(_sense_desc)
  823. #define aic_sense_error_action AIC_LIB_ENTRY(_sense_error_action)
  824. #define aic_error_action AIC_LIB_ENTRY(_error_action)
  825. #define aic_op_desc AIC_LIB_ENTRY(_op_desc)
  826. #define aic_cdb_string AIC_LIB_ENTRY(_cdb_string)
  827. #define aic_print_inquiry AIC_LIB_ENTRY(_print_inquiry)
  828. #define aic_calc_syncsrate AIC_LIB_ENTRY(_calc_syncrate)
  829. #define aic_calc_syncparam AIC_LIB_ENTRY(_calc_syncparam)
  830. #define aic_calc_speed AIC_LIB_ENTRY(_calc_speed)
  831. #define aic_inquiry_match AIC_LIB_ENTRY(_inquiry_match)
  832. #define aic_static_inquiry_match AIC_LIB_ENTRY(_static_inquiry_match)
  833. #define aic_parse_brace_option AIC_LIB_ENTRY(_parse_brace_option)
  834. /******************************************************************************/
  835. void aic_sense_desc(int /*sense_key*/, int /*asc*/,
  836. int /*ascq*/, struct scsi_inquiry_data*,
  837. const char** /*sense_key_desc*/,
  838. const char** /*asc_desc*/);
  839. aic_sense_action aic_sense_error_action(struct scsi_sense_data*,
  840. struct scsi_inquiry_data*,
  841. uint32_t /*sense_flags*/);
  842. uint32_t aic_error_action(struct scsi_cmnd *,
  843. struct scsi_inquiry_data *,
  844. cam_status, u_int);
  845. #define SF_RETRY_UA 0x01
  846. #define SF_NO_PRINT 0x02
  847. #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
  848. #define SF_PRINT_ALWAYS 0x08
  849. const char * aic_op_desc(uint16_t /*opcode*/, struct scsi_inquiry_data*);
  850. char * aic_cdb_string(uint8_t* /*cdb_ptr*/, char* /*cdb_string*/,
  851. size_t /*len*/);
  852. void aic_print_inquiry(struct scsi_inquiry_data*);
  853. u_int aic_calc_syncsrate(u_int /*period_factor*/);
  854. u_int aic_calc_syncparam(u_int /*period*/);
  855. u_int aic_calc_speed(u_int width, u_int period, u_int offset,
  856. u_int min_rate);
  857. int aic_inquiry_match(caddr_t /*inqbuffer*/,
  858. caddr_t /*table_entry*/);
  859. int aic_static_inquiry_match(caddr_t /*inqbuffer*/,
  860. caddr_t /*table_entry*/);
  861. typedef void aic_option_callback_t(u_long, int, int, int32_t);
  862. char * aic_parse_brace_option(char *opt_name, char *opt_arg,
  863. char *end, int depth,
  864. aic_option_callback_t *, u_long);
  865. static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
  866. int *error_code, int *sense_key,
  867. int *asc, int *ascq);
  868. static __inline void scsi_ulto2b(uint32_t val, uint8_t *bytes);
  869. static __inline void scsi_ulto3b(uint32_t val, uint8_t *bytes);
  870. static __inline void scsi_ulto4b(uint32_t val, uint8_t *bytes);
  871. static __inline uint32_t scsi_2btoul(uint8_t *bytes);
  872. static __inline uint32_t scsi_3btoul(uint8_t *bytes);
  873. static __inline int32_t scsi_3btol(uint8_t *bytes);
  874. static __inline uint32_t scsi_4btoul(uint8_t *bytes);
  875. static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
  876. int *error_code, int *sense_key,
  877. int *asc, int *ascq)
  878. {
  879. *error_code = sense->error_code & SSD_ERRCODE;
  880. *sense_key = sense->flags & SSD_KEY;
  881. *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
  882. *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
  883. }
  884. static __inline void
  885. scsi_ulto2b(uint32_t val, uint8_t *bytes)
  886. {
  887. bytes[0] = (val >> 8) & 0xff;
  888. bytes[1] = val & 0xff;
  889. }
  890. static __inline void
  891. scsi_ulto3b(uint32_t val, uint8_t *bytes)
  892. {
  893. bytes[0] = (val >> 16) & 0xff;
  894. bytes[1] = (val >> 8) & 0xff;
  895. bytes[2] = val & 0xff;
  896. }
  897. static __inline void
  898. scsi_ulto4b(uint32_t val, uint8_t *bytes)
  899. {
  900. bytes[0] = (val >> 24) & 0xff;
  901. bytes[1] = (val >> 16) & 0xff;
  902. bytes[2] = (val >> 8) & 0xff;
  903. bytes[3] = val & 0xff;
  904. }
  905. static __inline uint32_t
  906. scsi_2btoul(uint8_t *bytes)
  907. {
  908. uint32_t rv;
  909. rv = (bytes[0] << 8) |
  910. bytes[1];
  911. return (rv);
  912. }
  913. static __inline uint32_t
  914. scsi_3btoul(uint8_t *bytes)
  915. {
  916. uint32_t rv;
  917. rv = (bytes[0] << 16) |
  918. (bytes[1] << 8) |
  919. bytes[2];
  920. return (rv);
  921. }
  922. static __inline int32_t
  923. scsi_3btol(uint8_t *bytes)
  924. {
  925. uint32_t rc = scsi_3btoul(bytes);
  926. if (rc & 0x00800000)
  927. rc |= 0xff000000;
  928. return (int32_t) rc;
  929. }
  930. static __inline uint32_t
  931. scsi_4btoul(uint8_t *bytes)
  932. {
  933. uint32_t rv;
  934. rv = (bytes[0] << 24) |
  935. (bytes[1] << 16) |
  936. (bytes[2] << 8) |
  937. bytes[3];
  938. return (rv);
  939. }
  940. /* Macros for generating the elements of the PCI ID tables. */
  941. #define GETID(v, s) (unsigned)(((v) >> (s)) & 0xFFFF ?: PCI_ANY_ID)
  942. #define ID_C(x, c) \
  943. { \
  944. GETID(x,32), GETID(x,48), GETID(x,0), GETID(x,16), \
  945. (c) << 8, 0xFFFF00, 0 \
  946. }
  947. #define ID2C(x) \
  948. ID_C(x, PCI_CLASS_STORAGE_SCSI), \
  949. ID_C(x, PCI_CLASS_STORAGE_RAID)
  950. #define IDIROC(x) ((x) | ~ID_ALL_IROC_MASK)
  951. /* Generate IDs for all 16 possibilites.
  952. * The argument has already masked out
  953. * the 4 least significant bits of the device id.
  954. * (e.g., mask: ID_9005_GENERIC_MASK).
  955. */
  956. #define ID16(x) \
  957. ID(x), \
  958. ID((x) | 0x0001000000000000ull), \
  959. ID((x) | 0x0002000000000000ull), \
  960. ID((x) | 0x0003000000000000ull), \
  961. ID((x) | 0x0004000000000000ull), \
  962. ID((x) | 0x0005000000000000ull), \
  963. ID((x) | 0x0006000000000000ull), \
  964. ID((x) | 0x0007000000000000ull), \
  965. ID((x) | 0x0008000000000000ull), \
  966. ID((x) | 0x0009000000000000ull), \
  967. ID((x) | 0x000A000000000000ull), \
  968. ID((x) | 0x000B000000000000ull), \
  969. ID((x) | 0x000C000000000000ull), \
  970. ID((x) | 0x000D000000000000ull), \
  971. ID((x) | 0x000E000000000000ull), \
  972. ID((x) | 0x000F000000000000ull)
  973. #endif /*_AICLIB_H */