⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sata_fsl.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
			       u32 val){	struct sata_fsl_host_priv *host_priv = ap->host->private_data;	void __iomem *ssr_base = host_priv->ssr_base;	unsigned int sc_reg;	switch (sc_reg_in) {	case SCR_STATUS:	case SCR_ERROR:	case SCR_CONTROL:	case SCR_ACTIVE:		sc_reg = sc_reg_in;		break;	default:		return -EINVAL;	}	VPRINTK("xx_scr_write, reg_in = %d\n", sc_reg);	iowrite32(val, ssr_base + (sc_reg * 4));	return 0;}static int sata_fsl_scr_read(struct ata_port *ap, unsigned int sc_reg_in,			u32 *val){	struct sata_fsl_host_priv *host_priv = ap->host->private_data;	void __iomem *ssr_base = host_priv->ssr_base;	unsigned int sc_reg;	switch (sc_reg_in) {	case SCR_STATUS:	case SCR_ERROR:	case SCR_CONTROL:	case SCR_ACTIVE:		sc_reg = sc_reg_in;		break;	default:		return -EINVAL;	}	VPRINTK("xx_scr_read, reg_in = %d\n", sc_reg);	*val = ioread32(ssr_base + (sc_reg * 4));	return 0;}static void sata_fsl_freeze(struct ata_port *ap){	struct sata_fsl_host_priv *host_priv = ap->host->private_data;	void __iomem *hcr_base = host_priv->hcr_base;	u32 temp;	VPRINTK("xx_freeze, CQ=0x%x, CA=0x%x, CE=0x%x, DE=0x%x\n",		ioread32(CQ + hcr_base),		ioread32(CA + hcr_base),		ioread32(CE + hcr_base), ioread32(DE + hcr_base));	VPRINTK("CmdStat = 0x%x\n", ioread32(csr_base + COMMANDSTAT));	/* disable interrupts on the controller/port */	temp = ioread32(hcr_base + HCONTROL);	iowrite32((temp & ~0x3F), hcr_base + HCONTROL);	VPRINTK("in xx_freeze : HControl = 0x%x, HStatus = 0x%x\n",		ioread32(hcr_base + HCONTROL), ioread32(hcr_base + HSTATUS));}static void sata_fsl_thaw(struct ata_port *ap){	struct sata_fsl_host_priv *host_priv = ap->host->private_data;	void __iomem *hcr_base = host_priv->hcr_base;	u32 temp;	/* ack. any pending IRQs for this controller/port */	temp = ioread32(hcr_base + HSTATUS);	VPRINTK("xx_thaw, pending IRQs = 0x%x\n", (temp & 0x3F));	if (temp & 0x3F)		iowrite32((temp & 0x3F), hcr_base + HSTATUS);	/* enable interrupts on the controller/port */	temp = ioread32(hcr_base + HCONTROL);	iowrite32((temp | DEFAULT_PORT_IRQ_ENABLE_MASK), hcr_base + HCONTROL);	VPRINTK("xx_thaw : HControl = 0x%x, HStatus = 0x%x\n",		ioread32(hcr_base + HCONTROL), ioread32(hcr_base + HSTATUS));}/* * NOTE : 1st D2H FIS from device does not update sfis in command descriptor. */static inline void sata_fsl_cache_taskfile_from_d2h_fis(struct ata_queued_cmd							*qc,							struct ata_port *ap){	struct sata_fsl_port_priv *pp = ap->private_data;	struct sata_fsl_host_priv *host_priv = ap->host->private_data;	void __iomem *hcr_base = host_priv->hcr_base;	unsigned int tag = sata_fsl_tag(qc->tag, hcr_base);	struct command_desc *cd;	cd = pp->cmdentry + tag;	ata_tf_from_fis(cd->sfis, &pp->tf);}static u8 sata_fsl_check_status(struct ata_port *ap){	struct sata_fsl_port_priv *pp = ap->private_data;	return pp->tf.command;}static void sata_fsl_tf_read(struct ata_port *ap, struct ata_taskfile *tf){	struct sata_fsl_port_priv *pp = ap->private_data;	*tf = pp->tf;}static int sata_fsl_port_start(struct ata_port *ap){	struct device *dev = ap->host->dev;	struct sata_fsl_port_priv *pp;	int retval;	void *mem;	dma_addr_t mem_dma;	struct sata_fsl_host_priv *host_priv = ap->host->private_data;	void __iomem *hcr_base = host_priv->hcr_base;	u32 temp;	pp = kzalloc(sizeof(*pp), GFP_KERNEL);	if (!pp)		return -ENOMEM;	/*	 * allocate per command dma alignment pad buffer, which is used	 * internally by libATA to ensure that all transfers ending on	 * unaligned boundaries are padded, to align on Dword boundaries	 */	retval = ata_pad_alloc(ap, dev);	if (retval) {		kfree(pp);		return retval;	}	mem = dma_alloc_coherent(dev, SATA_FSL_PORT_PRIV_DMA_SZ, &mem_dma,				 GFP_KERNEL);	if (!mem) {		ata_pad_free(ap, dev);		kfree(pp);		return -ENOMEM;	}	memset(mem, 0, SATA_FSL_PORT_PRIV_DMA_SZ);	pp->cmdslot = mem;	pp->cmdslot_paddr = mem_dma;	mem += SATA_FSL_CMD_SLOT_SIZE;	mem_dma += SATA_FSL_CMD_SLOT_SIZE;	pp->cmdentry = mem;	pp->cmdentry_paddr = mem_dma;	ap->private_data = pp;	VPRINTK("CHBA = 0x%x, cmdentry_phys = 0x%x\n",		pp->cmdslot_paddr, pp->cmdentry_paddr);	/* Now, update the CHBA register in host controller cmd register set */	iowrite32(pp->cmdslot_paddr & 0xffffffff, hcr_base + CHBA);	/*	 * Now, we can bring the controller on-line & also initiate	 * the COMINIT sequence, we simply return here and the boot-probing	 * & device discovery process is re-initiated by libATA using a	 * Softreset EH (dummy) session. Hence, boot probing and device	 * discovey will be part of sata_fsl_softreset() callback.	 */	temp = ioread32(hcr_base + HCONTROL);	iowrite32((temp | HCONTROL_ONLINE_PHY_RST), hcr_base + HCONTROL);	VPRINTK("HStatus = 0x%x\n", ioread32(hcr_base + HSTATUS));	VPRINTK("HControl = 0x%x\n", ioread32(hcr_base + HCONTROL));	VPRINTK("CHBA  = 0x%x\n", ioread32(hcr_base + CHBA));#ifdef CONFIG_MPC8315_DS	/*	 * Workaround for 8315DS board 3gbps link-up issue,	 * currently limit SATA port to GEN1 speed	 */	sata_fsl_scr_read(ap, SCR_CONTROL, &temp);	temp &= ~(0xF << 4);	temp |= (0x1 << 4);	sata_fsl_scr_write(ap, SCR_CONTROL, temp);	sata_fsl_scr_read(ap, SCR_CONTROL, &temp);	dev_printk(KERN_WARNING, dev, "scr_control, speed limited to %x\n",			temp);#endif	return 0;}static void sata_fsl_port_stop(struct ata_port *ap){	struct device *dev = ap->host->dev;	struct sata_fsl_port_priv *pp = ap->private_data;	struct sata_fsl_host_priv *host_priv = ap->host->private_data;	void __iomem *hcr_base = host_priv->hcr_base;	u32 temp;	/*	 * Force host controller to go off-line, aborting current operations	 */	temp = ioread32(hcr_base + HCONTROL);	temp &= ~HCONTROL_ONLINE_PHY_RST;	temp |= HCONTROL_FORCE_OFFLINE;	iowrite32(temp, hcr_base + HCONTROL);	/* Poll for controller to go offline - should happen immediately */	ata_wait_register(hcr_base + HSTATUS, ONLINE, ONLINE, 1, 1);	ap->private_data = NULL;	dma_free_coherent(dev, SATA_FSL_PORT_PRIV_DMA_SZ,			  pp->cmdslot, pp->cmdslot_paddr);	ata_pad_free(ap, dev);	kfree(pp);}static unsigned int sata_fsl_dev_classify(struct ata_port *ap){	struct sata_fsl_host_priv *host_priv = ap->host->private_data;	void __iomem *hcr_base = host_priv->hcr_base;	struct ata_taskfile tf;	u32 temp;	temp = ioread32(hcr_base + SIGNATURE);	VPRINTK("raw sig = 0x%x\n", temp);	VPRINTK("HStatus = 0x%x\n", ioread32(hcr_base + HSTATUS));	VPRINTK("HControl = 0x%x\n", ioread32(hcr_base + HCONTROL));	tf.lbah = (temp >> 24) & 0xff;	tf.lbam = (temp >> 16) & 0xff;	tf.lbal = (temp >> 8) & 0xff;	tf.nsect = temp & 0xff;	return ata_dev_classify(&tf);}static int sata_fsl_softreset(struct ata_link *link, unsigned int *class,			      unsigned long deadline){	struct ata_port *ap = link->ap;	struct sata_fsl_port_priv *pp = ap->private_data;	struct sata_fsl_host_priv *host_priv = ap->host->private_data;	void __iomem *hcr_base = host_priv->hcr_base;	u32 temp;	struct ata_taskfile tf;	u8 *cfis;	u32 Serror;	int i = 0;	unsigned long start_jiffies;	DPRINTK("in xx_softreset\n");try_offline_again:	/*	 * Force host controller to go off-line, aborting current operations	 */	temp = ioread32(hcr_base + HCONTROL);	temp &= ~HCONTROL_ONLINE_PHY_RST;	iowrite32(temp, hcr_base + HCONTROL);	/* Poll for controller to go offline */	temp = ata_wait_register(hcr_base + HSTATUS, ONLINE, ONLINE, 1, 500);	if (temp & ONLINE) {		ata_port_printk(ap, KERN_ERR,				"Softreset failed, not off-lined %d\n", i);		/*		 * Try to offline controller atleast twice		 */		i++;		if (i == 2)			goto err;		else			goto try_offline_again;	}	DPRINTK("softreset, controller off-lined\n");	VPRINTK("HStatus = 0x%x\n", ioread32(hcr_base + HSTATUS));	VPRINTK("HControl = 0x%x\n", ioread32(hcr_base + HCONTROL));	/*	 * PHY reset should remain asserted for atleast 1ms	 */	msleep(1);	/*	 * Now, bring the host controller online again, this can take time	 * as PHY reset and communication establishment, 1st D2H FIS and	 * device signature update is done, on safe side assume 500ms	 * NOTE : Host online status may be indicated immediately!!	 */	temp = ioread32(hcr_base + HCONTROL);	temp |= (HCONTROL_ONLINE_PHY_RST | HCONTROL_SNOOP_ENABLE);	iowrite32(temp, hcr_base + HCONTROL);	temp = ata_wait_register(hcr_base + HSTATUS, ONLINE, 0, 1, 500);	if (!(temp & ONLINE)) {		ata_port_printk(ap, KERN_ERR,				"Softreset failed, not on-lined\n");		goto err;	}	DPRINTK("softreset, controller off-lined & on-lined\n");	VPRINTK("HStatus = 0x%x\n", ioread32(hcr_base + HSTATUS));	VPRINTK("HControl = 0x%x\n", ioread32(hcr_base + HCONTROL));	/*	 * First, wait for the PHYRDY change to occur before waiting for	 * the signature, and also verify if SStatus indicates device	 * presence	 */	temp = ata_wait_register(hcr_base + HSTATUS, 0xFF, 0, 1, 500);	if ((!(temp & 0x10)) || ata_link_offline(link)) {		ata_port_printk(ap, KERN_WARNING,				"No Device OR PHYRDY change,Hstatus = 0x%x\n",				ioread32(hcr_base + HSTATUS));		goto err;	}	/*	 * Wait for the first D2H from device,i.e,signature update notification	 */	start_jiffies = jiffies;	temp = ata_wait_register(hcr_base + HSTATUS, 0xFF, 0x10,			500, jiffies_to_msecs(deadline - start_jiffies));	if ((temp & 0xFF) != 0x18) {		ata_port_printk(ap, KERN_WARNING, "No Signature Update\n");		goto err;	} else {		ata_port_printk(ap, KERN_INFO,				"Signature Update detected @ %d msecs\n",				jiffies_to_msecs(jiffies - start_jiffies));	}	/*	 * Send a device reset (SRST) explicitly on command slot #0	 * Check : will the command queue (reg) be cleared during offlining ??	 * Also we will be online only if Phy commn. has been established	 * and device presence has been detected, therefore if we have	 * reached here, we can send a command to the target device	 */	DPRINTK("Sending SRST/device reset\n");	ata_tf_init(link->device, &tf);	cfis = (u8 *) &pp->cmdentry->cfis;	/* device reset/SRST is a control register update FIS, uses tag0 */	sata_fsl_setup_cmd_hdr_entry(pp, 0,				     SRST_CMD | CMD_DESC_SNOOP_ENABLE, 0, 0, 5);	tf.ctl |= ATA_SRST;	/* setup SRST bit in taskfile control reg */	ata_tf_to_fis(&tf, 0, 0, cfis);	DPRINTK("Dumping cfis : 0x%x, 0x%x, 0x%x, 0x%x\n",		cfis[0], cfis[1], cfis[2], cfis[3]);	/*	 * Queue SRST command to the controller/device, ensure that no	 * other commands are active on the controller/device	 */	DPRINTK("@Softreset, CQ = 0x%x, CA = 0x%x, CC = 0x%x\n",		ioread32(CQ + hcr_base),		ioread32(CA + hcr_base), ioread32(CC + hcr_base));	iowrite32(0xFFFF, CC + hcr_base);	iowrite32(1, CQ + hcr_base);	temp = ata_wait_register(CQ + hcr_base, 0x1, 0x1, 1, 5000);	if (temp & 0x1) {		ata_port_printk(ap, KERN_WARNING, "ATA_SRST issue failed\n");		DPRINTK("Softreset@5000,CQ=0x%x,CA=0x%x,CC=0x%x\n",			ioread32(CQ + hcr_base),			ioread32(CA + hcr_base), ioread32(CC + hcr_base));		sata_fsl_scr_read(ap, SCR_ERROR, &Serror);		DPRINTK("HStatus = 0x%x\n", ioread32(hcr_base + HSTATUS));		DPRINTK("HControl = 0x%x\n", ioread32(hcr_base + HCONTROL));		DPRINTK("Serror = 0x%x\n", Serror);		goto err;	}	msleep(1);	/*	 * SATA device enters reset state after receving a Control register	 * FIS with SRST bit asserted and it awaits another H2D Control reg.	 * FIS with SRST bit cleared, then the device does internal diags &	 * initialization, followed by indicating it's initialization status	 * using ATA signature D2H register FIS to the host controller.	 */	sata_fsl_setup_cmd_hdr_entry(pp, 0, CMD_DESC_SNOOP_ENABLE, 0, 0, 5);	tf.ctl &= ~ATA_SRST;	/* 2nd H2D Ctl. register FIS */	ata_tf_to_fis(&tf, 0, 0, cfis);	iowrite32(1, CQ + hcr_base);	msleep(150);		/* ?? */	/*	 * The above command would have signalled an interrupt on command	 * complete, which needs special handling, by clearing the Nth	 * command bit of the CCreg	 */	iowrite32(0x01, CC + hcr_base);	/* We know it will be cmd#0 always */	DPRINTK("SATA FSL : Now checking device signature\n");	*class = ATA_DEV_NONE;	/* Verify if SStatus indicates device presence */	if (ata_link_online(link)) {		/*		 * if we are here, device presence has been detected,		 * 1st D2H FIS would have been received, but sfis in		 * command desc. is not updated, but signature register		 * would have been updated		 */		*class = sata_fsl_dev_classify(ap);		DPRINTK("class = %d\n", *class);		VPRINTK("ccreg = 0x%x\n", ioread32(hcr_base + CC));		VPRINTK("cereg = 0x%x\n", ioread32(hcr_base + CE));	}	return 0;err:	return -EIO;}static void sata_fsl_error_handler(struct ata_port *ap){	DPRINTK("in xx_error_handler\n");	/* perform recovery */	ata_do_eh(ap, ata_std_prereset, sata_fsl_softreset, sata_std_hardreset,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -