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