Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Adaptec AAC series RAID controller driver |
Alan Cox | fa195af | 2008-10-27 15:16:36 +0000 | [diff] [blame] | 3 | * (c) Copyright 2001 Red Hat Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * based on the old aacraid driver that is.. |
| 6 | * Adaptec aacraid device driver for Linux. |
| 7 | * |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 8 | * Copyright (c) 2000-2010 Adaptec, Inc. |
| 9 | * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2, or (at your option) |
| 14 | * any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; see the file COPYING. If not, write to |
| 23 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 24 | * |
| 25 | * Module Name: |
| 26 | * commsup.c |
| 27 | * |
| 28 | * Abstract: Contain all routines that are required for FSA host/adapter |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 29 | * communication. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * |
| 31 | */ |
| 32 | |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/types.h> |
| 36 | #include <linux/sched.h> |
| 37 | #include <linux/pci.h> |
| 38 | #include <linux/spinlock.h> |
| 39 | #include <linux/slab.h> |
| 40 | #include <linux/completion.h> |
| 41 | #include <linux/blkdev.h> |
Al Viro | 164006d | 2005-11-30 23:47:05 -0500 | [diff] [blame] | 42 | #include <linux/delay.h> |
Christoph Hellwig | fe27381 | 2006-02-14 18:45:06 +0100 | [diff] [blame] | 43 | #include <linux/kthread.h> |
Al Viro | 6a3670c | 2006-09-24 23:45:29 +0100 | [diff] [blame] | 44 | #include <linux/interrupt.h> |
Matthew Wilcox | 6188e10 | 2008-04-18 22:21:05 -0400 | [diff] [blame] | 45 | #include <linux/semaphore.h> |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 46 | #include <scsi/scsi.h> |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 47 | #include <scsi/scsi_host.h> |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 48 | #include <scsi/scsi_device.h> |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 49 | #include <scsi/scsi_cmnd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #include "aacraid.h" |
| 52 | |
| 53 | /** |
| 54 | * fib_map_alloc - allocate the fib objects |
| 55 | * @dev: Adapter to allocate for |
| 56 | * |
| 57 | * Allocate and map the shared PCI space for the FIB blocks used to |
| 58 | * talk to the Adaptec firmware. |
| 59 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | static int fib_map_alloc(struct aac_dev *dev) |
| 62 | { |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 63 | dprintk((KERN_INFO |
| 64 | "allocate hardware fibs pci_alloc_consistent(%p, %d * (%d + %d), %p)\n", |
| 65 | dev->pdev, dev->max_fib_size, dev->scsi_host_ptr->can_queue, |
| 66 | AAC_NUM_MGT_FIB, &dev->hw_fib_pa)); |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 67 | dev->hw_fib_va = pci_alloc_consistent(dev->pdev, |
| 68 | (dev->max_fib_size + sizeof(struct aac_fib_xporthdr)) |
| 69 | * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) + (ALIGN32 - 1), |
| 70 | &dev->hw_fib_pa); |
| 71 | if (dev->hw_fib_va == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | return -ENOMEM; |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 77 | * aac_fib_map_free - free the fib objects |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | * @dev: Adapter to free |
| 79 | * |
| 80 | * Free the PCI mappings and the memory allocated for FIB blocks |
| 81 | * on this adapter. |
| 82 | */ |
| 83 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 84 | void aac_fib_map_free(struct aac_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Salyzyn, Mark | 9ad5204 | 2007-07-17 11:15:08 -0400 | [diff] [blame] | 86 | pci_free_consistent(dev->pdev, |
| 87 | dev->max_fib_size * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB), |
| 88 | dev->hw_fib_va, dev->hw_fib_pa); |
| 89 | dev->hw_fib_va = NULL; |
| 90 | dev->hw_fib_pa = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 94 | * aac_fib_setup - setup the fibs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | * @dev: Adapter to set up |
| 96 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 97 | * Allocate the PCI space for the fibs, map it and then initialise the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | * fib area, the unmapped fib data and also the free list |
| 99 | */ |
| 100 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 101 | int aac_fib_setup(struct aac_dev * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
| 103 | struct fib *fibptr; |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 104 | struct hw_fib *hw_fib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | dma_addr_t hw_fib_pa; |
| 106 | int i; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 107 | |
| 108 | while (((i = fib_map_alloc(dev)) == -ENOMEM) |
| 109 | && (dev->scsi_host_ptr->can_queue > (64 - AAC_NUM_MGT_FIB))) { |
| 110 | dev->init->MaxIoCommands = cpu_to_le32((dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) >> 1); |
| 111 | dev->scsi_host_ptr->can_queue = le32_to_cpu(dev->init->MaxIoCommands) - AAC_NUM_MGT_FIB; |
| 112 | } |
| 113 | if (i<0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return -ENOMEM; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 115 | |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 116 | /* 32 byte alignment for PMC */ |
| 117 | hw_fib_pa = (dev->hw_fib_pa + (ALIGN32 - 1)) & ~(ALIGN32 - 1); |
| 118 | dev->hw_fib_va = (struct hw_fib *)((unsigned char *)dev->hw_fib_va + |
| 119 | (hw_fib_pa - dev->hw_fib_pa)); |
| 120 | dev->hw_fib_pa = hw_fib_pa; |
| 121 | memset(dev->hw_fib_va, 0, |
| 122 | (dev->max_fib_size + sizeof(struct aac_fib_xporthdr)) * |
| 123 | (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB)); |
| 124 | |
| 125 | /* add Xport header */ |
| 126 | dev->hw_fib_va = (struct hw_fib *)((unsigned char *)dev->hw_fib_va + |
| 127 | sizeof(struct aac_fib_xporthdr)); |
| 128 | dev->hw_fib_pa += sizeof(struct aac_fib_xporthdr); |
| 129 | |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 130 | hw_fib = dev->hw_fib_va; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | hw_fib_pa = dev->hw_fib_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /* |
| 133 | * Initialise the fibs |
| 134 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 135 | for (i = 0, fibptr = &dev->fibs[i]; |
| 136 | i < (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB); |
| 137 | i++, fibptr++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
| 139 | fibptr->dev = dev; |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 140 | fibptr->hw_fib_va = hw_fib; |
| 141 | fibptr->data = (void *) fibptr->hw_fib_va->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | fibptr->next = fibptr+1; /* Forward chain the fibs */ |
Thomas Gleixner | 6de76cf | 2010-09-07 14:32:47 +0000 | [diff] [blame] | 143 | sema_init(&fibptr->event_wait, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | spin_lock_init(&fibptr->event_lock); |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 145 | hw_fib->header.XferState = cpu_to_le32(0xffffffff); |
| 146 | hw_fib->header.SenderSize = cpu_to_le16(dev->max_fib_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | fibptr->hw_fib_pa = hw_fib_pa; |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 148 | hw_fib = (struct hw_fib *)((unsigned char *)hw_fib + |
| 149 | dev->max_fib_size + sizeof(struct aac_fib_xporthdr)); |
| 150 | hw_fib_pa = hw_fib_pa + |
| 151 | dev->max_fib_size + sizeof(struct aac_fib_xporthdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | /* |
| 154 | * Add the fib chain to the free list |
| 155 | */ |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 156 | dev->fibs[dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB - 1].next = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* |
| 158 | * Enable this to debug out of queue space |
| 159 | */ |
| 160 | dev->free_fib = &dev->fibs[0]; |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 165 | * aac_fib_alloc - allocate a fib |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | * @dev: Adapter to allocate the fib for |
| 167 | * |
| 168 | * Allocate a fib from the adapter fib pool. If the pool is empty we |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 169 | * return NULL. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 171 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 172 | struct fib *aac_fib_alloc(struct aac_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
| 174 | struct fib * fibptr; |
| 175 | unsigned long flags; |
| 176 | spin_lock_irqsave(&dev->fib_lock, flags); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 177 | fibptr = dev->free_fib; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 178 | if(!fibptr){ |
| 179 | spin_unlock_irqrestore(&dev->fib_lock, flags); |
| 180 | return fibptr; |
| 181 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | dev->free_fib = fibptr->next; |
| 183 | spin_unlock_irqrestore(&dev->fib_lock, flags); |
| 184 | /* |
| 185 | * Set the proper node type code and node byte size |
| 186 | */ |
| 187 | fibptr->type = FSAFS_NTC_FIB_CONTEXT; |
| 188 | fibptr->size = sizeof(struct fib); |
| 189 | /* |
| 190 | * Null out fields that depend on being zero at the start of |
| 191 | * each I/O |
| 192 | */ |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 193 | fibptr->hw_fib_va->header.XferState = 0; |
Salyzyn, Mark | b6ef70f | 2008-01-08 13:26:43 -0800 | [diff] [blame] | 194 | fibptr->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | fibptr->callback = NULL; |
| 196 | fibptr->callback_data = NULL; |
| 197 | |
| 198 | return fibptr; |
| 199 | } |
| 200 | |
| 201 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 202 | * aac_fib_free - free a fib |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | * @fibptr: fib to free up |
| 204 | * |
| 205 | * Frees up a fib and places it on the appropriate queue |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 207 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 208 | void aac_fib_free(struct fib *fibptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 210 | unsigned long flags, flagsv; |
| 211 | |
| 212 | spin_lock_irqsave(&fibptr->event_lock, flagsv); |
| 213 | if (fibptr->done == 2) { |
| 214 | spin_unlock_irqrestore(&fibptr->event_lock, flagsv); |
| 215 | return; |
| 216 | } |
| 217 | spin_unlock_irqrestore(&fibptr->event_lock, flagsv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | spin_lock_irqsave(&fibptr->dev->fib_lock, flags); |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 220 | if (unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | aac_config.fib_timeouts++; |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 222 | if (fibptr->hw_fib_va->header.XferState != 0) { |
| 223 | printk(KERN_WARNING "aac_fib_free, XferState != 0, fibptr = 0x%p, XferState = 0x%x\n", |
| 224 | (void*)fibptr, |
| 225 | le32_to_cpu(fibptr->hw_fib_va->header.XferState)); |
| 226 | } |
| 227 | fibptr->next = fibptr->dev->free_fib; |
| 228 | fibptr->dev->free_fib = fibptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | spin_unlock_irqrestore(&fibptr->dev->fib_lock, flags); |
| 230 | } |
| 231 | |
| 232 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 233 | * aac_fib_init - initialise a fib |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | * @fibptr: The fib to initialize |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 235 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | * Set up the generic fib fields ready for use |
| 237 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 238 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 239 | void aac_fib_init(struct fib *fibptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 241 | struct hw_fib *hw_fib = fibptr->hw_fib_va; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
| 243 | hw_fib->header.StructType = FIB_MAGIC; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 244 | hw_fib->header.Size = cpu_to_le16(fibptr->dev->max_fib_size); |
| 245 | hw_fib->header.XferState = cpu_to_le32(HostOwned | FibInitialized | FibEmpty | FastResponseCapable); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 246 | hw_fib->header.SenderFibAddress = 0; /* Filled in later if needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | hw_fib->header.ReceiverFibAddress = cpu_to_le32(fibptr->hw_fib_pa); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 248 | hw_fib->header.SenderSize = cpu_to_le16(fibptr->dev->max_fib_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /** |
| 252 | * fib_deallocate - deallocate a fib |
| 253 | * @fibptr: fib to deallocate |
| 254 | * |
| 255 | * Will deallocate and return to the free pool the FIB pointed to by the |
| 256 | * caller. |
| 257 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 258 | |
Adrian Bunk | 4833869 | 2005-04-25 19:45:58 -0700 | [diff] [blame] | 259 | static void fib_dealloc(struct fib * fibptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | { |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 261 | struct hw_fib *hw_fib = fibptr->hw_fib_va; |
Eric Sesterhenn | 125e187 | 2006-06-23 02:06:06 -0700 | [diff] [blame] | 262 | BUG_ON(hw_fib->header.StructType != FIB_MAGIC); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 263 | hw_fib->header.XferState = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /* |
| 267 | * Commuication primitives define and support the queuing method we use to |
| 268 | * support host to adapter commuication. All queue accesses happen through |
| 269 | * these routines and are the only routines which have a knowledge of the |
| 270 | * how these queues are implemented. |
| 271 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | /** |
| 274 | * aac_get_entry - get a queue entry |
| 275 | * @dev: Adapter |
| 276 | * @qid: Queue Number |
| 277 | * @entry: Entry return |
| 278 | * @index: Index return |
| 279 | * @nonotify: notification control |
| 280 | * |
| 281 | * With a priority the routine returns a queue entry if the queue has free entries. If the queue |
| 282 | * is full(no free entries) than no entry is returned and the function returns 0 otherwise 1 is |
| 283 | * returned. |
| 284 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | static int aac_get_entry (struct aac_dev * dev, u32 qid, struct aac_entry **entry, u32 * index, unsigned long *nonotify) |
| 287 | { |
| 288 | struct aac_queue * q; |
Mark Haverkamp | bed30de | 2005-08-03 15:38:51 -0700 | [diff] [blame] | 289 | unsigned long idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | /* |
| 292 | * All of the queues wrap when they reach the end, so we check |
| 293 | * to see if they have reached the end and if they have we just |
| 294 | * set the index back to zero. This is a wrap. You could or off |
| 295 | * the high bits in all updates but this is a bit faster I think. |
| 296 | */ |
| 297 | |
| 298 | q = &dev->queues->queue[qid]; |
Mark Haverkamp | bed30de | 2005-08-03 15:38:51 -0700 | [diff] [blame] | 299 | |
| 300 | idx = *index = le32_to_cpu(*(q->headers.producer)); |
| 301 | /* Interrupt Moderation, only interrupt for first two entries */ |
| 302 | if (idx != le32_to_cpu(*(q->headers.consumer))) { |
| 303 | if (--idx == 0) { |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 304 | if (qid == AdapNormCmdQueue) |
Mark Haverkamp | bed30de | 2005-08-03 15:38:51 -0700 | [diff] [blame] | 305 | idx = ADAP_NORM_CMD_ENTRIES; |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 306 | else |
Mark Haverkamp | bed30de | 2005-08-03 15:38:51 -0700 | [diff] [blame] | 307 | idx = ADAP_NORM_RESP_ENTRIES; |
| 308 | } |
| 309 | if (idx != le32_to_cpu(*(q->headers.consumer))) |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 310 | *nonotify = 1; |
Mark Haverkamp | bed30de | 2005-08-03 15:38:51 -0700 | [diff] [blame] | 311 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 313 | if (qid == AdapNormCmdQueue) { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 314 | if (*index >= ADAP_NORM_CMD_ENTRIES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | *index = 0; /* Wrap to front of the Producer Queue. */ |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 316 | } else { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 317 | if (*index >= ADAP_NORM_RESP_ENTRIES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | *index = 0; /* Wrap to front of the Producer Queue. */ |
| 319 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 321 | /* Queue is full */ |
| 322 | if ((*index + 1) == le32_to_cpu(*(q->headers.consumer))) { |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 323 | printk(KERN_WARNING "Queue %d full, %u outstanding.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | qid, q->numpending); |
| 325 | return 0; |
| 326 | } else { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 327 | *entry = q->base + *index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | return 1; |
| 329 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 330 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
| 332 | /** |
| 333 | * aac_queue_get - get the next free QE |
| 334 | * @dev: Adapter |
| 335 | * @index: Returned index |
| 336 | * @priority: Priority of fib |
| 337 | * @fib: Fib to associate with the queue entry |
| 338 | * @wait: Wait if queue full |
| 339 | * @fibptr: Driver fib object to go with fib |
| 340 | * @nonotify: Don't notify the adapter |
| 341 | * |
| 342 | * Gets the next free QE off the requested priorty adapter command |
| 343 | * queue and associates the Fib with the QE. The QE represented by |
| 344 | * index is ready to insert on the queue when this routine returns |
| 345 | * success. |
| 346 | */ |
| 347 | |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 348 | int aac_queue_get(struct aac_dev * dev, u32 * index, u32 qid, struct hw_fib * hw_fib, int wait, struct fib * fibptr, unsigned long *nonotify) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
| 350 | struct aac_entry * entry = NULL; |
| 351 | int map = 0; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 352 | |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 353 | if (qid == AdapNormCmdQueue) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | /* if no entries wait for some if caller wants to */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 355 | while (!aac_get_entry(dev, qid, &entry, index, nonotify)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | printk(KERN_ERR "GetEntries failed\n"); |
| 357 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 358 | /* |
| 359 | * Setup queue entry with a command, status and fib mapped |
| 360 | */ |
| 361 | entry->size = cpu_to_le32(le16_to_cpu(hw_fib->header.Size)); |
| 362 | map = 1; |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 363 | } else { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 364 | while (!aac_get_entry(dev, qid, &entry, index, nonotify)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | /* if no entries wait for some if caller wants to */ |
| 366 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 367 | /* |
| 368 | * Setup queue entry with command, status and fib mapped |
| 369 | */ |
| 370 | entry->size = cpu_to_le32(le16_to_cpu(hw_fib->header.Size)); |
| 371 | entry->addr = hw_fib->header.SenderFibAddress; |
| 372 | /* Restore adapters pointer to the FIB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | hw_fib->header.ReceiverFibAddress = hw_fib->header.SenderFibAddress; /* Let the adapter now where to find its data */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 374 | map = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | /* |
| 377 | * If MapFib is true than we need to map the Fib and put pointers |
| 378 | * in the queue entry. |
| 379 | */ |
| 380 | if (map) |
| 381 | entry->addr = cpu_to_le32(fibptr->hw_fib_pa); |
| 382 | return 0; |
| 383 | } |
| 384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | /* |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 386 | * Define the highest level of host to adapter communication routines. |
| 387 | * These routines will support host to adapter FS commuication. These |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | * routines have no knowledge of the commuication method used. This level |
| 389 | * sends and receives FIBs. This level has no knowledge of how these FIBs |
| 390 | * get passed back and forth. |
| 391 | */ |
| 392 | |
| 393 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 394 | * aac_fib_send - send a fib to the adapter |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | * @command: Command to send |
| 396 | * @fibptr: The fib |
| 397 | * @size: Size of fib data area |
| 398 | * @priority: Priority of Fib |
| 399 | * @wait: Async/sync select |
| 400 | * @reply: True if a reply is wanted |
| 401 | * @callback: Called with reply |
| 402 | * @callback_data: Passed to callback |
| 403 | * |
| 404 | * Sends the requested FIB to the adapter and optionally will wait for a |
| 405 | * response FIB. If the caller does not wish to wait for a response than |
| 406 | * an event to wait on must be supplied. This event will be set when a |
| 407 | * response FIB is received from the adapter. |
| 408 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 409 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 410 | int aac_fib_send(u16 command, struct fib *fibptr, unsigned long size, |
| 411 | int priority, int wait, int reply, fib_callback callback, |
| 412 | void *callback_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | struct aac_dev * dev = fibptr->dev; |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 415 | struct hw_fib * hw_fib = fibptr->hw_fib_va; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | unsigned long flags = 0; |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 417 | unsigned long qflags; |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 418 | unsigned long mflags = 0; |
Mahesh Rajashekhara | 1160461 | 2012-02-08 22:51:04 -0800 | [diff] [blame^] | 419 | unsigned long sflags = 0; |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 420 | |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | if (!(hw_fib->header.XferState & cpu_to_le32(HostOwned))) |
| 423 | return -EBUSY; |
| 424 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 425 | * There are 5 cases with the wait and response requested flags. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | * The only invalid cases are if the caller requests to wait and |
| 427 | * does not request a response and if the caller does not want a |
| 428 | * response and the Fib is not allocated from pool. If a response |
| 429 | * is not requesed the Fib will just be deallocaed by the DPC |
| 430 | * routine when the response comes back from the adapter. No |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 431 | * further processing will be done besides deleting the Fib. We |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | * will have a debug mode where the adapter can notify the host |
| 433 | * it had a problem and the host can log that fact. |
| 434 | */ |
Salyzyn, Mark | b6ef70f | 2008-01-08 13:26:43 -0800 | [diff] [blame] | 435 | fibptr->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | if (wait && !reply) { |
| 437 | return -EINVAL; |
| 438 | } else if (!wait && reply) { |
| 439 | hw_fib->header.XferState |= cpu_to_le32(Async | ResponseExpected); |
| 440 | FIB_COUNTER_INCREMENT(aac_config.AsyncSent); |
| 441 | } else if (!wait && !reply) { |
| 442 | hw_fib->header.XferState |= cpu_to_le32(NoResponseExpected); |
| 443 | FIB_COUNTER_INCREMENT(aac_config.NoResponseSent); |
| 444 | } else if (wait && reply) { |
| 445 | hw_fib->header.XferState |= cpu_to_le32(ResponseExpected); |
| 446 | FIB_COUNTER_INCREMENT(aac_config.NormalSent); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 447 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | /* |
| 449 | * Map the fib into 32bits by using the fib number |
| 450 | */ |
| 451 | |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 452 | hw_fib->header.SenderFibAddress = cpu_to_le32(((u32)(fibptr - dev->fibs)) << 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | hw_fib->header.SenderData = (u32)(fibptr - dev->fibs); |
| 454 | /* |
| 455 | * Set FIB state to indicate where it came from and if we want a |
| 456 | * response from the adapter. Also load the command from the |
| 457 | * caller. |
| 458 | * |
| 459 | * Map the hw fib pointer as a 32bit value |
| 460 | */ |
| 461 | hw_fib->header.Command = cpu_to_le16(command); |
| 462 | hw_fib->header.XferState |= cpu_to_le32(SentFromHost); |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 463 | fibptr->hw_fib_va->header.Flags = 0; /* 0 the flags field - internal only*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | /* |
| 465 | * Set the size of the Fib we want to send to the adapter |
| 466 | */ |
| 467 | hw_fib->header.Size = cpu_to_le16(sizeof(struct aac_fibhdr) + size); |
| 468 | if (le16_to_cpu(hw_fib->header.Size) > le16_to_cpu(hw_fib->header.SenderSize)) { |
| 469 | return -EMSGSIZE; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 470 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | /* |
| 472 | * Get a queue entry connect the FIB to it and send an notify |
| 473 | * the adapter a command is ready. |
| 474 | */ |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 475 | hw_fib->header.XferState |= cpu_to_le32(NormalPriority); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | /* |
| 478 | * Fill in the Callback and CallbackContext if we are not |
| 479 | * going to wait. |
| 480 | */ |
| 481 | if (!wait) { |
| 482 | fibptr->callback = callback; |
| 483 | fibptr->callback_data = callback_data; |
Salyzyn, Mark | b6ef70f | 2008-01-08 13:26:43 -0800 | [diff] [blame] | 484 | fibptr->flags = FIB_CONTEXT_FLAG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
| 487 | fibptr->done = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 489 | FIB_COUNTER_INCREMENT(aac_config.FibsSent); |
| 490 | |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 491 | dprintk((KERN_DEBUG "Fib contents:.\n")); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 492 | dprintk((KERN_DEBUG " Command = %d.\n", le32_to_cpu(hw_fib->header.Command))); |
| 493 | dprintk((KERN_DEBUG " SubCommand = %d.\n", le32_to_cpu(((struct aac_query_mount *)fib_data(fibptr))->command))); |
| 494 | dprintk((KERN_DEBUG " XferState = %x.\n", le32_to_cpu(hw_fib->header.XferState))); |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 495 | dprintk((KERN_DEBUG " hw_fib va being sent=%p\n",fibptr->hw_fib_va)); |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 496 | dprintk((KERN_DEBUG " hw_fib pa being sent=%lx\n",(ulong)fibptr->hw_fib_pa)); |
| 497 | dprintk((KERN_DEBUG " fib being sent=%p\n",fibptr)); |
| 498 | |
Mark Haverkamp | c8f7b07 | 2006-08-03 08:02:24 -0700 | [diff] [blame] | 499 | if (!dev->queues) |
Mark Haverkamp | 65101355 | 2006-09-19 08:59:23 -0700 | [diff] [blame] | 500 | return -EBUSY; |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 501 | |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 502 | if (wait) { |
| 503 | |
| 504 | spin_lock_irqsave(&dev->manage_lock, mflags); |
| 505 | if (dev->management_fib_count >= AAC_NUM_MGT_FIB) { |
| 506 | printk(KERN_INFO "No management Fibs Available:%d\n", |
| 507 | dev->management_fib_count); |
| 508 | spin_unlock_irqrestore(&dev->manage_lock, mflags); |
| 509 | return -EBUSY; |
| 510 | } |
| 511 | dev->management_fib_count++; |
| 512 | spin_unlock_irqrestore(&dev->manage_lock, mflags); |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 513 | spin_lock_irqsave(&fibptr->event_lock, flags); |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 514 | } |
| 515 | |
Mahesh Rajashekhara | 1160461 | 2012-02-08 22:51:04 -0800 | [diff] [blame^] | 516 | if (dev->sync_mode) { |
| 517 | if (wait) |
| 518 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
| 519 | spin_lock_irqsave(&dev->sync_lock, sflags); |
| 520 | if (dev->sync_fib) { |
| 521 | list_add_tail(&fibptr->fiblink, &dev->sync_fib_list); |
| 522 | spin_unlock_irqrestore(&dev->sync_lock, sflags); |
| 523 | } else { |
| 524 | dev->sync_fib = fibptr; |
| 525 | spin_unlock_irqrestore(&dev->sync_lock, sflags); |
| 526 | aac_adapter_sync_cmd(dev, SEND_SYNCHRONOUS_FIB, |
| 527 | (u32)fibptr->hw_fib_pa, 0, 0, 0, 0, 0, |
| 528 | NULL, NULL, NULL, NULL, NULL); |
| 529 | } |
| 530 | if (wait) { |
| 531 | fibptr->flags |= FIB_CONTEXT_FLAG_WAIT; |
| 532 | if (down_interruptible(&fibptr->event_wait)) { |
| 533 | fibptr->flags &= ~FIB_CONTEXT_FLAG_WAIT; |
| 534 | return -EFAULT; |
| 535 | } |
| 536 | return 0; |
| 537 | } |
| 538 | return -EINPROGRESS; |
| 539 | } |
| 540 | |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 541 | if (aac_adapter_deliver(fibptr) != 0) { |
| 542 | printk(KERN_ERR "aac_fib_send: returned -EBUSY\n"); |
| 543 | if (wait) { |
| 544 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
| 545 | spin_lock_irqsave(&dev->manage_lock, mflags); |
| 546 | dev->management_fib_count--; |
| 547 | spin_unlock_irqrestore(&dev->manage_lock, mflags); |
| 548 | } |
| 549 | return -EBUSY; |
| 550 | } |
| 551 | |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | /* |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 554 | * If the caller wanted us to wait for response wait now. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | if (wait) { |
| 558 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 559 | /* Only set for first known interruptable command */ |
| 560 | if (wait < 0) { |
| 561 | /* |
| 562 | * *VERY* Dangerous to time out a command, the |
| 563 | * assumption is made that we have no hope of |
| 564 | * functioning because an interrupt routing or other |
| 565 | * hardware failure has occurred. |
| 566 | */ |
| 567 | unsigned long count = 36000000L; /* 3 minutes */ |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 568 | while (down_trylock(&fibptr->event_wait)) { |
Mark Haverkamp | 33524b7 | 2006-11-21 10:40:08 -0800 | [diff] [blame] | 569 | int blink; |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 570 | if (--count == 0) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 571 | struct aac_queue * q = &dev->queues->queue[AdapNormCmdQueue]; |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 572 | spin_lock_irqsave(q->lock, qflags); |
| 573 | q->numpending--; |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 574 | spin_unlock_irqrestore(q->lock, qflags); |
| 575 | if (wait == -1) { |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 576 | printk(KERN_ERR "aacraid: aac_fib_send: first asynchronous command timed out.\n" |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 577 | "Usually a result of a PCI interrupt routing problem;\n" |
| 578 | "update mother board BIOS or consider utilizing one of\n" |
| 579 | "the SAFE mode kernel options (acpi, apic etc)\n"); |
| 580 | } |
| 581 | return -ETIMEDOUT; |
| 582 | } |
Mark Haverkamp | 33524b7 | 2006-11-21 10:40:08 -0800 | [diff] [blame] | 583 | if ((blink = aac_adapter_check_health(dev)) > 0) { |
| 584 | if (wait == -1) { |
| 585 | printk(KERN_ERR "aacraid: aac_fib_send: adapter blinkLED 0x%x.\n" |
| 586 | "Usually a result of a serious unrecoverable hardware problem\n", |
| 587 | blink); |
| 588 | } |
| 589 | return -EFAULT; |
| 590 | } |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 591 | udelay(5); |
| 592 | } |
Mark Salyzyn | 0462590 | 2008-04-23 08:16:06 -0400 | [diff] [blame] | 593 | } else if (down_interruptible(&fibptr->event_wait)) { |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 594 | /* Do nothing ... satisfy |
| 595 | * down_interruptible must_check */ |
Mark Salyzyn | e6990c6 | 2008-04-14 14:20:16 -0400 | [diff] [blame] | 596 | } |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 597 | |
Mark Haverkamp | 33bb3b2 | 2007-03-15 10:27:21 -0700 | [diff] [blame] | 598 | spin_lock_irqsave(&fibptr->event_lock, flags); |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 599 | if (fibptr->done == 0) { |
Mark Haverkamp | 33bb3b2 | 2007-03-15 10:27:21 -0700 | [diff] [blame] | 600 | fibptr->done = 2; /* Tell interrupt we aborted */ |
Mark Haverkamp | c8f7b07 | 2006-08-03 08:02:24 -0700 | [diff] [blame] | 601 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 602 | return -ERESTARTSYS; |
Mark Haverkamp | c8f7b07 | 2006-08-03 08:02:24 -0700 | [diff] [blame] | 603 | } |
Mark Haverkamp | 33bb3b2 | 2007-03-15 10:27:21 -0700 | [diff] [blame] | 604 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
Eric Sesterhenn | 125e187 | 2006-06-23 02:06:06 -0700 | [diff] [blame] | 605 | BUG_ON(fibptr->done == 0); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 606 | |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 607 | if(unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | return -ETIMEDOUT; |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 609 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | /* |
| 612 | * If the user does not want a response than return success otherwise |
| 613 | * return pending |
| 614 | */ |
| 615 | if (reply) |
| 616 | return -EINPROGRESS; |
| 617 | else |
| 618 | return 0; |
| 619 | } |
| 620 | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 621 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | * aac_consumer_get - get the top of the queue |
| 623 | * @dev: Adapter |
| 624 | * @q: Queue |
| 625 | * @entry: Return entry |
| 626 | * |
| 627 | * Will return a pointer to the entry on the top of the queue requested that |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 628 | * we are a consumer of, and return the address of the queue entry. It does |
| 629 | * not change the state of the queue. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | */ |
| 631 | |
| 632 | int aac_consumer_get(struct aac_dev * dev, struct aac_queue * q, struct aac_entry **entry) |
| 633 | { |
| 634 | u32 index; |
| 635 | int status; |
| 636 | if (le32_to_cpu(*q->headers.producer) == le32_to_cpu(*q->headers.consumer)) { |
| 637 | status = 0; |
| 638 | } else { |
| 639 | /* |
| 640 | * The consumer index must be wrapped if we have reached |
| 641 | * the end of the queue, else we just use the entry |
| 642 | * pointed to by the header index |
| 643 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 644 | if (le32_to_cpu(*q->headers.consumer) >= q->entries) |
| 645 | index = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | else |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 647 | index = le32_to_cpu(*q->headers.consumer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | *entry = q->base + index; |
| 649 | status = 1; |
| 650 | } |
| 651 | return(status); |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * aac_consumer_free - free consumer entry |
| 656 | * @dev: Adapter |
| 657 | * @q: Queue |
| 658 | * @qid: Queue ident |
| 659 | * |
| 660 | * Frees up the current top of the queue we are a consumer of. If the |
| 661 | * queue was full notify the producer that the queue is no longer full. |
| 662 | */ |
| 663 | |
| 664 | void aac_consumer_free(struct aac_dev * dev, struct aac_queue *q, u32 qid) |
| 665 | { |
| 666 | int wasfull = 0; |
| 667 | u32 notify; |
| 668 | |
| 669 | if ((le32_to_cpu(*q->headers.producer)+1) == le32_to_cpu(*q->headers.consumer)) |
| 670 | wasfull = 1; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | if (le32_to_cpu(*q->headers.consumer) >= q->entries) |
| 673 | *q->headers.consumer = cpu_to_le32(1); |
| 674 | else |
Marcin Slusarz | 36b8dd1 | 2008-03-28 14:48:35 -0700 | [diff] [blame] | 675 | le32_add_cpu(q->headers.consumer, 1); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | if (wasfull) { |
| 678 | switch (qid) { |
| 679 | |
| 680 | case HostNormCmdQueue: |
| 681 | notify = HostNormCmdNotFull; |
| 682 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | case HostNormRespQueue: |
| 684 | notify = HostNormRespNotFull; |
| 685 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | default: |
| 687 | BUG(); |
| 688 | return; |
| 689 | } |
| 690 | aac_adapter_notify(dev, notify); |
| 691 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 692 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
| 694 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 695 | * aac_fib_adapter_complete - complete adapter issued fib |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | * @fibptr: fib to complete |
| 697 | * @size: size of fib |
| 698 | * |
| 699 | * Will do all necessary work to complete a FIB that was sent from |
| 700 | * the adapter. |
| 701 | */ |
| 702 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 703 | int aac_fib_adapter_complete(struct fib *fibptr, unsigned short size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | { |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 705 | struct hw_fib * hw_fib = fibptr->hw_fib_va; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | struct aac_dev * dev = fibptr->dev; |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 707 | struct aac_queue * q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | unsigned long nointr = 0; |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 709 | unsigned long qflags; |
| 710 | |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 711 | if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1) { |
| 712 | kfree(hw_fib); |
| 713 | return 0; |
| 714 | } |
| 715 | |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 716 | if (hw_fib->header.XferState == 0) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 717 | if (dev->comm_interface == AAC_COMM_MESSAGE) |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 718 | kfree(hw_fib); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 719 | return 0; |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 720 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | /* |
| 722 | * If we plan to do anything check the structure type first. |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 723 | */ |
| 724 | if (hw_fib->header.StructType != FIB_MAGIC) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 725 | if (dev->comm_interface == AAC_COMM_MESSAGE) |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 726 | kfree(hw_fib); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 727 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | } |
| 729 | /* |
| 730 | * This block handles the case where the adapter had sent us a |
| 731 | * command and we have finished processing the command. We |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 732 | * call completeFib when we are done processing the command |
| 733 | * and want to send a response back to the adapter. This will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | * send the completed cdb to the adapter. |
| 735 | */ |
| 736 | if (hw_fib->header.XferState & cpu_to_le32(SentFromAdapter)) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 737 | if (dev->comm_interface == AAC_COMM_MESSAGE) { |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 738 | kfree (hw_fib); |
| 739 | } else { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 740 | u32 index; |
| 741 | hw_fib->header.XferState |= cpu_to_le32(HostProcessed); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 742 | if (size) { |
| 743 | size += sizeof(struct aac_fibhdr); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 744 | if (size > le16_to_cpu(hw_fib->header.SenderSize)) |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 745 | return -EMSGSIZE; |
| 746 | hw_fib->header.Size = cpu_to_le16(size); |
| 747 | } |
| 748 | q = &dev->queues->queue[AdapNormRespQueue]; |
| 749 | spin_lock_irqsave(q->lock, qflags); |
| 750 | aac_queue_get(dev, &index, AdapNormRespQueue, hw_fib, 1, NULL, &nointr); |
| 751 | *(q->headers.producer) = cpu_to_le32(index + 1); |
| 752 | spin_unlock_irqrestore(q->lock, qflags); |
| 753 | if (!(nointr & (int)aac_config.irq_mod)) |
| 754 | aac_adapter_notify(dev, AdapNormRespQueue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 756 | } else { |
| 757 | printk(KERN_WARNING "aac_fib_adapter_complete: " |
| 758 | "Unknown xferstate detected.\n"); |
| 759 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 765 | * aac_fib_complete - fib completion handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | * @fib: FIB to complete |
| 767 | * |
| 768 | * Will do all necessary work to complete a FIB. |
| 769 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 770 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 771 | int aac_fib_complete(struct fib *fibptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | { |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 773 | unsigned long flags; |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 774 | struct hw_fib * hw_fib = fibptr->hw_fib_va; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
| 776 | /* |
| 777 | * Check for a fib which has already been completed |
| 778 | */ |
| 779 | |
| 780 | if (hw_fib->header.XferState == 0) |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 781 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | /* |
| 783 | * If we plan to do anything check the structure type first. |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 784 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
| 786 | if (hw_fib->header.StructType != FIB_MAGIC) |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 787 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | /* |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 789 | * This block completes a cdb which orginated on the host and we |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | * just need to deallocate the cdb or reinit it. At this point the |
| 791 | * command is complete that we had sent to the adapter and this |
| 792 | * cdb could be reused. |
| 793 | */ |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 794 | spin_lock_irqsave(&fibptr->event_lock, flags); |
| 795 | if (fibptr->done == 2) { |
| 796 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
| 797 | return 0; |
| 798 | } |
| 799 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
| 800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | if((hw_fib->header.XferState & cpu_to_le32(SentFromHost)) && |
| 802 | (hw_fib->header.XferState & cpu_to_le32(AdapterProcessed))) |
| 803 | { |
| 804 | fib_dealloc(fibptr); |
| 805 | } |
| 806 | else if(hw_fib->header.XferState & cpu_to_le32(SentFromHost)) |
| 807 | { |
| 808 | /* |
| 809 | * This handles the case when the host has aborted the I/O |
| 810 | * to the adapter because the adapter is not responding |
| 811 | */ |
| 812 | fib_dealloc(fibptr); |
| 813 | } else if(hw_fib->header.XferState & cpu_to_le32(HostOwned)) { |
| 814 | fib_dealloc(fibptr); |
| 815 | } else { |
| 816 | BUG(); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 817 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | /** |
| 822 | * aac_printf - handle printf from firmware |
| 823 | * @dev: Adapter |
| 824 | * @val: Message info |
| 825 | * |
| 826 | * Print a message passed to us by the controller firmware on the |
| 827 | * Adaptec board |
| 828 | */ |
| 829 | |
| 830 | void aac_printf(struct aac_dev *dev, u32 val) |
| 831 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | char *cp = dev->printfbuf; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 833 | if (dev->printf_enabled) |
| 834 | { |
| 835 | int length = val & 0xffff; |
| 836 | int level = (val >> 16) & 0xffff; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 837 | |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 838 | /* |
| 839 | * The size of the printfbuf is set in port.c |
| 840 | * There is no variable or define for it |
| 841 | */ |
| 842 | if (length > 255) |
| 843 | length = 255; |
| 844 | if (cp[length] != 0) |
| 845 | cp[length] = 0; |
| 846 | if (level == LOG_AAC_HIGH_ERROR) |
Mark Haverkamp | 1241f35 | 2006-03-27 09:44:23 -0800 | [diff] [blame] | 847 | printk(KERN_WARNING "%s:%s", dev->name, cp); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 848 | else |
Mark Haverkamp | 1241f35 | 2006-03-27 09:44:23 -0800 | [diff] [blame] | 849 | printk(KERN_INFO "%s:%s", dev->name, cp); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 850 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 851 | memset(cp, 0, 256); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | } |
| 853 | |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 854 | |
| 855 | /** |
| 856 | * aac_handle_aif - Handle a message from the firmware |
| 857 | * @dev: Which adapter this fib is from |
| 858 | * @fibptr: Pointer to fibptr from adapter |
| 859 | * |
| 860 | * This routine handles a driver notify fib from the adapter and |
| 861 | * dispatches it to the appropriate routine for handling. |
| 862 | */ |
| 863 | |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 864 | #define AIF_SNIFF_TIMEOUT (30*HZ) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 865 | static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr) |
| 866 | { |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 867 | struct hw_fib * hw_fib = fibptr->hw_fib_va; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 868 | struct aac_aifcmd * aifcmd = (struct aac_aifcmd *)hw_fib->data; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 869 | u32 channel, id, lun, container; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 870 | struct scsi_device *device; |
| 871 | enum { |
| 872 | NOTHING, |
| 873 | DELETE, |
| 874 | ADD, |
| 875 | CHANGE |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 876 | } device_config_needed = NOTHING; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 877 | |
| 878 | /* Sniff for container changes */ |
| 879 | |
Mark Haverkamp | c8f7b07 | 2006-08-03 08:02:24 -0700 | [diff] [blame] | 880 | if (!dev || !dev->fsa_dev) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 881 | return; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 882 | container = channel = id = lun = (u32)-1; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 883 | |
| 884 | /* |
| 885 | * We have set this up to try and minimize the number of |
| 886 | * re-configures that take place. As a result of this when |
| 887 | * certain AIF's come in we will set a flag waiting for another |
| 888 | * type of AIF before setting the re-config flag. |
| 889 | */ |
| 890 | switch (le32_to_cpu(aifcmd->command)) { |
| 891 | case AifCmdDriverNotify: |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 892 | switch (le32_to_cpu(((__le32 *)aifcmd->data)[0])) { |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 893 | /* |
| 894 | * Morph or Expand complete |
| 895 | */ |
| 896 | case AifDenMorphComplete: |
| 897 | case AifDenVolumeExtendComplete: |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 898 | container = le32_to_cpu(((__le32 *)aifcmd->data)[1]); |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 899 | if (container >= dev->maximum_num_containers) |
| 900 | break; |
| 901 | |
| 902 | /* |
Christoph Hellwig | f64a181 | 2005-10-31 18:32:08 +0100 | [diff] [blame] | 903 | * Find the scsi_device associated with the SCSI |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 904 | * address. Make sure we have the right array, and if |
| 905 | * so set the flag to initiate a new re-config once we |
| 906 | * see an AifEnConfigChange AIF come through. |
| 907 | */ |
| 908 | |
| 909 | if ((dev != NULL) && (dev->scsi_host_ptr != NULL)) { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 910 | device = scsi_device_lookup(dev->scsi_host_ptr, |
| 911 | CONTAINER_TO_CHANNEL(container), |
| 912 | CONTAINER_TO_ID(container), |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 913 | CONTAINER_TO_LUN(container)); |
| 914 | if (device) { |
| 915 | dev->fsa_dev[container].config_needed = CHANGE; |
| 916 | dev->fsa_dev[container].config_waiting_on = AifEnConfigChange; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 917 | dev->fsa_dev[container].config_waiting_stamp = jiffies; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 918 | scsi_device_put(device); |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | /* |
| 924 | * If we are waiting on something and this happens to be |
| 925 | * that thing then set the re-configure flag. |
| 926 | */ |
| 927 | if (container != (u32)-1) { |
| 928 | if (container >= dev->maximum_num_containers) |
| 929 | break; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 930 | if ((dev->fsa_dev[container].config_waiting_on == |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 931 | le32_to_cpu(*(__le32 *)aifcmd->data)) && |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 932 | time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 933 | dev->fsa_dev[container].config_waiting_on = 0; |
| 934 | } else for (container = 0; |
| 935 | container < dev->maximum_num_containers; ++container) { |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 936 | if ((dev->fsa_dev[container].config_waiting_on == |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 937 | le32_to_cpu(*(__le32 *)aifcmd->data)) && |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 938 | time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 939 | dev->fsa_dev[container].config_waiting_on = 0; |
| 940 | } |
| 941 | break; |
| 942 | |
| 943 | case AifCmdEventNotify: |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 944 | switch (le32_to_cpu(((__le32 *)aifcmd->data)[0])) { |
Salyzyn, Mark | 95e852e | 2008-01-08 12:01:07 -0800 | [diff] [blame] | 945 | case AifEnBatteryEvent: |
| 946 | dev->cache_protected = |
| 947 | (((__le32 *)aifcmd->data)[1] == cpu_to_le32(3)); |
| 948 | break; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 949 | /* |
| 950 | * Add an Array. |
| 951 | */ |
| 952 | case AifEnAddContainer: |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 953 | container = le32_to_cpu(((__le32 *)aifcmd->data)[1]); |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 954 | if (container >= dev->maximum_num_containers) |
| 955 | break; |
| 956 | dev->fsa_dev[container].config_needed = ADD; |
| 957 | dev->fsa_dev[container].config_waiting_on = |
| 958 | AifEnConfigChange; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 959 | dev->fsa_dev[container].config_waiting_stamp = jiffies; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 960 | break; |
| 961 | |
| 962 | /* |
| 963 | * Delete an Array. |
| 964 | */ |
| 965 | case AifEnDeleteContainer: |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 966 | container = le32_to_cpu(((__le32 *)aifcmd->data)[1]); |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 967 | if (container >= dev->maximum_num_containers) |
| 968 | break; |
| 969 | dev->fsa_dev[container].config_needed = DELETE; |
| 970 | dev->fsa_dev[container].config_waiting_on = |
| 971 | AifEnConfigChange; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 972 | dev->fsa_dev[container].config_waiting_stamp = jiffies; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 973 | break; |
| 974 | |
| 975 | /* |
| 976 | * Container change detected. If we currently are not |
| 977 | * waiting on something else, setup to wait on a Config Change. |
| 978 | */ |
| 979 | case AifEnContainerChange: |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 980 | container = le32_to_cpu(((__le32 *)aifcmd->data)[1]); |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 981 | if (container >= dev->maximum_num_containers) |
| 982 | break; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 983 | if (dev->fsa_dev[container].config_waiting_on && |
| 984 | time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 985 | break; |
| 986 | dev->fsa_dev[container].config_needed = CHANGE; |
| 987 | dev->fsa_dev[container].config_waiting_on = |
| 988 | AifEnConfigChange; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 989 | dev->fsa_dev[container].config_waiting_stamp = jiffies; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 990 | break; |
| 991 | |
| 992 | case AifEnConfigChange: |
| 993 | break; |
| 994 | |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 995 | case AifEnAddJBOD: |
| 996 | case AifEnDeleteJBOD: |
| 997 | container = le32_to_cpu(((__le32 *)aifcmd->data)[1]); |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 998 | if ((container >> 28)) { |
| 999 | container = (u32)-1; |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1000 | break; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1001 | } |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1002 | channel = (container >> 24) & 0xF; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1003 | if (channel >= dev->maximum_num_channels) { |
| 1004 | container = (u32)-1; |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1005 | break; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1006 | } |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1007 | id = container & 0xFFFF; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1008 | if (id >= dev->maximum_num_physicals) { |
| 1009 | container = (u32)-1; |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1010 | break; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1011 | } |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1012 | lun = (container >> 16) & 0xFF; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1013 | container = (u32)-1; |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1014 | channel = aac_phys_to_logical(channel); |
| 1015 | device_config_needed = |
| 1016 | (((__le32 *)aifcmd->data)[0] == |
| 1017 | cpu_to_le32(AifEnAddJBOD)) ? ADD : DELETE; |
Rajashekhara, Mahesh | 5ca0559 | 2010-05-10 04:05:50 -0700 | [diff] [blame] | 1018 | if (device_config_needed == ADD) { |
| 1019 | device = scsi_device_lookup(dev->scsi_host_ptr, |
| 1020 | channel, |
| 1021 | id, |
| 1022 | lun); |
| 1023 | if (device) { |
| 1024 | scsi_remove_device(device); |
| 1025 | scsi_device_put(device); |
| 1026 | } |
| 1027 | } |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1028 | break; |
| 1029 | |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1030 | case AifEnEnclosureManagement: |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1031 | /* |
| 1032 | * If in JBOD mode, automatic exposure of new |
| 1033 | * physical target to be suppressed until configured. |
| 1034 | */ |
| 1035 | if (dev->jbod) |
| 1036 | break; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1037 | switch (le32_to_cpu(((__le32 *)aifcmd->data)[3])) { |
| 1038 | case EM_DRIVE_INSERTION: |
| 1039 | case EM_DRIVE_REMOVAL: |
| 1040 | container = le32_to_cpu( |
| 1041 | ((__le32 *)aifcmd->data)[2]); |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1042 | if ((container >> 28)) { |
| 1043 | container = (u32)-1; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1044 | break; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1045 | } |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1046 | channel = (container >> 24) & 0xF; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1047 | if (channel >= dev->maximum_num_channels) { |
| 1048 | container = (u32)-1; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1049 | break; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1050 | } |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1051 | id = container & 0xFFFF; |
| 1052 | lun = (container >> 16) & 0xFF; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1053 | container = (u32)-1; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1054 | if (id >= dev->maximum_num_physicals) { |
| 1055 | /* legacy dev_t ? */ |
| 1056 | if ((0x2000 <= id) || lun || channel || |
| 1057 | ((channel = (id >> 7) & 0x3F) >= |
| 1058 | dev->maximum_num_channels)) |
| 1059 | break; |
| 1060 | lun = (id >> 4) & 7; |
| 1061 | id &= 0xF; |
| 1062 | } |
| 1063 | channel = aac_phys_to_logical(channel); |
| 1064 | device_config_needed = |
| 1065 | (((__le32 *)aifcmd->data)[3] |
| 1066 | == cpu_to_le32(EM_DRIVE_INSERTION)) ? |
| 1067 | ADD : DELETE; |
| 1068 | break; |
| 1069 | } |
| 1070 | break; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | /* |
| 1074 | * If we are waiting on something and this happens to be |
| 1075 | * that thing then set the re-configure flag. |
| 1076 | */ |
| 1077 | if (container != (u32)-1) { |
| 1078 | if (container >= dev->maximum_num_containers) |
| 1079 | break; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1080 | if ((dev->fsa_dev[container].config_waiting_on == |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1081 | le32_to_cpu(*(__le32 *)aifcmd->data)) && |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1082 | time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1083 | dev->fsa_dev[container].config_waiting_on = 0; |
| 1084 | } else for (container = 0; |
| 1085 | container < dev->maximum_num_containers; ++container) { |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1086 | if ((dev->fsa_dev[container].config_waiting_on == |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1087 | le32_to_cpu(*(__le32 *)aifcmd->data)) && |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1088 | time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1089 | dev->fsa_dev[container].config_waiting_on = 0; |
| 1090 | } |
| 1091 | break; |
| 1092 | |
| 1093 | case AifCmdJobProgress: |
| 1094 | /* |
| 1095 | * These are job progress AIF's. When a Clear is being |
| 1096 | * done on a container it is initially created then hidden from |
| 1097 | * the OS. When the clear completes we don't get a config |
| 1098 | * change so we monitor the job status complete on a clear then |
| 1099 | * wait for a container change. |
| 1100 | */ |
| 1101 | |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1102 | if (((__le32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero) && |
| 1103 | (((__le32 *)aifcmd->data)[6] == ((__le32 *)aifcmd->data)[5] || |
| 1104 | ((__le32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsSuccess))) { |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1105 | for (container = 0; |
| 1106 | container < dev->maximum_num_containers; |
| 1107 | ++container) { |
| 1108 | /* |
| 1109 | * Stomp on all config sequencing for all |
| 1110 | * containers? |
| 1111 | */ |
| 1112 | dev->fsa_dev[container].config_waiting_on = |
| 1113 | AifEnContainerChange; |
| 1114 | dev->fsa_dev[container].config_needed = ADD; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1115 | dev->fsa_dev[container].config_waiting_stamp = |
| 1116 | jiffies; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1117 | } |
| 1118 | } |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1119 | if (((__le32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero) && |
| 1120 | ((__le32 *)aifcmd->data)[6] == 0 && |
| 1121 | ((__le32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsRunning)) { |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1122 | for (container = 0; |
| 1123 | container < dev->maximum_num_containers; |
| 1124 | ++container) { |
| 1125 | /* |
| 1126 | * Stomp on all config sequencing for all |
| 1127 | * containers? |
| 1128 | */ |
| 1129 | dev->fsa_dev[container].config_waiting_on = |
| 1130 | AifEnContainerChange; |
| 1131 | dev->fsa_dev[container].config_needed = DELETE; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1132 | dev->fsa_dev[container].config_waiting_stamp = |
| 1133 | jiffies; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | break; |
| 1137 | } |
| 1138 | |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1139 | container = 0; |
| 1140 | retry_next: |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1141 | if (device_config_needed == NOTHING) |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1142 | for (; container < dev->maximum_num_containers; ++container) { |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1143 | if ((dev->fsa_dev[container].config_waiting_on == 0) && |
| 1144 | (dev->fsa_dev[container].config_needed != NOTHING) && |
| 1145 | time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) { |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1146 | device_config_needed = |
| 1147 | dev->fsa_dev[container].config_needed; |
| 1148 | dev->fsa_dev[container].config_needed = NOTHING; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1149 | channel = CONTAINER_TO_CHANNEL(container); |
| 1150 | id = CONTAINER_TO_ID(container); |
| 1151 | lun = CONTAINER_TO_LUN(container); |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1152 | break; |
| 1153 | } |
| 1154 | } |
| 1155 | if (device_config_needed == NOTHING) |
| 1156 | return; |
| 1157 | |
| 1158 | /* |
| 1159 | * If we decided that a re-configuration needs to be done, |
| 1160 | * schedule it here on the way out the door, please close the door |
| 1161 | * behind you. |
| 1162 | */ |
| 1163 | |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1164 | /* |
Christoph Hellwig | f64a181 | 2005-10-31 18:32:08 +0100 | [diff] [blame] | 1165 | * Find the scsi_device associated with the SCSI address, |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1166 | * and mark it as changed, invalidating the cache. This deals |
| 1167 | * with changes to existing device IDs. |
| 1168 | */ |
| 1169 | |
| 1170 | if (!dev || !dev->scsi_host_ptr) |
| 1171 | return; |
| 1172 | /* |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1173 | * force reload of disk info via aac_probe_container |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1174 | */ |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1175 | if ((channel == CONTAINER_CHANNEL) && |
| 1176 | (device_config_needed != NOTHING)) { |
| 1177 | if (dev->fsa_dev[container].valid == 1) |
| 1178 | dev->fsa_dev[container].valid = 2; |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1179 | aac_probe_container(dev, container); |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1180 | } |
| 1181 | device = scsi_device_lookup(dev->scsi_host_ptr, channel, id, lun); |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1182 | if (device) { |
| 1183 | switch (device_config_needed) { |
| 1184 | case DELETE: |
Rajashekhara, Mahesh | 9cccde9 | 2010-05-10 04:29:25 -0700 | [diff] [blame] | 1185 | #if (defined(AAC_DEBUG_INSTRUMENT_AIF_DELETE)) |
| 1186 | scsi_remove_device(device); |
| 1187 | #else |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1188 | if (scsi_device_online(device)) { |
| 1189 | scsi_device_set_state(device, SDEV_OFFLINE); |
| 1190 | sdev_printk(KERN_INFO, device, |
| 1191 | "Device offlined - %s\n", |
| 1192 | (channel == CONTAINER_CHANNEL) ? |
| 1193 | "array deleted" : |
| 1194 | "enclosure services event"); |
| 1195 | } |
Rajashekhara, Mahesh | 9cccde9 | 2010-05-10 04:29:25 -0700 | [diff] [blame] | 1196 | #endif |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1197 | break; |
| 1198 | case ADD: |
| 1199 | if (!scsi_device_online(device)) { |
| 1200 | sdev_printk(KERN_INFO, device, |
| 1201 | "Device online - %s\n", |
| 1202 | (channel == CONTAINER_CHANNEL) ? |
| 1203 | "array created" : |
| 1204 | "enclosure services event"); |
| 1205 | scsi_device_set_state(device, SDEV_RUNNING); |
| 1206 | } |
| 1207 | /* FALLTHRU */ |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1208 | case CHANGE: |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1209 | if ((channel == CONTAINER_CHANNEL) |
| 1210 | && (!dev->fsa_dev[container].valid)) { |
Rajashekhara, Mahesh | 9cccde9 | 2010-05-10 04:29:25 -0700 | [diff] [blame] | 1211 | #if (defined(AAC_DEBUG_INSTRUMENT_AIF_DELETE)) |
| 1212 | scsi_remove_device(device); |
| 1213 | #else |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1214 | if (!scsi_device_online(device)) |
| 1215 | break; |
| 1216 | scsi_device_set_state(device, SDEV_OFFLINE); |
| 1217 | sdev_printk(KERN_INFO, device, |
| 1218 | "Device offlined - %s\n", |
| 1219 | "array failed"); |
Rajashekhara, Mahesh | 9cccde9 | 2010-05-10 04:29:25 -0700 | [diff] [blame] | 1220 | #endif |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1221 | break; |
| 1222 | } |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1223 | scsi_rescan_device(&device->sdev_gendev); |
| 1224 | |
| 1225 | default: |
| 1226 | break; |
| 1227 | } |
| 1228 | scsi_device_put(device); |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1229 | device_config_needed = NOTHING; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1230 | } |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1231 | if (device_config_needed == ADD) |
| 1232 | scsi_add_device(dev->scsi_host_ptr, channel, id, lun); |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1233 | if (channel == CONTAINER_CHANNEL) { |
| 1234 | container++; |
| 1235 | device_config_needed = NOTHING; |
| 1236 | goto retry_next; |
| 1237 | } |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1240 | static int _aac_reset_adapter(struct aac_dev *aac, int forced) |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1241 | { |
| 1242 | int index, quirks; |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1243 | int retval; |
| 1244 | struct Scsi_Host *host; |
| 1245 | struct scsi_device *dev; |
| 1246 | struct scsi_cmnd *command; |
| 1247 | struct scsi_cmnd *command_list; |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1248 | int jafo = 0; |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1249 | |
| 1250 | /* |
| 1251 | * Assumptions: |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1252 | * - host is locked, unless called by the aacraid thread. |
| 1253 | * (a matter of convenience, due to legacy issues surrounding |
| 1254 | * eh_host_adapter_reset). |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1255 | * - in_reset is asserted, so no new i/o is getting to the |
| 1256 | * card. |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1257 | * - The card is dead, or will be very shortly ;-/ so no new |
| 1258 | * commands are completing in the interrupt service. |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1259 | */ |
| 1260 | host = aac->scsi_host_ptr; |
| 1261 | scsi_block_requests(host); |
| 1262 | aac_adapter_disable_int(aac); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1263 | if (aac->thread->pid != current->pid) { |
| 1264 | spin_unlock_irq(host->host_lock); |
| 1265 | kthread_stop(aac->thread); |
| 1266 | jafo = 1; |
| 1267 | } |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1268 | |
| 1269 | /* |
| 1270 | * If a positive health, means in a known DEAD PANIC |
| 1271 | * state and the adapter could be reset to `try again'. |
| 1272 | */ |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1273 | retval = aac_adapter_restart(aac, forced ? 0 : aac_adapter_check_health(aac)); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1274 | |
| 1275 | if (retval) |
| 1276 | goto out; |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1277 | |
Mark Haverkamp | d18b448 | 2006-11-21 10:40:31 -0800 | [diff] [blame] | 1278 | /* |
| 1279 | * Loop through the fibs, close the synchronous FIBS |
| 1280 | */ |
Mark Haverkamp | 33bb3b2 | 2007-03-15 10:27:21 -0700 | [diff] [blame] | 1281 | for (retval = 1, index = 0; index < (aac->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB); index++) { |
Mark Haverkamp | d18b448 | 2006-11-21 10:40:31 -0800 | [diff] [blame] | 1282 | struct fib *fib = &aac->fibs[index]; |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 1283 | if (!(fib->hw_fib_va->header.XferState & cpu_to_le32(NoResponseExpected | Async)) && |
| 1284 | (fib->hw_fib_va->header.XferState & cpu_to_le32(ResponseExpected))) { |
Mark Haverkamp | d18b448 | 2006-11-21 10:40:31 -0800 | [diff] [blame] | 1285 | unsigned long flagv; |
| 1286 | spin_lock_irqsave(&fib->event_lock, flagv); |
| 1287 | up(&fib->event_wait); |
| 1288 | spin_unlock_irqrestore(&fib->event_lock, flagv); |
| 1289 | schedule(); |
Mark Haverkamp | 33bb3b2 | 2007-03-15 10:27:21 -0700 | [diff] [blame] | 1290 | retval = 0; |
Mark Haverkamp | d18b448 | 2006-11-21 10:40:31 -0800 | [diff] [blame] | 1291 | } |
| 1292 | } |
Mark Haverkamp | 33bb3b2 | 2007-03-15 10:27:21 -0700 | [diff] [blame] | 1293 | /* Give some extra time for ioctls to complete. */ |
| 1294 | if (retval == 0) |
| 1295 | ssleep(2); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1296 | index = aac->cardtype; |
| 1297 | |
| 1298 | /* |
| 1299 | * Re-initialize the adapter, first free resources, then carefully |
| 1300 | * apply the initialization sequence to come back again. Only risk |
| 1301 | * is a change in Firmware dropping cache, it is assumed the caller |
| 1302 | * will ensure that i/o is queisced and the card is flushed in that |
| 1303 | * case. |
| 1304 | */ |
| 1305 | aac_fib_map_free(aac); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1306 | pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr, aac->comm_phys); |
| 1307 | aac->comm_addr = NULL; |
| 1308 | aac->comm_phys = 0; |
| 1309 | kfree(aac->queues); |
| 1310 | aac->queues = NULL; |
| 1311 | free_irq(aac->pdev->irq, aac); |
Vasily Averin | d0efab2 | 2011-09-02 19:31:46 +0400 | [diff] [blame] | 1312 | if (aac->msi) |
| 1313 | pci_disable_msi(aac->pdev); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1314 | kfree(aac->fsa_dev); |
| 1315 | aac->fsa_dev = NULL; |
Salyzyn, Mark | 94cf6ba | 2007-12-13 16:14:18 -0800 | [diff] [blame] | 1316 | quirks = aac_get_driver_ident(index)->quirks; |
| 1317 | if (quirks & AAC_QUIRK_31BIT) { |
Yang Hongyang | 929a22a | 2009-04-06 19:01:16 -0700 | [diff] [blame] | 1318 | if (((retval = pci_set_dma_mask(aac->pdev, DMA_BIT_MASK(31)))) || |
| 1319 | ((retval = pci_set_consistent_dma_mask(aac->pdev, DMA_BIT_MASK(31))))) |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1320 | goto out; |
| 1321 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1322 | if (((retval = pci_set_dma_mask(aac->pdev, DMA_BIT_MASK(32)))) || |
| 1323 | ((retval = pci_set_consistent_dma_mask(aac->pdev, DMA_BIT_MASK(32))))) |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1324 | goto out; |
| 1325 | } |
| 1326 | if ((retval = (*(aac_get_driver_ident(index)->init))(aac))) |
| 1327 | goto out; |
Salyzyn, Mark | 94cf6ba | 2007-12-13 16:14:18 -0800 | [diff] [blame] | 1328 | if (quirks & AAC_QUIRK_31BIT) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1329 | if ((retval = pci_set_dma_mask(aac->pdev, DMA_BIT_MASK(32)))) |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1330 | goto out; |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1331 | if (jafo) { |
| 1332 | aac->thread = kthread_run(aac_command_thread, aac, aac->name); |
| 1333 | if (IS_ERR(aac->thread)) { |
| 1334 | retval = PTR_ERR(aac->thread); |
| 1335 | goto out; |
| 1336 | } |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1337 | } |
| 1338 | (void)aac_get_adapter_info(aac); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1339 | if ((quirks & AAC_QUIRK_34SG) && (host->sg_tablesize > 34)) { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1340 | host->sg_tablesize = 34; |
| 1341 | host->max_sectors = (host->sg_tablesize * 8) + 112; |
| 1342 | } |
| 1343 | if ((quirks & AAC_QUIRK_17SG) && (host->sg_tablesize > 17)) { |
| 1344 | host->sg_tablesize = 17; |
| 1345 | host->max_sectors = (host->sg_tablesize * 8) + 112; |
| 1346 | } |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1347 | aac_get_config_status(aac, 1); |
| 1348 | aac_get_containers(aac); |
| 1349 | /* |
| 1350 | * This is where the assumption that the Adapter is quiesced |
| 1351 | * is important. |
| 1352 | */ |
| 1353 | command_list = NULL; |
| 1354 | __shost_for_each_device(dev, host) { |
| 1355 | unsigned long flags; |
| 1356 | spin_lock_irqsave(&dev->list_lock, flags); |
| 1357 | list_for_each_entry(command, &dev->cmd_list, list) |
| 1358 | if (command->SCp.phase == AAC_OWNER_FIRMWARE) { |
| 1359 | command->SCp.buffer = (struct scatterlist *)command_list; |
| 1360 | command_list = command; |
| 1361 | } |
| 1362 | spin_unlock_irqrestore(&dev->list_lock, flags); |
| 1363 | } |
| 1364 | while ((command = command_list)) { |
| 1365 | command_list = (struct scsi_cmnd *)command->SCp.buffer; |
| 1366 | command->SCp.buffer = NULL; |
| 1367 | command->result = DID_OK << 16 |
| 1368 | | COMMAND_COMPLETE << 8 |
| 1369 | | SAM_STAT_TASK_SET_FULL; |
| 1370 | command->SCp.phase = AAC_OWNER_ERROR_HANDLER; |
| 1371 | command->scsi_done(command); |
| 1372 | } |
| 1373 | retval = 0; |
| 1374 | |
| 1375 | out: |
| 1376 | aac->in_reset = 0; |
| 1377 | scsi_unblock_requests(host); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1378 | if (jafo) { |
| 1379 | spin_lock_irq(host->host_lock); |
| 1380 | } |
| 1381 | return retval; |
| 1382 | } |
| 1383 | |
| 1384 | int aac_reset_adapter(struct aac_dev * aac, int forced) |
| 1385 | { |
| 1386 | unsigned long flagv = 0; |
| 1387 | int retval; |
| 1388 | struct Scsi_Host * host; |
| 1389 | |
| 1390 | if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0) |
| 1391 | return -EBUSY; |
| 1392 | |
| 1393 | if (aac->in_reset) { |
| 1394 | spin_unlock_irqrestore(&aac->fib_lock, flagv); |
| 1395 | return -EBUSY; |
| 1396 | } |
| 1397 | aac->in_reset = 1; |
| 1398 | spin_unlock_irqrestore(&aac->fib_lock, flagv); |
| 1399 | |
| 1400 | /* |
| 1401 | * Wait for all commands to complete to this specific |
| 1402 | * target (block maximum 60 seconds). Although not necessary, |
| 1403 | * it does make us a good storage citizen. |
| 1404 | */ |
| 1405 | host = aac->scsi_host_ptr; |
| 1406 | scsi_block_requests(host); |
| 1407 | if (forced < 2) for (retval = 60; retval; --retval) { |
| 1408 | struct scsi_device * dev; |
| 1409 | struct scsi_cmnd * command; |
| 1410 | int active = 0; |
| 1411 | |
| 1412 | __shost_for_each_device(dev, host) { |
| 1413 | spin_lock_irqsave(&dev->list_lock, flagv); |
| 1414 | list_for_each_entry(command, &dev->cmd_list, list) { |
| 1415 | if (command->SCp.phase == AAC_OWNER_FIRMWARE) { |
| 1416 | active++; |
| 1417 | break; |
| 1418 | } |
| 1419 | } |
| 1420 | spin_unlock_irqrestore(&dev->list_lock, flagv); |
| 1421 | if (active) |
| 1422 | break; |
| 1423 | |
| 1424 | } |
| 1425 | /* |
| 1426 | * We can exit If all the commands are complete |
| 1427 | */ |
| 1428 | if (active == 0) |
| 1429 | break; |
| 1430 | ssleep(1); |
| 1431 | } |
| 1432 | |
| 1433 | /* Quiesce build, flush cache, write through mode */ |
Salyzyn, Mark | f858317 | 2007-10-30 15:50:49 -0400 | [diff] [blame] | 1434 | if (forced < 2) |
| 1435 | aac_send_shutdown(aac); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1436 | spin_lock_irqsave(host->host_lock, flagv); |
Salyzyn, Mark | f858317 | 2007-10-30 15:50:49 -0400 | [diff] [blame] | 1437 | retval = _aac_reset_adapter(aac, forced ? forced : ((aac_check_reset != 0) && (aac_check_reset != 1))); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1438 | spin_unlock_irqrestore(host->host_lock, flagv); |
| 1439 | |
Salyzyn, Mark | f858317 | 2007-10-30 15:50:49 -0400 | [diff] [blame] | 1440 | if ((forced < 2) && (retval == -ENODEV)) { |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1441 | /* Unwind aac_send_shutdown() IOP_RESET unsupported/disabled */ |
| 1442 | struct fib * fibctx = aac_fib_alloc(aac); |
| 1443 | if (fibctx) { |
| 1444 | struct aac_pause *cmd; |
| 1445 | int status; |
| 1446 | |
| 1447 | aac_fib_init(fibctx); |
| 1448 | |
| 1449 | cmd = (struct aac_pause *) fib_data(fibctx); |
| 1450 | |
| 1451 | cmd->command = cpu_to_le32(VM_ContainerConfig); |
| 1452 | cmd->type = cpu_to_le32(CT_PAUSE_IO); |
| 1453 | cmd->timeout = cpu_to_le32(1); |
| 1454 | cmd->min = cpu_to_le32(1); |
| 1455 | cmd->noRescan = cpu_to_le32(1); |
| 1456 | cmd->count = cpu_to_le32(0); |
| 1457 | |
| 1458 | status = aac_fib_send(ContainerCommand, |
| 1459 | fibctx, |
| 1460 | sizeof(struct aac_pause), |
| 1461 | FsaNormal, |
| 1462 | -2 /* Timeout silently */, 1, |
| 1463 | NULL, NULL); |
| 1464 | |
| 1465 | if (status >= 0) |
| 1466 | aac_fib_complete(fibctx); |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 1467 | /* FIB should be freed only after getting |
| 1468 | * the response from the F/W */ |
| 1469 | if (status != -ERESTARTSYS) |
| 1470 | aac_fib_free(fibctx); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1471 | } |
| 1472 | } |
| 1473 | |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1474 | return retval; |
| 1475 | } |
| 1476 | |
| 1477 | int aac_check_health(struct aac_dev * aac) |
| 1478 | { |
| 1479 | int BlinkLED; |
| 1480 | unsigned long time_now, flagv = 0; |
| 1481 | struct list_head * entry; |
| 1482 | struct Scsi_Host * host; |
| 1483 | |
| 1484 | /* Extending the scope of fib_lock slightly to protect aac->in_reset */ |
| 1485 | if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0) |
| 1486 | return 0; |
| 1487 | |
| 1488 | if (aac->in_reset || !(BlinkLED = aac_adapter_check_health(aac))) { |
| 1489 | spin_unlock_irqrestore(&aac->fib_lock, flagv); |
| 1490 | return 0; /* OK */ |
| 1491 | } |
| 1492 | |
| 1493 | aac->in_reset = 1; |
| 1494 | |
| 1495 | /* Fake up an AIF: |
| 1496 | * aac_aifcmd.command = AifCmdEventNotify = 1 |
| 1497 | * aac_aifcmd.seqnum = 0xFFFFFFFF |
| 1498 | * aac_aifcmd.data[0] = AifEnExpEvent = 23 |
| 1499 | * aac_aifcmd.data[1] = AifExeFirmwarePanic = 3 |
| 1500 | * aac.aifcmd.data[2] = AifHighPriority = 3 |
| 1501 | * aac.aifcmd.data[3] = BlinkLED |
| 1502 | */ |
| 1503 | |
| 1504 | time_now = jiffies/HZ; |
| 1505 | entry = aac->fib_list.next; |
| 1506 | |
| 1507 | /* |
| 1508 | * For each Context that is on the |
| 1509 | * fibctxList, make a copy of the |
| 1510 | * fib, and then set the event to wake up the |
| 1511 | * thread that is waiting for it. |
| 1512 | */ |
| 1513 | while (entry != &aac->fib_list) { |
| 1514 | /* |
| 1515 | * Extract the fibctx |
| 1516 | */ |
| 1517 | struct aac_fib_context *fibctx = list_entry(entry, struct aac_fib_context, next); |
| 1518 | struct hw_fib * hw_fib; |
| 1519 | struct fib * fib; |
| 1520 | /* |
| 1521 | * Check if the queue is getting |
| 1522 | * backlogged |
| 1523 | */ |
| 1524 | if (fibctx->count > 20) { |
| 1525 | /* |
| 1526 | * It's *not* jiffies folks, |
| 1527 | * but jiffies / HZ, so do not |
| 1528 | * panic ... |
| 1529 | */ |
| 1530 | u32 time_last = fibctx->jiffies; |
| 1531 | /* |
| 1532 | * Has it been > 2 minutes |
| 1533 | * since the last read off |
| 1534 | * the queue? |
| 1535 | */ |
| 1536 | if ((time_now - time_last) > aif_timeout) { |
| 1537 | entry = entry->next; |
| 1538 | aac_close_fib_context(aac, fibctx); |
| 1539 | continue; |
| 1540 | } |
| 1541 | } |
| 1542 | /* |
| 1543 | * Warning: no sleep allowed while |
| 1544 | * holding spinlock |
| 1545 | */ |
Salyzyn, Mark | 4dbc22d | 2007-04-16 11:21:50 -0400 | [diff] [blame] | 1546 | hw_fib = kzalloc(sizeof(struct hw_fib), GFP_ATOMIC); |
| 1547 | fib = kzalloc(sizeof(struct fib), GFP_ATOMIC); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1548 | if (fib && hw_fib) { |
| 1549 | struct aac_aifcmd * aif; |
| 1550 | |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 1551 | fib->hw_fib_va = hw_fib; |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1552 | fib->dev = aac; |
| 1553 | aac_fib_init(fib); |
| 1554 | fib->type = FSAFS_NTC_FIB_CONTEXT; |
| 1555 | fib->size = sizeof (struct fib); |
| 1556 | fib->data = hw_fib->data; |
| 1557 | aif = (struct aac_aifcmd *)hw_fib->data; |
| 1558 | aif->command = cpu_to_le32(AifCmdEventNotify); |
Salyzyn, Mark | a3940da | 2008-01-08 12:48:25 -0800 | [diff] [blame] | 1559 | aif->seqnum = cpu_to_le32(0xFFFFFFFF); |
| 1560 | ((__le32 *)aif->data)[0] = cpu_to_le32(AifEnExpEvent); |
| 1561 | ((__le32 *)aif->data)[1] = cpu_to_le32(AifExeFirmwarePanic); |
| 1562 | ((__le32 *)aif->data)[2] = cpu_to_le32(AifHighPriority); |
| 1563 | ((__le32 *)aif->data)[3] = cpu_to_le32(BlinkLED); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1564 | |
| 1565 | /* |
| 1566 | * Put the FIB onto the |
| 1567 | * fibctx's fibs |
| 1568 | */ |
| 1569 | list_add_tail(&fib->fiblink, &fibctx->fib_list); |
| 1570 | fibctx->count++; |
| 1571 | /* |
| 1572 | * Set the event to wake up the |
| 1573 | * thread that will waiting. |
| 1574 | */ |
| 1575 | up(&fibctx->wait_sem); |
| 1576 | } else { |
| 1577 | printk(KERN_WARNING "aifd: didn't allocate NewFib.\n"); |
| 1578 | kfree(fib); |
| 1579 | kfree(hw_fib); |
| 1580 | } |
| 1581 | entry = entry->next; |
| 1582 | } |
| 1583 | |
| 1584 | spin_unlock_irqrestore(&aac->fib_lock, flagv); |
| 1585 | |
| 1586 | if (BlinkLED < 0) { |
| 1587 | printk(KERN_ERR "%s: Host adapter dead %d\n", aac->name, BlinkLED); |
| 1588 | goto out; |
| 1589 | } |
| 1590 | |
| 1591 | printk(KERN_ERR "%s: Host adapter BLINK LED 0x%x\n", aac->name, BlinkLED); |
| 1592 | |
Salyzyn, Mark | 2f7ecc5 | 2008-02-08 08:36:23 -0800 | [diff] [blame] | 1593 | if (!aac_check_reset || ((aac_check_reset == 1) && |
Salyzyn, Mark | a3940da | 2008-01-08 12:48:25 -0800 | [diff] [blame] | 1594 | (aac->supplement_adapter_info.SupportedOptions2 & |
| 1595 | AAC_OPTION_IGNORE_RESET))) |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1596 | goto out; |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1597 | host = aac->scsi_host_ptr; |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1598 | if (aac->thread->pid != current->pid) |
| 1599 | spin_lock_irqsave(host->host_lock, flagv); |
Salyzyn, Mark | f858317 | 2007-10-30 15:50:49 -0400 | [diff] [blame] | 1600 | BlinkLED = _aac_reset_adapter(aac, aac_check_reset != 1); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1601 | if (aac->thread->pid != current->pid) |
| 1602 | spin_unlock_irqrestore(host->host_lock, flagv); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1603 | return BlinkLED; |
| 1604 | |
| 1605 | out: |
| 1606 | aac->in_reset = 0; |
| 1607 | return BlinkLED; |
| 1608 | } |
| 1609 | |
| 1610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | /** |
| 1612 | * aac_command_thread - command processing thread |
| 1613 | * @dev: Adapter to monitor |
| 1614 | * |
| 1615 | * Waits on the commandready event in it's queue. When the event gets set |
| 1616 | * it will pull FIBs off it's queue. It will continue to pull FIBs off |
| 1617 | * until the queue is empty. When the queue is empty it will wait for |
| 1618 | * more FIBs. |
| 1619 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1620 | |
Christoph Hellwig | fe27381 | 2006-02-14 18:45:06 +0100 | [diff] [blame] | 1621 | int aac_command_thread(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | { |
Christoph Hellwig | fe27381 | 2006-02-14 18:45:06 +0100 | [diff] [blame] | 1623 | struct aac_dev *dev = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | struct hw_fib *hw_fib, *hw_newfib; |
| 1625 | struct fib *fib, *newfib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | struct aac_fib_context *fibctx; |
| 1627 | unsigned long flags; |
| 1628 | DECLARE_WAITQUEUE(wait, current); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1629 | unsigned long next_jiffies = jiffies + HZ; |
| 1630 | unsigned long next_check_jiffies = next_jiffies; |
| 1631 | long difference = HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | |
| 1633 | /* |
| 1634 | * We can only have one thread per adapter for AIF's. |
| 1635 | */ |
| 1636 | if (dev->aif_thread) |
| 1637 | return -EINVAL; |
Christoph Hellwig | fe27381 | 2006-02-14 18:45:06 +0100 | [diff] [blame] | 1638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | /* |
| 1640 | * Let the DPC know it has a place to send the AIF's to. |
| 1641 | */ |
| 1642 | dev->aif_thread = 1; |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1643 | add_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | set_current_state(TASK_INTERRUPTIBLE); |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1645 | dprintk ((KERN_INFO "aac_command_thread start\n")); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1646 | while (1) { |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1647 | spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags); |
| 1648 | while(!list_empty(&(dev->queues->queue[HostNormCmdQueue].cmdq))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | struct list_head *entry; |
| 1650 | struct aac_aifcmd * aifcmd; |
| 1651 | |
| 1652 | set_current_state(TASK_RUNNING); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1653 | |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1654 | entry = dev->queues->queue[HostNormCmdQueue].cmdq.next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | list_del(entry); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1656 | |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1657 | spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | fib = list_entry(entry, struct fib, fiblink); |
| 1659 | /* |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1660 | * We will process the FIB here or pass it to a |
| 1661 | * worker thread that is TBD. We Really can't |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | * do anything at this point since we don't have |
| 1663 | * anything defined for this thread to do. |
| 1664 | */ |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 1665 | hw_fib = fib->hw_fib_va; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | memset(fib, 0, sizeof(struct fib)); |
| 1667 | fib->type = FSAFS_NTC_FIB_CONTEXT; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1668 | fib->size = sizeof(struct fib); |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 1669 | fib->hw_fib_va = hw_fib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | fib->data = hw_fib->data; |
| 1671 | fib->dev = dev; |
| 1672 | /* |
| 1673 | * We only handle AifRequest fibs from the adapter. |
| 1674 | */ |
| 1675 | aifcmd = (struct aac_aifcmd *) hw_fib->data; |
| 1676 | if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) { |
| 1677 | /* Handle Driver Notify Events */ |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1678 | aac_handle_aif(dev, fib); |
Mark Haverkamp | 56b5871 | 2005-04-27 06:05:51 -0700 | [diff] [blame] | 1679 | *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK); |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1680 | aac_fib_adapter_complete(fib, (u16)sizeof(u32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | /* The u32 here is important and intended. We are using |
| 1683 | 32bit wrapping time to fit the adapter field */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | u32 time_now, time_last; |
| 1686 | unsigned long flagv; |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1687 | unsigned num; |
| 1688 | struct hw_fib ** hw_fib_pool, ** hw_fib_p; |
| 1689 | struct fib ** fib_pool, ** fib_p; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1690 | |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1691 | /* Sniff events */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1692 | if ((aifcmd->command == |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1693 | cpu_to_le32(AifCmdEventNotify)) || |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1694 | (aifcmd->command == |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1695 | cpu_to_le32(AifCmdJobProgress))) { |
| 1696 | aac_handle_aif(dev, fib); |
| 1697 | } |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | time_now = jiffies/HZ; |
| 1700 | |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1701 | /* |
| 1702 | * Warning: no sleep allowed while |
| 1703 | * holding spinlock. We take the estimate |
| 1704 | * and pre-allocate a set of fibs outside the |
| 1705 | * lock. |
| 1706 | */ |
| 1707 | num = le32_to_cpu(dev->init->AdapterFibsSize) |
| 1708 | / sizeof(struct hw_fib); /* some extra */ |
| 1709 | spin_lock_irqsave(&dev->fib_lock, flagv); |
| 1710 | entry = dev->fib_list.next; |
| 1711 | while (entry != &dev->fib_list) { |
| 1712 | entry = entry->next; |
| 1713 | ++num; |
| 1714 | } |
| 1715 | spin_unlock_irqrestore(&dev->fib_lock, flagv); |
| 1716 | hw_fib_pool = NULL; |
| 1717 | fib_pool = NULL; |
| 1718 | if (num |
| 1719 | && ((hw_fib_pool = kmalloc(sizeof(struct hw_fib *) * num, GFP_KERNEL))) |
| 1720 | && ((fib_pool = kmalloc(sizeof(struct fib *) * num, GFP_KERNEL)))) { |
| 1721 | hw_fib_p = hw_fib_pool; |
| 1722 | fib_p = fib_pool; |
| 1723 | while (hw_fib_p < &hw_fib_pool[num]) { |
| 1724 | if (!(*(hw_fib_p++) = kmalloc(sizeof(struct hw_fib), GFP_KERNEL))) { |
| 1725 | --hw_fib_p; |
| 1726 | break; |
| 1727 | } |
| 1728 | if (!(*(fib_p++) = kmalloc(sizeof(struct fib), GFP_KERNEL))) { |
| 1729 | kfree(*(--hw_fib_p)); |
| 1730 | break; |
| 1731 | } |
| 1732 | } |
| 1733 | if ((num = hw_fib_p - hw_fib_pool) == 0) { |
| 1734 | kfree(fib_pool); |
| 1735 | fib_pool = NULL; |
| 1736 | kfree(hw_fib_pool); |
| 1737 | hw_fib_pool = NULL; |
| 1738 | } |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1739 | } else { |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1740 | kfree(hw_fib_pool); |
| 1741 | hw_fib_pool = NULL; |
| 1742 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | spin_lock_irqsave(&dev->fib_lock, flagv); |
| 1744 | entry = dev->fib_list.next; |
| 1745 | /* |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1746 | * For each Context that is on the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | * fibctxList, make a copy of the |
| 1748 | * fib, and then set the event to wake up the |
| 1749 | * thread that is waiting for it. |
| 1750 | */ |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1751 | hw_fib_p = hw_fib_pool; |
| 1752 | fib_p = fib_pool; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | while (entry != &dev->fib_list) { |
| 1754 | /* |
| 1755 | * Extract the fibctx |
| 1756 | */ |
| 1757 | fibctx = list_entry(entry, struct aac_fib_context, next); |
| 1758 | /* |
| 1759 | * Check if the queue is getting |
| 1760 | * backlogged |
| 1761 | */ |
| 1762 | if (fibctx->count > 20) |
| 1763 | { |
| 1764 | /* |
| 1765 | * It's *not* jiffies folks, |
| 1766 | * but jiffies / HZ so do not |
| 1767 | * panic ... |
| 1768 | */ |
| 1769 | time_last = fibctx->jiffies; |
| 1770 | /* |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1771 | * Has it been > 2 minutes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | * since the last read off |
| 1773 | * the queue? |
| 1774 | */ |
Mark Haverkamp | 404d9a9 | 2006-05-10 09:12:48 -0700 | [diff] [blame] | 1775 | if ((time_now - time_last) > aif_timeout) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | entry = entry->next; |
| 1777 | aac_close_fib_context(dev, fibctx); |
| 1778 | continue; |
| 1779 | } |
| 1780 | } |
| 1781 | /* |
| 1782 | * Warning: no sleep allowed while |
| 1783 | * holding spinlock |
| 1784 | */ |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1785 | if (hw_fib_p < &hw_fib_pool[num]) { |
| 1786 | hw_newfib = *hw_fib_p; |
| 1787 | *(hw_fib_p++) = NULL; |
| 1788 | newfib = *fib_p; |
| 1789 | *(fib_p++) = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | /* |
| 1791 | * Make the copy of the FIB |
| 1792 | */ |
| 1793 | memcpy(hw_newfib, hw_fib, sizeof(struct hw_fib)); |
| 1794 | memcpy(newfib, fib, sizeof(struct fib)); |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 1795 | newfib->hw_fib_va = hw_newfib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | /* |
| 1797 | * Put the FIB onto the |
| 1798 | * fibctx's fibs |
| 1799 | */ |
| 1800 | list_add_tail(&newfib->fiblink, &fibctx->fib_list); |
| 1801 | fibctx->count++; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1802 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | * Set the event to wake up the |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1804 | * thread that is waiting. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | */ |
| 1806 | up(&fibctx->wait_sem); |
| 1807 | } else { |
| 1808 | printk(KERN_WARNING "aifd: didn't allocate NewFib.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | } |
| 1810 | entry = entry->next; |
| 1811 | } |
| 1812 | /* |
| 1813 | * Set the status of this FIB |
| 1814 | */ |
Mark Haverkamp | 56b5871 | 2005-04-27 06:05:51 -0700 | [diff] [blame] | 1815 | *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK); |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1816 | aac_fib_adapter_complete(fib, sizeof(u32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | spin_unlock_irqrestore(&dev->fib_lock, flagv); |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1818 | /* Free up the remaining resources */ |
| 1819 | hw_fib_p = hw_fib_pool; |
| 1820 | fib_p = fib_pool; |
| 1821 | while (hw_fib_p < &hw_fib_pool[num]) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1822 | kfree(*hw_fib_p); |
| 1823 | kfree(*fib_p); |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1824 | ++fib_p; |
| 1825 | ++hw_fib_p; |
| 1826 | } |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1827 | kfree(hw_fib_pool); |
| 1828 | kfree(fib_pool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | kfree(fib); |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1831 | spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | } |
| 1833 | /* |
| 1834 | * There are no more AIF's |
| 1835 | */ |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1836 | spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1837 | |
| 1838 | /* |
| 1839 | * Background activity |
| 1840 | */ |
| 1841 | if ((time_before(next_check_jiffies,next_jiffies)) |
| 1842 | && ((difference = next_check_jiffies - jiffies) <= 0)) { |
| 1843 | next_check_jiffies = next_jiffies; |
| 1844 | if (aac_check_health(dev) == 0) { |
| 1845 | difference = ((long)(unsigned)check_interval) |
| 1846 | * HZ; |
| 1847 | next_check_jiffies = jiffies + difference; |
| 1848 | } else if (!dev->queues) |
| 1849 | break; |
| 1850 | } |
| 1851 | if (!time_before(next_check_jiffies,next_jiffies) |
| 1852 | && ((difference = next_jiffies - jiffies) <= 0)) { |
| 1853 | struct timeval now; |
| 1854 | int ret; |
| 1855 | |
| 1856 | /* Don't even try to talk to adapter if its sick */ |
| 1857 | ret = aac_check_health(dev); |
| 1858 | if (!ret && !dev->queues) |
| 1859 | break; |
| 1860 | next_check_jiffies = jiffies |
| 1861 | + ((long)(unsigned)check_interval) |
| 1862 | * HZ; |
| 1863 | do_gettimeofday(&now); |
| 1864 | |
| 1865 | /* Synchronize our watches */ |
| 1866 | if (((1000000 - (1000000 / HZ)) > now.tv_usec) |
| 1867 | && (now.tv_usec > (1000000 / HZ))) |
| 1868 | difference = (((1000000 - now.tv_usec) * HZ) |
| 1869 | + 500000) / 1000000; |
| 1870 | else if (ret == 0) { |
| 1871 | struct fib *fibptr; |
| 1872 | |
| 1873 | if ((fibptr = aac_fib_alloc(dev))) { |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 1874 | int status; |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1875 | __le32 *info; |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1876 | |
| 1877 | aac_fib_init(fibptr); |
| 1878 | |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1879 | info = (__le32 *) fib_data(fibptr); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1880 | if (now.tv_usec > 500000) |
| 1881 | ++now.tv_sec; |
| 1882 | |
| 1883 | *info = cpu_to_le32(now.tv_sec); |
| 1884 | |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 1885 | status = aac_fib_send(SendHostTime, |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1886 | fibptr, |
| 1887 | sizeof(*info), |
| 1888 | FsaNormal, |
| 1889 | 1, 1, |
| 1890 | NULL, |
| 1891 | NULL); |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 1892 | /* Do not set XferState to zero unless |
| 1893 | * receives a response from F/W */ |
| 1894 | if (status >= 0) |
| 1895 | aac_fib_complete(fibptr); |
| 1896 | /* FIB should be freed only after |
| 1897 | * getting the response from the F/W */ |
| 1898 | if (status != -ERESTARTSYS) |
| 1899 | aac_fib_free(fibptr); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1900 | } |
| 1901 | difference = (long)(unsigned)update_interval*HZ; |
| 1902 | } else { |
| 1903 | /* retry shortly */ |
| 1904 | difference = 10 * HZ; |
| 1905 | } |
| 1906 | next_jiffies = jiffies + difference; |
| 1907 | if (time_before(next_check_jiffies,next_jiffies)) |
| 1908 | difference = next_check_jiffies - jiffies; |
| 1909 | } |
| 1910 | if (difference <= 0) |
| 1911 | difference = 1; |
| 1912 | set_current_state(TASK_INTERRUPTIBLE); |
| 1913 | schedule_timeout(difference); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | |
Christoph Hellwig | fe27381 | 2006-02-14 18:45:06 +0100 | [diff] [blame] | 1915 | if (kthread_should_stop()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | } |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1918 | if (dev->queues) |
| 1919 | remove_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | dev->aif_thread = 0; |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 1921 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | } |