12908d778SJames Bottomley /* 22908d778SJames Bottomley * Aic94xx SAS/SATA driver sequencer interface. 32908d778SJames Bottomley * 42908d778SJames Bottomley * Copyright (C) 2005 Adaptec, Inc. All rights reserved. 52908d778SJames Bottomley * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com> 62908d778SJames Bottomley * 72908d778SJames Bottomley * Parts of this code adapted from David Chaw's adp94xx_seq.c. 82908d778SJames Bottomley * 92908d778SJames Bottomley * This file is licensed under GPLv2. 102908d778SJames Bottomley * 112908d778SJames Bottomley * This file is part of the aic94xx driver. 122908d778SJames Bottomley * 132908d778SJames Bottomley * The aic94xx driver is free software; you can redistribute it and/or 142908d778SJames Bottomley * modify it under the terms of the GNU General Public License as 152908d778SJames Bottomley * published by the Free Software Foundation; version 2 of the 162908d778SJames Bottomley * License. 172908d778SJames Bottomley * 182908d778SJames Bottomley * The aic94xx driver is distributed in the hope that it will be useful, 192908d778SJames Bottomley * but WITHOUT ANY WARRANTY; without even the implied warranty of 202908d778SJames Bottomley * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 212908d778SJames Bottomley * General Public License for more details. 222908d778SJames Bottomley * 232908d778SJames Bottomley * You should have received a copy of the GNU General Public License 242908d778SJames Bottomley * along with the aic94xx driver; if not, write to the Free Software 252908d778SJames Bottomley * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 262908d778SJames Bottomley * 272908d778SJames Bottomley */ 282908d778SJames Bottomley 292908d778SJames Bottomley #include <linux/delay.h> 302908d778SJames Bottomley #include <linux/pci.h> 31bc229b36SJames Bottomley #include <linux/module.h> 322908d778SJames Bottomley #include <linux/firmware.h> 332908d778SJames Bottomley #include "aic94xx_reg.h" 342908d778SJames Bottomley #include "aic94xx_hwi.h" 352908d778SJames Bottomley 362908d778SJames Bottomley #include "aic94xx_seq.h" 372908d778SJames Bottomley #include "aic94xx_dump.h" 382908d778SJames Bottomley 392908d778SJames Bottomley /* It takes no more than 0.05 us for an instruction 402908d778SJames Bottomley * to complete. So waiting for 1 us should be more than 412908d778SJames Bottomley * plenty. 422908d778SJames Bottomley */ 432908d778SJames Bottomley #define PAUSE_DELAY 1 442908d778SJames Bottomley #define PAUSE_TRIES 1000 452908d778SJames Bottomley 462908d778SJames Bottomley static const struct firmware *sequencer_fw; 472908d778SJames Bottomley static u16 cseq_vecs[CSEQ_NUM_VECS], lseq_vecs[LSEQ_NUM_VECS], mode2_task, 482908d778SJames Bottomley cseq_idle_loop, lseq_idle_loop; 492908d778SJames Bottomley static u8 *cseq_code, *lseq_code; 502908d778SJames Bottomley static u32 cseq_code_size, lseq_code_size; 512908d778SJames Bottomley 522908d778SJames Bottomley static u16 first_scb_site_no = 0xFFFF; 532908d778SJames Bottomley static u16 last_scb_site_no; 542908d778SJames Bottomley 552908d778SJames Bottomley /* ---------- Pause/Unpause CSEQ/LSEQ ---------- */ 562908d778SJames Bottomley 572908d778SJames Bottomley /** 582908d778SJames Bottomley * asd_pause_cseq - pause the central sequencer 592908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 602908d778SJames Bottomley * 612908d778SJames Bottomley * Return 0 on success, negative on failure. 622908d778SJames Bottomley */ 632908d778SJames Bottomley int asd_pause_cseq(struct asd_ha_struct *asd_ha) 642908d778SJames Bottomley { 652908d778SJames Bottomley int count = PAUSE_TRIES; 662908d778SJames Bottomley u32 arp2ctl; 672908d778SJames Bottomley 682908d778SJames Bottomley arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL); 692908d778SJames Bottomley if (arp2ctl & PAUSED) 702908d778SJames Bottomley return 0; 712908d778SJames Bottomley 722908d778SJames Bottomley asd_write_reg_dword(asd_ha, CARP2CTL, arp2ctl | EPAUSE); 732908d778SJames Bottomley do { 742908d778SJames Bottomley arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL); 752908d778SJames Bottomley if (arp2ctl & PAUSED) 762908d778SJames Bottomley return 0; 772908d778SJames Bottomley udelay(PAUSE_DELAY); 782908d778SJames Bottomley } while (--count > 0); 792908d778SJames Bottomley 802908d778SJames Bottomley ASD_DPRINTK("couldn't pause CSEQ\n"); 812908d778SJames Bottomley return -1; 822908d778SJames Bottomley } 832908d778SJames Bottomley 842908d778SJames Bottomley /** 852908d778SJames Bottomley * asd_unpause_cseq - unpause the central sequencer. 862908d778SJames Bottomley * @asd_ha: pointer to host adapter structure. 872908d778SJames Bottomley * 882908d778SJames Bottomley * Return 0 on success, negative on error. 892908d778SJames Bottomley */ 902908d778SJames Bottomley int asd_unpause_cseq(struct asd_ha_struct *asd_ha) 912908d778SJames Bottomley { 922908d778SJames Bottomley u32 arp2ctl; 932908d778SJames Bottomley int count = PAUSE_TRIES; 942908d778SJames Bottomley 952908d778SJames Bottomley arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL); 962908d778SJames Bottomley if (!(arp2ctl & PAUSED)) 972908d778SJames Bottomley return 0; 982908d778SJames Bottomley 992908d778SJames Bottomley asd_write_reg_dword(asd_ha, CARP2CTL, arp2ctl & ~EPAUSE); 1002908d778SJames Bottomley do { 1012908d778SJames Bottomley arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL); 1022908d778SJames Bottomley if (!(arp2ctl & PAUSED)) 1032908d778SJames Bottomley return 0; 1042908d778SJames Bottomley udelay(PAUSE_DELAY); 1052908d778SJames Bottomley } while (--count > 0); 1062908d778SJames Bottomley 1072908d778SJames Bottomley ASD_DPRINTK("couldn't unpause the CSEQ\n"); 1082908d778SJames Bottomley return -1; 1092908d778SJames Bottomley } 1102908d778SJames Bottomley 1112908d778SJames Bottomley /** 1122908d778SJames Bottomley * asd_seq_pause_lseq - pause a link sequencer 1132908d778SJames Bottomley * @asd_ha: pointer to a host adapter structure 1142908d778SJames Bottomley * @lseq: link sequencer of interest 1152908d778SJames Bottomley * 1162908d778SJames Bottomley * Return 0 on success, negative on error. 1172908d778SJames Bottomley */ 1182908d778SJames Bottomley static inline int asd_seq_pause_lseq(struct asd_ha_struct *asd_ha, int lseq) 1192908d778SJames Bottomley { 1202908d778SJames Bottomley u32 arp2ctl; 1212908d778SJames Bottomley int count = PAUSE_TRIES; 1222908d778SJames Bottomley 1232908d778SJames Bottomley arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq)); 1242908d778SJames Bottomley if (arp2ctl & PAUSED) 1252908d778SJames Bottomley return 0; 1262908d778SJames Bottomley 1272908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmARP2CTL(lseq), arp2ctl | EPAUSE); 1282908d778SJames Bottomley do { 1292908d778SJames Bottomley arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq)); 1302908d778SJames Bottomley if (arp2ctl & PAUSED) 1312908d778SJames Bottomley return 0; 1322908d778SJames Bottomley udelay(PAUSE_DELAY); 1332908d778SJames Bottomley } while (--count > 0); 1342908d778SJames Bottomley 1352908d778SJames Bottomley ASD_DPRINTK("couldn't pause LSEQ %d\n", lseq); 1362908d778SJames Bottomley return -1; 1372908d778SJames Bottomley } 1382908d778SJames Bottomley 1392908d778SJames Bottomley /** 1402908d778SJames Bottomley * asd_pause_lseq - pause the link sequencer(s) 1412908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 1422908d778SJames Bottomley * @lseq_mask: mask of link sequencers of interest 1432908d778SJames Bottomley * 1442908d778SJames Bottomley * Return 0 on success, negative on failure. 1452908d778SJames Bottomley */ 1462908d778SJames Bottomley int asd_pause_lseq(struct asd_ha_struct *asd_ha, u8 lseq_mask) 1472908d778SJames Bottomley { 1482908d778SJames Bottomley int lseq; 1492908d778SJames Bottomley int err = 0; 1502908d778SJames Bottomley 1512908d778SJames Bottomley for_each_sequencer(lseq_mask, lseq_mask, lseq) { 1522908d778SJames Bottomley err = asd_seq_pause_lseq(asd_ha, lseq); 1532908d778SJames Bottomley if (err) 1542908d778SJames Bottomley return err; 1552908d778SJames Bottomley } 1562908d778SJames Bottomley 1572908d778SJames Bottomley return err; 1582908d778SJames Bottomley } 1592908d778SJames Bottomley 1602908d778SJames Bottomley /** 1612908d778SJames Bottomley * asd_seq_unpause_lseq - unpause a link sequencer 1622908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 1632908d778SJames Bottomley * @lseq: link sequencer of interest 1642908d778SJames Bottomley * 1652908d778SJames Bottomley * Return 0 on success, negative on error. 1662908d778SJames Bottomley */ 1672908d778SJames Bottomley static inline int asd_seq_unpause_lseq(struct asd_ha_struct *asd_ha, int lseq) 1682908d778SJames Bottomley { 1692908d778SJames Bottomley u32 arp2ctl; 1702908d778SJames Bottomley int count = PAUSE_TRIES; 1712908d778SJames Bottomley 1722908d778SJames Bottomley arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq)); 1732908d778SJames Bottomley if (!(arp2ctl & PAUSED)) 1742908d778SJames Bottomley return 0; 1752908d778SJames Bottomley 1762908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmARP2CTL(lseq), arp2ctl & ~EPAUSE); 1772908d778SJames Bottomley do { 1782908d778SJames Bottomley arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq)); 1792908d778SJames Bottomley if (!(arp2ctl & PAUSED)) 1802908d778SJames Bottomley return 0; 1812908d778SJames Bottomley udelay(PAUSE_DELAY); 1822908d778SJames Bottomley } while (--count > 0); 1832908d778SJames Bottomley 1842908d778SJames Bottomley ASD_DPRINTK("couldn't unpause LSEQ %d\n", lseq); 1852908d778SJames Bottomley return 0; 1862908d778SJames Bottomley } 1872908d778SJames Bottomley 1882908d778SJames Bottomley 1892908d778SJames Bottomley /** 1902908d778SJames Bottomley * asd_unpause_lseq - unpause the link sequencer(s) 1912908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 1922908d778SJames Bottomley * @lseq_mask: mask of link sequencers of interest 1932908d778SJames Bottomley * 1942908d778SJames Bottomley * Return 0 on success, negative on failure. 1952908d778SJames Bottomley */ 1962908d778SJames Bottomley int asd_unpause_lseq(struct asd_ha_struct *asd_ha, u8 lseq_mask) 1972908d778SJames Bottomley { 1982908d778SJames Bottomley int lseq; 1992908d778SJames Bottomley int err = 0; 2002908d778SJames Bottomley 2012908d778SJames Bottomley for_each_sequencer(lseq_mask, lseq_mask, lseq) { 2022908d778SJames Bottomley err = asd_seq_unpause_lseq(asd_ha, lseq); 2032908d778SJames Bottomley if (err) 2042908d778SJames Bottomley return err; 2052908d778SJames Bottomley } 2062908d778SJames Bottomley 2072908d778SJames Bottomley return err; 2082908d778SJames Bottomley } 2092908d778SJames Bottomley 2102908d778SJames Bottomley /* ---------- Downloading CSEQ/LSEQ microcode ---------- */ 2112908d778SJames Bottomley 2122908d778SJames Bottomley static int asd_verify_cseq(struct asd_ha_struct *asd_ha, const u8 *_prog, 2132908d778SJames Bottomley u32 size) 2142908d778SJames Bottomley { 2152908d778SJames Bottomley u32 addr = CSEQ_RAM_REG_BASE_ADR; 2162908d778SJames Bottomley const u32 *prog = (u32 *) _prog; 2172908d778SJames Bottomley u32 i; 2182908d778SJames Bottomley 2192908d778SJames Bottomley for (i = 0; i < size; i += 4, prog++, addr += 4) { 2202908d778SJames Bottomley u32 val = asd_read_reg_dword(asd_ha, addr); 2212908d778SJames Bottomley 2222908d778SJames Bottomley if (le32_to_cpu(*prog) != val) { 2232908d778SJames Bottomley asd_printk("%s: cseq verify failed at %u " 2242908d778SJames Bottomley "read:0x%x, wanted:0x%x\n", 2252908d778SJames Bottomley pci_name(asd_ha->pcidev), 2262908d778SJames Bottomley i, val, le32_to_cpu(*prog)); 2272908d778SJames Bottomley return -1; 2282908d778SJames Bottomley } 2292908d778SJames Bottomley } 2302908d778SJames Bottomley ASD_DPRINTK("verified %d bytes, passed\n", size); 2312908d778SJames Bottomley return 0; 2322908d778SJames Bottomley } 2332908d778SJames Bottomley 2342908d778SJames Bottomley /** 2352908d778SJames Bottomley * asd_verify_lseq - verify the microcode of a link sequencer 2362908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 2372908d778SJames Bottomley * @_prog: pointer to the microcode 2382908d778SJames Bottomley * @size: size of the microcode in bytes 2392908d778SJames Bottomley * @lseq: link sequencer of interest 2402908d778SJames Bottomley * 2412908d778SJames Bottomley * The link sequencer code is accessed in 4 KB pages, which are selected 2422908d778SJames Bottomley * by setting LmRAMPAGE (bits 8 and 9) of the LmBISTCTL1 register. 2432908d778SJames Bottomley * The 10 KB LSEQm instruction code is mapped, page at a time, at 2442908d778SJames Bottomley * LmSEQRAM address. 2452908d778SJames Bottomley */ 2462908d778SJames Bottomley static int asd_verify_lseq(struct asd_ha_struct *asd_ha, const u8 *_prog, 2472908d778SJames Bottomley u32 size, int lseq) 2482908d778SJames Bottomley { 2492908d778SJames Bottomley #define LSEQ_CODEPAGE_SIZE 4096 2502908d778SJames Bottomley int pages = (size + LSEQ_CODEPAGE_SIZE - 1) / LSEQ_CODEPAGE_SIZE; 2512908d778SJames Bottomley u32 page; 2522908d778SJames Bottomley const u32 *prog = (u32 *) _prog; 2532908d778SJames Bottomley 2542908d778SJames Bottomley for (page = 0; page < pages; page++) { 2552908d778SJames Bottomley u32 i; 2562908d778SJames Bottomley 2572908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmBISTCTL1(lseq), 2582908d778SJames Bottomley page << LmRAMPAGE_LSHIFT); 2592908d778SJames Bottomley for (i = 0; size > 0 && i < LSEQ_CODEPAGE_SIZE; 2602908d778SJames Bottomley i += 4, prog++, size-=4) { 2612908d778SJames Bottomley 2622908d778SJames Bottomley u32 val = asd_read_reg_dword(asd_ha, LmSEQRAM(lseq)+i); 2632908d778SJames Bottomley 2642908d778SJames Bottomley if (le32_to_cpu(*prog) != val) { 2652908d778SJames Bottomley asd_printk("%s: LSEQ%d verify failed " 2662908d778SJames Bottomley "page:%d, offs:%d\n", 2672908d778SJames Bottomley pci_name(asd_ha->pcidev), 2682908d778SJames Bottomley lseq, page, i); 2692908d778SJames Bottomley return -1; 2702908d778SJames Bottomley } 2712908d778SJames Bottomley } 2722908d778SJames Bottomley } 2732908d778SJames Bottomley ASD_DPRINTK("LSEQ%d verified %d bytes, passed\n", lseq, 2742908d778SJames Bottomley (int)((u8 *)prog-_prog)); 2752908d778SJames Bottomley return 0; 2762908d778SJames Bottomley } 2772908d778SJames Bottomley 2782908d778SJames Bottomley /** 2792908d778SJames Bottomley * asd_verify_seq -- verify CSEQ/LSEQ microcode 2802908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 2812908d778SJames Bottomley * @prog: pointer to microcode 2822908d778SJames Bottomley * @size: size of the microcode 2832908d778SJames Bottomley * @lseq_mask: if 0, verify CSEQ microcode, else mask of LSEQs of interest 2842908d778SJames Bottomley * 2852908d778SJames Bottomley * Return 0 if microcode is correct, negative on mismatch. 2862908d778SJames Bottomley */ 2872908d778SJames Bottomley static int asd_verify_seq(struct asd_ha_struct *asd_ha, const u8 *prog, 2882908d778SJames Bottomley u32 size, u8 lseq_mask) 2892908d778SJames Bottomley { 2902908d778SJames Bottomley if (lseq_mask == 0) 2912908d778SJames Bottomley return asd_verify_cseq(asd_ha, prog, size); 2922908d778SJames Bottomley else { 2932908d778SJames Bottomley int lseq, err; 2942908d778SJames Bottomley 2952908d778SJames Bottomley for_each_sequencer(lseq_mask, lseq_mask, lseq) { 2962908d778SJames Bottomley err = asd_verify_lseq(asd_ha, prog, size, lseq); 2972908d778SJames Bottomley if (err) 2982908d778SJames Bottomley return err; 2992908d778SJames Bottomley } 3002908d778SJames Bottomley } 3012908d778SJames Bottomley 3022908d778SJames Bottomley return 0; 3032908d778SJames Bottomley } 3042908d778SJames Bottomley #define ASD_DMA_MODE_DOWNLOAD 3052908d778SJames Bottomley #ifdef ASD_DMA_MODE_DOWNLOAD 3062908d778SJames Bottomley /* This is the size of the CSEQ Mapped instruction page */ 3072908d778SJames Bottomley #define MAX_DMA_OVLY_COUNT ((1U << 14)-1) 3082908d778SJames Bottomley static int asd_download_seq(struct asd_ha_struct *asd_ha, 3092908d778SJames Bottomley const u8 * const prog, u32 size, u8 lseq_mask) 3102908d778SJames Bottomley { 3112908d778SJames Bottomley u32 comstaten; 3122908d778SJames Bottomley u32 reg; 3132908d778SJames Bottomley int page; 3142908d778SJames Bottomley const int pages = (size + MAX_DMA_OVLY_COUNT - 1) / MAX_DMA_OVLY_COUNT; 3152908d778SJames Bottomley struct asd_dma_tok *token; 3162908d778SJames Bottomley int err = 0; 3172908d778SJames Bottomley 3182908d778SJames Bottomley if (size % 4) { 3192908d778SJames Bottomley asd_printk("sequencer program not multiple of 4\n"); 3202908d778SJames Bottomley return -1; 3212908d778SJames Bottomley } 3222908d778SJames Bottomley 3232908d778SJames Bottomley asd_pause_cseq(asd_ha); 3242908d778SJames Bottomley asd_pause_lseq(asd_ha, 0xFF); 3252908d778SJames Bottomley 3262908d778SJames Bottomley /* save, disable and clear interrupts */ 3272908d778SJames Bottomley comstaten = asd_read_reg_dword(asd_ha, COMSTATEN); 3282908d778SJames Bottomley asd_write_reg_dword(asd_ha, COMSTATEN, 0); 3292908d778SJames Bottomley asd_write_reg_dword(asd_ha, COMSTAT, COMSTAT_MASK); 3302908d778SJames Bottomley 3312908d778SJames Bottomley asd_write_reg_dword(asd_ha, CHIMINTEN, RST_CHIMINTEN); 3322908d778SJames Bottomley asd_write_reg_dword(asd_ha, CHIMINT, CHIMINT_MASK); 3332908d778SJames Bottomley 3342908d778SJames Bottomley token = asd_alloc_coherent(asd_ha, MAX_DMA_OVLY_COUNT, GFP_KERNEL); 3352908d778SJames Bottomley if (!token) { 3362908d778SJames Bottomley asd_printk("out of memory for dma SEQ download\n"); 3372908d778SJames Bottomley err = -ENOMEM; 3382908d778SJames Bottomley goto out; 3392908d778SJames Bottomley } 3402908d778SJames Bottomley ASD_DPRINTK("dma-ing %d bytes\n", size); 3412908d778SJames Bottomley 3422908d778SJames Bottomley for (page = 0; page < pages; page++) { 3432908d778SJames Bottomley int i; 3442908d778SJames Bottomley u32 left = min(size-page*MAX_DMA_OVLY_COUNT, 3452908d778SJames Bottomley (u32)MAX_DMA_OVLY_COUNT); 3462908d778SJames Bottomley 3472908d778SJames Bottomley memcpy(token->vaddr, prog + page*MAX_DMA_OVLY_COUNT, left); 3482908d778SJames Bottomley asd_write_reg_addr(asd_ha, OVLYDMAADR, token->dma_handle); 3492908d778SJames Bottomley asd_write_reg_dword(asd_ha, OVLYDMACNT, left); 3502908d778SJames Bottomley reg = !page ? RESETOVLYDMA : 0; 3512908d778SJames Bottomley reg |= (STARTOVLYDMA | OVLYHALTERR); 3522908d778SJames Bottomley reg |= (lseq_mask ? (((u32)lseq_mask) << 8) : OVLYCSEQ); 3532908d778SJames Bottomley /* Start DMA. */ 3542908d778SJames Bottomley asd_write_reg_dword(asd_ha, OVLYDMACTL, reg); 3552908d778SJames Bottomley 3562908d778SJames Bottomley for (i = PAUSE_TRIES*100; i > 0; i--) { 3572908d778SJames Bottomley u32 dmadone = asd_read_reg_dword(asd_ha, OVLYDMACTL); 3582908d778SJames Bottomley if (!(dmadone & OVLYDMAACT)) 3592908d778SJames Bottomley break; 3602908d778SJames Bottomley udelay(PAUSE_DELAY); 3612908d778SJames Bottomley } 3622908d778SJames Bottomley } 3632908d778SJames Bottomley 3642908d778SJames Bottomley reg = asd_read_reg_dword(asd_ha, COMSTAT); 3652908d778SJames Bottomley if (!(reg & OVLYDMADONE) || (reg & OVLYERR) 3662908d778SJames Bottomley || (asd_read_reg_dword(asd_ha, CHIMINT) & DEVEXCEPT_MASK)){ 3672908d778SJames Bottomley asd_printk("%s: error DMA-ing sequencer code\n", 3682908d778SJames Bottomley pci_name(asd_ha->pcidev)); 3692908d778SJames Bottomley err = -ENODEV; 3702908d778SJames Bottomley } 3712908d778SJames Bottomley 3722908d778SJames Bottomley asd_free_coherent(asd_ha, token); 3732908d778SJames Bottomley out: 3742908d778SJames Bottomley asd_write_reg_dword(asd_ha, COMSTATEN, comstaten); 3752908d778SJames Bottomley 3762908d778SJames Bottomley return err ? : asd_verify_seq(asd_ha, prog, size, lseq_mask); 3772908d778SJames Bottomley } 3782908d778SJames Bottomley #else /* ASD_DMA_MODE_DOWNLOAD */ 3792908d778SJames Bottomley static int asd_download_seq(struct asd_ha_struct *asd_ha, const u8 *_prog, 3802908d778SJames Bottomley u32 size, u8 lseq_mask) 3812908d778SJames Bottomley { 3822908d778SJames Bottomley int i; 3832908d778SJames Bottomley u32 reg = 0; 3842908d778SJames Bottomley const u32 *prog = (u32 *) _prog; 3852908d778SJames Bottomley 3862908d778SJames Bottomley if (size % 4) { 3872908d778SJames Bottomley asd_printk("sequencer program not multiple of 4\n"); 3882908d778SJames Bottomley return -1; 3892908d778SJames Bottomley } 3902908d778SJames Bottomley 3912908d778SJames Bottomley asd_pause_cseq(asd_ha); 3922908d778SJames Bottomley asd_pause_lseq(asd_ha, 0xFF); 3932908d778SJames Bottomley 3942908d778SJames Bottomley reg |= (lseq_mask ? (((u32)lseq_mask) << 8) : OVLYCSEQ); 3952908d778SJames Bottomley reg |= PIOCMODE; 3962908d778SJames Bottomley 3972908d778SJames Bottomley asd_write_reg_dword(asd_ha, OVLYDMACNT, size); 3982908d778SJames Bottomley asd_write_reg_dword(asd_ha, OVLYDMACTL, reg); 3992908d778SJames Bottomley 4002908d778SJames Bottomley ASD_DPRINTK("downloading %s sequencer%s in PIO mode...\n", 4012908d778SJames Bottomley lseq_mask ? "LSEQ" : "CSEQ", lseq_mask ? "s" : ""); 4022908d778SJames Bottomley 4032908d778SJames Bottomley for (i = 0; i < size; i += 4, prog++) 4042908d778SJames Bottomley asd_write_reg_dword(asd_ha, SPIODATA, *prog); 4052908d778SJames Bottomley 4062908d778SJames Bottomley reg = (reg & ~PIOCMODE) | OVLYHALTERR; 4072908d778SJames Bottomley asd_write_reg_dword(asd_ha, OVLYDMACTL, reg); 4082908d778SJames Bottomley 4092908d778SJames Bottomley return asd_verify_seq(asd_ha, _prog, size, lseq_mask); 4102908d778SJames Bottomley } 4112908d778SJames Bottomley #endif /* ASD_DMA_MODE_DOWNLOAD */ 4122908d778SJames Bottomley 4132908d778SJames Bottomley /** 4142908d778SJames Bottomley * asd_seq_download_seqs - download the sequencer microcode 4152908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 4162908d778SJames Bottomley * 4172908d778SJames Bottomley * Download the central and link sequencer microcode. 4182908d778SJames Bottomley */ 4192908d778SJames Bottomley static int asd_seq_download_seqs(struct asd_ha_struct *asd_ha) 4202908d778SJames Bottomley { 4212908d778SJames Bottomley int err; 4222908d778SJames Bottomley 4232908d778SJames Bottomley if (!asd_ha->hw_prof.enabled_phys) { 4242908d778SJames Bottomley asd_printk("%s: no enabled phys!\n", pci_name(asd_ha->pcidev)); 4252908d778SJames Bottomley return -ENODEV; 4262908d778SJames Bottomley } 4272908d778SJames Bottomley 4282908d778SJames Bottomley /* Download the CSEQ */ 4292908d778SJames Bottomley ASD_DPRINTK("downloading CSEQ...\n"); 4302908d778SJames Bottomley err = asd_download_seq(asd_ha, cseq_code, cseq_code_size, 0); 4312908d778SJames Bottomley if (err) { 4322908d778SJames Bottomley asd_printk("CSEQ download failed:%d\n", err); 4332908d778SJames Bottomley return err; 4342908d778SJames Bottomley } 4352908d778SJames Bottomley 4362908d778SJames Bottomley /* Download the Link Sequencers code. All of the Link Sequencers 4372908d778SJames Bottomley * microcode can be downloaded at the same time. 4382908d778SJames Bottomley */ 4392908d778SJames Bottomley ASD_DPRINTK("downloading LSEQs...\n"); 4402908d778SJames Bottomley err = asd_download_seq(asd_ha, lseq_code, lseq_code_size, 4412908d778SJames Bottomley asd_ha->hw_prof.enabled_phys); 4422908d778SJames Bottomley if (err) { 4432908d778SJames Bottomley /* Try it one at a time */ 4442908d778SJames Bottomley u8 lseq; 4452908d778SJames Bottomley u8 lseq_mask = asd_ha->hw_prof.enabled_phys; 4462908d778SJames Bottomley 4472908d778SJames Bottomley for_each_sequencer(lseq_mask, lseq_mask, lseq) { 4482908d778SJames Bottomley err = asd_download_seq(asd_ha, lseq_code, 4492908d778SJames Bottomley lseq_code_size, 1<<lseq); 4502908d778SJames Bottomley if (err) 4512908d778SJames Bottomley break; 4522908d778SJames Bottomley } 4532908d778SJames Bottomley } 4542908d778SJames Bottomley if (err) 4552908d778SJames Bottomley asd_printk("LSEQs download failed:%d\n", err); 4562908d778SJames Bottomley 4572908d778SJames Bottomley return err; 4582908d778SJames Bottomley } 4592908d778SJames Bottomley 4602908d778SJames Bottomley /* ---------- Initializing the chip, chip memory, etc. ---------- */ 4612908d778SJames Bottomley 4622908d778SJames Bottomley /** 4632908d778SJames Bottomley * asd_init_cseq_mip - initialize CSEQ mode independent pages 4-7 4642908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 4652908d778SJames Bottomley */ 4662908d778SJames Bottomley static void asd_init_cseq_mip(struct asd_ha_struct *asd_ha) 4672908d778SJames Bottomley { 4682908d778SJames Bottomley /* CSEQ Mode Independent, page 4 setup. */ 4692908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_EXE_HEAD, 0xFFFF); 4702908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_EXE_TAIL, 0xFFFF); 4712908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_DONE_HEAD, 0xFFFF); 4722908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_DONE_TAIL, 0xFFFF); 4732908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_SEND_HEAD, 0xFFFF); 4742908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_SEND_TAIL, 0xFFFF); 4752908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_DMA2CHIM_HEAD, 0xFFFF); 4762908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_DMA2CHIM_TAIL, 0xFFFF); 4772908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_COPY_HEAD, 0xFFFF); 4782908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_COPY_TAIL, 0xFFFF); 4792908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_REG0, 0); 4802908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_REG1, 0); 4812908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_REG2, 0); 4822908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_LINK_CTL_Q_MAP, 0); 4832908d778SJames Bottomley { 4842908d778SJames Bottomley u8 con = asd_read_reg_byte(asd_ha, CCONEXIST); 4852908d778SJames Bottomley u8 val = hweight8(con); 4862908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_MAX_CSEQ_MODE, (val<<4)|val); 4872908d778SJames Bottomley } 4882908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_FREE_LIST_HACK_COUNT, 0); 4892908d778SJames Bottomley 4902908d778SJames Bottomley /* CSEQ Mode independent, page 5 setup. */ 4912908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_EST_NEXUS_REQ_QUEUE, 0); 4922908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_EST_NEXUS_REQ_QUEUE+4, 0); 4932908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_EST_NEXUS_REQ_COUNT, 0); 4942908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_EST_NEXUS_REQ_COUNT+4, 0); 4952908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_EST_NEXUS_HEAD, 0xFFFF); 4962908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_EST_NEXUS_TAIL, 0xFFFF); 4972908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_NEED_EST_NEXUS_SCB, 0); 4982908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_EST_NEXUS_REQ_HEAD, 0); 4992908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_EST_NEXUS_REQ_TAIL, 0); 5002908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_EST_NEXUS_SCB_OFFSET, 0); 5012908d778SJames Bottomley 5022908d778SJames Bottomley /* CSEQ Mode independent, page 6 setup. */ 5032908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_INT_ROUT_RET_ADDR0, 0); 5042908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_INT_ROUT_RET_ADDR1, 0); 5052908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_INT_ROUT_SCBPTR, 0); 5062908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_INT_ROUT_MODE, 0); 5072908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_ISR_SCRATCH_FLAGS, 0); 5082908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_ISR_SAVE_SINDEX, 0); 5092908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_ISR_SAVE_DINDEX, 0); 5102908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_MONIRTT_HEAD, 0xFFFF); 5112908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_MONIRTT_TAIL, 0xFFFF); 5122908d778SJames Bottomley /* Calculate the free scb mask. */ 5132908d778SJames Bottomley { 5142908d778SJames Bottomley u16 cmdctx = asd_get_cmdctx_size(asd_ha); 5152908d778SJames Bottomley cmdctx = (~((cmdctx/128)-1)) >> 8; 5162908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_FREE_SCB_MASK, (u8)cmdctx); 5172908d778SJames Bottomley } 5182908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_BUILTIN_FREE_SCB_HEAD, 5192908d778SJames Bottomley first_scb_site_no); 5202908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_BUILTIN_FREE_SCB_TAIL, 5212908d778SJames Bottomley last_scb_site_no); 5222908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_EXTENDED_FREE_SCB_HEAD, 0xFFFF); 5232908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_EXTENDED_FREE_SCB_TAIL, 0xFFFF); 5242908d778SJames Bottomley 5252908d778SJames Bottomley /* CSEQ Mode independent, page 7 setup. */ 5262908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_EMPTY_REQ_QUEUE, 0); 5272908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_EMPTY_REQ_QUEUE+4, 0); 5282908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_EMPTY_REQ_COUNT, 0); 5292908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_EMPTY_REQ_COUNT+4, 0); 5302908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_EMPTY_HEAD, 0xFFFF); 5312908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_Q_EMPTY_TAIL, 0xFFFF); 5322908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_NEED_EMPTY_SCB, 0); 5332908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_EMPTY_REQ_HEAD, 0); 5342908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_EMPTY_REQ_TAIL, 0); 5352908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_EMPTY_SCB_OFFSET, 0); 5362908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_PRIMITIVE_DATA, 0); 5372908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_TIMEOUT_CONST, 0); 5382908d778SJames Bottomley } 5392908d778SJames Bottomley 5402908d778SJames Bottomley /** 5412908d778SJames Bottomley * asd_init_cseq_mdp - initialize CSEQ Mode dependent pages 5422908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 5432908d778SJames Bottomley */ 5442908d778SJames Bottomley static void asd_init_cseq_mdp(struct asd_ha_struct *asd_ha) 5452908d778SJames Bottomley { 5462908d778SJames Bottomley int i; 5472908d778SJames Bottomley int moffs; 5482908d778SJames Bottomley 5492908d778SJames Bottomley moffs = CSEQ_PAGE_SIZE * 2; 5502908d778SJames Bottomley 5512908d778SJames Bottomley /* CSEQ Mode dependent, modes 0-7, page 0 setup. */ 5522908d778SJames Bottomley for (i = 0; i < 8; i++) { 5532908d778SJames Bottomley asd_write_reg_word(asd_ha, i*moffs+CSEQ_LRM_SAVE_SINDEX, 0); 5542908d778SJames Bottomley asd_write_reg_word(asd_ha, i*moffs+CSEQ_LRM_SAVE_SCBPTR, 0); 5552908d778SJames Bottomley asd_write_reg_word(asd_ha, i*moffs+CSEQ_Q_LINK_HEAD, 0xFFFF); 5562908d778SJames Bottomley asd_write_reg_word(asd_ha, i*moffs+CSEQ_Q_LINK_TAIL, 0xFFFF); 5572908d778SJames Bottomley asd_write_reg_byte(asd_ha, i*moffs+CSEQ_LRM_SAVE_SCRPAGE, 0); 5582908d778SJames Bottomley } 5592908d778SJames Bottomley 5602908d778SJames Bottomley /* CSEQ Mode dependent, mode 0-7, page 1 and 2 shall be ignored. */ 5612908d778SJames Bottomley 5622908d778SJames Bottomley /* CSEQ Mode dependent, mode 8, page 0 setup. */ 5632908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_RET_ADDR, 0xFFFF); 5642908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_RET_SCBPTR, 0); 5652908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_SAVE_SCBPTR, 0); 5662908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_EMPTY_TRANS_CTX, 0); 5672908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_RESP_LEN, 0); 5682908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_TMF_SCBPTR, 0); 5692908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_GLOBAL_PREV_SCB, 0); 5702908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_GLOBAL_HEAD, 0); 5712908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_CLEAR_LU_HEAD, 0); 5722908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_TMF_OPCODE, 0); 5732908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_SCRATCH_FLAGS, 0); 5742908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_HSB_SITE, 0); 5752908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_FIRST_INV_SCB_SITE, 5762908d778SJames Bottomley (u16)last_scb_site_no+1); 5772908d778SJames Bottomley asd_write_reg_word(asd_ha, CSEQ_FIRST_INV_DDB_SITE, 5782908d778SJames Bottomley (u16)asd_ha->hw_prof.max_ddbs); 5792908d778SJames Bottomley 5802908d778SJames Bottomley /* CSEQ Mode dependent, mode 8, page 1 setup. */ 5812908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CLEAR, 0); 5822908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CLEAR + 4, 0); 5832908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CHECK, 0); 5842908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CHECK + 4, 0); 5852908d778SJames Bottomley 5862908d778SJames Bottomley /* CSEQ Mode dependent, mode 8, page 2 setup. */ 5872908d778SJames Bottomley /* Tell the sequencer the bus address of the first SCB. */ 5882908d778SJames Bottomley asd_write_reg_addr(asd_ha, CSEQ_HQ_NEW_POINTER, 5892908d778SJames Bottomley asd_ha->seq.next_scb.dma_handle); 5902908d778SJames Bottomley ASD_DPRINTK("First SCB dma_handle: 0x%llx\n", 5912908d778SJames Bottomley (unsigned long long)asd_ha->seq.next_scb.dma_handle); 5922908d778SJames Bottomley 5932908d778SJames Bottomley /* Tell the sequencer the first Done List entry address. */ 5942908d778SJames Bottomley asd_write_reg_addr(asd_ha, CSEQ_HQ_DONE_BASE, 5952908d778SJames Bottomley asd_ha->seq.actual_dl->dma_handle); 5962908d778SJames Bottomley 5972908d778SJames Bottomley /* Initialize the Q_DONE_POINTER with the least significant 5982908d778SJames Bottomley * 4 bytes of the first Done List address. */ 5992908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQ_HQ_DONE_POINTER, 6002908d778SJames Bottomley ASD_BUSADDR_LO(asd_ha->seq.actual_dl->dma_handle)); 6012908d778SJames Bottomley 6022908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQ_HQ_DONE_PASS, ASD_DEF_DL_TOGGLE); 6032908d778SJames Bottomley 6042908d778SJames Bottomley /* CSEQ Mode dependent, mode 8, page 3 shall be ignored. */ 6052908d778SJames Bottomley } 6062908d778SJames Bottomley 6072908d778SJames Bottomley /** 6082908d778SJames Bottomley * asd_init_cseq_scratch -- setup and init CSEQ 6092908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 6102908d778SJames Bottomley * 6112908d778SJames Bottomley * Setup and initialize Central sequencers. Initialiaze the mode 6122908d778SJames Bottomley * independent and dependent scratch page to the default settings. 6132908d778SJames Bottomley */ 6142908d778SJames Bottomley static void asd_init_cseq_scratch(struct asd_ha_struct *asd_ha) 6152908d778SJames Bottomley { 6162908d778SJames Bottomley asd_init_cseq_mip(asd_ha); 6172908d778SJames Bottomley asd_init_cseq_mdp(asd_ha); 6182908d778SJames Bottomley } 6192908d778SJames Bottomley 6202908d778SJames Bottomley /** 6212908d778SJames Bottomley * asd_init_lseq_mip -- initialize LSEQ Mode independent pages 0-3 6222908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 6232908d778SJames Bottomley */ 6242908d778SJames Bottomley static void asd_init_lseq_mip(struct asd_ha_struct *asd_ha, u8 lseq) 6252908d778SJames Bottomley { 6262908d778SJames Bottomley int i; 6272908d778SJames Bottomley 6282908d778SJames Bottomley /* LSEQ Mode independent page 0 setup. */ 6292908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_Q_TGTXFR_HEAD(lseq), 0xFFFF); 6302908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_Q_TGTXFR_TAIL(lseq), 0xFFFF); 6312908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_LINK_NUMBER(lseq), lseq); 6322908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_SCRATCH_FLAGS(lseq), 6332908d778SJames Bottomley ASD_NOTIFY_ENABLE_SPINUP); 6342908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_CONNECTION_STATE(lseq),0x08000000); 6352908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_CONCTL(lseq), 0); 6362908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_CONSTAT(lseq), 0); 6372908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_CONNECTION_MODES(lseq), 0); 6382908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_REG1_ISR(lseq), 0); 6392908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_REG2_ISR(lseq), 0); 6402908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_REG3_ISR(lseq), 0); 6412908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_REG0_ISR(lseq), 0); 6422908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_REG0_ISR(lseq)+4, 0); 6432908d778SJames Bottomley 6442908d778SJames Bottomley /* LSEQ Mode independent page 1 setup. */ 6452908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR0(lseq), 0xFFFF); 6462908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR1(lseq), 0xFFFF); 6472908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR2(lseq), 0xFFFF); 6482908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR3(lseq), 0xFFFF); 6492908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_OPCODE0(lseq), 0); 6502908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_OPCODE1(lseq), 0); 6512908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_OPCODE2(lseq), 0); 6522908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_OPCODE3(lseq), 0); 6532908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_HEAD(lseq), 0); 6542908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_TAIL(lseq), 0); 6552908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_BUF_AVAIL(lseq), 0); 6562908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_TIMEOUT_CONST(lseq), 0); 6572908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_ISR_SAVE_SINDEX(lseq), 0); 6582908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_ISR_SAVE_DINDEX(lseq), 0); 6592908d778SJames Bottomley 6602908d778SJames Bottomley /* LSEQ Mode Independent page 2 setup. */ 6612908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR0(lseq), 0xFFFF); 6622908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR1(lseq), 0xFFFF); 6632908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR2(lseq), 0xFFFF); 6642908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR3(lseq), 0xFFFF); 6652908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD0(lseq), 0); 6662908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD1(lseq), 0); 6672908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD2(lseq), 0); 6682908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD3(lseq), 0); 6692908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_HEAD(lseq), 0); 6702908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_TAIL(lseq), 0); 6712908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_BUFS_AVAIL(lseq), 0); 6722908d778SJames Bottomley for (i = 0; i < 12; i += 4) 6732908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_ATA_SCR_REGS(lseq) + i, 0); 6742908d778SJames Bottomley 6752908d778SJames Bottomley /* LSEQ Mode Independent page 3 setup. */ 6762908d778SJames Bottomley 6772908d778SJames Bottomley /* Device present timer timeout */ 6782908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_DEV_PRES_TMR_TOUT_CONST(lseq), 6792908d778SJames Bottomley ASD_DEV_PRESENT_TIMEOUT); 6802908d778SJames Bottomley 6812908d778SJames Bottomley /* SATA interlock timer disabled */ 6822908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_SATA_INTERLOCK_TIMEOUT(lseq), 6832908d778SJames Bottomley ASD_SATA_INTERLOCK_TIMEOUT); 6842908d778SJames Bottomley 6852908d778SJames Bottomley /* STP shutdown timer timeout constant, IGNORED by the sequencer, 6862908d778SJames Bottomley * always 0. */ 6872908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_STP_SHUTDOWN_TIMEOUT(lseq), 6882908d778SJames Bottomley ASD_STP_SHUTDOWN_TIMEOUT); 6892908d778SJames Bottomley 6902908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_SRST_ASSERT_TIMEOUT(lseq), 6912908d778SJames Bottomley ASD_SRST_ASSERT_TIMEOUT); 6922908d778SJames Bottomley 6932908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_RCV_FIS_TIMEOUT(lseq), 6942908d778SJames Bottomley ASD_RCV_FIS_TIMEOUT); 6952908d778SJames Bottomley 6962908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_ONE_MILLISEC_TIMEOUT(lseq), 6972908d778SJames Bottomley ASD_ONE_MILLISEC_TIMEOUT); 6982908d778SJames Bottomley 6992908d778SJames Bottomley /* COM_INIT timer */ 7002908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_TEN_MS_COMINIT_TIMEOUT(lseq), 7012908d778SJames Bottomley ASD_TEN_MILLISEC_TIMEOUT); 7022908d778SJames Bottomley 7032908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_SMP_RCV_TIMEOUT(lseq), 7042908d778SJames Bottomley ASD_SMP_RCV_TIMEOUT); 7052908d778SJames Bottomley } 7062908d778SJames Bottomley 7072908d778SJames Bottomley /** 7082908d778SJames Bottomley * asd_init_lseq_mdp -- initialize LSEQ mode dependent pages. 7092908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 7102908d778SJames Bottomley */ 7112908d778SJames Bottomley static void asd_init_lseq_mdp(struct asd_ha_struct *asd_ha, int lseq) 7122908d778SJames Bottomley { 7132908d778SJames Bottomley int i; 7142908d778SJames Bottomley u32 moffs; 7152908d778SJames Bottomley u16 ret_addr[] = { 7162908d778SJames Bottomley 0xFFFF, /* mode 0 */ 7172908d778SJames Bottomley 0xFFFF, /* mode 1 */ 7182908d778SJames Bottomley mode2_task, /* mode 2 */ 7192908d778SJames Bottomley 0, 7202908d778SJames Bottomley 0xFFFF, /* mode 4/5 */ 7212908d778SJames Bottomley 0xFFFF, /* mode 4/5 */ 7222908d778SJames Bottomley }; 7232908d778SJames Bottomley 7242908d778SJames Bottomley /* 7252908d778SJames Bottomley * Mode 0,1,2 and 4/5 have common field on page 0 for the first 7262908d778SJames Bottomley * 14 bytes. 7272908d778SJames Bottomley */ 7282908d778SJames Bottomley for (i = 0; i < 3; i++) { 7292908d778SJames Bottomley moffs = i * LSEQ_MODE_SCRATCH_SIZE; 7302908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_RET_ADDR(lseq)+moffs, 7312908d778SJames Bottomley ret_addr[i]); 7322908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_REG0_MODE(lseq)+moffs, 0); 7332908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_MODE_FLAGS(lseq)+moffs, 0); 7342908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_RET_ADDR2(lseq)+moffs,0xFFFF); 7352908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_RET_ADDR1(lseq)+moffs,0xFFFF); 7362908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_OPCODE_TO_CSEQ(lseq)+moffs,0); 7372908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_DATA_TO_CSEQ(lseq)+moffs,0); 7382908d778SJames Bottomley } 7392908d778SJames Bottomley /* 7402908d778SJames Bottomley * Mode 5 page 0 overlaps the same scratch page with Mode 0 page 3. 7412908d778SJames Bottomley */ 7422908d778SJames Bottomley asd_write_reg_word(asd_ha, 7432908d778SJames Bottomley LmSEQ_RET_ADDR(lseq)+LSEQ_MODE5_PAGE0_OFFSET, 7442908d778SJames Bottomley ret_addr[5]); 7452908d778SJames Bottomley asd_write_reg_word(asd_ha, 7462908d778SJames Bottomley LmSEQ_REG0_MODE(lseq)+LSEQ_MODE5_PAGE0_OFFSET,0); 7472908d778SJames Bottomley asd_write_reg_word(asd_ha, 7482908d778SJames Bottomley LmSEQ_MODE_FLAGS(lseq)+LSEQ_MODE5_PAGE0_OFFSET, 0); 7492908d778SJames Bottomley asd_write_reg_word(asd_ha, 7502908d778SJames Bottomley LmSEQ_RET_ADDR2(lseq)+LSEQ_MODE5_PAGE0_OFFSET,0xFFFF); 7512908d778SJames Bottomley asd_write_reg_word(asd_ha, 7522908d778SJames Bottomley LmSEQ_RET_ADDR1(lseq)+LSEQ_MODE5_PAGE0_OFFSET,0xFFFF); 7532908d778SJames Bottomley asd_write_reg_byte(asd_ha, 7542908d778SJames Bottomley LmSEQ_OPCODE_TO_CSEQ(lseq)+LSEQ_MODE5_PAGE0_OFFSET,0); 7552908d778SJames Bottomley asd_write_reg_word(asd_ha, 7562908d778SJames Bottomley LmSEQ_DATA_TO_CSEQ(lseq)+LSEQ_MODE5_PAGE0_OFFSET, 0); 7572908d778SJames Bottomley 7582908d778SJames Bottomley /* LSEQ Mode dependent 0, page 0 setup. */ 7592908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_FIRST_INV_DDB_SITE(lseq), 7602908d778SJames Bottomley (u16)asd_ha->hw_prof.max_ddbs); 7612908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_EMPTY_TRANS_CTX(lseq), 0); 7622908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_RESP_LEN(lseq), 0); 7632908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_FIRST_INV_SCB_SITE(lseq), 7642908d778SJames Bottomley (u16)last_scb_site_no+1); 7652908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_INTEN_SAVE(lseq), 766355edd2eSAl Viro (u16) ((LmM0INTEN_MASK & 0xFFFF0000) >> 16)); 7672908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_INTEN_SAVE(lseq) + 2, 7682908d778SJames Bottomley (u16) LmM0INTEN_MASK & 0xFFFF); 7692908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_LINK_RST_FRM_LEN(lseq), 0); 7702908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_LINK_RST_PROTOCOL(lseq), 0); 7712908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_RESP_STATUS(lseq), 0); 7722908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_LAST_LOADED_SGE(lseq), 0); 7732908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_SAVE_SCBPTR(lseq), 0); 7742908d778SJames Bottomley 7752908d778SJames Bottomley /* LSEQ mode dependent, mode 1, page 0 setup. */ 7762908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_Q_XMIT_HEAD(lseq), 0xFFFF); 7772908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_M1_EMPTY_TRANS_CTX(lseq), 0); 7782908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_INI_CONN_TAG(lseq), 0); 7792908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_FAILED_OPEN_STATUS(lseq), 0); 7802908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_XMIT_REQUEST_TYPE(lseq), 0); 7812908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_M1_RESP_STATUS(lseq), 0); 7822908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_M1_LAST_LOADED_SGE(lseq), 0); 7832908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_M1_SAVE_SCBPTR(lseq), 0); 7842908d778SJames Bottomley 7852908d778SJames Bottomley /* LSEQ Mode dependent mode 2, page 0 setup */ 7862908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_PORT_COUNTER(lseq), 0); 7872908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_PM_TABLE_PTR(lseq), 0); 7882908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_SATA_INTERLOCK_TMR_SAVE(lseq), 0); 7892908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_IP_BITL(lseq), 0); 7902908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_COPY_SMP_CONN_TAG(lseq), 0); 7912908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_P0M2_OFFS1AH(lseq), 0); 7922908d778SJames Bottomley 7932908d778SJames Bottomley /* LSEQ Mode dependent, mode 4/5, page 0 setup. */ 7942908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_SAVED_OOB_STATUS(lseq), 0); 7952908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_SAVED_OOB_MODE(lseq), 0); 7962908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_Q_LINK_HEAD(lseq), 0xFFFF); 7972908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_LINK_RST_ERR(lseq), 0); 7982908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_SAVED_OOB_SIGNALS(lseq), 0); 7992908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_SAS_RESET_MODE(lseq), 0); 8002908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_LINK_RESET_RETRY_COUNT(lseq), 0); 8012908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_NUM_LINK_RESET_RETRIES(lseq), 0); 8022908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_OOB_INT_ENABLES(lseq), 0); 8032908d778SJames Bottomley /* 8042908d778SJames Bottomley * Set the desired interval between transmissions of the NOTIFY 8052908d778SJames Bottomley * (ENABLE SPINUP) primitive. Must be initilized to val - 1. 8062908d778SJames Bottomley */ 8072908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_NOTIFY_TIMER_TIMEOUT(lseq), 8082908d778SJames Bottomley ASD_NOTIFY_TIMEOUT - 1); 8092908d778SJames Bottomley /* No delay for the first NOTIFY to be sent to the attached target. */ 8102908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_NOTIFY_TIMER_DOWN_COUNT(lseq), 8112908d778SJames Bottomley ASD_NOTIFY_DOWN_COUNT); 812083d1631SWu, Gilbert asd_write_reg_word(asd_ha, LmSEQ_NOTIFY_TIMER_INITIAL_COUNT(lseq), 813083d1631SWu, Gilbert ASD_NOTIFY_DOWN_COUNT); 8142908d778SJames Bottomley 8152908d778SJames Bottomley /* LSEQ Mode dependent, mode 0 and 1, page 1 setup. */ 8162908d778SJames Bottomley for (i = 0; i < 2; i++) { 8172908d778SJames Bottomley int j; 8182908d778SJames Bottomley /* Start from Page 1 of Mode 0 and 1. */ 8192908d778SJames Bottomley moffs = LSEQ_PAGE_SIZE + i*LSEQ_MODE_SCRATCH_SIZE; 8202908d778SJames Bottomley /* All the fields of page 1 can be intialized to 0. */ 8212908d778SJames Bottomley for (j = 0; j < LSEQ_PAGE_SIZE; j += 4) 8222908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSCRATCH(lseq)+moffs+j,0); 8232908d778SJames Bottomley } 8242908d778SJames Bottomley 8252908d778SJames Bottomley /* LSEQ Mode dependent, mode 2, page 1 setup. */ 8262908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_INVALID_DWORD_COUNT(lseq), 0); 8272908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_DISPARITY_ERROR_COUNT(lseq), 0); 8282908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_LOSS_OF_SYNC_COUNT(lseq), 0); 8292908d778SJames Bottomley 8302908d778SJames Bottomley /* LSEQ Mode dependent, mode 4/5, page 1. */ 8312908d778SJames Bottomley for (i = 0; i < LSEQ_PAGE_SIZE; i+=4) 8322908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_FRAME_TYPE_MASK(lseq)+i, 0); 8332908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_FRAME_TYPE_MASK(lseq), 0xFF); 8342908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_HASHED_DEST_ADDR_MASK(lseq), 0xFF); 8352908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_HASHED_DEST_ADDR_MASK(lseq)+1,0xFF); 8362908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_HASHED_DEST_ADDR_MASK(lseq)+2,0xFF); 8372908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_HASHED_SRC_ADDR_MASK(lseq), 0xFF); 8382908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_HASHED_SRC_ADDR_MASK(lseq)+1, 0xFF); 8392908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_HASHED_SRC_ADDR_MASK(lseq)+2, 0xFF); 8402908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_DATA_OFFSET(lseq), 0xFFFFFFFF); 8412908d778SJames Bottomley 8422908d778SJames Bottomley /* LSEQ Mode dependent, mode 0, page 2 setup. */ 8432908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_SMP_RCV_TIMER_TERM_TS(lseq), 0); 8442908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_DEVICE_BITS(lseq), 0); 8452908d778SJames Bottomley asd_write_reg_word(asd_ha, LmSEQ_SDB_DDB(lseq), 0); 8462908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_SDB_NUM_TAGS(lseq), 0); 8472908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSEQ_SDB_CURR_TAG(lseq), 0); 8482908d778SJames Bottomley 8492908d778SJames Bottomley /* LSEQ Mode Dependent 1, page 2 setup. */ 8502908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_TX_ID_ADDR_FRAME(lseq), 0); 8512908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_TX_ID_ADDR_FRAME(lseq)+4, 0); 8522908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_OPEN_TIMER_TERM_TS(lseq), 0); 8532908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_SRST_AS_TIMER_TERM_TS(lseq), 0); 8542908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_LAST_LOADED_SG_EL(lseq), 0); 8552908d778SJames Bottomley 8562908d778SJames Bottomley /* LSEQ Mode Dependent 2, page 2 setup. */ 8572908d778SJames Bottomley /* The LmSEQ_STP_SHUTDOWN_TIMER_TERM_TS is IGNORED by the sequencer, 8582908d778SJames Bottomley * i.e. always 0. */ 8592908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_STP_SHUTDOWN_TIMER_TERM_TS(lseq),0); 8602908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_CLOSE_TIMER_TERM_TS(lseq), 0); 8612908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_BREAK_TIMER_TERM_TS(lseq), 0); 8622908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_DWS_RESET_TIMER_TERM_TS(lseq), 0); 8632908d778SJames Bottomley asd_write_reg_dword(asd_ha,LmSEQ_SATA_INTERLOCK_TIMER_TERM_TS(lseq),0); 8642908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_MCTL_TIMER_TERM_TS(lseq), 0); 8652908d778SJames Bottomley 8662908d778SJames Bottomley /* LSEQ Mode Dependent 4/5, page 2 setup. */ 8672908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_COMINIT_TIMER_TERM_TS(lseq), 0); 8682908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_RCV_ID_TIMER_TERM_TS(lseq), 0); 8692908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_RCV_FIS_TIMER_TERM_TS(lseq), 0); 8702908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmSEQ_DEV_PRES_TIMER_TERM_TS(lseq), 0); 8712908d778SJames Bottomley } 8722908d778SJames Bottomley 8732908d778SJames Bottomley /** 8742908d778SJames Bottomley * asd_init_lseq_scratch -- setup and init link sequencers 8752908d778SJames Bottomley * @asd_ha: pointer to host adapter struct 8762908d778SJames Bottomley */ 8772908d778SJames Bottomley static void asd_init_lseq_scratch(struct asd_ha_struct *asd_ha) 8782908d778SJames Bottomley { 8792908d778SJames Bottomley u8 lseq; 8802908d778SJames Bottomley u8 lseq_mask; 8812908d778SJames Bottomley 8822908d778SJames Bottomley lseq_mask = asd_ha->hw_prof.enabled_phys; 8832908d778SJames Bottomley for_each_sequencer(lseq_mask, lseq_mask, lseq) { 8842908d778SJames Bottomley asd_init_lseq_mip(asd_ha, lseq); 8852908d778SJames Bottomley asd_init_lseq_mdp(asd_ha, lseq); 8862908d778SJames Bottomley } 8872908d778SJames Bottomley } 8882908d778SJames Bottomley 8892908d778SJames Bottomley /** 8902908d778SJames Bottomley * asd_init_scb_sites -- initialize sequencer SCB sites (memory). 8912908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 8922908d778SJames Bottomley * 8932908d778SJames Bottomley * This should be done before initializing common CSEQ and LSEQ 8942908d778SJames Bottomley * scratch since those areas depend on some computed values here, 8952908d778SJames Bottomley * last_scb_site_no, etc. 8962908d778SJames Bottomley */ 8972908d778SJames Bottomley static void asd_init_scb_sites(struct asd_ha_struct *asd_ha) 8982908d778SJames Bottomley { 8992908d778SJames Bottomley u16 site_no; 9002908d778SJames Bottomley u16 max_scbs = 0; 9012908d778SJames Bottomley 9022908d778SJames Bottomley for (site_no = asd_ha->hw_prof.max_scbs-1; 9032908d778SJames Bottomley site_no != (u16) -1; 9042908d778SJames Bottomley site_no--) { 9052908d778SJames Bottomley u16 i; 9062908d778SJames Bottomley 9072908d778SJames Bottomley /* Initialize all fields in the SCB site to 0. */ 9082908d778SJames Bottomley for (i = 0; i < ASD_SCB_SIZE; i += 4) 9092908d778SJames Bottomley asd_scbsite_write_dword(asd_ha, site_no, i, 0); 9102908d778SJames Bottomley 9113b709df5SDarrick J. Wong /* Initialize SCB Site Opcode field to invalid. */ 9123b709df5SDarrick J. Wong asd_scbsite_write_byte(asd_ha, site_no, 9133b709df5SDarrick J. Wong offsetof(struct scb_header, opcode), 9143b709df5SDarrick J. Wong 0xFF); 9153b709df5SDarrick J. Wong 9163b709df5SDarrick J. Wong /* Initialize SCB Site Flags field to mean a response 9173b709df5SDarrick J. Wong * frame has been received. This means inadvertent 9183b709df5SDarrick J. Wong * frames received to be dropped. */ 9193b709df5SDarrick J. Wong asd_scbsite_write_byte(asd_ha, site_no, 0x49, 0x01); 9203b709df5SDarrick J. Wong 9212908d778SJames Bottomley /* Workaround needed by SEQ to fix a SATA issue is to exclude 9222908d778SJames Bottomley * certain SCB sites from the free list. */ 9232908d778SJames Bottomley if (!SCB_SITE_VALID(site_no)) 9242908d778SJames Bottomley continue; 9252908d778SJames Bottomley 9262908d778SJames Bottomley if (last_scb_site_no == 0) 9272908d778SJames Bottomley last_scb_site_no = site_no; 9282908d778SJames Bottomley 9292908d778SJames Bottomley /* For every SCB site, we need to initialize the 9302908d778SJames Bottomley * following fields: Q_NEXT, SCB_OPCODE, SCB_FLAGS, 9312908d778SJames Bottomley * and SG Element Flag. */ 9322908d778SJames Bottomley 9332908d778SJames Bottomley /* Q_NEXT field of the last SCB is invalidated. */ 9342908d778SJames Bottomley asd_scbsite_write_word(asd_ha, site_no, 0, first_scb_site_no); 9352908d778SJames Bottomley 9362908d778SJames Bottomley first_scb_site_no = site_no; 9372908d778SJames Bottomley max_scbs++; 9382908d778SJames Bottomley } 9392908d778SJames Bottomley asd_ha->hw_prof.max_scbs = max_scbs; 9402908d778SJames Bottomley ASD_DPRINTK("max_scbs:%d\n", asd_ha->hw_prof.max_scbs); 9412908d778SJames Bottomley ASD_DPRINTK("first_scb_site_no:0x%x\n", first_scb_site_no); 9422908d778SJames Bottomley ASD_DPRINTK("last_scb_site_no:0x%x\n", last_scb_site_no); 9432908d778SJames Bottomley } 9442908d778SJames Bottomley 9452908d778SJames Bottomley /** 9462908d778SJames Bottomley * asd_init_cseq_cio - initialize CSEQ CIO registers 9472908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 9482908d778SJames Bottomley */ 9492908d778SJames Bottomley static void asd_init_cseq_cio(struct asd_ha_struct *asd_ha) 9502908d778SJames Bottomley { 9512908d778SJames Bottomley int i; 9522908d778SJames Bottomley 9532908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQCOMINTEN, 0); 9542908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQDLCTL, ASD_DL_SIZE_BITS); 9552908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQDLOFFS, 0); 9562908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSEQDLOFFS+1, 0); 9572908d778SJames Bottomley asd_ha->seq.scbpro = 0; 9582908d778SJames Bottomley asd_write_reg_dword(asd_ha, SCBPRO, 0); 9592908d778SJames Bottomley asd_write_reg_dword(asd_ha, CSEQCON, 0); 9602908d778SJames Bottomley 9612908d778SJames Bottomley /* Intialize CSEQ Mode 11 Interrupt Vectors. 9622908d778SJames Bottomley * The addresses are 16 bit wide and in dword units. 9632908d778SJames Bottomley * The values of their macros are in byte units. 9642908d778SJames Bottomley * Thus we have to divide by 4. */ 9652908d778SJames Bottomley asd_write_reg_word(asd_ha, CM11INTVEC0, cseq_vecs[0]); 9662908d778SJames Bottomley asd_write_reg_word(asd_ha, CM11INTVEC1, cseq_vecs[1]); 9672908d778SJames Bottomley asd_write_reg_word(asd_ha, CM11INTVEC2, cseq_vecs[2]); 9682908d778SJames Bottomley 9692908d778SJames Bottomley /* Enable ARP2HALTC (ARP2 Halted from Halt Code Write). */ 9702908d778SJames Bottomley asd_write_reg_byte(asd_ha, CARP2INTEN, EN_ARP2HALTC); 9712908d778SJames Bottomley 9722908d778SJames Bottomley /* Initialize CSEQ Scratch Page to 0x04. */ 9732908d778SJames Bottomley asd_write_reg_byte(asd_ha, CSCRATCHPAGE, 0x04); 9742908d778SJames Bottomley 9752908d778SJames Bottomley /* Initialize CSEQ Mode[0-8] Dependent registers. */ 9762908d778SJames Bottomley /* Initialize Scratch Page to 0. */ 9772908d778SJames Bottomley for (i = 0; i < 9; i++) 9782908d778SJames Bottomley asd_write_reg_byte(asd_ha, CMnSCRATCHPAGE(i), 0); 9792908d778SJames Bottomley 9802908d778SJames Bottomley /* Reset the ARP2 Program Count. */ 9812908d778SJames Bottomley asd_write_reg_word(asd_ha, CPRGMCNT, cseq_idle_loop); 9822908d778SJames Bottomley 9832908d778SJames Bottomley for (i = 0; i < 8; i++) { 9842908d778SJames Bottomley /* Intialize Mode n Link m Interrupt Enable. */ 9852908d778SJames Bottomley asd_write_reg_dword(asd_ha, CMnINTEN(i), EN_CMnRSPMBXF); 9862908d778SJames Bottomley /* Initialize Mode n Request Mailbox. */ 9872908d778SJames Bottomley asd_write_reg_dword(asd_ha, CMnREQMBX(i), 0); 9882908d778SJames Bottomley } 9892908d778SJames Bottomley } 9902908d778SJames Bottomley 9912908d778SJames Bottomley /** 9922908d778SJames Bottomley * asd_init_lseq_cio -- initialize LmSEQ CIO registers 9932908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 9942908d778SJames Bottomley */ 9952908d778SJames Bottomley static void asd_init_lseq_cio(struct asd_ha_struct *asd_ha, int lseq) 9962908d778SJames Bottomley { 9972908d778SJames Bottomley u8 *sas_addr; 9982908d778SJames Bottomley int i; 9992908d778SJames Bottomley 10002908d778SJames Bottomley /* Enable ARP2HALTC (ARP2 Halted from Halt Code Write). */ 10012908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmARP2INTEN(lseq), EN_ARP2HALTC); 10022908d778SJames Bottomley 10032908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmSCRATCHPAGE(lseq), 0); 10042908d778SJames Bottomley 10052908d778SJames Bottomley /* Initialize Mode 0,1, and 2 SCRATCHPAGE to 0. */ 10062908d778SJames Bottomley for (i = 0; i < 3; i++) 10072908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmMnSCRATCHPAGE(lseq, i), 0); 10082908d778SJames Bottomley 10092908d778SJames Bottomley /* Initialize Mode 5 SCRATCHPAGE to 0. */ 10102908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmMnSCRATCHPAGE(lseq, 5), 0); 10112908d778SJames Bottomley 10122908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmRSPMBX(lseq), 0); 10132908d778SJames Bottomley /* Initialize Mode 0,1,2 and 5 Interrupt Enable and 10142908d778SJames Bottomley * Interrupt registers. */ 10152908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 0), LmM0INTEN_MASK); 10162908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmMnINT(lseq, 0), 0xFFFFFFFF); 10172908d778SJames Bottomley /* Mode 1 */ 10182908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 1), LmM1INTEN_MASK); 10192908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmMnINT(lseq, 1), 0xFFFFFFFF); 10202908d778SJames Bottomley /* Mode 2 */ 10212908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 2), LmM2INTEN_MASK); 10222908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmMnINT(lseq, 2), 0xFFFFFFFF); 10232908d778SJames Bottomley /* Mode 5 */ 10242908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 5), LmM5INTEN_MASK); 10252908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmMnINT(lseq, 5), 0xFFFFFFFF); 10262908d778SJames Bottomley 10272908d778SJames Bottomley /* Enable HW Timer status. */ 10282908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmHWTSTATEN(lseq), LmHWTSTATEN_MASK); 10292908d778SJames Bottomley 10302908d778SJames Bottomley /* Enable Primitive Status 0 and 1. */ 10312908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmPRIMSTAT0EN(lseq), LmPRIMSTAT0EN_MASK); 10322908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmPRIMSTAT1EN(lseq), LmPRIMSTAT1EN_MASK); 10332908d778SJames Bottomley 10342908d778SJames Bottomley /* Enable Frame Error. */ 10352908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmFRMERREN(lseq), LmFRMERREN_MASK); 10362908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmMnHOLDLVL(lseq, 0), 0x50); 10372908d778SJames Bottomley 10382908d778SJames Bottomley /* Initialize Mode 0 Transfer Level to 512. */ 10392908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmMnXFRLVL(lseq, 0), LmMnXFRLVL_512); 10402908d778SJames Bottomley /* Initialize Mode 1 Transfer Level to 256. */ 10412908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmMnXFRLVL(lseq, 1), LmMnXFRLVL_256); 10422908d778SJames Bottomley 10432908d778SJames Bottomley /* Initialize Program Count. */ 10442908d778SJames Bottomley asd_write_reg_word(asd_ha, LmPRGMCNT(lseq), lseq_idle_loop); 10452908d778SJames Bottomley 10462908d778SJames Bottomley /* Enable Blind SG Move. */ 10472908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmMODECTL(lseq), LmBLIND48); 10482908d778SJames Bottomley asd_write_reg_word(asd_ha, LmM3SATATIMER(lseq), 10492908d778SJames Bottomley ASD_SATA_INTERLOCK_TIMEOUT); 10502908d778SJames Bottomley 10512908d778SJames Bottomley (void) asd_read_reg_dword(asd_ha, LmREQMBX(lseq)); 10522908d778SJames Bottomley 10532908d778SJames Bottomley /* Clear Primitive Status 0 and 1. */ 10542908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmPRMSTAT0(lseq), 0xFFFFFFFF); 10552908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmPRMSTAT1(lseq), 0xFFFFFFFF); 10562908d778SJames Bottomley 10572908d778SJames Bottomley /* Clear HW Timer status. */ 10582908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmHWTSTAT(lseq), 0xFF); 10592908d778SJames Bottomley 10602908d778SJames Bottomley /* Clear DMA Errors for Mode 0 and 1. */ 10612908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmMnDMAERRS(lseq, 0), 0xFF); 10622908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmMnDMAERRS(lseq, 1), 0xFF); 10632908d778SJames Bottomley 10642908d778SJames Bottomley /* Clear SG DMA Errors for Mode 0 and 1. */ 10652908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmMnSGDMAERRS(lseq, 0), 0xFF); 10662908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmMnSGDMAERRS(lseq, 1), 0xFF); 10672908d778SJames Bottomley 10682908d778SJames Bottomley /* Clear Mode 0 Buffer Parity Error. */ 10692908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmMnBUFSTAT(lseq, 0), LmMnBUFPERR); 10702908d778SJames Bottomley 10712908d778SJames Bottomley /* Clear Mode 0 Frame Error register. */ 10722908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmMnFRMERR(lseq, 0), 0xFFFFFFFF); 10732908d778SJames Bottomley 10742908d778SJames Bottomley /* Reset LSEQ external interrupt arbiter. */ 10752908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmARP2INTCTL(lseq), RSTINTCTL); 10762908d778SJames Bottomley 10772908d778SJames Bottomley /* Set the Phy SAS for the LmSEQ WWN. */ 10782908d778SJames Bottomley sas_addr = asd_ha->phys[lseq].phy_desc->sas_addr; 10792908d778SJames Bottomley for (i = 0; i < SAS_ADDR_SIZE; i++) 10802908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmWWN(lseq) + i, sas_addr[i]); 10812908d778SJames Bottomley 10822908d778SJames Bottomley /* Set the Transmit Size to 1024 bytes, 0 = 256 Dwords. */ 10832908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmMnXMTSIZE(lseq, 1), 0); 10842908d778SJames Bottomley 10852908d778SJames Bottomley /* Set the Bus Inactivity Time Limit Timer. */ 10862908d778SJames Bottomley asd_write_reg_word(asd_ha, LmBITL_TIMER(lseq), 9); 10872908d778SJames Bottomley 10882908d778SJames Bottomley /* Enable SATA Port Multiplier. */ 10892908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmMnSATAFS(lseq, 1), 0x80); 10902908d778SJames Bottomley 10912908d778SJames Bottomley /* Initialize Interrupt Vector[0-10] address in Mode 3. 10922908d778SJames Bottomley * See the comment on CSEQ_INT_* */ 10932908d778SJames Bottomley asd_write_reg_word(asd_ha, LmM3INTVEC0(lseq), lseq_vecs[0]); 10942908d778SJames Bottomley asd_write_reg_word(asd_ha, LmM3INTVEC1(lseq), lseq_vecs[1]); 10952908d778SJames Bottomley asd_write_reg_word(asd_ha, LmM3INTVEC2(lseq), lseq_vecs[2]); 10962908d778SJames Bottomley asd_write_reg_word(asd_ha, LmM3INTVEC3(lseq), lseq_vecs[3]); 10972908d778SJames Bottomley asd_write_reg_word(asd_ha, LmM3INTVEC4(lseq), lseq_vecs[4]); 10982908d778SJames Bottomley asd_write_reg_word(asd_ha, LmM3INTVEC5(lseq), lseq_vecs[5]); 10992908d778SJames Bottomley asd_write_reg_word(asd_ha, LmM3INTVEC6(lseq), lseq_vecs[6]); 11002908d778SJames Bottomley asd_write_reg_word(asd_ha, LmM3INTVEC7(lseq), lseq_vecs[7]); 11012908d778SJames Bottomley asd_write_reg_word(asd_ha, LmM3INTVEC8(lseq), lseq_vecs[8]); 11022908d778SJames Bottomley asd_write_reg_word(asd_ha, LmM3INTVEC9(lseq), lseq_vecs[9]); 11032908d778SJames Bottomley asd_write_reg_word(asd_ha, LmM3INTVEC10(lseq), lseq_vecs[10]); 11042908d778SJames Bottomley /* 11052908d778SJames Bottomley * Program the Link LED control, applicable only for 11062908d778SJames Bottomley * Chip Rev. B or later. 11072908d778SJames Bottomley */ 11082908d778SJames Bottomley asd_write_reg_dword(asd_ha, LmCONTROL(lseq), 11092908d778SJames Bottomley (LEDTIMER | LEDMODE_TXRX | LEDTIMERS_100ms)); 11102908d778SJames Bottomley 11112908d778SJames Bottomley /* Set the Align Rate for SAS and STP mode. */ 11122908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmM1SASALIGN(lseq), SAS_ALIGN_DEFAULT); 11132908d778SJames Bottomley asd_write_reg_byte(asd_ha, LmM1STPALIGN(lseq), STP_ALIGN_DEFAULT); 11142908d778SJames Bottomley } 11152908d778SJames Bottomley 11162908d778SJames Bottomley 11172908d778SJames Bottomley /** 11182908d778SJames Bottomley * asd_post_init_cseq -- clear CSEQ Mode n Int. status and Response mailbox 11192908d778SJames Bottomley * @asd_ha: pointer to host adapter struct 11202908d778SJames Bottomley */ 11212908d778SJames Bottomley static void asd_post_init_cseq(struct asd_ha_struct *asd_ha) 11222908d778SJames Bottomley { 11232908d778SJames Bottomley int i; 11242908d778SJames Bottomley 11252908d778SJames Bottomley for (i = 0; i < 8; i++) 11262908d778SJames Bottomley asd_write_reg_dword(asd_ha, CMnINT(i), 0xFFFFFFFF); 11272908d778SJames Bottomley for (i = 0; i < 8; i++) 11282908d778SJames Bottomley asd_read_reg_dword(asd_ha, CMnRSPMBX(i)); 11292908d778SJames Bottomley /* Reset the external interrupt arbiter. */ 11302908d778SJames Bottomley asd_write_reg_byte(asd_ha, CARP2INTCTL, RSTINTCTL); 11312908d778SJames Bottomley } 11322908d778SJames Bottomley 11332908d778SJames Bottomley /** 11342908d778SJames Bottomley * asd_init_ddb_0 -- initialize DDB 0 11352908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 11362908d778SJames Bottomley * 11372908d778SJames Bottomley * Initialize DDB site 0 which is used internally by the sequencer. 11382908d778SJames Bottomley */ 11392908d778SJames Bottomley static void asd_init_ddb_0(struct asd_ha_struct *asd_ha) 11402908d778SJames Bottomley { 11412908d778SJames Bottomley int i; 11422908d778SJames Bottomley 11432908d778SJames Bottomley /* Zero out the DDB explicitly */ 11442908d778SJames Bottomley for (i = 0; i < sizeof(struct asd_ddb_seq_shared); i+=4) 11452908d778SJames Bottomley asd_ddbsite_write_dword(asd_ha, 0, i, 0); 11462908d778SJames Bottomley 11472908d778SJames Bottomley asd_ddbsite_write_word(asd_ha, 0, 11482908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, q_free_ddb_head), 0); 11492908d778SJames Bottomley asd_ddbsite_write_word(asd_ha, 0, 11502908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, q_free_ddb_tail), 11512908d778SJames Bottomley asd_ha->hw_prof.max_ddbs-1); 11522908d778SJames Bottomley asd_ddbsite_write_word(asd_ha, 0, 11532908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, q_free_ddb_cnt), 0); 11542908d778SJames Bottomley asd_ddbsite_write_word(asd_ha, 0, 11552908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, q_used_ddb_head), 0xFFFF); 11562908d778SJames Bottomley asd_ddbsite_write_word(asd_ha, 0, 11572908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, q_used_ddb_tail), 0xFFFF); 11582908d778SJames Bottomley asd_ddbsite_write_word(asd_ha, 0, 11592908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, shared_mem_lock), 0); 11602908d778SJames Bottomley asd_ddbsite_write_word(asd_ha, 0, 11612908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, smp_conn_tag), 0); 11622908d778SJames Bottomley asd_ddbsite_write_word(asd_ha, 0, 11632908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, est_nexus_buf_cnt), 0); 11642908d778SJames Bottomley asd_ddbsite_write_word(asd_ha, 0, 11652908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, est_nexus_buf_thresh), 11662908d778SJames Bottomley asd_ha->hw_prof.num_phys * 2); 11672908d778SJames Bottomley asd_ddbsite_write_byte(asd_ha, 0, 11682908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, settable_max_contexts),0); 11692908d778SJames Bottomley asd_ddbsite_write_byte(asd_ha, 0, 11702908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, conn_not_active), 0xFF); 11712908d778SJames Bottomley asd_ddbsite_write_byte(asd_ha, 0, 11722908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, phy_is_up), 0x00); 11732908d778SJames Bottomley /* DDB 0 is reserved */ 11742908d778SJames Bottomley set_bit(0, asd_ha->hw_prof.ddb_bitmap); 11752908d778SJames Bottomley } 11762908d778SJames Bottomley 11773b709df5SDarrick J. Wong static void asd_seq_init_ddb_sites(struct asd_ha_struct *asd_ha) 11783b709df5SDarrick J. Wong { 11793b709df5SDarrick J. Wong unsigned int i; 11803b709df5SDarrick J. Wong unsigned int ddb_site; 11813b709df5SDarrick J. Wong 11823b709df5SDarrick J. Wong for (ddb_site = 0 ; ddb_site < ASD_MAX_DDBS; ddb_site++) 11833b709df5SDarrick J. Wong for (i = 0; i < sizeof(struct asd_ddb_ssp_smp_target_port); i+= 4) 11843b709df5SDarrick J. Wong asd_ddbsite_write_dword(asd_ha, ddb_site, i, 0); 11853b709df5SDarrick J. Wong } 11863b709df5SDarrick J. Wong 11872908d778SJames Bottomley /** 11882908d778SJames Bottomley * asd_seq_setup_seqs -- setup and initialize central and link sequencers 11892908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 11902908d778SJames Bottomley */ 11912908d778SJames Bottomley static void asd_seq_setup_seqs(struct asd_ha_struct *asd_ha) 11922908d778SJames Bottomley { 11932908d778SJames Bottomley int lseq; 11942908d778SJames Bottomley u8 lseq_mask; 11952908d778SJames Bottomley 11963b709df5SDarrick J. Wong /* Initialize DDB sites */ 11973b709df5SDarrick J. Wong asd_seq_init_ddb_sites(asd_ha); 11983b709df5SDarrick J. Wong 11992908d778SJames Bottomley /* Initialize SCB sites. Done first to compute some values which 12002908d778SJames Bottomley * the rest of the init code depends on. */ 12012908d778SJames Bottomley asd_init_scb_sites(asd_ha); 12022908d778SJames Bottomley 12032908d778SJames Bottomley /* Initialize CSEQ Scratch RAM registers. */ 12042908d778SJames Bottomley asd_init_cseq_scratch(asd_ha); 12052908d778SJames Bottomley 12062908d778SJames Bottomley /* Initialize LmSEQ Scratch RAM registers. */ 12072908d778SJames Bottomley asd_init_lseq_scratch(asd_ha); 12082908d778SJames Bottomley 12092908d778SJames Bottomley /* Initialize CSEQ CIO registers. */ 12102908d778SJames Bottomley asd_init_cseq_cio(asd_ha); 12112908d778SJames Bottomley 12122908d778SJames Bottomley asd_init_ddb_0(asd_ha); 12132908d778SJames Bottomley 12142908d778SJames Bottomley /* Initialize LmSEQ CIO registers. */ 12152908d778SJames Bottomley lseq_mask = asd_ha->hw_prof.enabled_phys; 12162908d778SJames Bottomley for_each_sequencer(lseq_mask, lseq_mask, lseq) 12172908d778SJames Bottomley asd_init_lseq_cio(asd_ha, lseq); 12182908d778SJames Bottomley asd_post_init_cseq(asd_ha); 12192908d778SJames Bottomley } 12202908d778SJames Bottomley 12212908d778SJames Bottomley 12222908d778SJames Bottomley /** 12232908d778SJames Bottomley * asd_seq_start_cseq -- start the central sequencer, CSEQ 12242908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 12252908d778SJames Bottomley */ 12262908d778SJames Bottomley static int asd_seq_start_cseq(struct asd_ha_struct *asd_ha) 12272908d778SJames Bottomley { 12282908d778SJames Bottomley /* Reset the ARP2 instruction to location zero. */ 12292908d778SJames Bottomley asd_write_reg_word(asd_ha, CPRGMCNT, cseq_idle_loop); 12302908d778SJames Bottomley 12312908d778SJames Bottomley /* Unpause the CSEQ */ 12322908d778SJames Bottomley return asd_unpause_cseq(asd_ha); 12332908d778SJames Bottomley } 12342908d778SJames Bottomley 12352908d778SJames Bottomley /** 12362908d778SJames Bottomley * asd_seq_start_lseq -- start a link sequencer 12372908d778SJames Bottomley * @asd_ha: pointer to host adapter structure 12382908d778SJames Bottomley * @lseq: the link sequencer of interest 12392908d778SJames Bottomley */ 12402908d778SJames Bottomley static int asd_seq_start_lseq(struct asd_ha_struct *asd_ha, int lseq) 12412908d778SJames Bottomley { 12422908d778SJames Bottomley /* Reset the ARP2 instruction to location zero. */ 12432908d778SJames Bottomley asd_write_reg_word(asd_ha, LmPRGMCNT(lseq), lseq_idle_loop); 12442908d778SJames Bottomley 12452908d778SJames Bottomley /* Unpause the LmSEQ */ 12462908d778SJames Bottomley return asd_seq_unpause_lseq(asd_ha, lseq); 12472908d778SJames Bottomley } 12482908d778SJames Bottomley 1249bf2a1928SDarrick J. Wong int asd_release_firmware(void) 1250bf2a1928SDarrick J. Wong { 1251bf2a1928SDarrick J. Wong if (sequencer_fw) 1252bf2a1928SDarrick J. Wong release_firmware(sequencer_fw); 1253bf2a1928SDarrick J. Wong return 0; 1254bf2a1928SDarrick J. Wong } 1255bf2a1928SDarrick J. Wong 12562908d778SJames Bottomley static int asd_request_firmware(struct asd_ha_struct *asd_ha) 12572908d778SJames Bottomley { 12582908d778SJames Bottomley int err, i; 12592908d778SJames Bottomley struct sequencer_file_header header, *hdr_ptr; 12602908d778SJames Bottomley u32 csum = 0; 12612908d778SJames Bottomley u16 *ptr_cseq_vecs, *ptr_lseq_vecs; 12622908d778SJames Bottomley 12632908d778SJames Bottomley if (sequencer_fw) 12642908d778SJames Bottomley /* already loaded */ 12652908d778SJames Bottomley return 0; 12662908d778SJames Bottomley 12672908d778SJames Bottomley err = request_firmware(&sequencer_fw, 12682908d778SJames Bottomley SAS_RAZOR_SEQUENCER_FW_FILE, 12692908d778SJames Bottomley &asd_ha->pcidev->dev); 12702908d778SJames Bottomley if (err) 12712908d778SJames Bottomley return err; 12722908d778SJames Bottomley 12732908d778SJames Bottomley hdr_ptr = (struct sequencer_file_header *)sequencer_fw->data; 12742908d778SJames Bottomley 12752908d778SJames Bottomley header.csum = le32_to_cpu(hdr_ptr->csum); 12762908d778SJames Bottomley header.major = le32_to_cpu(hdr_ptr->major); 12772908d778SJames Bottomley header.minor = le32_to_cpu(hdr_ptr->minor); 12782908d778SJames Bottomley header.cseq_table_offset = le32_to_cpu(hdr_ptr->cseq_table_offset); 12792908d778SJames Bottomley header.cseq_table_size = le32_to_cpu(hdr_ptr->cseq_table_size); 12802908d778SJames Bottomley header.lseq_table_offset = le32_to_cpu(hdr_ptr->lseq_table_offset); 12812908d778SJames Bottomley header.lseq_table_size = le32_to_cpu(hdr_ptr->lseq_table_size); 12822908d778SJames Bottomley header.cseq_code_offset = le32_to_cpu(hdr_ptr->cseq_code_offset); 12832908d778SJames Bottomley header.cseq_code_size = le32_to_cpu(hdr_ptr->cseq_code_size); 12842908d778SJames Bottomley header.lseq_code_offset = le32_to_cpu(hdr_ptr->lseq_code_offset); 12852908d778SJames Bottomley header.lseq_code_size = le32_to_cpu(hdr_ptr->lseq_code_size); 12862908d778SJames Bottomley header.mode2_task = le16_to_cpu(hdr_ptr->mode2_task); 12872908d778SJames Bottomley header.cseq_idle_loop = le16_to_cpu(hdr_ptr->cseq_idle_loop); 12882908d778SJames Bottomley header.lseq_idle_loop = le16_to_cpu(hdr_ptr->lseq_idle_loop); 12892908d778SJames Bottomley 12902908d778SJames Bottomley for (i = sizeof(header.csum); i < sequencer_fw->size; i++) 12912908d778SJames Bottomley csum += sequencer_fw->data[i]; 12922908d778SJames Bottomley 12932908d778SJames Bottomley if (csum != header.csum) { 12942908d778SJames Bottomley asd_printk("Firmware file checksum mismatch\n"); 12952908d778SJames Bottomley return -EINVAL; 12962908d778SJames Bottomley } 12972908d778SJames Bottomley 12982908d778SJames Bottomley if (header.cseq_table_size != CSEQ_NUM_VECS || 12992908d778SJames Bottomley header.lseq_table_size != LSEQ_NUM_VECS) { 13002908d778SJames Bottomley asd_printk("Firmware file table size mismatch\n"); 13012908d778SJames Bottomley return -EINVAL; 13022908d778SJames Bottomley } 13032908d778SJames Bottomley 1304*a29fdd3cSJames Bottomley asd_printk("Found sequencer Firmware version %d.%d (%s)\n", 1305*a29fdd3cSJames Bottomley header.major, header.minor, hdr_ptr->version); 1306*a29fdd3cSJames Bottomley 1307*a29fdd3cSJames Bottomley if (header.major != SAS_RAZOR_SEQUENCER_FW_MAJOR) { 1308*a29fdd3cSJames Bottomley asd_printk("Firmware Major Version Mismatch;" 1309*a29fdd3cSJames Bottomley "driver requires version %d.X", 1310*a29fdd3cSJames Bottomley SAS_RAZOR_SEQUENCER_FW_MAJOR); 1311*a29fdd3cSJames Bottomley return -EINVAL; 1312*a29fdd3cSJames Bottomley } 1313*a29fdd3cSJames Bottomley 13142908d778SJames Bottomley ptr_cseq_vecs = (u16 *)&sequencer_fw->data[header.cseq_table_offset]; 13152908d778SJames Bottomley ptr_lseq_vecs = (u16 *)&sequencer_fw->data[header.lseq_table_offset]; 13162908d778SJames Bottomley mode2_task = header.mode2_task; 13172908d778SJames Bottomley cseq_idle_loop = header.cseq_idle_loop; 13182908d778SJames Bottomley lseq_idle_loop = header.lseq_idle_loop; 13192908d778SJames Bottomley 13202908d778SJames Bottomley for (i = 0; i < CSEQ_NUM_VECS; i++) 13212908d778SJames Bottomley cseq_vecs[i] = le16_to_cpu(ptr_cseq_vecs[i]); 13222908d778SJames Bottomley 13232908d778SJames Bottomley for (i = 0; i < LSEQ_NUM_VECS; i++) 13242908d778SJames Bottomley lseq_vecs[i] = le16_to_cpu(ptr_lseq_vecs[i]); 13252908d778SJames Bottomley 13262908d778SJames Bottomley cseq_code = &sequencer_fw->data[header.cseq_code_offset]; 13272908d778SJames Bottomley cseq_code_size = header.cseq_code_size; 13282908d778SJames Bottomley lseq_code = &sequencer_fw->data[header.lseq_code_offset]; 13292908d778SJames Bottomley lseq_code_size = header.lseq_code_size; 13302908d778SJames Bottomley 13312908d778SJames Bottomley return 0; 13322908d778SJames Bottomley } 13332908d778SJames Bottomley 13342908d778SJames Bottomley int asd_init_seqs(struct asd_ha_struct *asd_ha) 13352908d778SJames Bottomley { 13362908d778SJames Bottomley int err; 13372908d778SJames Bottomley 13382908d778SJames Bottomley err = asd_request_firmware(asd_ha); 13392908d778SJames Bottomley 13402908d778SJames Bottomley if (err) { 13412908d778SJames Bottomley asd_printk("Failed to load sequencer firmware file %s, error %d\n", 13422908d778SJames Bottomley SAS_RAZOR_SEQUENCER_FW_FILE, err); 13432908d778SJames Bottomley return err; 13442908d778SJames Bottomley } 13452908d778SJames Bottomley 13462908d778SJames Bottomley err = asd_seq_download_seqs(asd_ha); 13472908d778SJames Bottomley if (err) { 13482908d778SJames Bottomley asd_printk("couldn't download sequencers for %s\n", 13492908d778SJames Bottomley pci_name(asd_ha->pcidev)); 13502908d778SJames Bottomley return err; 13512908d778SJames Bottomley } 13522908d778SJames Bottomley 13532908d778SJames Bottomley asd_seq_setup_seqs(asd_ha); 13542908d778SJames Bottomley 13552908d778SJames Bottomley return 0; 13562908d778SJames Bottomley } 13572908d778SJames Bottomley 13582908d778SJames Bottomley int asd_start_seqs(struct asd_ha_struct *asd_ha) 13592908d778SJames Bottomley { 13602908d778SJames Bottomley int err; 13612908d778SJames Bottomley u8 lseq_mask; 13622908d778SJames Bottomley int lseq; 13632908d778SJames Bottomley 13642908d778SJames Bottomley err = asd_seq_start_cseq(asd_ha); 13652908d778SJames Bottomley if (err) { 13662908d778SJames Bottomley asd_printk("couldn't start CSEQ for %s\n", 13672908d778SJames Bottomley pci_name(asd_ha->pcidev)); 13682908d778SJames Bottomley return err; 13692908d778SJames Bottomley } 13702908d778SJames Bottomley 13712908d778SJames Bottomley lseq_mask = asd_ha->hw_prof.enabled_phys; 13722908d778SJames Bottomley for_each_sequencer(lseq_mask, lseq_mask, lseq) { 13732908d778SJames Bottomley err = asd_seq_start_lseq(asd_ha, lseq); 13742908d778SJames Bottomley if (err) { 13752908d778SJames Bottomley asd_printk("coudln't start LSEQ %d for %s\n", lseq, 13762908d778SJames Bottomley pci_name(asd_ha->pcidev)); 13772908d778SJames Bottomley return err; 13782908d778SJames Bottomley } 13792908d778SJames Bottomley } 13802908d778SJames Bottomley 13812908d778SJames Bottomley return 0; 13822908d778SJames Bottomley } 13832908d778SJames Bottomley 13842908d778SJames Bottomley /** 13852908d778SJames Bottomley * asd_update_port_links -- update port_map_by_links and phy_is_up 13862908d778SJames Bottomley * @sas_phy: pointer to the phy which has been added to a port 13872908d778SJames Bottomley * 13882908d778SJames Bottomley * 1) When a link reset has completed and we got BYTES DMAED with a 13892908d778SJames Bottomley * valid frame we call this function for that phy, to indicate that 13902908d778SJames Bottomley * the phy is up, i.e. we update the phy_is_up in DDB 0. The 13912908d778SJames Bottomley * sequencer checks phy_is_up when pending SCBs are to be sent, and 13922908d778SJames Bottomley * when an open address frame has been received. 13932908d778SJames Bottomley * 13942908d778SJames Bottomley * 2) When we know of ports, we call this function to update the map 13952908d778SJames Bottomley * of phys participaing in that port, i.e. we update the 13962908d778SJames Bottomley * port_map_by_links in DDB 0. When a HARD_RESET primitive has been 13972908d778SJames Bottomley * received, the sequencer disables all phys in that port. 13982908d778SJames Bottomley * port_map_by_links is also used as the conn_mask byte in the 13992908d778SJames Bottomley * initiator/target port DDB. 14002908d778SJames Bottomley */ 14013f048109Smalahal@us.ibm.com void asd_update_port_links(struct asd_ha_struct *asd_ha, struct asd_phy *phy) 14022908d778SJames Bottomley { 14033f048109Smalahal@us.ibm.com const u8 phy_mask = (u8) phy->asd_port->phy_mask; 14042908d778SJames Bottomley u8 phy_is_up; 14052908d778SJames Bottomley u8 mask; 14062908d778SJames Bottomley int i, err; 140757ba07dcSDarrick J. Wong unsigned long flags; 14082908d778SJames Bottomley 140957ba07dcSDarrick J. Wong spin_lock_irqsave(&asd_ha->hw_prof.ddb_lock, flags); 14102908d778SJames Bottomley for_each_phy(phy_mask, mask, i) 14112908d778SJames Bottomley asd_ddbsite_write_byte(asd_ha, 0, 14122908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, 14132908d778SJames Bottomley port_map_by_links)+i,phy_mask); 14142908d778SJames Bottomley 14152908d778SJames Bottomley for (i = 0; i < 12; i++) { 14162908d778SJames Bottomley phy_is_up = asd_ddbsite_read_byte(asd_ha, 0, 14172908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, phy_is_up)); 14182908d778SJames Bottomley err = asd_ddbsite_update_byte(asd_ha, 0, 14192908d778SJames Bottomley offsetof(struct asd_ddb_seq_shared, phy_is_up), 14202908d778SJames Bottomley phy_is_up, 14212908d778SJames Bottomley phy_is_up | phy_mask); 14222908d778SJames Bottomley if (!err) 14232908d778SJames Bottomley break; 14242908d778SJames Bottomley else if (err == -EFAULT) { 14252908d778SJames Bottomley asd_printk("phy_is_up: parity error in DDB 0\n"); 14262908d778SJames Bottomley break; 14272908d778SJames Bottomley } 14282908d778SJames Bottomley } 142957ba07dcSDarrick J. Wong spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags); 14302908d778SJames Bottomley 14312908d778SJames Bottomley if (err) 14322908d778SJames Bottomley asd_printk("couldn't update DDB 0:error:%d\n", err); 14332908d778SJames Bottomley } 1434bc229b36SJames Bottomley 1435bc229b36SJames Bottomley MODULE_FIRMWARE(SAS_RAZOR_SEQUENCER_FW_FILE); 1436