int scan_sata(int port) { unsigned char serial[ATA_ID_SERNO_LEN + 1]; unsigned char firmware[ATA_ID_FW_REV_LEN + 1]; unsigned char product[ATA_ID_PROD_LEN + 1]; u64 n_sectors; u16 *id; struct mv_priv *priv = (struct mv_priv *)sata_dev_desc[port].priv; if (!priv->link) return -ENODEV; id = (u16 *)malloc(ATA_ID_WORDS * 2); if (!id) { printf("Failed to malloc id data\n"); return -ENOMEM; } mv_sata_identify(port, id); ata_swap_buf_le16(id, ATA_ID_WORDS); #ifdef DEBUG ata_dump_id(id); #endif /* Serial number */ ata_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial)); memcpy(sata_dev_desc[port].product, serial, sizeof(serial)); /* Firmware version */ ata_id_c_string(id, firmware, ATA_ID_FW_REV, sizeof(firmware)); memcpy(sata_dev_desc[port].revision, firmware, sizeof(firmware)); /* Product model */ ata_id_c_string(id, product, ATA_ID_PROD, sizeof(product)); memcpy(sata_dev_desc[port].vendor, product, sizeof(product)); /* Total sectors */ n_sectors = ata_id_n_sectors(id); sata_dev_desc[port].lba = n_sectors; /* Check if support LBA48 */ if (ata_id_has_lba48(id)) { sata_dev_desc[port].lba48 = 1; debug("Device support LBA48\n"); } /* Get the NCQ queue depth from device */ priv->queue_depth = ata_id_queue_depth(id); /* Get the xfer mode from device */ mv_sata_xfer_mode(port, id); /* Set the xfer mode to highest speed */ mv_sata_set_features(port); /* Start up */ mv_start_edma_engine(port); return 0; }
int scan_sata(int dev) { fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; unsigned char serial[ATA_ID_SERNO_LEN + 1]; unsigned char firmware[ATA_ID_FW_REV_LEN + 1]; unsigned char product[ATA_ID_PROD_LEN + 1]; u16 *id; u64 n_sectors; /* if no detected link */ if (!sata->link) return -1; id = (u16 *)malloc(ATA_ID_WORDS * 2); if (!id) { printf("id malloc failed\n\r"); return -1; } /* Identify device to get information */ fsl_sata_identify(dev, id); /* Serial number */ ata_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial)); memcpy(sata_dev_desc[dev].product, serial, sizeof(serial)); /* Firmware version */ ata_id_c_string(id, firmware, ATA_ID_FW_REV, sizeof(firmware)); memcpy(sata_dev_desc[dev].revision, firmware, sizeof(firmware)); /* Product model */ ata_id_c_string(id, product, ATA_ID_PROD, sizeof(product)); memcpy(sata_dev_desc[dev].vendor, product, sizeof(product)); /* Totoal sectors */ n_sectors = ata_id_n_sectors(id); sata_dev_desc[dev].lba = (u32)n_sectors; /* Check if support LBA48 */ if (ata_id_has_lba48(id)) { sata_dev_desc[dev].lba48 = 1; debug("Device support LBA48\n\r"); } /* Get the NCQ queue depth from device */ sata->queue_depth = ata_id_queue_depth(id); /* Get the xfer mode from device */ fsl_sata_xfer_mode(dev, id); /* Get the write cache status from device */ fsl_sata_init_wcache(dev, id); /* Set the xfer mode to highest speed */ fsl_sata_set_features(dev); #ifdef DEBUG fsl_sata_identify(dev, id); ata_dump_id(id); #endif free((void *)id); return 0; }