2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc.
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; see the file COPYING. If not, write to
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 * Abstract: Hardware Device Interface for PMC SRC based controllers
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
36 #include <linux/pci.h>
37 #include <linux/spinlock.h>
38 #include <linux/slab.h>
39 #include <linux/blkdev.h>
40 #include <linux/delay.h>
41 #include <linux/completion.h>
42 #include <linux/time.h>
43 #include <linux/interrupt.h>
44 #include <scsi/scsi_host.h>
48 static int aac_src_get_sync_status(struct aac_dev *dev);
50 static irqreturn_t aac_src_intr_message(int irq, void *dev_id)
52 struct aac_msix_ctx *ctx;
54 unsigned long bellbits, bellbits_shifted;
56 int isFastResponse, mode;
59 ctx = (struct aac_msix_ctx *)dev_id;
61 vector_no = ctx->vector_no;
63 if (dev->msi_enabled) {
64 mode = AAC_INT_MODE_MSI;
66 bellbits = src_readl(dev, MUnit.ODR_MSI);
67 if (bellbits & 0x40000)
68 mode |= AAC_INT_MODE_AIF;
69 if (bellbits & 0x1000)
70 mode |= AAC_INT_MODE_SYNC;
73 mode = AAC_INT_MODE_INTX;
74 bellbits = src_readl(dev, MUnit.ODR_R);
75 if (bellbits & PmDoorBellResponseSent) {
76 bellbits = PmDoorBellResponseSent;
77 src_writel(dev, MUnit.ODR_C, bellbits);
78 src_readl(dev, MUnit.ODR_C);
80 bellbits_shifted = (bellbits >> SRC_ODR_SHIFT);
81 src_writel(dev, MUnit.ODR_C, bellbits);
82 src_readl(dev, MUnit.ODR_C);
84 if (bellbits_shifted & DoorBellAifPending)
85 mode |= AAC_INT_MODE_AIF;
86 else if (bellbits_shifted & OUTBOUNDDOORBELL_0)
87 mode |= AAC_INT_MODE_SYNC;
91 if (mode & AAC_INT_MODE_SYNC) {
93 struct list_head *entry;
95 extern int aac_sync_mode;
97 if (!aac_sync_mode && !dev->msi_enabled) {
98 src_writel(dev, MUnit.ODR_C, bellbits);
99 src_readl(dev, MUnit.ODR_C);
103 if (dev->sync_fib->callback)
104 dev->sync_fib->callback(dev->sync_fib->callback_data,
106 spin_lock_irqsave(&dev->sync_fib->event_lock, sflags);
107 if (dev->sync_fib->flags & FIB_CONTEXT_FLAG_WAIT) {
108 dev->management_fib_count--;
109 up(&dev->sync_fib->event_wait);
111 spin_unlock_irqrestore(&dev->sync_fib->event_lock,
113 spin_lock_irqsave(&dev->sync_lock, sflags);
114 if (!list_empty(&dev->sync_fib_list)) {
115 entry = dev->sync_fib_list.next;
116 dev->sync_fib = list_entry(entry,
122 dev->sync_fib = NULL;
124 spin_unlock_irqrestore(&dev->sync_lock, sflags);
126 aac_adapter_sync_cmd(dev, SEND_SYNCHRONOUS_FIB,
127 (u32)dev->sync_fib->hw_fib_pa,
129 NULL, NULL, NULL, NULL, NULL);
132 if (!dev->msi_enabled)
137 if (mode & AAC_INT_MODE_AIF) {
139 if (dev->sa_firmware) {
140 u32 events = src_readl(dev, MUnit.SCR0);
142 aac_intr_normal(dev, events, 1, 0, NULL);
143 writel(events, &dev->IndexRegs->Mailbox[0]);
144 src_writel(dev, MUnit.IDR, 1 << 23);
146 if (dev->aif_thread && dev->fsa_dev)
147 aac_intr_normal(dev, 0, 2, 0, NULL);
149 if (dev->msi_enabled)
150 aac_src_access_devreg(dev, AAC_CLEAR_AIF_BIT);
155 index = dev->host_rrq_idx[vector_no];
159 /* remove toggle bit (31) */
160 handle = le32_to_cpu((dev->host_rrq[index])
162 /* check fast response bits (30, 1) */
163 if (handle & 0x40000000)
165 handle &= 0x0000ffff;
169 if (dev->msi_enabled && dev->max_msix > 1)
170 atomic_dec(&dev->rrq_outstanding[vector_no]);
171 aac_intr_normal(dev, handle, 0, isFastResponse, NULL);
172 dev->host_rrq[index++] = 0;
173 if (index == (vector_no + 1) * dev->vector_cap)
174 index = vector_no * dev->vector_cap;
175 dev->host_rrq_idx[vector_no] = index;
184 * aac_src_disable_interrupt - Disable interrupts
188 static void aac_src_disable_interrupt(struct aac_dev *dev)
190 src_writel(dev, MUnit.OIMR, dev->OIMR = 0xffffffff);
194 * aac_src_enable_interrupt_message - Enable interrupts
198 static void aac_src_enable_interrupt_message(struct aac_dev *dev)
200 aac_src_access_devreg(dev, AAC_ENABLE_INTERRUPT);
204 * src_sync_cmd - send a command and wait
206 * @command: Command to execute
207 * @p1: first parameter
208 * @ret: adapter status
210 * This routine will send a synchronous command to the adapter and wait
211 * for its completion.
214 static int src_sync_cmd(struct aac_dev *dev, u32 command,
215 u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6,
216 u32 *status, u32 * r1, u32 * r2, u32 * r3, u32 * r4)
223 * Write the command into Mailbox 0
225 writel(command, &dev->IndexRegs->Mailbox[0]);
227 * Write the parameters into Mailboxes 1 - 6
229 writel(p1, &dev->IndexRegs->Mailbox[1]);
230 writel(p2, &dev->IndexRegs->Mailbox[2]);
231 writel(p3, &dev->IndexRegs->Mailbox[3]);
232 writel(p4, &dev->IndexRegs->Mailbox[4]);
235 * Clear the synch command doorbell to start on a clean slate.
237 if (!dev->msi_enabled)
240 OUTBOUNDDOORBELL_0 << SRC_ODR_SHIFT);
243 * Disable doorbell interrupts
245 src_writel(dev, MUnit.OIMR, dev->OIMR = 0xffffffff);
248 * Force the completion of the mask register write before issuing
251 src_readl(dev, MUnit.OIMR);
254 * Signal that there is a new synch command
256 src_writel(dev, MUnit.IDR, INBOUNDDOORBELL_0 << SRC_IDR_SHIFT);
258 if (!dev->sync_mode || command != SEND_SYNCHRONOUS_FIB) {
262 if (command == IOP_RESET_ALWAYS) {
263 /* Wait up to 10 sec */
266 /* Wait up to 5 minutes */
269 while (time_before(jiffies, start+delay)) {
270 udelay(5); /* Delay 5 microseconds to let Mon960 get info. */
272 * Mon960 will set doorbell0 bit when it has completed the command.
274 if (aac_src_get_sync_status(dev) & OUTBOUNDDOORBELL_0) {
276 * Clear the doorbell.
278 if (dev->msi_enabled)
279 aac_src_access_devreg(dev,
284 OUTBOUNDDOORBELL_0 << SRC_ODR_SHIFT);
289 * Yield the processor in case we are slow
293 if (unlikely(ok != 1)) {
295 * Restore interrupt mask even though we timed out
297 aac_adapter_enable_int(dev);
301 * Pull the synch status from Mailbox 0.
304 *status = readl(&dev->IndexRegs->Mailbox[0]);
306 *r1 = readl(&dev->IndexRegs->Mailbox[1]);
308 *r2 = readl(&dev->IndexRegs->Mailbox[2]);
310 *r3 = readl(&dev->IndexRegs->Mailbox[3]);
312 *r4 = readl(&dev->IndexRegs->Mailbox[4]);
313 if (command == GET_COMM_PREFERRED_SETTINGS)
315 readl(&dev->IndexRegs->Mailbox[5]) & 0xFFFF;
317 * Clear the synch command doorbell.
319 if (!dev->msi_enabled)
322 OUTBOUNDDOORBELL_0 << SRC_ODR_SHIFT);
326 * Restore interrupt mask
328 aac_adapter_enable_int(dev);
333 * aac_src_interrupt_adapter - interrupt adapter
336 * Send an interrupt to the i960 and breakpoint it.
339 static void aac_src_interrupt_adapter(struct aac_dev *dev)
341 src_sync_cmd(dev, BREAKPOINT_REQUEST,
343 NULL, NULL, NULL, NULL, NULL);
347 * aac_src_notify_adapter - send an event to the adapter
349 * @event: Event to send
351 * Notify the i960 that something it probably cares about has
355 static void aac_src_notify_adapter(struct aac_dev *dev, u32 event)
360 src_writel(dev, MUnit.ODR_C,
361 INBOUNDDOORBELL_1 << SRC_ODR_SHIFT);
363 case HostNormRespNotFull:
364 src_writel(dev, MUnit.ODR_C,
365 INBOUNDDOORBELL_4 << SRC_ODR_SHIFT);
367 case AdapNormRespQue:
368 src_writel(dev, MUnit.ODR_C,
369 INBOUNDDOORBELL_2 << SRC_ODR_SHIFT);
371 case HostNormCmdNotFull:
372 src_writel(dev, MUnit.ODR_C,
373 INBOUNDDOORBELL_3 << SRC_ODR_SHIFT);
376 src_writel(dev, MUnit.ODR_C,
377 INBOUNDDOORBELL_6 << SRC_ODR_SHIFT);
380 src_writel(dev, MUnit.ODR_C,
381 INBOUNDDOORBELL_5 << SRC_ODR_SHIFT);
390 * aac_src_start_adapter - activate adapter
393 * Start up processing on an i960 based AAC adapter
396 static void aac_src_start_adapter(struct aac_dev *dev)
398 union aac_init *init;
401 /* reset host_rrq_idx first */
402 for (i = 0; i < dev->max_msix; i++) {
403 dev->host_rrq_idx[i] = i * dev->vector_cap;
404 atomic_set(&dev->rrq_outstanding[i], 0);
406 atomic_set(&dev->msix_counter, 0);
407 dev->fibs_pushed_no = 0;
410 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) {
411 init->r8.host_elapsed_seconds = cpu_to_le32(get_seconds());
412 src_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS,
413 lower_32_bits(dev->init_pa),
414 upper_32_bits(dev->init_pa),
416 (AAC_MAX_HRRQ - 1) * sizeof(struct _rrq),
417 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
419 init->r7.host_elapsed_seconds = cpu_to_le32(get_seconds());
420 // We can only use a 32 bit address here
421 src_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS,
422 (u32)(ulong)dev->init_pa, 0, 0, 0, 0, 0,
423 NULL, NULL, NULL, NULL, NULL);
429 * aac_src_check_health
430 * @dev: device to check if healthy
432 * Will attempt to determine if the specified adapter is alive and
433 * capable of handling requests, returning 0 if alive.
435 static int aac_src_check_health(struct aac_dev *dev)
437 u32 status = src_readl(dev, MUnit.OMR);
440 * Check to see if the board panic'd.
442 if (unlikely(status & KERNEL_PANIC))
446 * Check to see if the board failed any self tests.
448 if (unlikely(status & SELF_TEST_FAILED))
452 * Check to see if the board failed any self tests.
454 if (unlikely(status & MONITOR_PANIC))
458 * Wait for the adapter to be up and running.
460 if (unlikely(!(status & KERNEL_UP_AND_RUNNING)))
471 return (status >> 16) & 0xFF;
474 static inline u32 aac_get_vector(struct aac_dev *dev)
476 return atomic_inc_return(&dev->msix_counter)%dev->max_msix;
480 * aac_src_deliver_message
483 * Will send a fib, returning 0 if successful.
485 static int aac_src_deliver_message(struct fib *fib)
487 struct aac_dev *dev = fib->dev;
488 struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue];
491 struct aac_fib_xporthdr *pFibX;
499 atomic_inc(&q->numpending);
501 native_hba = (fib->flags & FIB_CONTEXT_FLAG_NATIVE_HBA) ? 1 : 0;
504 if (dev->msi_enabled && dev->max_msix > 1 &&
505 (native_hba || fib->hw_fib_va->header.Command != AifRequest)) {
507 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE3)
509 vector_no = aac_get_vector(dev);
511 vector_no = fib->vector_no;
514 if (fib->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF) {
515 struct aac_hba_tm_req *tm_req;
517 tm_req = (struct aac_hba_tm_req *)
519 if (tm_req->iu_type ==
520 HBA_IU_TYPE_SCSI_TM_REQ) {
521 ((struct aac_hba_tm_req *)
522 fib->hw_fib_va)->reply_qid
524 ((struct aac_hba_tm_req *)
525 fib->hw_fib_va)->request_id
526 += (vector_no << 16);
528 ((struct aac_hba_reset_req *)
529 fib->hw_fib_va)->reply_qid
531 ((struct aac_hba_reset_req *)
532 fib->hw_fib_va)->request_id
533 += (vector_no << 16);
536 ((struct aac_hba_cmd_req *)
537 fib->hw_fib_va)->reply_qid
539 ((struct aac_hba_cmd_req *)
540 fib->hw_fib_va)->request_id
541 += (vector_no << 16);
544 fib->hw_fib_va->header.Handle += (vector_no << 16);
550 atomic_inc(&dev->rrq_outstanding[vector_no]);
553 address = fib->hw_fib_pa;
554 fibsize = (fib->hbacmd_size + 127) / 128 - 1;
559 src_writeq(dev, MUnit.IQN_L, (u64)address);
561 spin_lock_irqsave(&fib->dev->iq_lock, flags);
562 src_writel(dev, MUnit.IQN_H,
563 upper_32_bits(address) & 0xffffffff);
564 src_writel(dev, MUnit.IQN_L, address & 0xffffffff);
565 spin_unlock_irqrestore(&fib->dev->iq_lock, flags);
568 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
569 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) {
570 /* Calculate the amount to the fibsize bits */
571 fibsize = (le16_to_cpu(fib->hw_fib_va->header.Size)
573 /* New FIB header, 32-bit */
574 address = fib->hw_fib_pa;
575 fib->hw_fib_va->header.StructType = FIB_MAGIC2;
576 fib->hw_fib_va->header.SenderFibAddress =
577 cpu_to_le32((u32)address);
578 fib->hw_fib_va->header.u.TimeStamp = 0;
579 WARN_ON(upper_32_bits(address) != 0L);
581 /* Calculate the amount to the fibsize bits */
582 fibsize = (sizeof(struct aac_fib_xporthdr) +
583 le16_to_cpu(fib->hw_fib_va->header.Size)
585 /* Fill XPORT header */
586 pFibX = (struct aac_fib_xporthdr *)
587 ((unsigned char *)fib->hw_fib_va -
588 sizeof(struct aac_fib_xporthdr));
589 pFibX->Handle = fib->hw_fib_va->header.Handle;
591 cpu_to_le64((u64)fib->hw_fib_pa);
592 pFibX->Size = cpu_to_le32(
593 le16_to_cpu(fib->hw_fib_va->header.Size));
594 address = fib->hw_fib_pa -
595 (u64)sizeof(struct aac_fib_xporthdr);
602 src_writeq(dev, MUnit.IQ_L, (u64)address);
604 spin_lock_irqsave(&fib->dev->iq_lock, flags);
605 src_writel(dev, MUnit.IQ_H,
606 upper_32_bits(address) & 0xffffffff);
607 src_writel(dev, MUnit.IQ_L, address & 0xffffffff);
608 spin_unlock_irqrestore(&fib->dev->iq_lock, flags);
616 * @size: mapping resize request
619 static int aac_src_ioremap(struct aac_dev *dev, u32 size)
622 iounmap(dev->regs.src.bar1);
623 dev->regs.src.bar1 = NULL;
624 iounmap(dev->regs.src.bar0);
625 dev->base = dev->regs.src.bar0 = NULL;
628 dev->regs.src.bar1 = ioremap(pci_resource_start(dev->pdev, 2),
629 AAC_MIN_SRC_BAR1_SIZE);
631 if (dev->regs.src.bar1 == NULL)
633 dev->base = dev->regs.src.bar0 = ioremap(dev->base_start, size);
634 if (dev->base == NULL) {
635 iounmap(dev->regs.src.bar1);
636 dev->regs.src.bar1 = NULL;
639 dev->IndexRegs = &((struct src_registers __iomem *)
640 dev->base)->u.tupelo.IndexRegs;
646 * @size: mapping resize request
649 static int aac_srcv_ioremap(struct aac_dev *dev, u32 size)
652 iounmap(dev->regs.src.bar0);
653 dev->base = dev->regs.src.bar0 = NULL;
658 ioremap(pci_resource_start(dev->pdev, 2), AAC_MIN_SRCV_BAR1_SIZE);
660 if (dev->regs.src.bar1 == NULL)
662 dev->base = dev->regs.src.bar0 = ioremap(dev->base_start, size);
663 if (dev->base == NULL) {
664 iounmap(dev->regs.src.bar1);
665 dev->regs.src.bar1 = NULL;
668 dev->IndexRegs = &((struct src_registers __iomem *)
669 dev->base)->u.denali.IndexRegs;
673 void aac_set_intx_mode(struct aac_dev *dev)
675 if (dev->msi_enabled) {
676 aac_src_access_devreg(dev, AAC_ENABLE_INTX);
677 dev->msi_enabled = 0;
678 msleep(5000); /* Delay 5 seconds */
682 static void aac_dump_fw_fib_iop_reset(struct aac_dev *dev)
684 __le32 supported_options3;
689 supported_options3 = dev->supplement_adapter_info.supported_options3;
690 if (!(supported_options3 & AAC_OPTION_SUPPORTED3_IOP_RESET_FIB_DUMP))
693 aac_adapter_sync_cmd(dev, IOP_RESET_FW_FIB_DUMP,
694 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
697 static bool aac_is_ctrl_up_and_running(struct aac_dev *dev)
700 unsigned long status, start;
706 status = src_readl(dev, MUnit.OMR);
708 if (status == 0xffffffff)
711 if (status & KERNEL_BOOTING) {
716 if (time_after(jiffies, start+HZ*SOFT_RESET_TIME)) {
721 is_up = status & KERNEL_UP_AND_RUNNING;
728 static void aac_notify_fw_of_iop_reset(struct aac_dev *dev)
730 aac_adapter_sync_cmd(dev, IOP_RESET_ALWAYS, 0, 0, 0, 0, 0, 0, NULL,
731 NULL, NULL, NULL, NULL);
734 static void aac_send_iop_reset(struct aac_dev *dev)
736 aac_dump_fw_fib_iop_reset(dev);
738 aac_notify_fw_of_iop_reset(dev);
740 aac_set_intx_mode(dev);
742 src_writel(dev, MUnit.IDR, IOP_SRC_RESET_MASK);
747 static void aac_send_hardware_soft_reset(struct aac_dev *dev)
751 val = readl(((char *)(dev->base) + IBW_SWR_OFFSET));
753 writel(val, ((char *)(dev->base) + IBW_SWR_OFFSET));
754 msleep_interruptible(20000);
757 static int aac_src_restart_adapter(struct aac_dev *dev, int bled, u8 reset_type)
766 dev_err(&dev->pdev->dev, "adapter kernel panic'd %x.\n", bled);
769 * When there is a BlinkLED, IOP_RESET has not effect
771 if (bled >= 2 && dev->sa_firmware && reset_type & HW_IOP_RESET)
772 reset_type &= ~HW_IOP_RESET;
774 dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
776 dev_err(&dev->pdev->dev, "Controller reset type is %d\n", reset_type);
778 if (reset_type & HW_IOP_RESET) {
779 dev_info(&dev->pdev->dev, "Issuing IOP reset\n");
780 aac_send_iop_reset(dev);
783 * Creates a delay or wait till up and running comes thru
785 is_ctrl_up = aac_is_ctrl_up_and_running(dev);
787 dev_err(&dev->pdev->dev, "IOP reset failed\n");
789 dev_info(&dev->pdev->dev, "IOP reset succeded\n");
794 if (!dev->sa_firmware) {
795 dev_err(&dev->pdev->dev, "ARC Reset attempt failed\n");
800 if (reset_type & HW_SOFT_RESET) {
801 dev_info(&dev->pdev->dev, "Issuing SOFT reset\n");
802 aac_send_hardware_soft_reset(dev);
803 dev->msi_enabled = 0;
805 is_ctrl_up = aac_is_ctrl_up_and_running(dev);
807 dev_err(&dev->pdev->dev, "SOFT reset failed\n");
811 dev_info(&dev->pdev->dev, "SOFT reset succeded\n");
815 if (startup_timeout < 300)
816 startup_timeout = 300;
822 if (src_readl(dev, MUnit.OMR) & KERNEL_PANIC)
828 * aac_src_select_comm - Select communications method
830 * @comm: communications method
832 static int aac_src_select_comm(struct aac_dev *dev, int comm)
835 case AAC_COMM_MESSAGE:
836 dev->a_ops.adapter_intr = aac_src_intr_message;
837 dev->a_ops.adapter_deliver = aac_src_deliver_message;
846 * aac_src_init - initialize an Cardinal Frey Bar card
847 * @dev: device to configure
851 int aac_src_init(struct aac_dev *dev)
854 unsigned long status;
856 int instance = dev->id;
857 const char *name = dev->name;
859 dev->a_ops.adapter_ioremap = aac_src_ioremap;
860 dev->a_ops.adapter_comm = aac_src_select_comm;
862 dev->base_size = AAC_MIN_SRC_BAR0_SIZE;
863 if (aac_adapter_ioremap(dev, dev->base_size)) {
864 printk(KERN_WARNING "%s: unable to map adapter.\n", name);
868 /* Failure to reset here is an option ... */
869 dev->a_ops.adapter_sync_cmd = src_sync_cmd;
870 dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
872 if (dev->init_reset) {
873 dev->init_reset = false;
874 if (!aac_src_restart_adapter(dev, 0, IOP_HWSOFT_RESET))
879 * Check to see if the board panic'd while booting.
881 status = src_readl(dev, MUnit.OMR);
882 if (status & KERNEL_PANIC) {
883 if (aac_src_restart_adapter(dev,
884 aac_src_check_health(dev), IOP_HWSOFT_RESET))
889 * Check to see if the board failed any self tests.
891 status = src_readl(dev, MUnit.OMR);
892 if (status & SELF_TEST_FAILED) {
893 printk(KERN_ERR "%s%d: adapter self-test failed.\n",
894 dev->name, instance);
898 * Check to see if the monitor panic'd while booting.
900 if (status & MONITOR_PANIC) {
901 printk(KERN_ERR "%s%d: adapter monitor panic.\n",
902 dev->name, instance);
907 * Wait for the adapter to be up and running. Wait up to 3 minutes
909 while (!((status = src_readl(dev, MUnit.OMR)) &
910 KERNEL_UP_AND_RUNNING)) {
912 (status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC))) ||
913 time_after(jiffies, start+HZ*startup_timeout)) {
914 printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n",
915 dev->name, instance, status);
919 ((status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC)) ||
920 time_after(jiffies, start + HZ *
921 ((startup_timeout > 60)
922 ? (startup_timeout - 60)
923 : (startup_timeout / 2))))) {
924 if (likely(!aac_src_restart_adapter(dev,
925 aac_src_check_health(dev), IOP_HWSOFT_RESET)))
931 if (restart && aac_commit)
934 * Fill in the common function dispatch table.
936 dev->a_ops.adapter_interrupt = aac_src_interrupt_adapter;
937 dev->a_ops.adapter_disable_int = aac_src_disable_interrupt;
938 dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
939 dev->a_ops.adapter_notify = aac_src_notify_adapter;
940 dev->a_ops.adapter_sync_cmd = src_sync_cmd;
941 dev->a_ops.adapter_check_health = aac_src_check_health;
942 dev->a_ops.adapter_restart = aac_src_restart_adapter;
943 dev->a_ops.adapter_start = aac_src_start_adapter;
946 * First clear out all interrupts. Then enable the one's that we
949 aac_adapter_comm(dev, AAC_COMM_MESSAGE);
950 aac_adapter_disable_int(dev);
951 src_writel(dev, MUnit.ODR_C, 0xffffffff);
952 aac_adapter_enable_int(dev);
954 if (aac_init_adapter(dev) == NULL)
956 if (dev->comm_interface != AAC_COMM_MESSAGE_TYPE1)
959 dev->msi = !pci_enable_msi(dev->pdev);
961 dev->aac_msix[0].vector_no = 0;
962 dev->aac_msix[0].dev = dev;
964 if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr,
965 IRQF_SHARED, "aacraid", &(dev->aac_msix[0])) < 0) {
968 pci_disable_msi(dev->pdev);
970 printk(KERN_ERR "%s%d: Interrupt unavailable.\n",
974 dev->dbg_base = pci_resource_start(dev->pdev, 2);
975 dev->dbg_base_mapped = dev->regs.src.bar1;
976 dev->dbg_size = AAC_MIN_SRC_BAR1_SIZE;
977 dev->a_ops.adapter_enable_int = aac_src_enable_interrupt_message;
979 aac_adapter_enable_int(dev);
981 if (!dev->sync_mode) {
983 * Tell the adapter that all is configured, and it can
984 * start accepting requests
986 aac_src_start_adapter(dev);
996 * aac_srcv_init - initialize an SRCv card
997 * @dev: device to configure
1001 int aac_srcv_init(struct aac_dev *dev)
1003 unsigned long start;
1004 unsigned long status;
1006 int instance = dev->id;
1007 const char *name = dev->name;
1009 dev->a_ops.adapter_ioremap = aac_srcv_ioremap;
1010 dev->a_ops.adapter_comm = aac_src_select_comm;
1012 dev->base_size = AAC_MIN_SRCV_BAR0_SIZE;
1013 if (aac_adapter_ioremap(dev, dev->base_size)) {
1014 printk(KERN_WARNING "%s: unable to map adapter.\n", name);
1018 /* Failure to reset here is an option ... */
1019 dev->a_ops.adapter_sync_cmd = src_sync_cmd;
1020 dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
1022 if (dev->init_reset) {
1023 dev->init_reset = false;
1024 if (!aac_src_restart_adapter(dev, 0, IOP_HWSOFT_RESET))
1029 * Check to see if flash update is running.
1030 * Wait for the adapter to be up and running. Wait up to 5 minutes
1032 status = src_readl(dev, MUnit.OMR);
1033 if (status & FLASH_UPD_PENDING) {
1036 status = src_readl(dev, MUnit.OMR);
1037 if (time_after(jiffies, start+HZ*FWUPD_TIMEOUT)) {
1038 printk(KERN_ERR "%s%d: adapter flash update failed.\n",
1039 dev->name, instance);
1042 } while (!(status & FLASH_UPD_SUCCESS) &&
1043 !(status & FLASH_UPD_FAILED));
1044 /* Delay 10 seconds.
1045 * Because right now FW is doing a soft reset,
1046 * do not read scratch pad register at this time
1051 * Check to see if the board panic'd while booting.
1053 status = src_readl(dev, MUnit.OMR);
1054 if (status & KERNEL_PANIC) {
1055 if (aac_src_restart_adapter(dev,
1056 aac_src_check_health(dev), IOP_HWSOFT_RESET))
1061 * Check to see if the board failed any self tests.
1063 status = src_readl(dev, MUnit.OMR);
1064 if (status & SELF_TEST_FAILED) {
1065 printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance);
1069 * Check to see if the monitor panic'd while booting.
1071 if (status & MONITOR_PANIC) {
1072 printk(KERN_ERR "%s%d: adapter monitor panic.\n", dev->name, instance);
1077 * Wait for the adapter to be up and running. Wait up to 3 minutes
1079 while (!((status = src_readl(dev, MUnit.OMR)) &
1080 KERNEL_UP_AND_RUNNING) ||
1081 status == 0xffffffff) {
1083 (status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC))) ||
1084 time_after(jiffies, start+HZ*startup_timeout)) {
1085 printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n",
1086 dev->name, instance, status);
1090 ((status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC)) ||
1091 time_after(jiffies, start + HZ *
1092 ((startup_timeout > 60)
1093 ? (startup_timeout - 60)
1094 : (startup_timeout / 2))))) {
1095 if (likely(!aac_src_restart_adapter(dev,
1096 aac_src_check_health(dev), IOP_HWSOFT_RESET)))
1102 if (restart && aac_commit)
1105 * Fill in the common function dispatch table.
1107 dev->a_ops.adapter_interrupt = aac_src_interrupt_adapter;
1108 dev->a_ops.adapter_disable_int = aac_src_disable_interrupt;
1109 dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
1110 dev->a_ops.adapter_notify = aac_src_notify_adapter;
1111 dev->a_ops.adapter_sync_cmd = src_sync_cmd;
1112 dev->a_ops.adapter_check_health = aac_src_check_health;
1113 dev->a_ops.adapter_restart = aac_src_restart_adapter;
1114 dev->a_ops.adapter_start = aac_src_start_adapter;
1117 * First clear out all interrupts. Then enable the one's that we
1120 aac_adapter_comm(dev, AAC_COMM_MESSAGE);
1121 aac_adapter_disable_int(dev);
1122 src_writel(dev, MUnit.ODR_C, 0xffffffff);
1123 aac_adapter_enable_int(dev);
1125 if (aac_init_adapter(dev) == NULL)
1127 if ((dev->comm_interface != AAC_COMM_MESSAGE_TYPE2) &&
1128 (dev->comm_interface != AAC_COMM_MESSAGE_TYPE3))
1130 if (dev->msi_enabled)
1131 aac_src_access_devreg(dev, AAC_ENABLE_MSIX);
1133 if (aac_acquire_irq(dev))
1136 dev->dbg_base = pci_resource_start(dev->pdev, 2);
1137 dev->dbg_base_mapped = dev->regs.src.bar1;
1138 dev->dbg_size = AAC_MIN_SRCV_BAR1_SIZE;
1139 dev->a_ops.adapter_enable_int = aac_src_enable_interrupt_message;
1141 aac_adapter_enable_int(dev);
1143 if (!dev->sync_mode) {
1145 * Tell the adapter that all is configured, and it can
1146 * start accepting requests
1148 aac_src_start_adapter(dev);
1157 void aac_src_access_devreg(struct aac_dev *dev, int mode)
1162 case AAC_ENABLE_INTERRUPT:
1165 dev->OIMR = (dev->msi_enabled ?
1166 AAC_INT_ENABLE_TYPE1_MSIX :
1167 AAC_INT_ENABLE_TYPE1_INTX));
1170 case AAC_DISABLE_INTERRUPT:
1173 dev->OIMR = AAC_INT_DISABLE_ALL);
1176 case AAC_ENABLE_MSIX:
1178 val = src_readl(dev, MUnit.IDR);
1180 src_writel(dev, MUnit.IDR, val);
1181 src_readl(dev, MUnit.IDR);
1183 val = PMC_ALL_INTERRUPT_BITS;
1184 src_writel(dev, MUnit.IOAR, val);
1185 val = src_readl(dev, MUnit.OIMR);
1188 val & (~(PMC_GLOBAL_INT_BIT2 | PMC_GLOBAL_INT_BIT0)));
1191 case AAC_DISABLE_MSIX:
1193 val = src_readl(dev, MUnit.IDR);
1195 src_writel(dev, MUnit.IDR, val);
1196 src_readl(dev, MUnit.IDR);
1199 case AAC_CLEAR_AIF_BIT:
1201 val = src_readl(dev, MUnit.IDR);
1203 src_writel(dev, MUnit.IDR, val);
1204 src_readl(dev, MUnit.IDR);
1207 case AAC_CLEAR_SYNC_BIT:
1209 val = src_readl(dev, MUnit.IDR);
1211 src_writel(dev, MUnit.IDR, val);
1212 src_readl(dev, MUnit.IDR);
1215 case AAC_ENABLE_INTX:
1217 val = src_readl(dev, MUnit.IDR);
1219 src_writel(dev, MUnit.IDR, val);
1220 src_readl(dev, MUnit.IDR);
1222 val = PMC_ALL_INTERRUPT_BITS;
1223 src_writel(dev, MUnit.IOAR, val);
1224 src_readl(dev, MUnit.IOAR);
1225 val = src_readl(dev, MUnit.OIMR);
1226 src_writel(dev, MUnit.OIMR,
1227 val & (~(PMC_GLOBAL_INT_BIT2)));
1235 static int aac_src_get_sync_status(struct aac_dev *dev)
1240 if (dev->msi_enabled)
1241 val = src_readl(dev, MUnit.ODR_MSI) & 0x1000 ? 1 : 0;
1243 val = src_readl(dev, MUnit.ODR_R) >> SRC_ODR_SHIFT;