1 | /******************************************************************************
|
---|
2 | * ata.c - ATA command processing
|
---|
3 | *
|
---|
4 | * Copyright (c) 2011 thi.guten Software Development
|
---|
5 | * Copyright (c) 2011 Mensys B.V.
|
---|
6 | *
|
---|
7 | * Authors: Christian Mueller, Markus Thielen
|
---|
8 | *
|
---|
9 | * Parts copied from/inspired by the Linux AHCI driver;
|
---|
10 | * those parts are (c) Linux AHCI/ATA maintainers
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or modify
|
---|
13 | * it under the terms of the GNU General Public License as published by
|
---|
14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
15 | * (at your option) any later version.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful,
|
---|
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | * GNU General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, write to the Free Software
|
---|
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
25 | */
|
---|
26 |
|
---|
27 | #include "os2ahci.h"
|
---|
28 | #include "ata.h"
|
---|
29 |
|
---|
30 | /* -------------------------- macros and constants ------------------------- */
|
---|
31 |
|
---|
32 | /* ------------------------ typedefs and structures ------------------------ */
|
---|
33 |
|
---|
34 | /* -------------------------- function prototypes -------------------------- */
|
---|
35 |
|
---|
36 | /* ------------------------ global/static variables ------------------------ */
|
---|
37 |
|
---|
38 | /* ----------------------------- start of code ----------------------------- */
|
---|
39 |
|
---|
40 | /******************************************************************************
|
---|
41 | * Initialize AHCI command slot, FIS and S/G list for the specified ATA
|
---|
42 | * command. The command parameters are passed as a variable argument list
|
---|
43 | * of type and value(s). The list is terminated by AP_END.
|
---|
44 | *
|
---|
45 | * Notes:
|
---|
46 | *
|
---|
47 | * - The specified command slot is expected to be idle; no checks are
|
---|
48 | * performed to prevent messing with a busy port.
|
---|
49 | *
|
---|
50 | * - Port multipliers are not supported, yet, thus 'd' should always
|
---|
51 | * be 0 for the time being.
|
---|
52 | *
|
---|
53 | * - 'cmd' is passed as 16-bit integer because the compiler would push
|
---|
54 | * a 'u8' as 16-bit value (it's a fixed argument) and the stdarg
|
---|
55 | * macros would screw up the address of the first variable argument
|
---|
56 | * if the size of the last fixed argument wouldn't match what the
|
---|
57 | * compiler pushed on the stack.
|
---|
58 | *
|
---|
59 | * Return values:
|
---|
60 | * 0 : success
|
---|
61 | * > 0 : could not map all S/G entries; the return value is the number of
|
---|
62 | * S/G entries that could be mapped.
|
---|
63 | * < 0 : other error
|
---|
64 | */
|
---|
65 | int ata_cmd(AD_INFO *ai, int p, int d, int slot, int cmd, ...)
|
---|
66 | {
|
---|
67 | va_list va;
|
---|
68 | va_start(va, cmd);
|
---|
69 | return(v_ata_cmd(ai, p, d, slot, cmd, va));
|
---|
70 | }
|
---|
71 |
|
---|
72 | int v_ata_cmd(AD_INFO *ai, int p, int d, int slot, int cmd, va_list va)
|
---|
73 | {
|
---|
74 | AHCI_PORT_DMA _far *dma_base_virt;
|
---|
75 | AHCI_CMD_HDR _far *cmd_hdr;
|
---|
76 | AHCI_CMD_TBL _far *cmd_tbl;
|
---|
77 | SCATGATENTRY _far *sg_list = NULL;
|
---|
78 | SCATGATENTRY sg_single;
|
---|
79 | ATA_PARM ap;
|
---|
80 | ATA_CMD ata_cmd;
|
---|
81 | void _far *atapi_cmd = NULL;
|
---|
82 | u32 dma_base_phys;
|
---|
83 | u16 atapi_cmd_len = 0;
|
---|
84 | u16 ahci_flags = 0;
|
---|
85 | u16 sg_cnt = 0;
|
---|
86 | int i;
|
---|
87 | int n;
|
---|
88 |
|
---|
89 | /* --------------------------------------------------------------------------
|
---|
90 | * Initialize ATA command. The ATA command is set up with the main command
|
---|
91 | * value and a variable list of additional parameters such as the sector
|
---|
92 | * address, transfer count, ...
|
---|
93 | */
|
---|
94 | memset(&ata_cmd, 0x00, sizeof(ata_cmd));
|
---|
95 | ata_cmd.cmd = (u8) cmd;
|
---|
96 |
|
---|
97 | /* parse variable arguments */
|
---|
98 | do {
|
---|
99 | switch ((ap = va_arg(va, ATA_PARM))) {
|
---|
100 |
|
---|
101 | case AP_AHCI_FLAGS:
|
---|
102 | ahci_flags |= va_arg(va, u16);
|
---|
103 | break;
|
---|
104 |
|
---|
105 | case AP_WRITE:
|
---|
106 | if (va_arg(va, u16) != 0) {
|
---|
107 | ahci_flags |= AHCI_CMD_WRITE;
|
---|
108 | }
|
---|
109 | break;
|
---|
110 |
|
---|
111 | case AP_FEATURES:
|
---|
112 | /* ATA features word */
|
---|
113 | ata_cmd.features |= va_arg(va, u16);
|
---|
114 | break;
|
---|
115 |
|
---|
116 | case AP_COUNT:
|
---|
117 | /* transfer count */
|
---|
118 | ata_cmd.count = va_arg(va, u16);
|
---|
119 | break;
|
---|
120 |
|
---|
121 | case AP_SECTOR_28:
|
---|
122 | /* 28-bit sector address */
|
---|
123 | ata_cmd.lba_l = va_arg(va, u32);
|
---|
124 | if (ata_cmd.lba_l & 0xf0000000UL) {
|
---|
125 | dprintf("error: LBA-28 address %ld has more than 28 bits\n", ata_cmd.lba_l);
|
---|
126 | return(-1);
|
---|
127 | }
|
---|
128 | /* add upper 4 bits to device field */
|
---|
129 | ata_cmd.device |= (ata_cmd.lba_l >> 24) & 0x0fU;
|
---|
130 | /* only lower 24 bits come into lba_l */
|
---|
131 | ata_cmd.lba_l &= 0x00ffffffUL;
|
---|
132 | break;
|
---|
133 |
|
---|
134 | case AP_SECTOR_48:
|
---|
135 | /* 48-bit sector address */
|
---|
136 | ata_cmd.lba_l = va_arg(va, u32);
|
---|
137 | ata_cmd.lba_h = va_arg(va, u16);
|
---|
138 | break;
|
---|
139 |
|
---|
140 | case AP_DEVICE:
|
---|
141 | /* ATA device byte; note that this byte contains the highest
|
---|
142 | * 4 bits of LBA-28 address; we have to leave them alone here. */
|
---|
143 | ata_cmd.device |= va_arg(va, u16) & 0xf0U;
|
---|
144 | break;
|
---|
145 |
|
---|
146 | case AP_SGLIST:
|
---|
147 | /* scatter/gather list in SCATGATENTRY/count format */
|
---|
148 | sg_list = va_arg(va, void _far *);
|
---|
149 | sg_cnt = va_arg(va, u16);
|
---|
150 | break;
|
---|
151 |
|
---|
152 | case AP_VADDR:
|
---|
153 | /* virtual buffer address in addr/len format (up to 4K) */
|
---|
154 | DevHelp_VirtToPhys(va_arg(va, void _far *), &sg_single.ppXferBuf);
|
---|
155 | sg_single.XferBufLen = va_arg(va, u16);
|
---|
156 | sg_list = &sg_single;
|
---|
157 | sg_cnt = 1;
|
---|
158 | break;
|
---|
159 |
|
---|
160 | case AP_ATAPI_CMD:
|
---|
161 | /* ATAPI command */
|
---|
162 | atapi_cmd = va_arg(va, void _far *);
|
---|
163 | atapi_cmd_len = va_arg(va, u16);
|
---|
164 | ahci_flags |= AHCI_CMD_ATAPI;
|
---|
165 | break;
|
---|
166 |
|
---|
167 | case AP_ATA_CMD:
|
---|
168 | /* ATA command "pass-through" */
|
---|
169 | memcpy(&ata_cmd, va_arg(va, void _far *), sizeof(ATA_CMD));
|
---|
170 | break;
|
---|
171 |
|
---|
172 | case AP_END:
|
---|
173 | break;
|
---|
174 |
|
---|
175 | default:
|
---|
176 | dprintf("error: v_ata_cmd() called with invalid parameter type (%d)\n", (int) ap);
|
---|
177 | return(-1);
|
---|
178 | }
|
---|
179 |
|
---|
180 | } while (ap != AP_END);
|
---|
181 |
|
---|
182 | /* --------------------------------------------------------------------------
|
---|
183 | * Fill in AHCI ATA command information. This includes the port command slot,
|
---|
184 | * the corresponding command FIS and the S/G list. The layout of the AHCI
|
---|
185 | * port DMA region is based on the Linux AHCI driver and looks like this:
|
---|
186 | *
|
---|
187 | * - 32 AHCI command headers (AHCI_CMD_HDR) with 32 bytes, each
|
---|
188 | * - 1 FIS receive area with 256 bytes (AHCI_RX_FIS_SZ)
|
---|
189 | * - 32 AHCI command tables, each consisting of
|
---|
190 | * - 64 bytes for command FIS
|
---|
191 | * - 16 bytes for ATAPI comands
|
---|
192 | * - 48 bytes reserved
|
---|
193 | * - 48 S/G entries (AHCI_SG) with 32 bytes, each
|
---|
194 | *
|
---|
195 | * Since the whole DMA buffer for all ports is larger than 64KB and we need
|
---|
196 | * multiple segments to address all of them, there are no virtual pointers
|
---|
197 | * to the individual elements in AD_INFO. Instead, we're relying on macros
|
---|
198 | * for getting the base address of a particular port's DMA region, then
|
---|
199 | * map a structure on top of that for convenience (AHCI_PORT_DMA).
|
---|
200 | */
|
---|
201 | dma_base_virt = port_dma_base(ai, p);
|
---|
202 | dma_base_phys = port_dma_base_phys(ai, p);
|
---|
203 |
|
---|
204 | /* AHCI command header */
|
---|
205 | cmd_hdr = dma_base_virt->cmd_hdr + slot;
|
---|
206 | memset(cmd_hdr, 0x00, sizeof(*cmd_hdr));
|
---|
207 | cmd_hdr->options = ((d & 0x0f) << 12);
|
---|
208 | cmd_hdr->options |= ahci_flags; /* AHCI command flags */
|
---|
209 | cmd_hdr->options |= 5; /* length of command FIS in 32-bit words */
|
---|
210 | cmd_hdr->tbl_addr = dma_base_phys + offsetof(AHCI_PORT_DMA, cmd_tbl[slot]);
|
---|
211 |
|
---|
212 | /* AHCI command table */
|
---|
213 | cmd_tbl = dma_base_virt->cmd_tbl + slot;
|
---|
214 | memset(cmd_tbl, 0x00, sizeof(*cmd_tbl));
|
---|
215 | ata_cmd_to_fis(cmd_tbl->cmd_fis, &ata_cmd, d);
|
---|
216 |
|
---|
217 | if (atapi_cmd != NULL) {
|
---|
218 | /* copy ATAPI command */
|
---|
219 | memcpy(cmd_tbl->atapi_cmd, atapi_cmd, atapi_cmd_len);
|
---|
220 | }
|
---|
221 |
|
---|
222 | /* PRDT (S/G list)
|
---|
223 | *
|
---|
224 | * - The S/G list for AHCI adapters is limited to 22 bits for the transfer
|
---|
225 | * size of each element, thus we need to split S/G elements larger than
|
---|
226 | * 22 bits into 2 AHCI_SG elements.
|
---|
227 | *
|
---|
228 | * - The S/G element size for AHCI is what the spec calls "'0' based"
|
---|
229 | * (i.e. 0 means 1 bytes). On top of that, the spec requires S/G transfer
|
---|
230 | * sizes to be even in the context of 16-bit transfers, thus bit '1'
|
---|
231 | * always needs to be set.
|
---|
232 | *
|
---|
233 | * - AHCI_MAX_SG_ELEMENT_LEN defines the maximum size of an AHCI S/G
|
---|
234 | * element in bytes, ignoring the '0'-based methodology (i.e. 1 << 22).
|
---|
235 | *
|
---|
236 | * - There's a limit on the maximum number of S/G elements in the port DMA
|
---|
237 | * buffer (AHCI_MAX_SG) which is lower than the HW maximum. It's beyond
|
---|
238 | * the control of this function to split commands which require more
|
---|
239 | * than AHCI_MAX_SG entries. In order to help the caller, the return value
|
---|
240 | * of this function will indicate how many OS/2 S/G entries were
|
---|
241 | * successfully mapped.
|
---|
242 | *
|
---|
243 | */
|
---|
244 | for (i = n = 0; i < sg_cnt; i++) {
|
---|
245 | u32 sg_addr = sg_list[i].ppXferBuf;
|
---|
246 | u32 sg_size = sg_list[i].XferBufLen;
|
---|
247 |
|
---|
248 | do {
|
---|
249 | u32 chunk = (sg_size > AHCI_MAX_SG_ELEMENT_LEN) ? AHCI_MAX_SG_ELEMENT_LEN
|
---|
250 | : sg_size;
|
---|
251 | if (n >= AHCI_MAX_SG) {
|
---|
252 | /* couldn't store all S/G elements in our DMA buffer */
|
---|
253 | ddprintf("ata_cmd(): too many S/G elements\n");
|
---|
254 | return(i - 1);
|
---|
255 | }
|
---|
256 | cmd_tbl->sg_list[n].addr = sg_addr;
|
---|
257 | cmd_tbl->sg_list[n].size = chunk - 1;
|
---|
258 | sg_addr += chunk;
|
---|
259 | sg_size -= chunk;
|
---|
260 | n++;
|
---|
261 | } while (sg_size > 0);
|
---|
262 | }
|
---|
263 |
|
---|
264 | /* set final S/G count in AHCI command header */
|
---|
265 | cmd_hdr->options |= (u32) n << 16;
|
---|
266 |
|
---|
267 | if (debug >= 2) {
|
---|
268 | printf("ATA command for %d.%d.%d:\n", ad_no(ai), p, d);
|
---|
269 | phex(cmd_hdr, offsetof(AHCI_CMD_HDR, reserved), "cmd_hdr: ");
|
---|
270 | phex(&ata_cmd, sizeof(ata_cmd), "ata_cmd: ");
|
---|
271 | if (atapi_cmd != NULL) {
|
---|
272 | phex(atapi_cmd, atapi_cmd_len, "atapi_cmd: ");
|
---|
273 | }
|
---|
274 | if (n > 0) {
|
---|
275 | phex(cmd_tbl->sg_list, sizeof(*cmd_tbl->sg_list) * n, "sg_list: ");
|
---|
276 | }
|
---|
277 | }
|
---|
278 |
|
---|
279 | return(0);
|
---|
280 | }
|
---|
281 |
|
---|
282 | /******************************************************************************
|
---|
283 | * Fill SATA command FIS with values extracted from an ATA command structure.
|
---|
284 | * The command FIS buffer (fis) is expected to be initialized to 0s. The
|
---|
285 | * structure of the FIS maps to the ATA shadow register block, including
|
---|
286 | * registers which can be written twice to store 16 bits (called 'exp').
|
---|
287 | *
|
---|
288 | * The FIS structure looks like this (using LSB notation):
|
---|
289 | *
|
---|
290 | * +----------------+----------------+----------------+----------------+
|
---|
291 | * 00 | FIS type (27h) | C|R|R|R|PMP | Command | Features |
|
---|
292 | * +----------------+----------------+----------------+----------------+
|
---|
293 | * 04 | LBA 7:0 | LBA 15:8 | LBA 23:16 | R|R|R|D|Head |
|
---|
294 | * +----------------+----------------+----------------+----------------+
|
---|
295 | * 08 | LBA 31:24 | LBA 40:32 | LBA 47:40 | Features exp |
|
---|
296 | * +----------------+----------------+----------------+----------------+
|
---|
297 | * 12 | Count 7:0 | Count 15:8 | Reserved | Control |
|
---|
298 | * +----------------+----------------+----------------+----------------+
|
---|
299 | * 16 | Reserved | Reserved | Reserved | Reserved |
|
---|
300 | * +----------------+----------------+----------------+----------------+
|
---|
301 | */
|
---|
302 | void ata_cmd_to_fis(u8 _far *fis, ATA_CMD _far *ata_cmd, int d)
|
---|
303 | {
|
---|
304 | fis[0] = 0x27; /* register - host to device FIS */
|
---|
305 | fis[1] = (u8) (d & 0xf); /* port multiplier number */
|
---|
306 | fis[1] |= 0x80; /* bit 7 indicates Command FIS */
|
---|
307 | fis[2] = (u8) ata_cmd->cmd;
|
---|
308 | fis[3] = (u8) ata_cmd->features;
|
---|
309 |
|
---|
310 | fis[4] = (u8) ata_cmd->lba_l;
|
---|
311 | fis[5] = (u8) (ata_cmd->lba_l >> 8);
|
---|
312 | fis[6] = (u8) (ata_cmd->lba_l >> 16);
|
---|
313 | fis[7] = (u8) ata_cmd->device;
|
---|
314 |
|
---|
315 | fis[8] = (u8) (ata_cmd->lba_l >> 24);
|
---|
316 | fis[9] = (u8) ata_cmd->lba_h;
|
---|
317 | fis[10] = (u8) (ata_cmd->lba_h >> 8);
|
---|
318 | fis[11] = (u8) (ata_cmd->features >> 8);
|
---|
319 |
|
---|
320 | fis[12] = (u8) ata_cmd->count;
|
---|
321 | fis[13] = (u8) (ata_cmd->count >> 8);
|
---|
322 | }
|
---|
323 |
|
---|
324 | /******************************************************************************
|
---|
325 | * Get index in S/G list for the number of transferred sectors in the IORB.
|
---|
326 | *
|
---|
327 | * Returning io->cSGList indicates an error.
|
---|
328 | *
|
---|
329 | * NOTE: OS/2 makes sure S/G lists are set up such that entries at the HW
|
---|
330 | * limit will never cross sector boundaries. This means that splitting
|
---|
331 | * S/G lists into multiple commands can be done without editing the S/G
|
---|
332 | * lists.
|
---|
333 | */
|
---|
334 | u16 ata_get_sg_indx(IORB_EXECUTEIO _far *io)
|
---|
335 | {
|
---|
336 | ULONG offset = io->BlocksXferred * io->BlockSize;
|
---|
337 | USHORT i;
|
---|
338 |
|
---|
339 | for (i = 0; i < io->cSGList && offset > 0; i++) {
|
---|
340 | offset -= io->pSGList[i].XferBufLen;
|
---|
341 | }
|
---|
342 |
|
---|
343 | return(i);
|
---|
344 | }
|
---|
345 |
|
---|
346 | /******************************************************************************
|
---|
347 | * Get max S/G count which will fit into our HW S/G buffers. This function is
|
---|
348 | * called when the S/G list is too long and we need to split the IORB into
|
---|
349 | * multiple commands. It returns both the number of sectors and S/G list
|
---|
350 | * elements that we can handle in a single command.
|
---|
351 | *
|
---|
352 | * The parameter 'sg_indx' indicates the current start index in the S/G list
|
---|
353 | * (0 if this is the first command iteration).
|
---|
354 | *
|
---|
355 | * The parameter 'sg_max' is the return value of v_ata_cmd() and indicates
|
---|
356 | * how many S/G elements were successfully mapped. Whatever we return needs to
|
---|
357 | * be less or equal to this value.
|
---|
358 | *
|
---|
359 | * Returning 0 in *sg_cnt indicates an error.
|
---|
360 | *
|
---|
361 | * NOTE: OS/2 makes sure S/G lists are set up such that entries at HW limits
|
---|
362 | * will never cross sector boundaries. This means that splitting S/G
|
---|
363 | * lists into multiple commands can be done without editing S/G list
|
---|
364 | * elements. Since AHCI only allows 22 bits for each S/G element, the
|
---|
365 | * hardware limits are reported as AHCI_MAX_SG / 2 but will vary based
|
---|
366 | * on the actual length of S/G elements. This function looks for the
|
---|
367 | * maximum number of S/G elements that can be mapped on sector
|
---|
368 | * boundaries which will still fit into our HW S/G list.
|
---|
369 | */
|
---|
370 | void ata_max_sg_cnt(IORB_EXECUTEIO _far *io, USHORT sg_indx, USHORT sg_max,
|
---|
371 | USHORT _far *sg_cnt, USHORT _far *sector_cnt)
|
---|
372 | {
|
---|
373 | ULONG max_sector_cnt = 0;
|
---|
374 | USHORT max_sg_cnt = 0;
|
---|
375 | ULONG offset = 0;
|
---|
376 | USHORT i;
|
---|
377 |
|
---|
378 | for (i = sg_indx; i < io->cSGList; i++) {
|
---|
379 | if (i - sg_indx >= sg_max) {
|
---|
380 | /* we're beyond the number of S/G elements we can map */
|
---|
381 | break;
|
---|
382 | }
|
---|
383 |
|
---|
384 | offset += io->pSGList[i].XferBufLen;
|
---|
385 | if (offset % io->BlockSize == 0) {
|
---|
386 | /* this S/G element ends on a sector boundary */
|
---|
387 | max_sector_cnt = offset / io->BlockSize;
|
---|
388 | max_sg_cnt = i + 1;
|
---|
389 | }
|
---|
390 | }
|
---|
391 |
|
---|
392 | /* return the best match we found (0 indicating failure) */
|
---|
393 | *sector_cnt = max_sector_cnt;
|
---|
394 | *sg_cnt = max_sg_cnt;
|
---|
395 | }
|
---|
396 |
|
---|
397 |
|
---|
398 | /******************************************************************************
|
---|
399 | * Get device or media geometry. Device and media geometry are expected to be
|
---|
400 | * the same for non-removable devices, which will always be the case for the
|
---|
401 | * ATA devices we're dealing with (hard disks). ATAPI is a different story
|
---|
402 | * and handled by atapi_get_geometry().
|
---|
403 | */
|
---|
404 | int ata_get_geometry(IORBH _far *iorb, int slot)
|
---|
405 | {
|
---|
406 | ADD_WORKSPACE _far *aws = add_workspace(iorb);
|
---|
407 | int rc;
|
---|
408 |
|
---|
409 | /* allocate buffer for ATA identify information */
|
---|
410 | if ((aws->buf = malloc(ATA_ID_WORDS * sizeof(u16))) == NULL) {
|
---|
411 | iorb_seterr(iorb, IOERR_CMD_SW_RESOURCE);
|
---|
412 | return(-1);
|
---|
413 | }
|
---|
414 |
|
---|
415 | /* request ATA identify information */
|
---|
416 | aws->ppfunc = ata_get_geometry_pp;
|
---|
417 | rc = ata_cmd(ad_infos + iorb_unit_adapter(iorb),
|
---|
418 | iorb_unit_port(iorb),
|
---|
419 | iorb_unit_device(iorb),
|
---|
420 | slot,
|
---|
421 | ATA_CMD_ID_ATA,
|
---|
422 | AP_VADDR, (void _far *) aws->buf, ATA_ID_WORDS * sizeof(u16),
|
---|
423 | AP_END);
|
---|
424 |
|
---|
425 | if (rc != 0) {
|
---|
426 | iorb_seterr(iorb, IOERR_CMD_ADD_SOFTWARE_FAILURE);
|
---|
427 | }
|
---|
428 |
|
---|
429 | return(rc);
|
---|
430 | }
|
---|
431 |
|
---|
432 | /******************************************************************************
|
---|
433 | * Post processing function for ata_get_geometry(): convert the ATA identify
|
---|
434 | * information to OS/2 IOCC_GEOMETRY information.
|
---|
435 | */
|
---|
436 | void ata_get_geometry_pp(IORBH _far *iorb)
|
---|
437 | {
|
---|
438 | GEOMETRY _far *geometry = ((IORB_GEOMETRY _far *) iorb)->pGeometry;
|
---|
439 | USHORT geometry_len = ((IORB_GEOMETRY _far *) iorb)->GeometryLen;
|
---|
440 | u16 *id_buf = add_workspace(iorb)->buf;
|
---|
441 | int a = iorb_unit_adapter(iorb);
|
---|
442 | int p = iorb_unit_port(iorb);
|
---|
443 |
|
---|
444 | /* Fill-in geometry information; the ATA-8 spec declares the geometry
|
---|
445 | * fields in the ATA ID buffer as obsolete but it's still the best
|
---|
446 | * guess in most cases. If the information stored in the geometry
|
---|
447 | * fields is apparently incorrect, we'll use the algorithm typically
|
---|
448 | * used by SCSI adapters and modern PC BIOS versions:
|
---|
449 | *
|
---|
450 | * - 512 bytes per sector
|
---|
451 | * - 255 heads
|
---|
452 | * - 63 sectors per track (or 56 with the parameter "/4")
|
---|
453 | * - x cylinders (calculated)
|
---|
454 | *
|
---|
455 | * Please note that os2ahci currently does not natively support ATA sectors
|
---|
456 | * larger than 512 bytes, therefore relies on the translation logic built
|
---|
457 | * into the corresponding ATA disks. In order to prevent file systems that
|
---|
458 | * use block sizes larger than 512 bytes (FAT, JFS, ...) from ending up on
|
---|
459 | * incorrectly aligned physical sector accesses, hence using more physical
|
---|
460 | * I/Os than necessary, the command line parameter "/4" can be used to force
|
---|
461 | * a track size of 56 sectors. This way, partitions will start on 4K
|
---|
462 | * boundaries.
|
---|
463 | *
|
---|
464 | * Another limitation is that OS/2 has a 32-bit variable for the total number
|
---|
465 | * of sectors, limiting the maximum capacity to roughly 2TB. This is another
|
---|
466 | * issue that needs to be addressed sooner or later; large sectors could
|
---|
467 | * raise this limit to something like 8TB but this is not really much of a
|
---|
468 | * difference. Maybe there's something in later DDKs that allows more than
|
---|
469 | * 32 bits?
|
---|
470 | */
|
---|
471 | memset(geometry, 0x00, geometry_len);
|
---|
472 | geometry->BytesPerSector = ATA_SECTOR_SIZE;
|
---|
473 |
|
---|
474 | /* extract total number of sectors */
|
---|
475 | if (id_buf[ATA_ID_CFS_ENABLE_2] & 0x400) {
|
---|
476 | /* 48-bit LBA supported */
|
---|
477 | if (ATA_CAPACITY48_H(id_buf) != 0) {
|
---|
478 | /* more than 32 bits for number of sectors */
|
---|
479 | dprintf("warning: limiting disk %d.%d.%d to 2TB\n",
|
---|
480 | iorb_unit_adapter(iorb), iorb_unit_port(iorb),
|
---|
481 | iorb_unit_device(iorb));
|
---|
482 | geometry->TotalSectors = 0xffffffffUL;
|
---|
483 | } else {
|
---|
484 | geometry->TotalSectors = ATA_CAPACITY48_L(id_buf);
|
---|
485 | }
|
---|
486 | } else {
|
---|
487 | /* 28-bit LBA */
|
---|
488 | geometry->TotalSectors = ATA_CAPACITY(id_buf) & 0x0fffffffUL;
|
---|
489 | }
|
---|
490 |
|
---|
491 | /* fabricate the remaining geometry fields */
|
---|
492 | if (track_size[a][p] != 0) {
|
---|
493 | /* A specific track size has been requested for this port; this is
|
---|
494 | * typically done for disks with 4K sectors to make sure partitions
|
---|
495 | * start on 8-sector boundaries (parameter "/4").
|
---|
496 | */
|
---|
497 | geometry->NumHeads = 255;
|
---|
498 | geometry->SectorsPerTrack = track_size[a][p];
|
---|
499 | geometry->TotalCylinders = geometry->TotalSectors /
|
---|
500 | ((u32) geometry->NumHeads *
|
---|
501 | (u32) geometry->SectorsPerTrack);
|
---|
502 |
|
---|
503 | } else if (CUR_HEADS(id_buf) > 0 && CUR_CYLS(id_buf) > 0 &&
|
---|
504 | CUR_SECTORS(id_buf) > 0 &&
|
---|
505 | CUR_CAPACITY(id_buf) == CUR_HEADS(id_buf) *
|
---|
506 | CUR_CYLS(id_buf) *
|
---|
507 | CUR_SECTORS(id_buf)) {
|
---|
508 | /* BIOS-supplied (aka "current") geometry values look valid */
|
---|
509 | geometry->NumHeads = CUR_HEADS(id_buf);
|
---|
510 | geometry->SectorsPerTrack = CUR_SECTORS(id_buf);
|
---|
511 | geometry->TotalCylinders = CUR_CYLS(id_buf);
|
---|
512 |
|
---|
513 | } else if (ATA_HEADS(id_buf) > 0 && ATA_CYLS(id_buf) > 0 &&
|
---|
514 | ATA_SECTORS(id_buf) > 0) {
|
---|
515 | /* ATA-supplied values for geometry look valid */
|
---|
516 | geometry->NumHeads = ATA_HEADS(id_buf);
|
---|
517 | geometry->SectorsPerTrack = ATA_SECTORS(id_buf);
|
---|
518 | geometry->TotalCylinders = ATA_CYLS(id_buf);
|
---|
519 |
|
---|
520 | } else {
|
---|
521 | /* use typical SCSI geometry */
|
---|
522 | geometry->NumHeads = 255;
|
---|
523 | geometry->SectorsPerTrack = 63;
|
---|
524 | geometry->TotalCylinders = geometry->TotalSectors /
|
---|
525 | ((u32) geometry->NumHeads *
|
---|
526 | (u32) geometry->SectorsPerTrack);
|
---|
527 | }
|
---|
528 |
|
---|
529 | if (debug) {
|
---|
530 | printf("geometry information:\n");
|
---|
531 | printf(" heads: %d\n", (u16) geometry->NumHeads);
|
---|
532 | printf(" sectors: %d\n", (u16) geometry->SectorsPerTrack);
|
---|
533 | printf(" cylinders: %d\n", (u16) geometry->TotalCylinders);
|
---|
534 | printf(" capacity: %ldMB\n", (u32) (geometry->TotalSectors / 2048));
|
---|
535 | }
|
---|
536 |
|
---|
537 | /* tell interrupt handler that this IORB is complete */
|
---|
538 | add_workspace(iorb)->complete = 1;
|
---|
539 | }
|
---|
540 |
|
---|
541 | /******************************************************************************
|
---|
542 | * Test whether unit is ready.
|
---|
543 | */
|
---|
544 | int ata_unit_ready(IORBH _far *iorb, int slot)
|
---|
545 | {
|
---|
546 | /* This is a NOP for ATA devices (at least right now); returning an error
|
---|
547 | * without setting an error code means ahci_exec_iorb() will not queue any
|
---|
548 | * HW command and the IORB will complete successfully.
|
---|
549 | */
|
---|
550 | ((IORB_UNIT_STATUS _far *) iorb)->UnitStatus = US_READY | US_POWER;
|
---|
551 | return(-1);
|
---|
552 | }
|
---|
553 |
|
---|
554 | /******************************************************************************
|
---|
555 | * Read sectors from AHCI device.
|
---|
556 | */
|
---|
557 | int ata_read(IORBH _far *iorb, int slot)
|
---|
558 | {
|
---|
559 | IORB_EXECUTEIO _far *io = (IORB_EXECUTEIO _far *) iorb;
|
---|
560 | AD_INFO *ai = ad_infos + iorb_unit_adapter(iorb);
|
---|
561 | ULONG sector = io->RBA + io->BlocksXferred;
|
---|
562 | USHORT count = io->BlockCount - io->BlocksXferred;
|
---|
563 | USHORT sg_indx;
|
---|
564 | USHORT sg_cnt;
|
---|
565 | int p = iorb_unit_port(iorb);
|
---|
566 | int d = iorb_unit_device(iorb);
|
---|
567 | int rc;
|
---|
568 |
|
---|
569 | /* Kludge: some I/O commands during boot use excessive S/G buffer lengths
|
---|
570 | * which cause NCQ commands to lock up. If there's only one S/G element
|
---|
571 | * and this element is already larger than what we can derive from the sector
|
---|
572 | * count, we'll adjust that element.
|
---|
573 | */
|
---|
574 | if (io->BlocksXferred == 0 && io->cSGList == 1 &&
|
---|
575 | io->pSGList[0].XferBufLen > io->BlockCount * io->BlockSize) {
|
---|
576 | io->pSGList[0].XferBufLen = io->BlockCount * io->BlockSize;
|
---|
577 | }
|
---|
578 |
|
---|
579 | /* prepare read command while keeping an eye on S/G count limitations */
|
---|
580 | do {
|
---|
581 | sg_indx = ata_get_sg_indx(io);
|
---|
582 | sg_cnt = io->cSGList - sg_indx;
|
---|
583 |
|
---|
584 | if (sector >= (1UL << 28) || count > 256 || add_workspace(iorb)->is_ncq) {
|
---|
585 | /* need LBA48 for this command */
|
---|
586 | if (!ai->ports[p].devs[d].lba48) {
|
---|
587 | iorb_seterr(iorb, IOERR_RBA_LIMIT);
|
---|
588 | return(-1);
|
---|
589 | }
|
---|
590 | if (add_workspace(iorb)->is_ncq) {
|
---|
591 | /* use NCQ read; count goes into feature register, tag into count! */
|
---|
592 | rc = ata_cmd(ai, p, d, slot, ATA_CMD_FPDMA_READ,
|
---|
593 | AP_SECTOR_48, (u32) sector, (u16) 0,
|
---|
594 | AP_FEATURES, (u16) count,
|
---|
595 | AP_COUNT, (u16) (slot << 3), /* tag = slot */
|
---|
596 | AP_SGLIST, io->pSGList + sg_indx, (u16) sg_cnt,
|
---|
597 | AP_DEVICE, 0x40,
|
---|
598 | AP_END);
|
---|
599 | } else {
|
---|
600 | rc = ata_cmd(ai, p, d, slot, ATA_CMD_READ_EXT,
|
---|
601 | AP_SECTOR_48, (u32) sector, (u16) 0,
|
---|
602 | AP_COUNT, (u16) count,
|
---|
603 | AP_SGLIST, io->pSGList + sg_indx, (u16) sg_cnt,
|
---|
604 | AP_DEVICE, 0x40,
|
---|
605 | AP_END);
|
---|
606 | }
|
---|
607 |
|
---|
608 | } else {
|
---|
609 | rc = ata_cmd(ai, p, d, slot, ATA_CMD_READ,
|
---|
610 | AP_SECTOR_28, (u32) sector,
|
---|
611 | AP_COUNT, (u16) count & 0xffU,
|
---|
612 | AP_SGLIST, io->pSGList + sg_indx, (u16) sg_cnt,
|
---|
613 | AP_DEVICE, 0x40,
|
---|
614 | AP_END);
|
---|
615 | }
|
---|
616 |
|
---|
617 | if (rc > 0) {
|
---|
618 | /* couldn't map all S/G elements */
|
---|
619 | ata_max_sg_cnt(io, sg_indx, (USHORT) rc, &sg_cnt, &count);
|
---|
620 | }
|
---|
621 | } while (rc > 0 && sg_cnt > 0);
|
---|
622 |
|
---|
623 | if (rc == 0) {
|
---|
624 | add_workspace(iorb)->blocks = count;
|
---|
625 | add_workspace(iorb)->ppfunc = ata_read_pp;
|
---|
626 |
|
---|
627 | } else if (rc > 0) {
|
---|
628 | iorb_seterr(iorb, IOERR_CMD_SGLIST_BAD);
|
---|
629 |
|
---|
630 | } else {
|
---|
631 | iorb_seterr(iorb, IOERR_CMD_ADD_SOFTWARE_FAILURE);
|
---|
632 | }
|
---|
633 |
|
---|
634 | return(rc);
|
---|
635 | }
|
---|
636 |
|
---|
637 | /******************************************************************************
|
---|
638 | * Post processing function for ata_read(); this function updates the
|
---|
639 | * BlocksXferred counter in the IORB and, if not all blocks have been
|
---|
640 | * transferred, requeues the IORB to process the remaining sectors.
|
---|
641 | */
|
---|
642 | void ata_read_pp(IORBH _far *iorb)
|
---|
643 | {
|
---|
644 | IORB_EXECUTEIO _far *io = (IORB_EXECUTEIO _far *) iorb;
|
---|
645 |
|
---|
646 | io->BlocksXferred += add_workspace(iorb)->blocks;
|
---|
647 | dprintf("ata_read_pp(): blocks transferred = %d\n", (int) io->BlocksXferred);
|
---|
648 |
|
---|
649 | if (io->BlocksXferred >= io->BlockCount) {
|
---|
650 | /* we're done; tell IRQ handler the IORB is complete */
|
---|
651 | add_workspace(iorb)->complete = 1;
|
---|
652 | } else {
|
---|
653 | /* requeue this IORB for next iteration */
|
---|
654 | iorb_requeue(iorb);
|
---|
655 | }
|
---|
656 | }
|
---|
657 |
|
---|
658 | /******************************************************************************
|
---|
659 | * Verify readability of sectors on ATA device.
|
---|
660 | */
|
---|
661 | int ata_verify(IORBH _far *iorb, int slot)
|
---|
662 | {
|
---|
663 | IORB_EXECUTEIO _far *io = (IORB_EXECUTEIO _far *) iorb;
|
---|
664 | AD_INFO *ai = ad_infos + iorb_unit_adapter(iorb);
|
---|
665 | int p = iorb_unit_port(iorb);
|
---|
666 | int d = iorb_unit_device(iorb);
|
---|
667 | int rc;
|
---|
668 |
|
---|
669 | /* prepare verify command */
|
---|
670 | if (io->RBA >= (1UL << 28) || io->BlockCount > 256) {
|
---|
671 | /* need LBA48 for this command */
|
---|
672 | if (!ai->ports[p].devs[d].lba48) {
|
---|
673 | iorb_seterr(iorb, IOERR_RBA_LIMIT);
|
---|
674 | return(-1);
|
---|
675 | }
|
---|
676 | rc = ata_cmd(ai, p, d, slot, ATA_CMD_VERIFY_EXT,
|
---|
677 | AP_SECTOR_48, (u32) io->RBA, (u16) 0,
|
---|
678 | AP_COUNT, (u16) io->BlockCount,
|
---|
679 | AP_DEVICE, 0x40,
|
---|
680 | AP_END);
|
---|
681 | } else {
|
---|
682 | rc = ata_cmd(ai, p, d, slot, ATA_CMD_VERIFY,
|
---|
683 | AP_SECTOR_28, (u32) io->RBA,
|
---|
684 | AP_COUNT, (u16) io->BlockCount & 0xffU,
|
---|
685 | AP_END);
|
---|
686 | }
|
---|
687 |
|
---|
688 | return(rc);
|
---|
689 | }
|
---|
690 |
|
---|
691 | /******************************************************************************
|
---|
692 | * Write sectors to AHCI device.
|
---|
693 | */
|
---|
694 | int ata_write(IORBH _far *iorb, int slot)
|
---|
695 | {
|
---|
696 | IORB_EXECUTEIO _far *io = (IORB_EXECUTEIO _far *) iorb;
|
---|
697 | AD_INFO *ai = ad_infos + iorb_unit_adapter(iorb);
|
---|
698 | ULONG sector = io->RBA + io->BlocksXferred;
|
---|
699 | USHORT count = io->BlockCount - io->BlocksXferred;
|
---|
700 | USHORT sg_indx;
|
---|
701 | USHORT sg_cnt;
|
---|
702 | int p = iorb_unit_port(iorb);
|
---|
703 | int d = iorb_unit_device(iorb);
|
---|
704 | int rc;
|
---|
705 |
|
---|
706 | /* prepare write command while keeping an eye on S/G count limitations */
|
---|
707 | do {
|
---|
708 | sg_indx = ata_get_sg_indx(io);
|
---|
709 | sg_cnt = io->cSGList - sg_indx;
|
---|
710 |
|
---|
711 | if (sector >= (1UL << 28) || count > 256 || add_workspace(iorb)->is_ncq) {
|
---|
712 | /* need LBA48 for this command */
|
---|
713 | if (!ai->ports[p].devs[d].lba48) {
|
---|
714 | iorb_seterr(iorb, IOERR_RBA_LIMIT);
|
---|
715 | return(-1);
|
---|
716 | }
|
---|
717 | if (add_workspace(iorb)->is_ncq) {
|
---|
718 | /* use NCQ write; count goes into feature register, tag into count! */
|
---|
719 | rc = ata_cmd(ai, p, d, slot, ATA_CMD_FPDMA_WRITE,
|
---|
720 | AP_SECTOR_48, (u32) sector, (u16) 0,
|
---|
721 | AP_FEATURES, (u16) count,
|
---|
722 | AP_COUNT, (u16) (slot << 3), /* tag = slot */
|
---|
723 | AP_SGLIST, io->pSGList + sg_indx, (u16) sg_cnt,
|
---|
724 | AP_DEVICE, 0x40,
|
---|
725 | AP_DEVICE, (io->Flags & XIO_DISABLE_HW_WRITE_CACHE) ?
|
---|
726 | 0x80 : 0, /* force unit access */
|
---|
727 | AP_WRITE, 1,
|
---|
728 | AP_END);
|
---|
729 | } else {
|
---|
730 | rc = ata_cmd(ai, p, d, slot, ATA_CMD_WRITE_EXT,
|
---|
731 | AP_SECTOR_48, (u32) sector, (u16) 0,
|
---|
732 | AP_COUNT, (u16) count,
|
---|
733 | AP_SGLIST, io->pSGList + sg_indx, (u16) sg_cnt,
|
---|
734 | AP_DEVICE, 0x40,
|
---|
735 | AP_WRITE, 1,
|
---|
736 | AP_END);
|
---|
737 | }
|
---|
738 |
|
---|
739 | } else {
|
---|
740 | rc = ata_cmd(ai, p, d, slot, ATA_CMD_WRITE,
|
---|
741 | AP_SECTOR_28, (u32) sector,
|
---|
742 | AP_COUNT, (u16) count & 0xffU,
|
---|
743 | AP_SGLIST, io->pSGList + sg_indx, (u16) sg_cnt,
|
---|
744 | AP_DEVICE, 0x40,
|
---|
745 | AP_WRITE, 1,
|
---|
746 | AP_END);
|
---|
747 | }
|
---|
748 |
|
---|
749 | if (rc > 0) {
|
---|
750 | /* couldn't map all S/G elements */
|
---|
751 | ata_max_sg_cnt(io, sg_indx, (USHORT) rc, &sg_cnt, &count);
|
---|
752 | }
|
---|
753 | } while (rc > 0 && sg_cnt > 0);
|
---|
754 |
|
---|
755 | if (rc == 0) {
|
---|
756 | add_workspace(iorb)->blocks = count;
|
---|
757 | add_workspace(iorb)->ppfunc = ata_write_pp;
|
---|
758 |
|
---|
759 | } else if (rc > 0) {
|
---|
760 | iorb_seterr(iorb, IOERR_CMD_SGLIST_BAD);
|
---|
761 |
|
---|
762 | } else {
|
---|
763 | iorb_seterr(iorb, IOERR_CMD_ADD_SOFTWARE_FAILURE);
|
---|
764 | }
|
---|
765 |
|
---|
766 | return(rc);
|
---|
767 | }
|
---|
768 |
|
---|
769 | /******************************************************************************
|
---|
770 | * Post processing function for ata_write(); this function updates the
|
---|
771 | * BlocksXferred counter in the IORB and, if not all blocks have been
|
---|
772 | * transferred, requeues the IORB to process the remaining sectors.
|
---|
773 | */
|
---|
774 | void ata_write_pp(IORBH _far *iorb)
|
---|
775 | {
|
---|
776 | IORB_EXECUTEIO _far *io = (IORB_EXECUTEIO _far *) iorb;
|
---|
777 |
|
---|
778 | io->BlocksXferred += add_workspace(iorb)->blocks;
|
---|
779 | dprintf("ata_write_pp(): blocks transferred = %d\n", (int) io->BlocksXferred);
|
---|
780 |
|
---|
781 | if (io->BlocksXferred >= io->BlockCount) {
|
---|
782 | /* we're done; tell IRQ handler the IORB is complete */
|
---|
783 | add_workspace(iorb)->complete = 1;
|
---|
784 | } else {
|
---|
785 | /* requeue this IORB for next iteration */
|
---|
786 | iorb_requeue(iorb);
|
---|
787 | }
|
---|
788 | }
|
---|
789 |
|
---|
790 | /******************************************************************************
|
---|
791 | * Execute ATA command.
|
---|
792 | */
|
---|
793 | int ata_execute_ata(IORBH _far *iorb, int slot)
|
---|
794 | {
|
---|
795 | IORB_ADAPTER_PASSTHRU _far *apt = (IORB_ADAPTER_PASSTHRU _far *) iorb;
|
---|
796 | AD_INFO *ai = ad_infos + iorb_unit_adapter(iorb);
|
---|
797 | int p = iorb_unit_port(iorb);
|
---|
798 | int d = iorb_unit_device(iorb);
|
---|
799 | int rc;
|
---|
800 |
|
---|
801 | if (apt->ControllerCmdLen != sizeof(ATA_CMD)) {
|
---|
802 | iorb_seterr(iorb, IOERR_CMD_SYNTAX);
|
---|
803 | return(-1);
|
---|
804 | }
|
---|
805 |
|
---|
806 | rc = ata_cmd(ai, p, d, slot, 0,
|
---|
807 | AP_SGLIST, apt->pSGList, apt->cSGList,
|
---|
808 | AP_ATA_CMD, apt->pControllerCmd,
|
---|
809 | AP_WRITE, !(apt->Flags & PT_DIRECTION_IN),
|
---|
810 | AP_END);
|
---|
811 |
|
---|
812 | return(rc);
|
---|
813 | }
|
---|
814 |
|
---|
815 | /******************************************************************************
|
---|
816 | * Request sense information for a failed command. Since there is no "request
|
---|
817 | * sense" command for ATA devices, we need to read the current error code from
|
---|
818 | * the AHCI task file register and fabricate the sense information.
|
---|
819 | *
|
---|
820 | * NOTES:
|
---|
821 | *
|
---|
822 | * - This function must be called right after an ATA command has failed and
|
---|
823 | * before any other commands are queued on the corresponding port. This
|
---|
824 | * function is typically called in the port restart context hook which is
|
---|
825 | * triggered by an AHCI error interrupt.
|
---|
826 | *
|
---|
827 | * - The ATA error bits are a complete mess. We'll try and catch the most
|
---|
828 | * interesting error codes (such as medium errors) and report everything
|
---|
829 | * else with a generic error code.
|
---|
830 | */
|
---|
831 | int ata_req_sense(IORBH _far *iorb, int slot)
|
---|
832 | {
|
---|
833 | AD_INFO *ai = ad_infos + iorb_unit_adapter(iorb);
|
---|
834 | u8 _far *port_mmio = port_base(ai, iorb_unit_port(iorb));
|
---|
835 | u32 tf_data = readl(port_mmio + PORT_TFDATA);
|
---|
836 | u8 err = (u8) (tf_data >> 8);
|
---|
837 | u8 sts = (u8) (tf_data);
|
---|
838 |
|
---|
839 | if (sts & ATA_ERR) {
|
---|
840 | if (sts & ATA_DF) {
|
---|
841 | /* there is a device-specific error condition */
|
---|
842 | if (err & ATA_ICRC) {
|
---|
843 | iorb_seterr(iorb, IOERR_ADAPTER_DEVICEBUSCHECK);
|
---|
844 | } else if (err & ATA_UNC) {
|
---|
845 | iorb_seterr(iorb, IOERR_MEDIA);
|
---|
846 | } else if (err & ATA_IDNF) {
|
---|
847 | iorb_seterr(iorb, IOERR_RBA_ADDRESSING_ERROR);
|
---|
848 | } else {
|
---|
849 | iorb_seterr(iorb, IOERR_DEVICE_NONSPECIFIC);
|
---|
850 | }
|
---|
851 |
|
---|
852 | } else {
|
---|
853 | iorb_seterr(iorb, IOERR_DEVICE_NONSPECIFIC);
|
---|
854 | }
|
---|
855 | } else {
|
---|
856 | /* this function only gets called when we received an error interrupt */
|
---|
857 | iorb_seterr(iorb, IOERR_DEVICE_NONSPECIFIC);
|
---|
858 | }
|
---|
859 |
|
---|
860 | /* Return an error to indicate there's no HW command to be submitted and
|
---|
861 | * that the IORB can be completed "as is" (the upstream code expects the
|
---|
862 | * IORB error code, if any, to be set when this happens and this is exactly
|
---|
863 | * what this function is all about).
|
---|
864 | */
|
---|
865 | return(-1);
|
---|
866 | }
|
---|
867 |
|
---|
868 | /******************************************************************************
|
---|
869 | * Extract vendor and device name from an ATA INDENTIFY buffer. Since strings
|
---|
870 | * in the indentify buffer are byte-swapped, we need to swap them back.
|
---|
871 | */
|
---|
872 | char *ata_dev_name(u16 *id_buf)
|
---|
873 | {
|
---|
874 | static char dev_name[ATA_ID_PROD_LEN + 1];
|
---|
875 | char *t = dev_name;
|
---|
876 | char *s = (char *) (id_buf + ATA_ID_PROD);
|
---|
877 | int i;
|
---|
878 |
|
---|
879 | dev_name[sizeof(dev_name)-1] = '\0';
|
---|
880 |
|
---|
881 | for (i = 0; i < ATA_ID_PROD_LEN / 2; i++) {
|
---|
882 | *(t++) = s[1];
|
---|
883 | *(t++) = s[0];
|
---|
884 | s += 2;
|
---|
885 | }
|
---|
886 |
|
---|
887 | return(dev_name);
|
---|
888 | }
|
---|
889 |
|
---|