2 * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/libkern.h>
37 #include <sys/kernel.h>
38 #include <sys/sysctl.h>
45 #define min(a,b) (((a)<(b))?(a):(b))
50 #include <cam/cam_ccb.h>
51 #include <cam/cam_queue.h>
52 #include <cam/cam_xpt.h>
54 #include <cam/ata/ata_all.h>
56 #include <sys/endian.h>
65 for (bit = 15; bit >= 0; bit--)
72 ata_op_string(struct ata_cmd *cmd)
75 if (cmd->control & 0x04)
76 return ("SOFT_RESET");
77 switch (cmd->command) {
79 switch (cmd->features) {
80 case 0x00: return ("NOP FLUSHQUEUE");
81 case 0x01: return ("NOP AUTOPOLL");
84 case 0x03: return ("CFA_REQUEST_EXTENDED_ERROR");
86 switch (cmd->features) {
87 case 0x01: return ("DSM TRIM");
90 case 0x08: return ("DEVICE_RESET");
91 case 0x0b: return ("REQUEST_SENSE_DATA_EXT");
92 case 0x20: return ("READ");
93 case 0x24: return ("READ48");
94 case 0x25: return ("READ_DMA48");
95 case 0x26: return ("READ_DMA_QUEUED48");
96 case 0x27: return ("READ_NATIVE_MAX_ADDRESS48");
97 case 0x29: return ("READ_MUL48");
98 case 0x2a: return ("READ_STREAM_DMA48");
99 case 0x2b: return ("READ_STREAM48");
100 case 0x2f: return ("READ_LOG_EXT");
101 case 0x30: return ("WRITE");
102 case 0x34: return ("WRITE48");
103 case 0x35: return ("WRITE_DMA48");
104 case 0x36: return ("WRITE_DMA_QUEUED48");
105 case 0x37: return ("SET_MAX_ADDRESS48");
106 case 0x39: return ("WRITE_MUL48");
107 case 0x3a: return ("WRITE_STREAM_DMA48");
108 case 0x3b: return ("WRITE_STREAM48");
109 case 0x3d: return ("WRITE_DMA_FUA48");
110 case 0x3e: return ("WRITE_DMA_QUEUED_FUA48");
111 case 0x3f: return ("WRITE_LOG_EXT");
112 case 0x40: return ("READ_VERIFY");
113 case 0x42: return ("READ_VERIFY48");
115 switch (cmd->features) {
116 case 0x55: return ("WRITE_UNCORRECTABLE48 PSEUDO");
117 case 0xaa: return ("WRITE_UNCORRECTABLE48 FLAGGED");
119 return "WRITE_UNCORRECTABLE48";
120 case 0x51: return ("CONFIGURE_STREAM");
121 case 0x57: return ("WRITE_LOG_DMA_EXT");
122 case 0x5b: return ("TRUSTED_NON_DATA");
123 case 0x5c: return ("TRUSTED_RECEIVE");
124 case 0x5d: return ("TRUSTED_RECEIVE_DMA");
125 case 0x5e: return ("TRUSTED_SEND");
126 case 0x5f: return ("TRUSTED_SEND_DMA");
127 case 0x60: return ("READ_FPDMA_QUEUED");
128 case 0x61: return ("WRITE_FPDMA_QUEUED");
129 case 0x63: return ("NCQ_NON_DATA");
130 case 0x64: return ("SEND_FPDMA_QUEUED");
131 case 0x65: return ("RECEIVE_FPDMA_QUEUED");
133 if (cmd->features == 0xec)
134 return ("SEP_ATTN IDENTIFY");
135 switch (cmd->lba_low) {
136 case 0x00: return ("SEP_ATTN READ BUFFER");
137 case 0x02: return ("SEP_ATTN RECEIVE DIAGNOSTIC RESULTS");
138 case 0x80: return ("SEP_ATTN WRITE BUFFER");
139 case 0x82: return ("SEP_ATTN SEND DIAGNOSTIC");
142 case 0x70: return ("SEEK");
143 case 0x77: return ("SET_DATE_TIME_EXT");
144 case 0x78: return ("ACCESSIBLE_MAX_ADDRESS_CONFIGURATION");
145 case 0x87: return ("CFA_TRANSLATE_SECTOR");
146 case 0x90: return ("EXECUTE_DEVICE_DIAGNOSTIC");
147 case 0x92: return ("DOWNLOAD_MICROCODE");
148 case 0x93: return ("DOWNLOAD_MICROCODE_DMA");
149 case 0x9a: return ("ZAC_MANAGEMENT_OUT");
150 case 0xa0: return ("PACKET");
151 case 0xa1: return ("ATAPI_IDENTIFY");
152 case 0xa2: return ("SERVICE");
154 switch(cmd->features) {
155 case 0xd0: return ("SMART READ ATTR VALUES");
156 case 0xd1: return ("SMART READ ATTR THRESHOLDS");
157 case 0xd3: return ("SMART SAVE ATTR VALUES");
158 case 0xd4: return ("SMART EXECUTE OFFLINE IMMEDIATE");
159 case 0xd5: return ("SMART READ LOG DATA");
160 case 0xd8: return ("SMART ENABLE OPERATION");
161 case 0xd9: return ("SMART DISABLE OPERATION");
162 case 0xda: return ("SMART RETURN STATUS");
165 case 0xb1: return ("DEVICE CONFIGURATION");
166 case 0xb4: return ("SANITIZE_DEVICE");
167 case 0xc0: return ("CFA_ERASE");
168 case 0xc4: return ("READ_MUL");
169 case 0xc5: return ("WRITE_MUL");
170 case 0xc6: return ("SET_MULTI");
171 case 0xc7: return ("READ_DMA_QUEUED");
172 case 0xc8: return ("READ_DMA");
173 case 0xca: return ("WRITE_DMA");
174 case 0xcc: return ("WRITE_DMA_QUEUED");
175 case 0xcd: return ("CFA_WRITE_MULTIPLE_WITHOUT_ERASE");
176 case 0xce: return ("WRITE_MUL_FUA48");
177 case 0xd1: return ("CHECK_MEDIA_CARD_TYPE");
178 case 0xda: return ("GET_MEDIA_STATUS");
179 case 0xde: return ("MEDIA_LOCK");
180 case 0xdf: return ("MEDIA_UNLOCK");
181 case 0xe0: return ("STANDBY_IMMEDIATE");
182 case 0xe1: return ("IDLE_IMMEDIATE");
183 case 0xe2: return ("STANDBY");
184 case 0xe3: return ("IDLE");
185 case 0xe4: return ("READ_BUFFER/PM");
186 case 0xe5: return ("CHECK_POWER_MODE");
187 case 0xe6: return ("SLEEP");
188 case 0xe7: return ("FLUSHCACHE");
189 case 0xe8: return ("WRITE_PM");
190 case 0xea: return ("FLUSHCACHE48");
191 case 0xec: return ("ATA_IDENTIFY");
192 case 0xed: return ("MEDIA_EJECT");
194 switch (cmd->features) {
195 case 0x03: return ("SETFEATURES SET TRANSFER MODE");
196 case 0x02: return ("SETFEATURES ENABLE WCACHE");
197 case 0x82: return ("SETFEATURES DISABLE WCACHE");
198 case 0x06: return ("SETFEATURES ENABLE PUIS");
199 case 0x86: return ("SETFEATURES DISABLE PUIS");
200 case 0x07: return ("SETFEATURES SPIN-UP");
201 case 0x10: return ("SETFEATURES ENABLE SATA FEATURE");
202 case 0x90: return ("SETFEATURES DISABLE SATA FEATURE");
203 case 0xaa: return ("SETFEATURES ENABLE RCACHE");
204 case 0x55: return ("SETFEATURES DISABLE RCACHE");
205 case 0x5d: return ("SETFEATURES ENABLE RELIRQ");
206 case 0xdd: return ("SETFEATURES DISABLE RELIRQ");
207 case 0x5e: return ("SETFEATURES ENABLE SRVIRQ");
208 case 0xde: return ("SETFEATURES DISABLE SRVIRQ");
210 return "SETFEATURES";
211 case 0xf1: return ("SECURITY_SET_PASSWORD");
212 case 0xf2: return ("SECURITY_UNLOCK");
213 case 0xf3: return ("SECURITY_ERASE_PREPARE");
214 case 0xf4: return ("SECURITY_ERASE_UNIT");
215 case 0xf5: return ("SECURITY_FREEZE_LOCK");
216 case 0xf6: return ("SECURITY_DISABLE_PASSWORD");
217 case 0xf8: return ("READ_NATIVE_MAX_ADDRESS");
218 case 0xf9: return ("SET_MAX_ADDRESS");
224 ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len)
232 sbuf_new(&sb, cmd_string, len, SBUF_FIXEDLEN);
233 ata_cmd_sbuf(cmd, &sb);
235 error = sbuf_finish(&sb);
236 if (error != 0 && error != ENOMEM)
239 return(sbuf_data(&sb));
243 ata_cmd_sbuf(struct ata_cmd *cmd, struct sbuf *sb)
245 sbuf_printf(sb, "%02x %02x %02x %02x "
246 "%02x %02x %02x %02x %02x %02x %02x %02x",
247 cmd->command, cmd->features,
248 cmd->lba_low, cmd->lba_mid, cmd->lba_high, cmd->device,
249 cmd->lba_low_exp, cmd->lba_mid_exp, cmd->lba_high_exp,
250 cmd->features_exp, cmd->sector_count, cmd->sector_count_exp);
254 ata_res_string(struct ata_res *res, char *res_string, size_t len)
257 snprintf(res_string, len, "%02x %02x %02x %02x "
258 "%02x %02x %02x %02x %02x %02x %02x",
259 res->status, res->error,
260 res->lba_low, res->lba_mid, res->lba_high, res->device,
261 res->lba_low_exp, res->lba_mid_exp, res->lba_high_exp,
262 res->sector_count, res->sector_count_exp);
268 * ata_command_sbuf() returns 0 for success and -1 for failure.
271 ata_command_sbuf(struct ccb_ataio *ataio, struct sbuf *sb)
274 sbuf_printf(sb, "%s. ACB: ",
275 ata_op_string(&ataio->cmd));
276 ata_cmd_sbuf(&ataio->cmd, sb);
282 * ata_status_abuf() returns 0 for success and -1 for failure.
285 ata_status_sbuf(struct ccb_ataio *ataio, struct sbuf *sb)
288 sbuf_printf(sb, "ATA status: %02x (%s%s%s%s%s%s%s%s)",
290 (ataio->res.status & 0x80) ? "BSY " : "",
291 (ataio->res.status & 0x40) ? "DRDY " : "",
292 (ataio->res.status & 0x20) ? "DF " : "",
293 (ataio->res.status & 0x10) ? "SERV " : "",
294 (ataio->res.status & 0x08) ? "DRQ " : "",
295 (ataio->res.status & 0x04) ? "CORR " : "",
296 (ataio->res.status & 0x02) ? "IDX " : "",
297 (ataio->res.status & 0x01) ? "ERR" : "");
298 if (ataio->res.status & 1) {
299 sbuf_printf(sb, ", error: %02x (%s%s%s%s%s%s%s%s)",
301 (ataio->res.error & 0x80) ? "ICRC " : "",
302 (ataio->res.error & 0x40) ? "UNC " : "",
303 (ataio->res.error & 0x20) ? "MC " : "",
304 (ataio->res.error & 0x10) ? "IDNF " : "",
305 (ataio->res.error & 0x08) ? "MCR " : "",
306 (ataio->res.error & 0x04) ? "ABRT " : "",
307 (ataio->res.error & 0x02) ? "NM " : "",
308 (ataio->res.error & 0x01) ? "ILI" : "");
315 * ata_res_sbuf() returns 0 for success and -1 for failure.
318 ata_res_sbuf(struct ccb_ataio *ataio, struct sbuf *sb)
320 char res_str[(11 * 3) + 1];
322 sbuf_printf(sb, "RES: %s",
323 ata_res_string(&ataio->res, res_str, sizeof(res_str)));
329 ata_print_ident(struct ata_params *ident_data)
332 char product[48], revision[16], ata[12], sata[12];
334 cam_strvis(product, ident_data->model, sizeof(ident_data->model),
336 cam_strvis(revision, ident_data->revision, sizeof(ident_data->revision),
338 proto = (ident_data->config == ATA_PROTO_CFA) ? "CFA" :
339 (ident_data->config & ATA_PROTO_ATAPI) ? "ATAPI" : "ATA";
340 if (ata_version(ident_data->version_major) == 0) {
341 snprintf(ata, sizeof(ata), "%s", proto);
342 } else if (ata_version(ident_data->version_major) <= 7) {
343 snprintf(ata, sizeof(ata), "%s-%d", proto,
344 ata_version(ident_data->version_major));
345 } else if (ata_version(ident_data->version_major) == 8) {
346 snprintf(ata, sizeof(ata), "%s8-ACS", proto);
348 snprintf(ata, sizeof(ata), "ACS-%d %s",
349 ata_version(ident_data->version_major) - 7, proto);
351 if (ident_data->satacapabilities && ident_data->satacapabilities != 0xffff) {
352 if (ident_data->satacapabilities & ATA_SATA_GEN3)
353 snprintf(sata, sizeof(sata), " SATA 3.x");
354 else if (ident_data->satacapabilities & ATA_SATA_GEN2)
355 snprintf(sata, sizeof(sata), " SATA 2.x");
356 else if (ident_data->satacapabilities & ATA_SATA_GEN1)
357 snprintf(sata, sizeof(sata), " SATA 1.x");
359 snprintf(sata, sizeof(sata), " SATA");
362 printf("<%s %s> %s%s device\n", product, revision, ata, sata);
366 ata_print_ident_short(struct ata_params *ident_data)
368 char product[48], revision[16];
370 cam_strvis(product, ident_data->model, sizeof(ident_data->model),
372 cam_strvis(revision, ident_data->revision, sizeof(ident_data->revision),
374 printf("<%s %s>", product, revision);
378 semb_print_ident(struct sep_identify_data *ident_data)
380 char vendor[9], product[17], revision[5], fw[5], in[7], ins[5];
382 cam_strvis(vendor, ident_data->vendor_id, 8, sizeof(vendor));
383 cam_strvis(product, ident_data->product_id, 16, sizeof(product));
384 cam_strvis(revision, ident_data->product_rev, 4, sizeof(revision));
385 cam_strvis(fw, ident_data->firmware_rev, 4, sizeof(fw));
386 cam_strvis(in, ident_data->interface_id, 6, sizeof(in));
387 cam_strvis(ins, ident_data->interface_rev, 4, sizeof(ins));
388 printf("<%s %s %s %s> SEMB %s %s device\n",
389 vendor, product, revision, fw, in, ins);
393 semb_print_ident_short(struct sep_identify_data *ident_data)
395 char vendor[9], product[17], revision[5], fw[5];
397 cam_strvis(vendor, ident_data->vendor_id, 8, sizeof(vendor));
398 cam_strvis(product, ident_data->product_id, 16, sizeof(product));
399 cam_strvis(revision, ident_data->product_rev, 4, sizeof(revision));
400 cam_strvis(fw, ident_data->firmware_rev, 4, sizeof(fw));
401 printf("<%s %s %s %s>", vendor, product, revision, fw);
405 ata_logical_sector_size(struct ata_params *ident_data)
407 if ((ident_data->pss & ATA_PSS_VALID_MASK) == ATA_PSS_VALID_VALUE &&
408 (ident_data->pss & ATA_PSS_LSSABOVE512)) {
409 return (((u_int32_t)ident_data->lss_1 |
410 ((u_int32_t)ident_data->lss_2 << 16)) * 2);
416 ata_physical_sector_size(struct ata_params *ident_data)
418 if ((ident_data->pss & ATA_PSS_VALID_MASK) == ATA_PSS_VALID_VALUE) {
419 if (ident_data->pss & ATA_PSS_MULTLS) {
420 return ((uint64_t)ata_logical_sector_size(ident_data) *
421 (1 << (ident_data->pss & ATA_PSS_LSPPS)));
423 return (uint64_t)ata_logical_sector_size(ident_data);
430 ata_logical_sector_offset(struct ata_params *ident_data)
432 if ((ident_data->lsalign & 0xc000) == 0x4000) {
433 return ((uint64_t)ata_logical_sector_size(ident_data) *
434 (ident_data->lsalign & 0x3fff));
440 ata_28bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint8_t features,
441 uint32_t lba, uint8_t sector_count)
443 bzero(&ataio->cmd, sizeof(ataio->cmd));
444 ataio->cmd.flags = 0;
445 if (cmd == ATA_READ_DMA ||
446 cmd == ATA_READ_DMA_QUEUED ||
447 cmd == ATA_WRITE_DMA ||
448 cmd == ATA_WRITE_DMA_QUEUED)
449 ataio->cmd.flags |= CAM_ATAIO_DMA;
450 ataio->cmd.command = cmd;
451 ataio->cmd.features = features;
452 ataio->cmd.lba_low = lba;
453 ataio->cmd.lba_mid = lba >> 8;
454 ataio->cmd.lba_high = lba >> 16;
455 ataio->cmd.device = ATA_DEV_LBA | ((lba >> 24) & 0x0f);
456 ataio->cmd.sector_count = sector_count;
460 ata_48bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint16_t features,
461 uint64_t lba, uint16_t sector_count)
464 ataio->cmd.flags = CAM_ATAIO_48BIT;
465 if (cmd == ATA_READ_DMA48 ||
466 cmd == ATA_READ_DMA_QUEUED48 ||
467 cmd == ATA_READ_STREAM_DMA48 ||
468 cmd == ATA_WRITE_DMA48 ||
469 cmd == ATA_WRITE_DMA_FUA48 ||
470 cmd == ATA_WRITE_DMA_QUEUED48 ||
471 cmd == ATA_WRITE_DMA_QUEUED_FUA48 ||
472 cmd == ATA_WRITE_STREAM_DMA48 ||
473 cmd == ATA_DATA_SET_MANAGEMENT)
474 ataio->cmd.flags |= CAM_ATAIO_DMA;
475 ataio->cmd.command = cmd;
476 ataio->cmd.features = features;
477 ataio->cmd.lba_low = lba;
478 ataio->cmd.lba_mid = lba >> 8;
479 ataio->cmd.lba_high = lba >> 16;
480 ataio->cmd.device = ATA_DEV_LBA;
481 ataio->cmd.lba_low_exp = lba >> 24;
482 ataio->cmd.lba_mid_exp = lba >> 32;
483 ataio->cmd.lba_high_exp = lba >> 40;
484 ataio->cmd.features_exp = features >> 8;
485 ataio->cmd.sector_count = sector_count;
486 ataio->cmd.sector_count_exp = sector_count >> 8;
487 ataio->cmd.control = 0;
491 ata_ncq_cmd(struct ccb_ataio *ataio, uint8_t cmd,
492 uint64_t lba, uint16_t sector_count)
495 ataio->cmd.flags = CAM_ATAIO_48BIT | CAM_ATAIO_FPDMA;
496 ataio->cmd.command = cmd;
497 ataio->cmd.features = sector_count;
498 ataio->cmd.lba_low = lba;
499 ataio->cmd.lba_mid = lba >> 8;
500 ataio->cmd.lba_high = lba >> 16;
501 ataio->cmd.device = ATA_DEV_LBA;
502 ataio->cmd.lba_low_exp = lba >> 24;
503 ataio->cmd.lba_mid_exp = lba >> 32;
504 ataio->cmd.lba_high_exp = lba >> 40;
505 ataio->cmd.features_exp = sector_count >> 8;
506 ataio->cmd.sector_count = 0;
507 ataio->cmd.sector_count_exp = 0;
508 ataio->cmd.control = 0;
512 ata_reset_cmd(struct ccb_ataio *ataio)
514 bzero(&ataio->cmd, sizeof(ataio->cmd));
515 ataio->cmd.flags = CAM_ATAIO_CONTROL | CAM_ATAIO_NEEDRESULT;
516 ataio->cmd.control = 0x04;
520 ata_pm_read_cmd(struct ccb_ataio *ataio, int reg, int port)
522 bzero(&ataio->cmd, sizeof(ataio->cmd));
523 ataio->cmd.flags = CAM_ATAIO_NEEDRESULT;
524 ataio->cmd.command = ATA_READ_PM;
525 ataio->cmd.features = reg;
526 ataio->cmd.device = port & 0x0f;
530 ata_pm_write_cmd(struct ccb_ataio *ataio, int reg, int port, uint32_t val)
532 bzero(&ataio->cmd, sizeof(ataio->cmd));
533 ataio->cmd.flags = 0;
534 ataio->cmd.command = ATA_WRITE_PM;
535 ataio->cmd.features = reg;
536 ataio->cmd.sector_count = val;
537 ataio->cmd.lba_low = val >> 8;
538 ataio->cmd.lba_mid = val >> 16;
539 ataio->cmd.lba_high = val >> 24;
540 ataio->cmd.device = port & 0x0f;
544 ata_bswap(int8_t *buf, int len)
546 u_int16_t *ptr = (u_int16_t*)(buf + len);
548 while (--ptr >= (u_int16_t*)buf)
549 *ptr = be16toh(*ptr);
553 ata_btrim(int8_t *buf, int len)
557 for (ptr = buf; ptr < buf+len; ++ptr)
558 if (!*ptr || *ptr == '_')
560 for (ptr = buf + len - 1; ptr >= buf && *ptr == ' '; --ptr)
565 ata_bpack(int8_t *src, int8_t *dst, int len)
569 for (i = j = blank = 0 ; i < len; i++) {
570 if (blank && src[i] == ' ') continue;
571 if (blank && src[i] != ' ') {
588 ata_max_pmode(struct ata_params *ap)
590 if (ap->atavalid & ATA_FLAG_64_70) {
591 if (ap->apiomodes & 0x02)
593 if (ap->apiomodes & 0x01)
596 if (ap->mwdmamodes & 0x04)
598 if (ap->mwdmamodes & 0x02)
600 if (ap->mwdmamodes & 0x01)
602 if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x200)
604 if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x100)
606 if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x000)
612 ata_max_wmode(struct ata_params *ap)
614 if (ap->mwdmamodes & 0x04)
616 if (ap->mwdmamodes & 0x02)
618 if (ap->mwdmamodes & 0x01)
624 ata_max_umode(struct ata_params *ap)
626 if (ap->atavalid & ATA_FLAG_88) {
627 if (ap->udmamodes & 0x40)
629 if (ap->udmamodes & 0x20)
631 if (ap->udmamodes & 0x10)
633 if (ap->udmamodes & 0x08)
635 if (ap->udmamodes & 0x04)
637 if (ap->udmamodes & 0x02)
639 if (ap->udmamodes & 0x01)
646 ata_max_mode(struct ata_params *ap, int maxmode)
650 maxmode = ATA_DMA_MAX;
651 if (maxmode >= ATA_UDMA0 && ata_max_umode(ap) > 0)
652 return (min(maxmode, ata_max_umode(ap)));
653 if (maxmode >= ATA_WDMA0 && ata_max_wmode(ap) > 0)
654 return (min(maxmode, ata_max_wmode(ap)));
655 return (min(maxmode, ata_max_pmode(ap)));
659 ata_mode2string(int mode)
662 case -1: return "UNSUPPORTED";
663 case 0: return "NONE";
664 case ATA_PIO0: return "PIO0";
665 case ATA_PIO1: return "PIO1";
666 case ATA_PIO2: return "PIO2";
667 case ATA_PIO3: return "PIO3";
668 case ATA_PIO4: return "PIO4";
669 case ATA_WDMA0: return "WDMA0";
670 case ATA_WDMA1: return "WDMA1";
671 case ATA_WDMA2: return "WDMA2";
672 case ATA_UDMA0: return "UDMA0";
673 case ATA_UDMA1: return "UDMA1";
674 case ATA_UDMA2: return "UDMA2";
675 case ATA_UDMA3: return "UDMA3";
676 case ATA_UDMA4: return "UDMA4";
677 case ATA_UDMA5: return "UDMA5";
678 case ATA_UDMA6: return "UDMA6";
680 if (mode & ATA_DMA_MASK)
688 ata_string2mode(char *str)
690 if (!strcasecmp(str, "PIO0")) return (ATA_PIO0);
691 if (!strcasecmp(str, "PIO1")) return (ATA_PIO1);
692 if (!strcasecmp(str, "PIO2")) return (ATA_PIO2);
693 if (!strcasecmp(str, "PIO3")) return (ATA_PIO3);
694 if (!strcasecmp(str, "PIO4")) return (ATA_PIO4);
695 if (!strcasecmp(str, "WDMA0")) return (ATA_WDMA0);
696 if (!strcasecmp(str, "WDMA1")) return (ATA_WDMA1);
697 if (!strcasecmp(str, "WDMA2")) return (ATA_WDMA2);
698 if (!strcasecmp(str, "UDMA0")) return (ATA_UDMA0);
699 if (!strcasecmp(str, "UDMA16")) return (ATA_UDMA0);
700 if (!strcasecmp(str, "UDMA1")) return (ATA_UDMA1);
701 if (!strcasecmp(str, "UDMA25")) return (ATA_UDMA1);
702 if (!strcasecmp(str, "UDMA2")) return (ATA_UDMA2);
703 if (!strcasecmp(str, "UDMA33")) return (ATA_UDMA2);
704 if (!strcasecmp(str, "UDMA3")) return (ATA_UDMA3);
705 if (!strcasecmp(str, "UDMA44")) return (ATA_UDMA3);
706 if (!strcasecmp(str, "UDMA4")) return (ATA_UDMA4);
707 if (!strcasecmp(str, "UDMA66")) return (ATA_UDMA4);
708 if (!strcasecmp(str, "UDMA5")) return (ATA_UDMA5);
709 if (!strcasecmp(str, "UDMA100")) return (ATA_UDMA5);
710 if (!strcasecmp(str, "UDMA6")) return (ATA_UDMA6);
711 if (!strcasecmp(str, "UDMA133")) return (ATA_UDMA6);
717 ata_mode2speed(int mode)
755 ata_revision2speed(int revision)
769 ata_speed2revision(u_int speed)
786 ata_identify_match(caddr_t identbuffer, caddr_t table_entry)
788 struct scsi_inquiry_pattern *entry;
789 struct ata_params *ident;
791 entry = (struct scsi_inquiry_pattern *)table_entry;
792 ident = (struct ata_params *)identbuffer;
794 if ((cam_strmatch(ident->model, entry->product,
795 sizeof(ident->model)) == 0)
796 && (cam_strmatch(ident->revision, entry->revision,
797 sizeof(ident->revision)) == 0)) {
804 ata_static_identify_match(caddr_t identbuffer, caddr_t table_entry)
806 struct scsi_static_inquiry_pattern *entry;
807 struct ata_params *ident;
809 entry = (struct scsi_static_inquiry_pattern *)table_entry;
810 ident = (struct ata_params *)identbuffer;
812 if ((cam_strmatch(ident->model, entry->product,
813 sizeof(ident->model)) == 0)
814 && (cam_strmatch(ident->revision, entry->revision,
815 sizeof(ident->revision)) == 0)) {
822 semb_receive_diagnostic_results(struct ccb_ataio *ataio,
823 u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
824 uint8_t tag_action, int pcv, uint8_t page_code,
825 uint8_t *data_ptr, uint16_t length, uint32_t timeout)
828 length = min(length, 1020);
829 length = (length + 3) & ~3;
830 cam_fill_ataio(ataio,
838 ata_28bit_cmd(ataio, ATA_SEP_ATTN,
839 pcv ? page_code : 0, 0x02, length / 4);
843 semb_send_diagnostic(struct ccb_ataio *ataio,
844 u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
845 uint8_t tag_action, uint8_t *data_ptr, uint16_t length, uint32_t timeout)
848 length = min(length, 1020);
849 length = (length + 3) & ~3;
850 cam_fill_ataio(ataio,
853 /*flags*/length ? CAM_DIR_OUT : CAM_DIR_NONE,
858 ata_28bit_cmd(ataio, ATA_SEP_ATTN,
859 length > 0 ? data_ptr[0] : 0, 0x82, length / 4);
863 semb_read_buffer(struct ccb_ataio *ataio,
864 u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
865 uint8_t tag_action, uint8_t page_code,
866 uint8_t *data_ptr, uint16_t length, uint32_t timeout)
869 length = min(length, 1020);
870 length = (length + 3) & ~3;
871 cam_fill_ataio(ataio,
879 ata_28bit_cmd(ataio, ATA_SEP_ATTN,
880 page_code, 0x00, length / 4);
884 semb_write_buffer(struct ccb_ataio *ataio,
885 u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
886 uint8_t tag_action, uint8_t *data_ptr, uint16_t length, uint32_t timeout)
889 length = min(length, 1020);
890 length = (length + 3) & ~3;
891 cam_fill_ataio(ataio,
894 /*flags*/length ? CAM_DIR_OUT : CAM_DIR_NONE,
899 ata_28bit_cmd(ataio, ATA_SEP_ATTN,
900 length > 0 ? data_ptr[0] : 0, 0x80, length / 4);