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 0x20: return ("READ");
92 case 0x24: return ("READ48");
93 case 0x25: return ("READ_DMA48");
94 case 0x26: return ("READ_DMA_QUEUED48");
95 case 0x27: return ("READ_NATIVE_MAX_ADDRESS48");
96 case 0x29: return ("READ_MUL48");
97 case 0x2a: return ("READ_STREAM_DMA48");
98 case 0x2b: return ("READ_STREAM48");
99 case 0x2f: return ("READ_LOG_EXT");
100 case 0x30: return ("WRITE");
101 case 0x34: return ("WRITE48");
102 case 0x35: return ("WRITE_DMA48");
103 case 0x36: return ("WRITE_DMA_QUEUED48");
104 case 0x37: return ("SET_MAX_ADDRESS48");
105 case 0x39: return ("WRITE_MUL48");
106 case 0x3a: return ("WRITE_STREAM_DMA48");
107 case 0x3b: return ("WRITE_STREAM48");
108 case 0x3d: return ("WRITE_DMA_FUA48");
109 case 0x3e: return ("WRITE_DMA_QUEUED_FUA48");
110 case 0x3f: return ("WRITE_LOG_EXT");
111 case 0x40: return ("READ_VERIFY");
112 case 0x42: return ("READ_VERIFY48");
114 switch (cmd->features) {
115 case 0x55: return ("WRITE_UNCORRECTABLE48 PSEUDO");
116 case 0xaa: return ("WRITE_UNCORRECTABLE48 FLAGGED");
118 return "WRITE_UNCORRECTABLE48";
119 case 0x51: return ("CONFIGURE_STREAM");
120 case 0x60: return ("READ_FPDMA_QUEUED");
121 case 0x61: return ("WRITE_FPDMA_QUEUED");
122 case 0x63: return ("NCQ_NON_DATA");
123 case 0x64: return ("SEND_FPDMA_QUEUED");
124 case 0x65: return ("RECEIVE_FPDMA_QUEUED");
126 if (cmd->features == 0xec)
127 return ("SEP_ATTN IDENTIFY");
128 switch (cmd->lba_low) {
129 case 0x00: return ("SEP_ATTN READ BUFFER");
130 case 0x02: return ("SEP_ATTN RECEIVE DIAGNOSTIC RESULTS");
131 case 0x80: return ("SEP_ATTN WRITE BUFFER");
132 case 0x82: return ("SEP_ATTN SEND DIAGNOSTIC");
135 case 0x70: return ("SEEK");
136 case 0x87: return ("CFA_TRANSLATE_SECTOR");
137 case 0x90: return ("EXECUTE_DEVICE_DIAGNOSTIC");
138 case 0x92: return ("DOWNLOAD_MICROCODE");
139 case 0xa0: return ("PACKET");
140 case 0xa1: return ("ATAPI_IDENTIFY");
141 case 0xa2: return ("SERVICE");
143 switch(cmd->features) {
144 case 0xd0: return ("SMART READ ATTR VALUES");
145 case 0xd1: return ("SMART READ ATTR THRESHOLDS");
146 case 0xd3: return ("SMART SAVE ATTR VALUES");
147 case 0xd4: return ("SMART EXECUTE OFFLINE IMMEDIATE");
148 case 0xd5: return ("SMART READ LOG DATA");
149 case 0xd8: return ("SMART ENABLE OPERATION");
150 case 0xd9: return ("SMART DISABLE OPERATION");
151 case 0xda: return ("SMART RETURN STATUS");
154 case 0xb1: return ("DEVICE CONFIGURATION");
155 case 0xc0: return ("CFA_ERASE");
156 case 0xc4: return ("READ_MUL");
157 case 0xc5: return ("WRITE_MUL");
158 case 0xc6: return ("SET_MULTI");
159 case 0xc7: return ("READ_DMA_QUEUED");
160 case 0xc8: return ("READ_DMA");
161 case 0xca: return ("WRITE_DMA");
162 case 0xcc: return ("WRITE_DMA_QUEUED");
163 case 0xcd: return ("CFA_WRITE_MULTIPLE_WITHOUT_ERASE");
164 case 0xce: return ("WRITE_MUL_FUA48");
165 case 0xd1: return ("CHECK_MEDIA_CARD_TYPE");
166 case 0xda: return ("GET_MEDIA_STATUS");
167 case 0xde: return ("MEDIA_LOCK");
168 case 0xdf: return ("MEDIA_UNLOCK");
169 case 0xe0: return ("STANDBY_IMMEDIATE");
170 case 0xe1: return ("IDLE_IMMEDIATE");
171 case 0xe2: return ("STANDBY");
172 case 0xe3: return ("IDLE");
173 case 0xe4: return ("READ_BUFFER/PM");
174 case 0xe5: return ("CHECK_POWER_MODE");
175 case 0xe6: return ("SLEEP");
176 case 0xe7: return ("FLUSHCACHE");
177 case 0xe8: return ("WRITE_PM");
178 case 0xea: return ("FLUSHCACHE48");
179 case 0xec: return ("ATA_IDENTIFY");
180 case 0xed: return ("MEDIA_EJECT");
182 switch (cmd->features) {
183 case 0x03: return ("SETFEATURES SET TRANSFER MODE");
184 case 0x02: return ("SETFEATURES ENABLE WCACHE");
185 case 0x82: return ("SETFEATURES DISABLE WCACHE");
186 case 0x06: return ("SETFEATURES ENABLE PUIS");
187 case 0x86: return ("SETFEATURES DISABLE PUIS");
188 case 0x07: return ("SETFEATURES SPIN-UP");
189 case 0x10: return ("SETFEATURES ENABLE SATA FEATURE");
190 case 0x90: return ("SETFEATURES DISABLE SATA FEATURE");
191 case 0xaa: return ("SETFEATURES ENABLE RCACHE");
192 case 0x55: return ("SETFEATURES DISABLE RCACHE");
193 case 0x5d: return ("SETFEATURES ENABLE RELIRQ");
194 case 0xdd: return ("SETFEATURES DISABLE RELIRQ");
195 case 0x5e: return ("SETFEATURES ENABLE SRVIRQ");
196 case 0xde: return ("SETFEATURES DISABLE SRVIRQ");
198 return "SETFEATURES";
199 case 0xf1: return ("SECURITY_SET_PASSWORD");
200 case 0xf2: return ("SECURITY_UNLOCK");
201 case 0xf3: return ("SECURITY_ERASE_PREPARE");
202 case 0xf4: return ("SECURITY_ERASE_UNIT");
203 case 0xf5: return ("SECURITY_FREEZE_LOCK");
204 case 0xf6: return ("SECURITY_DISABLE_PASSWORD");
205 case 0xf8: return ("READ_NATIVE_MAX_ADDRESS");
206 case 0xf9: return ("SET_MAX_ADDRESS");
212 ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len)
220 sbuf_new(&sb, cmd_string, len, SBUF_FIXEDLEN);
221 ata_cmd_sbuf(cmd, &sb);
223 error = sbuf_finish(&sb);
224 if (error != 0 && error != ENOMEM)
227 return(sbuf_data(&sb));
231 ata_cmd_sbuf(struct ata_cmd *cmd, struct sbuf *sb)
233 sbuf_printf(sb, "%02x %02x %02x %02x "
234 "%02x %02x %02x %02x %02x %02x %02x %02x",
235 cmd->command, cmd->features,
236 cmd->lba_low, cmd->lba_mid, cmd->lba_high, cmd->device,
237 cmd->lba_low_exp, cmd->lba_mid_exp, cmd->lba_high_exp,
238 cmd->features_exp, cmd->sector_count, cmd->sector_count_exp);
242 ata_res_string(struct ata_res *res, char *res_string, size_t len)
250 sbuf_new(&sb, res_string, len, SBUF_FIXEDLEN);
251 ata_res_sbuf(res, &sb);
253 error = sbuf_finish(&sb);
254 if (error != 0 && error != ENOMEM)
257 return(sbuf_data(&sb));
261 ata_res_sbuf(struct ata_res *res, struct sbuf *sb)
264 sbuf_printf(sb, "%02x %02x %02x %02x "
265 "%02x %02x %02x %02x %02x %02x %02x",
266 res->status, res->error,
267 res->lba_low, res->lba_mid, res->lba_high, res->device,
268 res->lba_low_exp, res->lba_mid_exp, res->lba_high_exp,
269 res->sector_count, res->sector_count_exp);
275 * ata_command_sbuf() returns 0 for success and -1 for failure.
278 ata_command_sbuf(struct ccb_ataio *ataio, struct sbuf *sb)
281 sbuf_printf(sb, "%s. ACB: ",
282 ata_op_string(&ataio->cmd));
283 ata_cmd_sbuf(&ataio->cmd, sb);
289 * ata_status_abuf() returns 0 for success and -1 for failure.
292 ata_status_sbuf(struct ccb_ataio *ataio, struct sbuf *sb)
295 sbuf_printf(sb, "ATA status: %02x (%s%s%s%s%s%s%s%s)",
297 (ataio->res.status & 0x80) ? "BSY " : "",
298 (ataio->res.status & 0x40) ? "DRDY " : "",
299 (ataio->res.status & 0x20) ? "DF " : "",
300 (ataio->res.status & 0x10) ? "SERV " : "",
301 (ataio->res.status & 0x08) ? "DRQ " : "",
302 (ataio->res.status & 0x04) ? "CORR " : "",
303 (ataio->res.status & 0x02) ? "IDX " : "",
304 (ataio->res.status & 0x01) ? "ERR" : "");
305 if (ataio->res.status & 1) {
306 sbuf_printf(sb, ", error: %02x (%s%s%s%s%s%s%s%s)",
308 (ataio->res.error & 0x80) ? "ICRC " : "",
309 (ataio->res.error & 0x40) ? "UNC " : "",
310 (ataio->res.error & 0x20) ? "MC " : "",
311 (ataio->res.error & 0x10) ? "IDNF " : "",
312 (ataio->res.error & 0x08) ? "MCR " : "",
313 (ataio->res.error & 0x04) ? "ABRT " : "",
314 (ataio->res.error & 0x02) ? "NM " : "",
315 (ataio->res.error & 0x01) ? "ILI" : "");
322 ata_print_ident(struct ata_params *ident_data)
325 char product[48], revision[16], ata[12], sata[12];
327 cam_strvis(product, ident_data->model, sizeof(ident_data->model),
329 cam_strvis(revision, ident_data->revision, sizeof(ident_data->revision),
331 proto = (ident_data->config == ATA_PROTO_CFA) ? "CFA" :
332 (ident_data->config & ATA_PROTO_ATAPI) ? "ATAPI" : "ATA";
333 if (ata_version(ident_data->version_major) == 0) {
334 snprintf(ata, sizeof(ata), "%s", proto);
335 } else if (ata_version(ident_data->version_major) <= 7) {
336 snprintf(ata, sizeof(ata), "%s-%d", proto,
337 ata_version(ident_data->version_major));
338 } else if (ata_version(ident_data->version_major) == 8) {
339 snprintf(ata, sizeof(ata), "%s8-ACS", proto);
341 snprintf(ata, sizeof(ata), "ACS-%d %s",
342 ata_version(ident_data->version_major) - 7, proto);
344 if (ident_data->satacapabilities && ident_data->satacapabilities != 0xffff) {
345 if (ident_data->satacapabilities & ATA_SATA_GEN3)
346 snprintf(sata, sizeof(sata), " SATA 3.x");
347 else if (ident_data->satacapabilities & ATA_SATA_GEN2)
348 snprintf(sata, sizeof(sata), " SATA 2.x");
349 else if (ident_data->satacapabilities & ATA_SATA_GEN1)
350 snprintf(sata, sizeof(sata), " SATA 1.x");
352 snprintf(sata, sizeof(sata), " SATA");
355 printf("<%s %s> %s%s device\n", product, revision, ata, sata);
359 ata_print_ident_short(struct ata_params *ident_data)
361 char product[48], revision[16];
363 cam_strvis(product, ident_data->model, sizeof(ident_data->model),
365 cam_strvis(revision, ident_data->revision, sizeof(ident_data->revision),
367 printf("<%s %s>", product, revision);
371 semb_print_ident(struct sep_identify_data *ident_data)
373 char vendor[9], product[17], revision[5], fw[5], in[7], ins[5];
375 cam_strvis(vendor, ident_data->vendor_id, 8, sizeof(vendor));
376 cam_strvis(product, ident_data->product_id, 16, sizeof(product));
377 cam_strvis(revision, ident_data->product_rev, 4, sizeof(revision));
378 cam_strvis(fw, ident_data->firmware_rev, 4, sizeof(fw));
379 cam_strvis(in, ident_data->interface_id, 6, sizeof(in));
380 cam_strvis(ins, ident_data->interface_rev, 4, sizeof(ins));
381 printf("<%s %s %s %s> SEMB %s %s device\n",
382 vendor, product, revision, fw, in, ins);
386 semb_print_ident_short(struct sep_identify_data *ident_data)
388 char vendor[9], product[17], revision[5], fw[5];
390 cam_strvis(vendor, ident_data->vendor_id, 8, sizeof(vendor));
391 cam_strvis(product, ident_data->product_id, 16, sizeof(product));
392 cam_strvis(revision, ident_data->product_rev, 4, sizeof(revision));
393 cam_strvis(fw, ident_data->firmware_rev, 4, sizeof(fw));
394 printf("<%s %s %s %s>", vendor, product, revision, fw);
398 ata_logical_sector_size(struct ata_params *ident_data)
400 if ((ident_data->pss & ATA_PSS_VALID_MASK) == ATA_PSS_VALID_VALUE &&
401 (ident_data->pss & ATA_PSS_LSSABOVE512)) {
402 return (((u_int32_t)ident_data->lss_1 |
403 ((u_int32_t)ident_data->lss_2 << 16)) * 2);
409 ata_physical_sector_size(struct ata_params *ident_data)
411 if ((ident_data->pss & ATA_PSS_VALID_MASK) == ATA_PSS_VALID_VALUE) {
412 if (ident_data->pss & ATA_PSS_MULTLS) {
413 return ((uint64_t)ata_logical_sector_size(ident_data) *
414 (1 << (ident_data->pss & ATA_PSS_LSPPS)));
416 return (uint64_t)ata_logical_sector_size(ident_data);
423 ata_logical_sector_offset(struct ata_params *ident_data)
425 if ((ident_data->lsalign & 0xc000) == 0x4000) {
426 return ((uint64_t)ata_logical_sector_size(ident_data) *
427 (ident_data->lsalign & 0x3fff));
433 ata_28bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint8_t features,
434 uint32_t lba, uint8_t sector_count)
436 bzero(&ataio->cmd, sizeof(ataio->cmd));
437 ataio->cmd.flags = 0;
438 if (cmd == ATA_READ_DMA ||
439 cmd == ATA_READ_DMA_QUEUED ||
440 cmd == ATA_WRITE_DMA ||
441 cmd == ATA_WRITE_DMA_QUEUED)
442 ataio->cmd.flags |= CAM_ATAIO_DMA;
443 ataio->cmd.command = cmd;
444 ataio->cmd.features = features;
445 ataio->cmd.lba_low = lba;
446 ataio->cmd.lba_mid = lba >> 8;
447 ataio->cmd.lba_high = lba >> 16;
448 ataio->cmd.device = ATA_DEV_LBA | ((lba >> 24) & 0x0f);
449 ataio->cmd.sector_count = sector_count;
453 ata_48bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint16_t features,
454 uint64_t lba, uint16_t sector_count)
457 ataio->cmd.flags = CAM_ATAIO_48BIT;
458 if (cmd == ATA_READ_DMA48 ||
459 cmd == ATA_READ_DMA_QUEUED48 ||
460 cmd == ATA_READ_STREAM_DMA48 ||
461 cmd == ATA_WRITE_DMA48 ||
462 cmd == ATA_WRITE_DMA_FUA48 ||
463 cmd == ATA_WRITE_DMA_QUEUED48 ||
464 cmd == ATA_WRITE_DMA_QUEUED_FUA48 ||
465 cmd == ATA_WRITE_STREAM_DMA48 ||
466 cmd == ATA_DATA_SET_MANAGEMENT)
467 ataio->cmd.flags |= CAM_ATAIO_DMA;
468 ataio->cmd.command = cmd;
469 ataio->cmd.features = features;
470 ataio->cmd.lba_low = lba;
471 ataio->cmd.lba_mid = lba >> 8;
472 ataio->cmd.lba_high = lba >> 16;
473 ataio->cmd.device = ATA_DEV_LBA;
474 ataio->cmd.lba_low_exp = lba >> 24;
475 ataio->cmd.lba_mid_exp = lba >> 32;
476 ataio->cmd.lba_high_exp = lba >> 40;
477 ataio->cmd.features_exp = features >> 8;
478 ataio->cmd.sector_count = sector_count;
479 ataio->cmd.sector_count_exp = sector_count >> 8;
480 ataio->cmd.control = 0;
484 ata_ncq_cmd(struct ccb_ataio *ataio, uint8_t cmd,
485 uint64_t lba, uint16_t sector_count)
488 ataio->cmd.flags = CAM_ATAIO_48BIT | CAM_ATAIO_FPDMA;
489 ataio->cmd.command = cmd;
490 ataio->cmd.features = sector_count;
491 ataio->cmd.lba_low = lba;
492 ataio->cmd.lba_mid = lba >> 8;
493 ataio->cmd.lba_high = lba >> 16;
494 ataio->cmd.device = ATA_DEV_LBA;
495 ataio->cmd.lba_low_exp = lba >> 24;
496 ataio->cmd.lba_mid_exp = lba >> 32;
497 ataio->cmd.lba_high_exp = lba >> 40;
498 ataio->cmd.features_exp = sector_count >> 8;
499 ataio->cmd.sector_count = 0;
500 ataio->cmd.sector_count_exp = 0;
501 ataio->cmd.control = 0;
505 ata_reset_cmd(struct ccb_ataio *ataio)
507 bzero(&ataio->cmd, sizeof(ataio->cmd));
508 ataio->cmd.flags = CAM_ATAIO_CONTROL | CAM_ATAIO_NEEDRESULT;
509 ataio->cmd.control = 0x04;
513 ata_pm_read_cmd(struct ccb_ataio *ataio, int reg, int port)
515 bzero(&ataio->cmd, sizeof(ataio->cmd));
516 ataio->cmd.flags = CAM_ATAIO_NEEDRESULT;
517 ataio->cmd.command = ATA_READ_PM;
518 ataio->cmd.features = reg;
519 ataio->cmd.device = port & 0x0f;
523 ata_pm_write_cmd(struct ccb_ataio *ataio, int reg, int port, uint32_t val)
525 bzero(&ataio->cmd, sizeof(ataio->cmd));
526 ataio->cmd.flags = 0;
527 ataio->cmd.command = ATA_WRITE_PM;
528 ataio->cmd.features = reg;
529 ataio->cmd.sector_count = val;
530 ataio->cmd.lba_low = val >> 8;
531 ataio->cmd.lba_mid = val >> 16;
532 ataio->cmd.lba_high = val >> 24;
533 ataio->cmd.device = port & 0x0f;
537 ata_bswap(int8_t *buf, int len)
539 u_int16_t *ptr = (u_int16_t*)(buf + len);
541 while (--ptr >= (u_int16_t*)buf)
542 *ptr = be16toh(*ptr);
546 ata_btrim(int8_t *buf, int len)
550 for (ptr = buf; ptr < buf+len; ++ptr)
551 if (!*ptr || *ptr == '_')
553 for (ptr = buf + len - 1; ptr >= buf && *ptr == ' '; --ptr)
558 ata_bpack(int8_t *src, int8_t *dst, int len)
562 for (i = j = blank = 0 ; i < len; i++) {
563 if (blank && src[i] == ' ') continue;
564 if (blank && src[i] != ' ') {
581 ata_max_pmode(struct ata_params *ap)
583 if (ap->atavalid & ATA_FLAG_64_70) {
584 if (ap->apiomodes & 0x02)
586 if (ap->apiomodes & 0x01)
589 if (ap->mwdmamodes & 0x04)
591 if (ap->mwdmamodes & 0x02)
593 if (ap->mwdmamodes & 0x01)
595 if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x200)
597 if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x100)
599 if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x000)
605 ata_max_wmode(struct ata_params *ap)
607 if (ap->mwdmamodes & 0x04)
609 if (ap->mwdmamodes & 0x02)
611 if (ap->mwdmamodes & 0x01)
617 ata_max_umode(struct ata_params *ap)
619 if (ap->atavalid & ATA_FLAG_88) {
620 if (ap->udmamodes & 0x40)
622 if (ap->udmamodes & 0x20)
624 if (ap->udmamodes & 0x10)
626 if (ap->udmamodes & 0x08)
628 if (ap->udmamodes & 0x04)
630 if (ap->udmamodes & 0x02)
632 if (ap->udmamodes & 0x01)
639 ata_max_mode(struct ata_params *ap, int maxmode)
643 maxmode = ATA_DMA_MAX;
644 if (maxmode >= ATA_UDMA0 && ata_max_umode(ap) > 0)
645 return (min(maxmode, ata_max_umode(ap)));
646 if (maxmode >= ATA_WDMA0 && ata_max_wmode(ap) > 0)
647 return (min(maxmode, ata_max_wmode(ap)));
648 return (min(maxmode, ata_max_pmode(ap)));
652 ata_mode2string(int mode)
655 case -1: return "UNSUPPORTED";
656 case 0: return "NONE";
657 case ATA_PIO0: return "PIO0";
658 case ATA_PIO1: return "PIO1";
659 case ATA_PIO2: return "PIO2";
660 case ATA_PIO3: return "PIO3";
661 case ATA_PIO4: return "PIO4";
662 case ATA_WDMA0: return "WDMA0";
663 case ATA_WDMA1: return "WDMA1";
664 case ATA_WDMA2: return "WDMA2";
665 case ATA_UDMA0: return "UDMA0";
666 case ATA_UDMA1: return "UDMA1";
667 case ATA_UDMA2: return "UDMA2";
668 case ATA_UDMA3: return "UDMA3";
669 case ATA_UDMA4: return "UDMA4";
670 case ATA_UDMA5: return "UDMA5";
671 case ATA_UDMA6: return "UDMA6";
673 if (mode & ATA_DMA_MASK)
681 ata_string2mode(char *str)
683 if (!strcasecmp(str, "PIO0")) return (ATA_PIO0);
684 if (!strcasecmp(str, "PIO1")) return (ATA_PIO1);
685 if (!strcasecmp(str, "PIO2")) return (ATA_PIO2);
686 if (!strcasecmp(str, "PIO3")) return (ATA_PIO3);
687 if (!strcasecmp(str, "PIO4")) return (ATA_PIO4);
688 if (!strcasecmp(str, "WDMA0")) return (ATA_WDMA0);
689 if (!strcasecmp(str, "WDMA1")) return (ATA_WDMA1);
690 if (!strcasecmp(str, "WDMA2")) return (ATA_WDMA2);
691 if (!strcasecmp(str, "UDMA0")) return (ATA_UDMA0);
692 if (!strcasecmp(str, "UDMA16")) return (ATA_UDMA0);
693 if (!strcasecmp(str, "UDMA1")) return (ATA_UDMA1);
694 if (!strcasecmp(str, "UDMA25")) return (ATA_UDMA1);
695 if (!strcasecmp(str, "UDMA2")) return (ATA_UDMA2);
696 if (!strcasecmp(str, "UDMA33")) return (ATA_UDMA2);
697 if (!strcasecmp(str, "UDMA3")) return (ATA_UDMA3);
698 if (!strcasecmp(str, "UDMA44")) return (ATA_UDMA3);
699 if (!strcasecmp(str, "UDMA4")) return (ATA_UDMA4);
700 if (!strcasecmp(str, "UDMA66")) return (ATA_UDMA4);
701 if (!strcasecmp(str, "UDMA5")) return (ATA_UDMA5);
702 if (!strcasecmp(str, "UDMA100")) return (ATA_UDMA5);
703 if (!strcasecmp(str, "UDMA6")) return (ATA_UDMA6);
704 if (!strcasecmp(str, "UDMA133")) return (ATA_UDMA6);
710 ata_mode2speed(int mode)
748 ata_revision2speed(int revision)
762 ata_speed2revision(u_int speed)
779 ata_identify_match(caddr_t identbuffer, caddr_t table_entry)
781 struct scsi_inquiry_pattern *entry;
782 struct ata_params *ident;
784 entry = (struct scsi_inquiry_pattern *)table_entry;
785 ident = (struct ata_params *)identbuffer;
787 if ((cam_strmatch(ident->model, entry->product,
788 sizeof(ident->model)) == 0)
789 && (cam_strmatch(ident->revision, entry->revision,
790 sizeof(ident->revision)) == 0)) {
797 ata_static_identify_match(caddr_t identbuffer, caddr_t table_entry)
799 struct scsi_static_inquiry_pattern *entry;
800 struct ata_params *ident;
802 entry = (struct scsi_static_inquiry_pattern *)table_entry;
803 ident = (struct ata_params *)identbuffer;
805 if ((cam_strmatch(ident->model, entry->product,
806 sizeof(ident->model)) == 0)
807 && (cam_strmatch(ident->revision, entry->revision,
808 sizeof(ident->revision)) == 0)) {
815 semb_receive_diagnostic_results(struct ccb_ataio *ataio,
816 u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
817 uint8_t tag_action, int pcv, uint8_t page_code,
818 uint8_t *data_ptr, uint16_t length, uint32_t timeout)
821 length = min(length, 1020);
822 length = (length + 3) & ~3;
823 cam_fill_ataio(ataio,
831 ata_28bit_cmd(ataio, ATA_SEP_ATTN,
832 pcv ? page_code : 0, 0x02, length / 4);
836 semb_send_diagnostic(struct ccb_ataio *ataio,
837 u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
838 uint8_t tag_action, uint8_t *data_ptr, uint16_t length, uint32_t timeout)
841 length = min(length, 1020);
842 length = (length + 3) & ~3;
843 cam_fill_ataio(ataio,
846 /*flags*/length ? CAM_DIR_OUT : CAM_DIR_NONE,
851 ata_28bit_cmd(ataio, ATA_SEP_ATTN,
852 length > 0 ? data_ptr[0] : 0, 0x82, length / 4);
856 semb_read_buffer(struct ccb_ataio *ataio,
857 u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
858 uint8_t tag_action, uint8_t page_code,
859 uint8_t *data_ptr, uint16_t length, uint32_t timeout)
862 length = min(length, 1020);
863 length = (length + 3) & ~3;
864 cam_fill_ataio(ataio,
872 ata_28bit_cmd(ataio, ATA_SEP_ATTN,
873 page_code, 0x00, length / 4);
877 semb_write_buffer(struct ccb_ataio *ataio,
878 u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
879 uint8_t tag_action, uint8_t *data_ptr, uint16_t length, uint32_t timeout)
882 length = min(length, 1020);
883 length = (length + 3) & ~3;
884 cam_fill_ataio(ataio,
887 /*flags*/length ? CAM_DIR_OUT : CAM_DIR_NONE,
892 ata_28bit_cmd(ataio, ATA_SEP_ATTN,
893 length > 0 ? data_ptr[0] : 0, 0x80, length / 4);