blob: d562053f14d736b51440ed9748fca0efa3597e7b [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.
Raghava Aditya Renukuntaf4babba2017-02-02 15:53:36 -08009 * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; see the file COPYING. If not, write to
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 * Module Name:
27 * commsup.c
28 *
29 * Abstract: Contain all routines that are required for FSA host/adapter
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070030 * communication.
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 *
32 */
33
34#include <linux/kernel.h>
35#include <linux/init.h>
36#include <linux/types.h>
37#include <linux/sched.h>
38#include <linux/pci.h>
39#include <linux/spinlock.h>
40#include <linux/slab.h>
41#include <linux/completion.h>
42#include <linux/blkdev.h>
Al Viro164006d2005-11-30 23:47:05 -050043#include <linux/delay.h>
Christoph Hellwigfe273812006-02-14 18:45:06 +010044#include <linux/kthread.h>
Al Viro6a3670c2006-09-24 23:45:29 +010045#include <linux/interrupt.h>
Matthew Wilcox6188e102008-04-18 22:21:05 -040046#include <linux/semaphore.h>
Raghava Aditya Renukunta3d77d842017-02-02 15:53:25 -080047#include <linux/bcd.h>
Mark Haverkamp8c867b22006-08-03 08:03:30 -070048#include <scsi/scsi.h>
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070049#include <scsi/scsi_host.h>
Mark Haverkamp131256c2005-09-26 13:04:56 -070050#include <scsi/scsi_device.h>
Mark Haverkamp8c867b22006-08-03 08:03:30 -070051#include <scsi/scsi_cmnd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include "aacraid.h"
54
55/**
56 * fib_map_alloc - allocate the fib objects
57 * @dev: Adapter to allocate for
58 *
59 * Allocate and map the shared PCI space for the FIB blocks used to
60 * talk to the Adaptec firmware.
61 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063static int fib_map_alloc(struct aac_dev *dev)
64{
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -080065 if (dev->max_fib_size > AAC_MAX_NATIVE_SIZE)
66 dev->max_cmd_size = AAC_MAX_NATIVE_SIZE;
67 else
68 dev->max_cmd_size = dev->max_fib_size;
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -080069 if (dev->max_fib_size < AAC_MAX_NATIVE_SIZE) {
70 dev->max_cmd_size = AAC_MAX_NATIVE_SIZE;
71 } else {
72 dev->max_cmd_size = dev->max_fib_size;
73 }
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -080074
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070075 dprintk((KERN_INFO
Mahesh Rajashekharaf4819732017-04-05 16:14:16 +053076 "allocate hardware fibs dma_alloc_coherent(%p, %d * (%d + %d), %p)\n",
77 &dev->pdev->dev, dev->max_cmd_size, dev->scsi_host_ptr->can_queue,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070078 AAC_NUM_MGT_FIB, &dev->hw_fib_pa));
Mahesh Rajashekharaf4819732017-04-05 16:14:16 +053079 dev->hw_fib_va = dma_alloc_coherent(&dev->pdev->dev,
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -080080 (dev->max_cmd_size + sizeof(struct aac_fib_xporthdr))
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -070081 * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) + (ALIGN32 - 1),
Mahesh Rajashekharaf4819732017-04-05 16:14:16 +053082 &dev->hw_fib_pa, GFP_KERNEL);
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -070083 if (dev->hw_fib_va == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 return -ENOMEM;
85 return 0;
86}
87
88/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -080089 * aac_fib_map_free - free the fib objects
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 * @dev: Adapter to free
91 *
92 * Free the PCI mappings and the memory allocated for FIB blocks
93 * on this adapter.
94 */
95
Mark Haverkampbfb35aa82006-02-01 09:30:55 -080096void aac_fib_map_free(struct aac_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
Raghava Aditya Renukunta1bff5ab2017-02-16 12:51:14 -080098 size_t alloc_size;
99 size_t fib_size;
100 int num_fibs;
101
102 if(!dev->hw_fib_va || !dev->max_cmd_size)
103 return;
104
105 num_fibs = dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB;
106 fib_size = dev->max_fib_size + sizeof(struct aac_fib_xporthdr);
107 alloc_size = fib_size * num_fibs + ALIGN32 - 1;
108
Mahesh Rajashekharaf4819732017-04-05 16:14:16 +0530109 dma_free_coherent(&dev->pdev->dev, alloc_size, dev->hw_fib_va,
110 dev->hw_fib_pa);
Raghava Aditya Renukunta1bff5ab2017-02-16 12:51:14 -0800111
Salyzyn, Mark9ad52042007-07-17 11:15:08 -0400112 dev->hw_fib_va = NULL;
113 dev->hw_fib_pa = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
Raghava Aditya Renukunta3f4ce052016-02-03 15:06:00 -0800116void aac_fib_vector_assign(struct aac_dev *dev)
117{
118 u32 i = 0;
119 u32 vector = 1;
120 struct fib *fibptr = NULL;
121
122 for (i = 0, fibptr = &dev->fibs[i];
123 i < (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB);
124 i++, fibptr++) {
125 if ((dev->max_msix == 1) ||
126 (i > ((dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB - 1)
127 - dev->vector_cap))) {
128 fibptr->vector_no = 0;
129 } else {
130 fibptr->vector_no = vector;
131 vector++;
132 if (vector == dev->max_msix)
133 vector = 1;
134 }
135 }
136}
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800139 * aac_fib_setup - setup the fibs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 * @dev: Adapter to set up
141 *
Uwe Kleine-Königb5950762010-11-01 15:38:34 -0400142 * Allocate the PCI space for the fibs, map it and then initialise the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 * fib area, the unmapped fib data and also the free list
144 */
145
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800146int aac_fib_setup(struct aac_dev * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
148 struct fib *fibptr;
Mark Haverkampa8166a52007-03-15 10:26:22 -0700149 struct hw_fib *hw_fib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 dma_addr_t hw_fib_pa;
151 int i;
Raghava Aditya Renukuntad1ef4da2017-02-02 15:53:17 -0800152 u32 max_cmds;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700153
154 while (((i = fib_map_alloc(dev)) == -ENOMEM)
155 && (dev->scsi_host_ptr->can_queue > (64 - AAC_NUM_MGT_FIB))) {
Raghava Aditya Renukuntad1ef4da2017-02-02 15:53:17 -0800156 max_cmds = (dev->scsi_host_ptr->can_queue+AAC_NUM_MGT_FIB) >> 1;
157 dev->scsi_host_ptr->can_queue = max_cmds - AAC_NUM_MGT_FIB;
158 if (dev->comm_interface != AAC_COMM_MESSAGE_TYPE3)
159 dev->init->r7.max_io_commands = cpu_to_le32(max_cmds);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700160 }
161 if (i<0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 return -ENOMEM;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800163
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700164 memset(dev->hw_fib_va, 0,
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -0800165 (dev->max_cmd_size + sizeof(struct aac_fib_xporthdr)) *
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700166 (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB));
167
Raghava Aditya Renukunta1bff5ab2017-02-16 12:51:14 -0800168 /* 32 byte alignment for PMC */
169 hw_fib_pa = (dev->hw_fib_pa + (ALIGN32 - 1)) & ~(ALIGN32 - 1);
170 hw_fib = (struct hw_fib *)((unsigned char *)dev->hw_fib_va +
171 (hw_fib_pa - dev->hw_fib_pa));
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700172
Raghava Aditya Renukunta1bff5ab2017-02-16 12:51:14 -0800173 /* add Xport header */
174 hw_fib = (struct hw_fib *)((unsigned char *)hw_fib +
175 sizeof(struct aac_fib_xporthdr));
176 hw_fib_pa += sizeof(struct aac_fib_xporthdr);
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 /*
179 * Initialise the fibs
180 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800181 for (i = 0, fibptr = &dev->fibs[i];
182 i < (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB);
183 i++, fibptr++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 {
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530185 fibptr->flags = 0;
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -0800186 fibptr->size = sizeof(struct fib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 fibptr->dev = dev;
Mark Haverkampa8166a52007-03-15 10:26:22 -0700188 fibptr->hw_fib_va = hw_fib;
189 fibptr->data = (void *) fibptr->hw_fib_va->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 fibptr->next = fibptr+1; /* Forward chain the fibs */
Thomas Gleixner6de76cf2010-09-07 14:32:47 +0000191 sema_init(&fibptr->event_wait, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 spin_lock_init(&fibptr->event_lock);
Mark Haverkampa8166a52007-03-15 10:26:22 -0700193 hw_fib->header.XferState = cpu_to_le32(0xffffffff);
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -0800194 hw_fib->header.SenderSize =
195 cpu_to_le16(dev->max_fib_size); /* ?? max_cmd_size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 fibptr->hw_fib_pa = hw_fib_pa;
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -0800197 fibptr->hw_sgl_pa = hw_fib_pa +
198 offsetof(struct aac_hba_cmd_req, sge[2]);
199 /*
200 * one element is for the ptr to the separate sg list,
201 * second element for 32 byte alignment
202 */
203 fibptr->hw_error_pa = hw_fib_pa +
204 offsetof(struct aac_native_hba, resp.resp_bytes[0]);
205
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700206 hw_fib = (struct hw_fib *)((unsigned char *)hw_fib +
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800207 dev->max_cmd_size + sizeof(struct aac_fib_xporthdr));
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700208 hw_fib_pa = hw_fib_pa +
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800209 dev->max_cmd_size + sizeof(struct aac_fib_xporthdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 }
Raghava Aditya Renukunta3f4ce052016-02-03 15:06:00 -0800211
212 /*
213 *Assign vector numbers to fibs
214 */
215 aac_fib_vector_assign(dev);
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 /*
218 * Add the fib chain to the free list
219 */
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700220 dev->fibs[dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB - 1].next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 /*
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -0800222 * Set 8 fibs aside for management tools
223 */
224 dev->free_fib = &dev->fibs[dev->scsi_host_ptr->can_queue];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 return 0;
226}
227
228/**
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -0800229 * aac_fib_alloc_tag-allocate a fib using tags
230 * @dev: Adapter to allocate the fib for
231 *
232 * Allocate a fib from the adapter fib pool using tags
233 * from the blk layer.
234 */
235
236struct fib *aac_fib_alloc_tag(struct aac_dev *dev, struct scsi_cmnd *scmd)
237{
238 struct fib *fibptr;
239
240 fibptr = &dev->fibs[scmd->request->tag];
241 /*
242 * Null out fields that depend on being zero at the start of
243 * each I/O
244 */
245 fibptr->hw_fib_va->header.XferState = 0;
246 fibptr->type = FSAFS_NTC_FIB_CONTEXT;
247 fibptr->callback_data = NULL;
248 fibptr->callback = NULL;
249
250 return fibptr;
251}
252
253/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800254 * aac_fib_alloc - allocate a fib
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 * @dev: Adapter to allocate the fib for
256 *
257 * Allocate a fib from the adapter fib pool. If the pool is empty we
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700258 * return NULL.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800260
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800261struct fib *aac_fib_alloc(struct aac_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
263 struct fib * fibptr;
264 unsigned long flags;
265 spin_lock_irqsave(&dev->fib_lock, flags);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800266 fibptr = dev->free_fib;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700267 if(!fibptr){
268 spin_unlock_irqrestore(&dev->fib_lock, flags);
269 return fibptr;
270 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 dev->free_fib = fibptr->next;
272 spin_unlock_irqrestore(&dev->fib_lock, flags);
273 /*
274 * Set the proper node type code and node byte size
275 */
276 fibptr->type = FSAFS_NTC_FIB_CONTEXT;
277 fibptr->size = sizeof(struct fib);
278 /*
279 * Null out fields that depend on being zero at the start of
280 * each I/O
281 */
Mark Haverkampa8166a52007-03-15 10:26:22 -0700282 fibptr->hw_fib_va->header.XferState = 0;
Salyzyn, Markb6ef70f2008-01-08 13:26:43 -0800283 fibptr->flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 fibptr->callback = NULL;
285 fibptr->callback_data = NULL;
286
287 return fibptr;
288}
289
290/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800291 * aac_fib_free - free a fib
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 * @fibptr: fib to free up
293 *
294 * Frees up a fib and places it on the appropriate queue
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800296
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800297void aac_fib_free(struct fib *fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400299 unsigned long flags;
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530300
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400301 if (fibptr->done == 2)
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530302 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304 spin_lock_irqsave(&fibptr->dev->fib_lock, flags);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700305 if (unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 aac_config.fib_timeouts++;
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -0800307 if (!(fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA) &&
308 fibptr->hw_fib_va->header.XferState != 0) {
Mark Haverkamp03d44332007-03-15 10:27:45 -0700309 printk(KERN_WARNING "aac_fib_free, XferState != 0, fibptr = 0x%p, XferState = 0x%x\n",
310 (void*)fibptr,
311 le32_to_cpu(fibptr->hw_fib_va->header.XferState));
312 }
313 fibptr->next = fibptr->dev->free_fib;
314 fibptr->dev->free_fib = fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 spin_unlock_irqrestore(&fibptr->dev->fib_lock, flags);
316}
317
318/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800319 * aac_fib_init - initialise a fib
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 * @fibptr: The fib to initialize
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800321 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 * Set up the generic fib fields ready for use
323 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800324
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800325void aac_fib_init(struct fib *fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
Mark Haverkampa8166a52007-03-15 10:26:22 -0700327 struct hw_fib *hw_fib = fibptr->hw_fib_va;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530329 memset(&hw_fib->header, 0, sizeof(struct aac_fibhdr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 hw_fib->header.StructType = FIB_MAGIC;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700331 hw_fib->header.Size = cpu_to_le16(fibptr->dev->max_fib_size);
332 hw_fib->header.XferState = cpu_to_le32(HostOwned | FibInitialized | FibEmpty | FastResponseCapable);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530333 hw_fib->header.u.ReceiverFibAddress = cpu_to_le32(fibptr->hw_fib_pa);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700334 hw_fib->header.SenderSize = cpu_to_le16(fibptr->dev->max_fib_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
336
337/**
338 * fib_deallocate - deallocate a fib
339 * @fibptr: fib to deallocate
340 *
341 * Will deallocate and return to the free pool the FIB pointed to by the
342 * caller.
343 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800344
Adrian Bunk 48338692005-04-25 19:45:58 -0700345static void fib_dealloc(struct fib * fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Mark Haverkampa8166a52007-03-15 10:26:22 -0700347 struct hw_fib *hw_fib = fibptr->hw_fib_va;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800348 hw_fib->header.XferState = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
351/*
352 * Commuication primitives define and support the queuing method we use to
353 * support host to adapter commuication. All queue accesses happen through
354 * these routines and are the only routines which have a knowledge of the
355 * how these queues are implemented.
356 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358/**
359 * aac_get_entry - get a queue entry
360 * @dev: Adapter
361 * @qid: Queue Number
362 * @entry: Entry return
363 * @index: Index return
364 * @nonotify: notification control
365 *
366 * With a priority the routine returns a queue entry if the queue has free entries. If the queue
367 * is full(no free entries) than no entry is returned and the function returns 0 otherwise 1 is
368 * returned.
369 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371static int aac_get_entry (struct aac_dev * dev, u32 qid, struct aac_entry **entry, u32 * index, unsigned long *nonotify)
372{
373 struct aac_queue * q;
Mark Haverkampbed30de2005-08-03 15:38:51 -0700374 unsigned long idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 /*
377 * All of the queues wrap when they reach the end, so we check
378 * to see if they have reached the end and if they have we just
379 * set the index back to zero. This is a wrap. You could or off
380 * the high bits in all updates but this is a bit faster I think.
381 */
382
383 q = &dev->queues->queue[qid];
Mark Haverkampbed30de2005-08-03 15:38:51 -0700384
385 idx = *index = le32_to_cpu(*(q->headers.producer));
386 /* Interrupt Moderation, only interrupt for first two entries */
387 if (idx != le32_to_cpu(*(q->headers.consumer))) {
388 if (--idx == 0) {
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700389 if (qid == AdapNormCmdQueue)
Mark Haverkampbed30de2005-08-03 15:38:51 -0700390 idx = ADAP_NORM_CMD_ENTRIES;
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700391 else
Mark Haverkampbed30de2005-08-03 15:38:51 -0700392 idx = ADAP_NORM_RESP_ENTRIES;
393 }
394 if (idx != le32_to_cpu(*(q->headers.consumer)))
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800395 *nonotify = 1;
Mark Haverkampbed30de2005-08-03 15:38:51 -0700396 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700398 if (qid == AdapNormCmdQueue) {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800399 if (*index >= ADAP_NORM_CMD_ENTRIES)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 *index = 0; /* Wrap to front of the Producer Queue. */
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700401 } else {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800402 if (*index >= ADAP_NORM_RESP_ENTRIES)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 *index = 0; /* Wrap to front of the Producer Queue. */
404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800406 /* Queue is full */
407 if ((*index + 1) == le32_to_cpu(*(q->headers.consumer))) {
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700408 printk(KERN_WARNING "Queue %d full, %u outstanding.\n",
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400409 qid, atomic_read(&q->numpending));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 return 0;
411 } else {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800412 *entry = q->base + *index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 return 1;
414 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800415}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417/**
418 * aac_queue_get - get the next free QE
419 * @dev: Adapter
420 * @index: Returned index
421 * @priority: Priority of fib
422 * @fib: Fib to associate with the queue entry
423 * @wait: Wait if queue full
424 * @fibptr: Driver fib object to go with fib
425 * @nonotify: Don't notify the adapter
426 *
427 * Gets the next free QE off the requested priorty adapter command
428 * queue and associates the Fib with the QE. The QE represented by
429 * index is ready to insert on the queue when this routine returns
430 * success.
431 */
432
Mark Haverkamp28713322007-01-23 14:59:20 -0800433int 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 -0700434{
435 struct aac_entry * entry = NULL;
436 int map = 0;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800437
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700438 if (qid == AdapNormCmdQueue) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 /* if no entries wait for some if caller wants to */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800440 while (!aac_get_entry(dev, qid, &entry, index, nonotify)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 printk(KERN_ERR "GetEntries failed\n");
442 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800443 /*
444 * Setup queue entry with a command, status and fib mapped
445 */
446 entry->size = cpu_to_le32(le16_to_cpu(hw_fib->header.Size));
447 map = 1;
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700448 } else {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800449 while (!aac_get_entry(dev, qid, &entry, index, nonotify)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 /* if no entries wait for some if caller wants to */
451 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800452 /*
453 * Setup queue entry with command, status and fib mapped
454 */
455 entry->size = cpu_to_le32(le16_to_cpu(hw_fib->header.Size));
456 entry->addr = hw_fib->header.SenderFibAddress;
457 /* Restore adapters pointer to the FIB */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530458 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 -0800459 map = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 }
461 /*
462 * If MapFib is true than we need to map the Fib and put pointers
463 * in the queue entry.
464 */
465 if (map)
466 entry->addr = cpu_to_le32(fibptr->hw_fib_pa);
467 return 0;
468}
469
Raghava Aditya Renukunta16ae9dd2017-02-16 12:51:12 -0800470#ifdef CONFIG_EEH
471static inline int aac_check_eeh_failure(struct aac_dev *dev)
472{
473 /* Check for an EEH failure for the given
474 * device node. Function eeh_dev_check_failure()
475 * returns 0 if there has not been an EEH error
476 * otherwise returns a non-zero value.
477 *
478 * Need to be called before any PCI operation,
479 * i.e.,before aac_adapter_check_health()
480 */
481 struct eeh_dev *edev = pci_dev_to_eeh_dev(dev->pdev);
482
483 if (eeh_dev_check_failure(edev)) {
484 /* The EEH mechanisms will handle this
485 * error and reset the device if
486 * necessary.
487 */
488 return 1;
489 }
490 return 0;
491}
492#else
493static inline int aac_check_eeh_failure(struct aac_dev *dev)
494{
495 return 0;
496}
497#endif
498
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499/*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800500 * Define the highest level of host to adapter communication routines.
501 * These routines will support host to adapter FS commuication. These
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 * routines have no knowledge of the commuication method used. This level
503 * sends and receives FIBs. This level has no knowledge of how these FIBs
504 * get passed back and forth.
505 */
506
507/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800508 * aac_fib_send - send a fib to the adapter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 * @command: Command to send
510 * @fibptr: The fib
511 * @size: Size of fib data area
512 * @priority: Priority of Fib
513 * @wait: Async/sync select
514 * @reply: True if a reply is wanted
515 * @callback: Called with reply
516 * @callback_data: Passed to callback
517 *
518 * Sends the requested FIB to the adapter and optionally will wait for a
519 * response FIB. If the caller does not wish to wait for a response than
520 * an event to wait on must be supplied. This event will be set when a
521 * response FIB is received from the adapter.
522 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800523
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800524int aac_fib_send(u16 command, struct fib *fibptr, unsigned long size,
525 int priority, int wait, int reply, fib_callback callback,
526 void *callback_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 struct aac_dev * dev = fibptr->dev;
Mark Haverkampa8166a52007-03-15 10:26:22 -0700529 struct hw_fib * hw_fib = fibptr->hw_fib_va;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 unsigned long flags = 0;
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530531 unsigned long mflags = 0;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800532 unsigned long sflags = 0;
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 if (!(hw_fib->header.XferState & cpu_to_le32(HostOwned)))
535 return -EBUSY;
Raghava Aditya Renukuntaa0c61432017-02-16 12:51:13 -0800536
537 if (hw_fib->header.XferState & cpu_to_le32(AdapterProcessed))
538 return -EINVAL;
539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300541 * There are 5 cases with the wait and response requested flags.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 * The only invalid cases are if the caller requests to wait and
543 * does not request a response and if the caller does not want a
544 * response and the Fib is not allocated from pool. If a response
545 * is not requesed the Fib will just be deallocaed by the DPC
546 * routine when the response comes back from the adapter. No
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800547 * further processing will be done besides deleting the Fib. We
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 * will have a debug mode where the adapter can notify the host
549 * it had a problem and the host can log that fact.
550 */
Salyzyn, Markb6ef70f2008-01-08 13:26:43 -0800551 fibptr->flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (wait && !reply) {
553 return -EINVAL;
554 } else if (!wait && reply) {
555 hw_fib->header.XferState |= cpu_to_le32(Async | ResponseExpected);
556 FIB_COUNTER_INCREMENT(aac_config.AsyncSent);
557 } else if (!wait && !reply) {
558 hw_fib->header.XferState |= cpu_to_le32(NoResponseExpected);
559 FIB_COUNTER_INCREMENT(aac_config.NoResponseSent);
560 } else if (wait && reply) {
561 hw_fib->header.XferState |= cpu_to_le32(ResponseExpected);
562 FIB_COUNTER_INCREMENT(aac_config.NormalSent);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 /*
565 * Map the fib into 32bits by using the fib number
566 */
567
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -0800568 hw_fib->header.SenderFibAddress =
569 cpu_to_le32(((u32)(fibptr - dev->fibs)) << 2);
570
571 /* use the same shifted value for handle to be compatible
572 * with the new native hba command handle
573 */
574 hw_fib->header.Handle =
575 cpu_to_le32((((u32)(fibptr - dev->fibs)) << 2) + 1);
576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 /*
578 * Set FIB state to indicate where it came from and if we want a
579 * response from the adapter. Also load the command from the
580 * caller.
581 *
582 * Map the hw fib pointer as a 32bit value
583 */
584 hw_fib->header.Command = cpu_to_le16(command);
585 hw_fib->header.XferState |= cpu_to_le32(SentFromHost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 /*
587 * Set the size of the Fib we want to send to the adapter
588 */
589 hw_fib->header.Size = cpu_to_le16(sizeof(struct aac_fibhdr) + size);
590 if (le16_to_cpu(hw_fib->header.Size) > le16_to_cpu(hw_fib->header.SenderSize)) {
591 return -EMSGSIZE;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800592 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 /*
594 * Get a queue entry connect the FIB to it and send an notify
595 * the adapter a command is ready.
596 */
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700597 hw_fib->header.XferState |= cpu_to_le32(NormalPriority);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 /*
600 * Fill in the Callback and CallbackContext if we are not
601 * going to wait.
602 */
603 if (!wait) {
604 fibptr->callback = callback;
605 fibptr->callback_data = callback_data;
Salyzyn, Markb6ef70f2008-01-08 13:26:43 -0800606 fibptr->flags = FIB_CONTEXT_FLAG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 fibptr->done = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700611 FIB_COUNTER_INCREMENT(aac_config.FibsSent);
612
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700613 dprintk((KERN_DEBUG "Fib contents:.\n"));
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700614 dprintk((KERN_DEBUG " Command = %d.\n", le32_to_cpu(hw_fib->header.Command)));
615 dprintk((KERN_DEBUG " SubCommand = %d.\n", le32_to_cpu(((struct aac_query_mount *)fib_data(fibptr))->command)));
616 dprintk((KERN_DEBUG " XferState = %x.\n", le32_to_cpu(hw_fib->header.XferState)));
Mark Haverkampa8166a52007-03-15 10:26:22 -0700617 dprintk((KERN_DEBUG " hw_fib va being sent=%p\n",fibptr->hw_fib_va));
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700618 dprintk((KERN_DEBUG " hw_fib pa being sent=%lx\n",(ulong)fibptr->hw_fib_pa));
619 dprintk((KERN_DEBUG " fib being sent=%p\n",fibptr));
620
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700621 if (!dev->queues)
Mark Haverkamp65101352006-09-19 08:59:23 -0700622 return -EBUSY;
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700623
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530624 if (wait) {
625
626 spin_lock_irqsave(&dev->manage_lock, mflags);
627 if (dev->management_fib_count >= AAC_NUM_MGT_FIB) {
628 printk(KERN_INFO "No management Fibs Available:%d\n",
629 dev->management_fib_count);
630 spin_unlock_irqrestore(&dev->manage_lock, mflags);
631 return -EBUSY;
632 }
633 dev->management_fib_count++;
634 spin_unlock_irqrestore(&dev->manage_lock, mflags);
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700635 spin_lock_irqsave(&fibptr->event_lock, flags);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530636 }
637
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800638 if (dev->sync_mode) {
639 if (wait)
640 spin_unlock_irqrestore(&fibptr->event_lock, flags);
641 spin_lock_irqsave(&dev->sync_lock, sflags);
642 if (dev->sync_fib) {
643 list_add_tail(&fibptr->fiblink, &dev->sync_fib_list);
644 spin_unlock_irqrestore(&dev->sync_lock, sflags);
645 } else {
646 dev->sync_fib = fibptr;
647 spin_unlock_irqrestore(&dev->sync_lock, sflags);
648 aac_adapter_sync_cmd(dev, SEND_SYNCHRONOUS_FIB,
649 (u32)fibptr->hw_fib_pa, 0, 0, 0, 0, 0,
650 NULL, NULL, NULL, NULL, NULL);
651 }
652 if (wait) {
653 fibptr->flags |= FIB_CONTEXT_FLAG_WAIT;
654 if (down_interruptible(&fibptr->event_wait)) {
655 fibptr->flags &= ~FIB_CONTEXT_FLAG_WAIT;
656 return -EFAULT;
657 }
658 return 0;
659 }
660 return -EINPROGRESS;
661 }
662
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530663 if (aac_adapter_deliver(fibptr) != 0) {
664 printk(KERN_ERR "aac_fib_send: returned -EBUSY\n");
665 if (wait) {
666 spin_unlock_irqrestore(&fibptr->event_lock, flags);
667 spin_lock_irqsave(&dev->manage_lock, mflags);
668 dev->management_fib_count--;
669 spin_unlock_irqrestore(&dev->manage_lock, mflags);
670 }
671 return -EBUSY;
672 }
673
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 /*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800676 * If the caller wanted us to wait for response wait now.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 if (wait) {
680 spin_unlock_irqrestore(&fibptr->event_lock, flags);
Mark Haverkamp92033442005-09-20 12:56:50 -0700681 /* Only set for first known interruptable command */
682 if (wait < 0) {
683 /*
684 * *VERY* Dangerous to time out a command, the
685 * assumption is made that we have no hope of
686 * functioning because an interrupt routing or other
687 * hardware failure has occurred.
688 */
Ben Collins30002f12012-06-11 14:44:44 -0400689 unsigned long timeout = jiffies + (180 * HZ); /* 3 minutes */
Mark Haverkamp92033442005-09-20 12:56:50 -0700690 while (down_trylock(&fibptr->event_wait)) {
Mark Haverkamp33524b72006-11-21 10:40:08 -0800691 int blink;
Ben Collins30002f12012-06-11 14:44:44 -0400692 if (time_is_before_eq_jiffies(timeout)) {
Mark Haverkamp28713322007-01-23 14:59:20 -0800693 struct aac_queue * q = &dev->queues->queue[AdapNormCmdQueue];
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400694 atomic_dec(&q->numpending);
Mark Haverkamp92033442005-09-20 12:56:50 -0700695 if (wait == -1) {
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800696 printk(KERN_ERR "aacraid: aac_fib_send: first asynchronous command timed out.\n"
Mark Haverkamp92033442005-09-20 12:56:50 -0700697 "Usually a result of a PCI interrupt routing problem;\n"
698 "update mother board BIOS or consider utilizing one of\n"
699 "the SAFE mode kernel options (acpi, apic etc)\n");
700 }
701 return -ETIMEDOUT;
702 }
Raghava Aditya Renukunta16ae9dd2017-02-16 12:51:12 -0800703
704 if (aac_check_eeh_failure(dev))
705 return -EFAULT;
706
Mark Haverkamp33524b72006-11-21 10:40:08 -0800707 if ((blink = aac_adapter_check_health(dev)) > 0) {
708 if (wait == -1) {
709 printk(KERN_ERR "aacraid: aac_fib_send: adapter blinkLED 0x%x.\n"
710 "Usually a result of a serious unrecoverable hardware problem\n",
711 blink);
712 }
713 return -EFAULT;
714 }
Raghava Aditya Renukunta07beca22016-04-25 23:31:26 -0700715 /*
716 * Allow other processes / CPUS to use core
717 */
718 schedule();
Mark Haverkamp92033442005-09-20 12:56:50 -0700719 }
Mark Salyzyn04625902008-04-23 08:16:06 -0400720 } else if (down_interruptible(&fibptr->event_wait)) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530721 /* Do nothing ... satisfy
722 * down_interruptible must_check */
Mark Salyzyne6990c62008-04-14 14:20:16 -0400723 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530724
Mark Haverkamp33bb3b22007-03-15 10:27:21 -0700725 spin_lock_irqsave(&fibptr->event_lock, flags);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530726 if (fibptr->done == 0) {
Mark Haverkamp33bb3b22007-03-15 10:27:21 -0700727 fibptr->done = 2; /* Tell interrupt we aborted */
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700728 spin_unlock_irqrestore(&fibptr->event_lock, flags);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530729 return -ERESTARTSYS;
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700730 }
Mark Haverkamp33bb3b22007-03-15 10:27:21 -0700731 spin_unlock_irqrestore(&fibptr->event_lock, flags);
Eric Sesterhenn125e1872006-06-23 02:06:06 -0700732 BUG_ON(fibptr->done == 0);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800733
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400734 if(unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 return -ETIMEDOUT;
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400736 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 }
738 /*
739 * If the user does not want a response than return success otherwise
740 * return pending
741 */
742 if (reply)
743 return -EINPROGRESS;
744 else
745 return 0;
746}
747
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -0800748int aac_hba_send(u8 command, struct fib *fibptr, fib_callback callback,
749 void *callback_data)
750{
751 struct aac_dev *dev = fibptr->dev;
752 int wait;
753 unsigned long flags = 0;
754 unsigned long mflags = 0;
755
756 fibptr->flags = (FIB_CONTEXT_FLAG | FIB_CONTEXT_FLAG_NATIVE_HBA);
757 if (callback) {
758 wait = 0;
759 fibptr->callback = callback;
760 fibptr->callback_data = callback_data;
761 } else
762 wait = 1;
763
764
765 if (command == HBA_IU_TYPE_SCSI_CMD_REQ) {
766 struct aac_hba_cmd_req *hbacmd =
767 (struct aac_hba_cmd_req *)fibptr->hw_fib_va;
768
769 hbacmd->iu_type = command;
770 /* bit1 of request_id must be 0 */
771 hbacmd->request_id =
772 cpu_to_le32((((u32)(fibptr - dev->fibs)) << 2) + 1);
Hannes Reineckec323eab2017-06-30 19:18:11 +0200773 fibptr->flags |= FIB_CONTEXT_FLAG_SCSI_CMD;
Hannes Reineckeb60710e2017-06-30 19:18:10 +0200774 } else if (command != HBA_IU_TYPE_SCSI_TM_REQ)
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -0800775 return -EINVAL;
776
777
778 if (wait) {
779 spin_lock_irqsave(&dev->manage_lock, mflags);
780 if (dev->management_fib_count >= AAC_NUM_MGT_FIB) {
781 spin_unlock_irqrestore(&dev->manage_lock, mflags);
782 return -EBUSY;
783 }
784 dev->management_fib_count++;
785 spin_unlock_irqrestore(&dev->manage_lock, mflags);
786 spin_lock_irqsave(&fibptr->event_lock, flags);
787 }
788
789 if (aac_adapter_deliver(fibptr) != 0) {
790 if (wait) {
791 spin_unlock_irqrestore(&fibptr->event_lock, flags);
792 spin_lock_irqsave(&dev->manage_lock, mflags);
793 dev->management_fib_count--;
794 spin_unlock_irqrestore(&dev->manage_lock, mflags);
795 }
796 return -EBUSY;
797 }
798 FIB_COUNTER_INCREMENT(aac_config.NativeSent);
799
800 if (wait) {
Raghava Aditya Renukunta16ae9dd2017-02-16 12:51:12 -0800801
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -0800802 spin_unlock_irqrestore(&fibptr->event_lock, flags);
Raghava Aditya Renukunta16ae9dd2017-02-16 12:51:12 -0800803
804 if (aac_check_eeh_failure(dev))
805 return -EFAULT;
806
Raghava Aditya Renukunta8c41b9b2017-05-10 09:39:49 -0700807 fibptr->flags |= FIB_CONTEXT_FLAG_WAIT;
808 if (down_interruptible(&fibptr->event_wait))
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -0800809 fibptr->done = 2;
Raghava Aditya Renukunta8c41b9b2017-05-10 09:39:49 -0700810 fibptr->flags &= ~(FIB_CONTEXT_FLAG_WAIT);
811
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -0800812 spin_lock_irqsave(&fibptr->event_lock, flags);
813 if ((fibptr->done == 0) || (fibptr->done == 2)) {
814 fibptr->done = 2; /* Tell interrupt we aborted */
815 spin_unlock_irqrestore(&fibptr->event_lock, flags);
816 return -ERESTARTSYS;
817 }
818 spin_unlock_irqrestore(&fibptr->event_lock, flags);
819 WARN_ON(fibptr->done == 0);
820
821 if (unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT))
822 return -ETIMEDOUT;
823
824 return 0;
825 }
826
827 return -EINPROGRESS;
828}
829
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800830/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 * aac_consumer_get - get the top of the queue
832 * @dev: Adapter
833 * @q: Queue
834 * @entry: Return entry
835 *
836 * Will return a pointer to the entry on the top of the queue requested that
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800837 * we are a consumer of, and return the address of the queue entry. It does
838 * not change the state of the queue.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 */
840
841int aac_consumer_get(struct aac_dev * dev, struct aac_queue * q, struct aac_entry **entry)
842{
843 u32 index;
844 int status;
845 if (le32_to_cpu(*q->headers.producer) == le32_to_cpu(*q->headers.consumer)) {
846 status = 0;
847 } else {
848 /*
849 * The consumer index must be wrapped if we have reached
850 * the end of the queue, else we just use the entry
851 * pointed to by the header index
852 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800853 if (le32_to_cpu(*q->headers.consumer) >= q->entries)
854 index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 else
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800856 index = le32_to_cpu(*q->headers.consumer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 *entry = q->base + index;
858 status = 1;
859 }
860 return(status);
861}
862
863/**
864 * aac_consumer_free - free consumer entry
865 * @dev: Adapter
866 * @q: Queue
867 * @qid: Queue ident
868 *
869 * Frees up the current top of the queue we are a consumer of. If the
870 * queue was full notify the producer that the queue is no longer full.
871 */
872
873void aac_consumer_free(struct aac_dev * dev, struct aac_queue *q, u32 qid)
874{
875 int wasfull = 0;
876 u32 notify;
877
878 if ((le32_to_cpu(*q->headers.producer)+1) == le32_to_cpu(*q->headers.consumer))
879 wasfull = 1;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800880
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 if (le32_to_cpu(*q->headers.consumer) >= q->entries)
882 *q->headers.consumer = cpu_to_le32(1);
883 else
Marcin Slusarz36b8dd12008-03-28 14:48:35 -0700884 le32_add_cpu(q->headers.consumer, 1);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 if (wasfull) {
887 switch (qid) {
888
889 case HostNormCmdQueue:
890 notify = HostNormCmdNotFull;
891 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 case HostNormRespQueue:
893 notify = HostNormRespNotFull;
894 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 default:
896 BUG();
897 return;
898 }
899 aac_adapter_notify(dev, notify);
900 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800901}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800904 * aac_fib_adapter_complete - complete adapter issued fib
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 * @fibptr: fib to complete
906 * @size: size of fib
907 *
908 * Will do all necessary work to complete a FIB that was sent from
909 * the adapter.
910 */
911
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800912int aac_fib_adapter_complete(struct fib *fibptr, unsigned short size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913{
Mark Haverkampa8166a52007-03-15 10:26:22 -0700914 struct hw_fib * hw_fib = fibptr->hw_fib_va;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 struct aac_dev * dev = fibptr->dev;
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700916 struct aac_queue * q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 unsigned long nointr = 0;
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700918 unsigned long qflags;
919
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530920 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
Raghava Aditya Renukuntad1ef4da2017-02-02 15:53:17 -0800921 dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
922 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) {
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700923 kfree(hw_fib);
924 return 0;
925 }
926
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700927 if (hw_fib->header.XferState == 0) {
Mark Haverkamp28713322007-01-23 14:59:20 -0800928 if (dev->comm_interface == AAC_COMM_MESSAGE)
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700929 kfree(hw_fib);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800930 return 0;
Mark Haverkamp1640a2c2005-09-20 12:57:11 -0700931 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 /*
933 * If we plan to do anything check the structure type first.
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800934 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530935 if (hw_fib->header.StructType != FIB_MAGIC &&
936 hw_fib->header.StructType != FIB_MAGIC2 &&
937 hw_fib->header.StructType != FIB_MAGIC2_64) {
Mark Haverkamp28713322007-01-23 14:59:20 -0800938 if (dev->comm_interface == AAC_COMM_MESSAGE)
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700939 kfree(hw_fib);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800940 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 }
942 /*
943 * This block handles the case where the adapter had sent us a
944 * command and we have finished processing the command. We
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800945 * call completeFib when we are done processing the command
946 * and want to send a response back to the adapter. This will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 * send the completed cdb to the adapter.
948 */
949 if (hw_fib->header.XferState & cpu_to_le32(SentFromAdapter)) {
Mark Haverkamp28713322007-01-23 14:59:20 -0800950 if (dev->comm_interface == AAC_COMM_MESSAGE) {
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700951 kfree (hw_fib);
952 } else {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800953 u32 index;
954 hw_fib->header.XferState |= cpu_to_le32(HostProcessed);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700955 if (size) {
956 size += sizeof(struct aac_fibhdr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800957 if (size > le16_to_cpu(hw_fib->header.SenderSize))
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700958 return -EMSGSIZE;
959 hw_fib->header.Size = cpu_to_le16(size);
960 }
961 q = &dev->queues->queue[AdapNormRespQueue];
962 spin_lock_irqsave(q->lock, qflags);
963 aac_queue_get(dev, &index, AdapNormRespQueue, hw_fib, 1, NULL, &nointr);
964 *(q->headers.producer) = cpu_to_le32(index + 1);
965 spin_unlock_irqrestore(q->lock, qflags);
966 if (!(nointr & (int)aac_config.irq_mod))
967 aac_adapter_notify(dev, AdapNormRespQueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800969 } else {
970 printk(KERN_WARNING "aac_fib_adapter_complete: "
971 "Unknown xferstate detected.\n");
972 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 return 0;
975}
976
977/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800978 * aac_fib_complete - fib completion handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 * @fib: FIB to complete
980 *
981 * Will do all necessary work to complete a FIB.
982 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800983
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800984int aac_fib_complete(struct fib *fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985{
Mark Haverkampa8166a52007-03-15 10:26:22 -0700986 struct hw_fib * hw_fib = fibptr->hw_fib_va;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -0800988 if (fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA) {
989 fib_dealloc(fibptr);
990 return 0;
991 }
992
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 /*
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -0800994 * Check for a fib which has already been completed or with a
995 * status wait timeout
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 */
997
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -0800998 if (hw_fib->header.XferState == 0 || fibptr->done == 2)
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800999 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 /*
1001 * If we plan to do anything check the structure type first.
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001002 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301004 if (hw_fib->header.StructType != FIB_MAGIC &&
1005 hw_fib->header.StructType != FIB_MAGIC2 &&
1006 hw_fib->header.StructType != FIB_MAGIC2_64)
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001007 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 /*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001009 * This block completes a cdb which orginated on the host and we
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 * just need to deallocate the cdb or reinit it. At this point the
1011 * command is complete that we had sent to the adapter and this
1012 * cdb could be reused.
1013 */
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301014
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 if((hw_fib->header.XferState & cpu_to_le32(SentFromHost)) &&
1016 (hw_fib->header.XferState & cpu_to_le32(AdapterProcessed)))
1017 {
1018 fib_dealloc(fibptr);
1019 }
1020 else if(hw_fib->header.XferState & cpu_to_le32(SentFromHost))
1021 {
1022 /*
1023 * This handles the case when the host has aborted the I/O
1024 * to the adapter because the adapter is not responding
1025 */
1026 fib_dealloc(fibptr);
1027 } else if(hw_fib->header.XferState & cpu_to_le32(HostOwned)) {
1028 fib_dealloc(fibptr);
1029 } else {
1030 BUG();
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001031 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 return 0;
1033}
1034
1035/**
1036 * aac_printf - handle printf from firmware
1037 * @dev: Adapter
1038 * @val: Message info
1039 *
1040 * Print a message passed to us by the controller firmware on the
1041 * Adaptec board
1042 */
1043
1044void aac_printf(struct aac_dev *dev, u32 val)
1045{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 char *cp = dev->printfbuf;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001047 if (dev->printf_enabled)
1048 {
1049 int length = val & 0xffff;
1050 int level = (val >> 16) & 0xffff;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001051
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001052 /*
1053 * The size of the printfbuf is set in port.c
1054 * There is no variable or define for it
1055 */
1056 if (length > 255)
1057 length = 255;
1058 if (cp[length] != 0)
1059 cp[length] = 0;
1060 if (level == LOG_AAC_HIGH_ERROR)
Mark Haverkamp1241f352006-03-27 09:44:23 -08001061 printk(KERN_WARNING "%s:%s", dev->name, cp);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001062 else
Mark Haverkamp1241f352006-03-27 09:44:23 -08001063 printk(KERN_INFO "%s:%s", dev->name, cp);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001064 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001065 memset(cp, 0, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066}
1067
Raghava Aditya Renukunta9cb62fa2016-04-25 23:32:09 -07001068static inline int aac_aif_data(struct aac_aifcmd *aifcmd, uint32_t index)
1069{
1070 return le32_to_cpu(((__le32 *)aifcmd->data)[index]);
1071}
1072
1073
1074static void aac_handle_aif_bu(struct aac_dev *dev, struct aac_aifcmd *aifcmd)
1075{
1076 switch (aac_aif_data(aifcmd, 1)) {
1077 case AifBuCacheDataLoss:
1078 if (aac_aif_data(aifcmd, 2))
1079 dev_info(&dev->pdev->dev, "Backup unit had cache data loss - [%d]\n",
1080 aac_aif_data(aifcmd, 2));
1081 else
1082 dev_info(&dev->pdev->dev, "Backup Unit had cache data loss\n");
1083 break;
1084 case AifBuCacheDataRecover:
1085 if (aac_aif_data(aifcmd, 2))
1086 dev_info(&dev->pdev->dev, "DDR cache data recovered successfully - [%d]\n",
1087 aac_aif_data(aifcmd, 2));
1088 else
1089 dev_info(&dev->pdev->dev, "DDR cache data recovered successfully\n");
1090 break;
1091 }
1092}
Mark Haverkamp131256c2005-09-26 13:04:56 -07001093
1094/**
1095 * aac_handle_aif - Handle a message from the firmware
1096 * @dev: Which adapter this fib is from
1097 * @fibptr: Pointer to fibptr from adapter
1098 *
1099 * This routine handles a driver notify fib from the adapter and
1100 * dispatches it to the appropriate routine for handling.
1101 */
1102
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -04001103#define AIF_SNIFF_TIMEOUT (500*HZ)
Mark Haverkamp131256c2005-09-26 13:04:56 -07001104static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
1105{
Mark Haverkampa8166a52007-03-15 10:26:22 -07001106 struct hw_fib * hw_fib = fibptr->hw_fib_va;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001107 struct aac_aifcmd * aifcmd = (struct aac_aifcmd *)hw_fib->data;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001108 u32 channel, id, lun, container;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001109 struct scsi_device *device;
1110 enum {
1111 NOTHING,
1112 DELETE,
1113 ADD,
1114 CHANGE
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001115 } device_config_needed = NOTHING;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001116
1117 /* Sniff for container changes */
1118
Mark Haverkampc8f7b072006-08-03 08:02:24 -07001119 if (!dev || !dev->fsa_dev)
Mark Haverkamp131256c2005-09-26 13:04:56 -07001120 return;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001121 container = channel = id = lun = (u32)-1;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001122
1123 /*
1124 * We have set this up to try and minimize the number of
1125 * re-configures that take place. As a result of this when
1126 * certain AIF's come in we will set a flag waiting for another
1127 * type of AIF before setting the re-config flag.
1128 */
1129 switch (le32_to_cpu(aifcmd->command)) {
1130 case AifCmdDriverNotify:
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001131 switch (le32_to_cpu(((__le32 *)aifcmd->data)[0])) {
Mahesh Rajashekharadab04b02015-03-26 10:41:31 -04001132 case AifRawDeviceRemove:
1133 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
1134 if ((container >> 28)) {
1135 container = (u32)-1;
1136 break;
1137 }
1138 channel = (container >> 24) & 0xF;
1139 if (channel >= dev->maximum_num_channels) {
1140 container = (u32)-1;
1141 break;
1142 }
1143 id = container & 0xFFFF;
1144 if (id >= dev->maximum_num_physicals) {
1145 container = (u32)-1;
1146 break;
1147 }
1148 lun = (container >> 16) & 0xFF;
1149 container = (u32)-1;
1150 channel = aac_phys_to_logical(channel);
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -08001151 device_config_needed = DELETE;
Mahesh Rajashekharadab04b02015-03-26 10:41:31 -04001152 break;
Raghava Aditya Renukunta423400e2017-02-02 15:53:29 -08001153
Mark Haverkamp131256c2005-09-26 13:04:56 -07001154 /*
1155 * Morph or Expand complete
1156 */
1157 case AifDenMorphComplete:
1158 case AifDenVolumeExtendComplete:
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001159 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
Mark Haverkamp131256c2005-09-26 13:04:56 -07001160 if (container >= dev->maximum_num_containers)
1161 break;
1162
1163 /*
Christoph Hellwigf64a1812005-10-31 18:32:08 +01001164 * Find the scsi_device associated with the SCSI
Mark Haverkamp131256c2005-09-26 13:04:56 -07001165 * address. Make sure we have the right array, and if
1166 * so set the flag to initiate a new re-config once we
1167 * see an AifEnConfigChange AIF come through.
1168 */
1169
1170 if ((dev != NULL) && (dev->scsi_host_ptr != NULL)) {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001171 device = scsi_device_lookup(dev->scsi_host_ptr,
1172 CONTAINER_TO_CHANNEL(container),
1173 CONTAINER_TO_ID(container),
Mark Haverkamp131256c2005-09-26 13:04:56 -07001174 CONTAINER_TO_LUN(container));
1175 if (device) {
1176 dev->fsa_dev[container].config_needed = CHANGE;
1177 dev->fsa_dev[container].config_waiting_on = AifEnConfigChange;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001178 dev->fsa_dev[container].config_waiting_stamp = jiffies;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001179 scsi_device_put(device);
1180 }
1181 }
1182 }
1183
1184 /*
1185 * If we are waiting on something and this happens to be
1186 * that thing then set the re-configure flag.
1187 */
1188 if (container != (u32)-1) {
1189 if (container >= dev->maximum_num_containers)
1190 break;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001191 if ((dev->fsa_dev[container].config_waiting_on ==
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001192 le32_to_cpu(*(__le32 *)aifcmd->data)) &&
Mark Haverkamp31876f32006-03-27 09:43:55 -08001193 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
Mark Haverkamp131256c2005-09-26 13:04:56 -07001194 dev->fsa_dev[container].config_waiting_on = 0;
1195 } else for (container = 0;
1196 container < dev->maximum_num_containers; ++container) {
Mark Haverkamp31876f32006-03-27 09:43:55 -08001197 if ((dev->fsa_dev[container].config_waiting_on ==
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001198 le32_to_cpu(*(__le32 *)aifcmd->data)) &&
Mark Haverkamp31876f32006-03-27 09:43:55 -08001199 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
Mark Haverkamp131256c2005-09-26 13:04:56 -07001200 dev->fsa_dev[container].config_waiting_on = 0;
1201 }
1202 break;
1203
1204 case AifCmdEventNotify:
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001205 switch (le32_to_cpu(((__le32 *)aifcmd->data)[0])) {
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001206 case AifEnBatteryEvent:
1207 dev->cache_protected =
1208 (((__le32 *)aifcmd->data)[1] == cpu_to_le32(3));
1209 break;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001210 /*
1211 * Add an Array.
1212 */
1213 case AifEnAddContainer:
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001214 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
Mark Haverkamp131256c2005-09-26 13:04:56 -07001215 if (container >= dev->maximum_num_containers)
1216 break;
1217 dev->fsa_dev[container].config_needed = ADD;
1218 dev->fsa_dev[container].config_waiting_on =
1219 AifEnConfigChange;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001220 dev->fsa_dev[container].config_waiting_stamp = jiffies;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001221 break;
1222
1223 /*
1224 * Delete an Array.
1225 */
1226 case AifEnDeleteContainer:
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001227 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
Mark Haverkamp131256c2005-09-26 13:04:56 -07001228 if (container >= dev->maximum_num_containers)
1229 break;
1230 dev->fsa_dev[container].config_needed = DELETE;
1231 dev->fsa_dev[container].config_waiting_on =
1232 AifEnConfigChange;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001233 dev->fsa_dev[container].config_waiting_stamp = jiffies;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001234 break;
1235
1236 /*
1237 * Container change detected. If we currently are not
1238 * waiting on something else, setup to wait on a Config Change.
1239 */
1240 case AifEnContainerChange:
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001241 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
Mark Haverkamp131256c2005-09-26 13:04:56 -07001242 if (container >= dev->maximum_num_containers)
1243 break;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001244 if (dev->fsa_dev[container].config_waiting_on &&
1245 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
Mark Haverkamp131256c2005-09-26 13:04:56 -07001246 break;
1247 dev->fsa_dev[container].config_needed = CHANGE;
1248 dev->fsa_dev[container].config_waiting_on =
1249 AifEnConfigChange;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001250 dev->fsa_dev[container].config_waiting_stamp = jiffies;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001251 break;
1252
1253 case AifEnConfigChange:
1254 break;
1255
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001256 case AifEnAddJBOD:
1257 case AifEnDeleteJBOD:
1258 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
Mark Salyzyna4576b52008-04-30 15:47:35 -04001259 if ((container >> 28)) {
1260 container = (u32)-1;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001261 break;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001262 }
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001263 channel = (container >> 24) & 0xF;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001264 if (channel >= dev->maximum_num_channels) {
1265 container = (u32)-1;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001266 break;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001267 }
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001268 id = container & 0xFFFF;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001269 if (id >= dev->maximum_num_physicals) {
1270 container = (u32)-1;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001271 break;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001272 }
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001273 lun = (container >> 16) & 0xFF;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001274 container = (u32)-1;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001275 channel = aac_phys_to_logical(channel);
1276 device_config_needed =
1277 (((__le32 *)aifcmd->data)[0] ==
1278 cpu_to_le32(AifEnAddJBOD)) ? ADD : DELETE;
Rajashekhara, Mahesh5ca05592010-05-10 04:05:50 -07001279 if (device_config_needed == ADD) {
1280 device = scsi_device_lookup(dev->scsi_host_ptr,
1281 channel,
1282 id,
1283 lun);
1284 if (device) {
1285 scsi_remove_device(device);
1286 scsi_device_put(device);
1287 }
1288 }
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001289 break;
1290
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001291 case AifEnEnclosureManagement:
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001292 /*
1293 * If in JBOD mode, automatic exposure of new
1294 * physical target to be suppressed until configured.
1295 */
1296 if (dev->jbod)
1297 break;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001298 switch (le32_to_cpu(((__le32 *)aifcmd->data)[3])) {
1299 case EM_DRIVE_INSERTION:
1300 case EM_DRIVE_REMOVAL:
Mahesh Rajashekhara46154a02015-03-26 10:41:22 -04001301 case EM_SES_DRIVE_INSERTION:
1302 case EM_SES_DRIVE_REMOVAL:
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001303 container = le32_to_cpu(
1304 ((__le32 *)aifcmd->data)[2]);
Mark Salyzyna4576b52008-04-30 15:47:35 -04001305 if ((container >> 28)) {
1306 container = (u32)-1;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001307 break;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001308 }
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001309 channel = (container >> 24) & 0xF;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001310 if (channel >= dev->maximum_num_channels) {
1311 container = (u32)-1;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001312 break;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001313 }
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001314 id = container & 0xFFFF;
1315 lun = (container >> 16) & 0xFF;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001316 container = (u32)-1;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001317 if (id >= dev->maximum_num_physicals) {
1318 /* legacy dev_t ? */
1319 if ((0x2000 <= id) || lun || channel ||
1320 ((channel = (id >> 7) & 0x3F) >=
1321 dev->maximum_num_channels))
1322 break;
1323 lun = (id >> 4) & 7;
1324 id &= 0xF;
1325 }
1326 channel = aac_phys_to_logical(channel);
1327 device_config_needed =
Mahesh Rajashekhara46154a02015-03-26 10:41:22 -04001328 ((((__le32 *)aifcmd->data)[3]
1329 == cpu_to_le32(EM_DRIVE_INSERTION)) ||
1330 (((__le32 *)aifcmd->data)[3]
1331 == cpu_to_le32(EM_SES_DRIVE_INSERTION))) ?
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001332 ADD : DELETE;
1333 break;
1334 }
Raghava Aditya Renukunta9cb62fa2016-04-25 23:32:09 -07001335 case AifBuManagerEvent:
1336 aac_handle_aif_bu(dev, aifcmd);
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001337 break;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001338 }
1339
1340 /*
1341 * If we are waiting on something and this happens to be
1342 * that thing then set the re-configure flag.
1343 */
1344 if (container != (u32)-1) {
1345 if (container >= dev->maximum_num_containers)
1346 break;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001347 if ((dev->fsa_dev[container].config_waiting_on ==
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001348 le32_to_cpu(*(__le32 *)aifcmd->data)) &&
Mark Haverkamp31876f32006-03-27 09:43:55 -08001349 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
Mark Haverkamp131256c2005-09-26 13:04:56 -07001350 dev->fsa_dev[container].config_waiting_on = 0;
1351 } else for (container = 0;
1352 container < dev->maximum_num_containers; ++container) {
Mark Haverkamp31876f32006-03-27 09:43:55 -08001353 if ((dev->fsa_dev[container].config_waiting_on ==
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001354 le32_to_cpu(*(__le32 *)aifcmd->data)) &&
Mark Haverkamp31876f32006-03-27 09:43:55 -08001355 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
Mark Haverkamp131256c2005-09-26 13:04:56 -07001356 dev->fsa_dev[container].config_waiting_on = 0;
1357 }
1358 break;
1359
1360 case AifCmdJobProgress:
1361 /*
1362 * These are job progress AIF's. When a Clear is being
1363 * done on a container it is initially created then hidden from
1364 * the OS. When the clear completes we don't get a config
1365 * change so we monitor the job status complete on a clear then
1366 * wait for a container change.
1367 */
1368
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001369 if (((__le32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero) &&
1370 (((__le32 *)aifcmd->data)[6] == ((__le32 *)aifcmd->data)[5] ||
1371 ((__le32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsSuccess))) {
Mark Haverkamp131256c2005-09-26 13:04:56 -07001372 for (container = 0;
1373 container < dev->maximum_num_containers;
1374 ++container) {
1375 /*
1376 * Stomp on all config sequencing for all
1377 * containers?
1378 */
1379 dev->fsa_dev[container].config_waiting_on =
1380 AifEnContainerChange;
1381 dev->fsa_dev[container].config_needed = ADD;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001382 dev->fsa_dev[container].config_waiting_stamp =
1383 jiffies;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001384 }
1385 }
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001386 if (((__le32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero) &&
1387 ((__le32 *)aifcmd->data)[6] == 0 &&
1388 ((__le32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsRunning)) {
Mark Haverkamp131256c2005-09-26 13:04:56 -07001389 for (container = 0;
1390 container < dev->maximum_num_containers;
1391 ++container) {
1392 /*
1393 * Stomp on all config sequencing for all
1394 * containers?
1395 */
1396 dev->fsa_dev[container].config_waiting_on =
1397 AifEnContainerChange;
1398 dev->fsa_dev[container].config_needed = DELETE;
Mark Haverkamp31876f32006-03-27 09:43:55 -08001399 dev->fsa_dev[container].config_waiting_stamp =
1400 jiffies;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001401 }
1402 }
1403 break;
1404 }
1405
Mark Salyzyna4576b52008-04-30 15:47:35 -04001406 container = 0;
1407retry_next:
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001408 if (device_config_needed == NOTHING)
Mark Salyzyna4576b52008-04-30 15:47:35 -04001409 for (; container < dev->maximum_num_containers; ++container) {
Mark Haverkamp31876f32006-03-27 09:43:55 -08001410 if ((dev->fsa_dev[container].config_waiting_on == 0) &&
1411 (dev->fsa_dev[container].config_needed != NOTHING) &&
1412 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) {
Mark Haverkamp131256c2005-09-26 13:04:56 -07001413 device_config_needed =
1414 dev->fsa_dev[container].config_needed;
1415 dev->fsa_dev[container].config_needed = NOTHING;
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001416 channel = CONTAINER_TO_CHANNEL(container);
1417 id = CONTAINER_TO_ID(container);
1418 lun = CONTAINER_TO_LUN(container);
Mark Haverkamp131256c2005-09-26 13:04:56 -07001419 break;
1420 }
1421 }
1422 if (device_config_needed == NOTHING)
1423 return;
1424
1425 /*
1426 * If we decided that a re-configuration needs to be done,
1427 * schedule it here on the way out the door, please close the door
1428 * behind you.
1429 */
1430
Mark Haverkamp131256c2005-09-26 13:04:56 -07001431 /*
Christoph Hellwigf64a1812005-10-31 18:32:08 +01001432 * Find the scsi_device associated with the SCSI address,
Mark Haverkamp131256c2005-09-26 13:04:56 -07001433 * and mark it as changed, invalidating the cache. This deals
1434 * with changes to existing device IDs.
1435 */
1436
1437 if (!dev || !dev->scsi_host_ptr)
1438 return;
1439 /*
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001440 * force reload of disk info via aac_probe_container
Mark Haverkamp131256c2005-09-26 13:04:56 -07001441 */
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001442 if ((channel == CONTAINER_CHANNEL) &&
1443 (device_config_needed != NOTHING)) {
1444 if (dev->fsa_dev[container].valid == 1)
1445 dev->fsa_dev[container].valid = 2;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001446 aac_probe_container(dev, container);
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001447 }
1448 device = scsi_device_lookup(dev->scsi_host_ptr, channel, id, lun);
Mark Haverkamp131256c2005-09-26 13:04:56 -07001449 if (device) {
1450 switch (device_config_needed) {
1451 case DELETE:
Rajashekhara, Mahesh9cccde92010-05-10 04:29:25 -07001452#if (defined(AAC_DEBUG_INSTRUMENT_AIF_DELETE))
1453 scsi_remove_device(device);
1454#else
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001455 if (scsi_device_online(device)) {
1456 scsi_device_set_state(device, SDEV_OFFLINE);
1457 sdev_printk(KERN_INFO, device,
1458 "Device offlined - %s\n",
1459 (channel == CONTAINER_CHANNEL) ?
1460 "array deleted" :
1461 "enclosure services event");
1462 }
Rajashekhara, Mahesh9cccde92010-05-10 04:29:25 -07001463#endif
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001464 break;
1465 case ADD:
1466 if (!scsi_device_online(device)) {
1467 sdev_printk(KERN_INFO, device,
1468 "Device online - %s\n",
1469 (channel == CONTAINER_CHANNEL) ?
1470 "array created" :
1471 "enclosure services event");
1472 scsi_device_set_state(device, SDEV_RUNNING);
1473 }
1474 /* FALLTHRU */
Mark Haverkamp131256c2005-09-26 13:04:56 -07001475 case CHANGE:
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001476 if ((channel == CONTAINER_CHANNEL)
1477 && (!dev->fsa_dev[container].valid)) {
Rajashekhara, Mahesh9cccde92010-05-10 04:29:25 -07001478#if (defined(AAC_DEBUG_INSTRUMENT_AIF_DELETE))
1479 scsi_remove_device(device);
1480#else
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001481 if (!scsi_device_online(device))
1482 break;
1483 scsi_device_set_state(device, SDEV_OFFLINE);
1484 sdev_printk(KERN_INFO, device,
1485 "Device offlined - %s\n",
1486 "array failed");
Rajashekhara, Mahesh9cccde92010-05-10 04:29:25 -07001487#endif
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001488 break;
1489 }
Mark Haverkamp131256c2005-09-26 13:04:56 -07001490 scsi_rescan_device(&device->sdev_gendev);
1491
1492 default:
1493 break;
1494 }
1495 scsi_device_put(device);
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001496 device_config_needed = NOTHING;
Mark Haverkamp131256c2005-09-26 13:04:56 -07001497 }
Salyzyn, Mark0995ad32008-01-11 11:56:07 -08001498 if (device_config_needed == ADD)
1499 scsi_add_device(dev->scsi_host_ptr, channel, id, lun);
Mark Salyzyna4576b52008-04-30 15:47:35 -04001500 if (channel == CONTAINER_CHANNEL) {
1501 container++;
1502 device_config_needed = NOTHING;
1503 goto retry_next;
1504 }
Mark Haverkamp131256c2005-09-26 13:04:56 -07001505}
1506
Raghava Aditya Renukunta31364322017-02-02 15:53:33 -08001507static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001508{
1509 int index, quirks;
Mahesh Rajashekhara8b1462e2015-08-28 06:38:38 -04001510 int retval;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001511 struct Scsi_Host *host;
1512 struct scsi_device *dev;
1513 struct scsi_cmnd *command;
1514 struct scsi_cmnd *command_list;
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001515 int jafo = 0;
Raghava Aditya Renukunta31364322017-02-02 15:53:33 -08001516 int bled;
Raghava Aditya Renukunta8105d392017-05-10 09:39:36 -07001517 u64 dmamask;
Raghava Aditya Renukunta8c41b9b2017-05-10 09:39:49 -07001518 int num_of_fibs = 0;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001519
1520 /*
1521 * Assumptions:
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001522 * - host is locked, unless called by the aacraid thread.
1523 * (a matter of convenience, due to legacy issues surrounding
1524 * eh_host_adapter_reset).
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001525 * - in_reset is asserted, so no new i/o is getting to the
1526 * card.
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001527 * - The card is dead, or will be very shortly ;-/ so no new
1528 * commands are completing in the interrupt service.
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001529 */
1530 host = aac->scsi_host_ptr;
1531 scsi_block_requests(host);
1532 aac_adapter_disable_int(aac);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001533 if (aac->thread->pid != current->pid) {
1534 spin_unlock_irq(host->host_lock);
1535 kthread_stop(aac->thread);
1536 jafo = 1;
1537 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001538
1539 /*
1540 * If a positive health, means in a known DEAD PANIC
1541 * state and the adapter could be reset to `try again'.
1542 */
Raghava Aditya Renukunta31364322017-02-02 15:53:33 -08001543 bled = forced ? 0 : aac_adapter_check_health(aac);
1544 retval = aac_adapter_restart(aac, bled, reset_type);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001545
1546 if (retval)
1547 goto out;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001548
Mark Haverkampd18b4482006-11-21 10:40:31 -08001549 /*
1550 * Loop through the fibs, close the synchronous FIBS
1551 */
Raghava Aditya Renukunta8c41b9b2017-05-10 09:39:49 -07001552 retval = 1;
1553 num_of_fibs = aac->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB;
1554 for (index = 0; index < num_of_fibs; index++) {
1555
Mark Haverkampd18b4482006-11-21 10:40:31 -08001556 struct fib *fib = &aac->fibs[index];
Raghava Aditya Renukunta8c41b9b2017-05-10 09:39:49 -07001557 __le32 XferState = fib->hw_fib_va->header.XferState;
1558 bool is_response_expected = false;
1559
1560 if (!(XferState & cpu_to_le32(NoResponseExpected | Async)) &&
1561 (XferState & cpu_to_le32(ResponseExpected)))
1562 is_response_expected = true;
1563
1564 if (is_response_expected
1565 || fib->flags & FIB_CONTEXT_FLAG_WAIT) {
Mark Haverkampd18b4482006-11-21 10:40:31 -08001566 unsigned long flagv;
1567 spin_lock_irqsave(&fib->event_lock, flagv);
1568 up(&fib->event_wait);
1569 spin_unlock_irqrestore(&fib->event_lock, flagv);
1570 schedule();
Mark Haverkamp33bb3b22007-03-15 10:27:21 -07001571 retval = 0;
Mark Haverkampd18b4482006-11-21 10:40:31 -08001572 }
1573 }
Mark Haverkamp33bb3b22007-03-15 10:27:21 -07001574 /* Give some extra time for ioctls to complete. */
1575 if (retval == 0)
1576 ssleep(2);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001577 index = aac->cardtype;
1578
1579 /*
1580 * Re-initialize the adapter, first free resources, then carefully
1581 * apply the initialization sequence to come back again. Only risk
1582 * is a change in Firmware dropping cache, it is assumed the caller
1583 * will ensure that i/o is queisced and the card is flushed in that
1584 * case.
1585 */
1586 aac_fib_map_free(aac);
Mahesh Rajashekharaf4819732017-04-05 16:14:16 +05301587 dma_free_coherent(&aac->pdev->dev, aac->comm_size, aac->comm_addr,
1588 aac->comm_phys);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001589 aac->comm_addr = NULL;
1590 aac->comm_phys = 0;
1591 kfree(aac->queues);
1592 aac->queues = NULL;
Mahesh Rajashekhara8b1462e2015-08-28 06:38:38 -04001593 aac_free_irq(aac);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001594 kfree(aac->fsa_dev);
1595 aac->fsa_dev = NULL;
Raghava Aditya Renukunta8105d392017-05-10 09:39:36 -07001596
1597 dmamask = DMA_BIT_MASK(32);
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001598 quirks = aac_get_driver_ident(index)->quirks;
Raghava Aditya Renukunta8105d392017-05-10 09:39:36 -07001599 if (quirks & AAC_QUIRK_31BIT)
1600 retval = pci_set_dma_mask(aac->pdev, dmamask);
1601 else if (!(quirks & AAC_QUIRK_SRC))
1602 retval = pci_set_dma_mask(aac->pdev, dmamask);
1603 else
1604 retval = pci_set_consistent_dma_mask(aac->pdev, dmamask);
1605
1606 if (quirks & AAC_QUIRK_31BIT && !retval) {
1607 dmamask = DMA_BIT_MASK(31);
1608 retval = pci_set_consistent_dma_mask(aac->pdev, dmamask);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001609 }
Raghava Aditya Renukunta8105d392017-05-10 09:39:36 -07001610
1611 if (retval)
1612 goto out;
1613
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001614 if ((retval = (*(aac_get_driver_ident(index)->init))(aac)))
1615 goto out;
Raghava Aditya Renukunta8105d392017-05-10 09:39:36 -07001616
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001617 if (jafo) {
Kees Cookf1701682013-07-03 15:04:58 -07001618 aac->thread = kthread_run(aac_command_thread, aac, "%s",
1619 aac->name);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001620 if (IS_ERR(aac->thread)) {
1621 retval = PTR_ERR(aac->thread);
1622 goto out;
1623 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001624 }
1625 (void)aac_get_adapter_info(aac);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001626 if ((quirks & AAC_QUIRK_34SG) && (host->sg_tablesize > 34)) {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001627 host->sg_tablesize = 34;
1628 host->max_sectors = (host->sg_tablesize * 8) + 112;
1629 }
1630 if ((quirks & AAC_QUIRK_17SG) && (host->sg_tablesize > 17)) {
1631 host->sg_tablesize = 17;
1632 host->max_sectors = (host->sg_tablesize * 8) + 112;
1633 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001634 aac_get_config_status(aac, 1);
1635 aac_get_containers(aac);
1636 /*
1637 * This is where the assumption that the Adapter is quiesced
1638 * is important.
1639 */
1640 command_list = NULL;
1641 __shost_for_each_device(dev, host) {
1642 unsigned long flags;
1643 spin_lock_irqsave(&dev->list_lock, flags);
1644 list_for_each_entry(command, &dev->cmd_list, list)
1645 if (command->SCp.phase == AAC_OWNER_FIRMWARE) {
1646 command->SCp.buffer = (struct scatterlist *)command_list;
1647 command_list = command;
1648 }
1649 spin_unlock_irqrestore(&dev->list_lock, flags);
1650 }
1651 while ((command = command_list)) {
1652 command_list = (struct scsi_cmnd *)command->SCp.buffer;
1653 command->SCp.buffer = NULL;
1654 command->result = DID_OK << 16
1655 | COMMAND_COMPLETE << 8
1656 | SAM_STAT_TASK_SET_FULL;
1657 command->SCp.phase = AAC_OWNER_ERROR_HANDLER;
1658 command->scsi_done(command);
1659 }
Raghava Aditya Renukuntaa2d03212017-02-16 12:51:18 -08001660 /*
Raghava Aditya Renukunta95900622017-12-26 20:34:25 -08001661 * Any Device that was already marked offline needs to be marked
1662 * running
Raghava Aditya Renukuntaa2d03212017-02-16 12:51:18 -08001663 */
1664 __shost_for_each_device(dev, host) {
Raghava Aditya Renukunta95900622017-12-26 20:34:25 -08001665 if (!scsi_device_online(dev))
1666 scsi_device_set_state(dev, SDEV_RUNNING);
Raghava Aditya Renukuntaa2d03212017-02-16 12:51:18 -08001667 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001668 retval = 0;
1669
1670out:
1671 aac->in_reset = 0;
1672 scsi_unblock_requests(host);
Raghava Aditya Renukuntac5313ae2017-12-26 20:34:24 -08001673
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001674 if (jafo) {
1675 spin_lock_irq(host->host_lock);
1676 }
1677 return retval;
1678}
1679
Raghava Aditya Renukunta31364322017-02-02 15:53:33 -08001680int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001681{
1682 unsigned long flagv = 0;
1683 int retval;
1684 struct Scsi_Host * host;
Raghava Aditya Renukunta31364322017-02-02 15:53:33 -08001685 int bled;
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001686
1687 if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0)
1688 return -EBUSY;
1689
1690 if (aac->in_reset) {
1691 spin_unlock_irqrestore(&aac->fib_lock, flagv);
1692 return -EBUSY;
1693 }
1694 aac->in_reset = 1;
1695 spin_unlock_irqrestore(&aac->fib_lock, flagv);
1696
1697 /*
1698 * Wait for all commands to complete to this specific
1699 * target (block maximum 60 seconds). Although not necessary,
1700 * it does make us a good storage citizen.
1701 */
1702 host = aac->scsi_host_ptr;
1703 scsi_block_requests(host);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001704
1705 /* Quiesce build, flush cache, write through mode */
Salyzyn, Markf8583172007-10-30 15:50:49 -04001706 if (forced < 2)
1707 aac_send_shutdown(aac);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001708 spin_lock_irqsave(host->host_lock, flagv);
Raghava Aditya Renukunta31364322017-02-02 15:53:33 -08001709 bled = forced ? forced :
1710 (aac_check_reset != 0 && aac_check_reset != 1);
1711 retval = _aac_reset_adapter(aac, bled, reset_type);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001712 spin_unlock_irqrestore(host->host_lock, flagv);
1713
Salyzyn, Markf8583172007-10-30 15:50:49 -04001714 if ((forced < 2) && (retval == -ENODEV)) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001715 /* Unwind aac_send_shutdown() IOP_RESET unsupported/disabled */
1716 struct fib * fibctx = aac_fib_alloc(aac);
1717 if (fibctx) {
1718 struct aac_pause *cmd;
1719 int status;
1720
1721 aac_fib_init(fibctx);
1722
1723 cmd = (struct aac_pause *) fib_data(fibctx);
1724
1725 cmd->command = cpu_to_le32(VM_ContainerConfig);
1726 cmd->type = cpu_to_le32(CT_PAUSE_IO);
1727 cmd->timeout = cpu_to_le32(1);
1728 cmd->min = cpu_to_le32(1);
1729 cmd->noRescan = cpu_to_le32(1);
1730 cmd->count = cpu_to_le32(0);
1731
1732 status = aac_fib_send(ContainerCommand,
1733 fibctx,
1734 sizeof(struct aac_pause),
1735 FsaNormal,
1736 -2 /* Timeout silently */, 1,
1737 NULL, NULL);
1738
1739 if (status >= 0)
1740 aac_fib_complete(fibctx);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301741 /* FIB should be freed only after getting
1742 * the response from the F/W */
1743 if (status != -ERESTARTSYS)
1744 aac_fib_free(fibctx);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001745 }
1746 }
1747
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001748 return retval;
1749}
1750
1751int aac_check_health(struct aac_dev * aac)
1752{
1753 int BlinkLED;
1754 unsigned long time_now, flagv = 0;
1755 struct list_head * entry;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001756
1757 /* Extending the scope of fib_lock slightly to protect aac->in_reset */
1758 if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0)
1759 return 0;
1760
1761 if (aac->in_reset || !(BlinkLED = aac_adapter_check_health(aac))) {
1762 spin_unlock_irqrestore(&aac->fib_lock, flagv);
1763 return 0; /* OK */
1764 }
1765
1766 aac->in_reset = 1;
1767
1768 /* Fake up an AIF:
1769 * aac_aifcmd.command = AifCmdEventNotify = 1
1770 * aac_aifcmd.seqnum = 0xFFFFFFFF
1771 * aac_aifcmd.data[0] = AifEnExpEvent = 23
1772 * aac_aifcmd.data[1] = AifExeFirmwarePanic = 3
1773 * aac.aifcmd.data[2] = AifHighPriority = 3
1774 * aac.aifcmd.data[3] = BlinkLED
1775 */
1776
1777 time_now = jiffies/HZ;
1778 entry = aac->fib_list.next;
1779
1780 /*
1781 * For each Context that is on the
1782 * fibctxList, make a copy of the
1783 * fib, and then set the event to wake up the
1784 * thread that is waiting for it.
1785 */
1786 while (entry != &aac->fib_list) {
1787 /*
1788 * Extract the fibctx
1789 */
1790 struct aac_fib_context *fibctx = list_entry(entry, struct aac_fib_context, next);
1791 struct hw_fib * hw_fib;
1792 struct fib * fib;
1793 /*
1794 * Check if the queue is getting
1795 * backlogged
1796 */
1797 if (fibctx->count > 20) {
1798 /*
1799 * It's *not* jiffies folks,
1800 * but jiffies / HZ, so do not
1801 * panic ...
1802 */
1803 u32 time_last = fibctx->jiffies;
1804 /*
1805 * Has it been > 2 minutes
1806 * since the last read off
1807 * the queue?
1808 */
1809 if ((time_now - time_last) > aif_timeout) {
1810 entry = entry->next;
1811 aac_close_fib_context(aac, fibctx);
1812 continue;
1813 }
1814 }
1815 /*
1816 * Warning: no sleep allowed while
1817 * holding spinlock
1818 */
Salyzyn, Mark4dbc22d2007-04-16 11:21:50 -04001819 hw_fib = kzalloc(sizeof(struct hw_fib), GFP_ATOMIC);
1820 fib = kzalloc(sizeof(struct fib), GFP_ATOMIC);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001821 if (fib && hw_fib) {
1822 struct aac_aifcmd * aif;
1823
Mark Haverkampa8166a52007-03-15 10:26:22 -07001824 fib->hw_fib_va = hw_fib;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001825 fib->dev = aac;
1826 aac_fib_init(fib);
1827 fib->type = FSAFS_NTC_FIB_CONTEXT;
1828 fib->size = sizeof (struct fib);
1829 fib->data = hw_fib->data;
1830 aif = (struct aac_aifcmd *)hw_fib->data;
1831 aif->command = cpu_to_le32(AifCmdEventNotify);
Salyzyn, Marka3940da2008-01-08 12:48:25 -08001832 aif->seqnum = cpu_to_le32(0xFFFFFFFF);
1833 ((__le32 *)aif->data)[0] = cpu_to_le32(AifEnExpEvent);
1834 ((__le32 *)aif->data)[1] = cpu_to_le32(AifExeFirmwarePanic);
1835 ((__le32 *)aif->data)[2] = cpu_to_le32(AifHighPriority);
1836 ((__le32 *)aif->data)[3] = cpu_to_le32(BlinkLED);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001837
1838 /*
1839 * Put the FIB onto the
1840 * fibctx's fibs
1841 */
1842 list_add_tail(&fib->fiblink, &fibctx->fib_list);
1843 fibctx->count++;
1844 /*
1845 * Set the event to wake up the
1846 * thread that will waiting.
1847 */
1848 up(&fibctx->wait_sem);
1849 } else {
1850 printk(KERN_WARNING "aifd: didn't allocate NewFib.\n");
1851 kfree(fib);
1852 kfree(hw_fib);
1853 }
1854 entry = entry->next;
1855 }
1856
1857 spin_unlock_irqrestore(&aac->fib_lock, flagv);
1858
1859 if (BlinkLED < 0) {
Guilherme G. Piccoli911e5722017-04-06 18:12:09 -03001860 printk(KERN_ERR "%s: Host adapter is dead (or got a PCI error) %d\n",
1861 aac->name, BlinkLED);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001862 goto out;
1863 }
1864
1865 printk(KERN_ERR "%s: Host adapter BLINK LED 0x%x\n", aac->name, BlinkLED);
1866
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001867out:
1868 aac->in_reset = 0;
1869 return BlinkLED;
1870}
1871
Raghava Aditya Renukuntaf2d2cab2017-12-26 20:34:40 -08001872static inline int is_safw_raid_volume(struct aac_dev *aac, int bus, int target)
1873{
1874 return bus == CONTAINER_CHANNEL && target < aac->maximum_num_containers;
1875}
1876
Raghava Aditya Renukunta3031c652017-12-26 20:34:42 -08001877static struct scsi_device *aac_lookup_safw_scsi_device(struct aac_dev *dev,
1878 int bus,
1879 int target)
1880{
1881 if (bus != CONTAINER_CHANNEL)
1882 bus = aac_phys_to_logical(bus);
1883
1884 return scsi_device_lookup(dev->scsi_host_ptr, bus, target, 0);
1885}
1886
1887static int aac_add_safw_device(struct aac_dev *dev, int bus, int target)
1888{
1889 if (bus != CONTAINER_CHANNEL)
1890 bus = aac_phys_to_logical(bus);
1891
1892 return scsi_add_device(dev->scsi_host_ptr, bus, target, 0);
1893}
1894
1895static void aac_put_safw_scsi_device(struct scsi_device *sdev)
1896{
1897 if (sdev)
1898 scsi_device_put(sdev);
1899}
1900
1901static void aac_remove_safw_device(struct aac_dev *dev, int bus, int target)
1902{
1903 struct scsi_device *sdev;
1904
1905 sdev = aac_lookup_safw_scsi_device(dev, bus, target);
1906 scsi_remove_device(sdev);
1907 aac_put_safw_scsi_device(sdev);
1908}
1909
Raghava Aditya Renukuntaf2d2cab2017-12-26 20:34:40 -08001910static inline int aac_is_safw_scan_count_equal(struct aac_dev *dev,
1911 int bus, int target)
1912{
1913 return dev->hba_map[bus][target].scan_counter == dev->scan_counter;
1914}
1915
1916static int aac_is_safw_target_valid(struct aac_dev *dev, int bus, int target)
1917{
1918 if (is_safw_raid_volume(dev, bus, target))
1919 return dev->fsa_dev[target].valid;
1920 else
1921 return aac_is_safw_scan_count_equal(dev, bus, target);
1922}
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08001923
Raghava Aditya Renukunta3031c652017-12-26 20:34:42 -08001924static int aac_is_safw_device_exposed(struct aac_dev *dev, int bus, int target)
1925{
1926 int is_exposed = 0;
1927 struct scsi_device *sdev;
1928
1929 sdev = aac_lookup_safw_scsi_device(dev, bus, target);
1930 if (sdev)
1931 is_exposed = 1;
1932 aac_put_safw_scsi_device(sdev);
1933
1934 return is_exposed;
1935}
1936
Raghava Aditya Renukunta6f44a222017-12-26 20:34:43 -08001937static int aac_update_safw_host_devices(struct aac_dev *dev, int rescan)
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08001938{
Raghava Aditya Renukunta22906782017-12-26 20:34:41 -08001939 int i;
Raghava Aditya Renukunta6f44a222017-12-26 20:34:43 -08001940 int bus;
1941 int target;
Raghava Aditya Renukunta3031c652017-12-26 20:34:42 -08001942 int is_exposed = 0;
Raghava Aditya Renukunta6f44a222017-12-26 20:34:43 -08001943 int rcode = 0;
1944
1945 rcode = aac_setup_safw_adapter(dev, rescan);
1946 if (unlikely(rcode < 0)) {
1947 goto out;
1948 }
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08001949
Raghava Aditya Renukunta22906782017-12-26 20:34:41 -08001950 for (i = 0; i < AAC_BUS_TARGET_LOOP; i++) {
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08001951
Raghava Aditya Renukunta22906782017-12-26 20:34:41 -08001952 bus = get_bus_number(i);
1953 target = get_target_number(i);
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08001954
Raghava Aditya Renukunta3031c652017-12-26 20:34:42 -08001955 is_exposed = aac_is_safw_device_exposed(dev, bus, target);
Raghava Aditya Renukunta22906782017-12-26 20:34:41 -08001956
Raghava Aditya Renukunta3031c652017-12-26 20:34:42 -08001957 if (aac_is_safw_target_valid(dev, bus, target) && !is_exposed)
1958 aac_add_safw_device(dev, bus, target);
1959 else if (!aac_is_safw_target_valid(dev, bus, target) &&
1960 is_exposed)
1961 aac_remove_safw_device(dev, bus, target);
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08001962 }
Raghava Aditya Renukunta6f44a222017-12-26 20:34:43 -08001963out:
1964 return rcode;
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08001965}
1966
Raghava Aditya Renukuntaa1367e42017-12-26 20:34:46 -08001967static int aac_scan_safw_host(struct aac_dev *dev, int rescan)
1968{
1969 int rcode = 0;
1970
1971 rcode = aac_update_safw_host_devices(dev, rescan);
1972 if (rcode)
1973 aac_schedule_safw_scan_worker(dev);
1974
1975 return rcode;
1976}
1977
Raghava Aditya Renukunta8ebaa672017-12-26 20:34:45 -08001978int aac_scan_host(struct aac_dev *dev, int rescan)
1979{
1980 int rcode = 0;
1981
1982 mutex_lock(&dev->scan_mutex);
1983 if (dev->sa_firmware)
Raghava Aditya Renukuntaa1367e42017-12-26 20:34:46 -08001984 rcode = aac_scan_safw_host(dev, rescan);
Raghava Aditya Renukunta8ebaa672017-12-26 20:34:45 -08001985 else
1986 scsi_scan_host(dev->scsi_host_ptr);
1987 mutex_unlock(&dev->scan_mutex);
Raghava Aditya Renukuntaa1367e42017-12-26 20:34:46 -08001988
Raghava Aditya Renukunta8ebaa672017-12-26 20:34:45 -08001989 return rcode;
1990}
1991
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08001992/**
1993 * aac_handle_sa_aif Handle a message from the firmware
1994 * @dev: Which adapter this fib is from
1995 * @fibptr: Pointer to fibptr from adapter
1996 *
1997 * This routine handles a driver notify fib from the adapter and
1998 * dispatches it to the appropriate routine for handling.
1999 */
2000static void aac_handle_sa_aif(struct aac_dev *dev, struct fib *fibptr)
2001{
Raghava Aditya Renukuntaf2d2cab2017-12-26 20:34:40 -08002002 int i;
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08002003 u32 events = 0;
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08002004
2005 if (fibptr->hbacmd_size & SA_AIF_HOTPLUG)
2006 events = SA_AIF_HOTPLUG;
2007 else if (fibptr->hbacmd_size & SA_AIF_HARDWARE)
2008 events = SA_AIF_HARDWARE;
2009 else if (fibptr->hbacmd_size & SA_AIF_PDEV_CHANGE)
2010 events = SA_AIF_PDEV_CHANGE;
2011 else if (fibptr->hbacmd_size & SA_AIF_LDEV_CHANGE)
2012 events = SA_AIF_LDEV_CHANGE;
2013 else if (fibptr->hbacmd_size & SA_AIF_BPSTAT_CHANGE)
2014 events = SA_AIF_BPSTAT_CHANGE;
2015 else if (fibptr->hbacmd_size & SA_AIF_BPCFG_CHANGE)
2016 events = SA_AIF_BPCFG_CHANGE;
2017
2018 switch (events) {
2019 case SA_AIF_HOTPLUG:
2020 case SA_AIF_HARDWARE:
2021 case SA_AIF_PDEV_CHANGE:
2022 case SA_AIF_LDEV_CHANGE:
2023 case SA_AIF_BPCFG_CHANGE:
2024
Raghava Aditya Renukunta8ebaa672017-12-26 20:34:45 -08002025 aac_scan_host(dev, AAC_RESCAN);
2026
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08002027 break;
2028
2029 case SA_AIF_BPSTAT_CHANGE:
2030 /* currently do nothing */
2031 break;
2032 }
2033
2034 for (i = 1; i <= 10; ++i) {
2035 events = src_readl(dev, MUnit.IDR);
2036 if (events & (1<<23)) {
2037 pr_warn(" AIF not cleared by firmware - %d/%d)\n",
2038 i, 10);
2039 ssleep(1);
2040 }
2041 }
2042}
2043
Raghava Aditya Renukunta113156b2017-02-02 15:53:24 -08002044static int get_fib_count(struct aac_dev *dev)
2045{
2046 unsigned int num = 0;
2047 struct list_head *entry;
2048 unsigned long flagv;
2049
2050 /*
2051 * Warning: no sleep allowed while
2052 * holding spinlock. We take the estimate
2053 * and pre-allocate a set of fibs outside the
2054 * lock.
2055 */
2056 num = le32_to_cpu(dev->init->r7.adapter_fibs_size)
2057 / sizeof(struct hw_fib); /* some extra */
2058 spin_lock_irqsave(&dev->fib_lock, flagv);
2059 entry = dev->fib_list.next;
2060 while (entry != &dev->fib_list) {
2061 entry = entry->next;
2062 ++num;
2063 }
2064 spin_unlock_irqrestore(&dev->fib_lock, flagv);
2065
2066 return num;
2067}
2068
2069static int fillup_pools(struct aac_dev *dev, struct hw_fib **hw_fib_pool,
2070 struct fib **fib_pool,
2071 unsigned int num)
2072{
2073 struct hw_fib **hw_fib_p;
2074 struct fib **fib_p;
Raghava Aditya Renukunta113156b2017-02-02 15:53:24 -08002075
2076 hw_fib_p = hw_fib_pool;
2077 fib_p = fib_pool;
2078 while (hw_fib_p < &hw_fib_pool[num]) {
2079 *(hw_fib_p) = kmalloc(sizeof(struct hw_fib), GFP_KERNEL);
2080 if (!(*(hw_fib_p++))) {
2081 --hw_fib_p;
2082 break;
2083 }
2084
2085 *(fib_p) = kmalloc(sizeof(struct fib), GFP_KERNEL);
2086 if (!(*(fib_p++))) {
2087 kfree(*(--hw_fib_p));
2088 break;
2089 }
2090 }
2091
Raghava Aditya Renukuntae4985202017-03-14 09:20:19 -07002092 /*
2093 * Get the actual number of allocated fibs
2094 */
Raghava Aditya Renukunta113156b2017-02-02 15:53:24 -08002095 num = hw_fib_p - hw_fib_pool;
Raghava Aditya Renukuntae4985202017-03-14 09:20:19 -07002096 return num;
Raghava Aditya Renukunta113156b2017-02-02 15:53:24 -08002097}
2098
2099static void wakeup_fibctx_threads(struct aac_dev *dev,
2100 struct hw_fib **hw_fib_pool,
2101 struct fib **fib_pool,
2102 struct fib *fib,
2103 struct hw_fib *hw_fib,
2104 unsigned int num)
2105{
2106 unsigned long flagv;
2107 struct list_head *entry;
2108 struct hw_fib **hw_fib_p;
2109 struct fib **fib_p;
2110 u32 time_now, time_last;
2111 struct hw_fib *hw_newfib;
2112 struct fib *newfib;
2113 struct aac_fib_context *fibctx;
2114
2115 time_now = jiffies/HZ;
2116 spin_lock_irqsave(&dev->fib_lock, flagv);
2117 entry = dev->fib_list.next;
2118 /*
2119 * For each Context that is on the
2120 * fibctxList, make a copy of the
2121 * fib, and then set the event to wake up the
2122 * thread that is waiting for it.
2123 */
2124
2125 hw_fib_p = hw_fib_pool;
2126 fib_p = fib_pool;
2127 while (entry != &dev->fib_list) {
2128 /*
2129 * Extract the fibctx
2130 */
2131 fibctx = list_entry(entry, struct aac_fib_context,
2132 next);
2133 /*
2134 * Check if the queue is getting
2135 * backlogged
2136 */
2137 if (fibctx->count > 20) {
2138 /*
2139 * It's *not* jiffies folks,
2140 * but jiffies / HZ so do not
2141 * panic ...
2142 */
2143 time_last = fibctx->jiffies;
2144 /*
2145 * Has it been > 2 minutes
2146 * since the last read off
2147 * the queue?
2148 */
2149 if ((time_now - time_last) > aif_timeout) {
2150 entry = entry->next;
2151 aac_close_fib_context(dev, fibctx);
2152 continue;
2153 }
2154 }
2155 /*
2156 * Warning: no sleep allowed while
2157 * holding spinlock
2158 */
2159 if (hw_fib_p >= &hw_fib_pool[num]) {
2160 pr_warn("aifd: didn't allocate NewFib\n");
2161 entry = entry->next;
2162 continue;
2163 }
2164
2165 hw_newfib = *hw_fib_p;
2166 *(hw_fib_p++) = NULL;
2167 newfib = *fib_p;
2168 *(fib_p++) = NULL;
2169 /*
2170 * Make the copy of the FIB
2171 */
2172 memcpy(hw_newfib, hw_fib, sizeof(struct hw_fib));
2173 memcpy(newfib, fib, sizeof(struct fib));
2174 newfib->hw_fib_va = hw_newfib;
2175 /*
2176 * Put the FIB onto the
2177 * fibctx's fibs
2178 */
2179 list_add_tail(&newfib->fiblink, &fibctx->fib_list);
2180 fibctx->count++;
2181 /*
2182 * Set the event to wake up the
2183 * thread that is waiting.
2184 */
2185 up(&fibctx->wait_sem);
2186
2187 entry = entry->next;
2188 }
2189 /*
2190 * Set the status of this FIB
2191 */
2192 *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
2193 aac_fib_adapter_complete(fib, sizeof(u32));
2194 spin_unlock_irqrestore(&dev->fib_lock, flagv);
2195
2196}
2197
2198static void aac_process_events(struct aac_dev *dev)
2199{
2200 struct hw_fib *hw_fib;
2201 struct fib *fib;
2202 unsigned long flags;
2203 spinlock_t *t_lock;
Raghava Aditya Renukunta113156b2017-02-02 15:53:24 -08002204
2205 t_lock = dev->queues->queue[HostNormCmdQueue].lock;
2206 spin_lock_irqsave(t_lock, flags);
2207
2208 while (!list_empty(&(dev->queues->queue[HostNormCmdQueue].cmdq))) {
2209 struct list_head *entry;
2210 struct aac_aifcmd *aifcmd;
2211 unsigned int num;
2212 struct hw_fib **hw_fib_pool, **hw_fib_p;
2213 struct fib **fib_pool, **fib_p;
2214
2215 set_current_state(TASK_RUNNING);
2216
2217 entry = dev->queues->queue[HostNormCmdQueue].cmdq.next;
2218 list_del(entry);
2219
2220 t_lock = dev->queues->queue[HostNormCmdQueue].lock;
2221 spin_unlock_irqrestore(t_lock, flags);
2222
2223 fib = list_entry(entry, struct fib, fiblink);
2224 hw_fib = fib->hw_fib_va;
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08002225 if (dev->sa_firmware) {
2226 /* Thor AIF */
2227 aac_handle_sa_aif(dev, fib);
2228 aac_fib_adapter_complete(fib, (u16)sizeof(u32));
Raghava Aditya Renukuntad8447522017-02-16 12:51:23 -08002229 goto free_fib;
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08002230 }
Raghava Aditya Renukunta113156b2017-02-02 15:53:24 -08002231 /*
2232 * We will process the FIB here or pass it to a
2233 * worker thread that is TBD. We Really can't
2234 * do anything at this point since we don't have
2235 * anything defined for this thread to do.
2236 */
2237 memset(fib, 0, sizeof(struct fib));
2238 fib->type = FSAFS_NTC_FIB_CONTEXT;
2239 fib->size = sizeof(struct fib);
2240 fib->hw_fib_va = hw_fib;
2241 fib->data = hw_fib->data;
2242 fib->dev = dev;
2243 /*
2244 * We only handle AifRequest fibs from the adapter.
2245 */
2246
2247 aifcmd = (struct aac_aifcmd *) hw_fib->data;
2248 if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) {
2249 /* Handle Driver Notify Events */
2250 aac_handle_aif(dev, fib);
2251 *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
2252 aac_fib_adapter_complete(fib, (u16)sizeof(u32));
2253 goto free_fib;
2254 }
2255 /*
2256 * The u32 here is important and intended. We are using
2257 * 32bit wrapping time to fit the adapter field
2258 */
2259
2260 /* Sniff events */
2261 if (aifcmd->command == cpu_to_le32(AifCmdEventNotify)
2262 || aifcmd->command == cpu_to_le32(AifCmdJobProgress)) {
2263 aac_handle_aif(dev, fib);
2264 }
2265
2266 /*
2267 * get number of fibs to process
2268 */
2269 num = get_fib_count(dev);
2270 if (!num)
2271 goto free_fib;
2272
2273 hw_fib_pool = kmalloc_array(num, sizeof(struct hw_fib *),
2274 GFP_KERNEL);
2275 if (!hw_fib_pool)
2276 goto free_fib;
2277
2278 fib_pool = kmalloc_array(num, sizeof(struct fib *), GFP_KERNEL);
2279 if (!fib_pool)
2280 goto free_hw_fib_pool;
2281
2282 /*
2283 * Fill up fib pointer pools with actual fibs
2284 * and hw_fibs
2285 */
Raghava Aditya Renukuntae4985202017-03-14 09:20:19 -07002286 num = fillup_pools(dev, hw_fib_pool, fib_pool, num);
2287 if (!num)
Raghava Aditya Renukunta113156b2017-02-02 15:53:24 -08002288 goto free_mem;
2289
2290 /*
2291 * wakeup the thread that is waiting for
2292 * the response from fw (ioctl)
2293 */
2294 wakeup_fibctx_threads(dev, hw_fib_pool, fib_pool,
2295 fib, hw_fib, num);
2296
2297free_mem:
2298 /* Free up the remaining resources */
2299 hw_fib_p = hw_fib_pool;
2300 fib_p = fib_pool;
2301 while (hw_fib_p < &hw_fib_pool[num]) {
2302 kfree(*hw_fib_p);
2303 kfree(*fib_p);
2304 ++fib_p;
2305 ++hw_fib_p;
2306 }
2307 kfree(fib_pool);
2308free_hw_fib_pool:
2309 kfree(hw_fib_pool);
2310free_fib:
2311 kfree(fib);
2312 t_lock = dev->queues->queue[HostNormCmdQueue].lock;
2313 spin_lock_irqsave(t_lock, flags);
2314 }
2315 /*
2316 * There are no more AIF's
2317 */
2318 t_lock = dev->queues->queue[HostNormCmdQueue].lock;
2319 spin_unlock_irqrestore(t_lock, flags);
2320}
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002321
Raghava Aditya Renukunta3d77d842017-02-02 15:53:25 -08002322static int aac_send_wellness_command(struct aac_dev *dev, char *wellness_str,
2323 u32 datasize)
2324{
2325 struct aac_srb *srbcmd;
2326 struct sgmap64 *sg64;
2327 dma_addr_t addr;
2328 char *dma_buf;
2329 struct fib *fibptr;
2330 int ret = -ENOMEM;
2331 u32 vbus, vid;
2332
2333 fibptr = aac_fib_alloc(dev);
2334 if (!fibptr)
2335 goto out;
2336
Mahesh Rajashekharaf4819732017-04-05 16:14:16 +05302337 dma_buf = dma_alloc_coherent(&dev->pdev->dev, datasize, &addr,
2338 GFP_KERNEL);
Raghava Aditya Renukunta3d77d842017-02-02 15:53:25 -08002339 if (!dma_buf)
2340 goto fib_free_out;
2341
2342 aac_fib_init(fibptr);
2343
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002344 vbus = (u32)le16_to_cpu(dev->supplement_adapter_info.virt_device_bus);
2345 vid = (u32)le16_to_cpu(dev->supplement_adapter_info.virt_device_target);
Raghava Aditya Renukunta3d77d842017-02-02 15:53:25 -08002346
2347 srbcmd = (struct aac_srb *)fib_data(fibptr);
2348
2349 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
2350 srbcmd->channel = cpu_to_le32(vbus);
2351 srbcmd->id = cpu_to_le32(vid);
2352 srbcmd->lun = 0;
2353 srbcmd->flags = cpu_to_le32(SRB_DataOut);
2354 srbcmd->timeout = cpu_to_le32(10);
2355 srbcmd->retry_limit = 0;
2356 srbcmd->cdb_size = cpu_to_le32(12);
2357 srbcmd->count = cpu_to_le32(datasize);
2358
2359 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
2360 srbcmd->cdb[0] = BMIC_OUT;
2361 srbcmd->cdb[6] = WRITE_HOST_WELLNESS;
2362 memcpy(dma_buf, (char *)wellness_str, datasize);
2363
2364 sg64 = (struct sgmap64 *)&srbcmd->sg;
2365 sg64->count = cpu_to_le32(1);
2366 sg64->sg[0].addr[1] = cpu_to_le32((u32)(((addr) >> 16) >> 16));
2367 sg64->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2368 sg64->sg[0].count = cpu_to_le32(datasize);
2369
2370 ret = aac_fib_send(ScsiPortCommand64, fibptr, sizeof(struct aac_srb),
2371 FsaNormal, 1, 1, NULL, NULL);
2372
Mahesh Rajashekharaf4819732017-04-05 16:14:16 +05302373 dma_free_coherent(&dev->pdev->dev, datasize, dma_buf, addr);
Raghava Aditya Renukunta3d77d842017-02-02 15:53:25 -08002374
2375 /*
2376 * Do not set XferState to zero unless
2377 * receives a response from F/W
2378 */
2379 if (ret >= 0)
2380 aac_fib_complete(fibptr);
2381
2382 /*
2383 * FIB should be freed only after
2384 * getting the response from the F/W
2385 */
2386 if (ret != -ERESTARTSYS)
2387 goto fib_free_out;
2388
2389out:
2390 return ret;
2391fib_free_out:
2392 aac_fib_free(fibptr);
2393 goto out;
2394}
2395
Arnd Bergmann820f1882017-11-07 11:46:05 +01002396int aac_send_safw_hostttime(struct aac_dev *dev, struct timespec64 *now)
Raghava Aditya Renukunta3d77d842017-02-02 15:53:25 -08002397{
2398 struct tm cur_tm;
2399 char wellness_str[] = "<HW>TD\010\0\0\0\0\0\0\0\0\0DW\0\0ZZ";
2400 u32 datasize = sizeof(wellness_str);
Arnd Bergmann820f1882017-11-07 11:46:05 +01002401 time64_t local_time;
Raghava Aditya Renukunta3d77d842017-02-02 15:53:25 -08002402 int ret = -ENODEV;
2403
2404 if (!dev->sa_firmware)
2405 goto out;
2406
Arnd Bergmann820f1882017-11-07 11:46:05 +01002407 local_time = (now->tv_sec - (sys_tz.tz_minuteswest * 60));
2408 time64_to_tm(local_time, 0, &cur_tm);
Raghava Aditya Renukunta3d77d842017-02-02 15:53:25 -08002409 cur_tm.tm_mon += 1;
2410 cur_tm.tm_year += 1900;
2411 wellness_str[8] = bin2bcd(cur_tm.tm_hour);
2412 wellness_str[9] = bin2bcd(cur_tm.tm_min);
2413 wellness_str[10] = bin2bcd(cur_tm.tm_sec);
2414 wellness_str[12] = bin2bcd(cur_tm.tm_mon);
2415 wellness_str[13] = bin2bcd(cur_tm.tm_mday);
2416 wellness_str[14] = bin2bcd(cur_tm.tm_year / 100);
2417 wellness_str[15] = bin2bcd(cur_tm.tm_year % 100);
2418
2419 ret = aac_send_wellness_command(dev, wellness_str, datasize);
2420
2421out:
2422 return ret;
2423}
2424
Arnd Bergmann820f1882017-11-07 11:46:05 +01002425int aac_send_hosttime(struct aac_dev *dev, struct timespec64 *now)
Raghava Aditya Renukunta3d77d842017-02-02 15:53:25 -08002426{
2427 int ret = -ENOMEM;
2428 struct fib *fibptr;
2429 __le32 *info;
2430
2431 fibptr = aac_fib_alloc(dev);
2432 if (!fibptr)
2433 goto out;
2434
2435 aac_fib_init(fibptr);
2436 info = (__le32 *)fib_data(fibptr);
Arnd Bergmann820f1882017-11-07 11:46:05 +01002437 *info = cpu_to_le32(now->tv_sec); /* overflow in y2106 */
Raghava Aditya Renukunta3d77d842017-02-02 15:53:25 -08002438 ret = aac_fib_send(SendHostTime, fibptr, sizeof(*info), FsaNormal,
2439 1, 1, NULL, NULL);
2440
2441 /*
2442 * Do not set XferState to zero unless
2443 * receives a response from F/W
2444 */
2445 if (ret >= 0)
2446 aac_fib_complete(fibptr);
2447
2448 /*
2449 * FIB should be freed only after
2450 * getting the response from the F/W
2451 */
2452 if (ret != -ERESTARTSYS)
2453 aac_fib_free(fibptr);
2454
2455out:
2456 return ret;
2457}
2458
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459/**
2460 * aac_command_thread - command processing thread
2461 * @dev: Adapter to monitor
2462 *
2463 * Waits on the commandready event in it's queue. When the event gets set
2464 * it will pull FIBs off it's queue. It will continue to pull FIBs off
2465 * until the queue is empty. When the queue is empty it will wait for
2466 * more FIBs.
2467 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002468
Christoph Hellwigfe273812006-02-14 18:45:06 +01002469int aac_command_thread(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470{
Christoph Hellwigfe273812006-02-14 18:45:06 +01002471 struct aac_dev *dev = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 DECLARE_WAITQUEUE(wait, current);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002473 unsigned long next_jiffies = jiffies + HZ;
2474 unsigned long next_check_jiffies = next_jiffies;
2475 long difference = HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476
2477 /*
2478 * We can only have one thread per adapter for AIF's.
2479 */
2480 if (dev->aif_thread)
2481 return -EINVAL;
Christoph Hellwigfe273812006-02-14 18:45:06 +01002482
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 /*
2484 * Let the DPC know it has a place to send the AIF's to.
2485 */
2486 dev->aif_thread = 1;
Mark Haverkamp2f1309802005-09-26 13:02:15 -07002487 add_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 set_current_state(TASK_INTERRUPTIBLE);
Mark Haverkamp2f1309802005-09-26 13:02:15 -07002489 dprintk ((KERN_INFO "aac_command_thread start\n"));
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002490 while (1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491
Raghava Aditya Renukunta113156b2017-02-02 15:53:24 -08002492 aac_process_events(dev);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002493
2494 /*
2495 * Background activity
2496 */
2497 if ((time_before(next_check_jiffies,next_jiffies))
2498 && ((difference = next_check_jiffies - jiffies) <= 0)) {
2499 next_check_jiffies = next_jiffies;
Raghava Aditya Renukunta9473ddb2017-05-10 09:39:48 -07002500 if (aac_adapter_check_health(dev) == 0) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002501 difference = ((long)(unsigned)check_interval)
2502 * HZ;
2503 next_check_jiffies = jiffies + difference;
2504 } else if (!dev->queues)
2505 break;
2506 }
2507 if (!time_before(next_check_jiffies,next_jiffies)
2508 && ((difference = next_jiffies - jiffies) <= 0)) {
Arnd Bergmann820f1882017-11-07 11:46:05 +01002509 struct timespec64 now;
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002510 int ret;
2511
2512 /* Don't even try to talk to adapter if its sick */
Raghava Aditya Renukunta9473ddb2017-05-10 09:39:48 -07002513 ret = aac_adapter_check_health(dev);
Raghava Aditya Renukunta849ac6a2017-02-16 12:51:17 -08002514 if (ret || !dev->queues)
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002515 break;
2516 next_check_jiffies = jiffies
2517 + ((long)(unsigned)check_interval)
2518 * HZ;
Arnd Bergmann820f1882017-11-07 11:46:05 +01002519 ktime_get_real_ts64(&now);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002520
2521 /* Synchronize our watches */
Arnd Bergmann820f1882017-11-07 11:46:05 +01002522 if (((NSEC_PER_SEC - (NSEC_PER_SEC / HZ)) > now.tv_nsec)
2523 && (now.tv_nsec > (NSEC_PER_SEC / HZ)))
2524 difference = (((NSEC_PER_SEC - now.tv_nsec) * HZ)
2525 + NSEC_PER_SEC / 2) / NSEC_PER_SEC;
Colin Ian Kingfbdab3e2017-02-24 14:43:30 +00002526 else {
Arnd Bergmann820f1882017-11-07 11:46:05 +01002527 if (now.tv_nsec > NSEC_PER_SEC / 2)
Raghava Aditya Renukunta3d77d842017-02-02 15:53:25 -08002528 ++now.tv_sec;
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002529
Raghava Aditya Renukunta3d77d842017-02-02 15:53:25 -08002530 if (dev->sa_firmware)
2531 ret =
2532 aac_send_safw_hostttime(dev, &now);
2533 else
2534 ret = aac_send_hosttime(dev, &now);
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002535
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002536 difference = (long)(unsigned)update_interval*HZ;
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002537 }
2538 next_jiffies = jiffies + difference;
2539 if (time_before(next_check_jiffies,next_jiffies))
2540 difference = next_check_jiffies - jiffies;
2541 }
2542 if (difference <= 0)
2543 difference = 1;
2544 set_current_state(TASK_INTERRUPTIBLE);
Raghava Aditya Renukuntafc4bf752016-04-25 23:31:57 -07002545
2546 if (kthread_should_stop())
2547 break;
2548
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002549 schedule_timeout(difference);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550
Christoph Hellwigfe273812006-02-14 18:45:06 +01002551 if (kthread_should_stop())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 }
Mark Haverkamp2f1309802005-09-26 13:02:15 -07002554 if (dev->queues)
2555 remove_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 dev->aif_thread = 0;
Mark Haverkamp2f1309802005-09-26 13:02:15 -07002557 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558}
Mahesh Rajashekhara8b1462e2015-08-28 06:38:38 -04002559
2560int aac_acquire_irq(struct aac_dev *dev)
2561{
2562 int i;
2563 int j;
2564 int ret = 0;
Mahesh Rajashekhara8b1462e2015-08-28 06:38:38 -04002565
Mahesh Rajashekhara8b1462e2015-08-28 06:38:38 -04002566 if (!dev->sync_mode && dev->msi_enabled && dev->max_msix > 1) {
2567 for (i = 0; i < dev->max_msix; i++) {
2568 dev->aac_msix[i].vector_no = i;
2569 dev->aac_msix[i].dev = dev;
Hannes Reinecke0910d8b2016-11-08 08:11:30 +01002570 if (request_irq(pci_irq_vector(dev->pdev, i),
Mahesh Rajashekhara8b1462e2015-08-28 06:38:38 -04002571 dev->a_ops.adapter_intr,
2572 0, "aacraid", &(dev->aac_msix[i]))) {
2573 printk(KERN_ERR "%s%d: Failed to register IRQ for vector %d.\n",
2574 dev->name, dev->id, i);
2575 for (j = 0 ; j < i ; j++)
Hannes Reinecke0910d8b2016-11-08 08:11:30 +01002576 free_irq(pci_irq_vector(dev->pdev, j),
Mahesh Rajashekhara8b1462e2015-08-28 06:38:38 -04002577 &(dev->aac_msix[j]));
2578 pci_disable_msix(dev->pdev);
2579 ret = -1;
2580 }
Mahesh Rajashekhara8b1462e2015-08-28 06:38:38 -04002581 }
2582 } else {
2583 dev->aac_msix[0].vector_no = 0;
2584 dev->aac_msix[0].dev = dev;
2585
2586 if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr,
2587 IRQF_SHARED, "aacraid",
2588 &(dev->aac_msix[0])) < 0) {
2589 if (dev->msi)
2590 pci_disable_msi(dev->pdev);
2591 printk(KERN_ERR "%s%d: Interrupt unavailable.\n",
2592 dev->name, dev->id);
2593 ret = -1;
2594 }
2595 }
2596 return ret;
2597}
2598
2599void aac_free_irq(struct aac_dev *dev)
2600{
2601 int i;
2602 int cpu;
2603
2604 cpu = cpumask_first(cpu_online_mask);
Raghava Aditya Renukunta395e5df2017-05-10 09:39:52 -07002605 if (aac_is_src(dev)) {
Mahesh Rajashekhara8b1462e2015-08-28 06:38:38 -04002606 if (dev->max_msix > 1) {
Hannes Reinecke0910d8b2016-11-08 08:11:30 +01002607 for (i = 0; i < dev->max_msix; i++)
2608 free_irq(pci_irq_vector(dev->pdev, i),
2609 &(dev->aac_msix[i]));
Mahesh Rajashekhara8b1462e2015-08-28 06:38:38 -04002610 } else {
2611 free_irq(dev->pdev->irq, &(dev->aac_msix[0]));
2612 }
2613 } else {
2614 free_irq(dev->pdev->irq, dev);
2615 }
2616 if (dev->msi)
2617 pci_disable_msi(dev->pdev);
2618 else if (dev->max_msix > 1)
2619 pci_disable_msix(dev->pdev);
2620}