31 #include <linux/pci.h>
32 #include <linux/module.h>
45 #define PAUSE_TRIES 1000
47 static const struct firmware *sequencer_fw;
50 static const u8 *cseq_code, *lseq_code;
53 static u16 first_scb_site_no = 0xFFFF;
54 static u16 last_scb_site_no;
79 }
while (--count > 0);
103 if (!(arp2ctl & PAUSED))
106 }
while (--count > 0);
119 static int asd_seq_pause_lseq(
struct asd_ha_struct *asd_ha,
int lseq)
125 if (arp2ctl & PAUSED)
131 if (arp2ctl & PAUSED)
134 }
while (--count > 0);
153 err = asd_seq_pause_lseq(asd_ha, lseq);
168 static int asd_seq_unpause_lseq(
struct asd_ha_struct *asd_ha,
int lseq)
174 if (!(arp2ctl & PAUSED))
180 if (!(arp2ctl & PAUSED))
183 }
while (--count > 0);
192 static int asd_verify_cseq(
struct asd_ha_struct *asd_ha,
const u8 *_prog,
199 for (i = 0; i <
size; i += 4, prog++, addr += 4) {
204 "read:0x%x, wanted:0x%x\n",
226 static int asd_verify_lseq(
struct asd_ha_struct *asd_ha,
const u8 *_prog,
229 #define LSEQ_CODEPAGE_SIZE 4096
232 const u32 *prog = (
u32 *) _prog;
234 for (page = 0; page <
pages; page++) {
240 i += 4, prog++, size-=4) {
246 "page:%d, offs:%d\n",
253 ASD_DPRINTK(
"LSEQ%d verified %d bytes, passed\n", lseq,
254 (
int)((
u8 *)prog-_prog));
267 static int asd_verify_seq(
struct asd_ha_struct *asd_ha,
const u8 *prog,
268 u32 size,
u8 lseq_mask)
271 return asd_verify_cseq(asd_ha, prog, size);
276 err = asd_verify_lseq(asd_ha, prog, size, lseq);
284 #define ASD_DMA_MODE_DOWNLOAD
285 #ifdef ASD_DMA_MODE_DOWNLOAD
287 #define MAX_DMA_OVLY_COUNT ((1U << 14)-1)
289 const u8 *
const prog,
u32 size,
u8 lseq_mask)
299 asd_printk(
"sequencer program not multiple of 4\n");
303 asd_pause_cseq(asd_ha);
304 asd_pause_lseq(asd_ha, 0xFF);
316 asd_printk(
"out of memory for dma SEQ download\n");
322 for (page = 0; page <
pages; page++) {
325 (
u32)MAX_DMA_OVLY_COUNT);
327 memcpy(token->
vaddr, prog + page*MAX_DMA_OVLY_COUNT, left);
332 reg |= (lseq_mask ? (((
u32)lseq_mask) << 8) :
OVLYCSEQ);
347 asd_printk(
"%s: error DMA-ing sequencer code\n",
348 pci_name(asd_ha->
pcidev));
352 asd_free_coherent(asd_ha, token);
356 return err ? : asd_verify_seq(asd_ha, prog, size, lseq_mask);
359 static int asd_download_seq(
struct asd_ha_struct *asd_ha,
const u8 *_prog,
360 u32 size,
u8 lseq_mask)
364 const u32 *prog = (
u32 *) _prog;
367 asd_printk(
"sequencer program not multiple of 4\n");
371 asd_pause_cseq(asd_ha);
372 asd_pause_lseq(asd_ha, 0xFF);
374 reg |= (lseq_mask ? (((
u32)lseq_mask) << 8) :
OVLYCSEQ);
380 ASD_DPRINTK(
"downloading %s sequencer%s in PIO mode...\n",
381 lseq_mask ?
"LSEQ" :
"CSEQ", lseq_mask ?
"s" :
"");
383 for (i = 0; i <
size; i += 4, prog++)
389 return asd_verify_seq(asd_ha, _prog, size, lseq_mask);
399 static int asd_seq_download_seqs(
struct asd_ha_struct *asd_ha)
403 if (!asd_ha->
hw_prof.enabled_phys) {
425 u8 lseq_mask = asd_ha->
hw_prof.enabled_phys;
428 err = asd_download_seq(asd_ha, lseq_code,
435 asd_printk(
"LSEQs download failed:%d\n", err);
494 u16 cmdctx = asd_get_cmdctx_size(asd_ha);
495 cmdctx = (~((cmdctx/128)-1)) >> 8;
532 for (i = 0; i < 8; i++) {
556 (
u16)last_scb_site_no+1);
569 asd_ha->
seq.next_scb.dma_handle);
571 (
unsigned long long)asd_ha->
seq.next_scb.dma_handle);
575 asd_ha->
seq.actual_dl->dma_handle);
594 static void asd_init_cseq_scratch(
struct asd_ha_struct *asd_ha)
596 asd_init_cseq_mip(asd_ha);
597 asd_init_cseq_mdp(asd_ha);
652 for (i = 0; i < 12; i += 4)
691 static void asd_init_lseq_mdp(
struct asd_ha_struct *asd_ha,
int lseq)
708 for (i = 0; i < 3; i++) {
744 (
u16)last_scb_site_no+1);
796 for (i = 0; i < 2; i++) {
857 static void asd_init_lseq_scratch(
struct asd_ha_struct *asd_ha)
862 lseq_mask = asd_ha->
hw_prof.enabled_phys;
864 asd_init_lseq_mip(asd_ha, lseq);
865 asd_init_lseq_mdp(asd_ha, lseq);
882 for (site_no = asd_ha->
hw_prof.max_scbs-1;
889 asd_scbsite_write_dword(asd_ha, site_no, i, 0);
892 asd_scbsite_write_byte(asd_ha, site_no,
899 asd_scbsite_write_byte(asd_ha, site_no, 0x49, 0x01);
906 if (last_scb_site_no == 0)
907 last_scb_site_no = site_no;
914 asd_scbsite_write_word(asd_ha, site_no, 0, first_scb_site_no);
916 first_scb_site_no = site_no;
919 asd_ha->
hw_prof.max_scbs = 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);
937 asd_ha->
seq.scbpro = 0;
957 for (i = 0; i < 9; i++)
963 for (i = 0; i < 8; i++) {
975 static void asd_init_lseq_cio(
struct asd_ha_struct *asd_ha,
int lseq)
986 for (i = 0; i < 3; i++)
1058 sas_addr = asd_ha->
phys[lseq].phy_desc->sas_addr;
1101 static void asd_post_init_cseq(
struct asd_ha_struct *asd_ha)
1105 for (i = 0; i < 8; i++)
1107 for (i = 0; i < 8; i++)
1125 asd_ddbsite_write_dword(asd_ha, 0, i, 0);
1127 asd_ddbsite_write_word(asd_ha, 0,
1129 asd_ddbsite_write_word(asd_ha, 0,
1132 asd_ddbsite_write_word(asd_ha, 0,
1134 asd_ddbsite_write_word(asd_ha, 0,
1136 asd_ddbsite_write_word(asd_ha, 0,
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,
1157 static void asd_seq_init_ddb_sites(
struct asd_ha_struct *asd_ha)
1160 unsigned int ddb_site;
1162 for (ddb_site = 0 ; ddb_site <
ASD_MAX_DDBS; ddb_site++)
1164 asd_ddbsite_write_dword(asd_ha, ddb_site, i, 0);
1171 static void asd_seq_setup_seqs(
struct asd_ha_struct *asd_ha)
1177 asd_seq_init_ddb_sites(asd_ha);
1181 asd_init_scb_sites(asd_ha);
1184 asd_init_cseq_scratch(asd_ha);
1187 asd_init_lseq_scratch(asd_ha);
1190 asd_init_cseq_cio(asd_ha);
1192 asd_init_ddb_0(asd_ha);
1195 lseq_mask = asd_ha->
hw_prof.enabled_phys;
1197 asd_init_lseq_cio(asd_ha, lseq);
1198 asd_post_init_cseq(asd_ha);
1212 return asd_unpause_cseq(asd_ha);
1220 static int asd_seq_start_lseq(
struct asd_ha_struct *asd_ha,
int lseq)
1226 return asd_seq_unpause_lseq(asd_ha, lseq);
1235 static int asd_request_firmware(
struct asd_ha_struct *asd_ha)
1241 u16 *ptr_cseq_vecs, *ptr_lseq_vecs;
1270 for (i =
sizeof(
header.csum); i < sequencer_fw->size; i++)
1271 csum += sequencer_fw->
data[
i];
1273 if (csum !=
header.csum) {
1274 asd_printk(
"Firmware file checksum mismatch\n");
1280 asd_printk(
"Firmware file table size mismatch\n");
1284 asd_printk(
"Found sequencer Firmware version %d.%d (%s)\n",
1288 asd_printk(
"Firmware Major Version Mismatch;"
1289 "driver requires version %d.X",
1294 ptr_cseq_vecs = (
u16 *)&sequencer_fw->
data[
header.cseq_table_offset];
1295 ptr_lseq_vecs = (
u16 *)&sequencer_fw->
data[
header.lseq_table_offset];
1306 cseq_code = &sequencer_fw->
data[
header.cseq_code_offset];
1308 lseq_code = &sequencer_fw->
data[
header.lseq_code_offset];
1318 err = asd_request_firmware(asd_ha);
1321 asd_printk(
"Failed to load sequencer firmware file %s, error %d\n",
1326 err = asd_seq_download_seqs(asd_ha);
1328 asd_printk(
"couldn't download sequencers for %s\n",
1329 pci_name(asd_ha->
pcidev));
1333 asd_seq_setup_seqs(asd_ha);
1344 err = asd_seq_start_cseq(asd_ha);
1347 pci_name(asd_ha->
pcidev));
1351 lseq_mask = asd_ha->
hw_prof.enabled_phys;
1353 err = asd_seq_start_lseq(asd_ha, lseq);
1355 asd_printk(
"coudln't start LSEQ %d for %s\n", lseq,
1356 pci_name(asd_ha->
pcidev));
1387 unsigned long flags;
1391 asd_ddbsite_write_byte(asd_ha, 0,
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,
1404 else if (err == -
EFAULT) {
1405 asd_printk(
"phy_is_up: parity error in DDB 0\n");
1409 spin_unlock_irqrestore(&asd_ha->
hw_prof.ddb_lock,
flags);
1412 asd_printk(
"couldn't update DDB 0:error:%d\n", err);