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