Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Adaptec AAC series RAID controller driver |
Alan Cox | fa195af | 2008-10-27 15:16:36 +0000 | [diff] [blame] | 3 | * (c) Copyright 2001 Red Hat Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * based on the old aacraid driver that is.. |
| 6 | * Adaptec aacraid device driver for Linux. |
| 7 | * |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 8 | * Copyright (c) 2000-2010 Adaptec, Inc. |
Raghava Aditya Renukunta | f4babba | 2017-02-02 15:53:36 -0800 | [diff] [blame] | 9 | * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com) |
| 10 | * 2016-2017 Microsemi Corp. (aacraid@microsemi.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 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 | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 30 | * communication. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | * |
| 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 Viro | 164006d | 2005-11-30 23:47:05 -0500 | [diff] [blame] | 43 | #include <linux/delay.h> |
Christoph Hellwig | fe27381 | 2006-02-14 18:45:06 +0100 | [diff] [blame] | 44 | #include <linux/kthread.h> |
Al Viro | 6a3670c | 2006-09-24 23:45:29 +0100 | [diff] [blame] | 45 | #include <linux/interrupt.h> |
Matthew Wilcox | 6188e10 | 2008-04-18 22:21:05 -0400 | [diff] [blame] | 46 | #include <linux/semaphore.h> |
Raghava Aditya Renukunta | 3d77d84 | 2017-02-02 15:53:25 -0800 | [diff] [blame] | 47 | #include <linux/bcd.h> |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 48 | #include <scsi/scsi.h> |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 49 | #include <scsi/scsi_host.h> |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 50 | #include <scsi/scsi_device.h> |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 51 | #include <scsi/scsi_cmnd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 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, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | static int fib_map_alloc(struct aac_dev *dev) |
| 64 | { |
Raghava Aditya Renukunta | 3ffd6c5 | 2017-02-02 15:53:22 -0800 | [diff] [blame] | 65 | 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 Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 69 | 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 Renukunta | 3ffd6c5 | 2017-02-02 15:53:22 -0800 | [diff] [blame] | 74 | |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 75 | dprintk((KERN_INFO |
Mahesh Rajashekhara | f481973 | 2017-04-05 16:14:16 +0530 | [diff] [blame] | 76 | "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 | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 78 | AAC_NUM_MGT_FIB, &dev->hw_fib_pa)); |
Mahesh Rajashekhara | f481973 | 2017-04-05 16:14:16 +0530 | [diff] [blame] | 79 | dev->hw_fib_va = dma_alloc_coherent(&dev->pdev->dev, |
Raghava Aditya Renukunta | 3ffd6c5 | 2017-02-02 15:53:22 -0800 | [diff] [blame] | 80 | (dev->max_cmd_size + sizeof(struct aac_fib_xporthdr)) |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 81 | * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) + (ALIGN32 - 1), |
Mahesh Rajashekhara | f481973 | 2017-04-05 16:14:16 +0530 | [diff] [blame] | 82 | &dev->hw_fib_pa, GFP_KERNEL); |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 83 | if (dev->hw_fib_va == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | return -ENOMEM; |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 89 | * aac_fib_map_free - free the fib objects |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | * @dev: Adapter to free |
| 91 | * |
| 92 | * Free the PCI mappings and the memory allocated for FIB blocks |
| 93 | * on this adapter. |
| 94 | */ |
| 95 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 96 | void aac_fib_map_free(struct aac_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
Raghava Aditya Renukunta | 1bff5ab | 2017-02-16 12:51:14 -0800 | [diff] [blame] | 98 | 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 Rajashekhara | f481973 | 2017-04-05 16:14:16 +0530 | [diff] [blame] | 109 | dma_free_coherent(&dev->pdev->dev, alloc_size, dev->hw_fib_va, |
| 110 | dev->hw_fib_pa); |
Raghava Aditya Renukunta | 1bff5ab | 2017-02-16 12:51:14 -0800 | [diff] [blame] | 111 | |
Salyzyn, Mark | 9ad5204 | 2007-07-17 11:15:08 -0400 | [diff] [blame] | 112 | dev->hw_fib_va = NULL; |
| 113 | dev->hw_fib_pa = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Raghava Aditya Renukunta | 3f4ce05 | 2016-02-03 15:06:00 -0800 | [diff] [blame] | 116 | void 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 139 | * aac_fib_setup - setup the fibs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | * @dev: Adapter to set up |
| 141 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 142 | * Allocate the PCI space for the fibs, map it and then initialise the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | * fib area, the unmapped fib data and also the free list |
| 144 | */ |
| 145 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 146 | int aac_fib_setup(struct aac_dev * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
| 148 | struct fib *fibptr; |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 149 | struct hw_fib *hw_fib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | dma_addr_t hw_fib_pa; |
| 151 | int i; |
Raghava Aditya Renukunta | d1ef4da | 2017-02-02 15:53:17 -0800 | [diff] [blame] | 152 | u32 max_cmds; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 153 | |
| 154 | while (((i = fib_map_alloc(dev)) == -ENOMEM) |
| 155 | && (dev->scsi_host_ptr->can_queue > (64 - AAC_NUM_MGT_FIB))) { |
Raghava Aditya Renukunta | d1ef4da | 2017-02-02 15:53:17 -0800 | [diff] [blame] | 156 | 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 | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 160 | } |
| 161 | if (i<0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | return -ENOMEM; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 163 | |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 164 | memset(dev->hw_fib_va, 0, |
Raghava Aditya Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 165 | (dev->max_cmd_size + sizeof(struct aac_fib_xporthdr)) * |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 166 | (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB)); |
| 167 | |
Raghava Aditya Renukunta | 1bff5ab | 2017-02-16 12:51:14 -0800 | [diff] [blame] | 168 | /* 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 Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 172 | |
Raghava Aditya Renukunta | 1bff5ab | 2017-02-16 12:51:14 -0800 | [diff] [blame] | 173 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | /* |
| 179 | * Initialise the fibs |
| 180 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 181 | for (i = 0, fibptr = &dev->fibs[i]; |
| 182 | i < (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB); |
| 183 | i++, fibptr++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
Mahesh Rajashekhara | 85d22bb | 2012-07-14 18:18:51 +0530 | [diff] [blame] | 185 | fibptr->flags = 0; |
Raghava Aditya Renukunta | 6bf3b63 | 2016-02-03 15:05:59 -0800 | [diff] [blame] | 186 | fibptr->size = sizeof(struct fib); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | fibptr->dev = dev; |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 188 | fibptr->hw_fib_va = hw_fib; |
| 189 | fibptr->data = (void *) fibptr->hw_fib_va->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | fibptr->next = fibptr+1; /* Forward chain the fibs */ |
Thomas Gleixner | 6de76cf | 2010-09-07 14:32:47 +0000 | [diff] [blame] | 191 | sema_init(&fibptr->event_wait, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | spin_lock_init(&fibptr->event_lock); |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 193 | hw_fib->header.XferState = cpu_to_le32(0xffffffff); |
Raghava Aditya Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 194 | hw_fib->header.SenderSize = |
| 195 | cpu_to_le16(dev->max_fib_size); /* ?? max_cmd_size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | fibptr->hw_fib_pa = hw_fib_pa; |
Raghava Aditya Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 197 | 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 Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 206 | hw_fib = (struct hw_fib *)((unsigned char *)hw_fib + |
Raghava Aditya Renukunta | 3ffd6c5 | 2017-02-02 15:53:22 -0800 | [diff] [blame] | 207 | dev->max_cmd_size + sizeof(struct aac_fib_xporthdr)); |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 208 | hw_fib_pa = hw_fib_pa + |
Raghava Aditya Renukunta | 3ffd6c5 | 2017-02-02 15:53:22 -0800 | [diff] [blame] | 209 | dev->max_cmd_size + sizeof(struct aac_fib_xporthdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
Raghava Aditya Renukunta | 3f4ce05 | 2016-02-03 15:06:00 -0800 | [diff] [blame] | 211 | |
| 212 | /* |
| 213 | *Assign vector numbers to fibs |
| 214 | */ |
| 215 | aac_fib_vector_assign(dev); |
| 216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | /* |
| 218 | * Add the fib chain to the free list |
| 219 | */ |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 220 | dev->fibs[dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB - 1].next = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | /* |
Raghava Aditya Renukunta | 6bf3b63 | 2016-02-03 15:05:59 -0800 | [diff] [blame] | 222 | * Set 8 fibs aside for management tools |
| 223 | */ |
| 224 | dev->free_fib = &dev->fibs[dev->scsi_host_ptr->can_queue]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | /** |
Raghava Aditya Renukunta | 6bf3b63 | 2016-02-03 15:05:59 -0800 | [diff] [blame] | 229 | * 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 | |
| 236 | struct 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 Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 254 | * aac_fib_alloc - allocate a fib |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | * @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 | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 258 | * return NULL. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 260 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 261 | struct fib *aac_fib_alloc(struct aac_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | { |
| 263 | struct fib * fibptr; |
| 264 | unsigned long flags; |
| 265 | spin_lock_irqsave(&dev->fib_lock, flags); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 266 | fibptr = dev->free_fib; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 267 | if(!fibptr){ |
| 268 | spin_unlock_irqrestore(&dev->fib_lock, flags); |
| 269 | return fibptr; |
| 270 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | 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 Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 282 | fibptr->hw_fib_va->header.XferState = 0; |
Salyzyn, Mark | b6ef70f | 2008-01-08 13:26:43 -0800 | [diff] [blame] | 283 | fibptr->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | fibptr->callback = NULL; |
| 285 | fibptr->callback_data = NULL; |
| 286 | |
| 287 | return fibptr; |
| 288 | } |
| 289 | |
| 290 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 291 | * aac_fib_free - free a fib |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | * @fibptr: fib to free up |
| 293 | * |
| 294 | * Frees up a fib and places it on the appropriate queue |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 296 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 297 | void aac_fib_free(struct fib *fibptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { |
Mahesh Rajashekhara | ef61623 | 2015-03-26 10:41:30 -0400 | [diff] [blame] | 299 | unsigned long flags; |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 300 | |
Mahesh Rajashekhara | ef61623 | 2015-03-26 10:41:30 -0400 | [diff] [blame] | 301 | if (fibptr->done == 2) |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 302 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
| 304 | spin_lock_irqsave(&fibptr->dev->fib_lock, flags); |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 305 | if (unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | aac_config.fib_timeouts++; |
Raghava Aditya Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 307 | if (!(fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA) && |
| 308 | fibptr->hw_fib_va->header.XferState != 0) { |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 309 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | spin_unlock_irqrestore(&fibptr->dev->fib_lock, flags); |
| 316 | } |
| 317 | |
| 318 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 319 | * aac_fib_init - initialise a fib |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | * @fibptr: The fib to initialize |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 321 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | * Set up the generic fib fields ready for use |
| 323 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 324 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 325 | void aac_fib_init(struct fib *fibptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 327 | struct hw_fib *hw_fib = fibptr->hw_fib_va; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Mahesh Rajashekhara | 85d22bb | 2012-07-14 18:18:51 +0530 | [diff] [blame] | 329 | memset(&hw_fib->header, 0, sizeof(struct aac_fibhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | hw_fib->header.StructType = FIB_MAGIC; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 331 | 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 Rajashekhara | 85d22bb | 2012-07-14 18:18:51 +0530 | [diff] [blame] | 333 | hw_fib->header.u.ReceiverFibAddress = cpu_to_le32(fibptr->hw_fib_pa); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 334 | hw_fib->header.SenderSize = cpu_to_le16(fibptr->dev->max_fib_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 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, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 344 | |
Adrian Bunk | 4833869 | 2005-04-25 19:45:58 -0700 | [diff] [blame] | 345 | static void fib_dealloc(struct fib * fibptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 347 | struct hw_fib *hw_fib = fibptr->hw_fib_va; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 348 | hw_fib->header.XferState = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 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, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | /** |
| 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, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | static 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 Haverkamp | bed30de | 2005-08-03 15:38:51 -0700 | [diff] [blame] | 374 | unsigned long idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
| 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 Haverkamp | bed30de | 2005-08-03 15:38:51 -0700 | [diff] [blame] | 384 | |
| 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 Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 389 | if (qid == AdapNormCmdQueue) |
Mark Haverkamp | bed30de | 2005-08-03 15:38:51 -0700 | [diff] [blame] | 390 | idx = ADAP_NORM_CMD_ENTRIES; |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 391 | else |
Mark Haverkamp | bed30de | 2005-08-03 15:38:51 -0700 | [diff] [blame] | 392 | idx = ADAP_NORM_RESP_ENTRIES; |
| 393 | } |
| 394 | if (idx != le32_to_cpu(*(q->headers.consumer))) |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 395 | *nonotify = 1; |
Mark Haverkamp | bed30de | 2005-08-03 15:38:51 -0700 | [diff] [blame] | 396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 398 | if (qid == AdapNormCmdQueue) { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 399 | if (*index >= ADAP_NORM_CMD_ENTRIES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | *index = 0; /* Wrap to front of the Producer Queue. */ |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 401 | } else { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 402 | if (*index >= ADAP_NORM_RESP_ENTRIES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | *index = 0; /* Wrap to front of the Producer Queue. */ |
| 404 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 406 | /* Queue is full */ |
| 407 | if ((*index + 1) == le32_to_cpu(*(q->headers.consumer))) { |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 408 | printk(KERN_WARNING "Queue %d full, %u outstanding.\n", |
Mahesh Rajashekhara | ef61623 | 2015-03-26 10:41:30 -0400 | [diff] [blame] | 409 | qid, atomic_read(&q->numpending)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | return 0; |
| 411 | } else { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 412 | *entry = q->base + *index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | return 1; |
| 414 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 415 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 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 Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 433 | int aac_queue_get(struct aac_dev * dev, u32 * index, u32 qid, struct hw_fib * hw_fib, int wait, struct fib * fibptr, unsigned long *nonotify) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | { |
| 435 | struct aac_entry * entry = NULL; |
| 436 | int map = 0; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 437 | |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 438 | if (qid == AdapNormCmdQueue) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | /* if no entries wait for some if caller wants to */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 440 | while (!aac_get_entry(dev, qid, &entry, index, nonotify)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | printk(KERN_ERR "GetEntries failed\n"); |
| 442 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 443 | /* |
| 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 Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 448 | } else { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 449 | while (!aac_get_entry(dev, qid, &entry, index, nonotify)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | /* if no entries wait for some if caller wants to */ |
| 451 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 452 | /* |
| 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 Rajashekhara | 85d22bb | 2012-07-14 18:18:51 +0530 | [diff] [blame] | 458 | hw_fib->header.u.ReceiverFibAddress = hw_fib->header.SenderFibAddress; /* Let the adapter now where to find its data */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 459 | map = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | } |
| 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 Renukunta | 16ae9dd | 2017-02-16 12:51:12 -0800 | [diff] [blame] | 470 | #ifdef CONFIG_EEH |
| 471 | static 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 |
| 493 | static inline int aac_check_eeh_failure(struct aac_dev *dev) |
| 494 | { |
| 495 | return 0; |
| 496 | } |
| 497 | #endif |
| 498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | /* |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 500 | * Define the highest level of host to adapter communication routines. |
| 501 | * These routines will support host to adapter FS commuication. These |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | * 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 Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 508 | * aac_fib_send - send a fib to the adapter |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | * @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, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 523 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 524 | int 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | struct aac_dev * dev = fibptr->dev; |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 529 | struct hw_fib * hw_fib = fibptr->hw_fib_va; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | unsigned long flags = 0; |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 531 | unsigned long mflags = 0; |
Mahesh Rajashekhara | 1160461 | 2012-02-08 22:51:04 -0800 | [diff] [blame] | 532 | unsigned long sflags = 0; |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | if (!(hw_fib->header.XferState & cpu_to_le32(HostOwned))) |
| 535 | return -EBUSY; |
Raghava Aditya Renukunta | a0c6143 | 2017-02-16 12:51:13 -0800 | [diff] [blame] | 536 | |
| 537 | if (hw_fib->header.XferState & cpu_to_le32(AdapterProcessed)) |
| 538 | return -EINVAL; |
| 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 541 | * There are 5 cases with the wait and response requested flags. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | * 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, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 547 | * further processing will be done besides deleting the Fib. We |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | * 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, Mark | b6ef70f | 2008-01-08 13:26:43 -0800 | [diff] [blame] | 551 | fibptr->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | 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, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 563 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | /* |
| 565 | * Map the fib into 32bits by using the fib number |
| 566 | */ |
| 567 | |
Raghava Aditya Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 568 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | /* |
| 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, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 592 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | /* |
| 594 | * Get a queue entry connect the FIB to it and send an notify |
| 595 | * the adapter a command is ready. |
| 596 | */ |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 597 | hw_fib->header.XferState |= cpu_to_le32(NormalPriority); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | /* |
| 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, Mark | b6ef70f | 2008-01-08 13:26:43 -0800 | [diff] [blame] | 606 | fibptr->flags = FIB_CONTEXT_FLAG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
| 609 | fibptr->done = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 611 | FIB_COUNTER_INCREMENT(aac_config.FibsSent); |
| 612 | |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 613 | dprintk((KERN_DEBUG "Fib contents:.\n")); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 614 | 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 Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 617 | dprintk((KERN_DEBUG " hw_fib va being sent=%p\n",fibptr->hw_fib_va)); |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 618 | 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 Haverkamp | c8f7b07 | 2006-08-03 08:02:24 -0700 | [diff] [blame] | 621 | if (!dev->queues) |
Mark Haverkamp | 6510135 | 2006-09-19 08:59:23 -0700 | [diff] [blame] | 622 | return -EBUSY; |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 623 | |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 624 | 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 Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 635 | spin_lock_irqsave(&fibptr->event_lock, flags); |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 636 | } |
| 637 | |
Mahesh Rajashekhara | 1160461 | 2012-02-08 22:51:04 -0800 | [diff] [blame] | 638 | 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-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 663 | 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 Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | /* |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 676 | * If the caller wanted us to wait for response wait now. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | if (wait) { |
| 680 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 681 | /* 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 Collins | 30002f1 | 2012-06-11 14:44:44 -0400 | [diff] [blame] | 689 | unsigned long timeout = jiffies + (180 * HZ); /* 3 minutes */ |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 690 | while (down_trylock(&fibptr->event_wait)) { |
Mark Haverkamp | 33524b7 | 2006-11-21 10:40:08 -0800 | [diff] [blame] | 691 | int blink; |
Ben Collins | 30002f1 | 2012-06-11 14:44:44 -0400 | [diff] [blame] | 692 | if (time_is_before_eq_jiffies(timeout)) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 693 | struct aac_queue * q = &dev->queues->queue[AdapNormCmdQueue]; |
Mahesh Rajashekhara | ef61623 | 2015-03-26 10:41:30 -0400 | [diff] [blame] | 694 | atomic_dec(&q->numpending); |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 695 | if (wait == -1) { |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 696 | printk(KERN_ERR "aacraid: aac_fib_send: first asynchronous command timed out.\n" |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 697 | "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 Renukunta | 16ae9dd | 2017-02-16 12:51:12 -0800 | [diff] [blame] | 703 | |
| 704 | if (aac_check_eeh_failure(dev)) |
| 705 | return -EFAULT; |
| 706 | |
Mark Haverkamp | 33524b7 | 2006-11-21 10:40:08 -0800 | [diff] [blame] | 707 | 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 Renukunta | 07beca2 | 2016-04-25 23:31:26 -0700 | [diff] [blame] | 715 | /* |
| 716 | * Allow other processes / CPUS to use core |
| 717 | */ |
| 718 | schedule(); |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 719 | } |
Mark Salyzyn | 0462590 | 2008-04-23 08:16:06 -0400 | [diff] [blame] | 720 | } else if (down_interruptible(&fibptr->event_wait)) { |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 721 | /* Do nothing ... satisfy |
| 722 | * down_interruptible must_check */ |
Mark Salyzyn | e6990c6 | 2008-04-14 14:20:16 -0400 | [diff] [blame] | 723 | } |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 724 | |
Mark Haverkamp | 33bb3b2 | 2007-03-15 10:27:21 -0700 | [diff] [blame] | 725 | spin_lock_irqsave(&fibptr->event_lock, flags); |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 726 | if (fibptr->done == 0) { |
Mark Haverkamp | 33bb3b2 | 2007-03-15 10:27:21 -0700 | [diff] [blame] | 727 | fibptr->done = 2; /* Tell interrupt we aborted */ |
Mark Haverkamp | c8f7b07 | 2006-08-03 08:02:24 -0700 | [diff] [blame] | 728 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 729 | return -ERESTARTSYS; |
Mark Haverkamp | c8f7b07 | 2006-08-03 08:02:24 -0700 | [diff] [blame] | 730 | } |
Mark Haverkamp | 33bb3b2 | 2007-03-15 10:27:21 -0700 | [diff] [blame] | 731 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
Eric Sesterhenn | 125e187 | 2006-06-23 02:06:06 -0700 | [diff] [blame] | 732 | BUG_ON(fibptr->done == 0); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 733 | |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 734 | if(unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | return -ETIMEDOUT; |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 736 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | } |
| 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 Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 748 | int 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); |
| 773 | } else |
| 774 | return -EINVAL; |
| 775 | |
| 776 | |
| 777 | if (wait) { |
| 778 | spin_lock_irqsave(&dev->manage_lock, mflags); |
| 779 | if (dev->management_fib_count >= AAC_NUM_MGT_FIB) { |
| 780 | spin_unlock_irqrestore(&dev->manage_lock, mflags); |
| 781 | return -EBUSY; |
| 782 | } |
| 783 | dev->management_fib_count++; |
| 784 | spin_unlock_irqrestore(&dev->manage_lock, mflags); |
| 785 | spin_lock_irqsave(&fibptr->event_lock, flags); |
| 786 | } |
| 787 | |
| 788 | if (aac_adapter_deliver(fibptr) != 0) { |
| 789 | if (wait) { |
| 790 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
| 791 | spin_lock_irqsave(&dev->manage_lock, mflags); |
| 792 | dev->management_fib_count--; |
| 793 | spin_unlock_irqrestore(&dev->manage_lock, mflags); |
| 794 | } |
| 795 | return -EBUSY; |
| 796 | } |
| 797 | FIB_COUNTER_INCREMENT(aac_config.NativeSent); |
| 798 | |
| 799 | if (wait) { |
Raghava Aditya Renukunta | 16ae9dd | 2017-02-16 12:51:12 -0800 | [diff] [blame] | 800 | |
Raghava Aditya Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 801 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
Raghava Aditya Renukunta | 16ae9dd | 2017-02-16 12:51:12 -0800 | [diff] [blame] | 802 | |
| 803 | if (aac_check_eeh_failure(dev)) |
| 804 | return -EFAULT; |
| 805 | |
Raghava Aditya Renukunta | 8c41b9b | 2017-05-10 09:39:49 -0700 | [diff] [blame] | 806 | fibptr->flags |= FIB_CONTEXT_FLAG_WAIT; |
| 807 | if (down_interruptible(&fibptr->event_wait)) |
Raghava Aditya Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 808 | fibptr->done = 2; |
Raghava Aditya Renukunta | 8c41b9b | 2017-05-10 09:39:49 -0700 | [diff] [blame] | 809 | fibptr->flags &= ~(FIB_CONTEXT_FLAG_WAIT); |
| 810 | |
Raghava Aditya Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 811 | spin_lock_irqsave(&fibptr->event_lock, flags); |
| 812 | if ((fibptr->done == 0) || (fibptr->done == 2)) { |
| 813 | fibptr->done = 2; /* Tell interrupt we aborted */ |
| 814 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
| 815 | return -ERESTARTSYS; |
| 816 | } |
| 817 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
| 818 | WARN_ON(fibptr->done == 0); |
| 819 | |
| 820 | if (unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT)) |
| 821 | return -ETIMEDOUT; |
| 822 | |
| 823 | return 0; |
| 824 | } |
| 825 | |
| 826 | return -EINPROGRESS; |
| 827 | } |
| 828 | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 829 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | * aac_consumer_get - get the top of the queue |
| 831 | * @dev: Adapter |
| 832 | * @q: Queue |
| 833 | * @entry: Return entry |
| 834 | * |
| 835 | * Will return a pointer to the entry on the top of the queue requested that |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 836 | * we are a consumer of, and return the address of the queue entry. It does |
| 837 | * not change the state of the queue. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | */ |
| 839 | |
| 840 | int aac_consumer_get(struct aac_dev * dev, struct aac_queue * q, struct aac_entry **entry) |
| 841 | { |
| 842 | u32 index; |
| 843 | int status; |
| 844 | if (le32_to_cpu(*q->headers.producer) == le32_to_cpu(*q->headers.consumer)) { |
| 845 | status = 0; |
| 846 | } else { |
| 847 | /* |
| 848 | * The consumer index must be wrapped if we have reached |
| 849 | * the end of the queue, else we just use the entry |
| 850 | * pointed to by the header index |
| 851 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 852 | if (le32_to_cpu(*q->headers.consumer) >= q->entries) |
| 853 | index = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | else |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 855 | index = le32_to_cpu(*q->headers.consumer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | *entry = q->base + index; |
| 857 | status = 1; |
| 858 | } |
| 859 | return(status); |
| 860 | } |
| 861 | |
| 862 | /** |
| 863 | * aac_consumer_free - free consumer entry |
| 864 | * @dev: Adapter |
| 865 | * @q: Queue |
| 866 | * @qid: Queue ident |
| 867 | * |
| 868 | * Frees up the current top of the queue we are a consumer of. If the |
| 869 | * queue was full notify the producer that the queue is no longer full. |
| 870 | */ |
| 871 | |
| 872 | void aac_consumer_free(struct aac_dev * dev, struct aac_queue *q, u32 qid) |
| 873 | { |
| 874 | int wasfull = 0; |
| 875 | u32 notify; |
| 876 | |
| 877 | if ((le32_to_cpu(*q->headers.producer)+1) == le32_to_cpu(*q->headers.consumer)) |
| 878 | wasfull = 1; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | if (le32_to_cpu(*q->headers.consumer) >= q->entries) |
| 881 | *q->headers.consumer = cpu_to_le32(1); |
| 882 | else |
Marcin Slusarz | 36b8dd1 | 2008-03-28 14:48:35 -0700 | [diff] [blame] | 883 | le32_add_cpu(q->headers.consumer, 1); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | if (wasfull) { |
| 886 | switch (qid) { |
| 887 | |
| 888 | case HostNormCmdQueue: |
| 889 | notify = HostNormCmdNotFull; |
| 890 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | case HostNormRespQueue: |
| 892 | notify = HostNormRespNotFull; |
| 893 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | default: |
| 895 | BUG(); |
| 896 | return; |
| 897 | } |
| 898 | aac_adapter_notify(dev, notify); |
| 899 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 900 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
| 902 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 903 | * aac_fib_adapter_complete - complete adapter issued fib |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | * @fibptr: fib to complete |
| 905 | * @size: size of fib |
| 906 | * |
| 907 | * Will do all necessary work to complete a FIB that was sent from |
| 908 | * the adapter. |
| 909 | */ |
| 910 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 911 | int aac_fib_adapter_complete(struct fib *fibptr, unsigned short size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | { |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 913 | struct hw_fib * hw_fib = fibptr->hw_fib_va; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | struct aac_dev * dev = fibptr->dev; |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 915 | struct aac_queue * q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | unsigned long nointr = 0; |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 917 | unsigned long qflags; |
| 918 | |
Mahesh Rajashekhara | 85d22bb | 2012-07-14 18:18:51 +0530 | [diff] [blame] | 919 | if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 || |
Raghava Aditya Renukunta | d1ef4da | 2017-02-02 15:53:17 -0800 | [diff] [blame] | 920 | dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 || |
| 921 | dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) { |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 922 | kfree(hw_fib); |
| 923 | return 0; |
| 924 | } |
| 925 | |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 926 | if (hw_fib->header.XferState == 0) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 927 | if (dev->comm_interface == AAC_COMM_MESSAGE) |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 928 | kfree(hw_fib); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 929 | return 0; |
Mark Haverkamp | 1640a2c | 2005-09-20 12:57:11 -0700 | [diff] [blame] | 930 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | /* |
| 932 | * If we plan to do anything check the structure type first. |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 933 | */ |
Mahesh Rajashekhara | 85d22bb | 2012-07-14 18:18:51 +0530 | [diff] [blame] | 934 | if (hw_fib->header.StructType != FIB_MAGIC && |
| 935 | hw_fib->header.StructType != FIB_MAGIC2 && |
| 936 | hw_fib->header.StructType != FIB_MAGIC2_64) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 937 | if (dev->comm_interface == AAC_COMM_MESSAGE) |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 938 | kfree(hw_fib); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 939 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | } |
| 941 | /* |
| 942 | * This block handles the case where the adapter had sent us a |
| 943 | * command and we have finished processing the command. We |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 944 | * call completeFib when we are done processing the command |
| 945 | * and want to send a response back to the adapter. This will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | * send the completed cdb to the adapter. |
| 947 | */ |
| 948 | if (hw_fib->header.XferState & cpu_to_le32(SentFromAdapter)) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 949 | if (dev->comm_interface == AAC_COMM_MESSAGE) { |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 950 | kfree (hw_fib); |
| 951 | } else { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 952 | u32 index; |
| 953 | hw_fib->header.XferState |= cpu_to_le32(HostProcessed); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 954 | if (size) { |
| 955 | size += sizeof(struct aac_fibhdr); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 956 | if (size > le16_to_cpu(hw_fib->header.SenderSize)) |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 957 | return -EMSGSIZE; |
| 958 | hw_fib->header.Size = cpu_to_le16(size); |
| 959 | } |
| 960 | q = &dev->queues->queue[AdapNormRespQueue]; |
| 961 | spin_lock_irqsave(q->lock, qflags); |
| 962 | aac_queue_get(dev, &index, AdapNormRespQueue, hw_fib, 1, NULL, &nointr); |
| 963 | *(q->headers.producer) = cpu_to_le32(index + 1); |
| 964 | spin_unlock_irqrestore(q->lock, qflags); |
| 965 | if (!(nointr & (int)aac_config.irq_mod)) |
| 966 | aac_adapter_notify(dev, AdapNormRespQueue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 968 | } else { |
| 969 | printk(KERN_WARNING "aac_fib_adapter_complete: " |
| 970 | "Unknown xferstate detected.\n"); |
| 971 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | return 0; |
| 974 | } |
| 975 | |
| 976 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 977 | * aac_fib_complete - fib completion handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | * @fib: FIB to complete |
| 979 | * |
| 980 | * Will do all necessary work to complete a FIB. |
| 981 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 982 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 983 | int aac_fib_complete(struct fib *fibptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | { |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 985 | struct hw_fib * hw_fib = fibptr->hw_fib_va; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | |
Raghava Aditya Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 987 | if (fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA) { |
| 988 | fib_dealloc(fibptr); |
| 989 | return 0; |
| 990 | } |
| 991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | /* |
Raghava Aditya Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 993 | * Check for a fib which has already been completed or with a |
| 994 | * status wait timeout |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | */ |
| 996 | |
Raghava Aditya Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 997 | if (hw_fib->header.XferState == 0 || fibptr->done == 2) |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 998 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | /* |
| 1000 | * If we plan to do anything check the structure type first. |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1001 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
Mahesh Rajashekhara | 85d22bb | 2012-07-14 18:18:51 +0530 | [diff] [blame] | 1003 | if (hw_fib->header.StructType != FIB_MAGIC && |
| 1004 | hw_fib->header.StructType != FIB_MAGIC2 && |
| 1005 | hw_fib->header.StructType != FIB_MAGIC2_64) |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1006 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | /* |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1008 | * This block completes a cdb which orginated on the host and we |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | * just need to deallocate the cdb or reinit it. At this point the |
| 1010 | * command is complete that we had sent to the adapter and this |
| 1011 | * cdb could be reused. |
| 1012 | */ |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 1013 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | if((hw_fib->header.XferState & cpu_to_le32(SentFromHost)) && |
| 1015 | (hw_fib->header.XferState & cpu_to_le32(AdapterProcessed))) |
| 1016 | { |
| 1017 | fib_dealloc(fibptr); |
| 1018 | } |
| 1019 | else if(hw_fib->header.XferState & cpu_to_le32(SentFromHost)) |
| 1020 | { |
| 1021 | /* |
| 1022 | * This handles the case when the host has aborted the I/O |
| 1023 | * to the adapter because the adapter is not responding |
| 1024 | */ |
| 1025 | fib_dealloc(fibptr); |
| 1026 | } else if(hw_fib->header.XferState & cpu_to_le32(HostOwned)) { |
| 1027 | fib_dealloc(fibptr); |
| 1028 | } else { |
| 1029 | BUG(); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1030 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | /** |
| 1035 | * aac_printf - handle printf from firmware |
| 1036 | * @dev: Adapter |
| 1037 | * @val: Message info |
| 1038 | * |
| 1039 | * Print a message passed to us by the controller firmware on the |
| 1040 | * Adaptec board |
| 1041 | */ |
| 1042 | |
| 1043 | void aac_printf(struct aac_dev *dev, u32 val) |
| 1044 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | char *cp = dev->printfbuf; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1046 | if (dev->printf_enabled) |
| 1047 | { |
| 1048 | int length = val & 0xffff; |
| 1049 | int level = (val >> 16) & 0xffff; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1050 | |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1051 | /* |
| 1052 | * The size of the printfbuf is set in port.c |
| 1053 | * There is no variable or define for it |
| 1054 | */ |
| 1055 | if (length > 255) |
| 1056 | length = 255; |
| 1057 | if (cp[length] != 0) |
| 1058 | cp[length] = 0; |
| 1059 | if (level == LOG_AAC_HIGH_ERROR) |
Mark Haverkamp | 1241f35 | 2006-03-27 09:44:23 -0800 | [diff] [blame] | 1060 | printk(KERN_WARNING "%s:%s", dev->name, cp); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1061 | else |
Mark Haverkamp | 1241f35 | 2006-03-27 09:44:23 -0800 | [diff] [blame] | 1062 | printk(KERN_INFO "%s:%s", dev->name, cp); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1063 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1064 | memset(cp, 0, 256); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
Raghava Aditya Renukunta | 9cb62fa | 2016-04-25 23:32:09 -0700 | [diff] [blame] | 1067 | static inline int aac_aif_data(struct aac_aifcmd *aifcmd, uint32_t index) |
| 1068 | { |
| 1069 | return le32_to_cpu(((__le32 *)aifcmd->data)[index]); |
| 1070 | } |
| 1071 | |
| 1072 | |
| 1073 | static void aac_handle_aif_bu(struct aac_dev *dev, struct aac_aifcmd *aifcmd) |
| 1074 | { |
| 1075 | switch (aac_aif_data(aifcmd, 1)) { |
| 1076 | case AifBuCacheDataLoss: |
| 1077 | if (aac_aif_data(aifcmd, 2)) |
| 1078 | dev_info(&dev->pdev->dev, "Backup unit had cache data loss - [%d]\n", |
| 1079 | aac_aif_data(aifcmd, 2)); |
| 1080 | else |
| 1081 | dev_info(&dev->pdev->dev, "Backup Unit had cache data loss\n"); |
| 1082 | break; |
| 1083 | case AifBuCacheDataRecover: |
| 1084 | if (aac_aif_data(aifcmd, 2)) |
| 1085 | dev_info(&dev->pdev->dev, "DDR cache data recovered successfully - [%d]\n", |
| 1086 | aac_aif_data(aifcmd, 2)); |
| 1087 | else |
| 1088 | dev_info(&dev->pdev->dev, "DDR cache data recovered successfully\n"); |
| 1089 | break; |
| 1090 | } |
| 1091 | } |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1092 | |
| 1093 | /** |
| 1094 | * aac_handle_aif - Handle a message from the firmware |
| 1095 | * @dev: Which adapter this fib is from |
| 1096 | * @fibptr: Pointer to fibptr from adapter |
| 1097 | * |
| 1098 | * This routine handles a driver notify fib from the adapter and |
| 1099 | * dispatches it to the appropriate routine for handling. |
| 1100 | */ |
| 1101 | |
Mahesh Rajashekhara | 495c021 | 2015-03-26 10:41:25 -0400 | [diff] [blame] | 1102 | #define AIF_SNIFF_TIMEOUT (500*HZ) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1103 | static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr) |
| 1104 | { |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 1105 | struct hw_fib * hw_fib = fibptr->hw_fib_va; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1106 | struct aac_aifcmd * aifcmd = (struct aac_aifcmd *)hw_fib->data; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1107 | u32 channel, id, lun, container; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1108 | struct scsi_device *device; |
| 1109 | enum { |
| 1110 | NOTHING, |
| 1111 | DELETE, |
| 1112 | ADD, |
| 1113 | CHANGE |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1114 | } device_config_needed = NOTHING; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1115 | |
| 1116 | /* Sniff for container changes */ |
| 1117 | |
Mark Haverkamp | c8f7b07 | 2006-08-03 08:02:24 -0700 | [diff] [blame] | 1118 | if (!dev || !dev->fsa_dev) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1119 | return; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1120 | container = channel = id = lun = (u32)-1; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1121 | |
| 1122 | /* |
| 1123 | * We have set this up to try and minimize the number of |
| 1124 | * re-configures that take place. As a result of this when |
| 1125 | * certain AIF's come in we will set a flag waiting for another |
| 1126 | * type of AIF before setting the re-config flag. |
| 1127 | */ |
| 1128 | switch (le32_to_cpu(aifcmd->command)) { |
| 1129 | case AifCmdDriverNotify: |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1130 | switch (le32_to_cpu(((__le32 *)aifcmd->data)[0])) { |
Mahesh Rajashekhara | dab04b0 | 2015-03-26 10:41:31 -0400 | [diff] [blame] | 1131 | case AifRawDeviceRemove: |
| 1132 | container = le32_to_cpu(((__le32 *)aifcmd->data)[1]); |
| 1133 | if ((container >> 28)) { |
| 1134 | container = (u32)-1; |
| 1135 | break; |
| 1136 | } |
| 1137 | channel = (container >> 24) & 0xF; |
| 1138 | if (channel >= dev->maximum_num_channels) { |
| 1139 | container = (u32)-1; |
| 1140 | break; |
| 1141 | } |
| 1142 | id = container & 0xFFFF; |
| 1143 | if (id >= dev->maximum_num_physicals) { |
| 1144 | container = (u32)-1; |
| 1145 | break; |
| 1146 | } |
| 1147 | lun = (container >> 16) & 0xFF; |
| 1148 | container = (u32)-1; |
| 1149 | channel = aac_phys_to_logical(channel); |
Raghava Aditya Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 1150 | device_config_needed = DELETE; |
Mahesh Rajashekhara | dab04b0 | 2015-03-26 10:41:31 -0400 | [diff] [blame] | 1151 | break; |
Raghava Aditya Renukunta | 423400e | 2017-02-02 15:53:29 -0800 | [diff] [blame] | 1152 | |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1153 | /* |
| 1154 | * Morph or Expand complete |
| 1155 | */ |
| 1156 | case AifDenMorphComplete: |
| 1157 | case AifDenVolumeExtendComplete: |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1158 | container = le32_to_cpu(((__le32 *)aifcmd->data)[1]); |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1159 | if (container >= dev->maximum_num_containers) |
| 1160 | break; |
| 1161 | |
| 1162 | /* |
Christoph Hellwig | f64a181 | 2005-10-31 18:32:08 +0100 | [diff] [blame] | 1163 | * Find the scsi_device associated with the SCSI |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1164 | * address. Make sure we have the right array, and if |
| 1165 | * so set the flag to initiate a new re-config once we |
| 1166 | * see an AifEnConfigChange AIF come through. |
| 1167 | */ |
| 1168 | |
| 1169 | if ((dev != NULL) && (dev->scsi_host_ptr != NULL)) { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1170 | device = scsi_device_lookup(dev->scsi_host_ptr, |
| 1171 | CONTAINER_TO_CHANNEL(container), |
| 1172 | CONTAINER_TO_ID(container), |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1173 | CONTAINER_TO_LUN(container)); |
| 1174 | if (device) { |
| 1175 | dev->fsa_dev[container].config_needed = CHANGE; |
| 1176 | dev->fsa_dev[container].config_waiting_on = AifEnConfigChange; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1177 | dev->fsa_dev[container].config_waiting_stamp = jiffies; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1178 | scsi_device_put(device); |
| 1179 | } |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | /* |
| 1184 | * If we are waiting on something and this happens to be |
| 1185 | * that thing then set the re-configure flag. |
| 1186 | */ |
| 1187 | if (container != (u32)-1) { |
| 1188 | if (container >= dev->maximum_num_containers) |
| 1189 | break; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1190 | if ((dev->fsa_dev[container].config_waiting_on == |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1191 | le32_to_cpu(*(__le32 *)aifcmd->data)) && |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1192 | time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1193 | dev->fsa_dev[container].config_waiting_on = 0; |
| 1194 | } else for (container = 0; |
| 1195 | container < dev->maximum_num_containers; ++container) { |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1196 | if ((dev->fsa_dev[container].config_waiting_on == |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1197 | le32_to_cpu(*(__le32 *)aifcmd->data)) && |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1198 | time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1199 | dev->fsa_dev[container].config_waiting_on = 0; |
| 1200 | } |
| 1201 | break; |
| 1202 | |
| 1203 | case AifCmdEventNotify: |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1204 | switch (le32_to_cpu(((__le32 *)aifcmd->data)[0])) { |
Salyzyn, Mark | 95e852e | 2008-01-08 12:01:07 -0800 | [diff] [blame] | 1205 | case AifEnBatteryEvent: |
| 1206 | dev->cache_protected = |
| 1207 | (((__le32 *)aifcmd->data)[1] == cpu_to_le32(3)); |
| 1208 | break; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1209 | /* |
| 1210 | * Add an Array. |
| 1211 | */ |
| 1212 | case AifEnAddContainer: |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1213 | container = le32_to_cpu(((__le32 *)aifcmd->data)[1]); |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1214 | if (container >= dev->maximum_num_containers) |
| 1215 | break; |
| 1216 | dev->fsa_dev[container].config_needed = ADD; |
| 1217 | dev->fsa_dev[container].config_waiting_on = |
| 1218 | AifEnConfigChange; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1219 | dev->fsa_dev[container].config_waiting_stamp = jiffies; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1220 | break; |
| 1221 | |
| 1222 | /* |
| 1223 | * Delete an Array. |
| 1224 | */ |
| 1225 | case AifEnDeleteContainer: |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1226 | container = le32_to_cpu(((__le32 *)aifcmd->data)[1]); |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1227 | if (container >= dev->maximum_num_containers) |
| 1228 | break; |
| 1229 | dev->fsa_dev[container].config_needed = DELETE; |
| 1230 | dev->fsa_dev[container].config_waiting_on = |
| 1231 | AifEnConfigChange; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1232 | dev->fsa_dev[container].config_waiting_stamp = jiffies; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1233 | break; |
| 1234 | |
| 1235 | /* |
| 1236 | * Container change detected. If we currently are not |
| 1237 | * waiting on something else, setup to wait on a Config Change. |
| 1238 | */ |
| 1239 | case AifEnContainerChange: |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1240 | container = le32_to_cpu(((__le32 *)aifcmd->data)[1]); |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1241 | if (container >= dev->maximum_num_containers) |
| 1242 | break; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1243 | if (dev->fsa_dev[container].config_waiting_on && |
| 1244 | time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1245 | break; |
| 1246 | dev->fsa_dev[container].config_needed = CHANGE; |
| 1247 | dev->fsa_dev[container].config_waiting_on = |
| 1248 | AifEnConfigChange; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1249 | dev->fsa_dev[container].config_waiting_stamp = jiffies; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1250 | break; |
| 1251 | |
| 1252 | case AifEnConfigChange: |
| 1253 | break; |
| 1254 | |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1255 | case AifEnAddJBOD: |
| 1256 | case AifEnDeleteJBOD: |
| 1257 | container = le32_to_cpu(((__le32 *)aifcmd->data)[1]); |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1258 | if ((container >> 28)) { |
| 1259 | container = (u32)-1; |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1260 | break; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1261 | } |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1262 | channel = (container >> 24) & 0xF; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1263 | if (channel >= dev->maximum_num_channels) { |
| 1264 | container = (u32)-1; |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1265 | break; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1266 | } |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1267 | id = container & 0xFFFF; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1268 | if (id >= dev->maximum_num_physicals) { |
| 1269 | container = (u32)-1; |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1270 | break; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1271 | } |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1272 | lun = (container >> 16) & 0xFF; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1273 | container = (u32)-1; |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1274 | channel = aac_phys_to_logical(channel); |
| 1275 | device_config_needed = |
| 1276 | (((__le32 *)aifcmd->data)[0] == |
| 1277 | cpu_to_le32(AifEnAddJBOD)) ? ADD : DELETE; |
Rajashekhara, Mahesh | 5ca0559 | 2010-05-10 04:05:50 -0700 | [diff] [blame] | 1278 | if (device_config_needed == ADD) { |
| 1279 | device = scsi_device_lookup(dev->scsi_host_ptr, |
| 1280 | channel, |
| 1281 | id, |
| 1282 | lun); |
| 1283 | if (device) { |
| 1284 | scsi_remove_device(device); |
| 1285 | scsi_device_put(device); |
| 1286 | } |
| 1287 | } |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1288 | break; |
| 1289 | |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1290 | case AifEnEnclosureManagement: |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1291 | /* |
| 1292 | * If in JBOD mode, automatic exposure of new |
| 1293 | * physical target to be suppressed until configured. |
| 1294 | */ |
| 1295 | if (dev->jbod) |
| 1296 | break; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1297 | switch (le32_to_cpu(((__le32 *)aifcmd->data)[3])) { |
| 1298 | case EM_DRIVE_INSERTION: |
| 1299 | case EM_DRIVE_REMOVAL: |
Mahesh Rajashekhara | 46154a0 | 2015-03-26 10:41:22 -0400 | [diff] [blame] | 1300 | case EM_SES_DRIVE_INSERTION: |
| 1301 | case EM_SES_DRIVE_REMOVAL: |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1302 | container = le32_to_cpu( |
| 1303 | ((__le32 *)aifcmd->data)[2]); |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1304 | if ((container >> 28)) { |
| 1305 | container = (u32)-1; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1306 | break; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1307 | } |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1308 | channel = (container >> 24) & 0xF; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1309 | if (channel >= dev->maximum_num_channels) { |
| 1310 | container = (u32)-1; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1311 | break; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1312 | } |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1313 | id = container & 0xFFFF; |
| 1314 | lun = (container >> 16) & 0xFF; |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1315 | container = (u32)-1; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1316 | if (id >= dev->maximum_num_physicals) { |
| 1317 | /* legacy dev_t ? */ |
| 1318 | if ((0x2000 <= id) || lun || channel || |
| 1319 | ((channel = (id >> 7) & 0x3F) >= |
| 1320 | dev->maximum_num_channels)) |
| 1321 | break; |
| 1322 | lun = (id >> 4) & 7; |
| 1323 | id &= 0xF; |
| 1324 | } |
| 1325 | channel = aac_phys_to_logical(channel); |
| 1326 | device_config_needed = |
Mahesh Rajashekhara | 46154a0 | 2015-03-26 10:41:22 -0400 | [diff] [blame] | 1327 | ((((__le32 *)aifcmd->data)[3] |
| 1328 | == cpu_to_le32(EM_DRIVE_INSERTION)) || |
| 1329 | (((__le32 *)aifcmd->data)[3] |
| 1330 | == cpu_to_le32(EM_SES_DRIVE_INSERTION))) ? |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1331 | ADD : DELETE; |
| 1332 | break; |
| 1333 | } |
Raghava Aditya Renukunta | 9cb62fa | 2016-04-25 23:32:09 -0700 | [diff] [blame] | 1334 | case AifBuManagerEvent: |
| 1335 | aac_handle_aif_bu(dev, aifcmd); |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1336 | break; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | /* |
| 1340 | * If we are waiting on something and this happens to be |
| 1341 | * that thing then set the re-configure flag. |
| 1342 | */ |
| 1343 | if (container != (u32)-1) { |
| 1344 | if (container >= dev->maximum_num_containers) |
| 1345 | break; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1346 | if ((dev->fsa_dev[container].config_waiting_on == |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1347 | le32_to_cpu(*(__le32 *)aifcmd->data)) && |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1348 | time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1349 | dev->fsa_dev[container].config_waiting_on = 0; |
| 1350 | } else for (container = 0; |
| 1351 | container < dev->maximum_num_containers; ++container) { |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1352 | if ((dev->fsa_dev[container].config_waiting_on == |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1353 | le32_to_cpu(*(__le32 *)aifcmd->data)) && |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1354 | time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1355 | dev->fsa_dev[container].config_waiting_on = 0; |
| 1356 | } |
| 1357 | break; |
| 1358 | |
| 1359 | case AifCmdJobProgress: |
| 1360 | /* |
| 1361 | * These are job progress AIF's. When a Clear is being |
| 1362 | * done on a container it is initially created then hidden from |
| 1363 | * the OS. When the clear completes we don't get a config |
| 1364 | * change so we monitor the job status complete on a clear then |
| 1365 | * wait for a container change. |
| 1366 | */ |
| 1367 | |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1368 | if (((__le32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero) && |
| 1369 | (((__le32 *)aifcmd->data)[6] == ((__le32 *)aifcmd->data)[5] || |
| 1370 | ((__le32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsSuccess))) { |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1371 | for (container = 0; |
| 1372 | container < dev->maximum_num_containers; |
| 1373 | ++container) { |
| 1374 | /* |
| 1375 | * Stomp on all config sequencing for all |
| 1376 | * containers? |
| 1377 | */ |
| 1378 | dev->fsa_dev[container].config_waiting_on = |
| 1379 | AifEnContainerChange; |
| 1380 | dev->fsa_dev[container].config_needed = ADD; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1381 | dev->fsa_dev[container].config_waiting_stamp = |
| 1382 | jiffies; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1383 | } |
| 1384 | } |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1385 | if (((__le32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero) && |
| 1386 | ((__le32 *)aifcmd->data)[6] == 0 && |
| 1387 | ((__le32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsRunning)) { |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1388 | for (container = 0; |
| 1389 | container < dev->maximum_num_containers; |
| 1390 | ++container) { |
| 1391 | /* |
| 1392 | * Stomp on all config sequencing for all |
| 1393 | * containers? |
| 1394 | */ |
| 1395 | dev->fsa_dev[container].config_waiting_on = |
| 1396 | AifEnContainerChange; |
| 1397 | dev->fsa_dev[container].config_needed = DELETE; |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1398 | dev->fsa_dev[container].config_waiting_stamp = |
| 1399 | jiffies; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1400 | } |
| 1401 | } |
| 1402 | break; |
| 1403 | } |
| 1404 | |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1405 | container = 0; |
| 1406 | retry_next: |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1407 | if (device_config_needed == NOTHING) |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1408 | for (; container < dev->maximum_num_containers; ++container) { |
Mark Haverkamp | 31876f3 | 2006-03-27 09:43:55 -0800 | [diff] [blame] | 1409 | if ((dev->fsa_dev[container].config_waiting_on == 0) && |
| 1410 | (dev->fsa_dev[container].config_needed != NOTHING) && |
| 1411 | time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) { |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1412 | device_config_needed = |
| 1413 | dev->fsa_dev[container].config_needed; |
| 1414 | dev->fsa_dev[container].config_needed = NOTHING; |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1415 | channel = CONTAINER_TO_CHANNEL(container); |
| 1416 | id = CONTAINER_TO_ID(container); |
| 1417 | lun = CONTAINER_TO_LUN(container); |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1418 | break; |
| 1419 | } |
| 1420 | } |
| 1421 | if (device_config_needed == NOTHING) |
| 1422 | return; |
| 1423 | |
| 1424 | /* |
| 1425 | * If we decided that a re-configuration needs to be done, |
| 1426 | * schedule it here on the way out the door, please close the door |
| 1427 | * behind you. |
| 1428 | */ |
| 1429 | |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1430 | /* |
Christoph Hellwig | f64a181 | 2005-10-31 18:32:08 +0100 | [diff] [blame] | 1431 | * Find the scsi_device associated with the SCSI address, |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1432 | * and mark it as changed, invalidating the cache. This deals |
| 1433 | * with changes to existing device IDs. |
| 1434 | */ |
| 1435 | |
| 1436 | if (!dev || !dev->scsi_host_ptr) |
| 1437 | return; |
| 1438 | /* |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1439 | * force reload of disk info via aac_probe_container |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1440 | */ |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1441 | if ((channel == CONTAINER_CHANNEL) && |
| 1442 | (device_config_needed != NOTHING)) { |
| 1443 | if (dev->fsa_dev[container].valid == 1) |
| 1444 | dev->fsa_dev[container].valid = 2; |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1445 | aac_probe_container(dev, container); |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1446 | } |
| 1447 | device = scsi_device_lookup(dev->scsi_host_ptr, channel, id, lun); |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1448 | if (device) { |
| 1449 | switch (device_config_needed) { |
| 1450 | case DELETE: |
Rajashekhara, Mahesh | 9cccde9 | 2010-05-10 04:29:25 -0700 | [diff] [blame] | 1451 | #if (defined(AAC_DEBUG_INSTRUMENT_AIF_DELETE)) |
| 1452 | scsi_remove_device(device); |
| 1453 | #else |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1454 | if (scsi_device_online(device)) { |
| 1455 | scsi_device_set_state(device, SDEV_OFFLINE); |
| 1456 | sdev_printk(KERN_INFO, device, |
| 1457 | "Device offlined - %s\n", |
| 1458 | (channel == CONTAINER_CHANNEL) ? |
| 1459 | "array deleted" : |
| 1460 | "enclosure services event"); |
| 1461 | } |
Rajashekhara, Mahesh | 9cccde9 | 2010-05-10 04:29:25 -0700 | [diff] [blame] | 1462 | #endif |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1463 | break; |
| 1464 | case ADD: |
| 1465 | if (!scsi_device_online(device)) { |
| 1466 | sdev_printk(KERN_INFO, device, |
| 1467 | "Device online - %s\n", |
| 1468 | (channel == CONTAINER_CHANNEL) ? |
| 1469 | "array created" : |
| 1470 | "enclosure services event"); |
| 1471 | scsi_device_set_state(device, SDEV_RUNNING); |
| 1472 | } |
| 1473 | /* FALLTHRU */ |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1474 | case CHANGE: |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1475 | if ((channel == CONTAINER_CHANNEL) |
| 1476 | && (!dev->fsa_dev[container].valid)) { |
Rajashekhara, Mahesh | 9cccde9 | 2010-05-10 04:29:25 -0700 | [diff] [blame] | 1477 | #if (defined(AAC_DEBUG_INSTRUMENT_AIF_DELETE)) |
| 1478 | scsi_remove_device(device); |
| 1479 | #else |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1480 | if (!scsi_device_online(device)) |
| 1481 | break; |
| 1482 | scsi_device_set_state(device, SDEV_OFFLINE); |
| 1483 | sdev_printk(KERN_INFO, device, |
| 1484 | "Device offlined - %s\n", |
| 1485 | "array failed"); |
Rajashekhara, Mahesh | 9cccde9 | 2010-05-10 04:29:25 -0700 | [diff] [blame] | 1486 | #endif |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1487 | break; |
| 1488 | } |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1489 | scsi_rescan_device(&device->sdev_gendev); |
| 1490 | |
| 1491 | default: |
| 1492 | break; |
| 1493 | } |
| 1494 | scsi_device_put(device); |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1495 | device_config_needed = NOTHING; |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1496 | } |
Salyzyn, Mark | 0995ad3 | 2008-01-11 11:56:07 -0800 | [diff] [blame] | 1497 | if (device_config_needed == ADD) |
| 1498 | scsi_add_device(dev->scsi_host_ptr, channel, id, lun); |
Mark Salyzyn | a4576b5 | 2008-04-30 15:47:35 -0400 | [diff] [blame] | 1499 | if (channel == CONTAINER_CHANNEL) { |
| 1500 | container++; |
| 1501 | device_config_needed = NOTHING; |
| 1502 | goto retry_next; |
| 1503 | } |
Mark Haverkamp | 131256c | 2005-09-26 13:04:56 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
Raghava Aditya Renukunta | 3136432 | 2017-02-02 15:53:33 -0800 | [diff] [blame] | 1506 | static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type) |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1507 | { |
| 1508 | int index, quirks; |
Mahesh Rajashekhara | 8b1462e | 2015-08-28 06:38:38 -0400 | [diff] [blame] | 1509 | int retval; |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1510 | struct Scsi_Host *host; |
| 1511 | struct scsi_device *dev; |
| 1512 | struct scsi_cmnd *command; |
| 1513 | struct scsi_cmnd *command_list; |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1514 | int jafo = 0; |
Raghava Aditya Renukunta | 3136432 | 2017-02-02 15:53:33 -0800 | [diff] [blame] | 1515 | int bled; |
Raghava Aditya Renukunta | 8105d39 | 2017-05-10 09:39:36 -0700 | [diff] [blame] | 1516 | u64 dmamask; |
Raghava Aditya Renukunta | 8c41b9b | 2017-05-10 09:39:49 -0700 | [diff] [blame] | 1517 | int num_of_fibs = 0; |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1518 | |
| 1519 | /* |
| 1520 | * Assumptions: |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1521 | * - host is locked, unless called by the aacraid thread. |
| 1522 | * (a matter of convenience, due to legacy issues surrounding |
| 1523 | * eh_host_adapter_reset). |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1524 | * - in_reset is asserted, so no new i/o is getting to the |
| 1525 | * card. |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1526 | * - The card is dead, or will be very shortly ;-/ so no new |
| 1527 | * commands are completing in the interrupt service. |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1528 | */ |
| 1529 | host = aac->scsi_host_ptr; |
| 1530 | scsi_block_requests(host); |
| 1531 | aac_adapter_disable_int(aac); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1532 | if (aac->thread->pid != current->pid) { |
| 1533 | spin_unlock_irq(host->host_lock); |
| 1534 | kthread_stop(aac->thread); |
| 1535 | jafo = 1; |
| 1536 | } |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1537 | |
| 1538 | /* |
| 1539 | * If a positive health, means in a known DEAD PANIC |
| 1540 | * state and the adapter could be reset to `try again'. |
| 1541 | */ |
Raghava Aditya Renukunta | 3136432 | 2017-02-02 15:53:33 -0800 | [diff] [blame] | 1542 | bled = forced ? 0 : aac_adapter_check_health(aac); |
| 1543 | retval = aac_adapter_restart(aac, bled, reset_type); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1544 | |
| 1545 | if (retval) |
| 1546 | goto out; |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1547 | |
Mark Haverkamp | d18b448 | 2006-11-21 10:40:31 -0800 | [diff] [blame] | 1548 | /* |
| 1549 | * Loop through the fibs, close the synchronous FIBS |
| 1550 | */ |
Raghava Aditya Renukunta | 8c41b9b | 2017-05-10 09:39:49 -0700 | [diff] [blame] | 1551 | retval = 1; |
| 1552 | num_of_fibs = aac->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB; |
| 1553 | for (index = 0; index < num_of_fibs; index++) { |
| 1554 | |
Mark Haverkamp | d18b448 | 2006-11-21 10:40:31 -0800 | [diff] [blame] | 1555 | struct fib *fib = &aac->fibs[index]; |
Raghava Aditya Renukunta | 8c41b9b | 2017-05-10 09:39:49 -0700 | [diff] [blame] | 1556 | __le32 XferState = fib->hw_fib_va->header.XferState; |
| 1557 | bool is_response_expected = false; |
| 1558 | |
| 1559 | if (!(XferState & cpu_to_le32(NoResponseExpected | Async)) && |
| 1560 | (XferState & cpu_to_le32(ResponseExpected))) |
| 1561 | is_response_expected = true; |
| 1562 | |
| 1563 | if (is_response_expected |
| 1564 | || fib->flags & FIB_CONTEXT_FLAG_WAIT) { |
Mark Haverkamp | d18b448 | 2006-11-21 10:40:31 -0800 | [diff] [blame] | 1565 | unsigned long flagv; |
| 1566 | spin_lock_irqsave(&fib->event_lock, flagv); |
| 1567 | up(&fib->event_wait); |
| 1568 | spin_unlock_irqrestore(&fib->event_lock, flagv); |
| 1569 | schedule(); |
Mark Haverkamp | 33bb3b2 | 2007-03-15 10:27:21 -0700 | [diff] [blame] | 1570 | retval = 0; |
Mark Haverkamp | d18b448 | 2006-11-21 10:40:31 -0800 | [diff] [blame] | 1571 | } |
| 1572 | } |
Mark Haverkamp | 33bb3b2 | 2007-03-15 10:27:21 -0700 | [diff] [blame] | 1573 | /* Give some extra time for ioctls to complete. */ |
| 1574 | if (retval == 0) |
| 1575 | ssleep(2); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1576 | index = aac->cardtype; |
| 1577 | |
| 1578 | /* |
| 1579 | * Re-initialize the adapter, first free resources, then carefully |
| 1580 | * apply the initialization sequence to come back again. Only risk |
| 1581 | * is a change in Firmware dropping cache, it is assumed the caller |
| 1582 | * will ensure that i/o is queisced and the card is flushed in that |
| 1583 | * case. |
| 1584 | */ |
| 1585 | aac_fib_map_free(aac); |
Mahesh Rajashekhara | f481973 | 2017-04-05 16:14:16 +0530 | [diff] [blame] | 1586 | dma_free_coherent(&aac->pdev->dev, aac->comm_size, aac->comm_addr, |
| 1587 | aac->comm_phys); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1588 | aac->comm_addr = NULL; |
| 1589 | aac->comm_phys = 0; |
| 1590 | kfree(aac->queues); |
| 1591 | aac->queues = NULL; |
Mahesh Rajashekhara | 8b1462e | 2015-08-28 06:38:38 -0400 | [diff] [blame] | 1592 | aac_free_irq(aac); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1593 | kfree(aac->fsa_dev); |
| 1594 | aac->fsa_dev = NULL; |
Raghava Aditya Renukunta | 8105d39 | 2017-05-10 09:39:36 -0700 | [diff] [blame] | 1595 | |
| 1596 | dmamask = DMA_BIT_MASK(32); |
Salyzyn, Mark | 94cf6ba | 2007-12-13 16:14:18 -0800 | [diff] [blame] | 1597 | quirks = aac_get_driver_ident(index)->quirks; |
Raghava Aditya Renukunta | 8105d39 | 2017-05-10 09:39:36 -0700 | [diff] [blame] | 1598 | if (quirks & AAC_QUIRK_31BIT) |
| 1599 | retval = pci_set_dma_mask(aac->pdev, dmamask); |
| 1600 | else if (!(quirks & AAC_QUIRK_SRC)) |
| 1601 | retval = pci_set_dma_mask(aac->pdev, dmamask); |
| 1602 | else |
| 1603 | retval = pci_set_consistent_dma_mask(aac->pdev, dmamask); |
| 1604 | |
| 1605 | if (quirks & AAC_QUIRK_31BIT && !retval) { |
| 1606 | dmamask = DMA_BIT_MASK(31); |
| 1607 | retval = pci_set_consistent_dma_mask(aac->pdev, dmamask); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1608 | } |
Raghava Aditya Renukunta | 8105d39 | 2017-05-10 09:39:36 -0700 | [diff] [blame] | 1609 | |
| 1610 | if (retval) |
| 1611 | goto out; |
| 1612 | |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1613 | if ((retval = (*(aac_get_driver_ident(index)->init))(aac))) |
| 1614 | goto out; |
Raghava Aditya Renukunta | 8105d39 | 2017-05-10 09:39:36 -0700 | [diff] [blame] | 1615 | |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1616 | if (jafo) { |
Kees Cook | f170168 | 2013-07-03 15:04:58 -0700 | [diff] [blame] | 1617 | aac->thread = kthread_run(aac_command_thread, aac, "%s", |
| 1618 | aac->name); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1619 | if (IS_ERR(aac->thread)) { |
| 1620 | retval = PTR_ERR(aac->thread); |
| 1621 | goto out; |
| 1622 | } |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1623 | } |
| 1624 | (void)aac_get_adapter_info(aac); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1625 | if ((quirks & AAC_QUIRK_34SG) && (host->sg_tablesize > 34)) { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1626 | host->sg_tablesize = 34; |
| 1627 | host->max_sectors = (host->sg_tablesize * 8) + 112; |
| 1628 | } |
| 1629 | if ((quirks & AAC_QUIRK_17SG) && (host->sg_tablesize > 17)) { |
| 1630 | host->sg_tablesize = 17; |
| 1631 | host->max_sectors = (host->sg_tablesize * 8) + 112; |
| 1632 | } |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1633 | aac_get_config_status(aac, 1); |
| 1634 | aac_get_containers(aac); |
| 1635 | /* |
| 1636 | * This is where the assumption that the Adapter is quiesced |
| 1637 | * is important. |
| 1638 | */ |
| 1639 | command_list = NULL; |
| 1640 | __shost_for_each_device(dev, host) { |
| 1641 | unsigned long flags; |
| 1642 | spin_lock_irqsave(&dev->list_lock, flags); |
| 1643 | list_for_each_entry(command, &dev->cmd_list, list) |
| 1644 | if (command->SCp.phase == AAC_OWNER_FIRMWARE) { |
| 1645 | command->SCp.buffer = (struct scatterlist *)command_list; |
| 1646 | command_list = command; |
| 1647 | } |
| 1648 | spin_unlock_irqrestore(&dev->list_lock, flags); |
| 1649 | } |
| 1650 | while ((command = command_list)) { |
| 1651 | command_list = (struct scsi_cmnd *)command->SCp.buffer; |
| 1652 | command->SCp.buffer = NULL; |
| 1653 | command->result = DID_OK << 16 |
| 1654 | | COMMAND_COMPLETE << 8 |
| 1655 | | SAM_STAT_TASK_SET_FULL; |
| 1656 | command->SCp.phase = AAC_OWNER_ERROR_HANDLER; |
| 1657 | command->scsi_done(command); |
| 1658 | } |
Raghava Aditya Renukunta | a2d0321 | 2017-02-16 12:51:18 -0800 | [diff] [blame] | 1659 | /* |
| 1660 | * Any Device that was already marked offline needs to be cleaned up |
| 1661 | */ |
| 1662 | __shost_for_each_device(dev, host) { |
| 1663 | if (!scsi_device_online(dev)) { |
| 1664 | sdev_printk(KERN_INFO, dev, "Removing offline device\n"); |
| 1665 | scsi_remove_device(dev); |
| 1666 | scsi_device_put(dev); |
| 1667 | } |
| 1668 | } |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1669 | retval = 0; |
| 1670 | |
| 1671 | out: |
| 1672 | aac->in_reset = 0; |
| 1673 | scsi_unblock_requests(host); |
Raghava Aditya Renukunta | a2d0321 | 2017-02-16 12:51:18 -0800 | [diff] [blame] | 1674 | /* |
| 1675 | * Issue bus rescan to catch any configuration that might have |
| 1676 | * occurred |
| 1677 | */ |
| 1678 | if (!retval) { |
| 1679 | dev_info(&aac->pdev->dev, "Issuing bus rescan\n"); |
| 1680 | scsi_scan_host(host); |
| 1681 | } |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1682 | if (jafo) { |
| 1683 | spin_lock_irq(host->host_lock); |
| 1684 | } |
| 1685 | return retval; |
| 1686 | } |
| 1687 | |
Raghava Aditya Renukunta | 3136432 | 2017-02-02 15:53:33 -0800 | [diff] [blame] | 1688 | int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type) |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1689 | { |
| 1690 | unsigned long flagv = 0; |
| 1691 | int retval; |
| 1692 | struct Scsi_Host * host; |
Raghava Aditya Renukunta | 3136432 | 2017-02-02 15:53:33 -0800 | [diff] [blame] | 1693 | int bled; |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1694 | |
| 1695 | if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0) |
| 1696 | return -EBUSY; |
| 1697 | |
| 1698 | if (aac->in_reset) { |
| 1699 | spin_unlock_irqrestore(&aac->fib_lock, flagv); |
| 1700 | return -EBUSY; |
| 1701 | } |
| 1702 | aac->in_reset = 1; |
| 1703 | spin_unlock_irqrestore(&aac->fib_lock, flagv); |
| 1704 | |
| 1705 | /* |
| 1706 | * Wait for all commands to complete to this specific |
| 1707 | * target (block maximum 60 seconds). Although not necessary, |
| 1708 | * it does make us a good storage citizen. |
| 1709 | */ |
| 1710 | host = aac->scsi_host_ptr; |
| 1711 | scsi_block_requests(host); |
| 1712 | if (forced < 2) for (retval = 60; retval; --retval) { |
| 1713 | struct scsi_device * dev; |
| 1714 | struct scsi_cmnd * command; |
| 1715 | int active = 0; |
| 1716 | |
| 1717 | __shost_for_each_device(dev, host) { |
| 1718 | spin_lock_irqsave(&dev->list_lock, flagv); |
| 1719 | list_for_each_entry(command, &dev->cmd_list, list) { |
| 1720 | if (command->SCp.phase == AAC_OWNER_FIRMWARE) { |
| 1721 | active++; |
| 1722 | break; |
| 1723 | } |
| 1724 | } |
| 1725 | spin_unlock_irqrestore(&dev->list_lock, flagv); |
| 1726 | if (active) |
| 1727 | break; |
| 1728 | |
| 1729 | } |
| 1730 | /* |
| 1731 | * We can exit If all the commands are complete |
| 1732 | */ |
| 1733 | if (active == 0) |
| 1734 | break; |
| 1735 | ssleep(1); |
| 1736 | } |
| 1737 | |
| 1738 | /* Quiesce build, flush cache, write through mode */ |
Salyzyn, Mark | f858317 | 2007-10-30 15:50:49 -0400 | [diff] [blame] | 1739 | if (forced < 2) |
| 1740 | aac_send_shutdown(aac); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1741 | spin_lock_irqsave(host->host_lock, flagv); |
Raghava Aditya Renukunta | 3136432 | 2017-02-02 15:53:33 -0800 | [diff] [blame] | 1742 | bled = forced ? forced : |
| 1743 | (aac_check_reset != 0 && aac_check_reset != 1); |
| 1744 | retval = _aac_reset_adapter(aac, bled, reset_type); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1745 | spin_unlock_irqrestore(host->host_lock, flagv); |
| 1746 | |
Salyzyn, Mark | f858317 | 2007-10-30 15:50:49 -0400 | [diff] [blame] | 1747 | if ((forced < 2) && (retval == -ENODEV)) { |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1748 | /* Unwind aac_send_shutdown() IOP_RESET unsupported/disabled */ |
| 1749 | struct fib * fibctx = aac_fib_alloc(aac); |
| 1750 | if (fibctx) { |
| 1751 | struct aac_pause *cmd; |
| 1752 | int status; |
| 1753 | |
| 1754 | aac_fib_init(fibctx); |
| 1755 | |
| 1756 | cmd = (struct aac_pause *) fib_data(fibctx); |
| 1757 | |
| 1758 | cmd->command = cpu_to_le32(VM_ContainerConfig); |
| 1759 | cmd->type = cpu_to_le32(CT_PAUSE_IO); |
| 1760 | cmd->timeout = cpu_to_le32(1); |
| 1761 | cmd->min = cpu_to_le32(1); |
| 1762 | cmd->noRescan = cpu_to_le32(1); |
| 1763 | cmd->count = cpu_to_le32(0); |
| 1764 | |
| 1765 | status = aac_fib_send(ContainerCommand, |
| 1766 | fibctx, |
| 1767 | sizeof(struct aac_pause), |
| 1768 | FsaNormal, |
| 1769 | -2 /* Timeout silently */, 1, |
| 1770 | NULL, NULL); |
| 1771 | |
| 1772 | if (status >= 0) |
| 1773 | aac_fib_complete(fibctx); |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 1774 | /* FIB should be freed only after getting |
| 1775 | * the response from the F/W */ |
| 1776 | if (status != -ERESTARTSYS) |
| 1777 | aac_fib_free(fibctx); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1778 | } |
| 1779 | } |
| 1780 | |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1781 | return retval; |
| 1782 | } |
| 1783 | |
| 1784 | int aac_check_health(struct aac_dev * aac) |
| 1785 | { |
| 1786 | int BlinkLED; |
| 1787 | unsigned long time_now, flagv = 0; |
| 1788 | struct list_head * entry; |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1789 | |
| 1790 | /* Extending the scope of fib_lock slightly to protect aac->in_reset */ |
| 1791 | if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0) |
| 1792 | return 0; |
| 1793 | |
| 1794 | if (aac->in_reset || !(BlinkLED = aac_adapter_check_health(aac))) { |
| 1795 | spin_unlock_irqrestore(&aac->fib_lock, flagv); |
| 1796 | return 0; /* OK */ |
| 1797 | } |
| 1798 | |
| 1799 | aac->in_reset = 1; |
| 1800 | |
| 1801 | /* Fake up an AIF: |
| 1802 | * aac_aifcmd.command = AifCmdEventNotify = 1 |
| 1803 | * aac_aifcmd.seqnum = 0xFFFFFFFF |
| 1804 | * aac_aifcmd.data[0] = AifEnExpEvent = 23 |
| 1805 | * aac_aifcmd.data[1] = AifExeFirmwarePanic = 3 |
| 1806 | * aac.aifcmd.data[2] = AifHighPriority = 3 |
| 1807 | * aac.aifcmd.data[3] = BlinkLED |
| 1808 | */ |
| 1809 | |
| 1810 | time_now = jiffies/HZ; |
| 1811 | entry = aac->fib_list.next; |
| 1812 | |
| 1813 | /* |
| 1814 | * For each Context that is on the |
| 1815 | * fibctxList, make a copy of the |
| 1816 | * fib, and then set the event to wake up the |
| 1817 | * thread that is waiting for it. |
| 1818 | */ |
| 1819 | while (entry != &aac->fib_list) { |
| 1820 | /* |
| 1821 | * Extract the fibctx |
| 1822 | */ |
| 1823 | struct aac_fib_context *fibctx = list_entry(entry, struct aac_fib_context, next); |
| 1824 | struct hw_fib * hw_fib; |
| 1825 | struct fib * fib; |
| 1826 | /* |
| 1827 | * Check if the queue is getting |
| 1828 | * backlogged |
| 1829 | */ |
| 1830 | if (fibctx->count > 20) { |
| 1831 | /* |
| 1832 | * It's *not* jiffies folks, |
| 1833 | * but jiffies / HZ, so do not |
| 1834 | * panic ... |
| 1835 | */ |
| 1836 | u32 time_last = fibctx->jiffies; |
| 1837 | /* |
| 1838 | * Has it been > 2 minutes |
| 1839 | * since the last read off |
| 1840 | * the queue? |
| 1841 | */ |
| 1842 | if ((time_now - time_last) > aif_timeout) { |
| 1843 | entry = entry->next; |
| 1844 | aac_close_fib_context(aac, fibctx); |
| 1845 | continue; |
| 1846 | } |
| 1847 | } |
| 1848 | /* |
| 1849 | * Warning: no sleep allowed while |
| 1850 | * holding spinlock |
| 1851 | */ |
Salyzyn, Mark | 4dbc22d | 2007-04-16 11:21:50 -0400 | [diff] [blame] | 1852 | hw_fib = kzalloc(sizeof(struct hw_fib), GFP_ATOMIC); |
| 1853 | fib = kzalloc(sizeof(struct fib), GFP_ATOMIC); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1854 | if (fib && hw_fib) { |
| 1855 | struct aac_aifcmd * aif; |
| 1856 | |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 1857 | fib->hw_fib_va = hw_fib; |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1858 | fib->dev = aac; |
| 1859 | aac_fib_init(fib); |
| 1860 | fib->type = FSAFS_NTC_FIB_CONTEXT; |
| 1861 | fib->size = sizeof (struct fib); |
| 1862 | fib->data = hw_fib->data; |
| 1863 | aif = (struct aac_aifcmd *)hw_fib->data; |
| 1864 | aif->command = cpu_to_le32(AifCmdEventNotify); |
Salyzyn, Mark | a3940da | 2008-01-08 12:48:25 -0800 | [diff] [blame] | 1865 | aif->seqnum = cpu_to_le32(0xFFFFFFFF); |
| 1866 | ((__le32 *)aif->data)[0] = cpu_to_le32(AifEnExpEvent); |
| 1867 | ((__le32 *)aif->data)[1] = cpu_to_le32(AifExeFirmwarePanic); |
| 1868 | ((__le32 *)aif->data)[2] = cpu_to_le32(AifHighPriority); |
| 1869 | ((__le32 *)aif->data)[3] = cpu_to_le32(BlinkLED); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1870 | |
| 1871 | /* |
| 1872 | * Put the FIB onto the |
| 1873 | * fibctx's fibs |
| 1874 | */ |
| 1875 | list_add_tail(&fib->fiblink, &fibctx->fib_list); |
| 1876 | fibctx->count++; |
| 1877 | /* |
| 1878 | * Set the event to wake up the |
| 1879 | * thread that will waiting. |
| 1880 | */ |
| 1881 | up(&fibctx->wait_sem); |
| 1882 | } else { |
| 1883 | printk(KERN_WARNING "aifd: didn't allocate NewFib.\n"); |
| 1884 | kfree(fib); |
| 1885 | kfree(hw_fib); |
| 1886 | } |
| 1887 | entry = entry->next; |
| 1888 | } |
| 1889 | |
| 1890 | spin_unlock_irqrestore(&aac->fib_lock, flagv); |
| 1891 | |
| 1892 | if (BlinkLED < 0) { |
Guilherme G. Piccoli | 911e572 | 2017-04-06 18:12:09 -0300 | [diff] [blame] | 1893 | printk(KERN_ERR "%s: Host adapter is dead (or got a PCI error) %d\n", |
| 1894 | aac->name, BlinkLED); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1895 | goto out; |
| 1896 | } |
| 1897 | |
| 1898 | printk(KERN_ERR "%s: Host adapter BLINK LED 0x%x\n", aac->name, BlinkLED); |
| 1899 | |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1900 | out: |
| 1901 | aac->in_reset = 0; |
| 1902 | return BlinkLED; |
| 1903 | } |
| 1904 | |
Raghava Aditya Renukunta | 6223a39 | 2017-02-02 15:53:28 -0800 | [diff] [blame] | 1905 | |
| 1906 | static void aac_resolve_luns(struct aac_dev *dev) |
| 1907 | { |
| 1908 | int bus, target, channel; |
| 1909 | struct scsi_device *sdev; |
| 1910 | u8 devtype; |
| 1911 | u8 new_devtype; |
| 1912 | |
| 1913 | for (bus = 0; bus < AAC_MAX_BUSES; bus++) { |
| 1914 | for (target = 0; target < AAC_MAX_TARGETS; target++) { |
| 1915 | |
Raghava Aditya Renukunta | 6223a39 | 2017-02-02 15:53:28 -0800 | [diff] [blame] | 1916 | if (bus == CONTAINER_CHANNEL) |
| 1917 | channel = CONTAINER_CHANNEL; |
| 1918 | else |
| 1919 | channel = aac_phys_to_logical(bus); |
| 1920 | |
| 1921 | devtype = dev->hba_map[bus][target].devtype; |
| 1922 | new_devtype = dev->hba_map[bus][target].new_devtype; |
| 1923 | |
| 1924 | sdev = scsi_device_lookup(dev->scsi_host_ptr, channel, |
| 1925 | target, 0); |
| 1926 | |
Raghava Aditya Renukunta | a56e574 | 2017-02-22 07:23:13 -0800 | [diff] [blame] | 1927 | if (!sdev && new_devtype) |
Raghava Aditya Renukunta | 6223a39 | 2017-02-02 15:53:28 -0800 | [diff] [blame] | 1928 | scsi_add_device(dev->scsi_host_ptr, channel, |
| 1929 | target, 0); |
| 1930 | else if (sdev && new_devtype != devtype) |
| 1931 | scsi_remove_device(sdev); |
| 1932 | else if (sdev && new_devtype == devtype) |
| 1933 | scsi_rescan_device(&sdev->sdev_gendev); |
| 1934 | |
| 1935 | if (sdev) |
| 1936 | scsi_device_put(sdev); |
| 1937 | |
| 1938 | dev->hba_map[bus][target].devtype = new_devtype; |
| 1939 | } |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | /** |
| 1944 | * aac_handle_sa_aif Handle a message from the firmware |
| 1945 | * @dev: Which adapter this fib is from |
| 1946 | * @fibptr: Pointer to fibptr from adapter |
| 1947 | * |
| 1948 | * This routine handles a driver notify fib from the adapter and |
| 1949 | * dispatches it to the appropriate routine for handling. |
| 1950 | */ |
| 1951 | static void aac_handle_sa_aif(struct aac_dev *dev, struct fib *fibptr) |
| 1952 | { |
| 1953 | int i, bus, target, container, rcode = 0; |
| 1954 | u32 events = 0; |
| 1955 | struct fib *fib; |
| 1956 | struct scsi_device *sdev; |
| 1957 | |
| 1958 | if (fibptr->hbacmd_size & SA_AIF_HOTPLUG) |
| 1959 | events = SA_AIF_HOTPLUG; |
| 1960 | else if (fibptr->hbacmd_size & SA_AIF_HARDWARE) |
| 1961 | events = SA_AIF_HARDWARE; |
| 1962 | else if (fibptr->hbacmd_size & SA_AIF_PDEV_CHANGE) |
| 1963 | events = SA_AIF_PDEV_CHANGE; |
| 1964 | else if (fibptr->hbacmd_size & SA_AIF_LDEV_CHANGE) |
| 1965 | events = SA_AIF_LDEV_CHANGE; |
| 1966 | else if (fibptr->hbacmd_size & SA_AIF_BPSTAT_CHANGE) |
| 1967 | events = SA_AIF_BPSTAT_CHANGE; |
| 1968 | else if (fibptr->hbacmd_size & SA_AIF_BPCFG_CHANGE) |
| 1969 | events = SA_AIF_BPCFG_CHANGE; |
| 1970 | |
| 1971 | switch (events) { |
| 1972 | case SA_AIF_HOTPLUG: |
| 1973 | case SA_AIF_HARDWARE: |
| 1974 | case SA_AIF_PDEV_CHANGE: |
| 1975 | case SA_AIF_LDEV_CHANGE: |
| 1976 | case SA_AIF_BPCFG_CHANGE: |
| 1977 | |
| 1978 | fib = aac_fib_alloc(dev); |
| 1979 | if (!fib) { |
| 1980 | pr_err("aac_handle_sa_aif: out of memory\n"); |
| 1981 | return; |
| 1982 | } |
| 1983 | for (bus = 0; bus < AAC_MAX_BUSES; bus++) |
| 1984 | for (target = 0; target < AAC_MAX_TARGETS; target++) |
| 1985 | dev->hba_map[bus][target].new_devtype = 0; |
| 1986 | |
| 1987 | rcode = aac_report_phys_luns(dev, fib, AAC_RESCAN); |
| 1988 | |
| 1989 | if (rcode != -ERESTARTSYS) |
| 1990 | aac_fib_free(fib); |
| 1991 | |
| 1992 | aac_resolve_luns(dev); |
| 1993 | |
| 1994 | if (events == SA_AIF_LDEV_CHANGE || |
| 1995 | events == SA_AIF_BPCFG_CHANGE) { |
| 1996 | aac_get_containers(dev); |
| 1997 | for (container = 0; container < |
| 1998 | dev->maximum_num_containers; ++container) { |
| 1999 | sdev = scsi_device_lookup(dev->scsi_host_ptr, |
| 2000 | CONTAINER_CHANNEL, |
| 2001 | container, 0); |
| 2002 | if (dev->fsa_dev[container].valid && !sdev) { |
| 2003 | scsi_add_device(dev->scsi_host_ptr, |
| 2004 | CONTAINER_CHANNEL, |
| 2005 | container, 0); |
| 2006 | } else if (!dev->fsa_dev[container].valid && |
| 2007 | sdev) { |
| 2008 | scsi_remove_device(sdev); |
| 2009 | scsi_device_put(sdev); |
| 2010 | } else if (sdev) { |
| 2011 | scsi_rescan_device(&sdev->sdev_gendev); |
| 2012 | scsi_device_put(sdev); |
| 2013 | } |
| 2014 | } |
| 2015 | } |
| 2016 | break; |
| 2017 | |
| 2018 | case SA_AIF_BPSTAT_CHANGE: |
| 2019 | /* currently do nothing */ |
| 2020 | break; |
| 2021 | } |
| 2022 | |
| 2023 | for (i = 1; i <= 10; ++i) { |
| 2024 | events = src_readl(dev, MUnit.IDR); |
| 2025 | if (events & (1<<23)) { |
| 2026 | pr_warn(" AIF not cleared by firmware - %d/%d)\n", |
| 2027 | i, 10); |
| 2028 | ssleep(1); |
| 2029 | } |
| 2030 | } |
| 2031 | } |
| 2032 | |
Raghava Aditya Renukunta | 113156b | 2017-02-02 15:53:24 -0800 | [diff] [blame] | 2033 | static int get_fib_count(struct aac_dev *dev) |
| 2034 | { |
| 2035 | unsigned int num = 0; |
| 2036 | struct list_head *entry; |
| 2037 | unsigned long flagv; |
| 2038 | |
| 2039 | /* |
| 2040 | * Warning: no sleep allowed while |
| 2041 | * holding spinlock. We take the estimate |
| 2042 | * and pre-allocate a set of fibs outside the |
| 2043 | * lock. |
| 2044 | */ |
| 2045 | num = le32_to_cpu(dev->init->r7.adapter_fibs_size) |
| 2046 | / sizeof(struct hw_fib); /* some extra */ |
| 2047 | spin_lock_irqsave(&dev->fib_lock, flagv); |
| 2048 | entry = dev->fib_list.next; |
| 2049 | while (entry != &dev->fib_list) { |
| 2050 | entry = entry->next; |
| 2051 | ++num; |
| 2052 | } |
| 2053 | spin_unlock_irqrestore(&dev->fib_lock, flagv); |
| 2054 | |
| 2055 | return num; |
| 2056 | } |
| 2057 | |
| 2058 | static int fillup_pools(struct aac_dev *dev, struct hw_fib **hw_fib_pool, |
| 2059 | struct fib **fib_pool, |
| 2060 | unsigned int num) |
| 2061 | { |
| 2062 | struct hw_fib **hw_fib_p; |
| 2063 | struct fib **fib_p; |
Raghava Aditya Renukunta | 113156b | 2017-02-02 15:53:24 -0800 | [diff] [blame] | 2064 | |
| 2065 | hw_fib_p = hw_fib_pool; |
| 2066 | fib_p = fib_pool; |
| 2067 | while (hw_fib_p < &hw_fib_pool[num]) { |
| 2068 | *(hw_fib_p) = kmalloc(sizeof(struct hw_fib), GFP_KERNEL); |
| 2069 | if (!(*(hw_fib_p++))) { |
| 2070 | --hw_fib_p; |
| 2071 | break; |
| 2072 | } |
| 2073 | |
| 2074 | *(fib_p) = kmalloc(sizeof(struct fib), GFP_KERNEL); |
| 2075 | if (!(*(fib_p++))) { |
| 2076 | kfree(*(--hw_fib_p)); |
| 2077 | break; |
| 2078 | } |
| 2079 | } |
| 2080 | |
Raghava Aditya Renukunta | e498520 | 2017-03-14 09:20:19 -0700 | [diff] [blame] | 2081 | /* |
| 2082 | * Get the actual number of allocated fibs |
| 2083 | */ |
Raghava Aditya Renukunta | 113156b | 2017-02-02 15:53:24 -0800 | [diff] [blame] | 2084 | num = hw_fib_p - hw_fib_pool; |
Raghava Aditya Renukunta | e498520 | 2017-03-14 09:20:19 -0700 | [diff] [blame] | 2085 | return num; |
Raghava Aditya Renukunta | 113156b | 2017-02-02 15:53:24 -0800 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | static void wakeup_fibctx_threads(struct aac_dev *dev, |
| 2089 | struct hw_fib **hw_fib_pool, |
| 2090 | struct fib **fib_pool, |
| 2091 | struct fib *fib, |
| 2092 | struct hw_fib *hw_fib, |
| 2093 | unsigned int num) |
| 2094 | { |
| 2095 | unsigned long flagv; |
| 2096 | struct list_head *entry; |
| 2097 | struct hw_fib **hw_fib_p; |
| 2098 | struct fib **fib_p; |
| 2099 | u32 time_now, time_last; |
| 2100 | struct hw_fib *hw_newfib; |
| 2101 | struct fib *newfib; |
| 2102 | struct aac_fib_context *fibctx; |
| 2103 | |
| 2104 | time_now = jiffies/HZ; |
| 2105 | spin_lock_irqsave(&dev->fib_lock, flagv); |
| 2106 | entry = dev->fib_list.next; |
| 2107 | /* |
| 2108 | * For each Context that is on the |
| 2109 | * fibctxList, make a copy of the |
| 2110 | * fib, and then set the event to wake up the |
| 2111 | * thread that is waiting for it. |
| 2112 | */ |
| 2113 | |
| 2114 | hw_fib_p = hw_fib_pool; |
| 2115 | fib_p = fib_pool; |
| 2116 | while (entry != &dev->fib_list) { |
| 2117 | /* |
| 2118 | * Extract the fibctx |
| 2119 | */ |
| 2120 | fibctx = list_entry(entry, struct aac_fib_context, |
| 2121 | next); |
| 2122 | /* |
| 2123 | * Check if the queue is getting |
| 2124 | * backlogged |
| 2125 | */ |
| 2126 | if (fibctx->count > 20) { |
| 2127 | /* |
| 2128 | * It's *not* jiffies folks, |
| 2129 | * but jiffies / HZ so do not |
| 2130 | * panic ... |
| 2131 | */ |
| 2132 | time_last = fibctx->jiffies; |
| 2133 | /* |
| 2134 | * Has it been > 2 minutes |
| 2135 | * since the last read off |
| 2136 | * the queue? |
| 2137 | */ |
| 2138 | if ((time_now - time_last) > aif_timeout) { |
| 2139 | entry = entry->next; |
| 2140 | aac_close_fib_context(dev, fibctx); |
| 2141 | continue; |
| 2142 | } |
| 2143 | } |
| 2144 | /* |
| 2145 | * Warning: no sleep allowed while |
| 2146 | * holding spinlock |
| 2147 | */ |
| 2148 | if (hw_fib_p >= &hw_fib_pool[num]) { |
| 2149 | pr_warn("aifd: didn't allocate NewFib\n"); |
| 2150 | entry = entry->next; |
| 2151 | continue; |
| 2152 | } |
| 2153 | |
| 2154 | hw_newfib = *hw_fib_p; |
| 2155 | *(hw_fib_p++) = NULL; |
| 2156 | newfib = *fib_p; |
| 2157 | *(fib_p++) = NULL; |
| 2158 | /* |
| 2159 | * Make the copy of the FIB |
| 2160 | */ |
| 2161 | memcpy(hw_newfib, hw_fib, sizeof(struct hw_fib)); |
| 2162 | memcpy(newfib, fib, sizeof(struct fib)); |
| 2163 | newfib->hw_fib_va = hw_newfib; |
| 2164 | /* |
| 2165 | * Put the FIB onto the |
| 2166 | * fibctx's fibs |
| 2167 | */ |
| 2168 | list_add_tail(&newfib->fiblink, &fibctx->fib_list); |
| 2169 | fibctx->count++; |
| 2170 | /* |
| 2171 | * Set the event to wake up the |
| 2172 | * thread that is waiting. |
| 2173 | */ |
| 2174 | up(&fibctx->wait_sem); |
| 2175 | |
| 2176 | entry = entry->next; |
| 2177 | } |
| 2178 | /* |
| 2179 | * Set the status of this FIB |
| 2180 | */ |
| 2181 | *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK); |
| 2182 | aac_fib_adapter_complete(fib, sizeof(u32)); |
| 2183 | spin_unlock_irqrestore(&dev->fib_lock, flagv); |
| 2184 | |
| 2185 | } |
| 2186 | |
| 2187 | static void aac_process_events(struct aac_dev *dev) |
| 2188 | { |
| 2189 | struct hw_fib *hw_fib; |
| 2190 | struct fib *fib; |
| 2191 | unsigned long flags; |
| 2192 | spinlock_t *t_lock; |
Raghava Aditya Renukunta | 113156b | 2017-02-02 15:53:24 -0800 | [diff] [blame] | 2193 | |
| 2194 | t_lock = dev->queues->queue[HostNormCmdQueue].lock; |
| 2195 | spin_lock_irqsave(t_lock, flags); |
| 2196 | |
| 2197 | while (!list_empty(&(dev->queues->queue[HostNormCmdQueue].cmdq))) { |
| 2198 | struct list_head *entry; |
| 2199 | struct aac_aifcmd *aifcmd; |
| 2200 | unsigned int num; |
| 2201 | struct hw_fib **hw_fib_pool, **hw_fib_p; |
| 2202 | struct fib **fib_pool, **fib_p; |
| 2203 | |
| 2204 | set_current_state(TASK_RUNNING); |
| 2205 | |
| 2206 | entry = dev->queues->queue[HostNormCmdQueue].cmdq.next; |
| 2207 | list_del(entry); |
| 2208 | |
| 2209 | t_lock = dev->queues->queue[HostNormCmdQueue].lock; |
| 2210 | spin_unlock_irqrestore(t_lock, flags); |
| 2211 | |
| 2212 | fib = list_entry(entry, struct fib, fiblink); |
| 2213 | hw_fib = fib->hw_fib_va; |
Raghava Aditya Renukunta | 6223a39 | 2017-02-02 15:53:28 -0800 | [diff] [blame] | 2214 | if (dev->sa_firmware) { |
| 2215 | /* Thor AIF */ |
| 2216 | aac_handle_sa_aif(dev, fib); |
| 2217 | aac_fib_adapter_complete(fib, (u16)sizeof(u32)); |
Raghava Aditya Renukunta | d844752 | 2017-02-16 12:51:23 -0800 | [diff] [blame] | 2218 | goto free_fib; |
Raghava Aditya Renukunta | 6223a39 | 2017-02-02 15:53:28 -0800 | [diff] [blame] | 2219 | } |
Raghava Aditya Renukunta | 113156b | 2017-02-02 15:53:24 -0800 | [diff] [blame] | 2220 | /* |
| 2221 | * We will process the FIB here or pass it to a |
| 2222 | * worker thread that is TBD. We Really can't |
| 2223 | * do anything at this point since we don't have |
| 2224 | * anything defined for this thread to do. |
| 2225 | */ |
| 2226 | memset(fib, 0, sizeof(struct fib)); |
| 2227 | fib->type = FSAFS_NTC_FIB_CONTEXT; |
| 2228 | fib->size = sizeof(struct fib); |
| 2229 | fib->hw_fib_va = hw_fib; |
| 2230 | fib->data = hw_fib->data; |
| 2231 | fib->dev = dev; |
| 2232 | /* |
| 2233 | * We only handle AifRequest fibs from the adapter. |
| 2234 | */ |
| 2235 | |
| 2236 | aifcmd = (struct aac_aifcmd *) hw_fib->data; |
| 2237 | if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) { |
| 2238 | /* Handle Driver Notify Events */ |
| 2239 | aac_handle_aif(dev, fib); |
| 2240 | *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK); |
| 2241 | aac_fib_adapter_complete(fib, (u16)sizeof(u32)); |
| 2242 | goto free_fib; |
| 2243 | } |
| 2244 | /* |
| 2245 | * The u32 here is important and intended. We are using |
| 2246 | * 32bit wrapping time to fit the adapter field |
| 2247 | */ |
| 2248 | |
| 2249 | /* Sniff events */ |
| 2250 | if (aifcmd->command == cpu_to_le32(AifCmdEventNotify) |
| 2251 | || aifcmd->command == cpu_to_le32(AifCmdJobProgress)) { |
| 2252 | aac_handle_aif(dev, fib); |
| 2253 | } |
| 2254 | |
| 2255 | /* |
| 2256 | * get number of fibs to process |
| 2257 | */ |
| 2258 | num = get_fib_count(dev); |
| 2259 | if (!num) |
| 2260 | goto free_fib; |
| 2261 | |
| 2262 | hw_fib_pool = kmalloc_array(num, sizeof(struct hw_fib *), |
| 2263 | GFP_KERNEL); |
| 2264 | if (!hw_fib_pool) |
| 2265 | goto free_fib; |
| 2266 | |
| 2267 | fib_pool = kmalloc_array(num, sizeof(struct fib *), GFP_KERNEL); |
| 2268 | if (!fib_pool) |
| 2269 | goto free_hw_fib_pool; |
| 2270 | |
| 2271 | /* |
| 2272 | * Fill up fib pointer pools with actual fibs |
| 2273 | * and hw_fibs |
| 2274 | */ |
Raghava Aditya Renukunta | e498520 | 2017-03-14 09:20:19 -0700 | [diff] [blame] | 2275 | num = fillup_pools(dev, hw_fib_pool, fib_pool, num); |
| 2276 | if (!num) |
Raghava Aditya Renukunta | 113156b | 2017-02-02 15:53:24 -0800 | [diff] [blame] | 2277 | goto free_mem; |
| 2278 | |
| 2279 | /* |
| 2280 | * wakeup the thread that is waiting for |
| 2281 | * the response from fw (ioctl) |
| 2282 | */ |
| 2283 | wakeup_fibctx_threads(dev, hw_fib_pool, fib_pool, |
| 2284 | fib, hw_fib, num); |
| 2285 | |
| 2286 | free_mem: |
| 2287 | /* Free up the remaining resources */ |
| 2288 | hw_fib_p = hw_fib_pool; |
| 2289 | fib_p = fib_pool; |
| 2290 | while (hw_fib_p < &hw_fib_pool[num]) { |
| 2291 | kfree(*hw_fib_p); |
| 2292 | kfree(*fib_p); |
| 2293 | ++fib_p; |
| 2294 | ++hw_fib_p; |
| 2295 | } |
| 2296 | kfree(fib_pool); |
| 2297 | free_hw_fib_pool: |
| 2298 | kfree(hw_fib_pool); |
| 2299 | free_fib: |
| 2300 | kfree(fib); |
| 2301 | t_lock = dev->queues->queue[HostNormCmdQueue].lock; |
| 2302 | spin_lock_irqsave(t_lock, flags); |
| 2303 | } |
| 2304 | /* |
| 2305 | * There are no more AIF's |
| 2306 | */ |
| 2307 | t_lock = dev->queues->queue[HostNormCmdQueue].lock; |
| 2308 | spin_unlock_irqrestore(t_lock, flags); |
| 2309 | } |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 2310 | |
Raghava Aditya Renukunta | 3d77d84 | 2017-02-02 15:53:25 -0800 | [diff] [blame] | 2311 | static int aac_send_wellness_command(struct aac_dev *dev, char *wellness_str, |
| 2312 | u32 datasize) |
| 2313 | { |
| 2314 | struct aac_srb *srbcmd; |
| 2315 | struct sgmap64 *sg64; |
| 2316 | dma_addr_t addr; |
| 2317 | char *dma_buf; |
| 2318 | struct fib *fibptr; |
| 2319 | int ret = -ENOMEM; |
| 2320 | u32 vbus, vid; |
| 2321 | |
| 2322 | fibptr = aac_fib_alloc(dev); |
| 2323 | if (!fibptr) |
| 2324 | goto out; |
| 2325 | |
Mahesh Rajashekhara | f481973 | 2017-04-05 16:14:16 +0530 | [diff] [blame] | 2326 | dma_buf = dma_alloc_coherent(&dev->pdev->dev, datasize, &addr, |
| 2327 | GFP_KERNEL); |
Raghava Aditya Renukunta | 3d77d84 | 2017-02-02 15:53:25 -0800 | [diff] [blame] | 2328 | if (!dma_buf) |
| 2329 | goto fib_free_out; |
| 2330 | |
| 2331 | aac_fib_init(fibptr); |
| 2332 | |
Raghava Aditya Renukunta | 1c68856 | 2017-02-16 12:51:10 -0800 | [diff] [blame] | 2333 | vbus = (u32)le16_to_cpu(dev->supplement_adapter_info.virt_device_bus); |
| 2334 | vid = (u32)le16_to_cpu(dev->supplement_adapter_info.virt_device_target); |
Raghava Aditya Renukunta | 3d77d84 | 2017-02-02 15:53:25 -0800 | [diff] [blame] | 2335 | |
| 2336 | srbcmd = (struct aac_srb *)fib_data(fibptr); |
| 2337 | |
| 2338 | srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi); |
| 2339 | srbcmd->channel = cpu_to_le32(vbus); |
| 2340 | srbcmd->id = cpu_to_le32(vid); |
| 2341 | srbcmd->lun = 0; |
| 2342 | srbcmd->flags = cpu_to_le32(SRB_DataOut); |
| 2343 | srbcmd->timeout = cpu_to_le32(10); |
| 2344 | srbcmd->retry_limit = 0; |
| 2345 | srbcmd->cdb_size = cpu_to_le32(12); |
| 2346 | srbcmd->count = cpu_to_le32(datasize); |
| 2347 | |
| 2348 | memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb)); |
| 2349 | srbcmd->cdb[0] = BMIC_OUT; |
| 2350 | srbcmd->cdb[6] = WRITE_HOST_WELLNESS; |
| 2351 | memcpy(dma_buf, (char *)wellness_str, datasize); |
| 2352 | |
| 2353 | sg64 = (struct sgmap64 *)&srbcmd->sg; |
| 2354 | sg64->count = cpu_to_le32(1); |
| 2355 | sg64->sg[0].addr[1] = cpu_to_le32((u32)(((addr) >> 16) >> 16)); |
| 2356 | sg64->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff)); |
| 2357 | sg64->sg[0].count = cpu_to_le32(datasize); |
| 2358 | |
| 2359 | ret = aac_fib_send(ScsiPortCommand64, fibptr, sizeof(struct aac_srb), |
| 2360 | FsaNormal, 1, 1, NULL, NULL); |
| 2361 | |
Mahesh Rajashekhara | f481973 | 2017-04-05 16:14:16 +0530 | [diff] [blame] | 2362 | dma_free_coherent(&dev->pdev->dev, datasize, dma_buf, addr); |
Raghava Aditya Renukunta | 3d77d84 | 2017-02-02 15:53:25 -0800 | [diff] [blame] | 2363 | |
| 2364 | /* |
| 2365 | * Do not set XferState to zero unless |
| 2366 | * receives a response from F/W |
| 2367 | */ |
| 2368 | if (ret >= 0) |
| 2369 | aac_fib_complete(fibptr); |
| 2370 | |
| 2371 | /* |
| 2372 | * FIB should be freed only after |
| 2373 | * getting the response from the F/W |
| 2374 | */ |
| 2375 | if (ret != -ERESTARTSYS) |
| 2376 | goto fib_free_out; |
| 2377 | |
| 2378 | out: |
| 2379 | return ret; |
| 2380 | fib_free_out: |
| 2381 | aac_fib_free(fibptr); |
| 2382 | goto out; |
| 2383 | } |
| 2384 | |
| 2385 | int aac_send_safw_hostttime(struct aac_dev *dev, struct timeval *now) |
| 2386 | { |
| 2387 | struct tm cur_tm; |
| 2388 | char wellness_str[] = "<HW>TD\010\0\0\0\0\0\0\0\0\0DW\0\0ZZ"; |
| 2389 | u32 datasize = sizeof(wellness_str); |
| 2390 | unsigned long local_time; |
| 2391 | int ret = -ENODEV; |
| 2392 | |
| 2393 | if (!dev->sa_firmware) |
| 2394 | goto out; |
| 2395 | |
| 2396 | local_time = (u32)(now->tv_sec - (sys_tz.tz_minuteswest * 60)); |
| 2397 | time_to_tm(local_time, 0, &cur_tm); |
| 2398 | cur_tm.tm_mon += 1; |
| 2399 | cur_tm.tm_year += 1900; |
| 2400 | wellness_str[8] = bin2bcd(cur_tm.tm_hour); |
| 2401 | wellness_str[9] = bin2bcd(cur_tm.tm_min); |
| 2402 | wellness_str[10] = bin2bcd(cur_tm.tm_sec); |
| 2403 | wellness_str[12] = bin2bcd(cur_tm.tm_mon); |
| 2404 | wellness_str[13] = bin2bcd(cur_tm.tm_mday); |
| 2405 | wellness_str[14] = bin2bcd(cur_tm.tm_year / 100); |
| 2406 | wellness_str[15] = bin2bcd(cur_tm.tm_year % 100); |
| 2407 | |
| 2408 | ret = aac_send_wellness_command(dev, wellness_str, datasize); |
| 2409 | |
| 2410 | out: |
| 2411 | return ret; |
| 2412 | } |
| 2413 | |
| 2414 | int aac_send_hosttime(struct aac_dev *dev, struct timeval *now) |
| 2415 | { |
| 2416 | int ret = -ENOMEM; |
| 2417 | struct fib *fibptr; |
| 2418 | __le32 *info; |
| 2419 | |
| 2420 | fibptr = aac_fib_alloc(dev); |
| 2421 | if (!fibptr) |
| 2422 | goto out; |
| 2423 | |
| 2424 | aac_fib_init(fibptr); |
| 2425 | info = (__le32 *)fib_data(fibptr); |
| 2426 | *info = cpu_to_le32(now->tv_sec); |
| 2427 | ret = aac_fib_send(SendHostTime, fibptr, sizeof(*info), FsaNormal, |
| 2428 | 1, 1, NULL, NULL); |
| 2429 | |
| 2430 | /* |
| 2431 | * Do not set XferState to zero unless |
| 2432 | * receives a response from F/W |
| 2433 | */ |
| 2434 | if (ret >= 0) |
| 2435 | aac_fib_complete(fibptr); |
| 2436 | |
| 2437 | /* |
| 2438 | * FIB should be freed only after |
| 2439 | * getting the response from the F/W |
| 2440 | */ |
| 2441 | if (ret != -ERESTARTSYS) |
| 2442 | aac_fib_free(fibptr); |
| 2443 | |
| 2444 | out: |
| 2445 | return ret; |
| 2446 | } |
| 2447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | /** |
| 2449 | * aac_command_thread - command processing thread |
| 2450 | * @dev: Adapter to monitor |
| 2451 | * |
| 2452 | * Waits on the commandready event in it's queue. When the event gets set |
| 2453 | * it will pull FIBs off it's queue. It will continue to pull FIBs off |
| 2454 | * until the queue is empty. When the queue is empty it will wait for |
| 2455 | * more FIBs. |
| 2456 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2457 | |
Christoph Hellwig | fe27381 | 2006-02-14 18:45:06 +0100 | [diff] [blame] | 2458 | int aac_command_thread(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | { |
Christoph Hellwig | fe27381 | 2006-02-14 18:45:06 +0100 | [diff] [blame] | 2460 | struct aac_dev *dev = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | DECLARE_WAITQUEUE(wait, current); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 2462 | unsigned long next_jiffies = jiffies + HZ; |
| 2463 | unsigned long next_check_jiffies = next_jiffies; |
| 2464 | long difference = HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | |
| 2466 | /* |
| 2467 | * We can only have one thread per adapter for AIF's. |
| 2468 | */ |
| 2469 | if (dev->aif_thread) |
| 2470 | return -EINVAL; |
Christoph Hellwig | fe27381 | 2006-02-14 18:45:06 +0100 | [diff] [blame] | 2471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | /* |
| 2473 | * Let the DPC know it has a place to send the AIF's to. |
| 2474 | */ |
| 2475 | dev->aif_thread = 1; |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 2476 | add_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | set_current_state(TASK_INTERRUPTIBLE); |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 2478 | dprintk ((KERN_INFO "aac_command_thread start\n")); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2479 | while (1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | |
Raghava Aditya Renukunta | 113156b | 2017-02-02 15:53:24 -0800 | [diff] [blame] | 2481 | aac_process_events(dev); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 2482 | |
| 2483 | /* |
| 2484 | * Background activity |
| 2485 | */ |
| 2486 | if ((time_before(next_check_jiffies,next_jiffies)) |
| 2487 | && ((difference = next_check_jiffies - jiffies) <= 0)) { |
| 2488 | next_check_jiffies = next_jiffies; |
Raghava Aditya Renukunta | 9473ddb | 2017-05-10 09:39:48 -0700 | [diff] [blame] | 2489 | if (aac_adapter_check_health(dev) == 0) { |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 2490 | difference = ((long)(unsigned)check_interval) |
| 2491 | * HZ; |
| 2492 | next_check_jiffies = jiffies + difference; |
| 2493 | } else if (!dev->queues) |
| 2494 | break; |
| 2495 | } |
| 2496 | if (!time_before(next_check_jiffies,next_jiffies) |
| 2497 | && ((difference = next_jiffies - jiffies) <= 0)) { |
| 2498 | struct timeval now; |
| 2499 | int ret; |
| 2500 | |
| 2501 | /* Don't even try to talk to adapter if its sick */ |
Raghava Aditya Renukunta | 9473ddb | 2017-05-10 09:39:48 -0700 | [diff] [blame] | 2502 | ret = aac_adapter_check_health(dev); |
Raghava Aditya Renukunta | 849ac6a | 2017-02-16 12:51:17 -0800 | [diff] [blame] | 2503 | if (ret || !dev->queues) |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 2504 | break; |
| 2505 | next_check_jiffies = jiffies |
| 2506 | + ((long)(unsigned)check_interval) |
| 2507 | * HZ; |
| 2508 | do_gettimeofday(&now); |
| 2509 | |
| 2510 | /* Synchronize our watches */ |
| 2511 | if (((1000000 - (1000000 / HZ)) > now.tv_usec) |
| 2512 | && (now.tv_usec > (1000000 / HZ))) |
| 2513 | difference = (((1000000 - now.tv_usec) * HZ) |
| 2514 | + 500000) / 1000000; |
Colin Ian King | fbdab3e | 2017-02-24 14:43:30 +0000 | [diff] [blame] | 2515 | else { |
Raghava Aditya Renukunta | 3d77d84 | 2017-02-02 15:53:25 -0800 | [diff] [blame] | 2516 | if (now.tv_usec > 500000) |
| 2517 | ++now.tv_sec; |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 2518 | |
Raghava Aditya Renukunta | 3d77d84 | 2017-02-02 15:53:25 -0800 | [diff] [blame] | 2519 | if (dev->sa_firmware) |
| 2520 | ret = |
| 2521 | aac_send_safw_hostttime(dev, &now); |
| 2522 | else |
| 2523 | ret = aac_send_hosttime(dev, &now); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 2524 | |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 2525 | difference = (long)(unsigned)update_interval*HZ; |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 2526 | } |
| 2527 | next_jiffies = jiffies + difference; |
| 2528 | if (time_before(next_check_jiffies,next_jiffies)) |
| 2529 | difference = next_check_jiffies - jiffies; |
| 2530 | } |
| 2531 | if (difference <= 0) |
| 2532 | difference = 1; |
| 2533 | set_current_state(TASK_INTERRUPTIBLE); |
Raghava Aditya Renukunta | fc4bf75 | 2016-04-25 23:31:57 -0700 | [diff] [blame] | 2534 | |
| 2535 | if (kthread_should_stop()) |
| 2536 | break; |
| 2537 | |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 2538 | schedule_timeout(difference); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | |
Christoph Hellwig | fe27381 | 2006-02-14 18:45:06 +0100 | [diff] [blame] | 2540 | if (kthread_should_stop()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | } |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 2543 | if (dev->queues) |
| 2544 | remove_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | dev->aif_thread = 0; |
Mark Haverkamp | 2f130980 | 2005-09-26 13:02:15 -0700 | [diff] [blame] | 2546 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | } |
Mahesh Rajashekhara | 8b1462e | 2015-08-28 06:38:38 -0400 | [diff] [blame] | 2548 | |
| 2549 | int aac_acquire_irq(struct aac_dev *dev) |
| 2550 | { |
| 2551 | int i; |
| 2552 | int j; |
| 2553 | int ret = 0; |
Mahesh Rajashekhara | 8b1462e | 2015-08-28 06:38:38 -0400 | [diff] [blame] | 2554 | |
Mahesh Rajashekhara | 8b1462e | 2015-08-28 06:38:38 -0400 | [diff] [blame] | 2555 | if (!dev->sync_mode && dev->msi_enabled && dev->max_msix > 1) { |
| 2556 | for (i = 0; i < dev->max_msix; i++) { |
| 2557 | dev->aac_msix[i].vector_no = i; |
| 2558 | dev->aac_msix[i].dev = dev; |
Hannes Reinecke | 0910d8b | 2016-11-08 08:11:30 +0100 | [diff] [blame] | 2559 | if (request_irq(pci_irq_vector(dev->pdev, i), |
Mahesh Rajashekhara | 8b1462e | 2015-08-28 06:38:38 -0400 | [diff] [blame] | 2560 | dev->a_ops.adapter_intr, |
| 2561 | 0, "aacraid", &(dev->aac_msix[i]))) { |
| 2562 | printk(KERN_ERR "%s%d: Failed to register IRQ for vector %d.\n", |
| 2563 | dev->name, dev->id, i); |
| 2564 | for (j = 0 ; j < i ; j++) |
Hannes Reinecke | 0910d8b | 2016-11-08 08:11:30 +0100 | [diff] [blame] | 2565 | free_irq(pci_irq_vector(dev->pdev, j), |
Mahesh Rajashekhara | 8b1462e | 2015-08-28 06:38:38 -0400 | [diff] [blame] | 2566 | &(dev->aac_msix[j])); |
| 2567 | pci_disable_msix(dev->pdev); |
| 2568 | ret = -1; |
| 2569 | } |
Mahesh Rajashekhara | 8b1462e | 2015-08-28 06:38:38 -0400 | [diff] [blame] | 2570 | } |
| 2571 | } else { |
| 2572 | dev->aac_msix[0].vector_no = 0; |
| 2573 | dev->aac_msix[0].dev = dev; |
| 2574 | |
| 2575 | if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr, |
| 2576 | IRQF_SHARED, "aacraid", |
| 2577 | &(dev->aac_msix[0])) < 0) { |
| 2578 | if (dev->msi) |
| 2579 | pci_disable_msi(dev->pdev); |
| 2580 | printk(KERN_ERR "%s%d: Interrupt unavailable.\n", |
| 2581 | dev->name, dev->id); |
| 2582 | ret = -1; |
| 2583 | } |
| 2584 | } |
| 2585 | return ret; |
| 2586 | } |
| 2587 | |
| 2588 | void aac_free_irq(struct aac_dev *dev) |
| 2589 | { |
| 2590 | int i; |
| 2591 | int cpu; |
| 2592 | |
| 2593 | cpu = cpumask_first(cpu_online_mask); |
Raghava Aditya Renukunta | 395e5df | 2017-05-10 09:39:52 -0700 | [diff] [blame] | 2594 | if (aac_is_src(dev)) { |
Mahesh Rajashekhara | 8b1462e | 2015-08-28 06:38:38 -0400 | [diff] [blame] | 2595 | if (dev->max_msix > 1) { |
Hannes Reinecke | 0910d8b | 2016-11-08 08:11:30 +0100 | [diff] [blame] | 2596 | for (i = 0; i < dev->max_msix; i++) |
| 2597 | free_irq(pci_irq_vector(dev->pdev, i), |
| 2598 | &(dev->aac_msix[i])); |
Mahesh Rajashekhara | 8b1462e | 2015-08-28 06:38:38 -0400 | [diff] [blame] | 2599 | } else { |
| 2600 | free_irq(dev->pdev->irq, &(dev->aac_msix[0])); |
| 2601 | } |
| 2602 | } else { |
| 2603 | free_irq(dev->pdev->irq, dev); |
| 2604 | } |
| 2605 | if (dev->msi) |
| 2606 | pci_disable_msi(dev->pdev); |
| 2607 | else if (dev->max_msix > 1) |
| 2608 | pci_disable_msix(dev->pdev); |
| 2609 | } |