Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
aic94xx_seq.c
Go to the documentation of this file.
1 /*
2  * Aic94xx SAS/SATA driver sequencer interface.
3  *
4  * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
5  * Copyright (C) 2005 Luben Tuikov <[email protected]>
6  *
7  * Parts of this code adapted from David Chaw's adp94xx_seq.c.
8  *
9  * This file is licensed under GPLv2.
10  *
11  * This file is part of the aic94xx driver.
12  *
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
16  * License.
17  *
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.
22  *
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
26  *
27  */
28 
29 #include <linux/delay.h>
30 #include <linux/gfp.h>
31 #include <linux/pci.h>
32 #include <linux/module.h>
33 #include <linux/firmware.h>
34 #include "aic94xx_reg.h"
35 #include "aic94xx_hwi.h"
36 
37 #include "aic94xx_seq.h"
38 #include "aic94xx_dump.h"
39 
40 /* It takes no more than 0.05 us for an instruction
41  * to complete. So waiting for 1 us should be more than
42  * plenty.
43  */
44 #define PAUSE_DELAY 1
45 #define PAUSE_TRIES 1000
46 
47 static const struct firmware *sequencer_fw;
48 static u16 cseq_vecs[CSEQ_NUM_VECS], lseq_vecs[LSEQ_NUM_VECS], mode2_task,
50 static const u8 *cseq_code, *lseq_code;
52 
53 static u16 first_scb_site_no = 0xFFFF;
54 static u16 last_scb_site_no;
55 
56 /* ---------- Pause/Unpause CSEQ/LSEQ ---------- */
57 
64 static int asd_pause_cseq(struct asd_ha_struct *asd_ha)
65 {
66  int count = PAUSE_TRIES;
67  u32 arp2ctl;
68 
69  arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL);
70  if (arp2ctl & PAUSED)
71  return 0;
72 
73  asd_write_reg_dword(asd_ha, CARP2CTL, arp2ctl | EPAUSE);
74  do {
75  arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL);
76  if (arp2ctl & PAUSED)
77  return 0;
79  } while (--count > 0);
80 
81  ASD_DPRINTK("couldn't pause CSEQ\n");
82  return -1;
83 }
84 
91 static int asd_unpause_cseq(struct asd_ha_struct *asd_ha)
92 {
93  u32 arp2ctl;
94  int count = PAUSE_TRIES;
95 
96  arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL);
97  if (!(arp2ctl & PAUSED))
98  return 0;
99 
100  asd_write_reg_dword(asd_ha, CARP2CTL, arp2ctl & ~EPAUSE);
101  do {
102  arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL);
103  if (!(arp2ctl & PAUSED))
104  return 0;
106  } while (--count > 0);
107 
108  ASD_DPRINTK("couldn't unpause the CSEQ\n");
109  return -1;
110 }
111 
119 static int asd_seq_pause_lseq(struct asd_ha_struct *asd_ha, int lseq)
120 {
121  u32 arp2ctl;
122  int count = PAUSE_TRIES;
123 
124  arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq));
125  if (arp2ctl & PAUSED)
126  return 0;
127 
128  asd_write_reg_dword(asd_ha, LmARP2CTL(lseq), arp2ctl | EPAUSE);
129  do {
130  arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq));
131  if (arp2ctl & PAUSED)
132  return 0;
134  } while (--count > 0);
135 
136  ASD_DPRINTK("couldn't pause LSEQ %d\n", lseq);
137  return -1;
138 }
139 
147 static int asd_pause_lseq(struct asd_ha_struct *asd_ha, u8 lseq_mask)
148 {
149  int lseq;
150  int err = 0;
151 
152  for_each_sequencer(lseq_mask, lseq_mask, lseq) {
153  err = asd_seq_pause_lseq(asd_ha, lseq);
154  if (err)
155  return err;
156  }
157 
158  return err;
159 }
160 
168 static int asd_seq_unpause_lseq(struct asd_ha_struct *asd_ha, int lseq)
169 {
170  u32 arp2ctl;
171  int count = PAUSE_TRIES;
172 
173  arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq));
174  if (!(arp2ctl & PAUSED))
175  return 0;
176 
177  asd_write_reg_dword(asd_ha, LmARP2CTL(lseq), arp2ctl & ~EPAUSE);
178  do {
179  arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq));
180  if (!(arp2ctl & PAUSED))
181  return 0;
183  } while (--count > 0);
184 
185  ASD_DPRINTK("couldn't unpause LSEQ %d\n", lseq);
186  return 0;
187 }
188 
189 
190 /* ---------- Downloading CSEQ/LSEQ microcode ---------- */
191 
192 static int asd_verify_cseq(struct asd_ha_struct *asd_ha, const u8 *_prog,
193  u32 size)
194 {
196  const u32 *prog = (u32 *) _prog;
197  u32 i;
198 
199  for (i = 0; i < size; i += 4, prog++, addr += 4) {
200  u32 val = asd_read_reg_dword(asd_ha, addr);
201 
202  if (le32_to_cpu(*prog) != val) {
203  asd_printk("%s: cseq verify failed at %u "
204  "read:0x%x, wanted:0x%x\n",
205  pci_name(asd_ha->pcidev),
206  i, val, le32_to_cpu(*prog));
207  return -1;
208  }
209  }
210  ASD_DPRINTK("verified %d bytes, passed\n", size);
211  return 0;
212 }
213 
226 static int asd_verify_lseq(struct asd_ha_struct *asd_ha, const u8 *_prog,
227  u32 size, int lseq)
228 {
229 #define LSEQ_CODEPAGE_SIZE 4096
230  int pages = (size + LSEQ_CODEPAGE_SIZE - 1) / LSEQ_CODEPAGE_SIZE;
231  u32 page;
232  const u32 *prog = (u32 *) _prog;
233 
234  for (page = 0; page < pages; page++) {
235  u32 i;
236 
237  asd_write_reg_dword(asd_ha, LmBISTCTL1(lseq),
238  page << LmRAMPAGE_LSHIFT);
239  for (i = 0; size > 0 && i < LSEQ_CODEPAGE_SIZE;
240  i += 4, prog++, size-=4) {
241 
242  u32 val = asd_read_reg_dword(asd_ha, LmSEQRAM(lseq)+i);
243 
244  if (le32_to_cpu(*prog) != val) {
245  asd_printk("%s: LSEQ%d verify failed "
246  "page:%d, offs:%d\n",
247  pci_name(asd_ha->pcidev),
248  lseq, page, i);
249  return -1;
250  }
251  }
252  }
253  ASD_DPRINTK("LSEQ%d verified %d bytes, passed\n", lseq,
254  (int)((u8 *)prog-_prog));
255  return 0;
256 }
257 
267 static int asd_verify_seq(struct asd_ha_struct *asd_ha, const u8 *prog,
268  u32 size, u8 lseq_mask)
269 {
270  if (lseq_mask == 0)
271  return asd_verify_cseq(asd_ha, prog, size);
272  else {
273  int lseq, err;
274 
275  for_each_sequencer(lseq_mask, lseq_mask, lseq) {
276  err = asd_verify_lseq(asd_ha, prog, size, lseq);
277  if (err)
278  return err;
279  }
280  }
281 
282  return 0;
283 }
284 #define ASD_DMA_MODE_DOWNLOAD
285 #ifdef ASD_DMA_MODE_DOWNLOAD
286 /* This is the size of the CSEQ Mapped instruction page */
287 #define MAX_DMA_OVLY_COUNT ((1U << 14)-1)
288 static int asd_download_seq(struct asd_ha_struct *asd_ha,
289  const u8 * const prog, u32 size, u8 lseq_mask)
290 {
291  u32 comstaten;
292  u32 reg;
293  int page;
294  const int pages = (size + MAX_DMA_OVLY_COUNT - 1) / MAX_DMA_OVLY_COUNT;
295  struct asd_dma_tok *token;
296  int err = 0;
297 
298  if (size % 4) {
299  asd_printk("sequencer program not multiple of 4\n");
300  return -1;
301  }
302 
303  asd_pause_cseq(asd_ha);
304  asd_pause_lseq(asd_ha, 0xFF);
305 
306  /* save, disable and clear interrupts */
307  comstaten = asd_read_reg_dword(asd_ha, COMSTATEN);
308  asd_write_reg_dword(asd_ha, COMSTATEN, 0);
310 
313 
314  token = asd_alloc_coherent(asd_ha, MAX_DMA_OVLY_COUNT, GFP_KERNEL);
315  if (!token) {
316  asd_printk("out of memory for dma SEQ download\n");
317  err = -ENOMEM;
318  goto out;
319  }
320  ASD_DPRINTK("dma-ing %d bytes\n", size);
321 
322  for (page = 0; page < pages; page++) {
323  int i;
324  u32 left = min(size-page*MAX_DMA_OVLY_COUNT,
325  (u32)MAX_DMA_OVLY_COUNT);
326 
327  memcpy(token->vaddr, prog + page*MAX_DMA_OVLY_COUNT, left);
328  asd_write_reg_addr(asd_ha, OVLYDMAADR, token->dma_handle);
329  asd_write_reg_dword(asd_ha, OVLYDMACNT, left);
330  reg = !page ? RESETOVLYDMA : 0;
331  reg |= (STARTOVLYDMA | OVLYHALTERR);
332  reg |= (lseq_mask ? (((u32)lseq_mask) << 8) : OVLYCSEQ);
333  /* Start DMA. */
334  asd_write_reg_dword(asd_ha, OVLYDMACTL, reg);
335 
336  for (i = PAUSE_TRIES*100; i > 0; i--) {
337  u32 dmadone = asd_read_reg_dword(asd_ha, OVLYDMACTL);
338  if (!(dmadone & OVLYDMAACT))
339  break;
341  }
342  }
343 
344  reg = asd_read_reg_dword(asd_ha, COMSTAT);
345  if (!(reg & OVLYDMADONE) || (reg & OVLYERR)
346  || (asd_read_reg_dword(asd_ha, CHIMINT) & DEVEXCEPT_MASK)){
347  asd_printk("%s: error DMA-ing sequencer code\n",
348  pci_name(asd_ha->pcidev));
349  err = -ENODEV;
350  }
351 
352  asd_free_coherent(asd_ha, token);
353  out:
354  asd_write_reg_dword(asd_ha, COMSTATEN, comstaten);
355 
356  return err ? : asd_verify_seq(asd_ha, prog, size, lseq_mask);
357 }
358 #else /* ASD_DMA_MODE_DOWNLOAD */
359 static int asd_download_seq(struct asd_ha_struct *asd_ha, const u8 *_prog,
360  u32 size, u8 lseq_mask)
361 {
362  int i;
363  u32 reg = 0;
364  const u32 *prog = (u32 *) _prog;
365 
366  if (size % 4) {
367  asd_printk("sequencer program not multiple of 4\n");
368  return -1;
369  }
370 
371  asd_pause_cseq(asd_ha);
372  asd_pause_lseq(asd_ha, 0xFF);
373 
374  reg |= (lseq_mask ? (((u32)lseq_mask) << 8) : OVLYCSEQ);
375  reg |= PIOCMODE;
376 
377  asd_write_reg_dword(asd_ha, OVLYDMACNT, size);
378  asd_write_reg_dword(asd_ha, OVLYDMACTL, reg);
379 
380  ASD_DPRINTK("downloading %s sequencer%s in PIO mode...\n",
381  lseq_mask ? "LSEQ" : "CSEQ", lseq_mask ? "s" : "");
382 
383  for (i = 0; i < size; i += 4, prog++)
384  asd_write_reg_dword(asd_ha, SPIODATA, *prog);
385 
386  reg = (reg & ~PIOCMODE) | OVLYHALTERR;
387  asd_write_reg_dword(asd_ha, OVLYDMACTL, reg);
388 
389  return asd_verify_seq(asd_ha, _prog, size, lseq_mask);
390 }
391 #endif /* ASD_DMA_MODE_DOWNLOAD */
392 
399 static int asd_seq_download_seqs(struct asd_ha_struct *asd_ha)
400 {
401  int err;
402 
403  if (!asd_ha->hw_prof.enabled_phys) {
404  asd_printk("%s: no enabled phys!\n", pci_name(asd_ha->pcidev));
405  return -ENODEV;
406  }
407 
408  /* Download the CSEQ */
409  ASD_DPRINTK("downloading CSEQ...\n");
410  err = asd_download_seq(asd_ha, cseq_code, cseq_code_size, 0);
411  if (err) {
412  asd_printk("CSEQ download failed:%d\n", err);
413  return err;
414  }
415 
416  /* Download the Link Sequencers code. All of the Link Sequencers
417  * microcode can be downloaded at the same time.
418  */
419  ASD_DPRINTK("downloading LSEQs...\n");
420  err = asd_download_seq(asd_ha, lseq_code, lseq_code_size,
421  asd_ha->hw_prof.enabled_phys);
422  if (err) {
423  /* Try it one at a time */
424  u8 lseq;
425  u8 lseq_mask = asd_ha->hw_prof.enabled_phys;
426 
427  for_each_sequencer(lseq_mask, lseq_mask, lseq) {
428  err = asd_download_seq(asd_ha, lseq_code,
429  lseq_code_size, 1<<lseq);
430  if (err)
431  break;
432  }
433  }
434  if (err)
435  asd_printk("LSEQs download failed:%d\n", err);
436 
437  return err;
438 }
439 
440 /* ---------- Initializing the chip, chip memory, etc. ---------- */
441 
446 static void asd_init_cseq_mip(struct asd_ha_struct *asd_ha)
447 {
448  /* CSEQ Mode Independent, page 4 setup. */
449  asd_write_reg_word(asd_ha, CSEQ_Q_EXE_HEAD, 0xFFFF);
450  asd_write_reg_word(asd_ha, CSEQ_Q_EXE_TAIL, 0xFFFF);
451  asd_write_reg_word(asd_ha, CSEQ_Q_DONE_HEAD, 0xFFFF);
452  asd_write_reg_word(asd_ha, CSEQ_Q_DONE_TAIL, 0xFFFF);
453  asd_write_reg_word(asd_ha, CSEQ_Q_SEND_HEAD, 0xFFFF);
454  asd_write_reg_word(asd_ha, CSEQ_Q_SEND_TAIL, 0xFFFF);
455  asd_write_reg_word(asd_ha, CSEQ_Q_DMA2CHIM_HEAD, 0xFFFF);
456  asd_write_reg_word(asd_ha, CSEQ_Q_DMA2CHIM_TAIL, 0xFFFF);
457  asd_write_reg_word(asd_ha, CSEQ_Q_COPY_HEAD, 0xFFFF);
458  asd_write_reg_word(asd_ha, CSEQ_Q_COPY_TAIL, 0xFFFF);
459  asd_write_reg_word(asd_ha, CSEQ_REG0, 0);
460  asd_write_reg_word(asd_ha, CSEQ_REG1, 0);
461  asd_write_reg_dword(asd_ha, CSEQ_REG2, 0);
463  {
464  u8 con = asd_read_reg_byte(asd_ha, CCONEXIST);
465  u8 val = hweight8(con);
466  asd_write_reg_byte(asd_ha, CSEQ_MAX_CSEQ_MODE, (val<<4)|val);
467  }
469 
470  /* CSEQ Mode independent, page 5 setup. */
475  asd_write_reg_word(asd_ha, CSEQ_Q_EST_NEXUS_HEAD, 0xFFFF);
476  asd_write_reg_word(asd_ha, CSEQ_Q_EST_NEXUS_TAIL, 0xFFFF);
481 
482  /* CSEQ Mode independent, page 6 setup. */
490  asd_write_reg_word(asd_ha, CSEQ_Q_MONIRTT_HEAD, 0xFFFF);
491  asd_write_reg_word(asd_ha, CSEQ_Q_MONIRTT_TAIL, 0xFFFF);
492  /* Calculate the free scb mask. */
493  {
494  u16 cmdctx = asd_get_cmdctx_size(asd_ha);
495  cmdctx = (~((cmdctx/128)-1)) >> 8;
496  asd_write_reg_byte(asd_ha, CSEQ_FREE_SCB_MASK, (u8)cmdctx);
497  }
499  first_scb_site_no);
501  last_scb_site_no);
504 
505  /* CSEQ Mode independent, page 7 setup. */
510  asd_write_reg_word(asd_ha, CSEQ_Q_EMPTY_HEAD, 0xFFFF);
511  asd_write_reg_word(asd_ha, CSEQ_Q_EMPTY_TAIL, 0xFFFF);
518 }
519 
524 static void asd_init_cseq_mdp(struct asd_ha_struct *asd_ha)
525 {
526  int i;
527  int moffs;
528 
529  moffs = CSEQ_PAGE_SIZE * 2;
530 
531  /* CSEQ Mode dependent, modes 0-7, page 0 setup. */
532  for (i = 0; i < 8; i++) {
533  asd_write_reg_word(asd_ha, i*moffs+CSEQ_LRM_SAVE_SINDEX, 0);
534  asd_write_reg_word(asd_ha, i*moffs+CSEQ_LRM_SAVE_SCBPTR, 0);
535  asd_write_reg_word(asd_ha, i*moffs+CSEQ_Q_LINK_HEAD, 0xFFFF);
536  asd_write_reg_word(asd_ha, i*moffs+CSEQ_Q_LINK_TAIL, 0xFFFF);
537  asd_write_reg_byte(asd_ha, i*moffs+CSEQ_LRM_SAVE_SCRPAGE, 0);
538  }
539 
540  /* CSEQ Mode dependent, mode 0-7, page 1 and 2 shall be ignored. */
541 
542  /* CSEQ Mode dependent, mode 8, page 0 setup. */
543  asd_write_reg_word(asd_ha, CSEQ_RET_ADDR, 0xFFFF);
547  asd_write_reg_word(asd_ha, CSEQ_RESP_LEN, 0);
554  asd_write_reg_word(asd_ha, CSEQ_HSB_SITE, 0);
556  (u16)last_scb_site_no+1);
558  (u16)asd_ha->hw_prof.max_ddbs);
559 
560  /* CSEQ Mode dependent, mode 8, page 1 setup. */
562  asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CLEAR + 4, 0);
564  asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CHECK + 4, 0);
565 
566  /* CSEQ Mode dependent, mode 8, page 2 setup. */
567  /* Tell the sequencer the bus address of the first SCB. */
568  asd_write_reg_addr(asd_ha, CSEQ_HQ_NEW_POINTER,
569  asd_ha->seq.next_scb.dma_handle);
570  ASD_DPRINTK("First SCB dma_handle: 0x%llx\n",
571  (unsigned long long)asd_ha->seq.next_scb.dma_handle);
572 
573  /* Tell the sequencer the first Done List entry address. */
574  asd_write_reg_addr(asd_ha, CSEQ_HQ_DONE_BASE,
575  asd_ha->seq.actual_dl->dma_handle);
576 
577  /* Initialize the Q_DONE_POINTER with the least significant
578  * 4 bytes of the first Done List address. */
580  ASD_BUSADDR_LO(asd_ha->seq.actual_dl->dma_handle));
581 
583 
584  /* CSEQ Mode dependent, mode 8, page 3 shall be ignored. */
585 }
586 
594 static void asd_init_cseq_scratch(struct asd_ha_struct *asd_ha)
595 {
596  asd_init_cseq_mip(asd_ha);
597  asd_init_cseq_mdp(asd_ha);
598 }
599 
604 static void asd_init_lseq_mip(struct asd_ha_struct *asd_ha, u8 lseq)
605 {
606  int i;
607 
608  /* LSEQ Mode independent page 0 setup. */
609  asd_write_reg_word(asd_ha, LmSEQ_Q_TGTXFR_HEAD(lseq), 0xFFFF);
610  asd_write_reg_word(asd_ha, LmSEQ_Q_TGTXFR_TAIL(lseq), 0xFFFF);
611  asd_write_reg_byte(asd_ha, LmSEQ_LINK_NUMBER(lseq), lseq);
614  asd_write_reg_dword(asd_ha, LmSEQ_CONNECTION_STATE(lseq),0x08000000);
615  asd_write_reg_word(asd_ha, LmSEQ_CONCTL(lseq), 0);
616  asd_write_reg_byte(asd_ha, LmSEQ_CONSTAT(lseq), 0);
617  asd_write_reg_byte(asd_ha, LmSEQ_CONNECTION_MODES(lseq), 0);
618  asd_write_reg_word(asd_ha, LmSEQ_REG1_ISR(lseq), 0);
619  asd_write_reg_word(asd_ha, LmSEQ_REG2_ISR(lseq), 0);
620  asd_write_reg_word(asd_ha, LmSEQ_REG3_ISR(lseq), 0);
621  asd_write_reg_dword(asd_ha, LmSEQ_REG0_ISR(lseq), 0);
622  asd_write_reg_dword(asd_ha, LmSEQ_REG0_ISR(lseq)+4, 0);
623 
624  /* LSEQ Mode independent page 1 setup. */
625  asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR0(lseq), 0xFFFF);
626  asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR1(lseq), 0xFFFF);
627  asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR2(lseq), 0xFFFF);
628  asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR3(lseq), 0xFFFF);
636  asd_write_reg_dword(asd_ha, LmSEQ_TIMEOUT_CONST(lseq), 0);
637  asd_write_reg_word(asd_ha, LmSEQ_ISR_SAVE_SINDEX(lseq), 0);
638  asd_write_reg_word(asd_ha, LmSEQ_ISR_SAVE_DINDEX(lseq), 0);
639 
640  /* LSEQ Mode Independent page 2 setup. */
641  asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR0(lseq), 0xFFFF);
642  asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR1(lseq), 0xFFFF);
643  asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR2(lseq), 0xFFFF);
644  asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR3(lseq), 0xFFFF);
645  asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD0(lseq), 0);
646  asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD1(lseq), 0);
647  asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD2(lseq), 0);
648  asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD3(lseq), 0);
649  asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_HEAD(lseq), 0);
650  asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_TAIL(lseq), 0);
651  asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_BUFS_AVAIL(lseq), 0);
652  for (i = 0; i < 12; i += 4)
653  asd_write_reg_dword(asd_ha, LmSEQ_ATA_SCR_REGS(lseq) + i, 0);
654 
655  /* LSEQ Mode Independent page 3 setup. */
656 
657  /* Device present timer timeout */
660 
661  /* SATA interlock timer disabled */
664 
665  /* STP shutdown timer timeout constant, IGNORED by the sequencer,
666  * always 0. */
669 
672 
675 
678 
679  /* COM_INIT timer */
682 
685 }
686 
691 static void asd_init_lseq_mdp(struct asd_ha_struct *asd_ha, int lseq)
692 {
693  int i;
694  u32 moffs;
695  u16 ret_addr[] = {
696  0xFFFF, /* mode 0 */
697  0xFFFF, /* mode 1 */
698  mode2_task, /* mode 2 */
699  0,
700  0xFFFF, /* mode 4/5 */
701  0xFFFF, /* mode 4/5 */
702  };
703 
704  /*
705  * Mode 0,1,2 and 4/5 have common field on page 0 for the first
706  * 14 bytes.
707  */
708  for (i = 0; i < 3; i++) {
709  moffs = i * LSEQ_MODE_SCRATCH_SIZE;
710  asd_write_reg_word(asd_ha, LmSEQ_RET_ADDR(lseq)+moffs,
711  ret_addr[i]);
712  asd_write_reg_word(asd_ha, LmSEQ_REG0_MODE(lseq)+moffs, 0);
713  asd_write_reg_word(asd_ha, LmSEQ_MODE_FLAGS(lseq)+moffs, 0);
714  asd_write_reg_word(asd_ha, LmSEQ_RET_ADDR2(lseq)+moffs,0xFFFF);
715  asd_write_reg_word(asd_ha, LmSEQ_RET_ADDR1(lseq)+moffs,0xFFFF);
716  asd_write_reg_byte(asd_ha, LmSEQ_OPCODE_TO_CSEQ(lseq)+moffs,0);
717  asd_write_reg_word(asd_ha, LmSEQ_DATA_TO_CSEQ(lseq)+moffs,0);
718  }
719  /*
720  * Mode 5 page 0 overlaps the same scratch page with Mode 0 page 3.
721  */
722  asd_write_reg_word(asd_ha,
724  ret_addr[5]);
725  asd_write_reg_word(asd_ha,
727  asd_write_reg_word(asd_ha,
729  asd_write_reg_word(asd_ha,
731  asd_write_reg_word(asd_ha,
733  asd_write_reg_byte(asd_ha,
735  asd_write_reg_word(asd_ha,
737 
738  /* LSEQ Mode dependent 0, page 0 setup. */
740  (u16)asd_ha->hw_prof.max_ddbs);
741  asd_write_reg_word(asd_ha, LmSEQ_EMPTY_TRANS_CTX(lseq), 0);
742  asd_write_reg_word(asd_ha, LmSEQ_RESP_LEN(lseq), 0);
744  (u16)last_scb_site_no+1);
745  asd_write_reg_word(asd_ha, LmSEQ_INTEN_SAVE(lseq),
746  (u16) ((LmM0INTEN_MASK & 0xFFFF0000) >> 16));
747  asd_write_reg_word(asd_ha, LmSEQ_INTEN_SAVE(lseq) + 2,
748  (u16) LmM0INTEN_MASK & 0xFFFF);
749  asd_write_reg_byte(asd_ha, LmSEQ_LINK_RST_FRM_LEN(lseq), 0);
751  asd_write_reg_byte(asd_ha, LmSEQ_RESP_STATUS(lseq), 0);
752  asd_write_reg_byte(asd_ha, LmSEQ_LAST_LOADED_SGE(lseq), 0);
753  asd_write_reg_word(asd_ha, LmSEQ_SAVE_SCBPTR(lseq), 0);
754 
755  /* LSEQ mode dependent, mode 1, page 0 setup. */
756  asd_write_reg_word(asd_ha, LmSEQ_Q_XMIT_HEAD(lseq), 0xFFFF);
758  asd_write_reg_word(asd_ha, LmSEQ_INI_CONN_TAG(lseq), 0);
761  asd_write_reg_byte(asd_ha, LmSEQ_M1_RESP_STATUS(lseq), 0);
763  asd_write_reg_word(asd_ha, LmSEQ_M1_SAVE_SCBPTR(lseq), 0);
764 
765  /* LSEQ Mode dependent mode 2, page 0 setup */
766  asd_write_reg_word(asd_ha, LmSEQ_PORT_COUNTER(lseq), 0);
767  asd_write_reg_word(asd_ha, LmSEQ_PM_TABLE_PTR(lseq), 0);
769  asd_write_reg_word(asd_ha, LmSEQ_IP_BITL(lseq), 0);
771  asd_write_reg_byte(asd_ha, LmSEQ_P0M2_OFFS1AH(lseq), 0);
772 
773  /* LSEQ Mode dependent, mode 4/5, page 0 setup. */
774  asd_write_reg_byte(asd_ha, LmSEQ_SAVED_OOB_STATUS(lseq), 0);
775  asd_write_reg_byte(asd_ha, LmSEQ_SAVED_OOB_MODE(lseq), 0);
776  asd_write_reg_word(asd_ha, LmSEQ_Q_LINK_HEAD(lseq), 0xFFFF);
777  asd_write_reg_byte(asd_ha, LmSEQ_LINK_RST_ERR(lseq), 0);
779  asd_write_reg_byte(asd_ha, LmSEQ_SAS_RESET_MODE(lseq), 0);
782  asd_write_reg_word(asd_ha, LmSEQ_OOB_INT_ENABLES(lseq), 0);
783  /*
784  * Set the desired interval between transmissions of the NOTIFY
785  * (ENABLE SPINUP) primitive. Must be initialized to val - 1.
786  */
788  ASD_NOTIFY_TIMEOUT - 1);
789  /* No delay for the first NOTIFY to be sent to the attached target. */
794 
795  /* LSEQ Mode dependent, mode 0 and 1, page 1 setup. */
796  for (i = 0; i < 2; i++) {
797  int j;
798  /* Start from Page 1 of Mode 0 and 1. */
800  /* All the fields of page 1 can be initialized to 0. */
801  for (j = 0; j < LSEQ_PAGE_SIZE; j += 4)
802  asd_write_reg_dword(asd_ha, LmSCRATCH(lseq)+moffs+j,0);
803  }
804 
805  /* LSEQ Mode dependent, mode 2, page 1 setup. */
809 
810  /* LSEQ Mode dependent, mode 4/5, page 1. */
811  for (i = 0; i < LSEQ_PAGE_SIZE; i+=4)
812  asd_write_reg_dword(asd_ha, LmSEQ_FRAME_TYPE_MASK(lseq)+i, 0);
813  asd_write_reg_byte(asd_ha, LmSEQ_FRAME_TYPE_MASK(lseq), 0xFF);
814  asd_write_reg_byte(asd_ha, LmSEQ_HASHED_DEST_ADDR_MASK(lseq), 0xFF);
815  asd_write_reg_byte(asd_ha, LmSEQ_HASHED_DEST_ADDR_MASK(lseq)+1,0xFF);
816  asd_write_reg_byte(asd_ha, LmSEQ_HASHED_DEST_ADDR_MASK(lseq)+2,0xFF);
817  asd_write_reg_byte(asd_ha, LmSEQ_HASHED_SRC_ADDR_MASK(lseq), 0xFF);
818  asd_write_reg_byte(asd_ha, LmSEQ_HASHED_SRC_ADDR_MASK(lseq)+1, 0xFF);
819  asd_write_reg_byte(asd_ha, LmSEQ_HASHED_SRC_ADDR_MASK(lseq)+2, 0xFF);
820  asd_write_reg_dword(asd_ha, LmSEQ_DATA_OFFSET(lseq), 0xFFFFFFFF);
821 
822  /* LSEQ Mode dependent, mode 0, page 2 setup. */
824  asd_write_reg_byte(asd_ha, LmSEQ_DEVICE_BITS(lseq), 0);
825  asd_write_reg_word(asd_ha, LmSEQ_SDB_DDB(lseq), 0);
826  asd_write_reg_byte(asd_ha, LmSEQ_SDB_NUM_TAGS(lseq), 0);
827  asd_write_reg_byte(asd_ha, LmSEQ_SDB_CURR_TAG(lseq), 0);
828 
829  /* LSEQ Mode Dependent 1, page 2 setup. */
831  asd_write_reg_dword(asd_ha, LmSEQ_TX_ID_ADDR_FRAME(lseq)+4, 0);
835 
836  /* LSEQ Mode Dependent 2, page 2 setup. */
837  /* The LmSEQ_STP_SHUTDOWN_TIMER_TERM_TS is IGNORED by the sequencer,
838  * i.e. always 0. */
845 
846  /* LSEQ Mode Dependent 4/5, page 2 setup. */
851 }
852 
857 static void asd_init_lseq_scratch(struct asd_ha_struct *asd_ha)
858 {
859  u8 lseq;
860  u8 lseq_mask;
861 
862  lseq_mask = asd_ha->hw_prof.enabled_phys;
863  for_each_sequencer(lseq_mask, lseq_mask, lseq) {
864  asd_init_lseq_mip(asd_ha, lseq);
865  asd_init_lseq_mdp(asd_ha, lseq);
866  }
867 }
868 
877 static void asd_init_scb_sites(struct asd_ha_struct *asd_ha)
878 {
879  u16 site_no;
880  u16 max_scbs = 0;
881 
882  for (site_no = asd_ha->hw_prof.max_scbs-1;
883  site_no != (u16) -1;
884  site_no--) {
885  u16 i;
886 
887  /* Initialize all fields in the SCB site to 0. */
888  for (i = 0; i < ASD_SCB_SIZE; i += 4)
889  asd_scbsite_write_dword(asd_ha, site_no, i, 0);
890 
891  /* Initialize SCB Site Opcode field to invalid. */
892  asd_scbsite_write_byte(asd_ha, site_no,
893  offsetof(struct scb_header, opcode),
894  0xFF);
895 
896  /* Initialize SCB Site Flags field to mean a response
897  * frame has been received. This means inadvertent
898  * frames received to be dropped. */
899  asd_scbsite_write_byte(asd_ha, site_no, 0x49, 0x01);
900 
901  /* Workaround needed by SEQ to fix a SATA issue is to exclude
902  * certain SCB sites from the free list. */
903  if (!SCB_SITE_VALID(site_no))
904  continue;
905 
906  if (last_scb_site_no == 0)
907  last_scb_site_no = site_no;
908 
909  /* For every SCB site, we need to initialize the
910  * following fields: Q_NEXT, SCB_OPCODE, SCB_FLAGS,
911  * and SG Element Flag. */
912 
913  /* Q_NEXT field of the last SCB is invalidated. */
914  asd_scbsite_write_word(asd_ha, site_no, 0, first_scb_site_no);
915 
916  first_scb_site_no = site_no;
917  max_scbs++;
918  }
919  asd_ha->hw_prof.max_scbs = max_scbs;
920  ASD_DPRINTK("max_scbs:%d\n", asd_ha->hw_prof.max_scbs);
921  ASD_DPRINTK("first_scb_site_no:0x%x\n", first_scb_site_no);
922  ASD_DPRINTK("last_scb_site_no:0x%x\n", last_scb_site_no);
923 }
924 
929 static void asd_init_cseq_cio(struct asd_ha_struct *asd_ha)
930 {
931  int i;
932 
933  asd_write_reg_byte(asd_ha, CSEQCOMINTEN, 0);
935  asd_write_reg_byte(asd_ha, CSEQDLOFFS, 0);
936  asd_write_reg_byte(asd_ha, CSEQDLOFFS+1, 0);
937  asd_ha->seq.scbpro = 0;
938  asd_write_reg_dword(asd_ha, SCBPRO, 0);
939  asd_write_reg_dword(asd_ha, CSEQCON, 0);
940 
941  /* Initialize CSEQ Mode 11 Interrupt Vectors.
942  * The addresses are 16 bit wide and in dword units.
943  * The values of their macros are in byte units.
944  * Thus we have to divide by 4. */
945  asd_write_reg_word(asd_ha, CM11INTVEC0, cseq_vecs[0]);
946  asd_write_reg_word(asd_ha, CM11INTVEC1, cseq_vecs[1]);
947  asd_write_reg_word(asd_ha, CM11INTVEC2, cseq_vecs[2]);
948 
949  /* Enable ARP2HALTC (ARP2 Halted from Halt Code Write). */
951 
952  /* Initialize CSEQ Scratch Page to 0x04. */
953  asd_write_reg_byte(asd_ha, CSCRATCHPAGE, 0x04);
954 
955  /* Initialize CSEQ Mode[0-8] Dependent registers. */
956  /* Initialize Scratch Page to 0. */
957  for (i = 0; i < 9; i++)
958  asd_write_reg_byte(asd_ha, CMnSCRATCHPAGE(i), 0);
959 
960  /* Reset the ARP2 Program Count. */
962 
963  for (i = 0; i < 8; i++) {
964  /* Initialize Mode n Link m Interrupt Enable. */
966  /* Initialize Mode n Request Mailbox. */
967  asd_write_reg_dword(asd_ha, CMnREQMBX(i), 0);
968  }
969 }
970 
975 static void asd_init_lseq_cio(struct asd_ha_struct *asd_ha, int lseq)
976 {
977  u8 *sas_addr;
978  int i;
979 
980  /* Enable ARP2HALTC (ARP2 Halted from Halt Code Write). */
982 
983  asd_write_reg_byte(asd_ha, LmSCRATCHPAGE(lseq), 0);
984 
985  /* Initialize Mode 0,1, and 2 SCRATCHPAGE to 0. */
986  for (i = 0; i < 3; i++)
987  asd_write_reg_byte(asd_ha, LmMnSCRATCHPAGE(lseq, i), 0);
988 
989  /* Initialize Mode 5 SCRATCHPAGE to 0. */
990  asd_write_reg_byte(asd_ha, LmMnSCRATCHPAGE(lseq, 5), 0);
991 
992  asd_write_reg_dword(asd_ha, LmRSPMBX(lseq), 0);
993  /* Initialize Mode 0,1,2 and 5 Interrupt Enable and
994  * Interrupt registers. */
995  asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 0), LmM0INTEN_MASK);
996  asd_write_reg_dword(asd_ha, LmMnINT(lseq, 0), 0xFFFFFFFF);
997  /* Mode 1 */
998  asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 1), LmM1INTEN_MASK);
999  asd_write_reg_dword(asd_ha, LmMnINT(lseq, 1), 0xFFFFFFFF);
1000  /* Mode 2 */
1001  asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 2), LmM2INTEN_MASK);
1002  asd_write_reg_dword(asd_ha, LmMnINT(lseq, 2), 0xFFFFFFFF);
1003  /* Mode 5 */
1004  asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 5), LmM5INTEN_MASK);
1005  asd_write_reg_dword(asd_ha, LmMnINT(lseq, 5), 0xFFFFFFFF);
1006 
1007  /* Enable HW Timer status. */
1009 
1010  /* Enable Primitive Status 0 and 1. */
1013 
1014  /* Enable Frame Error. */
1016  asd_write_reg_byte(asd_ha, LmMnHOLDLVL(lseq, 0), 0x50);
1017 
1018  /* Initialize Mode 0 Transfer Level to 512. */
1019  asd_write_reg_byte(asd_ha, LmMnXFRLVL(lseq, 0), LmMnXFRLVL_512);
1020  /* Initialize Mode 1 Transfer Level to 256. */
1021  asd_write_reg_byte(asd_ha, LmMnXFRLVL(lseq, 1), LmMnXFRLVL_256);
1022 
1023  /* Initialize Program Count. */
1025 
1026  /* Enable Blind SG Move. */
1027  asd_write_reg_dword(asd_ha, LmMODECTL(lseq), LmBLIND48);
1028  asd_write_reg_word(asd_ha, LmM3SATATIMER(lseq),
1030 
1031  (void) asd_read_reg_dword(asd_ha, LmREQMBX(lseq));
1032 
1033  /* Clear Primitive Status 0 and 1. */
1034  asd_write_reg_dword(asd_ha, LmPRMSTAT0(lseq), 0xFFFFFFFF);
1035  asd_write_reg_dword(asd_ha, LmPRMSTAT1(lseq), 0xFFFFFFFF);
1036 
1037  /* Clear HW Timer status. */
1038  asd_write_reg_byte(asd_ha, LmHWTSTAT(lseq), 0xFF);
1039 
1040  /* Clear DMA Errors for Mode 0 and 1. */
1041  asd_write_reg_byte(asd_ha, LmMnDMAERRS(lseq, 0), 0xFF);
1042  asd_write_reg_byte(asd_ha, LmMnDMAERRS(lseq, 1), 0xFF);
1043 
1044  /* Clear SG DMA Errors for Mode 0 and 1. */
1045  asd_write_reg_byte(asd_ha, LmMnSGDMAERRS(lseq, 0), 0xFF);
1046  asd_write_reg_byte(asd_ha, LmMnSGDMAERRS(lseq, 1), 0xFF);
1047 
1048  /* Clear Mode 0 Buffer Parity Error. */
1049  asd_write_reg_byte(asd_ha, LmMnBUFSTAT(lseq, 0), LmMnBUFPERR);
1050 
1051  /* Clear Mode 0 Frame Error register. */
1052  asd_write_reg_dword(asd_ha, LmMnFRMERR(lseq, 0), 0xFFFFFFFF);
1053 
1054  /* Reset LSEQ external interrupt arbiter. */
1055  asd_write_reg_byte(asd_ha, LmARP2INTCTL(lseq), RSTINTCTL);
1056 
1057  /* Set the Phy SAS for the LmSEQ WWN. */
1058  sas_addr = asd_ha->phys[lseq].phy_desc->sas_addr;
1059  for (i = 0; i < SAS_ADDR_SIZE; i++)
1060  asd_write_reg_byte(asd_ha, LmWWN(lseq) + i, sas_addr[i]);
1061 
1062  /* Set the Transmit Size to 1024 bytes, 0 = 256 Dwords. */
1063  asd_write_reg_byte(asd_ha, LmMnXMTSIZE(lseq, 1), 0);
1064 
1065  /* Set the Bus Inactivity Time Limit Timer. */
1066  asd_write_reg_word(asd_ha, LmBITL_TIMER(lseq), 9);
1067 
1068  /* Enable SATA Port Multiplier. */
1069  asd_write_reg_byte(asd_ha, LmMnSATAFS(lseq, 1), 0x80);
1070 
1071  /* Initialize Interrupt Vector[0-10] address in Mode 3.
1072  * See the comment on CSEQ_INT_* */
1073  asd_write_reg_word(asd_ha, LmM3INTVEC0(lseq), lseq_vecs[0]);
1074  asd_write_reg_word(asd_ha, LmM3INTVEC1(lseq), lseq_vecs[1]);
1075  asd_write_reg_word(asd_ha, LmM3INTVEC2(lseq), lseq_vecs[2]);
1076  asd_write_reg_word(asd_ha, LmM3INTVEC3(lseq), lseq_vecs[3]);
1077  asd_write_reg_word(asd_ha, LmM3INTVEC4(lseq), lseq_vecs[4]);
1078  asd_write_reg_word(asd_ha, LmM3INTVEC5(lseq), lseq_vecs[5]);
1079  asd_write_reg_word(asd_ha, LmM3INTVEC6(lseq), lseq_vecs[6]);
1080  asd_write_reg_word(asd_ha, LmM3INTVEC7(lseq), lseq_vecs[7]);
1081  asd_write_reg_word(asd_ha, LmM3INTVEC8(lseq), lseq_vecs[8]);
1082  asd_write_reg_word(asd_ha, LmM3INTVEC9(lseq), lseq_vecs[9]);
1083  asd_write_reg_word(asd_ha, LmM3INTVEC10(lseq), lseq_vecs[10]);
1084  /*
1085  * Program the Link LED control, applicable only for
1086  * Chip Rev. B or later.
1087  */
1088  asd_write_reg_dword(asd_ha, LmCONTROL(lseq),
1090 
1091  /* Set the Align Rate for SAS and STP mode. */
1094 }
1095 
1096 
1101 static void asd_post_init_cseq(struct asd_ha_struct *asd_ha)
1102 {
1103  int i;
1104 
1105  for (i = 0; i < 8; i++)
1106  asd_write_reg_dword(asd_ha, CMnINT(i), 0xFFFFFFFF);
1107  for (i = 0; i < 8; i++)
1108  asd_read_reg_dword(asd_ha, CMnRSPMBX(i));
1109  /* Reset the external interrupt arbiter. */
1111 }
1112 
1119 static void asd_init_ddb_0(struct asd_ha_struct *asd_ha)
1120 {
1121  int i;
1122 
1123  /* Zero out the DDB explicitly */
1124  for (i = 0; i < sizeof(struct asd_ddb_seq_shared); i+=4)
1125  asd_ddbsite_write_dword(asd_ha, 0, i, 0);
1126 
1127  asd_ddbsite_write_word(asd_ha, 0,
1129  asd_ddbsite_write_word(asd_ha, 0,
1131  asd_ha->hw_prof.max_ddbs-1);
1132  asd_ddbsite_write_word(asd_ha, 0,
1134  asd_ddbsite_write_word(asd_ha, 0,
1135  offsetof(struct asd_ddb_seq_shared, q_used_ddb_head), 0xFFFF);
1136  asd_ddbsite_write_word(asd_ha, 0,
1137  offsetof(struct asd_ddb_seq_shared, q_used_ddb_tail), 0xFFFF);
1138  asd_ddbsite_write_word(asd_ha, 0,
1140  asd_ddbsite_write_word(asd_ha, 0,
1142  asd_ddbsite_write_word(asd_ha, 0,
1144  asd_ddbsite_write_word(asd_ha, 0,
1146  asd_ha->hw_prof.num_phys * 2);
1147  asd_ddbsite_write_byte(asd_ha, 0,
1149  asd_ddbsite_write_byte(asd_ha, 0,
1151  asd_ddbsite_write_byte(asd_ha, 0,
1152  offsetof(struct asd_ddb_seq_shared, phy_is_up), 0x00);
1153  /* DDB 0 is reserved */
1154  set_bit(0, asd_ha->hw_prof.ddb_bitmap);
1155 }
1156 
1157 static void asd_seq_init_ddb_sites(struct asd_ha_struct *asd_ha)
1158 {
1159  unsigned int i;
1160  unsigned int ddb_site;
1161 
1162  for (ddb_site = 0 ; ddb_site < ASD_MAX_DDBS; ddb_site++)
1163  for (i = 0; i < sizeof(struct asd_ddb_ssp_smp_target_port); i+= 4)
1164  asd_ddbsite_write_dword(asd_ha, ddb_site, i, 0);
1165 }
1166 
1171 static void asd_seq_setup_seqs(struct asd_ha_struct *asd_ha)
1172 {
1173  int lseq;
1174  u8 lseq_mask;
1175 
1176  /* Initialize DDB sites */
1177  asd_seq_init_ddb_sites(asd_ha);
1178 
1179  /* Initialize SCB sites. Done first to compute some values which
1180  * the rest of the init code depends on. */
1181  asd_init_scb_sites(asd_ha);
1182 
1183  /* Initialize CSEQ Scratch RAM registers. */
1184  asd_init_cseq_scratch(asd_ha);
1185 
1186  /* Initialize LmSEQ Scratch RAM registers. */
1187  asd_init_lseq_scratch(asd_ha);
1188 
1189  /* Initialize CSEQ CIO registers. */
1190  asd_init_cseq_cio(asd_ha);
1191 
1192  asd_init_ddb_0(asd_ha);
1193 
1194  /* Initialize LmSEQ CIO registers. */
1195  lseq_mask = asd_ha->hw_prof.enabled_phys;
1196  for_each_sequencer(lseq_mask, lseq_mask, lseq)
1197  asd_init_lseq_cio(asd_ha, lseq);
1198  asd_post_init_cseq(asd_ha);
1199 }
1200 
1201 
1206 static int asd_seq_start_cseq(struct asd_ha_struct *asd_ha)
1207 {
1208  /* Reset the ARP2 instruction to location zero. */
1210 
1211  /* Unpause the CSEQ */
1212  return asd_unpause_cseq(asd_ha);
1213 }
1214 
1220 static int asd_seq_start_lseq(struct asd_ha_struct *asd_ha, int lseq)
1221 {
1222  /* Reset the ARP2 instruction to location zero. */
1224 
1225  /* Unpause the LmSEQ */
1226  return asd_seq_unpause_lseq(asd_ha, lseq);
1227 }
1228 
1230 {
1231  release_firmware(sequencer_fw);
1232  return 0;
1233 }
1234 
1235 static int asd_request_firmware(struct asd_ha_struct *asd_ha)
1236 {
1237  int err, i;
1239  const struct sequencer_file_header *hdr_ptr;
1240  u32 csum = 0;
1241  u16 *ptr_cseq_vecs, *ptr_lseq_vecs;
1242 
1243  if (sequencer_fw)
1244  /* already loaded */
1245  return 0;
1246 
1247  err = request_firmware(&sequencer_fw,
1249  &asd_ha->pcidev->dev);
1250  if (err)
1251  return err;
1252 
1253  hdr_ptr = (const struct sequencer_file_header *)sequencer_fw->data;
1254 
1255  header.csum = le32_to_cpu(hdr_ptr->csum);
1256  header.major = le32_to_cpu(hdr_ptr->major);
1257  header.minor = le32_to_cpu(hdr_ptr->minor);
1258  header.cseq_table_offset = le32_to_cpu(hdr_ptr->cseq_table_offset);
1259  header.cseq_table_size = le32_to_cpu(hdr_ptr->cseq_table_size);
1260  header.lseq_table_offset = le32_to_cpu(hdr_ptr->lseq_table_offset);
1261  header.lseq_table_size = le32_to_cpu(hdr_ptr->lseq_table_size);
1262  header.cseq_code_offset = le32_to_cpu(hdr_ptr->cseq_code_offset);
1263  header.cseq_code_size = le32_to_cpu(hdr_ptr->cseq_code_size);
1264  header.lseq_code_offset = le32_to_cpu(hdr_ptr->lseq_code_offset);
1265  header.lseq_code_size = le32_to_cpu(hdr_ptr->lseq_code_size);
1266  header.mode2_task = le16_to_cpu(hdr_ptr->mode2_task);
1267  header.cseq_idle_loop = le16_to_cpu(hdr_ptr->cseq_idle_loop);
1268  header.lseq_idle_loop = le16_to_cpu(hdr_ptr->lseq_idle_loop);
1269 
1270  for (i = sizeof(header.csum); i < sequencer_fw->size; i++)
1271  csum += sequencer_fw->data[i];
1272 
1273  if (csum != header.csum) {
1274  asd_printk("Firmware file checksum mismatch\n");
1275  return -EINVAL;
1276  }
1277 
1278  if (header.cseq_table_size != CSEQ_NUM_VECS ||
1279  header.lseq_table_size != LSEQ_NUM_VECS) {
1280  asd_printk("Firmware file table size mismatch\n");
1281  return -EINVAL;
1282  }
1283 
1284  asd_printk("Found sequencer Firmware version %d.%d (%s)\n",
1285  header.major, header.minor, hdr_ptr->version);
1286 
1287  if (header.major != SAS_RAZOR_SEQUENCER_FW_MAJOR) {
1288  asd_printk("Firmware Major Version Mismatch;"
1289  "driver requires version %d.X",
1291  return -EINVAL;
1292  }
1293 
1294  ptr_cseq_vecs = (u16 *)&sequencer_fw->data[header.cseq_table_offset];
1295  ptr_lseq_vecs = (u16 *)&sequencer_fw->data[header.lseq_table_offset];
1296  mode2_task = header.mode2_task;
1297  cseq_idle_loop = header.cseq_idle_loop;
1298  lseq_idle_loop = header.lseq_idle_loop;
1299 
1300  for (i = 0; i < CSEQ_NUM_VECS; i++)
1301  cseq_vecs[i] = le16_to_cpu(ptr_cseq_vecs[i]);
1302 
1303  for (i = 0; i < LSEQ_NUM_VECS; i++)
1304  lseq_vecs[i] = le16_to_cpu(ptr_lseq_vecs[i]);
1305 
1306  cseq_code = &sequencer_fw->data[header.cseq_code_offset];
1307  cseq_code_size = header.cseq_code_size;
1308  lseq_code = &sequencer_fw->data[header.lseq_code_offset];
1309  lseq_code_size = header.lseq_code_size;
1310 
1311  return 0;
1312 }
1313 
1314 int asd_init_seqs(struct asd_ha_struct *asd_ha)
1315 {
1316  int err;
1317 
1318  err = asd_request_firmware(asd_ha);
1319 
1320  if (err) {
1321  asd_printk("Failed to load sequencer firmware file %s, error %d\n",
1323  return err;
1324  }
1325 
1326  err = asd_seq_download_seqs(asd_ha);
1327  if (err) {
1328  asd_printk("couldn't download sequencers for %s\n",
1329  pci_name(asd_ha->pcidev));
1330  return err;
1331  }
1332 
1333  asd_seq_setup_seqs(asd_ha);
1334 
1335  return 0;
1336 }
1337 
1338 int asd_start_seqs(struct asd_ha_struct *asd_ha)
1339 {
1340  int err;
1341  u8 lseq_mask;
1342  int lseq;
1343 
1344  err = asd_seq_start_cseq(asd_ha);
1345  if (err) {
1346  asd_printk("couldn't start CSEQ for %s\n",
1347  pci_name(asd_ha->pcidev));
1348  return err;
1349  }
1350 
1351  lseq_mask = asd_ha->hw_prof.enabled_phys;
1352  for_each_sequencer(lseq_mask, lseq_mask, lseq) {
1353  err = asd_seq_start_lseq(asd_ha, lseq);
1354  if (err) {
1355  asd_printk("coudln't start LSEQ %d for %s\n", lseq,
1356  pci_name(asd_ha->pcidev));
1357  return err;
1358  }
1359  }
1360 
1361  return 0;
1362 }
1363 
1381 void asd_update_port_links(struct asd_ha_struct *asd_ha, struct asd_phy *phy)
1382 {
1383  const u8 phy_mask = (u8) phy->asd_port->phy_mask;
1384  u8 phy_is_up;
1385  u8 mask;
1386  int i, err;
1387  unsigned long flags;
1388 
1389  spin_lock_irqsave(&asd_ha->hw_prof.ddb_lock, flags);
1390  for_each_phy(phy_mask, mask, i)
1391  asd_ddbsite_write_byte(asd_ha, 0,
1393  port_map_by_links)+i,phy_mask);
1394 
1395  for (i = 0; i < 12; i++) {
1396  phy_is_up = asd_ddbsite_read_byte(asd_ha, 0,
1398  err = asd_ddbsite_update_byte(asd_ha, 0,
1400  phy_is_up,
1401  phy_is_up | phy_mask);
1402  if (!err)
1403  break;
1404  else if (err == -EFAULT) {
1405  asd_printk("phy_is_up: parity error in DDB 0\n");
1406  break;
1407  }
1408  }
1409  spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags);
1410 
1411  if (err)
1412  asd_printk("couldn't update DDB 0:error:%d\n", err);
1413 }
1414