]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/cam/ata/ata_all.c
MFC r345986:
[FreeBSD/FreeBSD.git] / sys / cam / ata / ata_all.c
1 /*-
2  * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
14  *
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.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <sys/param.h>
31
32 #ifdef _KERNEL
33 #include <opt_scsi.h>
34
35 #include <sys/systm.h>
36 #include <sys/libkern.h>
37 #include <sys/kernel.h>
38 #include <sys/sysctl.h>
39 #else
40 #include <errno.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #ifndef min
45 #define min(a,b) (((a)<(b))?(a):(b))
46 #endif
47 #endif
48
49 #include <cam/cam.h>
50 #include <cam/cam_ccb.h>
51 #include <cam/cam_queue.h>
52 #include <cam/cam_xpt.h>
53 #include <sys/ata.h>
54 #include <cam/ata/ata_all.h>
55 #include <sys/sbuf.h>
56 #include <sys/endian.h>
57
58 int
59 ata_version(int ver)
60 {
61         int bit;
62
63         if (ver == 0xffff)
64                 return 0;
65         for (bit = 15; bit >= 0; bit--)
66                 if (ver & (1<<bit))
67                         return bit;
68         return 0;
69 }
70
71 char *
72 ata_op_string(struct ata_cmd *cmd)
73 {
74
75         if (cmd->control & 0x04)
76                 return ("SOFT_RESET");
77         switch (cmd->command) {
78         case 0x00:
79                 switch (cmd->features) {
80                 case 0x00: return ("NOP FLUSHQUEUE");
81                 case 0x01: return ("NOP AUTOPOLL");
82                 }
83                 return ("NOP");
84         case 0x03: return ("CFA_REQUEST_EXTENDED_ERROR");
85         case 0x06:
86                 switch (cmd->features) {
87                 case 0x01: return ("DSM TRIM");
88                 }
89                 return "DSM";
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");
114         case 0x44: return ("ZERO_EXT");
115         case 0x45:
116                 switch (cmd->features) {
117                 case 0x55: return ("WRITE_UNCORRECTABLE48 PSEUDO");
118                 case 0xaa: return ("WRITE_UNCORRECTABLE48 FLAGGED");
119                 }
120                 return "WRITE_UNCORRECTABLE48";
121         case 0x47: return ("READ_LOG_DMA_EXT");
122         case 0x4a: return ("ZAC_MANAGEMENT_IN");
123         case 0x51: return ("CONFIGURE_STREAM");
124         case 0x57: return ("WRITE_LOG_DMA_EXT");
125         case 0x5b: return ("TRUSTED_NON_DATA");
126         case 0x5c: return ("TRUSTED_RECEIVE");
127         case 0x5d: return ("TRUSTED_RECEIVE_DMA");
128         case 0x5e: return ("TRUSTED_SEND");
129         case 0x5f: return ("TRUSTED_SEND_DMA");
130         case 0x60: return ("READ_FPDMA_QUEUED");
131         case 0x61: return ("WRITE_FPDMA_QUEUED");
132         case 0x63:
133                 switch (cmd->features & 0xf) {
134                 case 0x00: return ("NCQ_NON_DATA ABORT NCQ QUEUE");
135                 case 0x01: return ("NCQ_NON_DATA DEADLINE HANDLING");
136                 case 0x05: return ("NCQ_NON_DATA SET FEATURES");
137                 /*
138                  * XXX KDM need common decoding between NCQ and non-NCQ
139                  * versions of SET FEATURES.
140                  */
141                 case 0x06: return ("NCQ_NON_DATA ZERO EXT");
142                 case 0x07: return ("NCQ_NON_DATA ZAC MANAGEMENT OUT");
143                 }
144                 return ("NCQ_NON_DATA");
145         case 0x64:
146                 switch (cmd->sector_count_exp & 0xf) {
147                 case 0x00: return ("SEND_FPDMA_QUEUED DATA SET MANAGEMENT");
148                 case 0x02: return ("SEND_FPDMA_QUEUED WRITE LOG DMA EXT");
149                 case 0x03: return ("SEND_FPDMA_QUEUED ZAC MANAGEMENT OUT");
150                 case 0x04: return ("SEND_FPDMA_QUEUED DATA SET MANAGEMENT XL");
151                 }
152                 return ("SEND_FPDMA_QUEUED");
153         case 0x65:
154                 switch (cmd->sector_count_exp & 0xf) {
155                 case 0x01: return ("RECEIVE_FPDMA_QUEUED READ LOG DMA EXT");
156                 case 0x02: return ("RECEIVE_FPDMA_QUEUED ZAC MANAGEMENT IN");
157                 }
158                 return ("RECEIVE_FPDMA_QUEUED");
159         case 0x67:
160                 if (cmd->features == 0xec)
161                         return ("SEP_ATTN IDENTIFY");
162                 switch (cmd->lba_low) {
163                 case 0x00: return ("SEP_ATTN READ BUFFER");
164                 case 0x02: return ("SEP_ATTN RECEIVE DIAGNOSTIC RESULTS");
165                 case 0x80: return ("SEP_ATTN WRITE BUFFER");
166                 case 0x82: return ("SEP_ATTN SEND DIAGNOSTIC");
167                 }
168                 return ("SEP_ATTN");
169         case 0x70: return ("SEEK");
170         case 0x77: return ("SET_DATE_TIME_EXT");
171         case 0x78: return ("ACCESSIBLE_MAX_ADDRESS_CONFIGURATION");
172         case 0x87: return ("CFA_TRANSLATE_SECTOR");
173         case 0x90: return ("EXECUTE_DEVICE_DIAGNOSTIC");
174         case 0x92: return ("DOWNLOAD_MICROCODE");
175         case 0x93: return ("DOWNLOAD_MICROCODE_DMA");
176         case 0x9a: return ("ZAC_MANAGEMENT_OUT");
177         case 0xa0: return ("PACKET");
178         case 0xa1: return ("ATAPI_IDENTIFY");
179         case 0xa2: return ("SERVICE");
180         case 0xb0:
181                 switch(cmd->features) {
182                 case 0xd0: return ("SMART READ ATTR VALUES");
183                 case 0xd1: return ("SMART READ ATTR THRESHOLDS");
184                 case 0xd3: return ("SMART SAVE ATTR VALUES");
185                 case 0xd4: return ("SMART EXECUTE OFFLINE IMMEDIATE");
186                 case 0xd5: return ("SMART READ LOG DATA");
187                 case 0xd8: return ("SMART ENABLE OPERATION");
188                 case 0xd9: return ("SMART DISABLE OPERATION");
189                 case 0xda: return ("SMART RETURN STATUS");
190                 }
191                 return ("SMART");
192         case 0xb1: return ("DEVICE CONFIGURATION");
193         case 0xb4: return ("SANITIZE_DEVICE");
194         case 0xc0: return ("CFA_ERASE");
195         case 0xc4: return ("READ_MUL");
196         case 0xc5: return ("WRITE_MUL");
197         case 0xc6: return ("SET_MULTI");
198         case 0xc7: return ("READ_DMA_QUEUED");
199         case 0xc8: return ("READ_DMA");
200         case 0xca: return ("WRITE_DMA");
201         case 0xcc: return ("WRITE_DMA_QUEUED");
202         case 0xcd: return ("CFA_WRITE_MULTIPLE_WITHOUT_ERASE");
203         case 0xce: return ("WRITE_MUL_FUA48");
204         case 0xd1: return ("CHECK_MEDIA_CARD_TYPE");
205         case 0xda: return ("GET_MEDIA_STATUS");
206         case 0xde: return ("MEDIA_LOCK");
207         case 0xdf: return ("MEDIA_UNLOCK");
208         case 0xe0: return ("STANDBY_IMMEDIATE");
209         case 0xe1: return ("IDLE_IMMEDIATE");
210         case 0xe2: return ("STANDBY");
211         case 0xe3: return ("IDLE");
212         case 0xe4: return ("READ_BUFFER/PM");
213         case 0xe5: return ("CHECK_POWER_MODE");
214         case 0xe6: return ("SLEEP");
215         case 0xe7: return ("FLUSHCACHE");
216         case 0xe8: return ("WRITE_BUFFER/PM");
217         case 0xe9: return ("READ_BUFFER_DMA");
218         case 0xea: return ("FLUSHCACHE48");
219         case 0xeb: return ("WRITE_BUFFER_DMA");
220         case 0xec: return ("ATA_IDENTIFY");
221         case 0xed: return ("MEDIA_EJECT");
222         case 0xef:
223                 /*
224                  * XXX KDM need common decoding between NCQ and non-NCQ
225                  * versions of SET FEATURES.
226                  */
227                 switch (cmd->features) {
228                 case 0x02: return ("SETFEATURES ENABLE WCACHE");
229                 case 0x03: return ("SETFEATURES SET TRANSFER MODE");
230                 case 0x04: return ("SETFEATURES ENABLE APM");
231                 case 0x06: return ("SETFEATURES ENABLE PUIS");
232                 case 0x07: return ("SETFEATURES SPIN-UP");
233                 case 0x0b: return ("SETFEATURES ENABLE WRITE READ VERIFY");
234                 case 0x0c: return ("SETFEATURES ENABLE DEVICE LIFE CONTROL");
235                 case 0x10: return ("SETFEATURES ENABLE SATA FEATURE");
236                 case 0x41: return ("SETFEATURES ENABLE FREEFALL CONTROL");
237                 case 0x43: return ("SETFEATURES SET MAX HOST INT SECT TIMES");
238                 case 0x45: return ("SETFEATURES SET RATE BASIS");
239                 case 0x4a: return ("SETFEATURES EXTENDED POWER CONDITIONS");
240                 case 0x55: return ("SETFEATURES DISABLE RCACHE");
241                 case 0x5d: return ("SETFEATURES ENABLE RELIRQ");
242                 case 0x5e: return ("SETFEATURES ENABLE SRVIRQ");
243                 case 0x62: return ("SETFEATURES LONG PHYS SECT ALIGN ERC");
244                 case 0x63: return ("SETFEATURES DSN");
245                 case 0x66: return ("SETFEATURES DISABLE DEFAULTS");
246                 case 0x82: return ("SETFEATURES DISABLE WCACHE");
247                 case 0x85: return ("SETFEATURES DISABLE APM");
248                 case 0x86: return ("SETFEATURES DISABLE PUIS");
249                 case 0x8b: return ("SETFEATURES DISABLE WRITE READ VERIFY");
250                 case 0x8c: return ("SETFEATURES DISABLE DEVICE LIFE CONTROL");
251                 case 0x90: return ("SETFEATURES DISABLE SATA FEATURE");
252                 case 0xaa: return ("SETFEATURES ENABLE RCACHE");
253                 case 0xC1: return ("SETFEATURES DISABLE FREEFALL CONTROL");
254                 case 0xC3: return ("SETFEATURES SENSE DATA REPORTING");
255                 case 0xC4: return ("SETFEATURES NCQ SENSE DATA RETURN");
256                 case 0xCC: return ("SETFEATURES ENABLE DEFAULTS");
257                 case 0xdd: return ("SETFEATURES DISABLE RELIRQ");
258                 case 0xde: return ("SETFEATURES DISABLE SRVIRQ");
259                 }
260                 return "SETFEATURES";
261         case 0xf1: return ("SECURITY_SET_PASSWORD");
262         case 0xf2: return ("SECURITY_UNLOCK");
263         case 0xf3: return ("SECURITY_ERASE_PREPARE");
264         case 0xf4: return ("SECURITY_ERASE_UNIT");
265         case 0xf5: return ("SECURITY_FREEZE_LOCK");
266         case 0xf6: return ("SECURITY_DISABLE_PASSWORD");
267         case 0xf8: return ("READ_NATIVE_MAX_ADDRESS");
268         case 0xf9: return ("SET_MAX_ADDRESS");
269         }
270         return "UNKNOWN";
271 }
272
273 char *
274 ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len)
275 {
276         struct sbuf sb;
277         int error;
278
279         if (len == 0)
280                 return ("");
281
282         sbuf_new(&sb, cmd_string, len, SBUF_FIXEDLEN);
283         ata_cmd_sbuf(cmd, &sb);
284
285         error = sbuf_finish(&sb);
286         if (error != 0 && error != ENOMEM)
287                 return ("");
288
289         return(sbuf_data(&sb));
290 }
291
292 void
293 ata_cmd_sbuf(struct ata_cmd *cmd, struct sbuf *sb)
294 {
295         sbuf_printf(sb, "%02x %02x %02x %02x "
296             "%02x %02x %02x %02x %02x %02x %02x %02x",
297             cmd->command, cmd->features,
298             cmd->lba_low, cmd->lba_mid, cmd->lba_high, cmd->device,
299             cmd->lba_low_exp, cmd->lba_mid_exp, cmd->lba_high_exp,
300             cmd->features_exp, cmd->sector_count, cmd->sector_count_exp);
301 }
302
303 char *
304 ata_res_string(struct ata_res *res, char *res_string, size_t len)
305 {
306         struct sbuf sb;
307         int error;
308
309         if (len == 0)
310                 return ("");
311
312         sbuf_new(&sb, res_string, len, SBUF_FIXEDLEN);
313         ata_res_sbuf(res, &sb);
314
315         error = sbuf_finish(&sb);
316         if (error != 0 && error != ENOMEM)
317                 return ("");
318
319         return(sbuf_data(&sb));
320 }
321
322 int
323 ata_res_sbuf(struct ata_res *res, struct sbuf *sb)
324 {
325
326         sbuf_printf(sb, "%02x %02x %02x %02x "
327             "%02x %02x %02x %02x %02x %02x %02x",
328             res->status, res->error,
329             res->lba_low, res->lba_mid, res->lba_high, res->device,
330             res->lba_low_exp, res->lba_mid_exp, res->lba_high_exp,
331             res->sector_count, res->sector_count_exp);
332
333         return (0);
334 }
335
336 /*
337  * ata_command_sbuf() returns 0 for success and -1 for failure.
338  */
339 int
340 ata_command_sbuf(struct ccb_ataio *ataio, struct sbuf *sb)
341 {
342
343         sbuf_printf(sb, "%s. ACB: ",
344             ata_op_string(&ataio->cmd));
345         ata_cmd_sbuf(&ataio->cmd, sb);
346
347         return(0);
348 }
349
350 /*
351  * ata_status_abuf() returns 0 for success and -1 for failure.
352  */
353 int
354 ata_status_sbuf(struct ccb_ataio *ataio, struct sbuf *sb)
355 {
356
357         sbuf_printf(sb, "ATA status: %02x (%s%s%s%s%s%s%s%s)",
358             ataio->res.status,
359             (ataio->res.status & 0x80) ? "BSY " : "",
360             (ataio->res.status & 0x40) ? "DRDY " : "",
361             (ataio->res.status & 0x20) ? "DF " : "",
362             (ataio->res.status & 0x10) ? "SERV " : "",
363             (ataio->res.status & 0x08) ? "DRQ " : "",
364             (ataio->res.status & 0x04) ? "CORR " : "",
365             (ataio->res.status & 0x02) ? "IDX " : "",
366             (ataio->res.status & 0x01) ? "ERR" : "");
367         if (ataio->res.status & 1) {
368             sbuf_printf(sb, ", error: %02x (%s%s%s%s%s%s%s%s)",
369                 ataio->res.error,
370                 (ataio->res.error & 0x80) ? "ICRC " : "",
371                 (ataio->res.error & 0x40) ? "UNC " : "",
372                 (ataio->res.error & 0x20) ? "MC " : "",
373                 (ataio->res.error & 0x10) ? "IDNF " : "",
374                 (ataio->res.error & 0x08) ? "MCR " : "",
375                 (ataio->res.error & 0x04) ? "ABRT " : "",
376                 (ataio->res.error & 0x02) ? "NM " : "",
377                 (ataio->res.error & 0x01) ? "ILI" : "");
378         }
379
380         return(0);
381 }
382
383 void
384 ata_print_ident(struct ata_params *ident_data)
385 {
386         const char *proto;
387         char product[48], revision[16], ata[12], sata[12];
388
389         cam_strvis(product, ident_data->model, sizeof(ident_data->model),
390                    sizeof(product));
391         cam_strvis(revision, ident_data->revision, sizeof(ident_data->revision),
392                    sizeof(revision));
393         proto = (ident_data->config == ATA_PROTO_CFA) ? "CFA" :
394                 (ident_data->config & ATA_PROTO_ATAPI) ? "ATAPI" : "ATA";
395         if (ata_version(ident_data->version_major) == 0) {
396                 snprintf(ata, sizeof(ata), "%s", proto);
397         } else if (ata_version(ident_data->version_major) <= 7) {
398                 snprintf(ata, sizeof(ata), "%s-%d", proto,
399                     ata_version(ident_data->version_major));
400         } else if (ata_version(ident_data->version_major) == 8) {
401                 snprintf(ata, sizeof(ata), "%s8-ACS", proto);
402         } else {
403                 snprintf(ata, sizeof(ata), "ACS-%d %s",
404                     ata_version(ident_data->version_major) - 7, proto);
405         }
406         if (ident_data->satacapabilities && ident_data->satacapabilities != 0xffff) {
407                 if (ident_data->satacapabilities & ATA_SATA_GEN3)
408                         snprintf(sata, sizeof(sata), " SATA 3.x");
409                 else if (ident_data->satacapabilities & ATA_SATA_GEN2)
410                         snprintf(sata, sizeof(sata), " SATA 2.x");
411                 else if (ident_data->satacapabilities & ATA_SATA_GEN1)
412                         snprintf(sata, sizeof(sata), " SATA 1.x");
413                 else
414                         snprintf(sata, sizeof(sata), " SATA");
415         } else
416                 sata[0] = 0;
417         printf("<%s %s> %s%s device\n", product, revision, ata, sata);
418 }
419
420 void
421 ata_print_ident_short(struct ata_params *ident_data)
422 {
423         char product[48], revision[16];
424
425         cam_strvis(product, ident_data->model, sizeof(ident_data->model),
426                    sizeof(product));
427         cam_strvis(revision, ident_data->revision, sizeof(ident_data->revision),
428                    sizeof(revision));
429         printf("<%s %s>", product, revision);
430 }
431
432 void
433 semb_print_ident(struct sep_identify_data *ident_data)
434 {
435         char vendor[9], product[17], revision[5], fw[5], in[7], ins[5];
436
437         cam_strvis(vendor, ident_data->vendor_id, 8, sizeof(vendor));
438         cam_strvis(product, ident_data->product_id, 16, sizeof(product));
439         cam_strvis(revision, ident_data->product_rev, 4, sizeof(revision));
440         cam_strvis(fw, ident_data->firmware_rev, 4, sizeof(fw));
441         cam_strvis(in, ident_data->interface_id, 6, sizeof(in));
442         cam_strvis(ins, ident_data->interface_rev, 4, sizeof(ins));
443         printf("<%s %s %s %s> SEMB %s %s device\n",
444             vendor, product, revision, fw, in, ins);
445 }
446
447 void
448 semb_print_ident_short(struct sep_identify_data *ident_data)
449 {
450         char vendor[9], product[17], revision[5], fw[5];
451
452         cam_strvis(vendor, ident_data->vendor_id, 8, sizeof(vendor));
453         cam_strvis(product, ident_data->product_id, 16, sizeof(product));
454         cam_strvis(revision, ident_data->product_rev, 4, sizeof(revision));
455         cam_strvis(fw, ident_data->firmware_rev, 4, sizeof(fw));
456         printf("<%s %s %s %s>", vendor, product, revision, fw);
457 }
458
459 uint32_t
460 ata_logical_sector_size(struct ata_params *ident_data)
461 {
462         if ((ident_data->pss & ATA_PSS_VALID_MASK) == ATA_PSS_VALID_VALUE &&
463             (ident_data->pss & ATA_PSS_LSSABOVE512)) {
464                 return (((u_int32_t)ident_data->lss_1 |
465                     ((u_int32_t)ident_data->lss_2 << 16)) * 2);
466         }
467         return (512);
468 }
469
470 uint64_t
471 ata_physical_sector_size(struct ata_params *ident_data)
472 {
473         if ((ident_data->pss & ATA_PSS_VALID_MASK) == ATA_PSS_VALID_VALUE) {
474                 if (ident_data->pss & ATA_PSS_MULTLS) {
475                         return ((uint64_t)ata_logical_sector_size(ident_data) *
476                             (1 << (ident_data->pss & ATA_PSS_LSPPS)));
477                 } else {
478                         return (uint64_t)ata_logical_sector_size(ident_data);
479                 }
480         }
481         return (512);
482 }
483
484 uint64_t
485 ata_logical_sector_offset(struct ata_params *ident_data)
486 {
487         if ((ident_data->lsalign & 0xc000) == 0x4000) {
488                 return ((uint64_t)ata_logical_sector_size(ident_data) *
489                     (ident_data->lsalign & 0x3fff));
490         }
491         return (0);
492 }
493
494 void
495 ata_28bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint8_t features,
496     uint32_t lba, uint8_t sector_count)
497 {
498         bzero(&ataio->cmd, sizeof(ataio->cmd));
499         ataio->cmd.flags = 0;
500         if (cmd == ATA_READ_DMA ||
501             cmd == ATA_READ_DMA_QUEUED ||
502             cmd == ATA_WRITE_DMA ||
503             cmd == ATA_WRITE_DMA_QUEUED ||
504             cmd == ATA_TRUSTED_RECEIVE_DMA ||
505             cmd == ATA_TRUSTED_SEND_DMA ||
506             cmd == ATA_DOWNLOAD_MICROCODE_DMA ||
507             cmd == ATA_READ_BUFFER_DMA ||
508             cmd == ATA_WRITE_BUFFER_DMA)
509                 ataio->cmd.flags |= CAM_ATAIO_DMA;
510         ataio->cmd.command = cmd;
511         ataio->cmd.features = features;
512         ataio->cmd.lba_low = lba;
513         ataio->cmd.lba_mid = lba >> 8;
514         ataio->cmd.lba_high = lba >> 16;
515         ataio->cmd.device = ATA_DEV_LBA | ((lba >> 24) & 0x0f);
516         ataio->cmd.sector_count = sector_count;
517 }
518
519 void
520 ata_48bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint16_t features,
521     uint64_t lba, uint16_t sector_count)
522 {
523
524         ataio->cmd.flags = CAM_ATAIO_48BIT;
525         if (cmd == ATA_READ_DMA48 ||
526             cmd == ATA_READ_DMA_QUEUED48 ||
527             cmd == ATA_READ_STREAM_DMA48 ||
528             cmd == ATA_WRITE_DMA48 ||
529             cmd == ATA_WRITE_DMA_FUA48 ||
530             cmd == ATA_WRITE_DMA_QUEUED48 ||
531             cmd == ATA_WRITE_DMA_QUEUED_FUA48 ||
532             cmd == ATA_WRITE_STREAM_DMA48 ||
533             cmd == ATA_DATA_SET_MANAGEMENT ||
534             cmd == ATA_READ_LOG_DMA_EXT ||
535             cmd == ATA_WRITE_LOG_DMA_EXT)
536                 ataio->cmd.flags |= CAM_ATAIO_DMA;
537         ataio->cmd.command = cmd;
538         ataio->cmd.features = features;
539         ataio->cmd.lba_low = lba;
540         ataio->cmd.lba_mid = lba >> 8;
541         ataio->cmd.lba_high = lba >> 16;
542         ataio->cmd.device = ATA_DEV_LBA;
543         ataio->cmd.lba_low_exp = lba >> 24;
544         ataio->cmd.lba_mid_exp = lba >> 32;
545         ataio->cmd.lba_high_exp = lba >> 40;
546         ataio->cmd.features_exp = features >> 8;
547         ataio->cmd.sector_count = sector_count;
548         ataio->cmd.sector_count_exp = sector_count >> 8;
549         ataio->cmd.control = 0;
550 }
551
552 void
553 ata_ncq_cmd(struct ccb_ataio *ataio, uint8_t cmd,
554     uint64_t lba, uint16_t sector_count)
555 {
556
557         ataio->cmd.flags = CAM_ATAIO_48BIT | CAM_ATAIO_FPDMA;
558         ataio->cmd.command = cmd;
559         ataio->cmd.features = sector_count;
560         ataio->cmd.lba_low = lba;
561         ataio->cmd.lba_mid = lba >> 8;
562         ataio->cmd.lba_high = lba >> 16;
563         ataio->cmd.device = ATA_DEV_LBA;
564         ataio->cmd.lba_low_exp = lba >> 24;
565         ataio->cmd.lba_mid_exp = lba >> 32;
566         ataio->cmd.lba_high_exp = lba >> 40;
567         ataio->cmd.features_exp = sector_count >> 8;
568         ataio->cmd.sector_count = 0;
569         ataio->cmd.sector_count_exp = 0;
570         ataio->cmd.control = 0;
571 }
572
573 void
574 ata_reset_cmd(struct ccb_ataio *ataio)
575 {
576         bzero(&ataio->cmd, sizeof(ataio->cmd));
577         ataio->cmd.flags = CAM_ATAIO_CONTROL | CAM_ATAIO_NEEDRESULT;
578         ataio->cmd.control = 0x04;
579 }
580
581 void
582 ata_pm_read_cmd(struct ccb_ataio *ataio, int reg, int port)
583 {
584         bzero(&ataio->cmd, sizeof(ataio->cmd));
585         ataio->cmd.flags = CAM_ATAIO_NEEDRESULT;
586         ataio->cmd.command = ATA_READ_PM;
587         ataio->cmd.features = reg;
588         ataio->cmd.device = port & 0x0f;
589 }
590
591 void
592 ata_pm_write_cmd(struct ccb_ataio *ataio, int reg, int port, uint32_t val)
593 {
594         bzero(&ataio->cmd, sizeof(ataio->cmd));
595         ataio->cmd.flags = 0;
596         ataio->cmd.command = ATA_WRITE_PM;
597         ataio->cmd.features = reg;
598         ataio->cmd.sector_count = val;
599         ataio->cmd.lba_low = val >> 8;
600         ataio->cmd.lba_mid = val >> 16;
601         ataio->cmd.lba_high = val >> 24;
602         ataio->cmd.device = port & 0x0f;
603 }
604
605 void
606 ata_read_log(struct ccb_ataio *ataio, uint32_t retries,
607              void (*cbfcnp)(struct cam_periph *, union ccb *),
608              uint32_t log_address, uint32_t page_number, uint16_t block_count,
609              uint32_t protocol, uint8_t *data_ptr, uint32_t dxfer_len,
610              uint32_t timeout)
611 {
612         uint64_t lba;
613
614         cam_fill_ataio(ataio,
615             /*retries*/ 1,
616             /*cbfcnp*/ cbfcnp,
617             /*flags*/ CAM_DIR_IN,
618             /*tag_action*/ 0,
619             /*data_ptr*/ data_ptr,
620             /*dxfer_len*/ dxfer_len,
621             /*timeout*/ timeout);
622
623         lba = (((uint64_t)page_number & 0xff00) << 32) |
624               ((page_number & 0x00ff) << 8) |
625               (log_address & 0xff);
626
627         ata_48bit_cmd(ataio,
628             /*cmd*/ (protocol & CAM_ATAIO_DMA) ? ATA_READ_LOG_DMA_EXT :
629                      ATA_READ_LOG_EXT,
630             /*features*/ 0,
631             /*lba*/ lba,
632             /*sector_count*/ block_count);
633 }
634
635 void
636 ata_bswap(int8_t *buf, int len)
637 {
638         u_int16_t *ptr = (u_int16_t*)(buf + len);
639
640         while (--ptr >= (u_int16_t*)buf)
641                 *ptr = be16toh(*ptr);
642 }
643
644 void
645 ata_btrim(int8_t *buf, int len)
646 {
647         int8_t *ptr;
648
649         for (ptr = buf; ptr < buf+len; ++ptr)
650                 if (!*ptr || *ptr == '_')
651                         *ptr = ' ';
652         for (ptr = buf + len - 1; ptr >= buf && *ptr == ' '; --ptr)
653                 *ptr = 0;
654 }
655
656 void
657 ata_bpack(int8_t *src, int8_t *dst, int len)
658 {
659         int i, j, blank;
660
661         for (i = j = blank = 0 ; i < len; i++) {
662                 if (blank && src[i] == ' ') continue;
663                 if (blank && src[i] != ' ') {
664                         dst[j++] = src[i];
665                         blank = 0;
666                         continue;
667                 }
668                 if (src[i] == ' ') {
669                         blank = 1;
670                         if (i == 0)
671                         continue;
672                 }
673                 dst[j++] = src[i];
674         }
675         while (j < len)
676                 dst[j++] = 0x00;
677 }
678
679 int
680 ata_max_pmode(struct ata_params *ap)
681 {
682     if (ap->atavalid & ATA_FLAG_64_70) {
683         if (ap->apiomodes & 0x02)
684             return ATA_PIO4;
685         if (ap->apiomodes & 0x01)
686             return ATA_PIO3;
687     }
688     if (ap->mwdmamodes & 0x04)
689         return ATA_PIO4;
690     if (ap->mwdmamodes & 0x02)
691         return ATA_PIO3;
692     if (ap->mwdmamodes & 0x01)
693         return ATA_PIO2;
694     if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x200)
695         return ATA_PIO2;
696     if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x100)
697         return ATA_PIO1;
698     if ((ap->retired_piomode & ATA_RETIRED_PIO_MASK) == 0x000)
699         return ATA_PIO0;
700     return ATA_PIO0;
701 }
702
703 int
704 ata_max_wmode(struct ata_params *ap)
705 {
706     if (ap->mwdmamodes & 0x04)
707         return ATA_WDMA2;
708     if (ap->mwdmamodes & 0x02)
709         return ATA_WDMA1;
710     if (ap->mwdmamodes & 0x01)
711         return ATA_WDMA0;
712     return -1;
713 }
714
715 int
716 ata_max_umode(struct ata_params *ap)
717 {
718     if (ap->atavalid & ATA_FLAG_88) {
719         if (ap->udmamodes & 0x40)
720             return ATA_UDMA6;
721         if (ap->udmamodes & 0x20)
722             return ATA_UDMA5;
723         if (ap->udmamodes & 0x10)
724             return ATA_UDMA4;
725         if (ap->udmamodes & 0x08)
726             return ATA_UDMA3;
727         if (ap->udmamodes & 0x04)
728             return ATA_UDMA2;
729         if (ap->udmamodes & 0x02)
730             return ATA_UDMA1;
731         if (ap->udmamodes & 0x01)
732             return ATA_UDMA0;
733     }
734     return -1;
735 }
736
737 int
738 ata_max_mode(struct ata_params *ap, int maxmode)
739 {
740
741         if (maxmode == 0)
742                 maxmode = ATA_DMA_MAX;
743         if (maxmode >= ATA_UDMA0 && ata_max_umode(ap) > 0)
744                 return (min(maxmode, ata_max_umode(ap)));
745         if (maxmode >= ATA_WDMA0 && ata_max_wmode(ap) > 0)
746                 return (min(maxmode, ata_max_wmode(ap)));
747         return (min(maxmode, ata_max_pmode(ap)));
748 }
749
750 char *
751 ata_mode2string(int mode)
752 {
753     switch (mode) {
754     case -1: return "UNSUPPORTED";
755     case 0: return "NONE";
756     case ATA_PIO0: return "PIO0";
757     case ATA_PIO1: return "PIO1";
758     case ATA_PIO2: return "PIO2";
759     case ATA_PIO3: return "PIO3";
760     case ATA_PIO4: return "PIO4";
761     case ATA_WDMA0: return "WDMA0";
762     case ATA_WDMA1: return "WDMA1";
763     case ATA_WDMA2: return "WDMA2";
764     case ATA_UDMA0: return "UDMA0";
765     case ATA_UDMA1: return "UDMA1";
766     case ATA_UDMA2: return "UDMA2";
767     case ATA_UDMA3: return "UDMA3";
768     case ATA_UDMA4: return "UDMA4";
769     case ATA_UDMA5: return "UDMA5";
770     case ATA_UDMA6: return "UDMA6";
771     default:
772         if (mode & ATA_DMA_MASK)
773             return "BIOSDMA";
774         else
775             return "BIOSPIO";
776     }
777 }
778
779 int
780 ata_string2mode(char *str)
781 {
782         if (!strcasecmp(str, "PIO0")) return (ATA_PIO0);
783         if (!strcasecmp(str, "PIO1")) return (ATA_PIO1);
784         if (!strcasecmp(str, "PIO2")) return (ATA_PIO2);
785         if (!strcasecmp(str, "PIO3")) return (ATA_PIO3);
786         if (!strcasecmp(str, "PIO4")) return (ATA_PIO4);
787         if (!strcasecmp(str, "WDMA0")) return (ATA_WDMA0);
788         if (!strcasecmp(str, "WDMA1")) return (ATA_WDMA1);
789         if (!strcasecmp(str, "WDMA2")) return (ATA_WDMA2);
790         if (!strcasecmp(str, "UDMA0")) return (ATA_UDMA0);
791         if (!strcasecmp(str, "UDMA16")) return (ATA_UDMA0);
792         if (!strcasecmp(str, "UDMA1")) return (ATA_UDMA1);
793         if (!strcasecmp(str, "UDMA25")) return (ATA_UDMA1);
794         if (!strcasecmp(str, "UDMA2")) return (ATA_UDMA2);
795         if (!strcasecmp(str, "UDMA33")) return (ATA_UDMA2);
796         if (!strcasecmp(str, "UDMA3")) return (ATA_UDMA3);
797         if (!strcasecmp(str, "UDMA44")) return (ATA_UDMA3);
798         if (!strcasecmp(str, "UDMA4")) return (ATA_UDMA4);
799         if (!strcasecmp(str, "UDMA66")) return (ATA_UDMA4);
800         if (!strcasecmp(str, "UDMA5")) return (ATA_UDMA5);
801         if (!strcasecmp(str, "UDMA100")) return (ATA_UDMA5);
802         if (!strcasecmp(str, "UDMA6")) return (ATA_UDMA6);
803         if (!strcasecmp(str, "UDMA133")) return (ATA_UDMA6);
804         return (-1);
805 }
806
807
808 u_int
809 ata_mode2speed(int mode)
810 {
811         switch (mode) {
812         case ATA_PIO0:
813         default:
814                 return (3300);
815         case ATA_PIO1:
816                 return (5200);
817         case ATA_PIO2:
818                 return (8300);
819         case ATA_PIO3:
820                 return (11100);
821         case ATA_PIO4:
822                 return (16700);
823         case ATA_WDMA0:
824                 return (4200);
825         case ATA_WDMA1:
826                 return (13300);
827         case ATA_WDMA2:
828                 return (16700);
829         case ATA_UDMA0:
830                 return (16700);
831         case ATA_UDMA1:
832                 return (25000);
833         case ATA_UDMA2:
834                 return (33300);
835         case ATA_UDMA3:
836                 return (44400);
837         case ATA_UDMA4:
838                 return (66700);
839         case ATA_UDMA5:
840                 return (100000);
841         case ATA_UDMA6:
842                 return (133000);
843         }
844 }
845
846 u_int
847 ata_revision2speed(int revision)
848 {
849         switch (revision) {
850         case 1:
851         default:
852                 return (150000);
853         case 2:
854                 return (300000);
855         case 3:
856                 return (600000);
857         }
858 }
859
860 int
861 ata_speed2revision(u_int speed)
862 {
863         switch (speed) {
864         case 0:
865                 return (0);
866         case 150000:
867                 return (1);
868         case 300000:
869                 return (2);
870         case 600000:
871                 return (3);
872         default:
873                 return (-1);
874         }
875 }
876
877 int
878 ata_identify_match(caddr_t identbuffer, caddr_t table_entry)
879 {
880         struct scsi_inquiry_pattern *entry;
881         struct ata_params *ident;
882  
883         entry = (struct scsi_inquiry_pattern *)table_entry;
884         ident = (struct ata_params *)identbuffer;
885
886         if ((cam_strmatch(ident->model, entry->product,
887                           sizeof(ident->model)) == 0)
888          && (cam_strmatch(ident->revision, entry->revision,
889                           sizeof(ident->revision)) == 0)) {
890                 return (0);
891         }
892         return (-1);
893 }
894
895 int
896 ata_static_identify_match(caddr_t identbuffer, caddr_t table_entry)
897 {
898         struct scsi_static_inquiry_pattern *entry;
899         struct ata_params *ident;
900  
901         entry = (struct scsi_static_inquiry_pattern *)table_entry;
902         ident = (struct ata_params *)identbuffer;
903
904         if ((cam_strmatch(ident->model, entry->product,
905                           sizeof(ident->model)) == 0)
906          && (cam_strmatch(ident->revision, entry->revision,
907                           sizeof(ident->revision)) == 0)) {
908                 return (0);
909         }
910         return (-1);
911 }
912
913 void
914 semb_receive_diagnostic_results(struct ccb_ataio *ataio,
915     u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
916     uint8_t tag_action, int pcv, uint8_t page_code,
917     uint8_t *data_ptr, uint16_t length, uint32_t timeout)
918 {
919
920         length = min(length, 1020);
921         length = (length + 3) & ~3;
922         cam_fill_ataio(ataio,
923                       retries,
924                       cbfcnp,
925                       /*flags*/CAM_DIR_IN,
926                       tag_action,
927                       data_ptr,
928                       length,
929                       timeout);
930         ata_28bit_cmd(ataio, ATA_SEP_ATTN,
931             pcv ? page_code : 0, 0x02, length / 4);
932 }
933
934 void
935 semb_send_diagnostic(struct ccb_ataio *ataio,
936     u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
937     uint8_t tag_action, uint8_t *data_ptr, uint16_t length, uint32_t timeout)
938 {
939
940         length = min(length, 1020);
941         length = (length + 3) & ~3;
942         cam_fill_ataio(ataio,
943                       retries,
944                       cbfcnp,
945                       /*flags*/length ? CAM_DIR_OUT : CAM_DIR_NONE,
946                       tag_action,
947                       data_ptr,
948                       length,
949                       timeout);
950         ata_28bit_cmd(ataio, ATA_SEP_ATTN,
951             length > 0 ? data_ptr[0] : 0, 0x82, length / 4);
952 }
953
954 void
955 semb_read_buffer(struct ccb_ataio *ataio,
956     u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
957     uint8_t tag_action, uint8_t page_code,
958     uint8_t *data_ptr, uint16_t length, uint32_t timeout)
959 {
960
961         length = min(length, 1020);
962         length = (length + 3) & ~3;
963         cam_fill_ataio(ataio,
964                       retries,
965                       cbfcnp,
966                       /*flags*/CAM_DIR_IN,
967                       tag_action,
968                       data_ptr,
969                       length,
970                       timeout);
971         ata_28bit_cmd(ataio, ATA_SEP_ATTN,
972             page_code, 0x00, length / 4);
973 }
974
975 void
976 semb_write_buffer(struct ccb_ataio *ataio,
977     u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
978     uint8_t tag_action, uint8_t *data_ptr, uint16_t length, uint32_t timeout)
979 {
980
981         length = min(length, 1020);
982         length = (length + 3) & ~3;
983         cam_fill_ataio(ataio,
984                       retries,
985                       cbfcnp,
986                       /*flags*/length ? CAM_DIR_OUT : CAM_DIR_NONE,
987                       tag_action,
988                       data_ptr,
989                       length,
990                       timeout);
991         ata_28bit_cmd(ataio, ATA_SEP_ATTN,
992             length > 0 ? data_ptr[0] : 0, 0x80, length / 4);
993 }
994
995
996 void
997 ata_zac_mgmt_out(struct ccb_ataio *ataio, uint32_t retries, 
998                  void (*cbfcnp)(struct cam_periph *, union ccb *),
999                  int use_ncq, uint8_t zm_action, uint64_t zone_id,
1000                  uint8_t zone_flags, uint16_t sector_count, uint8_t *data_ptr,
1001                  uint32_t dxfer_len, uint32_t timeout)
1002 {
1003         uint8_t command_out, ata_flags;
1004         uint16_t features_out, sectors_out;
1005         uint32_t auxiliary;
1006
1007         if (use_ncq == 0) {
1008                 command_out = ATA_ZAC_MANAGEMENT_OUT;
1009                 features_out = (zm_action & 0xf) | (zone_flags << 8);
1010                 if (dxfer_len == 0) {
1011                         ata_flags = 0;
1012                         sectors_out = 0;
1013                 } else {
1014                         ata_flags = CAM_ATAIO_DMA;
1015                         /* XXX KDM use sector count? */
1016                         sectors_out = ((dxfer_len >> 9) & 0xffff);
1017                 }
1018                 auxiliary = 0;
1019         } else {
1020                 if (dxfer_len == 0) {
1021                         command_out = ATA_NCQ_NON_DATA;
1022                         features_out = ATA_NCQ_ZAC_MGMT_OUT;
1023                         sectors_out = 0;
1024                 } else {
1025                         command_out = ATA_SEND_FPDMA_QUEUED;
1026
1027                         /* Note that we're defaulting to normal priority */
1028                         sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
1029
1030                         /*
1031                          * For SEND FPDMA QUEUED, the transfer length is
1032                          * encoded in the FEATURE register, and 0 means
1033                          * that 65536 512 byte blocks are to be tranferred.
1034                          * In practice, it seems unlikely that we'll see
1035                          * a transfer that large.
1036                          */
1037                         if (dxfer_len == (65536 * 512)) {
1038                                 features_out = 0;
1039                         } else {
1040                                 /*
1041                                  * Yes, the caller can theoretically send a
1042                                  * transfer larger than we can handle.
1043                                  * Anyone using this function needs enough
1044                                  * knowledge to avoid doing that.
1045                                  */
1046                                 features_out = ((dxfer_len >> 9) & 0xffff);
1047                         }
1048                 }
1049                 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
1050
1051                 ata_flags = CAM_ATAIO_FPDMA;
1052         }
1053
1054         cam_fill_ataio(ataio,
1055             /*retries*/ retries,
1056             /*cbfcnp*/ cbfcnp,
1057             /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
1058             /*tag_action*/ 0,
1059             /*data_ptr*/ data_ptr,
1060             /*dxfer_len*/ dxfer_len,
1061             /*timeout*/ timeout);
1062
1063         ata_48bit_cmd(ataio,
1064             /*cmd*/ command_out,
1065             /*features*/ features_out,
1066             /*lba*/ zone_id,
1067             /*sector_count*/ sectors_out);
1068
1069         ataio->cmd.flags |= ata_flags;
1070         if (auxiliary != 0) {
1071                 ataio->ata_flags |= ATA_FLAG_AUX;
1072                 ataio->aux = auxiliary;
1073         }
1074 }
1075
1076 void
1077 ata_zac_mgmt_in(struct ccb_ataio *ataio, uint32_t retries, 
1078                 void (*cbfcnp)(struct cam_periph *, union ccb *),
1079                 int use_ncq, uint8_t zm_action, uint64_t zone_id,
1080                 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
1081                 uint32_t timeout)
1082 {
1083         uint8_t command_out, ata_flags;
1084         uint16_t features_out, sectors_out;
1085         uint32_t auxiliary;
1086
1087         if (use_ncq == 0) {
1088                 command_out = ATA_ZAC_MANAGEMENT_IN;
1089                 /* XXX KDM put a macro here */
1090                 features_out = (zm_action & 0xf) | (zone_flags << 8);
1091                 ata_flags = CAM_ATAIO_DMA;
1092                 sectors_out = ((dxfer_len >> 9) & 0xffff);
1093                 auxiliary = 0;
1094         } else {
1095                 command_out = ATA_RECV_FPDMA_QUEUED;
1096                 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
1097                 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
1098                 ata_flags = CAM_ATAIO_FPDMA;
1099                 /*
1100                  * For RECEIVE FPDMA QUEUED, the transfer length is
1101                  * encoded in the FEATURE register, and 0 means
1102                  * that 65536 512 byte blocks are to be tranferred.
1103                  * In practice, it is unlikely we will see a transfer that
1104                  * large.
1105                  */
1106                 if (dxfer_len == (65536 * 512)) {
1107                         features_out = 0;
1108                 } else {
1109                         /*
1110                          * Yes, the caller can theoretically request a
1111                          * transfer larger than we can handle.
1112                          * Anyone using this function needs enough
1113                          * knowledge to avoid doing that.
1114                          */
1115                         features_out = ((dxfer_len >> 9) & 0xffff);
1116                 }
1117         }
1118
1119         cam_fill_ataio(ataio,
1120             /*retries*/ retries,
1121             /*cbfcnp*/ cbfcnp,
1122             /*flags*/ CAM_DIR_IN,
1123             /*tag_action*/ 0,
1124             /*data_ptr*/ data_ptr,
1125             /*dxfer_len*/ dxfer_len,
1126             /*timeout*/ timeout);
1127
1128         ata_48bit_cmd(ataio,
1129             /*cmd*/ command_out,
1130             /*features*/ features_out,
1131             /*lba*/ zone_id,
1132             /*sector_count*/ sectors_out);
1133
1134         ataio->cmd.flags |= ata_flags;
1135         if (auxiliary != 0) {
1136                 ataio->ata_flags |= ATA_FLAG_AUX;
1137                 ataio->aux = auxiliary;
1138         }
1139 }