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