]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/block/ahci.c
applied patches from Freescale and Ka-Ro
[karo-tx-uboot.git] / drivers / block / ahci.c
1 /*
2  * (C) Copyright 2008-2010 Freescale Semiconductor, Inc.
3  * Terry Lv <r65388@freescale.com>
4  *
5  * Copyright (C) Freescale Semiconductor, Inc. 2006.
6  * Author: Jason Jin<Jason.jin@freescale.com>
7  *         Zhang Wei<wei.zhang@freescale.com>
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (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,
25  * MA 02111-1307 USA
26  *
27  * with the reference on libata and ahci drvier in kernel
28  *
29  */
30 #include <common.h>
31
32 #include <command.h>
33 #include <pci.h>
34 #include <asm/processor.h>
35 #include <asm/errno.h>
36 #include <asm/io.h>
37 #include <malloc.h>
38 #include <scsi.h>
39 #include <ata.h>
40 #include <linux/ctype.h>
41 #include <ahci.h>
42
43 struct ahci_probe_ent *probe_ent = NULL;
44 hd_driveid_t *ataid[AHCI_MAX_PORTS];
45
46 #define writel_with_flush(a,b)  do { writel(a,b); readl(b); } while (0)
47
48
49 static inline u32 ahci_port_base(u32 base, u32 port)
50 {
51         return base + 0x100 + (port * 0x80);
52 }
53
54
55 static void ahci_setup_port(struct ahci_ioports *port, unsigned long base,
56                             unsigned int port_idx)
57 {
58         base = ahci_port_base(base, port_idx);
59
60         port->cmd_addr = base;
61         port->scr_addr = base + PORT_SCR;
62 }
63
64
65 #define msleep(a) udelay(a * 1000)
66 #define ssleep(a) msleep(a * 1000)
67
68 static int waiting_for_cmd_completed(volatile u8 *offset,
69                                      int timeout_msec,
70                                      u32 sign)
71 {
72         int i;
73         u32 status;
74
75         for (i = 0; ((status = readl(offset)) & sign) && i < timeout_msec; i++)
76                 msleep(1);
77
78         return (i < timeout_msec) ? 0 : -1;
79 }
80
81
82 static int ahci_host_init(struct ahci_probe_ent *probe_ent)
83 {
84         pci_dev_t pdev = probe_ent->dev;
85         volatile u8 *mmio = (volatile u8 *)probe_ent->mmio_base;
86         u32 tmp, cap_save;
87         u16 tmp16;
88         int i, j;
89         volatile u8 *port_mmio;
90         unsigned short vendor;
91
92         cap_save = readl(mmio + HOST_CAP);
93         cap_save &= ((1 << 28) | (1 << 17));
94         cap_save |= (1 << 27);
95
96         /* global controller reset */
97         tmp = readl(mmio + HOST_CTL);
98         if ((tmp & HOST_RESET) == 0)
99                 writel_with_flush(tmp | HOST_RESET, mmio + HOST_CTL);
100
101         /* reset must complete within 1 second, or
102          * the hardware should be considered fried.
103          */
104         ssleep(1);
105
106         tmp = readl(mmio + HOST_CTL);
107         if (tmp & HOST_RESET) {
108                 debug("controller reset failed (0x%x)\n", tmp);
109                 return -1;
110         }
111
112         writel_with_flush(HOST_AHCI_EN, mmio + HOST_CTL);
113         writel(cap_save, mmio + HOST_CAP);
114         writel_with_flush(0xf, mmio + HOST_PORTS_IMPL);
115
116         pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor);
117
118         if (vendor == PCI_VENDOR_ID_INTEL) {
119                 u16 tmp16;
120                 pci_read_config_word(pdev, 0x92, &tmp16);
121                 tmp16 |= 0xf;
122                 pci_write_config_word(pdev, 0x92, tmp16);
123         }
124
125         probe_ent->cap = readl(mmio + HOST_CAP);
126         probe_ent->port_map = readl(mmio + HOST_PORTS_IMPL);
127         probe_ent->n_ports = (probe_ent->cap & 0x1f) + 1;
128
129         debug("cap 0x%x  port_map 0x%x  n_ports %d\n",
130               probe_ent->cap, probe_ent->port_map, probe_ent->n_ports);
131
132         for (i = 0; i < probe_ent->n_ports; i++) {
133                 probe_ent->port[i].port_mmio = ahci_port_base((u32) mmio, i);
134                 port_mmio = (u8 *) probe_ent->port[i].port_mmio;
135                 ahci_setup_port(&probe_ent->port[i], (unsigned long)mmio, i);
136
137                 /* make sure port is not active */
138                 tmp = readl(port_mmio + PORT_CMD);
139                 if (tmp & (PORT_CMD_LIST_ON | PORT_CMD_FIS_ON |
140                            PORT_CMD_FIS_RX | PORT_CMD_START)) {
141                         tmp &= ~(PORT_CMD_LIST_ON | PORT_CMD_FIS_ON |
142                                  PORT_CMD_FIS_RX | PORT_CMD_START);
143                         writel_with_flush(tmp, port_mmio + PORT_CMD);
144
145                         /* spec says 500 msecs for each bit, so
146                          * this is slightly incorrect.
147                          */
148                         msleep(500);
149                 }
150
151                 writel(PORT_CMD_SPIN_UP, port_mmio + PORT_CMD);
152
153                 j = 0;
154                 while (j < 100) {
155                         msleep(10);
156                         tmp = readl(port_mmio + PORT_SCR_STAT);
157                         if ((tmp & 0xf) == 0x3)
158                                 break;
159                         j++;
160                 }
161
162                 tmp = readl(port_mmio + PORT_SCR_ERR);
163                 debug("PORT_SCR_ERR 0x%x\n", tmp);
164                 writel(tmp, port_mmio + PORT_SCR_ERR);
165
166                 /* ack any pending irq events for this port */
167                 tmp = readl(port_mmio + PORT_IRQ_STAT);
168                 debug("PORT_IRQ_STAT 0x%x\n", tmp);
169                 if (tmp)
170                         writel(tmp, port_mmio + PORT_IRQ_STAT);
171
172                 writel(1 << i, mmio + HOST_IRQ_STAT);
173
174                 /* set irq mask (enables interrupts) */
175                 writel(DEF_PORT_IRQ, port_mmio + PORT_IRQ_MASK);
176
177                 /*register linkup ports */
178                 tmp = readl(port_mmio + PORT_SCR_STAT);
179                 debug("Port %d status: 0x%x\n", i, tmp);
180                 if ((tmp & 0xf) == 0x03)
181                         probe_ent->link_port_map |= (0x01 << i);
182         }
183
184         tmp = readl(mmio + HOST_CTL);
185         debug("HOST_CTL 0x%x\n", tmp);
186         writel(tmp | HOST_IRQ_EN, mmio + HOST_CTL);
187         tmp = readl(mmio + HOST_CTL);
188         debug("HOST_CTL 0x%x\n", tmp);
189
190         pci_read_config_word(pdev, PCI_COMMAND, &tmp16);
191         tmp |= PCI_COMMAND_MASTER;
192         pci_write_config_word(pdev, PCI_COMMAND, tmp16);
193
194         return 0;
195 }
196
197
198 static void ahci_print_info(struct ahci_probe_ent *probe_ent)
199 {
200         pci_dev_t pdev = probe_ent->dev;
201         volatile u8 *mmio = (volatile u8 *)probe_ent->mmio_base;
202         u32 vers, cap, impl, speed;
203         const char *speed_s;
204         u16 cc;
205         const char *scc_s;
206
207         vers = readl(mmio + HOST_VERSION);
208         cap = probe_ent->cap;
209         impl = probe_ent->port_map;
210
211         speed = (cap >> 20) & 0xf;
212         if (speed == 1)
213                 speed_s = "1.5";
214         else if (speed == 2)
215                 speed_s = "3";
216         else
217                 speed_s = "?";
218
219         pci_read_config_word(pdev, 0x0a, &cc);
220         if (cc == 0x0101)
221                 scc_s = "IDE";
222         else if (cc == 0x0106)
223                 scc_s = "SATA";
224         else if (cc == 0x0104)
225                 scc_s = "RAID";
226         else
227                 scc_s = "unknown";
228
229         printf("AHCI %02x%02x.%02x%02x "
230                "%u slots %u ports %s Gbps 0x%x impl %s mode\n",
231                (vers >> 24) & 0xff,
232                (vers >> 16) & 0xff,
233                (vers >> 8) & 0xff,
234                vers & 0xff,
235                ((cap >> 8) & 0x1f) + 1, (cap & 0x1f) + 1, speed_s, impl, scc_s);
236
237         printf("flags: "
238                "%s%s%s%s%s%s"
239                "%s%s%s%s%s%s%s\n",
240                cap & (1 << 31) ? "64bit " : "",
241                cap & (1 << 30) ? "ncq " : "",
242                cap & (1 << 28) ? "ilck " : "",
243                cap & (1 << 27) ? "stag " : "",
244                cap & (1 << 26) ? "pm " : "",
245                cap & (1 << 25) ? "led " : "",
246                cap & (1 << 24) ? "clo " : "",
247                cap & (1 << 19) ? "nz " : "",
248                cap & (1 << 18) ? "only " : "",
249                cap & (1 << 17) ? "pmp " : "",
250                cap & (1 << 15) ? "pio " : "",
251                cap & (1 << 14) ? "slum " : "",
252                cap & (1 << 13) ? "part " : "");
253 }
254
255 static int ahci_init_one(pci_dev_t pdev)
256 {
257         u16 vendor;
258         int rc;
259
260         memset((void *)ataid, 0, sizeof(hd_driveid_t *) * AHCI_MAX_PORTS);
261
262         probe_ent = malloc(sizeof(struct ahci_probe_ent));
263         memset(probe_ent, 0, sizeof(struct ahci_probe_ent));
264         probe_ent->dev = pdev;
265
266         probe_ent->host_flags = ATA_FLAG_SATA
267                                 | ATA_FLAG_NO_LEGACY
268                                 | ATA_FLAG_MMIO
269                                 | ATA_FLAG_PIO_DMA
270                                 | ATA_FLAG_NO_ATAPI;
271         probe_ent->pio_mask = 0x1f;
272         probe_ent->udma_mask = 0x7f;    /*Fixme,assume to support UDMA6 */
273
274         probe_ent->mmio_base = (u32)pci_map_bar(pdev, AHCI_PCI_BAR,
275                                                 PCI_REGION_MEM);
276
277         /* Take from kernel:
278          * JMicron-specific fixup:
279          * make sure we're in AHCI mode
280          */
281         pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor);
282         if (vendor == 0x197b)
283                 pci_write_config_byte(pdev, 0x41, 0xa1);
284
285         /* initialize adapter */
286         rc = ahci_host_init(probe_ent);
287         if (rc)
288                 goto err_out;
289
290         ahci_print_info(probe_ent);
291
292         return 0;
293
294       err_out:
295         return rc;
296 }
297
298
299 #define MAX_DATA_BYTE_COUNT  (4*1024*1024)
300
301 static int ahci_fill_sg(u8 port, unsigned char *buf, int buf_len)
302 {
303         struct ahci_ioports *pp = &(probe_ent->port[port]);
304         struct ahci_sg *ahci_sg = pp->cmd_tbl_sg;
305         u32 sg_count;
306         int i;
307
308         sg_count = ((buf_len - 1) / MAX_DATA_BYTE_COUNT) + 1;
309         if (sg_count > AHCI_MAX_SG) {
310                 printf("Error:Too much sg!\n");
311                 return -1;
312         }
313
314         for (i = 0; i < sg_count; i++) {
315                 ahci_sg->addr =
316                     cpu_to_le32((u32) buf + i * MAX_DATA_BYTE_COUNT);
317                 ahci_sg->addr_hi = 0;
318                 ahci_sg->flags_size = cpu_to_le32(0x3fffff &
319                                           (buf_len < MAX_DATA_BYTE_COUNT
320                                            ? (buf_len - 1)
321                                            : (MAX_DATA_BYTE_COUNT - 1)));
322                 ahci_sg++;
323                 buf_len -= MAX_DATA_BYTE_COUNT;
324         }
325
326         return sg_count;
327 }
328
329
330 static void ahci_fill_cmd_slot(struct ahci_ioports *pp, u32 opts)
331 {
332         pp->cmd_slot->opts = cpu_to_le32(opts);
333         pp->cmd_slot->status = 0;
334         pp->cmd_slot->tbl_addr = cpu_to_le32(pp->cmd_tbl & 0xffffffff);
335         pp->cmd_slot->tbl_addr_hi = 0;
336 }
337
338
339 static void ahci_set_feature(u8 port)
340 {
341         struct ahci_ioports *pp = &(probe_ent->port[port]);
342         volatile u8 *port_mmio = (volatile u8 *)pp->port_mmio;
343         u32 cmd_fis_len = 5;    /* five dwords */
344         u8 fis[20];
345
346         /*set feature */
347         memset(fis, 0, 20);
348         fis[0] = 0x27;
349         fis[1] = 1 << 7;
350         fis[2] = ATA_CMD_SETF;
351         fis[3] = SETFEATURES_XFER;
352         fis[12] = __ilog2(probe_ent->udma_mask + 1) + 0x40 - 0x01;
353
354         memcpy((unsigned char *)pp->cmd_tbl, fis, 20);
355         ahci_fill_cmd_slot(pp, cmd_fis_len);
356         writel(1, port_mmio + PORT_CMD_ISSUE);
357         readl(port_mmio + PORT_CMD_ISSUE);
358
359         if (waiting_for_cmd_completed(port_mmio + PORT_CMD_ISSUE, 150, 0x1)) {
360                 printf("set feature error!\n");
361         }
362 }
363
364
365 static int ahci_port_start(u8 port)
366 {
367         struct ahci_ioports *pp = &(probe_ent->port[port]);
368         volatile u8 *port_mmio = (volatile u8 *)pp->port_mmio;
369         u32 port_status;
370         u32 mem;
371
372         debug("Enter start port: %d\n", port);
373         port_status = readl(port_mmio + PORT_SCR_STAT);
374         debug("Port %d status: %x\n", port, port_status);
375         if ((port_status & 0xf) != 0x03) {
376                 printf("No Link on this port!\n");
377                 return -1;
378         }
379
380         mem = (u32) malloc(AHCI_PORT_PRIV_DMA_SZ + 2048);
381         if (!mem) {
382                 free(pp);
383                 printf("No mem for table!\n");
384                 return -ENOMEM;
385         }
386
387         mem = (mem + 0x800) & (~0x7ff); /* Aligned to 2048-bytes */
388         memset((u8 *) mem, 0, AHCI_PORT_PRIV_DMA_SZ);
389
390         /*
391          * First item in chunk of DMA memory: 32-slot command table,
392          * 32 bytes each in size
393          */
394         pp->cmd_slot = (struct ahci_cmd_hdr *)mem;
395         debug("cmd_slot = 0x%x\n", pp->cmd_slot);
396         mem += (AHCI_CMD_SLOT_SZ * AHCI_MAX_CMD_SLOT);
397
398         /*
399          * Second item: Received-FIS area
400          */
401         pp->rx_fis = mem;
402         mem += AHCI_RX_FIS_SZ;
403
404         /*
405          * Third item: data area for storing a single command
406          * and its scatter-gather table
407          */
408         pp->cmd_tbl = mem;
409         debug("cmd_tbl_dma = 0x%x\n", pp->cmd_tbl);
410
411         mem += AHCI_CMD_TBL_HDR;
412         pp->cmd_tbl_sg = (struct ahci_sg *)mem;
413
414         writel_with_flush((u32) pp->cmd_slot, port_mmio + PORT_LST_ADDR);
415
416         writel_with_flush(pp->rx_fis, port_mmio + PORT_FIS_ADDR);
417
418         writel_with_flush(PORT_CMD_ICC_ACTIVE | PORT_CMD_FIS_RX |
419                           PORT_CMD_POWER_ON | PORT_CMD_SPIN_UP |
420                           PORT_CMD_START, port_mmio + PORT_CMD);
421
422         debug("Exit start port %d\n", port);
423
424         return 0;
425 }
426
427
428 static int get_ahci_device_data(u8 port, u8 *fis, int fis_len, u8 *buf,
429                                 int buf_len)
430 {
431
432         struct ahci_ioports *pp = &(probe_ent->port[port]);
433         volatile u8 *port_mmio = (volatile u8 *)pp->port_mmio;
434         u32 opts;
435         u32 port_status;
436         int sg_count;
437
438         debug("Enter get_ahci_device_data: for port %d\n", port);
439
440         if (port > probe_ent->n_ports) {
441                 printf("Invaild port number %d\n", port);
442                 return -1;
443         }
444
445         port_status = readl(port_mmio + PORT_SCR_STAT);
446         if ((port_status & 0xf) != 0x03) {
447                 debug("No Link on port %d!\n", port);
448                 return -1;
449         }
450
451         memcpy((unsigned char *)pp->cmd_tbl, fis, fis_len);
452
453         sg_count = ahci_fill_sg(port, buf, buf_len);
454         opts = (fis_len >> 2) | (sg_count << 16);
455         ahci_fill_cmd_slot(pp, opts);
456
457         writel_with_flush(1, port_mmio + PORT_CMD_ISSUE);
458
459         if (waiting_for_cmd_completed(port_mmio + PORT_CMD_ISSUE, 150, 0x1)) {
460                 printf("timeout exit!\n");
461                 return -1;
462         }
463         debug("get_ahci_device_data: %d byte transferred.\n",
464               pp->cmd_slot->status);
465
466         return 0;
467 }
468
469
470 static char *ata_id_strcpy(u16 *target, u16 *src, int len)
471 {
472         int i;
473         for (i = 0; i < len / 2; i++)
474                 target[i] = le16_to_cpu(src[i]);
475         return (char *)target;
476 }
477
478
479 static void dump_ataid(hd_driveid_t *ataid)
480 {
481         debug("(49)ataid->capability = 0x%x\n", ataid->capability);
482         debug("(53)ataid->field_valid =0x%x\n", ataid->field_valid);
483         debug("(63)ataid->dma_mword = 0x%x\n", ataid->dma_mword);
484         debug("(64)ataid->eide_pio_modes = 0x%x\n", ataid->eide_pio_modes);
485         debug("(75)ataid->queue_depth = 0x%x\n", ataid->queue_depth);
486         debug("(80)ataid->major_rev_num = 0x%x\n", ataid->major_rev_num);
487         debug("(81)ataid->minor_rev_num = 0x%x\n", ataid->minor_rev_num);
488         debug("(82)ataid->command_set_1 = 0x%x\n", ataid->command_set_1);
489         debug("(83)ataid->command_set_2 = 0x%x\n", ataid->command_set_2);
490         debug("(84)ataid->cfsse = 0x%x\n", ataid->cfsse);
491         debug("(85)ataid->cfs_enable_1 = 0x%x\n", ataid->cfs_enable_1);
492         debug("(86)ataid->cfs_enable_2 = 0x%x\n", ataid->cfs_enable_2);
493         debug("(87)ataid->csf_default = 0x%x\n", ataid->csf_default);
494         debug("(88)ataid->dma_ultra = 0x%x\n", ataid->dma_ultra);
495         debug("(93)ataid->hw_config = 0x%x\n", ataid->hw_config);
496 }
497
498
499 /*
500  * SCSI INQUIRY command operation.
501  */
502 static int ata_scsiop_inquiry(ccb *pccb)
503 {
504         u8 hdr[] = {
505                 0,
506                 0,
507                 0x5,            /* claim SPC-3 version compatibility */
508                 2,
509                 95 - 4,
510         };
511         u8 fis[20];
512         u8 *tmpid;
513         u8 port;
514
515         /* Clean ccb data buffer */
516         memset(pccb->pdata, 0, pccb->datalen);
517
518         memcpy(pccb->pdata, hdr, sizeof(hdr));
519
520         if (pccb->datalen <= 35)
521                 return 0;
522
523         memset(fis, 0, 20);
524         /* Construct the FIS */
525         fis[0] = 0x27;          /* Host to device FIS. */
526         fis[1] = 1 << 7;        /* Command FIS. */
527         fis[2] = ATA_CMD_IDENT; /* Command byte. */
528
529         /* Read id from sata */
530         port = pccb->target;
531         if (!(tmpid = malloc(sizeof(hd_driveid_t))))
532                 return -ENOMEM;
533
534         if (get_ahci_device_data(port, (u8 *) & fis, 20,
535                                  tmpid, sizeof(hd_driveid_t))) {
536                 debug("scsi_ahci: SCSI inquiry command failure.\n");
537                 return -EIO;
538         }
539
540         if (ataid[port])
541                 free(ataid[port]);
542         ataid[port] = (hd_driveid_t *) tmpid;
543
544         memcpy(&pccb->pdata[8], "ATA     ", 8);
545         ata_id_strcpy((u16 *) &pccb->pdata[16], (u16 *)ataid[port]->model, 16);
546         ata_id_strcpy((u16 *) &pccb->pdata[32], (u16 *)ataid[port]->fw_rev, 4);
547
548         dump_ataid(ataid[port]);
549         return 0;
550 }
551
552
553 /*
554  * SCSI READ10 command operation.
555  */
556 static int ata_scsiop_read10(ccb * pccb)
557 {
558         u64 lba = 0;
559         u32 len = 0;
560         u8 fis[20];
561
562         lba = (((u64) pccb->cmd[2]) << 24) | (((u64) pccb->cmd[3]) << 16)
563             | (((u64) pccb->cmd[4]) << 8) | ((u64) pccb->cmd[5]);
564         len = (((u32) pccb->cmd[7]) << 8) | ((u32) pccb->cmd[8]);
565
566         /* For 10-byte and 16-byte SCSI R/W commands, transfer
567          * length 0 means transfer 0 block of data.
568          * However, for ATA R/W commands, sector count 0 means
569          * 256 or 65536 sectors, not 0 sectors as in SCSI.
570          *
571          * WARNING: one or two older ATA drives treat 0 as 0...
572          */
573         if (!len)
574                 return 0;
575         memset(fis, 0, 20);
576
577         /* Construct the FIS */
578         fis[0] = 0x27;          /* Host to device FIS. */
579         fis[1] = 1 << 7;        /* Command FIS. */
580         fis[2] = ATA_CMD_RD_DMA;        /* Command byte. */
581
582         /* LBA address, only support LBA28 in this driver */
583         fis[4] = pccb->cmd[5];
584         fis[5] = pccb->cmd[4];
585         fis[6] = pccb->cmd[3];
586         fis[7] = (pccb->cmd[2] & 0x0f) | 0xe0;
587
588         /* Sector Count */
589         fis[12] = pccb->cmd[8];
590         fis[13] = pccb->cmd[7];
591
592         /* Read from ahci */
593         if (get_ahci_device_data(pccb->target, (u8 *) & fis, 20,
594                                  pccb->pdata, pccb->datalen)) {
595                 debug("scsi_ahci: SCSI READ10 command failure.\n");
596                 return -EIO;
597         }
598
599         return 0;
600 }
601
602
603 /*
604  * SCSI READ CAPACITY10 command operation.
605  */
606 static int ata_scsiop_read_capacity10(ccb *pccb)
607 {
608         u32 cap;
609
610         if (!ataid[pccb->target]) {
611                 printf("scsi_ahci: SCSI READ CAPACITY10 command failure. "
612                        "\tNo ATA info!\n"
613                        "\tPlease run SCSI commmand INQUIRY firstly!\n");
614                 return -EPERM;
615         }
616
617         cap = le32_to_cpu(ataid[pccb->target]->lba_capacity);
618         memcpy(pccb->pdata, &cap, sizeof(cap));
619
620         pccb->pdata[4] = pccb->pdata[5] = 0;
621         pccb->pdata[6] = 512 >> 8;
622         pccb->pdata[7] = 512 & 0xff;
623
624         return 0;
625 }
626
627
628 /*
629  * SCSI TEST UNIT READY command operation.
630  */
631 static int ata_scsiop_test_unit_ready(ccb *pccb)
632 {
633         return (ataid[pccb->target]) ? 0 : -EPERM;
634 }
635
636
637 int scsi_exec(ccb *pccb)
638 {
639         int ret;
640
641         switch (pccb->cmd[0]) {
642         case SCSI_READ10:
643                 ret = ata_scsiop_read10(pccb);
644                 break;
645         case SCSI_RD_CAPAC:
646                 ret = ata_scsiop_read_capacity10(pccb);
647                 break;
648         case SCSI_TST_U_RDY:
649                 ret = ata_scsiop_test_unit_ready(pccb);
650                 break;
651         case SCSI_INQUIRY:
652                 ret = ata_scsiop_inquiry(pccb);
653                 break;
654         default:
655                 printf("Unsupport SCSI command 0x%02x\n", pccb->cmd[0]);
656                 return FALSE;
657         }
658
659         if (ret) {
660                 debug("SCSI command 0x%02x ret errno %d\n", pccb->cmd[0], ret);
661                 return FALSE;
662         }
663         return TRUE;
664
665 }
666
667
668 void scsi_low_level_init(int busdevfunc)
669 {
670         int i;
671         u32 linkmap;
672
673         ahci_init_one(busdevfunc);
674
675         linkmap = probe_ent->link_port_map;
676
677         for (i = 0; i < CONFIG_SYS_SCSI_MAX_SCSI_ID; i++) {
678                 if (((linkmap >> i) & 0x01)) {
679                         if (ahci_port_start((u8) i)) {
680                                 printf("Can not start port %d\n", i);
681                                 continue;
682                         }
683                         ahci_set_feature((u8) i);
684                 }
685         }
686 }
687
688
689 void scsi_bus_reset(void)
690 {
691         /*Not implement*/
692 }
693
694
695 void scsi_print_error(ccb * pccb)
696 {
697         /*The ahci error info can be read in the ahci driver*/
698 }