27 #include <linux/pci.h>
28 #include <linux/slab.h>
30 #include <linux/module.h>
43 static int asd_get_user_sas_addr(
struct asd_ha_struct *asd_ha)
46 if (asd_ha->
hw_prof.sas_addr[0])
53 static void asd_propagate_sas_addr(
struct asd_ha_struct *asd_ha)
58 if (asd_ha->
hw_prof.phy_desc[i].sas_addr[0] == 0)
71 static void asd_init_phy_identify(
struct asd_phy *
phy)
87 static int asd_init_phy(
struct asd_phy *phy)
105 asd_printk(
"no mem for IDENTIFY for phy%d\n", sas_phy->
id);
108 asd_init_phy_identify(phy);
151 int err = asd_init_phy(&asd_ha->
phys[i]);
170 asd_printk(
"couldn't access conf. space of %s\n",
177 asd_printk(
"couldn't write to MBAR_KEY of %s\n",
222 asd_ha->
seq.tc_index_bitmap_bits = asd_ha->
hw_prof.max_scbs;
223 asd_ha->
seq.tc_index_array = kzalloc(asd_ha->
seq.tc_index_bitmap_bits*
225 if (!asd_ha->
seq.tc_index_array)
228 bitmap_bytes = (asd_ha->
seq.tc_index_bitmap_bits+7)/8;
230 asd_ha->
seq.tc_index_bitmap = kzalloc(bitmap_bytes,
GFP_KERNEL);
231 if (!asd_ha->
seq.tc_index_bitmap)
242 asd_ha->
seq.tc_index_bitmap =
NULL;
243 asd_ha->
seq.tc_index_array =
NULL;
249 INIT_LIST_HEAD(&seq->
pend_q);
254 static void asd_get_max_scb_ddb(
struct asd_ha_struct *asd_ha)
265 static void asd_dl_tasklet_handler(
unsigned long);
269 asd_ha->
seq.actual_dl
270 = asd_alloc_coherent(asd_ha,
273 if (!asd_ha->
seq.actual_dl)
275 asd_ha->
seq.dl = asd_ha->
seq.actual_dl->vaddr;
277 asd_ha->
seq.dl_next = 0;
279 (
unsigned long) asd_ha);
295 for (i = 0; i < seq->
num_edbs; i++) {
308 for (i-- ; i >= 0; i--)
309 asd_free_coherent(asd_ha, seq->
edb_arr[i]);
331 asd_printk(
"couldn't allocate list of escbs\n");
352 static void asd_assign_edbs2escbs(
struct asd_ha_struct *asd_ha)
369 memset(eb, 0,
sizeof(*eb));
389 int edbs = 2*(1+asd_ha->
hw_prof.num_phys);
391 seq->
num_escbs = (edbs+ASD_EDBS_PER_SCB-1)/ASD_EDBS_PER_SCB;
406 asd_assign_edbs2escbs(asd_ha);
433 for (i = 0 ; i < 4 ; i++) {
445 }
while (--count > 0);
465 pci_name(asd_ha->
pcidev));
469 asd_disable_ints(asd_ha);
474 pci_name(asd_ha->
pcidev));
481 pci_name(asd_ha->
pcidev));
488 #define MAX_DEVS ((OCM_MAX_SIZE) / (ASD_DDB_SIZE))
490 static int max_devs = 0;
493 "\tMaximum number of SAS devices to support (not LUs).\n"
494 "\tDefault: 2176, Maximum: 65663.\n");
496 static int max_cmnds = 0;
499 "\tMaximum number of commands queuable.\n"
500 "\tDefault: 512, Maximum: 66047.\n");
502 static void asd_extend_devctx_ocm(
struct asd_ha_struct *asd_ha)
522 asd_extend_devctx_ocm(asd_ha);
525 if (max_devs <= asd_ha->hw_prof.max_ddbs || max_devs > 0xFFFF) {
526 max_devs = asd_ha->
hw_prof.max_ddbs;
533 if (!asd_ha->
hw_prof.ddb_ext) {
534 asd_printk(
"couldn't allocate memory for %d devices\n",
536 max_devs = asd_ha->
hw_prof.max_ddbs;
539 dma_handle = asd_ha->
hw_prof.ddb_ext->dma_handle;
543 asd_write_reg_addr(asd_ha,
DEVCTXBASE, dma_handle);
548 asd_ha->
hw_prof.max_ddbs = max_devs;
561 if (max_cmnds <= asd_ha->hw_prof.max_scbs || max_cmnds > 0xFFFF) {
562 max_cmnds = asd_ha->
hw_prof.max_scbs;
569 if (!asd_ha->
hw_prof.scb_ext) {
570 asd_printk(
"couldn't allocate memory for %d commands\n",
572 max_cmnds = asd_ha->
hw_prof.max_scbs;
575 dma_handle = asd_ha->
hw_prof.scb_ext->dma_handle;
579 asd_write_reg_addr(asd_ha,
CMDCTXBASE, dma_handle);
584 asd_ha->
hw_prof.max_scbs = max_cmnds;
605 asd_get_max_scb_ddb(asd_ha);
606 asd_extend_devctx(asd_ha);
607 asd_extend_cmdctx(asd_ha);
610 bitmap_bytes = (asd_ha->
hw_prof.max_ddbs+7)/8;
613 if (!asd_ha->
hw_prof.ddb_bitmap)
625 err = asd_init_sw(asd_ha);
631 asd_printk(
"couldn't read PCIC_HSTPCIX_CNTRL of %s\n",
632 pci_name(asd_ha->
pcidev));
638 asd_printk(
"couldn't disable split completion timer of %s\n",
639 pci_name(asd_ha->
pcidev));
658 asd_init_ctxmem(asd_ha);
660 if (asd_get_user_sas_addr(asd_ha)) {
661 asd_printk(
"No SAS Address provided for %s\n",
662 pci_name(asd_ha->
pcidev));
667 asd_propagate_sas_addr(asd_ha);
669 err = asd_init_phys(asd_ha);
671 asd_printk(
"couldn't initialize phys for %s\n",
672 pci_name(asd_ha->
pcidev));
676 asd_init_ports(asd_ha);
678 err = asd_init_scbs(asd_ha);
680 asd_printk(
"couldn't initialize scbs for %s\n",
681 pci_name(asd_ha->
pcidev));
685 err = asd_init_dl(asd_ha);
687 asd_printk(
"couldn't initialize the done list:%d\n",
692 err = asd_init_escbs(asd_ha);
698 err = asd_init_chip(asd_ha);
730 static void asd_dl_tasklet_handler(
unsigned long data)
756 list_del_init(&ascb->
list);
775 static void asd_process_donelist_isr(
struct asd_ha_struct *asd_ha)
777 tasklet_schedule(&asd_ha->
seq.dl_tasklet);
792 asd_printk(
"%s: command/status buffer dma parity error\n",
793 pci_name(asd_ha->
pcidev));
794 }
else if (comstat &
CSERR) {
798 asd_printk(
"%s: command/status dma error, DMAERR: 0x%02x, "
799 "CSDMAADR: 0x%04x, CSDMAADR+4: 0x%04x\n",
805 for (i = 0; i < 8; i++) {
812 asd_dump_seq_state(asd_ha, 0);
813 }
else if (comstat &
OVLYERR) {
815 dmaerr = (dmaerr >> 8) & 0xFF;
820 asd_chip_reset(asd_ha);
825 static const char *halt_code[256] = {
826 "UNEXPECTED_INTERRUPT0",
827 "UNEXPECTED_INTERRUPT1",
828 "UNEXPECTED_INTERRUPT2",
829 "UNEXPECTED_INTERRUPT3",
830 "UNEXPECTED_INTERRUPT4",
831 "UNEXPECTED_INTERRUPT5",
832 "UNEXPECTED_INTERRUPT6",
833 "UNEXPECTED_INTERRUPT7",
834 "UNEXPECTED_INTERRUPT8",
835 "UNEXPECTED_INTERRUPT9",
836 "UNEXPECTED_INTERRUPT10",
837 [11 ... 19] =
"unknown[11,19]",
838 "NO_FREE_SCB_AVAILABLE",
839 "INVALID_SCB_OPCODE",
840 "INVALID_MBX_OPCODE",
843 "ATA_TAG_TABLE_FAULT",
844 "ATA_TAG_MASK_FAULT",
845 "BAD_LINK_QUEUE_STATE",
846 "DMA2CHIM_QUEUE_ERROR",
847 "EMPTY_SCB_LIST_FULL",
849 "IN_USE_SCB_ON_FREE_LIST",
850 "BAD_OPEN_WAIT_STATE",
851 "INVALID_STP_AFFILIATION",
854 "TOO_MANY_EMPTIES_NEEDED",
855 "EMPTY_REQ_QUEUE_ERROR",
856 "Q_MONIRTT_MGMT_ERROR",
857 "TARGET_MODE_FLOW_ERROR",
858 "DEVICE_QUEUE_NOT_FOUND",
859 "START_IRTT_TIMER_ERROR",
860 "ABORT_TASK_ILLEGAL_REQ",
861 [43 ... 255] =
"unknown[43,255]"
874 halt_code[(arp2int>>16)&0xFF]);
893 }
else if (arp2int & ARP2HALTC)
896 lseq,halt_code[(arp2int>>16)&0xFF]);
899 pci_name(asd_ha->
pcidev), lseq,
903 asd_chip_reset(asd_ha);
916 asd_chip_reset(asd_ha);
918 asd_arp2_err(asd_ha, dchstatus);
930 asd_printk(
"hmm, EXSI interrupted but no error?\n");
935 asd_printk(
"ASI SEEPROM format error for %s\n",
936 pci_name(asd_ha->
pcidev));
939 asd_printk(
"ASI SEEPROM checksum 0x%x error for %s\n",
941 pci_name(asd_ha->
pcidev));
952 asd_printk(
"%s: CPI2 xfer err: addr: 0x%x, wdata: 0x%x, "
953 "count: 0x%x, byteen: 0x%x, targerr: 0x%x "
954 "master id: 0x%x, master err: 0x%x\n",
961 (statr & CPI2ASIMSTERR_MASK));
964 asd_chip_reset(asd_ha);
991 else if (pcix_status &
RCV_SCE) {
992 asd_printk(
"received split completion error for %s\n",
993 pci_name(asd_ha->
pcidev));
997 }
else if (pcix_status &
UNEXP_SC) {
998 asd_printk(
"unexpected split completion for %s\n",
999 pci_name(asd_ha->
pcidev));
1004 asd_printk(
"split completion discarded for %s\n",
1005 pci_name(asd_ha->
pcidev));
1007 asd_printk(
"uncorrectable ECC error for %s\n",
1008 pci_name(asd_ha->
pcidev));
1009 asd_chip_reset(asd_ha);
1031 asd_process_donelist_isr(asd_ha);
1033 asd_com_sas_isr(asd_ha);
1035 asd_dch_sas_isr(asd_ha);
1037 asd_rbi_exsi_isr(asd_ha);
1039 asd_hst_pcix_isr(asd_ha);
1052 unsigned long flags;
1054 ascb = kmem_cache_zalloc(asd_ascb_cache, gfp_flags);
1066 asd_init_ascb(asd_ha, ascb);
1069 ascb->
tc_index = asd_tc_index_get(seq, ascb);
1108 for ( ; *num > 0; --*num) {
1109 struct asd_ascb *ascb = asd_ascb_alloc(asd_ha, gfp_flags);
1120 last->
scb->header.next_scb =
1159 last->
scb->header.next_scb =
1178 ascb->
timer.data = (
unsigned long) ascb;
1209 unsigned long flags;
1214 can_queue = asd_ha->
hw_prof.max_scbs - asd_ha->
seq.pending;
1215 if (can_queue >= num)
1216 asd_ha->
seq.pending += num;
1221 spin_unlock_irqrestore(&asd_ha->
seq.pend_q_lock, flags);
1226 asd_swap_head_scb(asd_ha, ascb);
1230 asd_start_scb_timers(&list);
1232 asd_ha->
seq.scbpro += num;
1233 list_splice_init(&list, asd_ha->
seq.pend_q.prev);
1235 spin_unlock_irqrestore(&asd_ha->
seq.pend_q_lock, flags);
1261 unsigned long flags;
1264 asd_swap_head_scb(asd_ha, ascb);
1265 asd_ha->
seq.scbpro += num;
1267 spin_unlock_irqrestore(&asd_ha->
seq.pend_q_lock, flags);
1282 if (phy_id < ASD_MAX_PHYS) {
1303 if (phy_id < ASD_MAX_PHYS) {
1363 asd_printk(
"%s called with phy_mask of 0!?\n", __func__);
1369 asd_enable_phy(asd_ha, i);
1375 asd_printk(
"no memory for control phy ascb list\n");
1385 ASD_DPRINTK(
"posting %d control phy scbs\n", num);
1388 asd_ascb_free_list(ascb_list);