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) {
78 case 0x00: return ("NOP");
79 case 0x03: return ("CFA_REQUEST_EXTENDED_ERROR");
81 switch (cmd->features) {
82 case 0x01: return ("DSM TRIM");
85 case 0x08: return ("DEVICE_RESET");
86 case 0x20: return ("READ");
87 case 0x24: return ("READ48");
88 case 0x25: return ("READ_DMA48");
89 case 0x26: return ("READ_DMA_QUEUED48");
90 case 0x27: return ("READ_NATIVE_MAX_ADDRESS48");
91 case 0x29: return ("READ_MUL48");
92 case 0x2a: return ("READ_STREAM_DMA48");
93 case 0x2b: return ("READ_STREAM48");
94 case 0x2f: return ("READ_LOG_EXT");
95 case 0x30: return ("WRITE");
96 case 0x34: return ("WRITE48");
97 case 0x35: return ("WRITE_DMA48");
98 case 0x36: return ("WRITE_DMA_QUEUED48");
99 case 0x37: return ("SET_MAX_ADDRESS48");
100 case 0x39: return ("WRITE_MUL48");
101 case 0x3a: return ("WRITE_STREAM_DMA48");
102 case 0x3b: return ("WRITE_STREAM48");
103 case 0x3d: return ("WRITE_DMA_FUA48");
104 case 0x3e: return ("WRITE_DMA_QUEUED_FUA48");
105 case 0x3f: return ("WRITE_LOG_EXT");
106 case 0x40: return ("READ_VERIFY");
107 case 0x42: return ("READ_VERIFY48");
108 case 0x51: return ("CONFIGURE_STREAM");
109 case 0x60: return ("READ_FPDMA_QUEUED");
110 case 0x61: return ("WRITE_FPDMA_QUEUED");
111 case 0x63: return ("NCQ_NON_DATA");
112 case 0x64: return ("SEND_FPDMA_QUEUED");
113 case 0x65: return ("RECEIVE_FPDMA_QUEUED");
115 if (cmd->features == 0xec)
116 return ("SEP_ATTN IDENTIFY");
117 switch (cmd->lba_low) {
118 case 0x00: return ("SEP_ATTN READ BUFFER");
119 case 0x02: return ("SEP_ATTN RECEIVE DIAGNOSTIC RESULTS");
120 case 0x80: return ("SEP_ATTN WRITE BUFFER");
121 case 0x82: return ("SEP_ATTN SEND DIAGNOSTIC");
124 case 0x70: return ("SEEK");
125 case 0x87: return ("CFA_TRANSLATE_SECTOR");
126 case 0x90: return ("EXECUTE_DEVICE_DIAGNOSTIC");
127 case 0x92: return ("DOWNLOAD_MICROCODE");
128 case 0xa0: return ("PACKET");
129 case 0xa1: return ("ATAPI_IDENTIFY");
130 case 0xa2: return ("SERVICE");
131 case 0xb0: return ("SMART");
132 case 0xb1: return ("DEVICE CONFIGURATION");
133 case 0xc0: return ("CFA_ERASE");
134 case 0xc4: return ("READ_MUL");
135 case 0xc5: return ("WRITE_MUL");
136 case 0xc6: return ("SET_MULTI");
137 case 0xc7: return ("READ_DMA_QUEUED");
138 case 0xc8: return ("READ_DMA");
139 case 0xca: return ("WRITE_DMA");
140 case 0xcc: return ("WRITE_DMA_QUEUED");
141 case 0xcd: return ("CFA_WRITE_MULTIPLE_WITHOUT_ERASE");
142 case 0xce: return ("WRITE_MUL_FUA48");
143 case 0xd1: return ("CHECK_MEDIA_CARD_TYPE");
144 case 0xda: return ("GET_MEDIA_STATUS");
145 case 0xde: return ("MEDIA_LOCK");
146 case 0xdf: return ("MEDIA_UNLOCK");
147 case 0xe0: return ("STANDBY_IMMEDIATE");
148 case 0xe1: return ("IDLE_IMMEDIATE");
149 case 0xe2: return ("STANDBY");
150 case 0xe3: return ("IDLE");
151 case 0xe4: return ("READ_BUFFER/PM");
152 case 0xe5: return ("CHECK_POWER_MODE");
153 case 0xe6: return ("SLEEP");
154 case 0xe7: return ("FLUSHCACHE");
155 case 0xe8: return ("WRITE_PM");
156 case 0xea: return ("FLUSHCACHE48");
157 case 0xec: return ("ATA_IDENTIFY");
158 case 0xed: return ("MEDIA_EJECT");
160 switch (cmd->features) {
161 case 0x03: return ("SETFEATURES SET TRANSFER MODE");
162 case 0x02: return ("SETFEATURES ENABLE WCACHE");
163 case 0x82: return ("SETFEATURES DISABLE WCACHE");
164 case 0x06: return ("SETFEATURES ENABLE PUIS");
165 case 0x86: return ("SETFEATURES DISABLE PUIS");
166 case 0x07: return ("SETFEATURES SPIN-UP");
167 case 0x10: return ("SETFEATURES ENABLE SATA FEATURE");
168 case 0x90: return ("SETFEATURES DISABLE SATA FEATURE");
169 case 0xaa: return ("SETFEATURES ENABLE RCACHE");
170 case 0x55: return ("SETFEATURES DISABLE RCACHE");
172 return "SETFEATURES";
173 case 0xf1: return ("SECURITY_SET_PASSWORD");
174 case 0xf2: return ("SECURITY_UNLOCK");
175 case 0xf3: return ("SECURITY_ERASE_PREPARE");
176 case 0xf4: return ("SECURITY_ERASE_UNIT");
177 case 0xf5: return ("SECURITY_FREEZE_LOCK");
178 case 0xf6: return ("SECURITY_DISABLE_PASSWORD");
179 case 0xf8: return ("READ_NATIVE_MAX_ADDRESS");
180 case 0xf9: return ("SET_MAX_ADDRESS");
186 ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len)
189 snprintf(cmd_string, len, "%02x %02x %02x %02x "
190 "%02x %02x %02x %02x %02x %02x %02x %02x",
191 cmd->command, cmd->features,
192 cmd->lba_low, cmd->lba_mid, cmd->lba_high, cmd->device,
193 cmd->lba_low_exp, cmd->lba_mid_exp, cmd->lba_high_exp,
194 cmd->features_exp, cmd->sector_count, cmd->sector_count_exp);
200 ata_res_string(struct ata_res *res, char *res_string, size_t len)
203 snprintf(res_string, len, "%02x %02x %02x %02x "
204 "%02x %02x %02x %02x %02x %02x %02x",
205 res->status, res->error,
206 res->lba_low, res->lba_mid, res->lba_high, res->device,
207 res->lba_low_exp, res->lba_mid_exp, res->lba_high_exp,
208 res->sector_count, res->sector_count_exp);
214 * ata_command_sbuf() returns 0 for success and -1 for failure.
217 ata_command_sbuf(struct ccb_ataio *ataio, struct sbuf *sb)
219 char cmd_str[(12 * 3) + 1];
221 sbuf_printf(sb, "%s. ACB: %s",
222 ata_op_string(&ataio->cmd),
223 ata_cmd_string(&ataio->cmd, cmd_str, sizeof(cmd_str)));
229 * ata_status_abuf() returns 0 for success and -1 for failure.
232 ata_status_sbuf(struct ccb_ataio *ataio, struct sbuf *sb)
235 sbuf_printf(sb, "ATA status: %02x (%s%s%s%s%s%s%s%s)",
237 (ataio->res.status & 0x80) ? "BSY " : "",
238 (ataio->res.status & 0x40) ? "DRDY " : "",
239 (ataio->res.status & 0x20) ? "DF " : "",
240 (ataio->res.status & 0x10) ? "SERV " : "",
241 (ataio->res.status & 0x08) ? "DRQ " : "",
242 (ataio->res.status & 0x04) ? "CORR " : "",
243 (ataio->res.status & 0x02) ? "IDX " : "",
244 (ataio->res.status & 0x01) ? "ERR" : "");
245 if (ataio->res.status & 1) {
246 sbuf_printf(sb, ", error: %02x (%s%s%s%s%s%s%s%s)",
248 (ataio->res.error & 0x80) ? "ICRC " : "",
249 (ataio->res.error & 0x40) ? "UNC " : "",
250 (ataio->res.error & 0x20) ? "MC " : "",
251 (ataio->res.error & 0x10) ? "IDNF " : "",
252 (ataio->res.error & 0x08) ? "MCR " : "",
253 (ataio->res.error & 0x04) ? "ABRT " : "",
254 (ataio->res.error & 0x02) ? "NM " : "",
255 (ataio->res.error & 0x01) ? "ILI" : "");
262 * ata_res_sbuf() returns 0 for success and -1 for failure.
265 ata_res_sbuf(struct ccb_ataio *ataio, struct sbuf *sb)
267 char res_str[(11 * 3) + 1];
269 sbuf_printf(sb, "RES: %s",
270 ata_res_string(&ataio->res, res_str, sizeof(res_str)));
276 ata_print_ident(struct ata_params *ident_data)
279 char product[48], revision[16], ata[12], sata[12];
281 cam_strvis(product, ident_data->model, sizeof(ident_data->model),
283 cam_strvis(revision, ident_data->revision, sizeof(ident_data->revision),
285 proto = (ident_data->config == ATA_PROTO_CFA) ? "CFA" :
286 (ident_data->config & ATA_PROTO_ATAPI) ? "ATAPI" : "ATA";
287 if (ata_version(ident_data->version_major) == 0) {
288 snprintf(ata, sizeof(ata), "%s", proto);
289 } else if (ata_version(ident_data->version_major) <= 7) {
290 snprintf(ata, sizeof(ata), "%s-%d", proto,
291 ata_version(ident_data->version_major));
292 } else if (ata_version(ident_data->version_major) == 8) {
293 snprintf(ata, sizeof(ata), "%s8-ACS", proto);
295 snprintf(ata, sizeof(ata), "ACS-%d %s",
296 ata_version(ident_data->version_major) - 7, proto);
298 if (ident_data->satacapabilities && ident_data->satacapabilities != 0xffff) {
299 if (ident_data->satacapabilities & ATA_SATA_GEN3)
300 snprintf(sata, sizeof(sata), " SATA 3.x");
301 else if (ident_data->satacapabilities & ATA_SATA_GEN2)
302 snprintf(sata, sizeof(sata), " SATA 2.x");
303 else if (ident_data->satacapabilities & ATA_SATA_GEN1)
304 snprintf(sata, sizeof(sata), " SATA 1.x");
306 snprintf(sata, sizeof(sata), " SATA");
309 printf("<%s %s> %s%s device\n", product, revision, ata, sata);
313 ata_print_ident_short(struct ata_params *ident_data)
315 char product[48], revision[16];
317 cam_strvis(product, ident_data->model, sizeof(ident_data->model),
319 cam_strvis(revision, ident_data->revision, sizeof(ident_data->revision),
321 printf("<%s %s>", product, revision);
325 semb_print_ident(struct sep_identify_data *ident_data)
327 char vendor[9], product[17], revision[5], fw[5], in[7], ins[5];
329 cam_strvis(vendor, ident_data->vendor_id, 8, sizeof(vendor));
330 cam_strvis(product, ident_data->product_id, 16, sizeof(product));
331 cam_strvis(revision, ident_data->product_rev, 4, sizeof(revision));
332 cam_strvis(fw, ident_data->firmware_rev, 4, sizeof(fw));
333 cam_strvis(in, ident_data->interface_id, 6, sizeof(in));
334 cam_strvis(ins, ident_data->interface_rev, 4, sizeof(ins));
335 printf("<%s %s %s %s> SEMB %s %s device\n",
336 vendor, product, revision, fw, in, ins);
340 semb_print_ident_short(struct sep_identify_data *ident_data)
342 char vendor[9], product[17], revision[5], fw[5];
344 cam_strvis(vendor, ident_data->vendor_id, 8, sizeof(vendor));
345 cam_strvis(product, ident_data->product_id, 16, sizeof(product));
346 cam_strvis(revision, ident_data->product_rev, 4, sizeof(revision));
347 cam_strvis(fw, ident_data->firmware_rev, 4, sizeof(fw));
348 printf("<%s %s %s %s>", vendor, product, revision, fw);
352 ata_logical_sector_size(struct ata_params *ident_data)
354 if ((ident_data->pss & ATA_PSS_VALID_MASK) == ATA_PSS_VALID_VALUE &&
355 (ident_data->pss & ATA_PSS_LSSABOVE512)) {
356 return (((u_int32_t)ident_data->lss_1 |
357 ((u_int32_t)ident_data->lss_2 << 16)) * 2);
363 ata_physical_sector_size(struct ata_params *ident_data)
365 if ((ident_data->pss & ATA_PSS_VALID_MASK) == ATA_PSS_VALID_VALUE) {
366 if (ident_data->pss & ATA_PSS_MULTLS) {
367 return ((uint64_t)ata_logical_sector_size(ident_data) *
368 (1 << (ident_data->pss & ATA_PSS_LSPPS)));
370 return (uint64_t)ata_logical_sector_size(ident_data);
377 ata_logical_sector_offset(struct ata_params *ident_data)
379 if ((ident_data->lsalign & 0xc000) == 0x4000) {
380 return ((uint64_t)ata_logical_sector_size(ident_data) *
381 (ident_data->lsalign & 0x3fff));
387 ata_28bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint8_t features,
388 uint32_t lba, uint8_t sector_count)
390 bzero(&ataio->cmd, sizeof(ataio->cmd));
391 ataio->cmd.flags = 0;
392 if (cmd == ATA_READ_DMA ||
393 cmd == ATA_READ_DMA_QUEUED ||
394 cmd == ATA_WRITE_DMA ||
395 cmd == ATA_WRITE_DMA_QUEUED)
396 ataio->cmd.flags |= CAM_ATAIO_DMA;
397 ataio->cmd.command = cmd;
398 ataio->cmd.features = features;
399 ataio->cmd.lba_low = lba;
400 ataio->cmd.lba_mid = lba >> 8;
401 ataio->cmd.lba_high = lba >> 16;
402 ataio->cmd.device = ATA_DEV_LBA | ((lba >> 24) & 0x0f);
403 ataio->cmd.sector_count = sector_count;
407 ata_48bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint16_t features,
408 uint64_t lba, uint16_t sector_count)
411 ataio->cmd.flags = CAM_ATAIO_48BIT;
412 if (cmd == ATA_READ_DMA48 ||
413 cmd == ATA_READ_DMA_QUEUED48 ||
414 cmd == ATA_READ_STREAM_DMA48 ||
415 cmd == ATA_WRITE_DMA48 ||
416 cmd == ATA_WRITE_DMA_FUA48 ||
417 cmd == ATA_WRITE_DMA_QUEUED48 ||
418 cmd == ATA_WRITE_DMA_QUEUED_FUA48 ||
419 cmd == ATA_WRITE_STREAM_DMA48 ||
420 cmd == ATA_DATA_SET_MANAGEMENT)
421 ataio->cmd.flags |= CAM_ATAIO_DMA;
422 ataio->cmd.command = cmd;
423 ataio->cmd.features = features;
424 ataio->cmd.lba_low = lba;
425 ataio->cmd.lba_mid = lba >> 8;
426 ataio->cmd.lba_high = lba >> 16;
427 ataio->cmd.device = ATA_DEV_LBA;
428 ataio->cmd.lba_low_exp = lba >> 24;
429 ataio->cmd.lba_mid_exp = lba >> 32;
430 ataio->cmd.lba_high_exp = lba >> 40;
431 ataio->cmd.features_exp = features >> 8;
432 ataio->cmd.sector_count = sector_count;
433 ataio->cmd.sector_count_exp = sector_count >> 8;
434 ataio->cmd.control = 0;
438 ata_ncq_cmd(struct ccb_ataio *ataio, uint8_t cmd,
439 uint64_t lba, uint16_t sector_count)
442 ataio->cmd.flags = CAM_ATAIO_48BIT | CAM_ATAIO_FPDMA;
443 ataio->cmd.command = cmd;
444 ataio->cmd.features = sector_count;
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;
449 ataio->cmd.lba_low_exp = lba >> 24;
450 ataio->cmd.lba_mid_exp = lba >> 32;
451 ataio->cmd.lba_high_exp = lba >> 40;
452 ataio->cmd.features_exp = sector_count >> 8;
453 ataio->cmd.sector_count = 0;
454 ataio->cmd.sector_count_exp = 0;
455 ataio->cmd.control = 0;
459 ata_reset_cmd(struct ccb_ataio *ataio)
461 bzero(&ataio->cmd, sizeof(ataio->cmd));
462 ataio->cmd.flags = CAM_ATAIO_CONTROL | CAM_ATAIO_NEEDRESULT;
463 ataio->cmd.control = 0x04;
467 ata_pm_read_cmd(struct ccb_ataio *ataio, int reg, int port)
469 bzero(&ataio->cmd, sizeof(ataio->cmd));
470 ataio->cmd.flags = CAM_ATAIO_NEEDRESULT;
471 ataio->cmd.command = ATA_READ_PM;
472 ataio->cmd.features = reg;
473 ataio->cmd.device = port & 0x0f;
477 ata_pm_write_cmd(struct ccb_ataio *ataio, int reg, int port, uint32_t val)
479 bzero(&ataio->cmd, sizeof(ataio->cmd));
480 ataio->cmd.flags = 0;
481 ataio->cmd.command = ATA_WRITE_PM;
482 ataio->cmd.features = reg;
483 ataio->cmd.sector_count = val;
484 ataio->cmd.lba_low = val >> 8;
485 ataio->cmd.lba_mid = val >> 16;
486 ataio->cmd.lba_high = val >> 24;
487 ataio->cmd.device = port & 0x0f;
491 ata_bswap(int8_t *buf, int len)
493 u_int16_t *ptr = (u_int16_t*)(buf + len);
495 while (--ptr >= (u_int16_t*)buf)
496 *ptr = be16toh(*ptr);
500 ata_btrim(int8_t *buf, int len)
504 for (ptr = buf; ptr < buf+len; ++ptr)
505 if (!*ptr || *ptr == '_')
507 for (ptr = buf + len - 1; ptr >= buf && *ptr == ' '; --ptr)
512 ata_bpack(int8_t *src, int8_t *dst, int len)
516 for (i = j = blank = 0 ; i < len; i++) {
517 if (blank && src[i] == ' ') continue;
518 if (blank && src[i] != ' ') {
535 ata_max_pmode(struct ata_params *ap)
537 if (ap->atavalid & ATA_FLAG_64_70) {
538 if (ap->apiomodes & 0x02)
540 if (ap->apiomodes & 0x01)
543 if (ap->mwdmamodes & 0x04)
545 if (ap->mwdmamodes & 0x02)
547 if (ap->mwdmamodes & 0x01)
549 if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x200)
551 if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x100)
553 if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x000)
559 ata_max_wmode(struct ata_params *ap)
561 if (ap->mwdmamodes & 0x04)
563 if (ap->mwdmamodes & 0x02)
565 if (ap->mwdmamodes & 0x01)
571 ata_max_umode(struct ata_params *ap)
573 if (ap->atavalid & ATA_FLAG_88) {
574 if (ap->udmamodes & 0x40)
576 if (ap->udmamodes & 0x20)
578 if (ap->udmamodes & 0x10)
580 if (ap->udmamodes & 0x08)
582 if (ap->udmamodes & 0x04)
584 if (ap->udmamodes & 0x02)
586 if (ap->udmamodes & 0x01)
593 ata_max_mode(struct ata_params *ap, int maxmode)
597 maxmode = ATA_DMA_MAX;
598 if (maxmode >= ATA_UDMA0 && ata_max_umode(ap) > 0)
599 return (min(maxmode, ata_max_umode(ap)));
600 if (maxmode >= ATA_WDMA0 && ata_max_wmode(ap) > 0)
601 return (min(maxmode, ata_max_wmode(ap)));
602 return (min(maxmode, ata_max_pmode(ap)));
606 ata_mode2string(int mode)
609 case -1: return "UNSUPPORTED";
610 case 0: return "NONE";
611 case ATA_PIO0: return "PIO0";
612 case ATA_PIO1: return "PIO1";
613 case ATA_PIO2: return "PIO2";
614 case ATA_PIO3: return "PIO3";
615 case ATA_PIO4: return "PIO4";
616 case ATA_WDMA0: return "WDMA0";
617 case ATA_WDMA1: return "WDMA1";
618 case ATA_WDMA2: return "WDMA2";
619 case ATA_UDMA0: return "UDMA0";
620 case ATA_UDMA1: return "UDMA1";
621 case ATA_UDMA2: return "UDMA2";
622 case ATA_UDMA3: return "UDMA3";
623 case ATA_UDMA4: return "UDMA4";
624 case ATA_UDMA5: return "UDMA5";
625 case ATA_UDMA6: return "UDMA6";
627 if (mode & ATA_DMA_MASK)
635 ata_string2mode(char *str)
637 if (!strcasecmp(str, "PIO0")) return (ATA_PIO0);
638 if (!strcasecmp(str, "PIO1")) return (ATA_PIO1);
639 if (!strcasecmp(str, "PIO2")) return (ATA_PIO2);
640 if (!strcasecmp(str, "PIO3")) return (ATA_PIO3);
641 if (!strcasecmp(str, "PIO4")) return (ATA_PIO4);
642 if (!strcasecmp(str, "WDMA0")) return (ATA_WDMA0);
643 if (!strcasecmp(str, "WDMA1")) return (ATA_WDMA1);
644 if (!strcasecmp(str, "WDMA2")) return (ATA_WDMA2);
645 if (!strcasecmp(str, "UDMA0")) return (ATA_UDMA0);
646 if (!strcasecmp(str, "UDMA16")) return (ATA_UDMA0);
647 if (!strcasecmp(str, "UDMA1")) return (ATA_UDMA1);
648 if (!strcasecmp(str, "UDMA25")) return (ATA_UDMA1);
649 if (!strcasecmp(str, "UDMA2")) return (ATA_UDMA2);
650 if (!strcasecmp(str, "UDMA33")) return (ATA_UDMA2);
651 if (!strcasecmp(str, "UDMA3")) return (ATA_UDMA3);
652 if (!strcasecmp(str, "UDMA44")) return (ATA_UDMA3);
653 if (!strcasecmp(str, "UDMA4")) return (ATA_UDMA4);
654 if (!strcasecmp(str, "UDMA66")) return (ATA_UDMA4);
655 if (!strcasecmp(str, "UDMA5")) return (ATA_UDMA5);
656 if (!strcasecmp(str, "UDMA100")) return (ATA_UDMA5);
657 if (!strcasecmp(str, "UDMA6")) return (ATA_UDMA6);
658 if (!strcasecmp(str, "UDMA133")) return (ATA_UDMA6);
664 ata_mode2speed(int mode)
702 ata_revision2speed(int revision)
716 ata_speed2revision(u_int speed)
733 ata_identify_match(caddr_t identbuffer, caddr_t table_entry)
735 struct scsi_inquiry_pattern *entry;
736 struct ata_params *ident;
738 entry = (struct scsi_inquiry_pattern *)table_entry;
739 ident = (struct ata_params *)identbuffer;
741 if ((cam_strmatch(ident->model, entry->product,
742 sizeof(ident->model)) == 0)
743 && (cam_strmatch(ident->revision, entry->revision,
744 sizeof(ident->revision)) == 0)) {
751 ata_static_identify_match(caddr_t identbuffer, caddr_t table_entry)
753 struct scsi_static_inquiry_pattern *entry;
754 struct ata_params *ident;
756 entry = (struct scsi_static_inquiry_pattern *)table_entry;
757 ident = (struct ata_params *)identbuffer;
759 if ((cam_strmatch(ident->model, entry->product,
760 sizeof(ident->model)) == 0)
761 && (cam_strmatch(ident->revision, entry->revision,
762 sizeof(ident->revision)) == 0)) {
769 semb_receive_diagnostic_results(struct ccb_ataio *ataio,
770 u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
771 uint8_t tag_action, int pcv, uint8_t page_code,
772 uint8_t *data_ptr, uint16_t length, uint32_t timeout)
775 length = min(length, 1020);
776 length = (length + 3) & ~3;
777 cam_fill_ataio(ataio,
785 ata_28bit_cmd(ataio, ATA_SEP_ATTN,
786 pcv ? page_code : 0, 0x02, length / 4);
790 semb_send_diagnostic(struct ccb_ataio *ataio,
791 u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
792 uint8_t tag_action, uint8_t *data_ptr, uint16_t length, uint32_t timeout)
795 length = min(length, 1020);
796 length = (length + 3) & ~3;
797 cam_fill_ataio(ataio,
800 /*flags*/length ? CAM_DIR_OUT : CAM_DIR_NONE,
805 ata_28bit_cmd(ataio, ATA_SEP_ATTN,
806 length > 0 ? data_ptr[0] : 0, 0x82, length / 4);
810 semb_read_buffer(struct ccb_ataio *ataio,
811 u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
812 uint8_t tag_action, uint8_t page_code,
813 uint8_t *data_ptr, uint16_t length, uint32_t timeout)
816 length = min(length, 1020);
817 length = (length + 3) & ~3;
818 cam_fill_ataio(ataio,
826 ata_28bit_cmd(ataio, ATA_SEP_ATTN,
827 page_code, 0x00, length / 4);
831 semb_write_buffer(struct ccb_ataio *ataio,
832 u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
833 uint8_t tag_action, uint8_t *data_ptr, uint16_t length, uint32_t timeout)
836 length = min(length, 1020);
837 length = (length + 3) & ~3;
838 cam_fill_ataio(ataio,
841 /*flags*/length ? CAM_DIR_OUT : CAM_DIR_NONE,
846 ata_28bit_cmd(ataio, ATA_SEP_ATTN,
847 length > 0 ? data_ptr[0] : 0, 0x80, length / 4);