aic94xx_seq.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  1. /*
  2. * Aic94xx SAS/SATA driver sequencer interface.
  3. *
  4. * Copyright (C) 2005 Adaptec, Inc. All rights reserved.
  5. * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
  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. #include <linux/delay.h>
  29. #include <linux/gfp.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"
  35. #include "aic94xx_seq.h"
  36. #include "aic94xx_dump.h"
  37. /* It takes no more than 0.05 us for an instruction
  38. * to complete. So waiting for 1 us should be more than
  39. * plenty.
  40. */
  41. #define PAUSE_DELAY 1
  42. #define PAUSE_TRIES 1000
  43. static const struct firmware *sequencer_fw;
  44. static u16 cseq_vecs[CSEQ_NUM_VECS], lseq_vecs[LSEQ_NUM_VECS], mode2_task,
  45. cseq_idle_loop, lseq_idle_loop;
  46. static const u8 *cseq_code, *lseq_code;
  47. static u32 cseq_code_size, lseq_code_size;
  48. static u16 first_scb_site_no = 0xFFFF;
  49. static u16 last_scb_site_no;
  50. /* ---------- Pause/Unpause CSEQ/LSEQ ---------- */
  51. /**
  52. * asd_pause_cseq - pause the central sequencer
  53. * @asd_ha: pointer to host adapter structure
  54. *
  55. * Return 0 on success, negative on failure.
  56. */
  57. static int asd_pause_cseq(struct asd_ha_struct *asd_ha)
  58. {
  59. int count = PAUSE_TRIES;
  60. u32 arp2ctl;
  61. arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL);
  62. if (arp2ctl & PAUSED)
  63. return 0;
  64. asd_write_reg_dword(asd_ha, CARP2CTL, arp2ctl | EPAUSE);
  65. do {
  66. arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL);
  67. if (arp2ctl & PAUSED)
  68. return 0;
  69. udelay(PAUSE_DELAY);
  70. } while (--count > 0);
  71. ASD_DPRINTK("couldn't pause CSEQ\n");
  72. return -1;
  73. }
  74. /**
  75. * asd_unpause_cseq - unpause the central sequencer.
  76. * @asd_ha: pointer to host adapter structure.
  77. *
  78. * Return 0 on success, negative on error.
  79. */
  80. static int asd_unpause_cseq(struct asd_ha_struct *asd_ha)
  81. {
  82. u32 arp2ctl;
  83. int count = PAUSE_TRIES;
  84. arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL);
  85. if (!(arp2ctl & PAUSED))
  86. return 0;
  87. asd_write_reg_dword(asd_ha, CARP2CTL, arp2ctl & ~EPAUSE);
  88. do {
  89. arp2ctl = asd_read_reg_dword(asd_ha, CARP2CTL);
  90. if (!(arp2ctl & PAUSED))
  91. return 0;
  92. udelay(PAUSE_DELAY);
  93. } while (--count > 0);
  94. ASD_DPRINTK("couldn't unpause the CSEQ\n");
  95. return -1;
  96. }
  97. /**
  98. * asd_seq_pause_lseq - pause a link sequencer
  99. * @asd_ha: pointer to a host adapter structure
  100. * @lseq: link sequencer of interest
  101. *
  102. * Return 0 on success, negative on error.
  103. */
  104. static int asd_seq_pause_lseq(struct asd_ha_struct *asd_ha, int lseq)
  105. {
  106. u32 arp2ctl;
  107. int count = PAUSE_TRIES;
  108. arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq));
  109. if (arp2ctl & PAUSED)
  110. return 0;
  111. asd_write_reg_dword(asd_ha, LmARP2CTL(lseq), arp2ctl | EPAUSE);
  112. do {
  113. arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq));
  114. if (arp2ctl & PAUSED)
  115. return 0;
  116. udelay(PAUSE_DELAY);
  117. } while (--count > 0);
  118. ASD_DPRINTK("couldn't pause LSEQ %d\n", lseq);
  119. return -1;
  120. }
  121. /**
  122. * asd_pause_lseq - pause the link sequencer(s)
  123. * @asd_ha: pointer to host adapter structure
  124. * @lseq_mask: mask of link sequencers of interest
  125. *
  126. * Return 0 on success, negative on failure.
  127. */
  128. static int asd_pause_lseq(struct asd_ha_struct *asd_ha, u8 lseq_mask)
  129. {
  130. int lseq;
  131. int err = 0;
  132. for_each_sequencer(lseq_mask, lseq_mask, lseq) {
  133. err = asd_seq_pause_lseq(asd_ha, lseq);
  134. if (err)
  135. return err;
  136. }
  137. return err;
  138. }
  139. /**
  140. * asd_seq_unpause_lseq - unpause a link sequencer
  141. * @asd_ha: pointer to host adapter structure
  142. * @lseq: link sequencer of interest
  143. *
  144. * Return 0 on success, negative on error.
  145. */
  146. static int asd_seq_unpause_lseq(struct asd_ha_struct *asd_ha, int lseq)
  147. {
  148. u32 arp2ctl;
  149. int count = PAUSE_TRIES;
  150. arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq));
  151. if (!(arp2ctl & PAUSED))
  152. return 0;
  153. asd_write_reg_dword(asd_ha, LmARP2CTL(lseq), arp2ctl & ~EPAUSE);
  154. do {
  155. arp2ctl = asd_read_reg_dword(asd_ha, LmARP2CTL(lseq));
  156. if (!(arp2ctl & PAUSED))
  157. return 0;
  158. udelay(PAUSE_DELAY);
  159. } while (--count > 0);
  160. ASD_DPRINTK("couldn't unpause LSEQ %d\n", lseq);
  161. return 0;
  162. }
  163. /* ---------- Downloading CSEQ/LSEQ microcode ---------- */
  164. static int asd_verify_cseq(struct asd_ha_struct *asd_ha, const u8 *_prog,
  165. u32 size)
  166. {
  167. u32 addr = CSEQ_RAM_REG_BASE_ADR;
  168. const u32 *prog = (u32 *) _prog;
  169. u32 i;
  170. for (i = 0; i < size; i += 4, prog++, addr += 4) {
  171. u32 val = asd_read_reg_dword(asd_ha, addr);
  172. if (le32_to_cpu(*prog) != val) {
  173. asd_printk("%s: cseq verify failed at %u "
  174. "read:0x%x, wanted:0x%x\n",
  175. pci_name(asd_ha->pcidev),
  176. i, val, le32_to_cpu(*prog));
  177. return -1;
  178. }
  179. }
  180. ASD_DPRINTK("verified %d bytes, passed\n", size);
  181. return 0;
  182. }
  183. /**
  184. * asd_verify_lseq - verify the microcode of a link sequencer
  185. * @asd_ha: pointer to host adapter structure
  186. * @_prog: pointer to the microcode
  187. * @size: size of the microcode in bytes
  188. * @lseq: link sequencer of interest
  189. *
  190. * The link sequencer code is accessed in 4 KB pages, which are selected
  191. * by setting LmRAMPAGE (bits 8 and 9) of the LmBISTCTL1 register.
  192. * The 10 KB LSEQm instruction code is mapped, page at a time, at
  193. * LmSEQRAM address.
  194. */
  195. static int asd_verify_lseq(struct asd_ha_struct *asd_ha, const u8 *_prog,
  196. u32 size, int lseq)
  197. {
  198. #define LSEQ_CODEPAGE_SIZE 4096
  199. int pages = (size + LSEQ_CODEPAGE_SIZE - 1) / LSEQ_CODEPAGE_SIZE;
  200. u32 page;
  201. const u32 *prog = (u32 *) _prog;
  202. for (page = 0; page < pages; page++) {
  203. u32 i;
  204. asd_write_reg_dword(asd_ha, LmBISTCTL1(lseq),
  205. page << LmRAMPAGE_LSHIFT);
  206. for (i = 0; size > 0 && i < LSEQ_CODEPAGE_SIZE;
  207. i += 4, prog++, size-=4) {
  208. u32 val = asd_read_reg_dword(asd_ha, LmSEQRAM(lseq)+i);
  209. if (le32_to_cpu(*prog) != val) {
  210. asd_printk("%s: LSEQ%d verify failed "
  211. "page:%d, offs:%d\n",
  212. pci_name(asd_ha->pcidev),
  213. lseq, page, i);
  214. return -1;
  215. }
  216. }
  217. }
  218. ASD_DPRINTK("LSEQ%d verified %d bytes, passed\n", lseq,
  219. (int)((u8 *)prog-_prog));
  220. return 0;
  221. }
  222. /**
  223. * asd_verify_seq -- verify CSEQ/LSEQ microcode
  224. * @asd_ha: pointer to host adapter structure
  225. * @prog: pointer to microcode
  226. * @size: size of the microcode
  227. * @lseq_mask: if 0, verify CSEQ microcode, else mask of LSEQs of interest
  228. *
  229. * Return 0 if microcode is correct, negative on mismatch.
  230. */
  231. static int asd_verify_seq(struct asd_ha_struct *asd_ha, const u8 *prog,
  232. u32 size, u8 lseq_mask)
  233. {
  234. if (lseq_mask == 0)
  235. return asd_verify_cseq(asd_ha, prog, size);
  236. else {
  237. int lseq, err;
  238. for_each_sequencer(lseq_mask, lseq_mask, lseq) {
  239. err = asd_verify_lseq(asd_ha, prog, size, lseq);
  240. if (err)
  241. return err;
  242. }
  243. }
  244. return 0;
  245. }
  246. #define ASD_DMA_MODE_DOWNLOAD
  247. #ifdef ASD_DMA_MODE_DOWNLOAD
  248. /* This is the size of the CSEQ Mapped instruction page */
  249. #define MAX_DMA_OVLY_COUNT ((1U << 14)-1)
  250. static int asd_download_seq(struct asd_ha_struct *asd_ha,
  251. const u8 * const prog, u32 size, u8 lseq_mask)
  252. {
  253. u32 comstaten;
  254. u32 reg;
  255. int page;
  256. const int pages = (size + MAX_DMA_OVLY_COUNT - 1) / MAX_DMA_OVLY_COUNT;
  257. struct asd_dma_tok *token;
  258. int err = 0;
  259. if (size % 4) {
  260. asd_printk("sequencer program not multiple of 4\n");
  261. return -1;
  262. }
  263. asd_pause_cseq(asd_ha);
  264. asd_pause_lseq(asd_ha, 0xFF);
  265. /* save, disable and clear interrupts */
  266. comstaten = asd_read_reg_dword(asd_ha, COMSTATEN);
  267. asd_write_reg_dword(asd_ha, COMSTATEN, 0);
  268. asd_write_reg_dword(asd_ha, COMSTAT, COMSTAT_MASK);
  269. asd_write_reg_dword(asd_ha, CHIMINTEN, RST_CHIMINTEN);
  270. asd_write_reg_dword(asd_ha, CHIMINT, CHIMINT_MASK);
  271. token = asd_alloc_coherent(asd_ha, MAX_DMA_OVLY_COUNT, GFP_KERNEL);
  272. if (!token) {
  273. asd_printk("out of memory for dma SEQ download\n");
  274. err = -ENOMEM;
  275. goto out;
  276. }
  277. ASD_DPRINTK("dma-ing %d bytes\n", size);
  278. for (page = 0; page < pages; page++) {
  279. int i;
  280. u32 left = min(size-page*MAX_DMA_OVLY_COUNT,
  281. (u32)MAX_DMA_OVLY_COUNT);
  282. memcpy(token->vaddr, prog + page*MAX_DMA_OVLY_COUNT, left);
  283. asd_write_reg_addr(asd_ha, OVLYDMAADR, token->dma_handle);
  284. asd_write_reg_dword(asd_ha, OVLYDMACNT, left);
  285. reg = !page ? RESETOVLYDMA : 0;
  286. reg |= (STARTOVLYDMA | OVLYHALTERR);
  287. reg |= (lseq_mask ? (((u32)lseq_mask) << 8) : OVLYCSEQ);
  288. /* Start DMA. */
  289. asd_write_reg_dword(asd_ha, OVLYDMACTL, reg);
  290. for (i = PAUSE_TRIES*100; i > 0; i--) {
  291. u32 dmadone = asd_read_reg_dword(asd_ha, OVLYDMACTL);
  292. if (!(dmadone & OVLYDMAACT))
  293. break;
  294. udelay(PAUSE_DELAY);
  295. }
  296. }
  297. reg = asd_read_reg_dword(asd_ha, COMSTAT);
  298. if (!(reg & OVLYDMADONE) || (reg & OVLYERR)
  299. || (asd_read_reg_dword(asd_ha, CHIMINT) & DEVEXCEPT_MASK)){
  300. asd_printk("%s: error DMA-ing sequencer code\n",
  301. pci_name(asd_ha->pcidev));
  302. err = -ENODEV;
  303. }
  304. asd_free_coherent(asd_ha, token);
  305. out:
  306. asd_write_reg_dword(asd_ha, COMSTATEN, comstaten);
  307. return err ? : asd_verify_seq(asd_ha, prog, size, lseq_mask);
  308. }
  309. #else /* ASD_DMA_MODE_DOWNLOAD */
  310. static int asd_download_seq(struct asd_ha_struct *asd_ha, const u8 *_prog,
  311. u32 size, u8 lseq_mask)
  312. {
  313. int i;
  314. u32 reg = 0;
  315. const u32 *prog = (u32 *) _prog;
  316. if (size % 4) {
  317. asd_printk("sequencer program not multiple of 4\n");
  318. return -1;
  319. }
  320. asd_pause_cseq(asd_ha);
  321. asd_pause_lseq(asd_ha, 0xFF);
  322. reg |= (lseq_mask ? (((u32)lseq_mask) << 8) : OVLYCSEQ);
  323. reg |= PIOCMODE;
  324. asd_write_reg_dword(asd_ha, OVLYDMACNT, size);
  325. asd_write_reg_dword(asd_ha, OVLYDMACTL, reg);
  326. ASD_DPRINTK("downloading %s sequencer%s in PIO mode...\n",
  327. lseq_mask ? "LSEQ" : "CSEQ", lseq_mask ? "s" : "");
  328. for (i = 0; i < size; i += 4, prog++)
  329. asd_write_reg_dword(asd_ha, SPIODATA, *prog);
  330. reg = (reg & ~PIOCMODE) | OVLYHALTERR;
  331. asd_write_reg_dword(asd_ha, OVLYDMACTL, reg);
  332. return asd_verify_seq(asd_ha, _prog, size, lseq_mask);
  333. }
  334. #endif /* ASD_DMA_MODE_DOWNLOAD */
  335. /**
  336. * asd_seq_download_seqs - download the sequencer microcode
  337. * @asd_ha: pointer to host adapter structure
  338. *
  339. * Download the central and link sequencer microcode.
  340. */
  341. static int asd_seq_download_seqs(struct asd_ha_struct *asd_ha)
  342. {
  343. int err;
  344. if (!asd_ha->hw_prof.enabled_phys) {
  345. asd_printk("%s: no enabled phys!\n", pci_name(asd_ha->pcidev));
  346. return -ENODEV;
  347. }
  348. /* Download the CSEQ */
  349. ASD_DPRINTK("downloading CSEQ...\n");
  350. err = asd_download_seq(asd_ha, cseq_code, cseq_code_size, 0);
  351. if (err) {
  352. asd_printk("CSEQ download failed:%d\n", err);
  353. return err;
  354. }
  355. /* Download the Link Sequencers code. All of the Link Sequencers
  356. * microcode can be downloaded at the same time.
  357. */
  358. ASD_DPRINTK("downloading LSEQs...\n");
  359. err = asd_download_seq(asd_ha, lseq_code, lseq_code_size,
  360. asd_ha->hw_prof.enabled_phys);
  361. if (err) {
  362. /* Try it one at a time */
  363. u8 lseq;
  364. u8 lseq_mask = asd_ha->hw_prof.enabled_phys;
  365. for_each_sequencer(lseq_mask, lseq_mask, lseq) {
  366. err = asd_download_seq(asd_ha, lseq_code,
  367. lseq_code_size, 1<<lseq);
  368. if (err)
  369. break;
  370. }
  371. }
  372. if (err)
  373. asd_printk("LSEQs download failed:%d\n", err);
  374. return err;
  375. }
  376. /* ---------- Initializing the chip, chip memory, etc. ---------- */
  377. /**
  378. * asd_init_cseq_mip - initialize CSEQ mode independent pages 4-7
  379. * @asd_ha: pointer to host adapter structure
  380. */
  381. static void asd_init_cseq_mip(struct asd_ha_struct *asd_ha)
  382. {
  383. /* CSEQ Mode Independent, page 4 setup. */
  384. asd_write_reg_word(asd_ha, CSEQ_Q_EXE_HEAD, 0xFFFF);
  385. asd_write_reg_word(asd_ha, CSEQ_Q_EXE_TAIL, 0xFFFF);
  386. asd_write_reg_word(asd_ha, CSEQ_Q_DONE_HEAD, 0xFFFF);
  387. asd_write_reg_word(asd_ha, CSEQ_Q_DONE_TAIL, 0xFFFF);
  388. asd_write_reg_word(asd_ha, CSEQ_Q_SEND_HEAD, 0xFFFF);
  389. asd_write_reg_word(asd_ha, CSEQ_Q_SEND_TAIL, 0xFFFF);
  390. asd_write_reg_word(asd_ha, CSEQ_Q_DMA2CHIM_HEAD, 0xFFFF);
  391. asd_write_reg_word(asd_ha, CSEQ_Q_DMA2CHIM_TAIL, 0xFFFF);
  392. asd_write_reg_word(asd_ha, CSEQ_Q_COPY_HEAD, 0xFFFF);
  393. asd_write_reg_word(asd_ha, CSEQ_Q_COPY_TAIL, 0xFFFF);
  394. asd_write_reg_word(asd_ha, CSEQ_REG0, 0);
  395. asd_write_reg_word(asd_ha, CSEQ_REG1, 0);
  396. asd_write_reg_dword(asd_ha, CSEQ_REG2, 0);
  397. asd_write_reg_byte(asd_ha, CSEQ_LINK_CTL_Q_MAP, 0);
  398. {
  399. u8 con = asd_read_reg_byte(asd_ha, CCONEXIST);
  400. u8 val = hweight8(con);
  401. asd_write_reg_byte(asd_ha, CSEQ_MAX_CSEQ_MODE, (val<<4)|val);
  402. }
  403. asd_write_reg_word(asd_ha, CSEQ_FREE_LIST_HACK_COUNT, 0);
  404. /* CSEQ Mode independent, page 5 setup. */
  405. asd_write_reg_dword(asd_ha, CSEQ_EST_NEXUS_REQ_QUEUE, 0);
  406. asd_write_reg_dword(asd_ha, CSEQ_EST_NEXUS_REQ_QUEUE+4, 0);
  407. asd_write_reg_dword(asd_ha, CSEQ_EST_NEXUS_REQ_COUNT, 0);
  408. asd_write_reg_dword(asd_ha, CSEQ_EST_NEXUS_REQ_COUNT+4, 0);
  409. asd_write_reg_word(asd_ha, CSEQ_Q_EST_NEXUS_HEAD, 0xFFFF);
  410. asd_write_reg_word(asd_ha, CSEQ_Q_EST_NEXUS_TAIL, 0xFFFF);
  411. asd_write_reg_word(asd_ha, CSEQ_NEED_EST_NEXUS_SCB, 0);
  412. asd_write_reg_byte(asd_ha, CSEQ_EST_NEXUS_REQ_HEAD, 0);
  413. asd_write_reg_byte(asd_ha, CSEQ_EST_NEXUS_REQ_TAIL, 0);
  414. asd_write_reg_byte(asd_ha, CSEQ_EST_NEXUS_SCB_OFFSET, 0);
  415. /* CSEQ Mode independent, page 6 setup. */
  416. asd_write_reg_word(asd_ha, CSEQ_INT_ROUT_RET_ADDR0, 0);
  417. asd_write_reg_word(asd_ha, CSEQ_INT_ROUT_RET_ADDR1, 0);
  418. asd_write_reg_word(asd_ha, CSEQ_INT_ROUT_SCBPTR, 0);
  419. asd_write_reg_byte(asd_ha, CSEQ_INT_ROUT_MODE, 0);
  420. asd_write_reg_byte(asd_ha, CSEQ_ISR_SCRATCH_FLAGS, 0);
  421. asd_write_reg_word(asd_ha, CSEQ_ISR_SAVE_SINDEX, 0);
  422. asd_write_reg_word(asd_ha, CSEQ_ISR_SAVE_DINDEX, 0);
  423. asd_write_reg_word(asd_ha, CSEQ_Q_MONIRTT_HEAD, 0xFFFF);
  424. asd_write_reg_word(asd_ha, CSEQ_Q_MONIRTT_TAIL, 0xFFFF);
  425. /* Calculate the free scb mask. */
  426. {
  427. u16 cmdctx = asd_get_cmdctx_size(asd_ha);
  428. cmdctx = (~((cmdctx/128)-1)) >> 8;
  429. asd_write_reg_byte(asd_ha, CSEQ_FREE_SCB_MASK, (u8)cmdctx);
  430. }
  431. asd_write_reg_word(asd_ha, CSEQ_BUILTIN_FREE_SCB_HEAD,
  432. first_scb_site_no);
  433. asd_write_reg_word(asd_ha, CSEQ_BUILTIN_FREE_SCB_TAIL,
  434. last_scb_site_no);
  435. asd_write_reg_word(asd_ha, CSEQ_EXTENDED_FREE_SCB_HEAD, 0xFFFF);
  436. asd_write_reg_word(asd_ha, CSEQ_EXTENDED_FREE_SCB_TAIL, 0xFFFF);
  437. /* CSEQ Mode independent, page 7 setup. */
  438. asd_write_reg_dword(asd_ha, CSEQ_EMPTY_REQ_QUEUE, 0);
  439. asd_write_reg_dword(asd_ha, CSEQ_EMPTY_REQ_QUEUE+4, 0);
  440. asd_write_reg_dword(asd_ha, CSEQ_EMPTY_REQ_COUNT, 0);
  441. asd_write_reg_dword(asd_ha, CSEQ_EMPTY_REQ_COUNT+4, 0);
  442. asd_write_reg_word(asd_ha, CSEQ_Q_EMPTY_HEAD, 0xFFFF);
  443. asd_write_reg_word(asd_ha, CSEQ_Q_EMPTY_TAIL, 0xFFFF);
  444. asd_write_reg_word(asd_ha, CSEQ_NEED_EMPTY_SCB, 0);
  445. asd_write_reg_byte(asd_ha, CSEQ_EMPTY_REQ_HEAD, 0);
  446. asd_write_reg_byte(asd_ha, CSEQ_EMPTY_REQ_TAIL, 0);
  447. asd_write_reg_byte(asd_ha, CSEQ_EMPTY_SCB_OFFSET, 0);
  448. asd_write_reg_word(asd_ha, CSEQ_PRIMITIVE_DATA, 0);
  449. asd_write_reg_dword(asd_ha, CSEQ_TIMEOUT_CONST, 0);
  450. }
  451. /**
  452. * asd_init_cseq_mdp - initialize CSEQ Mode dependent pages
  453. * @asd_ha: pointer to host adapter structure
  454. */
  455. static void asd_init_cseq_mdp(struct asd_ha_struct *asd_ha)
  456. {
  457. int i;
  458. int moffs;
  459. moffs = CSEQ_PAGE_SIZE * 2;
  460. /* CSEQ Mode dependent, modes 0-7, page 0 setup. */
  461. for (i = 0; i < 8; i++) {
  462. asd_write_reg_word(asd_ha, i*moffs+CSEQ_LRM_SAVE_SINDEX, 0);
  463. asd_write_reg_word(asd_ha, i*moffs+CSEQ_LRM_SAVE_SCBPTR, 0);
  464. asd_write_reg_word(asd_ha, i*moffs+CSEQ_Q_LINK_HEAD, 0xFFFF);
  465. asd_write_reg_word(asd_ha, i*moffs+CSEQ_Q_LINK_TAIL, 0xFFFF);
  466. asd_write_reg_byte(asd_ha, i*moffs+CSEQ_LRM_SAVE_SCRPAGE, 0);
  467. }
  468. /* CSEQ Mode dependent, mode 0-7, page 1 and 2 shall be ignored. */
  469. /* CSEQ Mode dependent, mode 8, page 0 setup. */
  470. asd_write_reg_word(asd_ha, CSEQ_RET_ADDR, 0xFFFF);
  471. asd_write_reg_word(asd_ha, CSEQ_RET_SCBPTR, 0);
  472. asd_write_reg_word(asd_ha, CSEQ_SAVE_SCBPTR, 0);
  473. asd_write_reg_word(asd_ha, CSEQ_EMPTY_TRANS_CTX, 0);
  474. asd_write_reg_word(asd_ha, CSEQ_RESP_LEN, 0);
  475. asd_write_reg_word(asd_ha, CSEQ_TMF_SCBPTR, 0);
  476. asd_write_reg_word(asd_ha, CSEQ_GLOBAL_PREV_SCB, 0);
  477. asd_write_reg_word(asd_ha, CSEQ_GLOBAL_HEAD, 0);
  478. asd_write_reg_word(asd_ha, CSEQ_CLEAR_LU_HEAD, 0);
  479. asd_write_reg_byte(asd_ha, CSEQ_TMF_OPCODE, 0);
  480. asd_write_reg_byte(asd_ha, CSEQ_SCRATCH_FLAGS, 0);
  481. asd_write_reg_word(asd_ha, CSEQ_HSB_SITE, 0);
  482. asd_write_reg_word(asd_ha, CSEQ_FIRST_INV_SCB_SITE,
  483. (u16)last_scb_site_no+1);
  484. asd_write_reg_word(asd_ha, CSEQ_FIRST_INV_DDB_SITE,
  485. (u16)asd_ha->hw_prof.max_ddbs);
  486. /* CSEQ Mode dependent, mode 8, page 1 setup. */
  487. asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CLEAR, 0);
  488. asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CLEAR + 4, 0);
  489. asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CHECK, 0);
  490. asd_write_reg_dword(asd_ha, CSEQ_LUN_TO_CHECK + 4, 0);
  491. /* CSEQ Mode dependent, mode 8, page 2 setup. */
  492. /* Tell the sequencer the bus address of the first SCB. */
  493. asd_write_reg_addr(asd_ha, CSEQ_HQ_NEW_POINTER,
  494. asd_ha->seq.next_scb.dma_handle);
  495. ASD_DPRINTK("First SCB dma_handle: 0x%llx\n",
  496. (unsigned long long)asd_ha->seq.next_scb.dma_handle);
  497. /* Tell the sequencer the first Done List entry address. */
  498. asd_write_reg_addr(asd_ha, CSEQ_HQ_DONE_BASE,
  499. asd_ha->seq.actual_dl->dma_handle);
  500. /* Initialize the Q_DONE_POINTER with the least significant
  501. * 4 bytes of the first Done List address. */
  502. asd_write_reg_dword(asd_ha, CSEQ_HQ_DONE_POINTER,
  503. ASD_BUSADDR_LO(asd_ha->seq.actual_dl->dma_handle));
  504. asd_write_reg_byte(asd_ha, CSEQ_HQ_DONE_PASS, ASD_DEF_DL_TOGGLE);
  505. /* CSEQ Mode dependent, mode 8, page 3 shall be ignored. */
  506. }
  507. /**
  508. * asd_init_cseq_scratch -- setup and init CSEQ
  509. * @asd_ha: pointer to host adapter structure
  510. *
  511. * Setup and initialize Central sequencers. Initialize the mode
  512. * independent and dependent scratch page to the default settings.
  513. */
  514. static void asd_init_cseq_scratch(struct asd_ha_struct *asd_ha)
  515. {
  516. asd_init_cseq_mip(asd_ha);
  517. asd_init_cseq_mdp(asd_ha);
  518. }
  519. /**
  520. * asd_init_lseq_mip -- initialize LSEQ Mode independent pages 0-3
  521. * @asd_ha: pointer to host adapter structure
  522. */
  523. static void asd_init_lseq_mip(struct asd_ha_struct *asd_ha, u8 lseq)
  524. {
  525. int i;
  526. /* LSEQ Mode independent page 0 setup. */
  527. asd_write_reg_word(asd_ha, LmSEQ_Q_TGTXFR_HEAD(lseq), 0xFFFF);
  528. asd_write_reg_word(asd_ha, LmSEQ_Q_TGTXFR_TAIL(lseq), 0xFFFF);
  529. asd_write_reg_byte(asd_ha, LmSEQ_LINK_NUMBER(lseq), lseq);
  530. asd_write_reg_byte(asd_ha, LmSEQ_SCRATCH_FLAGS(lseq),
  531. ASD_NOTIFY_ENABLE_SPINUP);
  532. asd_write_reg_dword(asd_ha, LmSEQ_CONNECTION_STATE(lseq),0x08000000);
  533. asd_write_reg_word(asd_ha, LmSEQ_CONCTL(lseq), 0);
  534. asd_write_reg_byte(asd_ha, LmSEQ_CONSTAT(lseq), 0);
  535. asd_write_reg_byte(asd_ha, LmSEQ_CONNECTION_MODES(lseq), 0);
  536. asd_write_reg_word(asd_ha, LmSEQ_REG1_ISR(lseq), 0);
  537. asd_write_reg_word(asd_ha, LmSEQ_REG2_ISR(lseq), 0);
  538. asd_write_reg_word(asd_ha, LmSEQ_REG3_ISR(lseq), 0);
  539. asd_write_reg_dword(asd_ha, LmSEQ_REG0_ISR(lseq), 0);
  540. asd_write_reg_dword(asd_ha, LmSEQ_REG0_ISR(lseq)+4, 0);
  541. /* LSEQ Mode independent page 1 setup. */
  542. asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR0(lseq), 0xFFFF);
  543. asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR1(lseq), 0xFFFF);
  544. asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR2(lseq), 0xFFFF);
  545. asd_write_reg_word(asd_ha, LmSEQ_EST_NEXUS_SCBPTR3(lseq), 0xFFFF);
  546. asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_OPCODE0(lseq), 0);
  547. asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_OPCODE1(lseq), 0);
  548. asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_OPCODE2(lseq), 0);
  549. asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_OPCODE3(lseq), 0);
  550. asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_HEAD(lseq), 0);
  551. asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_SCB_TAIL(lseq), 0);
  552. asd_write_reg_byte(asd_ha, LmSEQ_EST_NEXUS_BUF_AVAIL(lseq), 0);
  553. asd_write_reg_dword(asd_ha, LmSEQ_TIMEOUT_CONST(lseq), 0);
  554. asd_write_reg_word(asd_ha, LmSEQ_ISR_SAVE_SINDEX(lseq), 0);
  555. asd_write_reg_word(asd_ha, LmSEQ_ISR_SAVE_DINDEX(lseq), 0);
  556. /* LSEQ Mode Independent page 2 setup. */
  557. asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR0(lseq), 0xFFFF);
  558. asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR1(lseq), 0xFFFF);
  559. asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR2(lseq), 0xFFFF);
  560. asd_write_reg_word(asd_ha, LmSEQ_EMPTY_SCB_PTR3(lseq), 0xFFFF);
  561. asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD0(lseq), 0);
  562. asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD1(lseq), 0);
  563. asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD2(lseq), 0);
  564. asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_OPCD3(lseq), 0);
  565. asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_HEAD(lseq), 0);
  566. asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_SCB_TAIL(lseq), 0);
  567. asd_write_reg_byte(asd_ha, LmSEQ_EMPTY_BUFS_AVAIL(lseq), 0);
  568. for (i = 0; i < 12; i += 4)
  569. asd_write_reg_dword(asd_ha, LmSEQ_ATA_SCR_REGS(lseq) + i, 0);
  570. /* LSEQ Mode Independent page 3 setup. */
  571. /* Device present timer timeout */
  572. asd_write_reg_dword(asd_ha, LmSEQ_DEV_PRES_TMR_TOUT_CONST(lseq),
  573. ASD_DEV_PRESENT_TIMEOUT);
  574. /* SATA interlock timer disabled */
  575. asd_write_reg_dword(asd_ha, LmSEQ_SATA_INTERLOCK_TIMEOUT(lseq),
  576. ASD_SATA_INTERLOCK_TIMEOUT);
  577. /* STP shutdown timer timeout constant, IGNORED by the sequencer,
  578. * always 0. */
  579. asd_write_reg_dword(asd_ha, LmSEQ_STP_SHUTDOWN_TIMEOUT(lseq),
  580. ASD_STP_SHUTDOWN_TIMEOUT);
  581. asd_write_reg_dword(asd_ha, LmSEQ_SRST_ASSERT_TIMEOUT(lseq),
  582. ASD_SRST_ASSERT_TIMEOUT);
  583. asd_write_reg_dword(asd_ha, LmSEQ_RCV_FIS_TIMEOUT(lseq),
  584. ASD_RCV_FIS_TIMEOUT);
  585. asd_write_reg_dword(asd_ha, LmSEQ_ONE_MILLISEC_TIMEOUT(lseq),
  586. ASD_ONE_MILLISEC_TIMEOUT);
  587. /* COM_INIT timer */
  588. asd_write_reg_dword(asd_ha, LmSEQ_TEN_MS_COMINIT_TIMEOUT(lseq),
  589. ASD_TEN_MILLISEC_TIMEOUT);
  590. asd_write_reg_dword(asd_ha, LmSEQ_SMP_RCV_TIMEOUT(lseq),
  591. ASD_SMP_RCV_TIMEOUT);
  592. }
  593. /**
  594. * asd_init_lseq_mdp -- initialize LSEQ mode dependent pages.
  595. * @asd_ha: pointer to host adapter structure
  596. */
  597. static void asd_init_lseq_mdp(struct asd_ha_struct *asd_ha, int lseq)
  598. {
  599. int i;
  600. u32 moffs;
  601. u16 ret_addr[] = {
  602. 0xFFFF, /* mode 0 */
  603. 0xFFFF, /* mode 1 */
  604. mode2_task, /* mode 2 */
  605. 0,
  606. 0xFFFF, /* mode 4/5 */
  607. 0xFFFF, /* mode 4/5 */
  608. };
  609. /*
  610. * Mode 0,1,2 and 4/5 have common field on page 0 for the first
  611. * 14 bytes.
  612. */
  613. for (i = 0; i < 3; i++) {
  614. moffs = i * LSEQ_MODE_SCRATCH_SIZE;
  615. asd_write_reg_word(asd_ha, LmSEQ_RET_ADDR(lseq)+moffs,
  616. ret_addr[i]);
  617. asd_write_reg_word(asd_ha, LmSEQ_REG0_MODE(lseq)+moffs, 0);
  618. asd_write_reg_word(asd_ha, LmSEQ_MODE_FLAGS(lseq)+moffs, 0);
  619. asd_write_reg_word(asd_ha, LmSEQ_RET_ADDR2(lseq)+moffs,0xFFFF);
  620. asd_write_reg_word(asd_ha, LmSEQ_RET_ADDR1(lseq)+moffs,0xFFFF);
  621. asd_write_reg_byte(asd_ha, LmSEQ_OPCODE_TO_CSEQ(lseq)+moffs,0);
  622. asd_write_reg_word(asd_ha, LmSEQ_DATA_TO_CSEQ(lseq)+moffs,0);
  623. }
  624. /*
  625. * Mode 5 page 0 overlaps the same scratch page with Mode 0 page 3.
  626. */
  627. asd_write_reg_word(asd_ha,
  628. LmSEQ_RET_ADDR(lseq)+LSEQ_MODE5_PAGE0_OFFSET,
  629. ret_addr[5]);
  630. asd_write_reg_word(asd_ha,
  631. LmSEQ_REG0_MODE(lseq)+LSEQ_MODE5_PAGE0_OFFSET,0);
  632. asd_write_reg_word(asd_ha,
  633. LmSEQ_MODE_FLAGS(lseq)+LSEQ_MODE5_PAGE0_OFFSET, 0);
  634. asd_write_reg_word(asd_ha,
  635. LmSEQ_RET_ADDR2(lseq)+LSEQ_MODE5_PAGE0_OFFSET,0xFFFF);
  636. asd_write_reg_word(asd_ha,
  637. LmSEQ_RET_ADDR1(lseq)+LSEQ_MODE5_PAGE0_OFFSET,0xFFFF);
  638. asd_write_reg_byte(asd_ha,
  639. LmSEQ_OPCODE_TO_CSEQ(lseq)+LSEQ_MODE5_PAGE0_OFFSET,0);
  640. asd_write_reg_word(asd_ha,
  641. LmSEQ_DATA_TO_CSEQ(lseq)+LSEQ_MODE5_PAGE0_OFFSET, 0);
  642. /* LSEQ Mode dependent 0, page 0 setup. */
  643. asd_write_reg_word(asd_ha, LmSEQ_FIRST_INV_DDB_SITE(lseq),
  644. (u16)asd_ha->hw_prof.max_ddbs);
  645. asd_write_reg_word(asd_ha, LmSEQ_EMPTY_TRANS_CTX(lseq), 0);
  646. asd_write_reg_word(asd_ha, LmSEQ_RESP_LEN(lseq), 0);
  647. asd_write_reg_word(asd_ha, LmSEQ_FIRST_INV_SCB_SITE(lseq),
  648. (u16)last_scb_site_no+1);
  649. asd_write_reg_word(asd_ha, LmSEQ_INTEN_SAVE(lseq),
  650. (u16) ((LmM0INTEN_MASK & 0xFFFF0000) >> 16));
  651. asd_write_reg_word(asd_ha, LmSEQ_INTEN_SAVE(lseq) + 2,
  652. (u16) LmM0INTEN_MASK & 0xFFFF);
  653. asd_write_reg_byte(asd_ha, LmSEQ_LINK_RST_FRM_LEN(lseq), 0);
  654. asd_write_reg_byte(asd_ha, LmSEQ_LINK_RST_PROTOCOL(lseq), 0);
  655. asd_write_reg_byte(asd_ha, LmSEQ_RESP_STATUS(lseq), 0);
  656. asd_write_reg_byte(asd_ha, LmSEQ_LAST_LOADED_SGE(lseq), 0);
  657. asd_write_reg_word(asd_ha, LmSEQ_SAVE_SCBPTR(lseq), 0);
  658. /* LSEQ mode dependent, mode 1, page 0 setup. */
  659. asd_write_reg_word(asd_ha, LmSEQ_Q_XMIT_HEAD(lseq), 0xFFFF);
  660. asd_write_reg_word(asd_ha, LmSEQ_M1_EMPTY_TRANS_CTX(lseq), 0);
  661. asd_write_reg_word(asd_ha, LmSEQ_INI_CONN_TAG(lseq), 0);
  662. asd_write_reg_byte(asd_ha, LmSEQ_FAILED_OPEN_STATUS(lseq), 0);
  663. asd_write_reg_byte(asd_ha, LmSEQ_XMIT_REQUEST_TYPE(lseq), 0);
  664. asd_write_reg_byte(asd_ha, LmSEQ_M1_RESP_STATUS(lseq), 0);
  665. asd_write_reg_byte(asd_ha, LmSEQ_M1_LAST_LOADED_SGE(lseq), 0);
  666. asd_write_reg_word(asd_ha, LmSEQ_M1_SAVE_SCBPTR(lseq), 0);
  667. /* LSEQ Mode dependent mode 2, page 0 setup */
  668. asd_write_reg_word(asd_ha, LmSEQ_PORT_COUNTER(lseq), 0);
  669. asd_write_reg_word(asd_ha, LmSEQ_PM_TABLE_PTR(lseq), 0);
  670. asd_write_reg_word(asd_ha, LmSEQ_SATA_INTERLOCK_TMR_SAVE(lseq), 0);
  671. asd_write_reg_word(asd_ha, LmSEQ_IP_BITL(lseq), 0);
  672. asd_write_reg_word(asd_ha, LmSEQ_COPY_SMP_CONN_TAG(lseq), 0);
  673. asd_write_reg_byte(asd_ha, LmSEQ_P0M2_OFFS1AH(lseq), 0);
  674. /* LSEQ Mode dependent, mode 4/5, page 0 setup. */
  675. asd_write_reg_byte(asd_ha, LmSEQ_SAVED_OOB_STATUS(lseq), 0);
  676. asd_write_reg_byte(asd_ha, LmSEQ_SAVED_OOB_MODE(lseq), 0);
  677. asd_write_reg_word(asd_ha, LmSEQ_Q_LINK_HEAD(lseq), 0xFFFF);
  678. asd_write_reg_byte(asd_ha, LmSEQ_LINK_RST_ERR(lseq), 0);
  679. asd_write_reg_byte(asd_ha, LmSEQ_SAVED_OOB_SIGNALS(lseq), 0);
  680. asd_write_reg_byte(asd_ha, LmSEQ_SAS_RESET_MODE(lseq), 0);
  681. asd_write_reg_byte(asd_ha, LmSEQ_LINK_RESET_RETRY_COUNT(lseq), 0);
  682. asd_write_reg_byte(asd_ha, LmSEQ_NUM_LINK_RESET_RETRIES(lseq), 0);
  683. asd_write_reg_word(asd_ha, LmSEQ_OOB_INT_ENABLES(lseq), 0);
  684. /*
  685. * Set the desired interval between transmissions of the NOTIFY
  686. * (ENABLE SPINUP) primitive. Must be initialized to val - 1.
  687. */
  688. asd_write_reg_word(asd_ha, LmSEQ_NOTIFY_TIMER_TIMEOUT(lseq),
  689. ASD_NOTIFY_TIMEOUT - 1);
  690. /* No delay for the first NOTIFY to be sent to the attached target. */
  691. asd_write_reg_word(asd_ha, LmSEQ_NOTIFY_TIMER_DOWN_COUNT(lseq),
  692. ASD_NOTIFY_DOWN_COUNT);
  693. asd_write_reg_word(asd_ha, LmSEQ_NOTIFY_TIMER_INITIAL_COUNT(lseq),
  694. ASD_NOTIFY_DOWN_COUNT);
  695. /* LSEQ Mode dependent, mode 0 and 1, page 1 setup. */
  696. for (i = 0; i < 2; i++) {
  697. int j;
  698. /* Start from Page 1 of Mode 0 and 1. */
  699. moffs = LSEQ_PAGE_SIZE + i*LSEQ_MODE_SCRATCH_SIZE;
  700. /* All the fields of page 1 can be initialized to 0. */
  701. for (j = 0; j < LSEQ_PAGE_SIZE; j += 4)
  702. asd_write_reg_dword(asd_ha, LmSCRATCH(lseq)+moffs+j,0);
  703. }
  704. /* LSEQ Mode dependent, mode 2, page 1 setup. */
  705. asd_write_reg_dword(asd_ha, LmSEQ_INVALID_DWORD_COUNT(lseq), 0);
  706. asd_write_reg_dword(asd_ha, LmSEQ_DISPARITY_ERROR_COUNT(lseq), 0);
  707. asd_write_reg_dword(asd_ha, LmSEQ_LOSS_OF_SYNC_COUNT(lseq), 0);
  708. /* LSEQ Mode dependent, mode 4/5, page 1. */
  709. for (i = 0; i < LSEQ_PAGE_SIZE; i+=4)
  710. asd_write_reg_dword(asd_ha, LmSEQ_FRAME_TYPE_MASK(lseq)+i, 0);
  711. asd_write_reg_byte(asd_ha, LmSEQ_FRAME_TYPE_MASK(lseq), 0xFF);
  712. asd_write_reg_byte(asd_ha, LmSEQ_HASHED_DEST_ADDR_MASK(lseq), 0xFF);
  713. asd_write_reg_byte(asd_ha, LmSEQ_HASHED_DEST_ADDR_MASK(lseq)+1,0xFF);
  714. asd_write_reg_byte(asd_ha, LmSEQ_HASHED_DEST_ADDR_MASK(lseq)+2,0xFF);
  715. asd_write_reg_byte(asd_ha, LmSEQ_HASHED_SRC_ADDR_MASK(lseq), 0xFF);
  716. asd_write_reg_byte(asd_ha, LmSEQ_HASHED_SRC_ADDR_MASK(lseq)+1, 0xFF);
  717. asd_write_reg_byte(asd_ha, LmSEQ_HASHED_SRC_ADDR_MASK(lseq)+2, 0xFF);
  718. asd_write_reg_dword(asd_ha, LmSEQ_DATA_OFFSET(lseq), 0xFFFFFFFF);
  719. /* LSEQ Mode dependent, mode 0, page 2 setup. */
  720. asd_write_reg_dword(asd_ha, LmSEQ_SMP_RCV_TIMER_TERM_TS(lseq), 0);
  721. asd_write_reg_byte(asd_ha, LmSEQ_DEVICE_BITS(lseq), 0);
  722. asd_write_reg_word(asd_ha, LmSEQ_SDB_DDB(lseq), 0);
  723. asd_write_reg_byte(asd_ha, LmSEQ_SDB_NUM_TAGS(lseq), 0);
  724. asd_write_reg_byte(asd_ha, LmSEQ_SDB_CURR_TAG(lseq), 0);
  725. /* LSEQ Mode Dependent 1, page 2 setup. */
  726. asd_write_reg_dword(asd_ha, LmSEQ_TX_ID_ADDR_FRAME(lseq), 0);
  727. asd_write_reg_dword(asd_ha, LmSEQ_TX_ID_ADDR_FRAME(lseq)+4, 0);
  728. asd_write_reg_dword(asd_ha, LmSEQ_OPEN_TIMER_TERM_TS(lseq), 0);
  729. asd_write_reg_dword(asd_ha, LmSEQ_SRST_AS_TIMER_TERM_TS(lseq), 0);
  730. asd_write_reg_dword(asd_ha, LmSEQ_LAST_LOADED_SG_EL(lseq), 0);
  731. /* LSEQ Mode Dependent 2, page 2 setup. */
  732. /* The LmSEQ_STP_SHUTDOWN_TIMER_TERM_TS is IGNORED by the sequencer,
  733. * i.e. always 0. */
  734. asd_write_reg_dword(asd_ha, LmSEQ_STP_SHUTDOWN_TIMER_TERM_TS(lseq),0);
  735. asd_write_reg_dword(asd_ha, LmSEQ_CLOSE_TIMER_TERM_TS(lseq), 0);
  736. asd_write_reg_dword(asd_ha, LmSEQ_BREAK_TIMER_TERM_TS(lseq), 0);
  737. asd_write_reg_dword(asd_ha, LmSEQ_DWS_RESET_TIMER_TERM_TS(lseq), 0);
  738. asd_write_reg_dword(asd_ha,LmSEQ_SATA_INTERLOCK_TIMER_TERM_TS(lseq),0);
  739. asd_write_reg_dword(asd_ha, LmSEQ_MCTL_TIMER_TERM_TS(lseq), 0);
  740. /* LSEQ Mode Dependent 4/5, page 2 setup. */
  741. asd_write_reg_dword(asd_ha, LmSEQ_COMINIT_TIMER_TERM_TS(lseq), 0);
  742. asd_write_reg_dword(asd_ha, LmSEQ_RCV_ID_TIMER_TERM_TS(lseq), 0);
  743. asd_write_reg_dword(asd_ha, LmSEQ_RCV_FIS_TIMER_TERM_TS(lseq), 0);
  744. asd_write_reg_dword(asd_ha, LmSEQ_DEV_PRES_TIMER_TERM_TS(lseq), 0);
  745. }
  746. /**
  747. * asd_init_lseq_scratch -- setup and init link sequencers
  748. * @asd_ha: pointer to host adapter struct
  749. */
  750. static void asd_init_lseq_scratch(struct asd_ha_struct *asd_ha)
  751. {
  752. u8 lseq;
  753. u8 lseq_mask;
  754. lseq_mask = asd_ha->hw_prof.enabled_phys;
  755. for_each_sequencer(lseq_mask, lseq_mask, lseq) {
  756. asd_init_lseq_mip(asd_ha, lseq);
  757. asd_init_lseq_mdp(asd_ha, lseq);
  758. }
  759. }
  760. /**
  761. * asd_init_scb_sites -- initialize sequencer SCB sites (memory).
  762. * @asd_ha: pointer to host adapter structure
  763. *
  764. * This should be done before initializing common CSEQ and LSEQ
  765. * scratch since those areas depend on some computed values here,
  766. * last_scb_site_no, etc.
  767. */
  768. static void asd_init_scb_sites(struct asd_ha_struct *asd_ha)
  769. {
  770. u16 site_no;
  771. u16 max_scbs = 0;
  772. for (site_no = asd_ha->hw_prof.max_scbs-1;
  773. site_no != (u16) -1;
  774. site_no--) {
  775. u16 i;
  776. /* Initialize all fields in the SCB site to 0. */
  777. for (i = 0; i < ASD_SCB_SIZE; i += 4)
  778. asd_scbsite_write_dword(asd_ha, site_no, i, 0);
  779. /* Initialize SCB Site Opcode field to invalid. */
  780. asd_scbsite_write_byte(asd_ha, site_no,
  781. offsetof(struct scb_header, opcode),
  782. 0xFF);
  783. /* Initialize SCB Site Flags field to mean a response
  784. * frame has been received. This means inadvertent
  785. * frames received to be dropped. */
  786. asd_scbsite_write_byte(asd_ha, site_no, 0x49, 0x01);
  787. /* Workaround needed by SEQ to fix a SATA issue is to exclude
  788. * certain SCB sites from the free list. */
  789. if (!SCB_SITE_VALID(site_no))
  790. continue;
  791. if (last_scb_site_no == 0)
  792. last_scb_site_no = site_no;
  793. /* For every SCB site, we need to initialize the
  794. * following fields: Q_NEXT, SCB_OPCODE, SCB_FLAGS,
  795. * and SG Element Flag. */
  796. /* Q_NEXT field of the last SCB is invalidated. */
  797. asd_scbsite_write_word(asd_ha, site_no, 0, first_scb_site_no);
  798. first_scb_site_no = site_no;
  799. max_scbs++;
  800. }
  801. asd_ha->hw_prof.max_scbs = max_scbs;
  802. ASD_DPRINTK("max_scbs:%d\n", asd_ha->hw_prof.max_scbs);
  803. ASD_DPRINTK("first_scb_site_no:0x%x\n", first_scb_site_no);
  804. ASD_DPRINTK("last_scb_site_no:0x%x\n", last_scb_site_no);
  805. }
  806. /**
  807. * asd_init_cseq_cio - initialize CSEQ CIO registers
  808. * @asd_ha: pointer to host adapter structure
  809. */
  810. static void asd_init_cseq_cio(struct asd_ha_struct *asd_ha)
  811. {
  812. int i;
  813. asd_write_reg_byte(asd_ha, CSEQCOMINTEN, 0);
  814. asd_write_reg_byte(asd_ha, CSEQDLCTL, ASD_DL_SIZE_BITS);
  815. asd_write_reg_byte(asd_ha, CSEQDLOFFS, 0);
  816. asd_write_reg_byte(asd_ha, CSEQDLOFFS+1, 0);
  817. asd_ha->seq.scbpro = 0;
  818. asd_write_reg_dword(asd_ha, SCBPRO, 0);
  819. asd_write_reg_dword(asd_ha, CSEQCON, 0);
  820. /* Initialize CSEQ Mode 11 Interrupt Vectors.
  821. * The addresses are 16 bit wide and in dword units.
  822. * The values of their macros are in byte units.
  823. * Thus we have to divide by 4. */
  824. asd_write_reg_word(asd_ha, CM11INTVEC0, cseq_vecs[0]);
  825. asd_write_reg_word(asd_ha, CM11INTVEC1, cseq_vecs[1]);
  826. asd_write_reg_word(asd_ha, CM11INTVEC2, cseq_vecs[2]);
  827. /* Enable ARP2HALTC (ARP2 Halted from Halt Code Write). */
  828. asd_write_reg_byte(asd_ha, CARP2INTEN, EN_ARP2HALTC);
  829. /* Initialize CSEQ Scratch Page to 0x04. */
  830. asd_write_reg_byte(asd_ha, CSCRATCHPAGE, 0x04);
  831. /* Initialize CSEQ Mode[0-8] Dependent registers. */
  832. /* Initialize Scratch Page to 0. */
  833. for (i = 0; i < 9; i++)
  834. asd_write_reg_byte(asd_ha, CMnSCRATCHPAGE(i), 0);
  835. /* Reset the ARP2 Program Count. */
  836. asd_write_reg_word(asd_ha, CPRGMCNT, cseq_idle_loop);
  837. for (i = 0; i < 8; i++) {
  838. /* Initialize Mode n Link m Interrupt Enable. */
  839. asd_write_reg_dword(asd_ha, CMnINTEN(i), EN_CMnRSPMBXF);
  840. /* Initialize Mode n Request Mailbox. */
  841. asd_write_reg_dword(asd_ha, CMnREQMBX(i), 0);
  842. }
  843. }
  844. /**
  845. * asd_init_lseq_cio -- initialize LmSEQ CIO registers
  846. * @asd_ha: pointer to host adapter structure
  847. */
  848. static void asd_init_lseq_cio(struct asd_ha_struct *asd_ha, int lseq)
  849. {
  850. u8 *sas_addr;
  851. int i;
  852. /* Enable ARP2HALTC (ARP2 Halted from Halt Code Write). */
  853. asd_write_reg_dword(asd_ha, LmARP2INTEN(lseq), EN_ARP2HALTC);
  854. asd_write_reg_byte(asd_ha, LmSCRATCHPAGE(lseq), 0);
  855. /* Initialize Mode 0,1, and 2 SCRATCHPAGE to 0. */
  856. for (i = 0; i < 3; i++)
  857. asd_write_reg_byte(asd_ha, LmMnSCRATCHPAGE(lseq, i), 0);
  858. /* Initialize Mode 5 SCRATCHPAGE to 0. */
  859. asd_write_reg_byte(asd_ha, LmMnSCRATCHPAGE(lseq, 5), 0);
  860. asd_write_reg_dword(asd_ha, LmRSPMBX(lseq), 0);
  861. /* Initialize Mode 0,1,2 and 5 Interrupt Enable and
  862. * Interrupt registers. */
  863. asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 0), LmM0INTEN_MASK);
  864. asd_write_reg_dword(asd_ha, LmMnINT(lseq, 0), 0xFFFFFFFF);
  865. /* Mode 1 */
  866. asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 1), LmM1INTEN_MASK);
  867. asd_write_reg_dword(asd_ha, LmMnINT(lseq, 1), 0xFFFFFFFF);
  868. /* Mode 2 */
  869. asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 2), LmM2INTEN_MASK);
  870. asd_write_reg_dword(asd_ha, LmMnINT(lseq, 2), 0xFFFFFFFF);
  871. /* Mode 5 */
  872. asd_write_reg_dword(asd_ha, LmMnINTEN(lseq, 5), LmM5INTEN_MASK);
  873. asd_write_reg_dword(asd_ha, LmMnINT(lseq, 5), 0xFFFFFFFF);
  874. /* Enable HW Timer status. */
  875. asd_write_reg_byte(asd_ha, LmHWTSTATEN(lseq), LmHWTSTATEN_MASK);
  876. /* Enable Primitive Status 0 and 1. */
  877. asd_write_reg_dword(asd_ha, LmPRIMSTAT0EN(lseq), LmPRIMSTAT0EN_MASK);
  878. asd_write_reg_dword(asd_ha, LmPRIMSTAT1EN(lseq), LmPRIMSTAT1EN_MASK);
  879. /* Enable Frame Error. */
  880. asd_write_reg_dword(asd_ha, LmFRMERREN(lseq), LmFRMERREN_MASK);
  881. asd_write_reg_byte(asd_ha, LmMnHOLDLVL(lseq, 0), 0x50);
  882. /* Initialize Mode 0 Transfer Level to 512. */
  883. asd_write_reg_byte(asd_ha, LmMnXFRLVL(lseq, 0), LmMnXFRLVL_512);
  884. /* Initialize Mode 1 Transfer Level to 256. */
  885. asd_write_reg_byte(asd_ha, LmMnXFRLVL(lseq, 1), LmMnXFRLVL_256);
  886. /* Initialize Program Count. */
  887. asd_write_reg_word(asd_ha, LmPRGMCNT(lseq), lseq_idle_loop);
  888. /* Enable Blind SG Move. */
  889. asd_write_reg_dword(asd_ha, LmMODECTL(lseq), LmBLIND48);
  890. asd_write_reg_word(asd_ha, LmM3SATATIMER(lseq),
  891. ASD_SATA_INTERLOCK_TIMEOUT);
  892. (void) asd_read_reg_dword(asd_ha, LmREQMBX(lseq));
  893. /* Clear Primitive Status 0 and 1. */
  894. asd_write_reg_dword(asd_ha, LmPRMSTAT0(lseq), 0xFFFFFFFF);
  895. asd_write_reg_dword(asd_ha, LmPRMSTAT1(lseq), 0xFFFFFFFF);
  896. /* Clear HW Timer status. */
  897. asd_write_reg_byte(asd_ha, LmHWTSTAT(lseq), 0xFF);
  898. /* Clear DMA Errors for Mode 0 and 1. */
  899. asd_write_reg_byte(asd_ha, LmMnDMAERRS(lseq, 0), 0xFF);
  900. asd_write_reg_byte(asd_ha, LmMnDMAERRS(lseq, 1), 0xFF);
  901. /* Clear SG DMA Errors for Mode 0 and 1. */
  902. asd_write_reg_byte(asd_ha, LmMnSGDMAERRS(lseq, 0), 0xFF);
  903. asd_write_reg_byte(asd_ha, LmMnSGDMAERRS(lseq, 1), 0xFF);
  904. /* Clear Mode 0 Buffer Parity Error. */
  905. asd_write_reg_byte(asd_ha, LmMnBUFSTAT(lseq, 0), LmMnBUFPERR);
  906. /* Clear Mode 0 Frame Error register. */
  907. asd_write_reg_dword(asd_ha, LmMnFRMERR(lseq, 0), 0xFFFFFFFF);
  908. /* Reset LSEQ external interrupt arbiter. */
  909. asd_write_reg_byte(asd_ha, LmARP2INTCTL(lseq), RSTINTCTL);
  910. /* Set the Phy SAS for the LmSEQ WWN. */
  911. sas_addr = asd_ha->phys[lseq].phy_desc->sas_addr;
  912. for (i = 0; i < SAS_ADDR_SIZE; i++)
  913. asd_write_reg_byte(asd_ha, LmWWN(lseq) + i, sas_addr[i]);
  914. /* Set the Transmit Size to 1024 bytes, 0 = 256 Dwords. */
  915. asd_write_reg_byte(asd_ha, LmMnXMTSIZE(lseq, 1), 0);
  916. /* Set the Bus Inactivity Time Limit Timer. */
  917. asd_write_reg_word(asd_ha, LmBITL_TIMER(lseq), 9);
  918. /* Enable SATA Port Multiplier. */
  919. asd_write_reg_byte(asd_ha, LmMnSATAFS(lseq, 1), 0x80);
  920. /* Initialize Interrupt Vector[0-10] address in Mode 3.
  921. * See the comment on CSEQ_INT_* */
  922. asd_write_reg_word(asd_ha, LmM3INTVEC0(lseq), lseq_vecs[0]);
  923. asd_write_reg_word(asd_ha, LmM3INTVEC1(lseq), lseq_vecs[1]);
  924. asd_write_reg_word(asd_ha, LmM3INTVEC2(lseq), lseq_vecs[2]);
  925. asd_write_reg_word(asd_ha, LmM3INTVEC3(lseq), lseq_vecs[3]);
  926. asd_write_reg_word(asd_ha, LmM3INTVEC4(lseq), lseq_vecs[4]);
  927. asd_write_reg_word(asd_ha, LmM3INTVEC5(lseq), lseq_vecs[5]);
  928. asd_write_reg_word(asd_ha, LmM3INTVEC6(lseq), lseq_vecs[6]);
  929. asd_write_reg_word(asd_ha, LmM3INTVEC7(lseq), lseq_vecs[7]);
  930. asd_write_reg_word(asd_ha, LmM3INTVEC8(lseq), lseq_vecs[8]);
  931. asd_write_reg_word(asd_ha, LmM3INTVEC9(lseq), lseq_vecs[9]);
  932. asd_write_reg_word(asd_ha, LmM3INTVEC10(lseq), lseq_vecs[10]);
  933. /*
  934. * Program the Link LED control, applicable only for
  935. * Chip Rev. B or later.
  936. */
  937. asd_write_reg_dword(asd_ha, LmCONTROL(lseq),
  938. (LEDTIMER | LEDMODE_TXRX | LEDTIMERS_100ms));
  939. /* Set the Align Rate for SAS and STP mode. */
  940. asd_write_reg_byte(asd_ha, LmM1SASALIGN(lseq), SAS_ALIGN_DEFAULT);
  941. asd_write_reg_byte(asd_ha, LmM1STPALIGN(lseq), STP_ALIGN_DEFAULT);
  942. }
  943. /**
  944. * asd_post_init_cseq -- clear CSEQ Mode n Int. status and Response mailbox
  945. * @asd_ha: pointer to host adapter struct
  946. */
  947. static void asd_post_init_cseq(struct asd_ha_struct *asd_ha)
  948. {
  949. int i;
  950. for (i = 0; i < 8; i++)
  951. asd_write_reg_dword(asd_ha, CMnINT(i), 0xFFFFFFFF);
  952. for (i = 0; i < 8; i++)
  953. asd_read_reg_dword(asd_ha, CMnRSPMBX(i));
  954. /* Reset the external interrupt arbiter. */
  955. asd_write_reg_byte(asd_ha, CARP2INTCTL, RSTINTCTL);
  956. }
  957. /**
  958. * asd_init_ddb_0 -- initialize DDB 0
  959. * @asd_ha: pointer to host adapter structure
  960. *
  961. * Initialize DDB site 0 which is used internally by the sequencer.
  962. */
  963. static void asd_init_ddb_0(struct asd_ha_struct *asd_ha)
  964. {
  965. int i;
  966. /* Zero out the DDB explicitly */
  967. for (i = 0; i < sizeof(struct asd_ddb_seq_shared); i+=4)
  968. asd_ddbsite_write_dword(asd_ha, 0, i, 0);
  969. asd_ddbsite_write_word(asd_ha, 0,
  970. offsetof(struct asd_ddb_seq_shared, q_free_ddb_head), 0);
  971. asd_ddbsite_write_word(asd_ha, 0,
  972. offsetof(struct asd_ddb_seq_shared, q_free_ddb_tail),
  973. asd_ha->hw_prof.max_ddbs-1);
  974. asd_ddbsite_write_word(asd_ha, 0,
  975. offsetof(struct asd_ddb_seq_shared, q_free_ddb_cnt), 0);
  976. asd_ddbsite_write_word(asd_ha, 0,
  977. offsetof(struct asd_ddb_seq_shared, q_used_ddb_head), 0xFFFF);
  978. asd_ddbsite_write_word(asd_ha, 0,
  979. offsetof(struct asd_ddb_seq_shared, q_used_ddb_tail), 0xFFFF);
  980. asd_ddbsite_write_word(asd_ha, 0,
  981. offsetof(struct asd_ddb_seq_shared, shared_mem_lock), 0);
  982. asd_ddbsite_write_word(asd_ha, 0,
  983. offsetof(struct asd_ddb_seq_shared, smp_conn_tag), 0);
  984. asd_ddbsite_write_word(asd_ha, 0,
  985. offsetof(struct asd_ddb_seq_shared, est_nexus_buf_cnt), 0);
  986. asd_ddbsite_write_word(asd_ha, 0,
  987. offsetof(struct asd_ddb_seq_shared, est_nexus_buf_thresh),
  988. asd_ha->hw_prof.num_phys * 2);
  989. asd_ddbsite_write_byte(asd_ha, 0,
  990. offsetof(struct asd_ddb_seq_shared, settable_max_contexts),0);
  991. asd_ddbsite_write_byte(asd_ha, 0,
  992. offsetof(struct asd_ddb_seq_shared, conn_not_active), 0xFF);
  993. asd_ddbsite_write_byte(asd_ha, 0,
  994. offsetof(struct asd_ddb_seq_shared, phy_is_up), 0x00);
  995. /* DDB 0 is reserved */
  996. set_bit(0, asd_ha->hw_prof.ddb_bitmap);
  997. }
  998. static void asd_seq_init_ddb_sites(struct asd_ha_struct *asd_ha)
  999. {
  1000. unsigned int i;
  1001. unsigned int ddb_site;
  1002. for (ddb_site = 0 ; ddb_site < ASD_MAX_DDBS; ddb_site++)
  1003. for (i = 0; i < sizeof(struct asd_ddb_ssp_smp_target_port); i+= 4)
  1004. asd_ddbsite_write_dword(asd_ha, ddb_site, i, 0);
  1005. }
  1006. /**
  1007. * asd_seq_setup_seqs -- setup and initialize central and link sequencers
  1008. * @asd_ha: pointer to host adapter structure
  1009. */
  1010. static void asd_seq_setup_seqs(struct asd_ha_struct *asd_ha)
  1011. {
  1012. int lseq;
  1013. u8 lseq_mask;
  1014. /* Initialize DDB sites */
  1015. asd_seq_init_ddb_sites(asd_ha);
  1016. /* Initialize SCB sites. Done first to compute some values which
  1017. * the rest of the init code depends on. */
  1018. asd_init_scb_sites(asd_ha);
  1019. /* Initialize CSEQ Scratch RAM registers. */
  1020. asd_init_cseq_scratch(asd_ha);
  1021. /* Initialize LmSEQ Scratch RAM registers. */
  1022. asd_init_lseq_scratch(asd_ha);
  1023. /* Initialize CSEQ CIO registers. */
  1024. asd_init_cseq_cio(asd_ha);
  1025. asd_init_ddb_0(asd_ha);
  1026. /* Initialize LmSEQ CIO registers. */
  1027. lseq_mask = asd_ha->hw_prof.enabled_phys;
  1028. for_each_sequencer(lseq_mask, lseq_mask, lseq)
  1029. asd_init_lseq_cio(asd_ha, lseq);
  1030. asd_post_init_cseq(asd_ha);
  1031. }
  1032. /**
  1033. * asd_seq_start_cseq -- start the central sequencer, CSEQ
  1034. * @asd_ha: pointer to host adapter structure
  1035. */
  1036. static int asd_seq_start_cseq(struct asd_ha_struct *asd_ha)
  1037. {
  1038. /* Reset the ARP2 instruction to location zero. */
  1039. asd_write_reg_word(asd_ha, CPRGMCNT, cseq_idle_loop);
  1040. /* Unpause the CSEQ */
  1041. return asd_unpause_cseq(asd_ha);
  1042. }
  1043. /**
  1044. * asd_seq_start_lseq -- start a link sequencer
  1045. * @asd_ha: pointer to host adapter structure
  1046. * @lseq: the link sequencer of interest
  1047. */
  1048. static int asd_seq_start_lseq(struct asd_ha_struct *asd_ha, int lseq)
  1049. {
  1050. /* Reset the ARP2 instruction to location zero. */
  1051. asd_write_reg_word(asd_ha, LmPRGMCNT(lseq), lseq_idle_loop);
  1052. /* Unpause the LmSEQ */
  1053. return asd_seq_unpause_lseq(asd_ha, lseq);
  1054. }
  1055. int asd_release_firmware(void)
  1056. {
  1057. release_firmware(sequencer_fw);
  1058. return 0;
  1059. }
  1060. static int asd_request_firmware(struct asd_ha_struct *asd_ha)
  1061. {
  1062. int err, i;
  1063. struct sequencer_file_header header;
  1064. const struct sequencer_file_header *hdr_ptr;
  1065. u32 csum = 0;
  1066. u16 *ptr_cseq_vecs, *ptr_lseq_vecs;
  1067. if (sequencer_fw)
  1068. /* already loaded */
  1069. return 0;
  1070. err = reject_firmware(&sequencer_fw,
  1071. SAS_RAZOR_SEQUENCER_FW_FILE,
  1072. &asd_ha->pcidev->dev);
  1073. if (err)
  1074. return err;
  1075. hdr_ptr = (const struct sequencer_file_header *)sequencer_fw->data;
  1076. header.csum = le32_to_cpu(hdr_ptr->csum);
  1077. header.major = le32_to_cpu(hdr_ptr->major);
  1078. header.minor = le32_to_cpu(hdr_ptr->minor);
  1079. header.cseq_table_offset = le32_to_cpu(hdr_ptr->cseq_table_offset);
  1080. header.cseq_table_size = le32_to_cpu(hdr_ptr->cseq_table_size);
  1081. header.lseq_table_offset = le32_to_cpu(hdr_ptr->lseq_table_offset);
  1082. header.lseq_table_size = le32_to_cpu(hdr_ptr->lseq_table_size);
  1083. header.cseq_code_offset = le32_to_cpu(hdr_ptr->cseq_code_offset);
  1084. header.cseq_code_size = le32_to_cpu(hdr_ptr->cseq_code_size);
  1085. header.lseq_code_offset = le32_to_cpu(hdr_ptr->lseq_code_offset);
  1086. header.lseq_code_size = le32_to_cpu(hdr_ptr->lseq_code_size);
  1087. header.mode2_task = le16_to_cpu(hdr_ptr->mode2_task);
  1088. header.cseq_idle_loop = le16_to_cpu(hdr_ptr->cseq_idle_loop);
  1089. header.lseq_idle_loop = le16_to_cpu(hdr_ptr->lseq_idle_loop);
  1090. for (i = sizeof(header.csum); i < sequencer_fw->size; i++)
  1091. csum += sequencer_fw->data[i];
  1092. if (csum != header.csum) {
  1093. asd_printk("Firmware file checksum mismatch\n");
  1094. return -EINVAL;
  1095. }
  1096. if (header.cseq_table_size != CSEQ_NUM_VECS ||
  1097. header.lseq_table_size != LSEQ_NUM_VECS) {
  1098. asd_printk("Firmware file table size mismatch\n");
  1099. return -EINVAL;
  1100. }
  1101. asd_printk("Found sequencer Firmware version %d.%d (%s)\n",
  1102. header.major, header.minor, hdr_ptr->version);
  1103. if (header.major != SAS_RAZOR_SEQUENCER_FW_MAJOR) {
  1104. asd_printk("Firmware Major Version Mismatch;"
  1105. "driver requires version %d.X",
  1106. SAS_RAZOR_SEQUENCER_FW_MAJOR);
  1107. return -EINVAL;
  1108. }
  1109. ptr_cseq_vecs = (u16 *)&sequencer_fw->data[header.cseq_table_offset];
  1110. ptr_lseq_vecs = (u16 *)&sequencer_fw->data[header.lseq_table_offset];
  1111. mode2_task = header.mode2_task;
  1112. cseq_idle_loop = header.cseq_idle_loop;
  1113. lseq_idle_loop = header.lseq_idle_loop;
  1114. for (i = 0; i < CSEQ_NUM_VECS; i++)
  1115. cseq_vecs[i] = le16_to_cpu(ptr_cseq_vecs[i]);
  1116. for (i = 0; i < LSEQ_NUM_VECS; i++)
  1117. lseq_vecs[i] = le16_to_cpu(ptr_lseq_vecs[i]);
  1118. cseq_code = &sequencer_fw->data[header.cseq_code_offset];
  1119. cseq_code_size = header.cseq_code_size;
  1120. lseq_code = &sequencer_fw->data[header.lseq_code_offset];
  1121. lseq_code_size = header.lseq_code_size;
  1122. return 0;
  1123. }
  1124. int asd_init_seqs(struct asd_ha_struct *asd_ha)
  1125. {
  1126. int err;
  1127. err = asd_request_firmware(asd_ha);
  1128. if (err) {
  1129. asd_printk("Failed to load sequencer firmware file %s, error %d\n",
  1130. SAS_RAZOR_SEQUENCER_FW_FILE, err);
  1131. return err;
  1132. }
  1133. err = asd_seq_download_seqs(asd_ha);
  1134. if (err) {
  1135. asd_printk("couldn't download sequencers for %s\n",
  1136. pci_name(asd_ha->pcidev));
  1137. return err;
  1138. }
  1139. asd_seq_setup_seqs(asd_ha);
  1140. return 0;
  1141. }
  1142. int asd_start_seqs(struct asd_ha_struct *asd_ha)
  1143. {
  1144. int err;
  1145. u8 lseq_mask;
  1146. int lseq;
  1147. err = asd_seq_start_cseq(asd_ha);
  1148. if (err) {
  1149. asd_printk("couldn't start CSEQ for %s\n",
  1150. pci_name(asd_ha->pcidev));
  1151. return err;
  1152. }
  1153. lseq_mask = asd_ha->hw_prof.enabled_phys;
  1154. for_each_sequencer(lseq_mask, lseq_mask, lseq) {
  1155. err = asd_seq_start_lseq(asd_ha, lseq);
  1156. if (err) {
  1157. asd_printk("couldn't start LSEQ %d for %s\n", lseq,
  1158. pci_name(asd_ha->pcidev));
  1159. return err;
  1160. }
  1161. }
  1162. return 0;
  1163. }
  1164. /**
  1165. * asd_update_port_links -- update port_map_by_links and phy_is_up
  1166. * @sas_phy: pointer to the phy which has been added to a port
  1167. *
  1168. * 1) When a link reset has completed and we got BYTES DMAED with a
  1169. * valid frame we call this function for that phy, to indicate that
  1170. * the phy is up, i.e. we update the phy_is_up in DDB 0. The
  1171. * sequencer checks phy_is_up when pending SCBs are to be sent, and
  1172. * when an open address frame has been received.
  1173. *
  1174. * 2) When we know of ports, we call this function to update the map
  1175. * of phys participaing in that port, i.e. we update the
  1176. * port_map_by_links in DDB 0. When a HARD_RESET primitive has been
  1177. * received, the sequencer disables all phys in that port.
  1178. * port_map_by_links is also used as the conn_mask byte in the
  1179. * initiator/target port DDB.
  1180. */
  1181. void asd_update_port_links(struct asd_ha_struct *asd_ha, struct asd_phy *phy)
  1182. {
  1183. const u8 phy_mask = (u8) phy->asd_port->phy_mask;
  1184. u8 phy_is_up;
  1185. u8 mask;
  1186. int i, err;
  1187. unsigned long flags;
  1188. spin_lock_irqsave(&asd_ha->hw_prof.ddb_lock, flags);
  1189. for_each_phy(phy_mask, mask, i)
  1190. asd_ddbsite_write_byte(asd_ha, 0,
  1191. offsetof(struct asd_ddb_seq_shared,
  1192. port_map_by_links)+i,phy_mask);
  1193. for (i = 0; i < 12; i++) {
  1194. phy_is_up = asd_ddbsite_read_byte(asd_ha, 0,
  1195. offsetof(struct asd_ddb_seq_shared, phy_is_up));
  1196. err = asd_ddbsite_update_byte(asd_ha, 0,
  1197. offsetof(struct asd_ddb_seq_shared, phy_is_up),
  1198. phy_is_up,
  1199. phy_is_up | phy_mask);
  1200. if (!err)
  1201. break;
  1202. else if (err == -EFAULT) {
  1203. asd_printk("phy_is_up: parity error in DDB 0\n");
  1204. break;
  1205. }
  1206. }
  1207. spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags);
  1208. if (err)
  1209. asd_printk("couldn't update DDB 0:error:%d\n", err);
  1210. }
  1211. /*(DEBLOBBED)*/