Commit 1fe62aa7 authored by Andrey Filippov's avatar Andrey Filippov

AHCI driver is finally working with x393_sata AHCI SATA controller

parent e94696c1
......@@ -61,9 +61,10 @@ static int elphel_port_start(struct ata_port *ap)
int dbg_i;
libahci_debug_init(ap->host);
dev_info(dev, "starting port %d", ap->port_no);
dev_dbg(dev, "starting port %d", ap->port_no);
#ifdef DEBUG_EVENT_ELPHEL
libahci_debug_wait_flag();
#endif
pp = devm_kzalloc(dev, sizeof(struct ahci_port_priv), GFP_KERNEL);
if (!pp)
return -ENOMEM;
......@@ -98,10 +99,10 @@ address must be aligned to a 128-byte cache line, indicated by bits 06:00 being
*/
mem_dma = dma_map_single(dev, mem, AHCI_CMD_TBL_AR_SZ, DMA_TO_DEVICE); // maybe DMA_BIDIRECTIONAL, but currently we do not use DMA for received FISes
dev_info(dev, "ahci_elphel.c: dbg_i= 0x%08x, mem= 0x%08x, mem_dma= 0x%08x", dbg_i, (u32) mem, (u32) mem_dma);
dev_dbg(dev, "ahci_elphel.c: dbg_i= 0x%08x, mem= 0x%08x, mem_dma= 0x%08x", dbg_i, (u32) mem, (u32) mem_dma);
pp->cmd_tbl = mem + dbg_i;
pp->cmd_tbl_dma = mem_dma + dbg_i;
dev_info(dev, "ahci_elphel.c: dbg_i= 0x%08x, pp->cmd_tbl= 0x%08x, pp->cmd_tbl_dma= 0x%08x", dbg_i, (u32) pp->cmd_tbl, (u32) pp->cmd_tbl_dma);
dev_dbg(dev, "ahci_elphel.c: dbg_i= 0x%08x, pp->cmd_tbl= 0x%08x, pp->cmd_tbl_dma= 0x%08x", dbg_i, (u32) pp->cmd_tbl, (u32) pp->cmd_tbl_dma);
/*
* Set predefined addresses
......@@ -134,10 +135,10 @@ address must be aligned to a 128-byte cache line, indicated by bits 06:00 being
//libahci_debug_saxigp1_save(ap, 0x3000);
//libahci_debug_saxigp1_save(ap, 0x3000);
dev_info(dev, "flags (ATA_FLAG_xxx): %u", ap->flags);
dev_info(dev, "pflags (ATA_PFLAG_xxx): %u", ap->pflags);
dev_dbg(dev, "flags (ATA_FLAG_xxx): %u", ap->flags);
dev_dbg(dev, "pflags (ATA_PFLAG_xxx): %u", ap->pflags);
dev_info(dev, "ahci_elphel.c: Calling ahci_port_resume()");
dev_dbg(dev, "ahci_elphel.c: Calling ahci_port_resume()");
return ahci_port_resume(ap);
}
......@@ -162,7 +163,7 @@ static int elphel_parse_prop(const struct device_node *devn,
val = of_get_address(devn, 0, NULL, NULL);
if (val != NULL) {
dpriv->base_addr = be32_to_cpu(val);
dev_info(dev, "base_addr: 0x%08u", dpriv->base_addr);
dev_dbg(dev, "base_addr: 0x%08u", dpriv->base_addr);
} else {
dev_err(dev, "can not get register address");
}
......@@ -203,15 +204,15 @@ static int elphel_drv_probe(struct platform_device *pdev)
hpriv->plat_data = drv_priv;
reg_val = readl(hpriv->mmio + HOST_CAP);
dev_info(dev, "HOST CAP register: 0x%08x", reg_val);
dev_dbg(dev, "HOST CAP register: 0x%08x", reg_val);
reg_val = readl(hpriv->mmio + HOST_CTL);
dev_info(dev, "HOST GHC register: 0x%08x", reg_val);
dev_dbg(dev, "HOST GHC register: 0x%08x", reg_val);
reg_val = readl(hpriv->mmio + HOST_IRQ_STAT);
dev_info(dev, "HOST IS register: 0x%08x", reg_val);
dev_dbg(dev, "HOST IS register: 0x%08x", reg_val);
reg_val = readl(hpriv->mmio + HOST_PORTS_IMPL);
dev_info(dev, "HOST PI register: 0x%08x", reg_val);
dev_dbg(dev, "HOST PI register: 0x%08x", reg_val);
reg_val = readl(hpriv->mmio + HOST_VERSION);
dev_info(dev, "HOST VS register: 0x%08x", reg_val);
dev_dbg(dev, "HOST VS register: 0x%08x", reg_val);
phys_addr_t paddr = virt_to_phys(hpriv->mmio);
void *vaddr = phys_to_virt(paddr);
......@@ -232,7 +233,7 @@ static int elphel_drv_probe(struct platform_device *pdev)
ahci_platform_disable_resources(hpriv);
return ret;
}
dev_info(dev, "ahci platform host initialized");
dev_dbg(dev, "ahci platform host initialized");
return 0;
}
......@@ -257,7 +258,7 @@ static unsigned int elphel_read_id(struct ata_device *dev, struct ata_taskfile *
if (err_mask)
return err_mask;
dev_info(d, "elphel_read_id(): issue identify command finished\n");
dev_dbg(d, "elphel_read_id(): issue identify command finished\n");
/*dev_info(d, "dump IDENTIFY:\n");
msg_str = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!msg_str)
......
......@@ -204,18 +204,21 @@ static void ahci_enable_ahci(void __iomem *mmio)
int i;
u32 tmp;
#ifdef DEBUG_EVENT_ELPHEL
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
int len;
#endif
/* turn on AHCI_EN */
tmp = readl(mmio + HOST_CTL);
if (tmp & HOST_AHCI_EN) {// MSB (0x80000000) is already set (RO in x393_sata)
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "ahci_enable_ahci() - already enabled");
libahci_debug_event(NULL, msg_str, len);
kfree(msg_str);
msg_str = NULL;
}
#endif
return;
}
/* Some controllers need AHCI_EN to be written multiple times.
......@@ -226,13 +229,14 @@ static void ahci_enable_ahci(void __iomem *mmio)
writel(tmp, mmio + HOST_CTL);
tmp = readl(mmio + HOST_CTL); /* flush && sanity check */
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "write HOST_AHCI_EN to HOST_CTL register");
libahci_debug_event(NULL, msg_str, len);
kfree(msg_str);
msg_str = NULL;
}
#endif
if (tmp & HOST_AHCI_EN)
return;
msleep(10);
......@@ -295,6 +299,7 @@ static ssize_t ahci_read_em_buffer(struct device *dev,
size_t count;
int i;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -302,7 +307,7 @@ static ssize_t ahci_read_em_buffer(struct device *dev,
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
spin_lock_irqsave(ap->lock, flags);
em_ctl = readl(mmio + HOST_EM_CTL);
......@@ -359,6 +364,7 @@ static ssize_t ahci_store_em_buffer(struct device *dev,
unsigned long flags;
int i;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -366,7 +372,7 @@ static ssize_t ahci_store_em_buffer(struct device *dev,
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
/* check size validity */
if (!(ap->flags & ATA_FLAG_EM) ||
......@@ -437,6 +443,7 @@ void ahci_save_initial_config(struct device *dev, struct ahci_host_priv *hpriv)
u32 cap, cap2, vers, port_map;
int i;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -444,7 +451,7 @@ void ahci_save_initial_config(struct device *dev, struct ahci_host_priv *hpriv)
libahci_debug_event(NULL, msg_str, len);
kfree(msg_str);
}
#endif
/* make sure AHCI mode is enabled before accessing CAP */
ahci_enable_ahci(mmio);
......@@ -573,6 +580,7 @@ static void ahci_restore_initial_config(struct ata_host *host)
struct ahci_host_priv *hpriv = host->private_data;
void __iomem *mmio = hpriv->mmio;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -580,7 +588,7 @@ static void ahci_restore_initial_config(struct ata_host *host)
libahci_debug_event(NULL, msg_str, len);
kfree(msg_str);
}
#endif
writel(hpriv->saved_cap, mmio + HOST_CAP);
if (hpriv->saved_cap2)
writel(hpriv->saved_cap2, mmio + HOST_CAP2);
......@@ -610,29 +618,32 @@ static int ahci_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
void __iomem *port_mmio = ahci_port_base(link->ap);
int offset = ahci_scr_offset(link->ap, sc_reg);
int len;
#ifdef DEBUG_EVENT_ELPHEL
int len;
u32 tmp;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "ahci_scr_read() port=%u SATA status and control registers %u", link->ap->port_no,sc_reg);
libahci_debug_event(link->ap, msg_str, len);
}
#endif
if (offset) {
*val = readl(port_mmio + offset);
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL) {
tmp = readl(port_mmio + PORT_CMD);
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "\tport %u offset: 0x%x, value: 0x%x (current PxCMD=0x%08x)", link->ap->port_no, offset, *val, tmp);
libahci_debug_event(link->ap, msg_str, len);
}
kfree(msg_str);
#endif
return 0;
}
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL)
kfree(msg_str);
#endif
return -EINVAL;
}
......@@ -641,26 +652,30 @@ static int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
void __iomem *port_mmio = ahci_port_base(link->ap);
int offset = ahci_scr_offset(link->ap, sc_reg);
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "ahci_scr_write(): port %u SATA status and control registers", link->ap->port_no);
libahci_debug_event(link->ap, msg_str, len);
}
#endif
if (offset) {
writel(val, port_mmio + offset);
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "\tport %u offset: 0x%x, value: 0x%x", link->ap->port_no, offset, val);
libahci_debug_event(link->ap, msg_str, len);
}
kfree(msg_str);
#endif
return 0;
}
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL)
kfree(msg_str);
#endif
return -EINVAL;
}
......@@ -669,25 +684,28 @@ void ahci_start_engine(struct ata_port *ap)
void __iomem *port_mmio = ahci_port_base(ap);
u32 tmp;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "ahci_start_engine() port %u set PxCMD.ST", ap->port_no);
libahci_debug_event(ap, msg_str, len);
}
dev_info(ap->host->dev, "ahci_start_engine()\n");
#endif
dev_dbg(ap->host->dev, "ahci_start_engine()\n");
/* start DMA */
tmp = readl(port_mmio + PORT_CMD);
tmp |= PORT_CMD_START;
writel(tmp, port_mmio + PORT_CMD);
readl(port_mmio + PORT_CMD); /* flush */
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "\twrite to port %u register PxCMD, value: 0x%08x", ap->port_no, tmp);
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
}
EXPORT_SYMBOL_GPL(ahci_start_engine);
......@@ -696,22 +714,26 @@ int ahci_stop_engine(struct ata_port *ap)
void __iomem *port_mmio = ahci_port_base(ap);
u32 tmp;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "ahci_stop_engine(): clear PxCMD.ST port %u command list DMA engine", ap->port_no);
libahci_debug_event(ap, msg_str, len);
}
#endif
tmp = readl(port_mmio + PORT_CMD);
/* check if the HBA is idle */
if ((tmp & (PORT_CMD_START | PORT_CMD_LIST_ON)) == 0){
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "\tDMA was not running, no need to stop: (PxCMD=0x%08x)", tmp);
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
return 0;
}
......@@ -725,18 +747,23 @@ int ahci_stop_engine(struct ata_port *ap)
PORT_CMD_LIST_ON, PORT_CMD_LIST_ON, 1, 500);
if (tmp & PORT_CMD_LIST_ON) {
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "\t FAILED waiting PORT_CMD_LIST_ON to clear, PxCMD, value: 0x%08x", tmp);
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
return -EIO;
}
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "\t SUCCESS waiting PORT_CMD_LIST_ON to clear, PxCMD, value: 0x%08x", tmp);
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
return 0;
}
EXPORT_SYMBOL_GPL(ahci_stop_engine);
......@@ -747,7 +774,7 @@ void ahci_start_fis_rx(struct ata_port *ap)
struct ahci_host_priv *hpriv = ap->host->private_data;
struct ahci_port_priv *pp = ap->private_data;
u32 tmp;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -755,7 +782,7 @@ void ahci_start_fis_rx(struct ata_port *ap)
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
/* set FIS registers */
if (hpriv->cap & HOST_CAP_64)
writel((pp->cmd_slot_dma >> 16) >> 16,
......@@ -782,6 +809,7 @@ static int ahci_stop_fis_rx(struct ata_port *ap)
void __iomem *port_mmio = ahci_port_base(ap);
u32 tmp;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -789,7 +817,7 @@ static int ahci_stop_fis_rx(struct ata_port *ap)
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
/* disable FIS reception */
tmp = readl(port_mmio + PORT_CMD);
tmp &= ~PORT_CMD_FIS_RX;
......@@ -812,7 +840,7 @@ static void ahci_power_up(struct ata_port *ap)
struct ahci_host_priv *hpriv = ap->host->private_data;
void __iomem *port_mmio = ahci_port_base(ap);
u32 cmd;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -820,7 +848,7 @@ static void ahci_power_up(struct ata_port *ap)
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
cmd = readl(port_mmio + PORT_CMD) & ~PORT_CMD_ICC_MASK;
/* spin up device */
......@@ -841,6 +869,7 @@ static int ahci_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
struct ahci_port_priv *pp = ap->private_data;
void __iomem *port_mmio = ahci_port_base(ap);
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -848,7 +877,7 @@ static int ahci_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
if (policy != ATA_LPM_MAX_POWER) {
/*
* Disable interrupts on Phy Ready. This keeps us from
......@@ -935,6 +964,7 @@ static void ahci_start_port(struct ata_port *ap)
ssize_t rc;
int i;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -942,6 +972,7 @@ static void ahci_start_port(struct ata_port *ap)
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
/* enable FIS reception */
ahci_start_fis_rx(ap);
......@@ -985,6 +1016,7 @@ static int ahci_deinit_port(struct ata_port *ap, const char **emsg)
{
int rc;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -992,7 +1024,7 @@ static int ahci_deinit_port(struct ata_port *ap, const char **emsg)
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
/* disable DMA */
rc = ahci_stop_engine(ap);
if (rc) {
......@@ -1015,7 +1047,7 @@ int ahci_reset_controller(struct ata_host *host)
struct ahci_host_priv *hpriv = host->private_data;
void __iomem *mmio = hpriv->mmio;
u32 tmp;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -1023,7 +1055,7 @@ int ahci_reset_controller(struct ata_host *host)
libahci_debug_event(NULL, msg_str, len);
kfree(msg_str);
}
#endif
/* we must be in AHCI mode, before using anything
* AHCI-specific, such as HOST_RESET.
*/
......@@ -1071,6 +1103,7 @@ static void ahci_sw_activity(struct ata_link *link)
struct ata_port *ap = link->ap;
struct ahci_port_priv *pp = ap->private_data;
struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -1078,7 +1111,7 @@ static void ahci_sw_activity(struct ata_link *link)
libahci_debug_event(NULL, msg_str, len);
kfree(msg_str);
}
#endif
if (!(link->flags & ATA_LFLAG_SW_ACTIVITY))
return;
......@@ -1096,6 +1129,7 @@ static void ahci_sw_activity_blink(unsigned long arg)
unsigned long led_message = emp->led_state;
u32 activity_led_state;
unsigned long flags;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -1103,7 +1137,7 @@ static void ahci_sw_activity_blink(unsigned long arg)
libahci_debug_event(NULL, msg_str, len);
kfree(msg_str);
}
#endif
led_message &= EM_MSG_LED_VALUE;
led_message |= ap->port_no | (link->pmp << 8);
......@@ -1143,14 +1177,15 @@ static void ahci_init_sw_activity(struct ata_link *link)
struct ata_port *ap = link->ap;
struct ahci_port_priv *pp = ap->private_data;
struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
int len;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "ahci_init_sw_activity()");
libahci_debug_event(NULL, msg_str, len);
kfree(msg_str);
}
#endif
/* init activity stats, setup timer */
emp->saved_activity = emp->activity = 0;
setup_timer(&emp->timer, ahci_sw_activity_blink, (unsigned long)link);
......@@ -1166,6 +1201,7 @@ int ahci_reset_em(struct ata_host *host)
void __iomem *mmio = hpriv->mmio;
u32 em_ctl;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -1173,7 +1209,7 @@ int ahci_reset_em(struct ata_host *host)
libahci_debug_event(NULL, msg_str, len);
kfree(msg_str);
}
#endif
em_ctl = readl(mmio + HOST_EM_CTL);
if ((em_ctl & EM_CTL_TM) || (em_ctl & EM_CTL_RST))
return -EINVAL;
......@@ -1195,6 +1231,7 @@ static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state,
int pmp;
struct ahci_em_priv *emp;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -1202,7 +1239,7 @@ static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state,
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
/* get the slot number from the message */
pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8;
if (pmp < EM_MAX_SLOTS)
......@@ -1255,6 +1292,7 @@ static ssize_t ahci_led_show(struct ata_port *ap, char *buf)
struct ata_link *link;
struct ahci_em_priv *emp;
int rc = 0;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -1262,7 +1300,7 @@ static ssize_t ahci_led_show(struct ata_port *ap, char *buf)
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
ata_for_each_link(link, ap, EDGE) {
emp = &pp->em_priv[link->pmp];
rc += sprintf(buf, "%lx\n", emp->led_state);
......@@ -1277,6 +1315,7 @@ static ssize_t ahci_led_store(struct ata_port *ap, const char *buf,
int pmp;
struct ahci_port_priv *pp = ap->private_data;
struct ahci_em_priv *emp;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -1284,7 +1323,7 @@ static ssize_t ahci_led_store(struct ata_port *ap, const char *buf,
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
if (kstrtouint(buf, 0, &state) < 0)
return -EINVAL;
......@@ -1312,6 +1351,7 @@ static ssize_t ahci_activity_store(struct ata_device *dev, enum sw_activity val)
struct ahci_port_priv *pp = ap->private_data;
struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
u32 port_led_state = emp->led_state;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -1319,7 +1359,7 @@ static ssize_t ahci_activity_store(struct ata_device *dev, enum sw_activity val)
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
/* save the desired Activity LED behavior */
if (val == OFF) {
/* clear LFLAG */
......@@ -1349,6 +1389,7 @@ static ssize_t ahci_activity_show(struct ata_device *dev, char *buf)
struct ata_port *ap = link->ap;
struct ahci_port_priv *pp = ap->private_data;
struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -1356,6 +1397,7 @@ static ssize_t ahci_activity_show(struct ata_device *dev, char *buf)
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
/* display the saved value of activity behavior for this
* disk.
*/
......@@ -1370,6 +1412,7 @@ static void ahci_port_init(struct device *dev, struct ata_port *ap,
int rc;
u32 tmp;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -1377,7 +1420,7 @@ static void ahci_port_init(struct device *dev, struct ata_port *ap,
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
/* make sure port is not active */
rc = ahci_deinit_port(ap, &emsg);
if (rc)
......@@ -1405,6 +1448,7 @@ void ahci_init_controller(struct ata_host *host)
void __iomem *port_mmio;
u32 tmp;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -1412,7 +1456,7 @@ void ahci_init_controller(struct ata_host *host)
libahci_debug_event(NULL, msg_str, len);
kfree(msg_str);
}
#endif
for (i = 0; i < host->n_ports; i++) {
struct ata_port *ap = host->ports[i];
......@@ -1434,6 +1478,7 @@ EXPORT_SYMBOL_GPL(ahci_init_controller);
static void ahci_dev_config(struct ata_device *dev)
{
struct ahci_host_priv *hpriv = dev->link->ap->host->private_data;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -1441,7 +1486,7 @@ static void ahci_dev_config(struct ata_device *dev)
libahci_debug_event(NULL, msg_str, len);
kfree(msg_str);
}
#endif
if (hpriv->flags & AHCI_HFLAG_SECT255) {
dev->max_sectors = 255;
ata_dev_info(dev,
......@@ -1455,21 +1500,23 @@ unsigned int ahci_dev_classify(struct ata_port *ap)
struct ata_taskfile tf;
u32 tmp;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
#endif
tmp = readl(port_mmio + PORT_SIG);
tf.lbah = (tmp >> 24) & 0xff;
tf.lbam = (tmp >> 16) & 0xff;
tf.lbal = (tmp >> 8) & 0xff;
tf.nsect = (tmp) & 0xff;
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "ahci_dev_classify(): reading port %u signature: PxSIG = 0x%08x", ap->port_no, tmp);
libahci_debug_event(ap, msg_str, len);
kfree(msg_str);
}
#endif
return ata_dev_classify(&tf);
}
EXPORT_SYMBOL_GPL(ahci_dev_classify);
......@@ -1479,28 +1526,26 @@ void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
{
dma_addr_t cmd_tbl_dma;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
#endif
cmd_tbl_dma = pp->cmd_tbl_dma + tag * AHCI_CMD_TBL_SZ;
pp->cmd_slot[tag].opts = cpu_to_le32(opts);
pp->cmd_slot[tag].status = 0;
// pp->cmd_slot[tag].tbl_addr = cpu_to_le32(cmd_tbl_dma & 0xffffffff);
// Elphel - JUST TEMPORARILY
// pp->cmd_slot[tag].tbl_addr = cpu_to_le32(cmd_tbl_dma & 0xffffff80);
// pp->cmd_slot[tag].tbl_addr = cpu_to_le32((cmd_tbl_dma & 0xffffffff) +64); // All data correct
pp->cmd_slot[tag].tbl_addr = cpu_to_le32((cmd_tbl_dma & 0xffffffff)); // All data correct
pp->cmd_slot[tag].tbl_addr_hi = cpu_to_le32((cmd_tbl_dma >> 16) >> 16);
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "\tfill command slot %u: DW0 = 0x%08x, DW1 = 0x%08x, DW2 = 0x%08x, DW3 = 0x%08x",
tag, pp->cmd_slot[tag].opts, pp->cmd_slot[tag].status, pp->cmd_slot[tag].tbl_addr, pp->cmd_slot[tag].tbl_addr_hi);
libahci_debug_event(NULL, msg_str, len);
kfree(msg_str);
}
#endif
}
EXPORT_SYMBOL_GPL(ahci_fill_cmd_slot);
......@@ -1512,13 +1557,14 @@ int ahci_kick_engine(struct ata_port *ap)
u32 tmp;
int busy, rc;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "ahci_kick_engine() kick port %u DMA engine", ap->port_no);
libahci_debug_event(ap, msg_str, len);
}
#endif
/* stop engine */
rc = ahci_stop_engine(ap);
if (rc)
......@@ -1543,11 +1589,12 @@ int ahci_kick_engine(struct ata_port *ap)
tmp |= PORT_CMD_CLO;
writel(tmp, port_mmio + PORT_CMD);
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "\twrite port %u register PxCMD, value: 0x%08x", ap->port_no, tmp);
libahci_debug_event(ap, msg_str, len);
}
#endif
rc = 0;
tmp = ata_wait_register(ap, port_mmio + PORT_CMD,
PORT_CMD_CLO, PORT_CMD_CLO, 1, 500);
......@@ -1557,12 +1604,14 @@ int ahci_kick_engine(struct ata_port *ap)
/* restart engine */
out_restart:
hpriv->start_engine(ap);
#ifdef DEBUG_EVENT_ELPHEL
if (msg_str != NULL) {
len = snprintf(msg_str, LIBAHCI_DEBUG_BUFSZ, "\tahci_kick_engine() will return %d, busy was 0x%08x", rc, busy);
libahci_debug_event(ap, msg_str, len);
}
kfree(msg_str);
#endif
return rc;
}
EXPORT_SYMBOL_GPL(ahci_kick_engine);
......@@ -1577,6 +1626,7 @@ static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
u8 *fis = pp->cmd_tbl;
u32 tmp;
#ifdef DEBUG_EVENT_ELPHEL
int len;
char *msg_str = kzalloc(LIBAHCI_DEBUG_BUFSZ, GFP_KERNEL);
if (msg_str != NULL) {
......@@ -1584,7 +1634,7 @@ static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,