2 * Aic94xx SAS/SATA driver sequencer interface.
4 * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
5 * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
7 * Parts of this code adapted from David Chaw's adp94xx_seq.c.
9 * This file is licensed under GPLv2.
11 * This file is part of the aic94xx driver.
13 * The aic94xx driver is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; version 2 of the
18 * The aic94xx driver is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with the aic94xx driver; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <linux/delay.h>
30 #include <linux/pci.h>
31 #include <linux/module.h>
32 #include <linux/firmware.h>
33 #include "aic94xx_reg.h"
34 #include "aic94xx_hwi.h"
36 #include "aic94xx_seq.h"
37 #include "aic94xx_dump.h"
39 /* It takes no more than 0.05 us for an instruction
40 * to complete. So waiting for 1 us should be more than
44 #define PAUSE_TRIES 1000
46 static const struct firmware *sequencer_fw;
47 static const char *sequencer_version;
48 static u16 cseq_vecs[CSEQ_NUM_VECS], lseq_vecs[LSEQ_NUM_VECS], mode2_task,
49 cseq_idle_loop, lseq_idle_loop;
50 static u8 *cseq_code, *lseq_code;
51 static u32 cseq_code_size, lseq_code_size;
53 static u16 first_scb_site_no = 0xFFFF;
54 static u16 last_scb_site_no;
56 /* ---------- Pause/Unpause CSEQ/LSEQ ---------- */
59 * asd_pause_cseq - pause the central sequencer
60 * @asd_ha: pointer to host adapter structure
62 * Return 0 on success, negative on failure.
64 int asd_pause_cseq(struct asd_ha_struct *asd_ha)
66 int count = PAUSE_TRIES;
69 arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL);
73 asd_write_reg_dword(asd_ha, CARP2CTL, arp2ctl | EPAUSE);
75 arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL);
79 } while (--count > 0);
81 ASD_DPRINTK("couldn't pause CSEQ\n");
86 * asd_unpause_cseq - unpause the central sequencer.
87 * @asd_ha: pointer to host adapter structure.
89 * Return 0 on success, negative on error.
91 int asd_unpause_cseq(struct asd_ha_struct *asd_ha)
94 int count = PAUSE_TRIES;
96 arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL);
97 if (!(arp2ctl & PAUSED))
100 asd_write_reg_dword(asd_ha, CARP2CTL, arp2ctl & ~EPAUSE);
102 arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL);
103 if (!(arp2ctl & PAUSED))
106 } while (--count > 0);
108 ASD_DPRINTK("couldn't unpause the CSEQ\n");
113 * asd_seq_pause_lseq - pause a link sequencer
114 * @asd_ha: pointer to a host adapter structure
115 * @lseq: link sequencer of interest
117 * Return 0 on success, negative on error.
119 static inline int asd_seq_pause_lseq(struct asd_ha_struct *asd_ha, int lseq)
122 int count = PAUSE_TRIES;
124 arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq));
125 if (arp2ctl & PAUSED)
128 asd_write_reg_dword(asd_ha, LmARP2CTL(lseq), arp2ctl | EPAUSE);
130 arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq));
131 if (arp2ctl & PAUSED)
134 } while (--count > 0);
136 ASD_DPRINTK("couldn't pause LSEQ %d\n", lseq);
141 * asd_pause_lseq - pause the link sequencer(s)
142 * @asd_ha: pointer to host adapter structure
143 * @lseq_mask: mask of link sequencers of interest
145 * Return 0 on success, negative on failure.
147 int asd_pause_lseq(struct asd_ha_struct *asd_ha, u8 lseq_mask)
152 for_each_sequencer(lseq_mask, lseq_mask, lseq) {
153 err = asd_seq_pause_lseq(asd_ha, lseq);
162 * asd_seq_unpause_lseq - unpause a link sequencer
163 * @asd_ha: pointer to host adapter structure
164 * @lseq: link sequencer of interest
166 * Return 0 on success, negative on error.
168 static inline int asd_seq_unpause_lseq(struct asd_ha_struct *asd_ha, int lseq)
171 int count = PAUSE_TRIES;
173 arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq));
174 if (!(arp2ctl & PAUSED))
177 asd_write_reg_dword(asd_ha, LmARP2CTL(lseq), arp2ctl & ~EPAUSE);
179 arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq));
180 if (!(arp2ctl & PAUSED))
183 } while (--count > 0);
185 ASD_DPRINTK("couldn't unpause LSEQ %d\n", lseq);
191 * asd_unpause_lseq - unpause the link sequencer(s)
192 * @asd_ha: pointer to host adapter structure
193 * @lseq_mask: mask of link sequencers of interest
195 * Return 0 on success, negative on failure.
197 int asd_unpause_lseq(struct asd_ha_struct *asd_ha, u8 lseq_mask)
202 for_each_sequencer(lseq_mask, lseq_mask, lseq) {
203 err = asd_seq_unpause_lseq(asd_ha, lseq);
211 /* ---------- Downloading CSEQ/LSEQ microcode ---------- */
213 static int asd_verify_cseq(struct asd_ha_struct *asd_ha, const u8 *_prog,
216 u32 addr = CSEQ_RAM_REG_BASE_ADR;
217 const u32 *prog = (u32 *) _prog;
220 for (i = 0; i < size; i += 4, prog++, addr += 4) {
221 u32 val = asd_read_reg_dword(asd_ha, addr);
223 if (le32_to_cpu(*prog) != val) {
224 asd_printk("%s: cseq verify failed at %u "
225 "read:0x%x, wanted:0x%x\n",
226 pci_name(asd_ha->pcidev),
227 i, val, le32_to_cpu(*prog));
231 ASD_DPRINTK("verified %d bytes, passed\n", size);
236 * asd_verify_lseq - verify the microcode of a link sequencer
237 * @asd_ha: pointer to host adapter structure
238 * @_prog: pointer to the microcode
239 * @size: size of the microcode in bytes
240 * @lseq: link sequencer of interest
242 * The link sequencer code is accessed in 4 KB pages, which are selected
243 * by setting LmRAMPAGE (bits 8 and 9) of the LmBISTCTL1 register.
244 * The 10 KB LSEQm instruction code is mapped, page at a time, at
247 static int asd_verify_lseq(struct asd_ha_struct *asd_ha, const u8 *_prog,
250 #define LSEQ_CODEPAGE_SIZE 4096
251 int pages = (size + LSEQ_CODEPAGE_SIZE - 1) / LSEQ_CODEPAGE_SIZE;
253 const u32 *prog = (u32 *) _prog;
255 for (page = 0; page < pages; page++) {
258 asd_write_reg_dword(asd_ha, LmBISTCTL1(lseq),
259 page << LmRAMPAGE_LSHIFT);
260 for (i = 0; size > 0 && i < LSEQ_CODEPAGE_SIZE;
261 i += 4, prog++, size-=4) {
263 u32 val = asd_read_reg_dword(asd_ha, LmSEQRAM(lseq)+i);
265 if (le32_to_cpu(*prog) != val) {
266 asd_printk("%s: LSEQ%d verify failed "
267 "page:%d, offs:%d\n",
268 pci_name(asd_ha->pcidev),
274 ASD_DPRINTK("LSEQ%d verified %d bytes, passed\n", lseq,
275 (int)((u8 *)prog-_prog));
280 * asd_verify_seq -- verify CSEQ/LSEQ microcode
281 * @asd_ha: pointer to host adapter structure
282 * @prog: pointer to microcode
283 * @size: size of the microcode
284 * @lseq_mask: if 0, verify CSEQ microcode, else mask of LSEQs of interest
286 * Return 0 if microcode is correct, negative on mismatch.
288 static int asd_verify_seq(struct asd_ha_struct *asd_ha, const u8 *prog,
289 u32 size, u8 lseq_mask)
292 return asd_verify_cseq(asd_ha, prog, size);
296 for_each_sequencer(lseq_mask, lseq_mask, lseq) {
297 err = asd_verify_lseq(asd_ha, prog, size, lseq);
305 #define ASD_DMA_MODE_DOWNLOAD
306 #ifdef ASD_DMA_MODE_DOWNLOAD
307 /* This is the size of the CSEQ Mapped instruction page */
308 #define MAX_DMA_OVLY_COUNT ((1U << 14)-1)
309 static int asd_download_seq(struct asd_ha_struct *asd_ha,
310 const u8 * const prog, u32 size, u8 lseq_mask)
315 const int pages = (size + MAX_DMA_OVLY_COUNT - 1) / MAX_DMA_OVLY_COUNT;
316 struct asd_dma_tok *token;
320 asd_printk("sequencer program not multiple of 4\n");
324 asd_pause_cseq(asd_ha);
325 asd_pause_lseq(asd_ha, 0xFF);
327 /* save, disable and clear interrupts */
328 comstaten = asd_read_reg_dword(asd_ha, COMSTATEN);
329 asd_write_reg_dword(asd_ha, COMSTATEN, 0);
330 asd_write_reg_dword(asd_ha, COMSTAT, COMSTAT_MASK);
332 asd_write_reg_dword(asd_ha, CHIMINTEN, RST_CHIMINTEN);
333 asd_write_reg_dword(asd_ha, CHIMINT, CHIMINT_MASK);
335 token = asd_alloc_coherent(asd_ha, MAX_DMA_OVLY_COUNT, GFP_KERNEL);
337 asd_printk("out of memory for dma SEQ download\n");
341 ASD_DPRINTK("dma-ing %d bytes\n", size);
343 for (page = 0; page < pages; page++) {
345 u32 left = min(size-page*MAX_DMA_OVLY_COUNT,
346 (u32)MAX_DMA_OVLY_COUNT);
348 memcpy(token->vaddr, prog + page*MAX_DMA_OVLY_COUNT, left);
349 asd_write_reg_addr(asd_ha, OVLYDMAADR, token->dma_handle);
350 asd_write_reg_dword(asd_ha, OVLYDMACNT, left);
351 reg = !page ? RESETOVLYDMA : 0;
352 reg |= (STARTOVLYDMA | OVLYHALTERR);
353 reg |= (lseq_mask ? (((u32)lseq_mask) << 8) : OVLYCSEQ);
355 asd_write_reg_dword(asd_ha, OVLYDMACTL, reg);
357 for (i = PAUSE_TRIES*100; i > 0; i--) {
358 u32 dmadone = asd_read_reg_dword(asd_ha, OVLYDMACTL);
359 if (!(dmadone & OVLYDMAACT))
365 reg = asd_read_reg_dword(asd_ha, COMSTAT);
366 if (!(reg & OVLYDMADONE) || (reg & OVLYERR)
367 || (asd_read_reg_dword(asd_ha, CHIMINT) & DEVEXCEPT_MASK)){
368 asd_printk("%s: error DMA-ing sequencer code\n",
369 pci_name(asd_ha->pcidev));
373 asd_free_coherent(asd_ha, token);
375 asd_write_reg_dword(asd_ha, COMSTATEN, comstaten);
377 return err ? : asd_verify_seq(asd_ha, prog, size, lseq_mask);
379 #else /* ASD_DMA_MODE_DOWNLOAD */
380 static int asd_download_seq(struct asd_ha_struct *asd_ha, const u8 *_prog,
381 u32 size, u8 lseq_mask)
385 const u32 *prog = (u32 *) _prog;
388 asd_printk("sequencer program not multiple of 4\n");
392 asd_pause_cseq(asd_ha);
393 asd_pause_lseq(asd_ha, 0xFF);
395 reg |= (lseq_mask ? (((u32)lseq_mask) << 8) : OVLYCSEQ);
398 asd_write_reg_dword(asd_ha, OVLYDMACNT, size);
399 asd_write_reg_dword(asd_ha, OVLYDMACTL, reg);
401 ASD_DPRINTK("downloading %s sequencer%s in PIO mode...\n",
402 lseq_mask ? "LSEQ" : "CSEQ", lseq_mask ? "s" : "");
404 for (i = 0; i < size; i += 4, prog++)
405 asd_write_reg_dword(asd_ha, SPIODATA, *prog);
407 reg = (reg & ~PIOCMODE) | OVLYHALTERR;
408 asd_write_reg_dword(asd_ha, OVLYDMACTL, reg);
410 return asd_verify_seq(asd_ha, _prog, size, lseq_mask);
412 #endif /* ASD_DMA_MODE_DOWNLOAD */
415 * asd_seq_download_seqs - download the sequencer microcode
416 * @asd_ha: pointer to host adapter structure
418 * Download the central and link sequencer microcode.
420 static int asd_seq_download_seqs(struct asd_ha_struct *asd_ha)
424 if (!asd_ha->hw_prof.enabled_phys) {
425 asd_printk("%s: no enabled phys!\n", pci_name(asd_ha->pcidev));
429 /* Download the CSEQ */
430 ASD_DPRINTK("downloading CSEQ...\n");
431 err = asd_download_seq(asd_ha, cseq_code, cseq_code_size, 0);
433 asd_printk("CSEQ download failed:%d\n", err);
437 /* Download the Link Sequencers code. All of the Link Sequencers
438 * microcode can be downloaded at the same time.
440 ASD_DPRINTK("downloading LSEQs...\n");
441 err = asd_download_seq(asd_ha, lseq_code, lseq_code_size,
442 asd_ha->hw_prof.enabled_phys);
444 /* Try it one at a time */
446 u8 lseq_mask = asd_ha->hw_prof.enabled_phys;
448 for_each_sequencer(lseq_mask, lseq_mask, lseq) {
449 err = asd_download_seq(asd_ha, lseq_code,
450 lseq_code_size, 1<<lseq);
456 asd_printk("LSEQs download failed:%d\n", err);
461 /* ---------- Initializing the chip, chip memory, etc. ---------- */
464 * asd_init_cseq_mip - initialize CSEQ mode independent pages 4-7
465 * @asd_ha: pointer to host adapter structure
467 static void asd_init_cseq_mip(struct asd_ha_struct *asd_ha)
469 /* CSEQ Mode Independent, page 4 setup. */
470 asd_write_reg_word(asd_ha, CSEQ_Q_EXE_HEAD, 0xFFFF);
471 asd_write_reg_word(asd_ha, CSEQ_Q_EXE_TAIL, 0xFFFF);
472 asd_write_reg_word(asd_ha, CSEQ_Q_DONE_HEAD, 0xFFFF);
473 asd_write_reg_word(asd_ha, CSEQ_Q_DONE_TAIL, 0xFFFF);
474 asd_write_reg_word(asd_ha, CSEQ_Q_SEND_HEAD, 0xFFFF);
475 asd_write_reg_word(asd_ha, CSEQ_Q_SEND_TAIL, 0xFFFF);
476 asd_write_reg_word(asd_ha, CSEQ_Q_DMA2CHIM_HEAD, 0xFFFF);
477 asd_write_reg_word(asd_ha, CSEQ_Q_DMA2CHIM_TAIL, 0xFFFF);
478 asd_write_reg_word(asd_ha, CSEQ_Q_COPY_HEAD, 0xFFFF);
479 asd_write_reg_word(asd_ha, CSEQ_Q_COPY_TAIL, 0xFFFF);
480 asd_write_reg_word(asd_ha, CSEQ_REG0, 0);
481 asd_write_reg_word(asd_ha, CSEQ_REG1, 0);
482 asd_write_reg_dword(asd_ha, CSEQ_REG2, 0);
483 asd_write_reg_byte(asd_ha, CSEQ_LINK_CTL_Q_MAP, 0);
485 u8 con = asd_read_reg_byte(asd_ha, CCONEXIST);
486 u8 val = hweight8(con);
487 asd_write_reg_byte(asd_ha, CSEQ_MAX_CSEQ_MODE, (val<<4)|val);
489 asd_write_reg_word(asd_ha, CSEQ_FREE_LIST_HACK_COUNT, 0);
491 /* CSEQ Mode independent, page 5 setup. */
492 asd_write_reg_dword(asd_ha, CSEQ_EST_NEXUS_REQ_QUEUE, 0);
493 asd_write_reg_dword(asd_ha, CSEQ_EST_NEXUS_REQ_QUEUE+4, 0);
494 asd_write_reg_dword(asd_ha, CSEQ_EST_NEXUS_REQ_COUNT, 0);
495 asd_write_reg_dword(asd_ha, CSEQ_EST_NEXUS_REQ_COUNT+4, 0);
496 asd_write_reg_word(asd_ha, CSEQ_Q_EST_NEXUS_HEAD, 0xFFFF);
497 asd_write_reg_word(asd_ha, CSEQ_Q_EST_NEXUS_TAIL, 0xFFFF);
498 asd_write_reg_word(asd_ha, CSEQ_NEED_EST_NEXUS_SCB, 0);
499 asd_write_reg_byte(asd_ha, CSEQ_EST_NEXUS_REQ_HEAD, 0);
500 asd_write_reg_byte(asd_ha, CSEQ_EST_NEXUS_REQ_TAIL, 0);
501 asd_write_reg_byte(asd_ha, CSEQ_EST_NEXUS_SCB_OFFSET, 0);
503 /* CSEQ Mode independent, page 6 setup. */
504 asd_write_reg_word(asd_ha, CSEQ_INT_ROUT_RET_ADDR0, 0);
505 asd_write_reg_word(asd_ha, CSEQ_INT_ROUT_RET_ADDR1, 0);
506 asd_write_reg_word(asd_ha, CSEQ_INT_ROUT_SCBPTR, 0);
507 asd_write_reg_byte(asd_ha, CSEQ_INT_ROUT_MODE, 0);
508 asd_write_reg_byte(asd_ha, CSEQ_ISR_SCRATCH_FLAGS, 0);
509 asd_write_reg_word(asd_ha, CSEQ_ISR_SAVE_SINDEX, 0);
510 asd_write_reg_word(asd_ha, CSEQ_ISR_SAVE_DINDEX, 0);
511 asd_write_reg_word(asd_ha, CSEQ_Q_MONIRTT_HEAD, 0xFFFF);
512 asd_write_reg_word(asd_ha, CSEQ_Q_MONIRTT_TAIL, 0xFFFF);
513 /* Calculate the free scb mask. */
515 u16 cmdctx = asd_get_cmdctx_size(asd_ha);
516 cmdctx = (~((cmdctx/128)-1)) >> 8;
517 asd_write_reg_byte(asd_ha, CSEQ_FREE_SCB_MASK, (u8)cmdctx);
519 asd_write_reg_word(asd_ha, CSEQ_BUILTIN_FREE_SCB_HEAD,
521 asd_write_reg_word(asd_ha, CSEQ_BUILTIN_FREE_SCB_TAIL,
523 asd_write_reg_word(asd_ha, CSEQ_EXTENDED_FREE_SCB_HEAD, 0xFFFF);
524 asd_write_reg_word(asd_ha, CSEQ_EXTENDED_FREE_SCB_TAIL, 0xFFFF);
526 /* CSEQ Mode independent, page 7 setup. */
527 asd_write_reg_dword(asd_ha, CSEQ_EMPTY_REQ_QUEUE, 0);
528 asd_write_reg_dword(asd_ha, CSEQ_EMPTY_REQ_QUEUE+4, 0);
529 asd_write_reg_dword(asd_ha, CSEQ_EMPTY_REQ_COUNT, 0);
530 asd_write_reg_dword(asd_ha, CSEQ_EMPTY_REQ_COUNT+4, 0);
531 asd_write_reg_word(asd_ha, CSEQ_Q_EMPTY_HEAD, 0xFFFF);
532 asd_write_reg_word(asd_ha, CSEQ_Q_EMPTY_TAIL, 0xFFFF);
533 asd_write_reg_word(asd_ha, CSEQ_NEED_EMPTY_SCB, 0);
534 asd_write_reg_byte(asd_ha, CSEQ_EMPTY_REQ_HEAD, 0);
535 asd_write_reg_byte(asd_ha, CSEQ_EMPTY_REQ_TAIL, 0);
536 asd_write_reg_byte(asd_ha, CSEQ_EMPTY_SCB_OFFSET, 0);
537 asd_write_reg_word(asd_ha, CSEQ_PRIMITIVE_DATA, 0);
538 asd_write_reg_dword(asd_ha, CSEQ_TIMEOUT_CONST, 0);
542 * asd_init_cseq_mdp - initialize CSEQ Mode dependent pages
543 * @asd_ha: pointer to host adapter structure
545 static void asd_init_cseq_mdp(struct asd_ha_struct *asd_ha)
550 moffs = CSEQ_PAGE_SIZE * 2;
552 /* CSEQ Mode dependent, modes 0-7, page 0 setup. */
553 for (i = 0; i < 8; i++) {
554 asd_write_reg_word(asd_ha, i*moffs+CSEQ_LRM_SAVE_SINDEX, 0);
555 asd_write_reg_word(asd_ha, i*moffs+CSEQ_LRM_SAVE_SCBPTR, 0);
556 asd_write_reg_word(asd_ha, i*moffs+CSEQ_Q_LINK_HEAD, 0xFFFF);
557 asd_write_reg_word(asd_ha, i*moffs+CSEQ_Q_LINK_TAIL, 0xFFFF);
558 asd_write_reg_byte(asd_ha, i*moffs+CSEQ_LRM_SAVE_SCRPAGE, 0);
561 /* CSEQ Mode dependent, mode 0-7, page 1 and 2 shall be ignored. */
563 /* CSEQ Mode dependent, mode 8, page 0 setup. */
564 asd_write_reg_word(asd_ha, CSEQ_RET_ADDR, 0xFFFF);
565 asd_write_reg_word(asd_ha, CSEQ_RET_SCBPTR, 0);
566 asd_write_reg_word(asd_ha, CSEQ_SAVE_SCBPTR, 0);
567 asd_write_reg_word(asd_ha, CSEQ_EMPTY_TRANS_CTX, 0);
568 asd_write_reg_word(asd_ha, CSEQ_RESP_LEN, 0);
569 asd_write_reg_word(asd_ha, CSEQ_TMF_SCBPTR, 0);
570 asd_write_reg_word(asd_ha, CSEQ_GLOBAL_PREV_SCB, 0);
571 asd_write_reg_word(asd_ha, CSEQ_GLOBAL_HEAD, 0);
572 asd_write_reg_word(asd_ha, CSEQ_CLEAR_LU_HEAD, 0);
573 asd_write_reg_byte(asd_ha, CSEQ_TMF_OPCODE, 0);
574 asd_write_reg_byte(asd_ha, CSEQ_SCRATCH_FLAGS, 0);
575 asd_write_reg_word(asd_ha, CSEQ_HSB_SITE, 0);
576 asd_write_reg_word(asd_ha, CSEQ_FIRST_INV_SCB_SITE,
577 (u16)last_scb_site_no+1);
578 asd_write_reg_word(asd_ha, CSEQ_FIRST_INV_DDB_SITE,
579 (u16)asd_ha->hw_prof.max_ddbs);
581 /* CSEQ Mode dependent, mode 8, page 1 setup. */
582 asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CLEAR, 0);
583 asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CLEAR + 4, 0);
584 asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CHECK, 0);
585 asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CHECK + 4, 0);
587 /* CSEQ Mode dependent, mode 8, page 2 setup. */
588 /* Tell the sequencer the bus address of the first SCB. */
589 asd_write_reg_addr(asd_ha, CSEQ_HQ_NEW_POINTER,
590 asd_ha->seq.next_scb.dma_handle);
591 ASD_DPRINTK("First SCB dma_handle: 0x%llx\n",
592 (unsigned long long)asd_ha->seq.next_scb.dma_handle);
594 /* Tell the sequencer the first Done List entry address. */
595 asd_write_reg_addr(asd_ha, CSEQ_HQ_DONE_BASE,
596 asd_ha->seq.actual_dl->dma_handle);
598 /* Initialize the Q_DONE_POINTER with the least significant
599 * 4 bytes of the first Done List address. */
600 asd_write_reg_dword(asd_ha, CSEQ_HQ_DONE_POINTER,
601 ASD_BUSADDR_LO(asd_ha->seq.actual_dl->dma_handle));
603 asd_write_reg_byte(asd_ha, CSEQ_HQ_DONE_PASS, ASD_DEF_DL_TOGGLE);
605 /* CSEQ Mode dependent, mode 8, page 3 shall be ignored. */
609 * asd_init_cseq_scratch -- setup and init CSEQ
610 * @asd_ha: pointer to host adapter structure
612 * Setup and initialize Central sequencers. Initialiaze the mode
613 * independent and dependent scratch page to the default settings.
615 static void asd_init_cseq_scratch(struct asd_ha_struct *asd_ha)
617 asd_init_cseq_mip(asd_ha);
618 asd_init_cseq_mdp(asd_ha);
622 * asd_init_lseq_mip -- initialize LSEQ Mode independent pages 0-3
623 * @asd_ha: pointer to host adapter structure
625 static void asd_init_lseq_mip(struct asd_ha_struct *asd_ha, u8 lseq)
629 /* LSEQ Mode independent page 0 setup. */
630 asd_write_reg_word(asd_ha, LmSEQ_Q_TGTXFR_HEAD(lseq), 0xFFFF);
631 asd_write_reg_word(asd_ha, LmSEQ_Q_TGTXFR_TAIL(lseq), 0xFFFF);
632 asd_write_reg_byte(asd_ha, LmSEQ_LINK_NUMBER(lseq), lseq);
633 asd_write_reg_byte(asd_ha, LmSEQ_SCRATCH_FLAGS(lseq),
634 ASD_NOTIFY_ENABLE_SPINUP);
635 asd_write_reg_dword(asd_ha, LmSEQ_CONNECTION_STATE(lseq),0x08000000);
636 asd_write_reg_word(asd_ha, LmSEQ_CONCTL(lseq), 0);
637 asd_write_reg_byte(asd_ha, LmSEQ_CONSTAT(lseq), 0);
638 asd_write_reg_byte(asd_ha, LmSEQ_CONNECTION_MODES(lseq), 0);
639 asd_write_reg_word(asd_ha, LmSEQ_REG1_ISR(lseq), 0);
640 asd_write_reg_word(asd_ha, LmSEQ_REG2_ISR(lseq), 0);
641 asd_write_reg_word(asd_ha, LmSEQ_REG3_ISR(lseq), 0);
642 asd_write_reg_dword(asd_ha, LmSEQ_REG0_ISR(lseq), 0);
643 asd_write_reg_dword(asd_ha, LmSEQ_REG0_ISR(lseq)+4, 0);
645 /* LSEQ Mode independent page 1 setup. */
646 asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR0(lseq), 0xFFFF);
647 asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR1(lseq), 0xFFFF);
648 asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR2(lseq), 0xFFFF);
649 asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR3(lseq), 0xFFFF);
650 asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_OPCODE0(lseq), 0);
651 asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_OPCODE1(lseq), 0);
652 asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_OPCODE2(lseq), 0);
653 asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_OPCODE3(lseq), 0);
654 asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_HEAD(lseq), 0);
655 asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_TAIL(lseq), 0);
656 asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_BUF_AVAIL(lseq), 0);
657 asd_write_reg_dword(asd_ha, LmSEQ_TIMEOUT_CONST(lseq), 0);
658 asd_write_reg_word(asd_ha, LmSEQ_ISR_SAVE_SINDEX(lseq), 0);
659 asd_write_reg_word(asd_ha, LmSEQ_ISR_SAVE_DINDEX(lseq), 0);
661 /* LSEQ Mode Independent page 2 setup. */
662 asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR0(lseq), 0xFFFF);
663 asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR1(lseq), 0xFFFF);
664 asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR2(lseq), 0xFFFF);
665 asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR3(lseq), 0xFFFF);
666 asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD0(lseq), 0);
667 asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD1(lseq), 0);
668 asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD2(lseq), 0);
669 asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD3(lseq), 0);
670 asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_HEAD(lseq), 0);
671 asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_TAIL(lseq), 0);
672 asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_BUFS_AVAIL(lseq), 0);
673 for (i = 0; i < 12; i += 4)
674 asd_write_reg_dword(asd_ha, LmSEQ_ATA_SCR_REGS(lseq) + i, 0);
676 /* LSEQ Mode Independent page 3 setup. */
678 /* Device present timer timeout */
679 asd_write_reg_dword(asd_ha, LmSEQ_DEV_PRES_TMR_TOUT_CONST(lseq),
680 ASD_DEV_PRESENT_TIMEOUT);
682 /* SATA interlock timer disabled */
683 asd_write_reg_dword(asd_ha, LmSEQ_SATA_INTERLOCK_TIMEOUT(lseq),
684 ASD_SATA_INTERLOCK_TIMEOUT);
686 /* STP shutdown timer timeout constant, IGNORED by the sequencer,
688 asd_write_reg_dword(asd_ha, LmSEQ_STP_SHUTDOWN_TIMEOUT(lseq),
689 ASD_STP_SHUTDOWN_TIMEOUT);
691 asd_write_reg_dword(asd_ha, LmSEQ_SRST_ASSERT_TIMEOUT(lseq),
692 ASD_SRST_ASSERT_TIMEOUT);
694 asd_write_reg_dword(asd_ha, LmSEQ_RCV_FIS_TIMEOUT(lseq),
695 ASD_RCV_FIS_TIMEOUT);
697 asd_write_reg_dword(asd_ha, LmSEQ_ONE_MILLISEC_TIMEOUT(lseq),
698 ASD_ONE_MILLISEC_TIMEOUT);
701 asd_write_reg_dword(asd_ha, LmSEQ_TEN_MS_COMINIT_TIMEOUT(lseq),
702 ASD_TEN_MILLISEC_TIMEOUT);
704 asd_write_reg_dword(asd_ha, LmSEQ_SMP_RCV_TIMEOUT(lseq),
705 ASD_SMP_RCV_TIMEOUT);
709 * asd_init_lseq_mdp -- initialize LSEQ mode dependent pages.
710 * @asd_ha: pointer to host adapter structure
712 static void asd_init_lseq_mdp(struct asd_ha_struct *asd_ha, int lseq)
719 mode2_task, /* mode 2 */
721 0xFFFF, /* mode 4/5 */
722 0xFFFF, /* mode 4/5 */
726 * Mode 0,1,2 and 4/5 have common field on page 0 for the first
729 for (i = 0; i < 3; i++) {
730 moffs = i * LSEQ_MODE_SCRATCH_SIZE;
731 asd_write_reg_word(asd_ha, LmSEQ_RET_ADDR(lseq)+moffs,
733 asd_write_reg_word(asd_ha, LmSEQ_REG0_MODE(lseq)+moffs, 0);
734 asd_write_reg_word(asd_ha, LmSEQ_MODE_FLAGS(lseq)+moffs, 0);
735 asd_write_reg_word(asd_ha, LmSEQ_RET_ADDR2(lseq)+moffs,0xFFFF);
736 asd_write_reg_word(asd_ha, LmSEQ_RET_ADDR1(lseq)+moffs,0xFFFF);
737 asd_write_reg_byte(asd_ha, LmSEQ_OPCODE_TO_CSEQ(lseq)+moffs,0);
738 asd_write_reg_word(asd_ha, LmSEQ_DATA_TO_CSEQ(lseq)+moffs,0);
741 * Mode 5 page 0 overlaps the same scratch page with Mode 0 page 3.
743 asd_write_reg_word(asd_ha,
744 LmSEQ_RET_ADDR(lseq)+LSEQ_MODE5_PAGE0_OFFSET,
746 asd_write_reg_word(asd_ha,
747 LmSEQ_REG0_MODE(lseq)+LSEQ_MODE5_PAGE0_OFFSET,0);
748 asd_write_reg_word(asd_ha,
749 LmSEQ_MODE_FLAGS(lseq)+LSEQ_MODE5_PAGE0_OFFSET, 0);
750 asd_write_reg_word(asd_ha,
751 LmSEQ_RET_ADDR2(lseq)+LSEQ_MODE5_PAGE0_OFFSET,0xFFFF);
752 asd_write_reg_word(asd_ha,
753 LmSEQ_RET_ADDR1(lseq)+LSEQ_MODE5_PAGE0_OFFSET,0xFFFF);
754 asd_write_reg_byte(asd_ha,
755 LmSEQ_OPCODE_TO_CSEQ(lseq)+LSEQ_MODE5_PAGE0_OFFSET,0);
756 asd_write_reg_word(asd_ha,
757 LmSEQ_DATA_TO_CSEQ(lseq)+LSEQ_MODE5_PAGE0_OFFSET, 0);
759 /* LSEQ Mode dependent 0, page 0 setup. */
760 asd_write_reg_word(asd_ha, LmSEQ_FIRST_INV_DDB_SITE(lseq),
761 (u16)asd_ha->hw_prof.max_ddbs);
762 asd_write_reg_word(asd_ha, LmSEQ_EMPTY_TRANS_CTX(lseq), 0);
763 asd_write_reg_word(asd_ha, LmSEQ_RESP_LEN(lseq), 0);
764 asd_write_reg_word(asd_ha, LmSEQ_FIRST_INV_SCB_SITE(lseq),
765 (u16)last_scb_site_no+1);
766 asd_write_reg_word(asd_ha, LmSEQ_INTEN_SAVE(lseq),
767 (u16) ((LmM0INTEN_MASK & 0xFFFF0000) >> 16));
768 asd_write_reg_word(asd_ha, LmSEQ_INTEN_SAVE(lseq) + 2,
769 (u16) LmM0INTEN_MASK & 0xFFFF);
770 asd_write_reg_byte(asd_ha, LmSEQ_LINK_RST_FRM_LEN(lseq), 0);
771 asd_write_reg_byte(asd_ha, LmSEQ_LINK_RST_PROTOCOL(lseq), 0);
772 asd_write_reg_byte(asd_ha, LmSEQ_RESP_STATUS(lseq), 0);
773 asd_write_reg_byte(asd_ha, LmSEQ_LAST_LOADED_SGE(lseq), 0);
774 asd_write_reg_word(asd_ha, LmSEQ_SAVE_SCBPTR(lseq), 0);
776 /* LSEQ mode dependent, mode 1, page 0 setup. */
777 asd_write_reg_word(asd_ha, LmSEQ_Q_XMIT_HEAD(lseq), 0xFFFF);
778 asd_write_reg_word(asd_ha, LmSEQ_M1_EMPTY_TRANS_CTX(lseq), 0);
779 asd_write_reg_word(asd_ha, LmSEQ_INI_CONN_TAG(lseq), 0);
780 asd_write_reg_byte(asd_ha, LmSEQ_FAILED_OPEN_STATUS(lseq), 0);
781 asd_write_reg_byte(asd_ha, LmSEQ_XMIT_REQUEST_TYPE(lseq), 0);
782 asd_write_reg_byte(asd_ha, LmSEQ_M1_RESP_STATUS(lseq), 0);
783 asd_write_reg_byte(asd_ha, LmSEQ_M1_LAST_LOADED_SGE(lseq), 0);
784 asd_write_reg_word(asd_ha, LmSEQ_M1_SAVE_SCBPTR(lseq), 0);
786 /* LSEQ Mode dependent mode 2, page 0 setup */
787 asd_write_reg_word(asd_ha, LmSEQ_PORT_COUNTER(lseq), 0);
788 asd_write_reg_word(asd_ha, LmSEQ_PM_TABLE_PTR(lseq), 0);
789 asd_write_reg_word(asd_ha, LmSEQ_SATA_INTERLOCK_TMR_SAVE(lseq), 0);
790 asd_write_reg_word(asd_ha, LmSEQ_IP_BITL(lseq), 0);
791 asd_write_reg_word(asd_ha, LmSEQ_COPY_SMP_CONN_TAG(lseq), 0);
792 asd_write_reg_byte(asd_ha, LmSEQ_P0M2_OFFS1AH(lseq), 0);
794 /* LSEQ Mode dependent, mode 4/5, page 0 setup. */
795 asd_write_reg_byte(asd_ha, LmSEQ_SAVED_OOB_STATUS(lseq), 0);
796 asd_write_reg_byte(asd_ha, LmSEQ_SAVED_OOB_MODE(lseq), 0);
797 asd_write_reg_word(asd_ha, LmSEQ_Q_LINK_HEAD(lseq), 0xFFFF);
798 asd_write_reg_byte(asd_ha, LmSEQ_LINK_RST_ERR(lseq), 0);
799 asd_write_reg_byte(asd_ha, LmSEQ_SAVED_OOB_SIGNALS(lseq), 0);
800 asd_write_reg_byte(asd_ha, LmSEQ_SAS_RESET_MODE(lseq), 0);
801 asd_write_reg_byte(asd_ha, LmSEQ_LINK_RESET_RETRY_COUNT(lseq), 0);
802 asd_write_reg_byte(asd_ha, LmSEQ_NUM_LINK_RESET_RETRIES(lseq), 0);
803 asd_write_reg_word(asd_ha, LmSEQ_OOB_INT_ENABLES(lseq), 0);
805 * Set the desired interval between transmissions of the NOTIFY
806 * (ENABLE SPINUP) primitive. Must be initilized to val - 1.
808 asd_write_reg_word(asd_ha, LmSEQ_NOTIFY_TIMER_TIMEOUT(lseq),
809 ASD_NOTIFY_TIMEOUT - 1);
810 /* No delay for the first NOTIFY to be sent to the attached target. */
811 asd_write_reg_word(asd_ha, LmSEQ_NOTIFY_TIMER_DOWN_COUNT(lseq),
812 ASD_NOTIFY_DOWN_COUNT);
813 asd_write_reg_word(asd_ha, LmSEQ_NOTIFY_TIMER_INITIAL_COUNT(lseq),
814 ASD_NOTIFY_DOWN_COUNT);
816 /* LSEQ Mode dependent, mode 0 and 1, page 1 setup. */
817 for (i = 0; i < 2; i++) {
819 /* Start from Page 1 of Mode 0 and 1. */
820 moffs = LSEQ_PAGE_SIZE + i*LSEQ_MODE_SCRATCH_SIZE;
821 /* All the fields of page 1 can be intialized to 0. */
822 for (j = 0; j < LSEQ_PAGE_SIZE; j += 4)
823 asd_write_reg_dword(asd_ha, LmSCRATCH(lseq)+moffs+j,0);
826 /* LSEQ Mode dependent, mode 2, page 1 setup. */
827 asd_write_reg_dword(asd_ha, LmSEQ_INVALID_DWORD_COUNT(lseq), 0);
828 asd_write_reg_dword(asd_ha, LmSEQ_DISPARITY_ERROR_COUNT(lseq), 0);
829 asd_write_reg_dword(asd_ha, LmSEQ_LOSS_OF_SYNC_COUNT(lseq), 0);
831 /* LSEQ Mode dependent, mode 4/5, page 1. */
832 for (i = 0; i < LSEQ_PAGE_SIZE; i+=4)
833 asd_write_reg_dword(asd_ha, LmSEQ_FRAME_TYPE_MASK(lseq)+i, 0);
834 asd_write_reg_byte(asd_ha, LmSEQ_FRAME_TYPE_MASK(lseq), 0xFF);
835 asd_write_reg_byte(asd_ha, LmSEQ_HASHED_DEST_ADDR_MASK(lseq), 0xFF);
836 asd_write_reg_byte(asd_ha, LmSEQ_HASHED_DEST_ADDR_MASK(lseq)+1,0xFF);
837 asd_write_reg_byte(asd_ha, LmSEQ_HASHED_DEST_ADDR_MASK(lseq)+2,0xFF);
838 asd_write_reg_byte(asd_ha, LmSEQ_HASHED_SRC_ADDR_MASK(lseq), 0xFF);
839 asd_write_reg_byte(asd_ha, LmSEQ_HASHED_SRC_ADDR_MASK(lseq)+1, 0xFF);
840 asd_write_reg_byte(asd_ha, LmSEQ_HASHED_SRC_ADDR_MASK(lseq)+2, 0xFF);
841 asd_write_reg_dword(asd_ha, LmSEQ_DATA_OFFSET(lseq), 0xFFFFFFFF);
843 /* LSEQ Mode dependent, mode 0, page 2 setup. */
844 asd_write_reg_dword(asd_ha, LmSEQ_SMP_RCV_TIMER_TERM_TS(lseq), 0);
845 asd_write_reg_byte(asd_ha, LmSEQ_DEVICE_BITS(lseq), 0);
846 asd_write_reg_word(asd_ha, LmSEQ_SDB_DDB(lseq), 0);
847 asd_write_reg_byte(asd_ha, LmSEQ_SDB_NUM_TAGS(lseq), 0);
848 asd_write_reg_byte(asd_ha, LmSEQ_SDB_CURR_TAG(lseq), 0);
850 /* LSEQ Mode Dependent 1, page 2 setup. */
851 asd_write_reg_dword(asd_ha, LmSEQ_TX_ID_ADDR_FRAME(lseq), 0);
852 asd_write_reg_dword(asd_ha, LmSEQ_TX_ID_ADDR_FRAME(lseq)+4, 0);
853 asd_write_reg_dword(asd_ha, LmSEQ_OPEN_TIMER_TERM_TS(lseq), 0);
854 asd_write_reg_dword(asd_ha, LmSEQ_SRST_AS_TIMER_TERM_TS(lseq), 0);
855 asd_write_reg_dword(asd_ha, LmSEQ_LAST_LOADED_SG_EL(lseq), 0);
857 /* LSEQ Mode Dependent 2, page 2 setup. */
858 /* The LmSEQ_STP_SHUTDOWN_TIMER_TERM_TS is IGNORED by the sequencer,
860 asd_write_reg_dword(asd_ha, LmSEQ_STP_SHUTDOWN_TIMER_TERM_TS(lseq),0);
861 asd_write_reg_dword(asd_ha, LmSEQ_CLOSE_TIMER_TERM_TS(lseq), 0);
862 asd_write_reg_dword(asd_ha, LmSEQ_BREAK_TIMER_TERM_TS(lseq), 0);
863 asd_write_reg_dword(asd_ha, LmSEQ_DWS_RESET_TIMER_TERM_TS(lseq), 0);
864 asd_write_reg_dword(asd_ha,LmSEQ_SATA_INTERLOCK_TIMER_TERM_TS(lseq),0);
865 asd_write_reg_dword(asd_ha, LmSEQ_MCTL_TIMER_TERM_TS(lseq), 0);
867 /* LSEQ Mode Dependent 4/5, page 2 setup. */
868 asd_write_reg_dword(asd_ha, LmSEQ_COMINIT_TIMER_TERM_TS(lseq), 0);
869 asd_write_reg_dword(asd_ha, LmSEQ_RCV_ID_TIMER_TERM_TS(lseq), 0);
870 asd_write_reg_dword(asd_ha, LmSEQ_RCV_FIS_TIMER_TERM_TS(lseq), 0);
871 asd_write_reg_dword(asd_ha, LmSEQ_DEV_PRES_TIMER_TERM_TS(lseq), 0);
875 * asd_init_lseq_scratch -- setup and init link sequencers
876 * @asd_ha: pointer to host adapter struct
878 static void asd_init_lseq_scratch(struct asd_ha_struct *asd_ha)
883 lseq_mask = asd_ha->hw_prof.enabled_phys;
884 for_each_sequencer(lseq_mask, lseq_mask, lseq) {
885 asd_init_lseq_mip(asd_ha, lseq);
886 asd_init_lseq_mdp(asd_ha, lseq);
891 * asd_init_scb_sites -- initialize sequencer SCB sites (memory).
892 * @asd_ha: pointer to host adapter structure
894 * This should be done before initializing common CSEQ and LSEQ
895 * scratch since those areas depend on some computed values here,
896 * last_scb_site_no, etc.
898 static void asd_init_scb_sites(struct asd_ha_struct *asd_ha)
903 for (site_no = asd_ha->hw_prof.max_scbs-1;
908 /* Initialize all fields in the SCB site to 0. */
909 for (i = 0; i < ASD_SCB_SIZE; i += 4)
910 asd_scbsite_write_dword(asd_ha, site_no, i, 0);
912 /* Initialize SCB Site Opcode field to invalid. */
913 asd_scbsite_write_byte(asd_ha, site_no,
914 offsetof(struct scb_header, opcode),
917 /* Initialize SCB Site Flags field to mean a response
918 * frame has been received. This means inadvertent
919 * frames received to be dropped. */
920 asd_scbsite_write_byte(asd_ha, site_no, 0x49, 0x01);
922 /* Workaround needed by SEQ to fix a SATA issue is to exclude
923 * certain SCB sites from the free list. */
924 if (!SCB_SITE_VALID(site_no))
927 if (last_scb_site_no == 0)
928 last_scb_site_no = site_no;
930 /* For every SCB site, we need to initialize the
931 * following fields: Q_NEXT, SCB_OPCODE, SCB_FLAGS,
932 * and SG Element Flag. */
934 /* Q_NEXT field of the last SCB is invalidated. */
935 asd_scbsite_write_word(asd_ha, site_no, 0, first_scb_site_no);
937 first_scb_site_no = site_no;
940 asd_ha->hw_prof.max_scbs = max_scbs;
941 ASD_DPRINTK("max_scbs:%d\n", asd_ha->hw_prof.max_scbs);
942 ASD_DPRINTK("first_scb_site_no:0x%x\n", first_scb_site_no);
943 ASD_DPRINTK("last_scb_site_no:0x%x\n", last_scb_site_no);
947 * asd_init_cseq_cio - initialize CSEQ CIO registers
948 * @asd_ha: pointer to host adapter structure
950 static void asd_init_cseq_cio(struct asd_ha_struct *asd_ha)
954 asd_write_reg_byte(asd_ha, CSEQCOMINTEN, 0);
955 asd_write_reg_byte(asd_ha, CSEQDLCTL, ASD_DL_SIZE_BITS);
956 asd_write_reg_byte(asd_ha, CSEQDLOFFS, 0);
957 asd_write_reg_byte(asd_ha, CSEQDLOFFS+1, 0);
958 asd_ha->seq.scbpro = 0;
959 asd_write_reg_dword(asd_ha, SCBPRO, 0);
960 asd_write_reg_dword(asd_ha, CSEQCON, 0);
962 /* Intialize CSEQ Mode 11 Interrupt Vectors.
963 * The addresses are 16 bit wide and in dword units.
964 * The values of their macros are in byte units.
965 * Thus we have to divide by 4. */
966 asd_write_reg_word(asd_ha, CM11INTVEC0, cseq_vecs[0]);
967 asd_write_reg_word(asd_ha, CM11INTVEC1, cseq_vecs[1]);
968 asd_write_reg_word(asd_ha, CM11INTVEC2, cseq_vecs[2]);
970 /* Enable ARP2HALTC (ARP2 Halted from Halt Code Write). */
971 asd_write_reg_byte(asd_ha, CARP2INTEN, EN_ARP2HALTC);
973 /* Initialize CSEQ Scratch Page to 0x04. */
974 asd_write_reg_byte(asd_ha, CSCRATCHPAGE, 0x04);
976 /* Initialize CSEQ Mode[0-8] Dependent registers. */
977 /* Initialize Scratch Page to 0. */
978 for (i = 0; i < 9; i++)
979 asd_write_reg_byte(asd_ha, CMnSCRATCHPAGE(i), 0);
981 /* Reset the ARP2 Program Count. */
982 asd_write_reg_word(asd_ha, CPRGMCNT, cseq_idle_loop);
984 for (i = 0; i < 8; i++) {
985 /* Intialize Mode n Link m Interrupt Enable. */
986 asd_write_reg_dword(asd_ha, CMnINTEN(i), EN_CMnRSPMBXF);
987 /* Initialize Mode n Request Mailbox. */
988 asd_write_reg_dword(asd_ha, CMnREQMBX(i), 0);
993 * asd_init_lseq_cio -- initialize LmSEQ CIO registers
994 * @asd_ha: pointer to host adapter structure
996 static void asd_init_lseq_cio(struct asd_ha_struct *asd_ha, int lseq)
1001 /* Enable ARP2HALTC (ARP2 Halted from Halt Code Write). */
1002 asd_write_reg_dword(asd_ha, LmARP2INTEN(lseq), EN_ARP2HALTC);
1004 asd_write_reg_byte(asd_ha, LmSCRATCHPAGE(lseq), 0);
1006 /* Initialize Mode 0,1, and 2 SCRATCHPAGE to 0. */
1007 for (i = 0; i < 3; i++)
1008 asd_write_reg_byte(asd_ha, LmMnSCRATCHPAGE(lseq, i), 0);
1010 /* Initialize Mode 5 SCRATCHPAGE to 0. */
1011 asd_write_reg_byte(asd_ha, LmMnSCRATCHPAGE(lseq, 5), 0);
1013 asd_write_reg_dword(asd_ha, LmRSPMBX(lseq), 0);
1014 /* Initialize Mode 0,1,2 and 5 Interrupt Enable and
1015 * Interrupt registers. */
1016 asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 0), LmM0INTEN_MASK);
1017 asd_write_reg_dword(asd_ha, LmMnINT(lseq, 0), 0xFFFFFFFF);
1019 asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 1), LmM1INTEN_MASK);
1020 asd_write_reg_dword(asd_ha, LmMnINT(lseq, 1), 0xFFFFFFFF);
1022 asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 2), LmM2INTEN_MASK);
1023 asd_write_reg_dword(asd_ha, LmMnINT(lseq, 2), 0xFFFFFFFF);
1025 asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 5), LmM5INTEN_MASK);
1026 asd_write_reg_dword(asd_ha, LmMnINT(lseq, 5), 0xFFFFFFFF);
1028 /* Enable HW Timer status. */
1029 asd_write_reg_byte(asd_ha, LmHWTSTATEN(lseq), LmHWTSTATEN_MASK);
1031 /* Enable Primitive Status 0 and 1. */
1032 asd_write_reg_dword(asd_ha, LmPRIMSTAT0EN(lseq), LmPRIMSTAT0EN_MASK);
1033 asd_write_reg_dword(asd_ha, LmPRIMSTAT1EN(lseq), LmPRIMSTAT1EN_MASK);
1035 /* Enable Frame Error. */
1036 asd_write_reg_dword(asd_ha, LmFRMERREN(lseq), LmFRMERREN_MASK);
1037 asd_write_reg_byte(asd_ha, LmMnHOLDLVL(lseq, 0), 0x50);
1039 /* Initialize Mode 0 Transfer Level to 512. */
1040 asd_write_reg_byte(asd_ha, LmMnXFRLVL(lseq, 0), LmMnXFRLVL_512);
1041 /* Initialize Mode 1 Transfer Level to 256. */
1042 asd_write_reg_byte(asd_ha, LmMnXFRLVL(lseq, 1), LmMnXFRLVL_256);
1044 /* Initialize Program Count. */
1045 asd_write_reg_word(asd_ha, LmPRGMCNT(lseq), lseq_idle_loop);
1047 /* Enable Blind SG Move. */
1048 asd_write_reg_dword(asd_ha, LmMODECTL(lseq), LmBLIND48);
1049 asd_write_reg_word(asd_ha, LmM3SATATIMER(lseq),
1050 ASD_SATA_INTERLOCK_TIMEOUT);
1052 (void) asd_read_reg_dword(asd_ha, LmREQMBX(lseq));
1054 /* Clear Primitive Status 0 and 1. */
1055 asd_write_reg_dword(asd_ha, LmPRMSTAT0(lseq), 0xFFFFFFFF);
1056 asd_write_reg_dword(asd_ha, LmPRMSTAT1(lseq), 0xFFFFFFFF);
1058 /* Clear HW Timer status. */
1059 asd_write_reg_byte(asd_ha, LmHWTSTAT(lseq), 0xFF);
1061 /* Clear DMA Errors for Mode 0 and 1. */
1062 asd_write_reg_byte(asd_ha, LmMnDMAERRS(lseq, 0), 0xFF);
1063 asd_write_reg_byte(asd_ha, LmMnDMAERRS(lseq, 1), 0xFF);
1065 /* Clear SG DMA Errors for Mode 0 and 1. */
1066 asd_write_reg_byte(asd_ha, LmMnSGDMAERRS(lseq, 0), 0xFF);
1067 asd_write_reg_byte(asd_ha, LmMnSGDMAERRS(lseq, 1), 0xFF);
1069 /* Clear Mode 0 Buffer Parity Error. */
1070 asd_write_reg_byte(asd_ha, LmMnBUFSTAT(lseq, 0), LmMnBUFPERR);
1072 /* Clear Mode 0 Frame Error register. */
1073 asd_write_reg_dword(asd_ha, LmMnFRMERR(lseq, 0), 0xFFFFFFFF);
1075 /* Reset LSEQ external interrupt arbiter. */
1076 asd_write_reg_byte(asd_ha, LmARP2INTCTL(lseq), RSTINTCTL);
1078 /* Set the Phy SAS for the LmSEQ WWN. */
1079 sas_addr = asd_ha->phys[lseq].phy_desc->sas_addr;
1080 for (i = 0; i < SAS_ADDR_SIZE; i++)
1081 asd_write_reg_byte(asd_ha, LmWWN(lseq) + i, sas_addr[i]);
1083 /* Set the Transmit Size to 1024 bytes, 0 = 256 Dwords. */
1084 asd_write_reg_byte(asd_ha, LmMnXMTSIZE(lseq, 1), 0);
1086 /* Set the Bus Inactivity Time Limit Timer. */
1087 asd_write_reg_word(asd_ha, LmBITL_TIMER(lseq), 9);
1089 /* Enable SATA Port Multiplier. */
1090 asd_write_reg_byte(asd_ha, LmMnSATAFS(lseq, 1), 0x80);
1092 /* Initialize Interrupt Vector[0-10] address in Mode 3.
1093 * See the comment on CSEQ_INT_* */
1094 asd_write_reg_word(asd_ha, LmM3INTVEC0(lseq), lseq_vecs[0]);
1095 asd_write_reg_word(asd_ha, LmM3INTVEC1(lseq), lseq_vecs[1]);
1096 asd_write_reg_word(asd_ha, LmM3INTVEC2(lseq), lseq_vecs[2]);
1097 asd_write_reg_word(asd_ha, LmM3INTVEC3(lseq), lseq_vecs[3]);
1098 asd_write_reg_word(asd_ha, LmM3INTVEC4(lseq), lseq_vecs[4]);
1099 asd_write_reg_word(asd_ha, LmM3INTVEC5(lseq), lseq_vecs[5]);
1100 asd_write_reg_word(asd_ha, LmM3INTVEC6(lseq), lseq_vecs[6]);
1101 asd_write_reg_word(asd_ha, LmM3INTVEC7(lseq), lseq_vecs[7]);
1102 asd_write_reg_word(asd_ha, LmM3INTVEC8(lseq), lseq_vecs[8]);
1103 asd_write_reg_word(asd_ha, LmM3INTVEC9(lseq), lseq_vecs[9]);
1104 asd_write_reg_word(asd_ha, LmM3INTVEC10(lseq), lseq_vecs[10]);
1106 * Program the Link LED control, applicable only for
1107 * Chip Rev. B or later.
1109 asd_write_reg_dword(asd_ha, LmCONTROL(lseq),
1110 (LEDTIMER | LEDMODE_TXRX | LEDTIMERS_100ms));
1112 /* Set the Align Rate for SAS and STP mode. */
1113 asd_write_reg_byte(asd_ha, LmM1SASALIGN(lseq), SAS_ALIGN_DEFAULT);
1114 asd_write_reg_byte(asd_ha, LmM1STPALIGN(lseq), STP_ALIGN_DEFAULT);
1119 * asd_post_init_cseq -- clear CSEQ Mode n Int. status and Response mailbox
1120 * @asd_ha: pointer to host adapter struct
1122 static void asd_post_init_cseq(struct asd_ha_struct *asd_ha)
1126 for (i = 0; i < 8; i++)
1127 asd_write_reg_dword(asd_ha, CMnINT(i), 0xFFFFFFFF);
1128 for (i = 0; i < 8; i++)
1129 asd_read_reg_dword(asd_ha, CMnRSPMBX(i));
1130 /* Reset the external interrupt arbiter. */
1131 asd_write_reg_byte(asd_ha, CARP2INTCTL, RSTINTCTL);
1135 * asd_init_ddb_0 -- initialize DDB 0
1136 * @asd_ha: pointer to host adapter structure
1138 * Initialize DDB site 0 which is used internally by the sequencer.
1140 static void asd_init_ddb_0(struct asd_ha_struct *asd_ha)
1144 /* Zero out the DDB explicitly */
1145 for (i = 0; i < sizeof(struct asd_ddb_seq_shared); i+=4)
1146 asd_ddbsite_write_dword(asd_ha, 0, i, 0);
1148 asd_ddbsite_write_word(asd_ha, 0,
1149 offsetof(struct asd_ddb_seq_shared, q_free_ddb_head), 0);
1150 asd_ddbsite_write_word(asd_ha, 0,
1151 offsetof(struct asd_ddb_seq_shared, q_free_ddb_tail),
1152 asd_ha->hw_prof.max_ddbs-1);
1153 asd_ddbsite_write_word(asd_ha, 0,
1154 offsetof(struct asd_ddb_seq_shared, q_free_ddb_cnt), 0);
1155 asd_ddbsite_write_word(asd_ha, 0,
1156 offsetof(struct asd_ddb_seq_shared, q_used_ddb_head), 0xFFFF);
1157 asd_ddbsite_write_word(asd_ha, 0,
1158 offsetof(struct asd_ddb_seq_shared, q_used_ddb_tail), 0xFFFF);
1159 asd_ddbsite_write_word(asd_ha, 0,
1160 offsetof(struct asd_ddb_seq_shared, shared_mem_lock), 0);
1161 asd_ddbsite_write_word(asd_ha, 0,
1162 offsetof(struct asd_ddb_seq_shared, smp_conn_tag), 0);
1163 asd_ddbsite_write_word(asd_ha, 0,
1164 offsetof(struct asd_ddb_seq_shared, est_nexus_buf_cnt), 0);
1165 asd_ddbsite_write_word(asd_ha, 0,
1166 offsetof(struct asd_ddb_seq_shared, est_nexus_buf_thresh),
1167 asd_ha->hw_prof.num_phys * 2);
1168 asd_ddbsite_write_byte(asd_ha, 0,
1169 offsetof(struct asd_ddb_seq_shared, settable_max_contexts),0);
1170 asd_ddbsite_write_byte(asd_ha, 0,
1171 offsetof(struct asd_ddb_seq_shared, conn_not_active), 0xFF);
1172 asd_ddbsite_write_byte(asd_ha, 0,
1173 offsetof(struct asd_ddb_seq_shared, phy_is_up), 0x00);
1174 /* DDB 0 is reserved */
1175 set_bit(0, asd_ha->hw_prof.ddb_bitmap);
1178 static void asd_seq_init_ddb_sites(struct asd_ha_struct *asd_ha)
1181 unsigned int ddb_site;
1183 for (ddb_site = 0 ; ddb_site < ASD_MAX_DDBS; ddb_site++)
1184 for (i = 0; i < sizeof(struct asd_ddb_ssp_smp_target_port); i+= 4)
1185 asd_ddbsite_write_dword(asd_ha, ddb_site, i, 0);
1189 * asd_seq_setup_seqs -- setup and initialize central and link sequencers
1190 * @asd_ha: pointer to host adapter structure
1192 static void asd_seq_setup_seqs(struct asd_ha_struct *asd_ha)
1197 /* Initialize DDB sites */
1198 asd_seq_init_ddb_sites(asd_ha);
1200 /* Initialize SCB sites. Done first to compute some values which
1201 * the rest of the init code depends on. */
1202 asd_init_scb_sites(asd_ha);
1204 /* Initialize CSEQ Scratch RAM registers. */
1205 asd_init_cseq_scratch(asd_ha);
1207 /* Initialize LmSEQ Scratch RAM registers. */
1208 asd_init_lseq_scratch(asd_ha);
1210 /* Initialize CSEQ CIO registers. */
1211 asd_init_cseq_cio(asd_ha);
1213 asd_init_ddb_0(asd_ha);
1215 /* Initialize LmSEQ CIO registers. */
1216 lseq_mask = asd_ha->hw_prof.enabled_phys;
1217 for_each_sequencer(lseq_mask, lseq_mask, lseq)
1218 asd_init_lseq_cio(asd_ha, lseq);
1219 asd_post_init_cseq(asd_ha);
1224 * asd_seq_start_cseq -- start the central sequencer, CSEQ
1225 * @asd_ha: pointer to host adapter structure
1227 static int asd_seq_start_cseq(struct asd_ha_struct *asd_ha)
1229 /* Reset the ARP2 instruction to location zero. */
1230 asd_write_reg_word(asd_ha, CPRGMCNT, cseq_idle_loop);
1232 /* Unpause the CSEQ */
1233 return asd_unpause_cseq(asd_ha);
1237 * asd_seq_start_lseq -- start a link sequencer
1238 * @asd_ha: pointer to host adapter structure
1239 * @lseq: the link sequencer of interest
1241 static int asd_seq_start_lseq(struct asd_ha_struct *asd_ha, int lseq)
1243 /* Reset the ARP2 instruction to location zero. */
1244 asd_write_reg_word(asd_ha, LmPRGMCNT(lseq), lseq_idle_loop);
1246 /* Unpause the LmSEQ */
1247 return asd_seq_unpause_lseq(asd_ha, lseq);
1250 int asd_release_firmware(void)
1253 release_firmware(sequencer_fw);
1257 static int asd_request_firmware(struct asd_ha_struct *asd_ha)
1260 struct sequencer_file_header header, *hdr_ptr;
1262 u16 *ptr_cseq_vecs, *ptr_lseq_vecs;
1265 /* already loaded */
1268 err = request_firmware(&sequencer_fw,
1269 SAS_RAZOR_SEQUENCER_FW_FILE,
1270 &asd_ha->pcidev->dev);
1274 hdr_ptr = (struct sequencer_file_header *)sequencer_fw->data;
1276 header.csum = le32_to_cpu(hdr_ptr->csum);
1277 header.major = le32_to_cpu(hdr_ptr->major);
1278 header.minor = le32_to_cpu(hdr_ptr->minor);
1279 sequencer_version = hdr_ptr->version;
1280 header.cseq_table_offset = le32_to_cpu(hdr_ptr->cseq_table_offset);
1281 header.cseq_table_size = le32_to_cpu(hdr_ptr->cseq_table_size);
1282 header.lseq_table_offset = le32_to_cpu(hdr_ptr->lseq_table_offset);
1283 header.lseq_table_size = le32_to_cpu(hdr_ptr->lseq_table_size);
1284 header.cseq_code_offset = le32_to_cpu(hdr_ptr->cseq_code_offset);
1285 header.cseq_code_size = le32_to_cpu(hdr_ptr->cseq_code_size);
1286 header.lseq_code_offset = le32_to_cpu(hdr_ptr->lseq_code_offset);
1287 header.lseq_code_size = le32_to_cpu(hdr_ptr->lseq_code_size);
1288 header.mode2_task = le16_to_cpu(hdr_ptr->mode2_task);
1289 header.cseq_idle_loop = le16_to_cpu(hdr_ptr->cseq_idle_loop);
1290 header.lseq_idle_loop = le16_to_cpu(hdr_ptr->lseq_idle_loop);
1292 for (i = sizeof(header.csum); i < sequencer_fw->size; i++)
1293 csum += sequencer_fw->data[i];
1295 if (csum != header.csum) {
1296 asd_printk("Firmware file checksum mismatch\n");
1300 if (header.cseq_table_size != CSEQ_NUM_VECS ||
1301 header.lseq_table_size != LSEQ_NUM_VECS) {
1302 asd_printk("Firmware file table size mismatch\n");
1306 ptr_cseq_vecs = (u16 *)&sequencer_fw->data[header.cseq_table_offset];
1307 ptr_lseq_vecs = (u16 *)&sequencer_fw->data[header.lseq_table_offset];
1308 mode2_task = header.mode2_task;
1309 cseq_idle_loop = header.cseq_idle_loop;
1310 lseq_idle_loop = header.lseq_idle_loop;
1312 for (i = 0; i < CSEQ_NUM_VECS; i++)
1313 cseq_vecs[i] = le16_to_cpu(ptr_cseq_vecs[i]);
1315 for (i = 0; i < LSEQ_NUM_VECS; i++)
1316 lseq_vecs[i] = le16_to_cpu(ptr_lseq_vecs[i]);
1318 cseq_code = &sequencer_fw->data[header.cseq_code_offset];
1319 cseq_code_size = header.cseq_code_size;
1320 lseq_code = &sequencer_fw->data[header.lseq_code_offset];
1321 lseq_code_size = header.lseq_code_size;
1326 int asd_init_seqs(struct asd_ha_struct *asd_ha)
1330 err = asd_request_firmware(asd_ha);
1333 asd_printk("Failed to load sequencer firmware file %s, error %d\n",
1334 SAS_RAZOR_SEQUENCER_FW_FILE, err);
1338 asd_printk("using sequencer %s\n", sequencer_version);
1339 err = asd_seq_download_seqs(asd_ha);
1341 asd_printk("couldn't download sequencers for %s\n",
1342 pci_name(asd_ha->pcidev));
1346 asd_seq_setup_seqs(asd_ha);
1351 int asd_start_seqs(struct asd_ha_struct *asd_ha)
1357 err = asd_seq_start_cseq(asd_ha);
1359 asd_printk("couldn't start CSEQ for %s\n",
1360 pci_name(asd_ha->pcidev));
1364 lseq_mask = asd_ha->hw_prof.enabled_phys;
1365 for_each_sequencer(lseq_mask, lseq_mask, lseq) {
1366 err = asd_seq_start_lseq(asd_ha, lseq);
1368 asd_printk("coudln't start LSEQ %d for %s\n", lseq,
1369 pci_name(asd_ha->pcidev));
1378 * asd_update_port_links -- update port_map_by_links and phy_is_up
1379 * @sas_phy: pointer to the phy which has been added to a port
1381 * 1) When a link reset has completed and we got BYTES DMAED with a
1382 * valid frame we call this function for that phy, to indicate that
1383 * the phy is up, i.e. we update the phy_is_up in DDB 0. The
1384 * sequencer checks phy_is_up when pending SCBs are to be sent, and
1385 * when an open address frame has been received.
1387 * 2) When we know of ports, we call this function to update the map
1388 * of phys participaing in that port, i.e. we update the
1389 * port_map_by_links in DDB 0. When a HARD_RESET primitive has been
1390 * received, the sequencer disables all phys in that port.
1391 * port_map_by_links is also used as the conn_mask byte in the
1392 * initiator/target port DDB.
1394 void asd_update_port_links(struct asd_ha_struct *asd_ha, struct asd_phy *phy)
1396 const u8 phy_mask = (u8) phy->asd_port->phy_mask;
1400 unsigned long flags;
1402 spin_lock_irqsave(&asd_ha->hw_prof.ddb_lock, flags);
1403 for_each_phy(phy_mask, mask, i)
1404 asd_ddbsite_write_byte(asd_ha, 0,
1405 offsetof(struct asd_ddb_seq_shared,
1406 port_map_by_links)+i,phy_mask);
1408 for (i = 0; i < 12; i++) {
1409 phy_is_up = asd_ddbsite_read_byte(asd_ha, 0,
1410 offsetof(struct asd_ddb_seq_shared, phy_is_up));
1411 err = asd_ddbsite_update_byte(asd_ha, 0,
1412 offsetof(struct asd_ddb_seq_shared, phy_is_up),
1414 phy_is_up | phy_mask);
1417 else if (err == -EFAULT) {
1418 asd_printk("phy_is_up: parity error in DDB 0\n");
1422 spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags);
1425 asd_printk("couldn't update DDB 0:error:%d\n", err);
1428 MODULE_FIRMWARE(SAS_RAZOR_SEQUENCER_FW_FILE);