blob: bb7988d5321655ad55a8012570c610d036331b5c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Adaptec AAC series RAID controller driver
Alan Coxfa195af2008-10-27 15:16:36 +00003 * (c) Copyright 2001 Red Hat Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
7 *
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07008 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
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 7c00ffa2005-05-16 18:28:42 -070029 * communication.
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 *
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 Viro164006d2005-11-30 23:47:05 -050042#include <linux/delay.h>
Christoph Hellwigfe273812006-02-14 18:45:06 +010043#include <linux/kthread.h>
Al Viro6a3670c2006-09-24 23:45:29 +010044#include <linux/interrupt.h>
Matthew Wilcox6188e102008-04-18 22:21:05 -040045#include <linux/semaphore.h>
Mark Haverkamp8c867b22006-08-03 08:03:30 -070046#include <scsi/scsi.h>
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070047#include <scsi/scsi_host.h>
Mark Haverkamp131256c2005-09-26 13:04:56 -070048#include <scsi/scsi_device.h>
Mark Haverkamp8c867b22006-08-03 08:03:30 -070049#include <scsi/scsi_cmnd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
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, Mark8ce3eca2008-01-16 07:39:06 -080060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061static int fib_map_alloc(struct aac_dev *dev)
62{
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070063 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 Rajashekharae8b12f02011-03-17 02:10:32 -070067 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 Torvalds1da177e2005-04-16 15:20:36 -070072 return -ENOMEM;
73 return 0;
74}
75
76/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -080077 * aac_fib_map_free - free the fib objects
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 * @dev: Adapter to free
79 *
80 * Free the PCI mappings and the memory allocated for FIB blocks
81 * on this adapter.
82 */
83
Mark Haverkampbfb35aa82006-02-01 09:30:55 -080084void aac_fib_map_free(struct aac_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Raghava Aditya Renukuntaf88fa792016-02-03 15:06:02 -080086 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 }
Salyzyn, Mark9ad52042007-07-17 11:15:08 -040092 dev->hw_fib_va = NULL;
93 dev->hw_fib_pa = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
Raghava Aditya Renukunta3f4ce052016-02-03 15:06:00 -080096void 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800119 * aac_fib_setup - setup the fibs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 * @dev: Adapter to set up
121 *
Uwe Kleine-Königb5950762010-11-01 15:38:34 -0400122 * Allocate the PCI space for the fibs, map it and then initialise the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 * fib area, the unmapped fib data and also the free list
124 */
125
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800126int aac_fib_setup(struct aac_dev * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
128 struct fib *fibptr;
Mark Haverkampa8166a52007-03-15 10:26:22 -0700129 struct hw_fib *hw_fib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 dma_addr_t hw_fib_pa;
131 int i;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700132
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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 return -ENOMEM;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800140
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700141 /* 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
Mark Haverkampa8166a52007-03-15 10:26:22 -0700155 hw_fib = dev->hw_fib_va;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 hw_fib_pa = dev->hw_fib_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 /*
158 * Initialise the fibs
159 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800160 for (i = 0, fibptr = &dev->fibs[i];
161 i < (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB);
162 i++, fibptr++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 {
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530164 fibptr->flags = 0;
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -0800165 fibptr->size = sizeof(struct fib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 fibptr->dev = dev;
Mark Haverkampa8166a52007-03-15 10:26:22 -0700167 fibptr->hw_fib_va = hw_fib;
168 fibptr->data = (void *) fibptr->hw_fib_va->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 fibptr->next = fibptr+1; /* Forward chain the fibs */
Thomas Gleixner6de76cf2010-09-07 14:32:47 +0000170 sema_init(&fibptr->event_wait, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 spin_lock_init(&fibptr->event_lock);
Mark Haverkampa8166a52007-03-15 10:26:22 -0700172 hw_fib->header.XferState = cpu_to_le32(0xffffffff);
173 hw_fib->header.SenderSize = cpu_to_le16(dev->max_fib_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 fibptr->hw_fib_pa = hw_fib_pa;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700175 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
Raghava Aditya Renukunta3f4ce052016-02-03 15:06:00 -0800180
181 /*
182 *Assign vector numbers to fibs
183 */
184 aac_fib_vector_assign(dev);
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 /*
187 * Add the fib chain to the free list
188 */
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700189 dev->fibs[dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB - 1].next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 /*
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -0800191 * Set 8 fibs aside for management tools
192 */
193 dev->free_fib = &dev->fibs[dev->scsi_host_ptr->can_queue];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 return 0;
195}
196
197/**
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -0800198 * 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
205struct 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
222/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800223 * aac_fib_alloc - allocate a fib
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 * @dev: Adapter to allocate the fib for
225 *
226 * Allocate a fib from the adapter fib pool. If the pool is empty we
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700227 * return NULL.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800229
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800230struct fib *aac_fib_alloc(struct aac_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
232 struct fib * fibptr;
233 unsigned long flags;
234 spin_lock_irqsave(&dev->fib_lock, flags);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800235 fibptr = dev->free_fib;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700236 if(!fibptr){
237 spin_unlock_irqrestore(&dev->fib_lock, flags);
238 return fibptr;
239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 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 */
Mark Haverkampa8166a52007-03-15 10:26:22 -0700251 fibptr->hw_fib_va->header.XferState = 0;
Salyzyn, Markb6ef70f2008-01-08 13:26:43 -0800252 fibptr->flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 fibptr->callback = NULL;
254 fibptr->callback_data = NULL;
255
256 return fibptr;
257}
258
259/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800260 * aac_fib_free - free a fib
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 * @fibptr: fib to free up
262 *
263 * Frees up a fib and places it on the appropriate queue
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800265
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800266void aac_fib_free(struct fib *fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400268 unsigned long flags;
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530269
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400270 if (fibptr->done == 2)
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530271 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273 spin_lock_irqsave(&fibptr->dev->fib_lock, flags);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700274 if (unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 aac_config.fib_timeouts++;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700276 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 spin_unlock_irqrestore(&fibptr->dev->fib_lock, flags);
284}
285
286/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800287 * aac_fib_init - initialise a fib
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 * @fibptr: The fib to initialize
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800289 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 * Set up the generic fib fields ready for use
291 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800292
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800293void aac_fib_init(struct fib *fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Mark Haverkampa8166a52007-03-15 10:26:22 -0700295 struct hw_fib *hw_fib = fibptr->hw_fib_va;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530297 memset(&hw_fib->header, 0, sizeof(struct aac_fibhdr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 hw_fib->header.StructType = FIB_MAGIC;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700299 hw_fib->header.Size = cpu_to_le16(fibptr->dev->max_fib_size);
300 hw_fib->header.XferState = cpu_to_le32(HostOwned | FibInitialized | FibEmpty | FastResponseCapable);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530301 hw_fib->header.u.ReceiverFibAddress = cpu_to_le32(fibptr->hw_fib_pa);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700302 hw_fib->header.SenderSize = cpu_to_le16(fibptr->dev->max_fib_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303}
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 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800312
Adrian Bunk 48338692005-04-25 19:45:58 -0700313static void fib_dealloc(struct fib * fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
Mark Haverkampa8166a52007-03-15 10:26:22 -0700315 struct hw_fib *hw_fib = fibptr->hw_fib_va;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800316 hw_fib->header.XferState = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
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 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326/**
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 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339static 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;
Mark Haverkampbed30de2005-08-03 15:38:51 -0700342 unsigned long idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
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];
Mark Haverkampbed30de2005-08-03 15:38:51 -0700352
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) {
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700357 if (qid == AdapNormCmdQueue)
Mark Haverkampbed30de2005-08-03 15:38:51 -0700358 idx = ADAP_NORM_CMD_ENTRIES;
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700359 else
Mark Haverkampbed30de2005-08-03 15:38:51 -0700360 idx = ADAP_NORM_RESP_ENTRIES;
361 }
362 if (idx != le32_to_cpu(*(q->headers.consumer)))
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800363 *nonotify = 1;
Mark Haverkampbed30de2005-08-03 15:38:51 -0700364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700366 if (qid == AdapNormCmdQueue) {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800367 if (*index >= ADAP_NORM_CMD_ENTRIES)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 *index = 0; /* Wrap to front of the Producer Queue. */
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700369 } else {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800370 if (*index >= ADAP_NORM_RESP_ENTRIES)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 *index = 0; /* Wrap to front of the Producer Queue. */
372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800374 /* Queue is full */
375 if ((*index + 1) == le32_to_cpu(*(q->headers.consumer))) {
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700376 printk(KERN_WARNING "Queue %d full, %u outstanding.\n",
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400377 qid, atomic_read(&q->numpending));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 return 0;
379 } else {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800380 *entry = q->base + *index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return 1;
382 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800383}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
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
Mark Haverkamp28713322007-01-23 14:59:20 -0800401int 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 Torvalds1da177e2005-04-16 15:20:36 -0700402{
403 struct aac_entry * entry = NULL;
404 int map = 0;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800405
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700406 if (qid == AdapNormCmdQueue) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 /* if no entries wait for some if caller wants to */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800408 while (!aac_get_entry(dev, qid, &entry, index, nonotify)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 printk(KERN_ERR "GetEntries failed\n");
410 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800411 /*
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;
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700416 } else {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800417 while (!aac_get_entry(dev, qid, &entry, index, nonotify)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 /* if no entries wait for some if caller wants to */
419 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800420 /*
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 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530426 hw_fib->header.u.ReceiverFibAddress = hw_fib->header.SenderFibAddress; /* Let the adapter now where to find its data */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800427 map = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438/*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800439 * Define the highest level of host to adapter communication routines.
440 * These routines will support host to adapter FS commuication. These
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 * 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/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800447 * aac_fib_send - send a fib to the adapter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 * @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 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800462
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800463int 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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 struct aac_dev * dev = fibptr->dev;
Mark Haverkampa8166a52007-03-15 10:26:22 -0700468 struct hw_fib * hw_fib = fibptr->hw_fib_va;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 unsigned long flags = 0;
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530470 unsigned long mflags = 0;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800471 unsigned long sflags = 0;
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530472
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 if (!(hw_fib->header.XferState & cpu_to_le32(HostOwned)))
475 return -EBUSY;
476 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300477 * There are 5 cases with the wait and response requested flags.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 * 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
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800483 * further processing will be done besides deleting the Fib. We
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 * 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 */
Salyzyn, Markb6ef70f2008-01-08 13:26:43 -0800487 fibptr->flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 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);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 /*
501 * Map the fib into 32bits by using the fib number
502 */
503
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700504 hw_fib->header.SenderFibAddress = cpu_to_le32(((u32)(fibptr - dev->fibs)) << 2);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530505 hw_fib->header.Handle = (u32)(fibptr - dev->fibs) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 /*
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 /*
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;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 /*
523 * Get a queue entry connect the FIB to it and send an notify
524 * the adapter a command is ready.
525 */
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700526 hw_fib->header.XferState |= cpu_to_le32(NormalPriority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 /*
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;
Salyzyn, Markb6ef70f2008-01-08 13:26:43 -0800535 fibptr->flags = FIB_CONTEXT_FLAG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 fibptr->done = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700540 FIB_COUNTER_INCREMENT(aac_config.FibsSent);
541
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700542 dprintk((KERN_DEBUG "Fib contents:.\n"));
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700543 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)));
Mark Haverkampa8166a52007-03-15 10:26:22 -0700546 dprintk((KERN_DEBUG " hw_fib va being sent=%p\n",fibptr->hw_fib_va));
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700547 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
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700550 if (!dev->queues)
Mark Haverkamp65101352006-09-19 08:59:23 -0700551 return -EBUSY;
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700552
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530553 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);
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700564 spin_lock_irqsave(&fibptr->event_lock, flags);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530565 }
566
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800567 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
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530592 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
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 /*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800605 * If the caller wanted us to wait for response wait now.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 if (wait) {
609 spin_unlock_irqrestore(&fibptr->event_lock, flags);
Mark Haverkamp92033442005-09-20 12:56:50 -0700610 /* 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 */
Ben Collins30002f12012-06-11 14:44:44 -0400618 unsigned long timeout = jiffies + (180 * HZ); /* 3 minutes */
Mark Haverkamp92033442005-09-20 12:56:50 -0700619 while (down_trylock(&fibptr->event_wait)) {
Mark Haverkamp33524b72006-11-21 10:40:08 -0800620 int blink;
Ben Collins30002f12012-06-11 14:44:44 -0400621 if (time_is_before_eq_jiffies(timeout)) {
Mark Haverkamp28713322007-01-23 14:59:20 -0800622 struct aac_queue * q = &dev->queues->queue[AdapNormCmdQueue];
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400623 atomic_dec(&q->numpending);
Mark Haverkamp92033442005-09-20 12:56:50 -0700624 if (wait == -1) {
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800625 printk(KERN_ERR "aacraid: aac_fib_send: first asynchronous command timed out.\n"
Mark Haverkamp92033442005-09-20 12:56:50 -0700626 "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 }
Mark Haverkamp33524b72006-11-21 10:40:08 -0800632 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 }
Raghava Aditya Renukunta07beca22016-04-25 23:31:26 -0700640 /*
641 * Allow other processes / CPUS to use core
642 */
643 schedule();
Mark Haverkamp92033442005-09-20 12:56:50 -0700644 }
Mark Salyzyn04625902008-04-23 08:16:06 -0400645 } else if (down_interruptible(&fibptr->event_wait)) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530646 /* Do nothing ... satisfy
647 * down_interruptible must_check */
Mark Salyzyne6990c62008-04-14 14:20:16 -0400648 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530649
Mark Haverkamp33bb3b22007-03-15 10:27:21 -0700650 spin_lock_irqsave(&fibptr->event_lock, flags);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530651 if (fibptr->done == 0) {
Mark Haverkamp33bb3b22007-03-15 10:27:21 -0700652 fibptr->done = 2; /* Tell interrupt we aborted */
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700653 spin_unlock_irqrestore(&fibptr->event_lock, flags);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530654 return -ERESTARTSYS;
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700655 }
Mark Haverkamp33bb3b22007-03-15 10:27:21 -0700656 spin_unlock_irqrestore(&fibptr->event_lock, flags);
Eric Sesterhenn125e1872006-06-23 02:06:06 -0700657 BUG_ON(fibptr->done == 0);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800658
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400659 if(unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 return -ETIMEDOUT;
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400661 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 }
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
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800673/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 * 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
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800680 * we are a consumer of, and return the address of the queue entry. It does
681 * not change the state of the queue.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 */
683
684int 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 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800696 if (le32_to_cpu(*q->headers.consumer) >= q->entries)
697 index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 else
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800699 index = le32_to_cpu(*q->headers.consumer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 *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
716void 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;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800723
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 if (le32_to_cpu(*q->headers.consumer) >= q->entries)
725 *q->headers.consumer = cpu_to_le32(1);
726 else
Marcin Slusarz36b8dd12008-03-28 14:48:35 -0700727 le32_add_cpu(q->headers.consumer, 1);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 if (wasfull) {
730 switch (qid) {
731
732 case HostNormCmdQueue:
733 notify = HostNormCmdNotFull;
734 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 case HostNormRespQueue:
736 notify = HostNormRespNotFull;
737 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 default:
739 BUG();
740 return;
741 }
742 aac_adapter_notify(dev, notify);
743 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800744}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800747 * aac_fib_adapter_complete - complete adapter issued fib
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 * @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
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800755int aac_fib_adapter_complete(struct fib *fibptr, unsigned short size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756{
Mark Haverkampa8166a52007-03-15 10:26:22 -0700757 struct hw_fib * hw_fib = fibptr->hw_fib_va;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 struct aac_dev * dev = fibptr->dev;
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700759 struct aac_queue * q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 unsigned long nointr = 0;
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700761 unsigned long qflags;
762
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530763 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
764 dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700765 kfree(hw_fib);
766 return 0;
767 }
768
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700769 if (hw_fib->header.XferState == 0) {
Mark Haverkamp28713322007-01-23 14:59:20 -0800770 if (dev->comm_interface == AAC_COMM_MESSAGE)
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700771 kfree(hw_fib);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800772 return 0;
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700773 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 /*
775 * If we plan to do anything check the structure type first.
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800776 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530777 if (hw_fib->header.StructType != FIB_MAGIC &&
778 hw_fib->header.StructType != FIB_MAGIC2 &&
779 hw_fib->header.StructType != FIB_MAGIC2_64) {
Mark Haverkamp28713322007-01-23 14:59:20 -0800780 if (dev->comm_interface == AAC_COMM_MESSAGE)
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700781 kfree(hw_fib);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800782 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 }
784 /*
785 * This block handles the case where the adapter had sent us a
786 * command and we have finished processing the command. We
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800787 * call completeFib when we are done processing the command
788 * and want to send a response back to the adapter. This will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 * send the completed cdb to the adapter.
790 */
791 if (hw_fib->header.XferState & cpu_to_le32(SentFromAdapter)) {
Mark Haverkamp28713322007-01-23 14:59:20 -0800792 if (dev->comm_interface == AAC_COMM_MESSAGE) {
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700793 kfree (hw_fib);
794 } else {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800795 u32 index;
796 hw_fib->header.XferState |= cpu_to_le32(HostProcessed);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700797 if (size) {
798 size += sizeof(struct aac_fibhdr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800799 if (size > le16_to_cpu(hw_fib->header.SenderSize))
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700800 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800811 } else {
812 printk(KERN_WARNING "aac_fib_adapter_complete: "
813 "Unknown xferstate detected.\n");
814 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 return 0;
817}
818
819/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800820 * aac_fib_complete - fib completion handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 * @fib: FIB to complete
822 *
823 * Will do all necessary work to complete a FIB.
824 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800825
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800826int aac_fib_complete(struct fib *fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
Mark Haverkampa8166a52007-03-15 10:26:22 -0700828 struct hw_fib * hw_fib = fibptr->hw_fib_va;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 /*
831 * Check for a fib which has already been completed
832 */
833
834 if (hw_fib->header.XferState == 0)
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800835 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 /*
837 * If we plan to do anything check the structure type first.
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800838 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530840 if (hw_fib->header.StructType != FIB_MAGIC &&
841 hw_fib->header.StructType != FIB_MAGIC2 &&
842 hw_fib->header.StructType != FIB_MAGIC2_64)
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800843 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 /*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800845 * This block completes a cdb which orginated on the host and we
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 * 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 */
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 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();
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800867 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 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
880void aac_printf(struct aac_dev *dev, u32 val)
881{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 char *cp = dev->printfbuf;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700883 if (dev->printf_enabled)
884 {
885 int length = val & 0xffff;
886 int level = (val >> 16) & 0xffff;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800887
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700888 /*
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)
Mark Haverkamp1241f352006-03-27 09:44:23 -0800897 printk(KERN_WARNING "%s:%s", dev->name, cp);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700898 else
Mark Haverkamp1241f352006-03-27 09:44:23 -0800899 printk(KERN_INFO "%s:%s", dev->name, cp);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700900 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800901 memset(cp, 0, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902}
903
Mark Haverkamp131256c2005-09-26 13:04:56 -0700904
905/**
906 * aac_handle_aif - Handle a message from the firmware
907 * @dev: Which adapter this fib is from
908 * @fibptr: Pointer to fibptr from adapter
909 *
910 * This routine handles a driver notify fib from the adapter and
911 * dispatches it to the appropriate routine for handling.
912 */
913
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400914#define AIF_SNIFF_TIMEOUT (500*HZ)
Mark Haverkamp131256c2005-09-26 13:04:56 -0700915static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
916{
Mark Haverkampa8166a52007-03-15 10:26:22 -0700917 struct hw_fib * hw_fib = fibptr->hw_fib_va;
Mark Haverkamp131256c2005-09-26 13:04:56 -0700918 struct aac_aifcmd * aifcmd = (struct aac_aifcmd *)hw_fib->data;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -0800919 u32 channel, id, lun, container;
Mark Haverkamp131256c2005-09-26 13:04:56 -0700920 struct scsi_device *device;
921 enum {
922 NOTHING,
923 DELETE,
924 ADD,
925 CHANGE
Salyzyn, Mark0995ad32008-01-11 11:56:07 -0800926 } device_config_needed = NOTHING;
Mark Haverkamp131256c2005-09-26 13:04:56 -0700927
928 /* Sniff for container changes */
929
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700930 if (!dev || !dev->fsa_dev)
Mark Haverkamp131256c2005-09-26 13:04:56 -0700931 return;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -0800932 container = channel = id = lun = (u32)-1;
Mark Haverkamp131256c2005-09-26 13:04:56 -0700933
934 /*
935 * We have set this up to try and minimize the number of
936 * re-configures that take place. As a result of this when
937 * certain AIF's come in we will set a flag waiting for another
938 * type of AIF before setting the re-config flag.
939 */
940 switch (le32_to_cpu(aifcmd->command)) {
941 case AifCmdDriverNotify:
Christoph Hellwigf3307f72007-11-08 17:27:47 +0000942 switch (le32_to_cpu(((__le32 *)aifcmd->data)[0])) {
Mahesh Rajashekharadab04b02015-03-26 10:41:31 -0400943 case AifRawDeviceRemove:
944 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
945 if ((container >> 28)) {
946 container = (u32)-1;
947 break;
948 }
949 channel = (container >> 24) & 0xF;
950 if (channel >= dev->maximum_num_channels) {
951 container = (u32)-1;
952 break;
953 }
954 id = container & 0xFFFF;
955 if (id >= dev->maximum_num_physicals) {
956 container = (u32)-1;
957 break;
958 }
959 lun = (container >> 16) & 0xFF;
960 container = (u32)-1;
961 channel = aac_phys_to_logical(channel);
962 device_config_needed =
963 (((__le32 *)aifcmd->data)[0] ==
964 cpu_to_le32(AifRawDeviceRemove)) ? DELETE : ADD;
965
966 if (device_config_needed == ADD) {
967 device = scsi_device_lookup(
968 dev->scsi_host_ptr,
969 channel, id, lun);
970 if (device) {
971 scsi_remove_device(device);
972 scsi_device_put(device);
973 }
974 }
975 break;
Mark Haverkamp131256c2005-09-26 13:04:56 -0700976 /*
977 * Morph or Expand complete
978 */
979 case AifDenMorphComplete:
980 case AifDenVolumeExtendComplete:
Christoph Hellwigf3307f72007-11-08 17:27:47 +0000981 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
Mark Haverkamp131256c2005-09-26 13:04:56 -0700982 if (container >= dev->maximum_num_containers)
983 break;
984
985 /*
Christoph Hellwigf64a1812005-10-31 18:32:08 +0100986 * Find the scsi_device associated with the SCSI
Mark Haverkamp131256c2005-09-26 13:04:56 -0700987 * address. Make sure we have the right array, and if
988 * so set the flag to initiate a new re-config once we
989 * see an AifEnConfigChange AIF come through.
990 */
991
992 if ((dev != NULL) && (dev->scsi_host_ptr != NULL)) {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800993 device = scsi_device_lookup(dev->scsi_host_ptr,
994 CONTAINER_TO_CHANNEL(container),
995 CONTAINER_TO_ID(container),
Mark Haverkamp131256c2005-09-26 13:04:56 -0700996 CONTAINER_TO_LUN(container));
997 if (device) {
998 dev->fsa_dev[container].config_needed = CHANGE;
999 dev->fsa_dev[container].config_waiting_on = AifEnConfigChange;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001000 dev->fsa_dev[container].config_waiting_stamp = jiffies;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001001 scsi_device_put(device);
1002 }
1003 }
1004 }
1005
1006 /*
1007 * If we are waiting on something and this happens to be
1008 * that thing then set the re-configure flag.
1009 */
1010 if (container != (u32)-1) {
1011 if (container >= dev->maximum_num_containers)
1012 break;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001013 if ((dev->fsa_dev[container].config_waiting_on ==
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001014 le32_to_cpu(*(__le32 *)aifcmd->data)) &&
Mark Haverkamp31876f32006-03-27 09:43:55 -08001015 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
Mark Haverkamp131256c2005-09-26 13:04:56 -07001016 dev->fsa_dev[container].config_waiting_on = 0;
1017 } else for (container = 0;
1018 container < dev->maximum_num_containers; ++container) {
Mark Haverkamp31876f32006-03-27 09:43:55 -08001019 if ((dev->fsa_dev[container].config_waiting_on ==
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001020 le32_to_cpu(*(__le32 *)aifcmd->data)) &&
Mark Haverkamp31876f32006-03-27 09:43:55 -08001021 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
Mark Haverkamp131256c2005-09-26 13:04:56 -07001022 dev->fsa_dev[container].config_waiting_on = 0;
1023 }
1024 break;
1025
1026 case AifCmdEventNotify:
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001027 switch (le32_to_cpu(((__le32 *)aifcmd->data)[0])) {
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001028 case AifEnBatteryEvent:
1029 dev->cache_protected =
1030 (((__le32 *)aifcmd->data)[1] == cpu_to_le32(3));
1031 break;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001032 /*
1033 * Add an Array.
1034 */
1035 case AifEnAddContainer:
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001036 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
Mark Haverkamp131256c2005-09-26 13:04:56 -07001037 if (container >= dev->maximum_num_containers)
1038 break;
1039 dev->fsa_dev[container].config_needed = ADD;
1040 dev->fsa_dev[container].config_waiting_on =
1041 AifEnConfigChange;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001042 dev->fsa_dev[container].config_waiting_stamp = jiffies;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001043 break;
1044
1045 /*
1046 * Delete an Array.
1047 */
1048 case AifEnDeleteContainer:
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001049 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
Mark Haverkamp131256c2005-09-26 13:04:56 -07001050 if (container >= dev->maximum_num_containers)
1051 break;
1052 dev->fsa_dev[container].config_needed = DELETE;
1053 dev->fsa_dev[container].config_waiting_on =
1054 AifEnConfigChange;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001055 dev->fsa_dev[container].config_waiting_stamp = jiffies;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001056 break;
1057
1058 /*
1059 * Container change detected. If we currently are not
1060 * waiting on something else, setup to wait on a Config Change.
1061 */
1062 case AifEnContainerChange:
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001063 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
Mark Haverkamp131256c2005-09-26 13:04:56 -07001064 if (container >= dev->maximum_num_containers)
1065 break;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001066 if (dev->fsa_dev[container].config_waiting_on &&
1067 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
Mark Haverkamp131256c2005-09-26 13:04:56 -07001068 break;
1069 dev->fsa_dev[container].config_needed = CHANGE;
1070 dev->fsa_dev[container].config_waiting_on =
1071 AifEnConfigChange;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001072 dev->fsa_dev[container].config_waiting_stamp = jiffies;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001073 break;
1074
1075 case AifEnConfigChange:
1076 break;
1077
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001078 case AifEnAddJBOD:
1079 case AifEnDeleteJBOD:
1080 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
Mark Salyzyna4576b52008-04-30 15:47:35 -04001081 if ((container >> 28)) {
1082 container = (u32)-1;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001083 break;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001084 }
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001085 channel = (container >> 24) & 0xF;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001086 if (channel >= dev->maximum_num_channels) {
1087 container = (u32)-1;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001088 break;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001089 }
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001090 id = container & 0xFFFF;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001091 if (id >= dev->maximum_num_physicals) {
1092 container = (u32)-1;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001093 break;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001094 }
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001095 lun = (container >> 16) & 0xFF;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001096 container = (u32)-1;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001097 channel = aac_phys_to_logical(channel);
1098 device_config_needed =
1099 (((__le32 *)aifcmd->data)[0] ==
1100 cpu_to_le32(AifEnAddJBOD)) ? ADD : DELETE;
Rajashekhara, Mahesh5ca05592010-05-10 04:05:50 -07001101 if (device_config_needed == ADD) {
1102 device = scsi_device_lookup(dev->scsi_host_ptr,
1103 channel,
1104 id,
1105 lun);
1106 if (device) {
1107 scsi_remove_device(device);
1108 scsi_device_put(device);
1109 }
1110 }
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001111 break;
1112
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001113 case AifEnEnclosureManagement:
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001114 /*
1115 * If in JBOD mode, automatic exposure of new
1116 * physical target to be suppressed until configured.
1117 */
1118 if (dev->jbod)
1119 break;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001120 switch (le32_to_cpu(((__le32 *)aifcmd->data)[3])) {
1121 case EM_DRIVE_INSERTION:
1122 case EM_DRIVE_REMOVAL:
Mahesh Rajashekhara46154a02015-03-26 10:41:22 -04001123 case EM_SES_DRIVE_INSERTION:
1124 case EM_SES_DRIVE_REMOVAL:
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001125 container = le32_to_cpu(
1126 ((__le32 *)aifcmd->data)[2]);
Mark Salyzyna4576b52008-04-30 15:47:35 -04001127 if ((container >> 28)) {
1128 container = (u32)-1;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001129 break;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001130 }
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001131 channel = (container >> 24) & 0xF;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001132 if (channel >= dev->maximum_num_channels) {
1133 container = (u32)-1;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001134 break;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001135 }
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001136 id = container & 0xFFFF;
1137 lun = (container >> 16) & 0xFF;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001138 container = (u32)-1;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001139 if (id >= dev->maximum_num_physicals) {
1140 /* legacy dev_t ? */
1141 if ((0x2000 <= id) || lun || channel ||
1142 ((channel = (id >> 7) & 0x3F) >=
1143 dev->maximum_num_channels))
1144 break;
1145 lun = (id >> 4) & 7;
1146 id &= 0xF;
1147 }
1148 channel = aac_phys_to_logical(channel);
1149 device_config_needed =
Mahesh Rajashekhara46154a02015-03-26 10:41:22 -04001150 ((((__le32 *)aifcmd->data)[3]
1151 == cpu_to_le32(EM_DRIVE_INSERTION)) ||
1152 (((__le32 *)aifcmd->data)[3]
1153 == cpu_to_le32(EM_SES_DRIVE_INSERTION))) ?
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001154 ADD : DELETE;
1155 break;
1156 }
1157 break;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001158 }
1159
1160 /*
1161 * If we are waiting on something and this happens to be
1162 * that thing then set the re-configure flag.
1163 */
1164 if (container != (u32)-1) {
1165 if (container >= dev->maximum_num_containers)
1166 break;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001167 if ((dev->fsa_dev[container].config_waiting_on ==
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001168 le32_to_cpu(*(__le32 *)aifcmd->data)) &&
Mark Haverkamp31876f32006-03-27 09:43:55 -08001169 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
Mark Haverkamp131256c2005-09-26 13:04:56 -07001170 dev->fsa_dev[container].config_waiting_on = 0;
1171 } else for (container = 0;
1172 container < dev->maximum_num_containers; ++container) {
Mark Haverkamp31876f32006-03-27 09:43:55 -08001173 if ((dev->fsa_dev[container].config_waiting_on ==
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001174 le32_to_cpu(*(__le32 *)aifcmd->data)) &&
Mark Haverkamp31876f32006-03-27 09:43:55 -08001175 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
Mark Haverkamp131256c2005-09-26 13:04:56 -07001176 dev->fsa_dev[container].config_waiting_on = 0;
1177 }
1178 break;
1179
1180 case AifCmdJobProgress:
1181 /*
1182 * These are job progress AIF's. When a Clear is being
1183 * done on a container it is initially created then hidden from
1184 * the OS. When the clear completes we don't get a config
1185 * change so we monitor the job status complete on a clear then
1186 * wait for a container change.
1187 */
1188
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001189 if (((__le32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero) &&
1190 (((__le32 *)aifcmd->data)[6] == ((__le32 *)aifcmd->data)[5] ||
1191 ((__le32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsSuccess))) {
Mark Haverkamp131256c2005-09-26 13:04:56 -07001192 for (container = 0;
1193 container < dev->maximum_num_containers;
1194 ++container) {
1195 /*
1196 * Stomp on all config sequencing for all
1197 * containers?
1198 */
1199 dev->fsa_dev[container].config_waiting_on =
1200 AifEnContainerChange;
1201 dev->fsa_dev[container].config_needed = ADD;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001202 dev->fsa_dev[container].config_waiting_stamp =
1203 jiffies;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001204 }
1205 }
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001206 if (((__le32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero) &&
1207 ((__le32 *)aifcmd->data)[6] == 0 &&
1208 ((__le32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsRunning)) {
Mark Haverkamp131256c2005-09-26 13:04:56 -07001209 for (container = 0;
1210 container < dev->maximum_num_containers;
1211 ++container) {
1212 /*
1213 * Stomp on all config sequencing for all
1214 * containers?
1215 */
1216 dev->fsa_dev[container].config_waiting_on =
1217 AifEnContainerChange;
1218 dev->fsa_dev[container].config_needed = DELETE;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001219 dev->fsa_dev[container].config_waiting_stamp =
1220 jiffies;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001221 }
1222 }
1223 break;
1224 }
1225
Mark Salyzyna4576b52008-04-30 15:47:35 -04001226 container = 0;
1227retry_next:
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001228 if (device_config_needed == NOTHING)
Mark Salyzyna4576b52008-04-30 15:47:35 -04001229 for (; container < dev->maximum_num_containers; ++container) {
Mark Haverkamp31876f32006-03-27 09:43:55 -08001230 if ((dev->fsa_dev[container].config_waiting_on == 0) &&
1231 (dev->fsa_dev[container].config_needed != NOTHING) &&
1232 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) {
Mark Haverkamp131256c2005-09-26 13:04:56 -07001233 device_config_needed =
1234 dev->fsa_dev[container].config_needed;
1235 dev->fsa_dev[container].config_needed = NOTHING;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001236 channel = CONTAINER_TO_CHANNEL(container);
1237 id = CONTAINER_TO_ID(container);
1238 lun = CONTAINER_TO_LUN(container);
Mark Haverkamp131256c2005-09-26 13:04:56 -07001239 break;
1240 }
1241 }
1242 if (device_config_needed == NOTHING)
1243 return;
1244
1245 /*
1246 * If we decided that a re-configuration needs to be done,
1247 * schedule it here on the way out the door, please close the door
1248 * behind you.
1249 */
1250
Mark Haverkamp131256c2005-09-26 13:04:56 -07001251 /*
Christoph Hellwigf64a1812005-10-31 18:32:08 +01001252 * Find the scsi_device associated with the SCSI address,
Mark Haverkamp131256c2005-09-26 13:04:56 -07001253 * and mark it as changed, invalidating the cache. This deals
1254 * with changes to existing device IDs.
1255 */
1256
1257 if (!dev || !dev->scsi_host_ptr)
1258 return;
1259 /*
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001260 * force reload of disk info via aac_probe_container
Mark Haverkamp131256c2005-09-26 13:04:56 -07001261 */
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001262 if ((channel == CONTAINER_CHANNEL) &&
1263 (device_config_needed != NOTHING)) {
1264 if (dev->fsa_dev[container].valid == 1)
1265 dev->fsa_dev[container].valid = 2;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001266 aac_probe_container(dev, container);
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001267 }
1268 device = scsi_device_lookup(dev->scsi_host_ptr, channel, id, lun);
Mark Haverkamp131256c2005-09-26 13:04:56 -07001269 if (device) {
1270 switch (device_config_needed) {
1271 case DELETE:
Rajashekhara, Mahesh9cccde92010-05-10 04:29:25 -07001272#if (defined(AAC_DEBUG_INSTRUMENT_AIF_DELETE))
1273 scsi_remove_device(device);
1274#else
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001275 if (scsi_device_online(device)) {
1276 scsi_device_set_state(device, SDEV_OFFLINE);
1277 sdev_printk(KERN_INFO, device,
1278 "Device offlined - %s\n",
1279 (channel == CONTAINER_CHANNEL) ?
1280 "array deleted" :
1281 "enclosure services event");
1282 }
Rajashekhara, Mahesh9cccde92010-05-10 04:29:25 -07001283#endif
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001284 break;
1285 case ADD:
1286 if (!scsi_device_online(device)) {
1287 sdev_printk(KERN_INFO, device,
1288 "Device online - %s\n",
1289 (channel == CONTAINER_CHANNEL) ?
1290 "array created" :
1291 "enclosure services event");
1292 scsi_device_set_state(device, SDEV_RUNNING);
1293 }
1294 /* FALLTHRU */
Mark Haverkamp131256c2005-09-26 13:04:56 -07001295 case CHANGE:
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001296 if ((channel == CONTAINER_CHANNEL)
1297 && (!dev->fsa_dev[container].valid)) {
Rajashekhara, Mahesh9cccde92010-05-10 04:29:25 -07001298#if (defined(AAC_DEBUG_INSTRUMENT_AIF_DELETE))
1299 scsi_remove_device(device);
1300#else
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001301 if (!scsi_device_online(device))
1302 break;
1303 scsi_device_set_state(device, SDEV_OFFLINE);
1304 sdev_printk(KERN_INFO, device,
1305 "Device offlined - %s\n",
1306 "array failed");
Rajashekhara, Mahesh9cccde92010-05-10 04:29:25 -07001307#endif
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001308 break;
1309 }
Mark Haverkamp131256c2005-09-26 13:04:56 -07001310 scsi_rescan_device(&device->sdev_gendev);
1311
1312 default:
1313 break;
1314 }
1315 scsi_device_put(device);
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001316 device_config_needed = NOTHING;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001317 }
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001318 if (device_config_needed == ADD)
1319 scsi_add_device(dev->scsi_host_ptr, channel, id, lun);
Mark Salyzyna4576b52008-04-30 15:47:35 -04001320 if (channel == CONTAINER_CHANNEL) {
1321 container++;
1322 device_config_needed = NOTHING;
1323 goto retry_next;
1324 }
Mark Haverkamp131256c2005-09-26 13:04:56 -07001325}
1326
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001327static int _aac_reset_adapter(struct aac_dev *aac, int forced)
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001328{
1329 int index, quirks;
Mahesh Rajashekhara8b1462e2015-08-28 06:38:38 -04001330 int retval;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001331 struct Scsi_Host *host;
1332 struct scsi_device *dev;
1333 struct scsi_cmnd *command;
1334 struct scsi_cmnd *command_list;
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001335 int jafo = 0;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001336
1337 /*
1338 * Assumptions:
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001339 * - host is locked, unless called by the aacraid thread.
1340 * (a matter of convenience, due to legacy issues surrounding
1341 * eh_host_adapter_reset).
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001342 * - in_reset is asserted, so no new i/o is getting to the
1343 * card.
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001344 * - The card is dead, or will be very shortly ;-/ so no new
1345 * commands are completing in the interrupt service.
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001346 */
1347 host = aac->scsi_host_ptr;
1348 scsi_block_requests(host);
1349 aac_adapter_disable_int(aac);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001350 if (aac->thread->pid != current->pid) {
1351 spin_unlock_irq(host->host_lock);
1352 kthread_stop(aac->thread);
1353 jafo = 1;
1354 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001355
1356 /*
1357 * If a positive health, means in a known DEAD PANIC
1358 * state and the adapter could be reset to `try again'.
1359 */
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001360 retval = aac_adapter_restart(aac, forced ? 0 : aac_adapter_check_health(aac));
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001361
1362 if (retval)
1363 goto out;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001364
Mark Haverkampd18b4482006-11-21 10:40:31 -08001365 /*
1366 * Loop through the fibs, close the synchronous FIBS
1367 */
Mark Haverkamp33bb3b22007-03-15 10:27:21 -07001368 for (retval = 1, index = 0; index < (aac->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB); index++) {
Mark Haverkampd18b4482006-11-21 10:40:31 -08001369 struct fib *fib = &aac->fibs[index];
Mark Haverkampa8166a52007-03-15 10:26:22 -07001370 if (!(fib->hw_fib_va->header.XferState & cpu_to_le32(NoResponseExpected | Async)) &&
1371 (fib->hw_fib_va->header.XferState & cpu_to_le32(ResponseExpected))) {
Mark Haverkampd18b4482006-11-21 10:40:31 -08001372 unsigned long flagv;
1373 spin_lock_irqsave(&fib->event_lock, flagv);
1374 up(&fib->event_wait);
1375 spin_unlock_irqrestore(&fib->event_lock, flagv);
1376 schedule();
Mark Haverkamp33bb3b22007-03-15 10:27:21 -07001377 retval = 0;
Mark Haverkampd18b4482006-11-21 10:40:31 -08001378 }
1379 }
Mark Haverkamp33bb3b22007-03-15 10:27:21 -07001380 /* Give some extra time for ioctls to complete. */
1381 if (retval == 0)
1382 ssleep(2);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001383 index = aac->cardtype;
1384
1385 /*
1386 * Re-initialize the adapter, first free resources, then carefully
1387 * apply the initialization sequence to come back again. Only risk
1388 * is a change in Firmware dropping cache, it is assumed the caller
1389 * will ensure that i/o is queisced and the card is flushed in that
1390 * case.
1391 */
1392 aac_fib_map_free(aac);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001393 pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr, aac->comm_phys);
1394 aac->comm_addr = NULL;
1395 aac->comm_phys = 0;
1396 kfree(aac->queues);
1397 aac->queues = NULL;
Mahesh Rajashekhara8b1462e2015-08-28 06:38:38 -04001398 aac_free_irq(aac);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001399 kfree(aac->fsa_dev);
1400 aac->fsa_dev = NULL;
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001401 quirks = aac_get_driver_ident(index)->quirks;
1402 if (quirks & AAC_QUIRK_31BIT) {
Yang Hongyang929a22a2009-04-06 19:01:16 -07001403 if (((retval = pci_set_dma_mask(aac->pdev, DMA_BIT_MASK(31)))) ||
1404 ((retval = pci_set_consistent_dma_mask(aac->pdev, DMA_BIT_MASK(31)))))
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001405 goto out;
1406 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07001407 if (((retval = pci_set_dma_mask(aac->pdev, DMA_BIT_MASK(32)))) ||
1408 ((retval = pci_set_consistent_dma_mask(aac->pdev, DMA_BIT_MASK(32)))))
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001409 goto out;
1410 }
1411 if ((retval = (*(aac_get_driver_ident(index)->init))(aac)))
1412 goto out;
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001413 if (quirks & AAC_QUIRK_31BIT)
Yang Hongyang284901a2009-04-06 19:01:15 -07001414 if ((retval = pci_set_dma_mask(aac->pdev, DMA_BIT_MASK(32))))
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001415 goto out;
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001416 if (jafo) {
Kees Cookf1701682013-07-03 15:04:58 -07001417 aac->thread = kthread_run(aac_command_thread, aac, "%s",
1418 aac->name);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001419 if (IS_ERR(aac->thread)) {
1420 retval = PTR_ERR(aac->thread);
1421 goto out;
1422 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001423 }
1424 (void)aac_get_adapter_info(aac);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001425 if ((quirks & AAC_QUIRK_34SG) && (host->sg_tablesize > 34)) {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001426 host->sg_tablesize = 34;
1427 host->max_sectors = (host->sg_tablesize * 8) + 112;
1428 }
1429 if ((quirks & AAC_QUIRK_17SG) && (host->sg_tablesize > 17)) {
1430 host->sg_tablesize = 17;
1431 host->max_sectors = (host->sg_tablesize * 8) + 112;
1432 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001433 aac_get_config_status(aac, 1);
1434 aac_get_containers(aac);
1435 /*
1436 * This is where the assumption that the Adapter is quiesced
1437 * is important.
1438 */
1439 command_list = NULL;
1440 __shost_for_each_device(dev, host) {
1441 unsigned long flags;
1442 spin_lock_irqsave(&dev->list_lock, flags);
1443 list_for_each_entry(command, &dev->cmd_list, list)
1444 if (command->SCp.phase == AAC_OWNER_FIRMWARE) {
1445 command->SCp.buffer = (struct scatterlist *)command_list;
1446 command_list = command;
1447 }
1448 spin_unlock_irqrestore(&dev->list_lock, flags);
1449 }
1450 while ((command = command_list)) {
1451 command_list = (struct scsi_cmnd *)command->SCp.buffer;
1452 command->SCp.buffer = NULL;
1453 command->result = DID_OK << 16
1454 | COMMAND_COMPLETE << 8
1455 | SAM_STAT_TASK_SET_FULL;
1456 command->SCp.phase = AAC_OWNER_ERROR_HANDLER;
1457 command->scsi_done(command);
1458 }
1459 retval = 0;
1460
1461out:
1462 aac->in_reset = 0;
1463 scsi_unblock_requests(host);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001464 if (jafo) {
1465 spin_lock_irq(host->host_lock);
1466 }
1467 return retval;
1468}
1469
1470int aac_reset_adapter(struct aac_dev * aac, int forced)
1471{
1472 unsigned long flagv = 0;
1473 int retval;
1474 struct Scsi_Host * host;
1475
1476 if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0)
1477 return -EBUSY;
1478
1479 if (aac->in_reset) {
1480 spin_unlock_irqrestore(&aac->fib_lock, flagv);
1481 return -EBUSY;
1482 }
1483 aac->in_reset = 1;
1484 spin_unlock_irqrestore(&aac->fib_lock, flagv);
1485
1486 /*
1487 * Wait for all commands to complete to this specific
1488 * target (block maximum 60 seconds). Although not necessary,
1489 * it does make us a good storage citizen.
1490 */
1491 host = aac->scsi_host_ptr;
1492 scsi_block_requests(host);
1493 if (forced < 2) for (retval = 60; retval; --retval) {
1494 struct scsi_device * dev;
1495 struct scsi_cmnd * command;
1496 int active = 0;
1497
1498 __shost_for_each_device(dev, host) {
1499 spin_lock_irqsave(&dev->list_lock, flagv);
1500 list_for_each_entry(command, &dev->cmd_list, list) {
1501 if (command->SCp.phase == AAC_OWNER_FIRMWARE) {
1502 active++;
1503 break;
1504 }
1505 }
1506 spin_unlock_irqrestore(&dev->list_lock, flagv);
1507 if (active)
1508 break;
1509
1510 }
1511 /*
1512 * We can exit If all the commands are complete
1513 */
1514 if (active == 0)
1515 break;
1516 ssleep(1);
1517 }
1518
1519 /* Quiesce build, flush cache, write through mode */
Salyzyn, Markf8583172007-10-30 15:50:49 -04001520 if (forced < 2)
1521 aac_send_shutdown(aac);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001522 spin_lock_irqsave(host->host_lock, flagv);
Salyzyn, Markf8583172007-10-30 15:50:49 -04001523 retval = _aac_reset_adapter(aac, forced ? forced : ((aac_check_reset != 0) && (aac_check_reset != 1)));
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001524 spin_unlock_irqrestore(host->host_lock, flagv);
1525
Salyzyn, Markf8583172007-10-30 15:50:49 -04001526 if ((forced < 2) && (retval == -ENODEV)) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001527 /* Unwind aac_send_shutdown() IOP_RESET unsupported/disabled */
1528 struct fib * fibctx = aac_fib_alloc(aac);
1529 if (fibctx) {
1530 struct aac_pause *cmd;
1531 int status;
1532
1533 aac_fib_init(fibctx);
1534
1535 cmd = (struct aac_pause *) fib_data(fibctx);
1536
1537 cmd->command = cpu_to_le32(VM_ContainerConfig);
1538 cmd->type = cpu_to_le32(CT_PAUSE_IO);
1539 cmd->timeout = cpu_to_le32(1);
1540 cmd->min = cpu_to_le32(1);
1541 cmd->noRescan = cpu_to_le32(1);
1542 cmd->count = cpu_to_le32(0);
1543
1544 status = aac_fib_send(ContainerCommand,
1545 fibctx,
1546 sizeof(struct aac_pause),
1547 FsaNormal,
1548 -2 /* Timeout silently */, 1,
1549 NULL, NULL);
1550
1551 if (status >= 0)
1552 aac_fib_complete(fibctx);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301553 /* FIB should be freed only after getting
1554 * the response from the F/W */
1555 if (status != -ERESTARTSYS)
1556 aac_fib_free(fibctx);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001557 }
1558 }
1559
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001560 return retval;
1561}
1562
1563int aac_check_health(struct aac_dev * aac)
1564{
1565 int BlinkLED;
1566 unsigned long time_now, flagv = 0;
1567 struct list_head * entry;
1568 struct Scsi_Host * host;
1569
1570 /* Extending the scope of fib_lock slightly to protect aac->in_reset */
1571 if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0)
1572 return 0;
1573
1574 if (aac->in_reset || !(BlinkLED = aac_adapter_check_health(aac))) {
1575 spin_unlock_irqrestore(&aac->fib_lock, flagv);
1576 return 0; /* OK */
1577 }
1578
1579 aac->in_reset = 1;
1580
1581 /* Fake up an AIF:
1582 * aac_aifcmd.command = AifCmdEventNotify = 1
1583 * aac_aifcmd.seqnum = 0xFFFFFFFF
1584 * aac_aifcmd.data[0] = AifEnExpEvent = 23
1585 * aac_aifcmd.data[1] = AifExeFirmwarePanic = 3
1586 * aac.aifcmd.data[2] = AifHighPriority = 3
1587 * aac.aifcmd.data[3] = BlinkLED
1588 */
1589
1590 time_now = jiffies/HZ;
1591 entry = aac->fib_list.next;
1592
1593 /*
1594 * For each Context that is on the
1595 * fibctxList, make a copy of the
1596 * fib, and then set the event to wake up the
1597 * thread that is waiting for it.
1598 */
1599 while (entry != &aac->fib_list) {
1600 /*
1601 * Extract the fibctx
1602 */
1603 struct aac_fib_context *fibctx = list_entry(entry, struct aac_fib_context, next);
1604 struct hw_fib * hw_fib;
1605 struct fib * fib;
1606 /*
1607 * Check if the queue is getting
1608 * backlogged
1609 */
1610 if (fibctx->count > 20) {
1611 /*
1612 * It's *not* jiffies folks,
1613 * but jiffies / HZ, so do not
1614 * panic ...
1615 */
1616 u32 time_last = fibctx->jiffies;
1617 /*
1618 * Has it been > 2 minutes
1619 * since the last read off
1620 * the queue?
1621 */
1622 if ((time_now - time_last) > aif_timeout) {
1623 entry = entry->next;
1624 aac_close_fib_context(aac, fibctx);
1625 continue;
1626 }
1627 }
1628 /*
1629 * Warning: no sleep allowed while
1630 * holding spinlock
1631 */
Salyzyn, Mark4dbc22d2007-04-16 11:21:50 -04001632 hw_fib = kzalloc(sizeof(struct hw_fib), GFP_ATOMIC);
1633 fib = kzalloc(sizeof(struct fib), GFP_ATOMIC);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001634 if (fib && hw_fib) {
1635 struct aac_aifcmd * aif;
1636
Mark Haverkampa8166a52007-03-15 10:26:22 -07001637 fib->hw_fib_va = hw_fib;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001638 fib->dev = aac;
1639 aac_fib_init(fib);
1640 fib->type = FSAFS_NTC_FIB_CONTEXT;
1641 fib->size = sizeof (struct fib);
1642 fib->data = hw_fib->data;
1643 aif = (struct aac_aifcmd *)hw_fib->data;
1644 aif->command = cpu_to_le32(AifCmdEventNotify);
Salyzyn, Marka3940da2008-01-08 12:48:25 -08001645 aif->seqnum = cpu_to_le32(0xFFFFFFFF);
1646 ((__le32 *)aif->data)[0] = cpu_to_le32(AifEnExpEvent);
1647 ((__le32 *)aif->data)[1] = cpu_to_le32(AifExeFirmwarePanic);
1648 ((__le32 *)aif->data)[2] = cpu_to_le32(AifHighPriority);
1649 ((__le32 *)aif->data)[3] = cpu_to_le32(BlinkLED);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001650
1651 /*
1652 * Put the FIB onto the
1653 * fibctx's fibs
1654 */
1655 list_add_tail(&fib->fiblink, &fibctx->fib_list);
1656 fibctx->count++;
1657 /*
1658 * Set the event to wake up the
1659 * thread that will waiting.
1660 */
1661 up(&fibctx->wait_sem);
1662 } else {
1663 printk(KERN_WARNING "aifd: didn't allocate NewFib.\n");
1664 kfree(fib);
1665 kfree(hw_fib);
1666 }
1667 entry = entry->next;
1668 }
1669
1670 spin_unlock_irqrestore(&aac->fib_lock, flagv);
1671
1672 if (BlinkLED < 0) {
1673 printk(KERN_ERR "%s: Host adapter dead %d\n", aac->name, BlinkLED);
1674 goto out;
1675 }
1676
1677 printk(KERN_ERR "%s: Host adapter BLINK LED 0x%x\n", aac->name, BlinkLED);
1678
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001679 if (!aac_check_reset || ((aac_check_reset == 1) &&
Salyzyn, Marka3940da2008-01-08 12:48:25 -08001680 (aac->supplement_adapter_info.SupportedOptions2 &
1681 AAC_OPTION_IGNORE_RESET)))
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001682 goto out;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001683 host = aac->scsi_host_ptr;
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001684 if (aac->thread->pid != current->pid)
1685 spin_lock_irqsave(host->host_lock, flagv);
Salyzyn, Markf8583172007-10-30 15:50:49 -04001686 BlinkLED = _aac_reset_adapter(aac, aac_check_reset != 1);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001687 if (aac->thread->pid != current->pid)
1688 spin_unlock_irqrestore(host->host_lock, flagv);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001689 return BlinkLED;
1690
1691out:
1692 aac->in_reset = 0;
1693 return BlinkLED;
1694}
1695
1696
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697/**
1698 * aac_command_thread - command processing thread
1699 * @dev: Adapter to monitor
1700 *
1701 * Waits on the commandready event in it's queue. When the event gets set
1702 * it will pull FIBs off it's queue. It will continue to pull FIBs off
1703 * until the queue is empty. When the queue is empty it will wait for
1704 * more FIBs.
1705 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001706
Christoph Hellwigfe273812006-02-14 18:45:06 +01001707int aac_command_thread(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708{
Christoph Hellwigfe273812006-02-14 18:45:06 +01001709 struct aac_dev *dev = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 struct hw_fib *hw_fib, *hw_newfib;
1711 struct fib *fib, *newfib;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 struct aac_fib_context *fibctx;
1713 unsigned long flags;
1714 DECLARE_WAITQUEUE(wait, current);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001715 unsigned long next_jiffies = jiffies + HZ;
1716 unsigned long next_check_jiffies = next_jiffies;
1717 long difference = HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
1719 /*
1720 * We can only have one thread per adapter for AIF's.
1721 */
1722 if (dev->aif_thread)
1723 return -EINVAL;
Christoph Hellwigfe273812006-02-14 18:45:06 +01001724
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 /*
1726 * Let the DPC know it has a place to send the AIF's to.
1727 */
1728 dev->aif_thread = 1;
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001729 add_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 set_current_state(TASK_INTERRUPTIBLE);
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001731 dprintk ((KERN_INFO "aac_command_thread start\n"));
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001732 while (1) {
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001733 spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
1734 while(!list_empty(&(dev->queues->queue[HostNormCmdQueue].cmdq))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 struct list_head *entry;
1736 struct aac_aifcmd * aifcmd;
1737
1738 set_current_state(TASK_RUNNING);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001739
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001740 entry = dev->queues->queue[HostNormCmdQueue].cmdq.next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 list_del(entry);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001742
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001743 spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 fib = list_entry(entry, struct fib, fiblink);
1745 /*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001746 * We will process the FIB here or pass it to a
1747 * worker thread that is TBD. We Really can't
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 * do anything at this point since we don't have
1749 * anything defined for this thread to do.
1750 */
Mark Haverkampa8166a52007-03-15 10:26:22 -07001751 hw_fib = fib->hw_fib_va;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 memset(fib, 0, sizeof(struct fib));
1753 fib->type = FSAFS_NTC_FIB_CONTEXT;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001754 fib->size = sizeof(struct fib);
Mark Haverkampa8166a52007-03-15 10:26:22 -07001755 fib->hw_fib_va = hw_fib;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 fib->data = hw_fib->data;
1757 fib->dev = dev;
1758 /*
1759 * We only handle AifRequest fibs from the adapter.
1760 */
1761 aifcmd = (struct aac_aifcmd *) hw_fib->data;
1762 if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) {
1763 /* Handle Driver Notify Events */
Mark Haverkamp131256c2005-09-26 13:04:56 -07001764 aac_handle_aif(dev, fib);
Mark Haverkamp 56b58712005-04-27 06:05:51 -07001765 *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001766 aac_fib_adapter_complete(fib, (u16)sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 /* The u32 here is important and intended. We are using
1769 32bit wrapping time to fit the adapter field */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001770
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 u32 time_now, time_last;
1772 unsigned long flagv;
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001773 unsigned num;
1774 struct hw_fib ** hw_fib_pool, ** hw_fib_p;
1775 struct fib ** fib_pool, ** fib_p;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001776
Mark Haverkamp131256c2005-09-26 13:04:56 -07001777 /* Sniff events */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001778 if ((aifcmd->command ==
Mark Haverkamp131256c2005-09-26 13:04:56 -07001779 cpu_to_le32(AifCmdEventNotify)) ||
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001780 (aifcmd->command ==
Mark Haverkamp131256c2005-09-26 13:04:56 -07001781 cpu_to_le32(AifCmdJobProgress))) {
1782 aac_handle_aif(dev, fib);
1783 }
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001784
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 time_now = jiffies/HZ;
1786
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001787 /*
1788 * Warning: no sleep allowed while
1789 * holding spinlock. We take the estimate
1790 * and pre-allocate a set of fibs outside the
1791 * lock.
1792 */
1793 num = le32_to_cpu(dev->init->AdapterFibsSize)
1794 / sizeof(struct hw_fib); /* some extra */
1795 spin_lock_irqsave(&dev->fib_lock, flagv);
1796 entry = dev->fib_list.next;
1797 while (entry != &dev->fib_list) {
1798 entry = entry->next;
1799 ++num;
1800 }
1801 spin_unlock_irqrestore(&dev->fib_lock, flagv);
1802 hw_fib_pool = NULL;
1803 fib_pool = NULL;
1804 if (num
1805 && ((hw_fib_pool = kmalloc(sizeof(struct hw_fib *) * num, GFP_KERNEL)))
1806 && ((fib_pool = kmalloc(sizeof(struct fib *) * num, GFP_KERNEL)))) {
1807 hw_fib_p = hw_fib_pool;
1808 fib_p = fib_pool;
1809 while (hw_fib_p < &hw_fib_pool[num]) {
1810 if (!(*(hw_fib_p++) = kmalloc(sizeof(struct hw_fib), GFP_KERNEL))) {
1811 --hw_fib_p;
1812 break;
1813 }
1814 if (!(*(fib_p++) = kmalloc(sizeof(struct fib), GFP_KERNEL))) {
1815 kfree(*(--hw_fib_p));
1816 break;
1817 }
1818 }
1819 if ((num = hw_fib_p - hw_fib_pool) == 0) {
1820 kfree(fib_pool);
1821 fib_pool = NULL;
1822 kfree(hw_fib_pool);
1823 hw_fib_pool = NULL;
1824 }
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001825 } else {
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001826 kfree(hw_fib_pool);
1827 hw_fib_pool = NULL;
1828 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 spin_lock_irqsave(&dev->fib_lock, flagv);
1830 entry = dev->fib_list.next;
1831 /*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001832 * For each Context that is on the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 * fibctxList, make a copy of the
1834 * fib, and then set the event to wake up the
1835 * thread that is waiting for it.
1836 */
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001837 hw_fib_p = hw_fib_pool;
1838 fib_p = fib_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 while (entry != &dev->fib_list) {
1840 /*
1841 * Extract the fibctx
1842 */
1843 fibctx = list_entry(entry, struct aac_fib_context, next);
1844 /*
1845 * Check if the queue is getting
1846 * backlogged
1847 */
1848 if (fibctx->count > 20)
1849 {
1850 /*
1851 * It's *not* jiffies folks,
1852 * but jiffies / HZ so do not
1853 * panic ...
1854 */
1855 time_last = fibctx->jiffies;
1856 /*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001857 * Has it been > 2 minutes
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 * since the last read off
1859 * the queue?
1860 */
Mark Haverkamp404d9a92006-05-10 09:12:48 -07001861 if ((time_now - time_last) > aif_timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 entry = entry->next;
1863 aac_close_fib_context(dev, fibctx);
1864 continue;
1865 }
1866 }
1867 /*
1868 * Warning: no sleep allowed while
1869 * holding spinlock
1870 */
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001871 if (hw_fib_p < &hw_fib_pool[num]) {
1872 hw_newfib = *hw_fib_p;
1873 *(hw_fib_p++) = NULL;
1874 newfib = *fib_p;
1875 *(fib_p++) = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 /*
1877 * Make the copy of the FIB
1878 */
1879 memcpy(hw_newfib, hw_fib, sizeof(struct hw_fib));
1880 memcpy(newfib, fib, sizeof(struct fib));
Mark Haverkampa8166a52007-03-15 10:26:22 -07001881 newfib->hw_fib_va = hw_newfib;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 /*
1883 * Put the FIB onto the
1884 * fibctx's fibs
1885 */
1886 list_add_tail(&newfib->fiblink, &fibctx->fib_list);
1887 fibctx->count++;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001888 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 * Set the event to wake up the
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001890 * thread that is waiting.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 */
1892 up(&fibctx->wait_sem);
1893 } else {
1894 printk(KERN_WARNING "aifd: didn't allocate NewFib.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 }
1896 entry = entry->next;
1897 }
1898 /*
1899 * Set the status of this FIB
1900 */
Mark Haverkamp 56b58712005-04-27 06:05:51 -07001901 *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001902 aac_fib_adapter_complete(fib, sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 spin_unlock_irqrestore(&dev->fib_lock, flagv);
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001904 /* Free up the remaining resources */
1905 hw_fib_p = hw_fib_pool;
1906 fib_p = fib_pool;
1907 while (hw_fib_p < &hw_fib_pool[num]) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001908 kfree(*hw_fib_p);
1909 kfree(*fib_p);
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001910 ++fib_p;
1911 ++hw_fib_p;
1912 }
Jesper Juhlc9475cb2005-11-07 01:01:26 -08001913 kfree(hw_fib_pool);
1914 kfree(fib_pool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 kfree(fib);
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001917 spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 }
1919 /*
1920 * There are no more AIF's
1921 */
Mark Haverkamp2f1309802005-09-26 13:02:15 -07001922 spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001923
1924 /*
1925 * Background activity
1926 */
1927 if ((time_before(next_check_jiffies,next_jiffies))
1928 && ((difference = next_check_jiffies - jiffies) <= 0)) {
1929 next_check_jiffies = next_jiffies;
1930 if (aac_check_health(dev) == 0) {
1931 difference = ((long)(unsigned)check_interval)
1932 * HZ;
1933 next_check_jiffies = jiffies + difference;
1934 } else if (!dev->queues)
1935 break;
1936 }
1937 if (!time_before(next_check_jiffies,next_jiffies)
1938 && ((difference = next_jiffies - jiffies) <= 0)) {
1939 struct timeval now;
1940 int ret;
1941
1942 /* Don't even try to talk to adapter if its sick */
1943 ret = aac_check_health(dev);
1944 if (!ret && !dev->queues)
1945 break;
1946 next_check_jiffies = jiffies
1947 + ((long)(unsigned)check_interval)
1948 * HZ;
1949 do_gettimeofday(&now);
1950
1951 /* Synchronize our watches */
1952 if (((1000000 - (1000000 / HZ)) > now.tv_usec)
1953 && (now.tv_usec > (1000000 / HZ)))
1954 difference = (((1000000 - now.tv_usec) * HZ)
1955 + 500000) / 1000000;
1956 else if (ret == 0) {
1957 struct fib *fibptr;
1958
1959 if ((fibptr = aac_fib_alloc(dev))) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301960 int status;
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001961 __le32 *info;
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001962
1963 aac_fib_init(fibptr);
1964
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001965 info = (__le32 *) fib_data(fibptr);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001966 if (now.tv_usec > 500000)
1967 ++now.tv_sec;
1968
1969 *info = cpu_to_le32(now.tv_sec);
1970
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301971 status = aac_fib_send(SendHostTime,
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001972 fibptr,
1973 sizeof(*info),
1974 FsaNormal,
1975 1, 1,
1976 NULL,
1977 NULL);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301978 /* Do not set XferState to zero unless
1979 * receives a response from F/W */
1980 if (status >= 0)
1981 aac_fib_complete(fibptr);
1982 /* FIB should be freed only after
1983 * getting the response from the F/W */
1984 if (status != -ERESTARTSYS)
1985 aac_fib_free(fibptr);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001986 }
1987 difference = (long)(unsigned)update_interval*HZ;
1988 } else {
1989 /* retry shortly */
1990 difference = 10 * HZ;
1991 }
1992 next_jiffies = jiffies + difference;
1993 if (time_before(next_check_jiffies,next_jiffies))
1994 difference = next_check_jiffies - jiffies;
1995 }
1996 if (difference <= 0)
1997 difference = 1;
1998 set_current_state(TASK_INTERRUPTIBLE);
Raghava Aditya Renukuntafc4bf752016-04-25 23:31:57 -07001999
2000 if (kthread_should_stop())
2001 break;
2002
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002003 schedule_timeout(difference);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004
Christoph Hellwigfe273812006-02-14 18:45:06 +01002005 if (kthread_should_stop())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 }
Mark Haverkamp2f1309802005-09-26 13:02:15 -07002008 if (dev->queues)
2009 remove_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 dev->aif_thread = 0;
Mark Haverkamp2f1309802005-09-26 13:02:15 -07002011 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012}
Mahesh Rajashekhara8b1462e2015-08-28 06:38:38 -04002013
2014int aac_acquire_irq(struct aac_dev *dev)
2015{
2016 int i;
2017 int j;
2018 int ret = 0;
2019 int cpu;
2020
2021 cpu = cpumask_first(cpu_online_mask);
2022 if (!dev->sync_mode && dev->msi_enabled && dev->max_msix > 1) {
2023 for (i = 0; i < dev->max_msix; i++) {
2024 dev->aac_msix[i].vector_no = i;
2025 dev->aac_msix[i].dev = dev;
2026 if (request_irq(dev->msixentry[i].vector,
2027 dev->a_ops.adapter_intr,
2028 0, "aacraid", &(dev->aac_msix[i]))) {
2029 printk(KERN_ERR "%s%d: Failed to register IRQ for vector %d.\n",
2030 dev->name, dev->id, i);
2031 for (j = 0 ; j < i ; j++)
2032 free_irq(dev->msixentry[j].vector,
2033 &(dev->aac_msix[j]));
2034 pci_disable_msix(dev->pdev);
2035 ret = -1;
2036 }
2037 if (irq_set_affinity_hint(dev->msixentry[i].vector,
2038 get_cpu_mask(cpu))) {
2039 printk(KERN_ERR "%s%d: Failed to set IRQ affinity for cpu %d\n",
2040 dev->name, dev->id, cpu);
2041 }
2042 cpu = cpumask_next(cpu, cpu_online_mask);
2043 }
2044 } else {
2045 dev->aac_msix[0].vector_no = 0;
2046 dev->aac_msix[0].dev = dev;
2047
2048 if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr,
2049 IRQF_SHARED, "aacraid",
2050 &(dev->aac_msix[0])) < 0) {
2051 if (dev->msi)
2052 pci_disable_msi(dev->pdev);
2053 printk(KERN_ERR "%s%d: Interrupt unavailable.\n",
2054 dev->name, dev->id);
2055 ret = -1;
2056 }
2057 }
2058 return ret;
2059}
2060
2061void aac_free_irq(struct aac_dev *dev)
2062{
2063 int i;
2064 int cpu;
2065
2066 cpu = cpumask_first(cpu_online_mask);
2067 if (dev->pdev->device == PMC_DEVICE_S6 ||
2068 dev->pdev->device == PMC_DEVICE_S7 ||
2069 dev->pdev->device == PMC_DEVICE_S8 ||
2070 dev->pdev->device == PMC_DEVICE_S9) {
2071 if (dev->max_msix > 1) {
2072 for (i = 0; i < dev->max_msix; i++) {
2073 if (irq_set_affinity_hint(
2074 dev->msixentry[i].vector, NULL)) {
2075 printk(KERN_ERR "%s%d: Failed to reset IRQ affinity for cpu %d\n",
2076 dev->name, dev->id, cpu);
2077 }
2078 cpu = cpumask_next(cpu, cpu_online_mask);
2079 free_irq(dev->msixentry[i].vector,
2080 &(dev->aac_msix[i]));
2081 }
2082 } else {
2083 free_irq(dev->pdev->irq, &(dev->aac_msix[0]));
2084 }
2085 } else {
2086 free_irq(dev->pdev->irq, dev);
2087 }
2088 if (dev->msi)
2089 pci_disable_msi(dev->pdev);
2090 else if (dev->max_msix > 1)
2091 pci_disable_msix(dev->pdev);
2092}