Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1 | /* |
| 2 | * This is the Fusion MPT base driver providing common API layer interface |
| 3 | * for access to MPT (Message Passing Technology) firmware. |
| 4 | * |
| 5 | * This code is based on drivers/scsi/mpt3sas/mpt3sas_base.c |
Sreekanth Reddy | a4ffce0 | 2014-09-12 15:35:29 +0530 | [diff] [blame] | 6 | * Copyright (C) 2012-2014 LSI Corporation |
Sreekanth Reddy | a03bd15 | 2015-01-12 11:39:02 +0530 | [diff] [blame] | 7 | * Copyright (C) 2013-2014 Avago Technologies |
| 8 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * as published by the Free Software Foundation; either version 2 |
| 13 | * of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * NO WARRANTY |
| 21 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 22 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT |
| 23 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, |
| 24 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is |
| 25 | * solely responsible for determining the appropriateness of using and |
| 26 | * distributing the Program and assumes all risks associated with its |
| 27 | * exercise of rights under this Agreement, including but not limited to |
| 28 | * the risks and costs of program errors, damage to or loss of data, |
| 29 | * programs or equipment, and unavailability or interruption of operations. |
| 30 | |
| 31 | * DISCLAIMER OF LIABILITY |
| 32 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY |
| 33 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 34 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND |
| 35 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 36 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 37 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED |
| 38 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES |
| 39 | |
| 40 | * You should have received a copy of the GNU General Public License |
| 41 | * along with this program; if not, write to the Free Software |
| 42 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 43 | * USA. |
| 44 | */ |
| 45 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 46 | #include <linux/kernel.h> |
| 47 | #include <linux/module.h> |
| 48 | #include <linux/errno.h> |
| 49 | #include <linux/init.h> |
| 50 | #include <linux/slab.h> |
| 51 | #include <linux/types.h> |
| 52 | #include <linux/pci.h> |
| 53 | #include <linux/kdev_t.h> |
| 54 | #include <linux/blkdev.h> |
| 55 | #include <linux/delay.h> |
| 56 | #include <linux/interrupt.h> |
| 57 | #include <linux/dma-mapping.h> |
| 58 | #include <linux/io.h> |
| 59 | #include <linux/time.h> |
Tina Ruchandani | 23409bd | 2016-04-13 00:01:40 -0700 | [diff] [blame] | 60 | #include <linux/ktime.h> |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 61 | #include <linux/kthread.h> |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 62 | #include <asm/page.h> /* To get host page size per arch */ |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 63 | #include <linux/aer.h> |
| 64 | |
| 65 | |
| 66 | #include "mpt3sas_base.h" |
| 67 | |
| 68 | static MPT_CALLBACK mpt_callbacks[MPT_MAX_CALLBACKS]; |
| 69 | |
| 70 | |
| 71 | #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */ |
| 72 | |
| 73 | /* maximum controller queue depth */ |
| 74 | #define MAX_HBA_QUEUE_DEPTH 30000 |
| 75 | #define MAX_CHAIN_DEPTH 100000 |
| 76 | static int max_queue_depth = -1; |
| 77 | module_param(max_queue_depth, int, 0); |
| 78 | MODULE_PARM_DESC(max_queue_depth, " max controller queue depth "); |
| 79 | |
| 80 | static int max_sgl_entries = -1; |
| 81 | module_param(max_sgl_entries, int, 0); |
| 82 | MODULE_PARM_DESC(max_sgl_entries, " max sg entries "); |
| 83 | |
| 84 | static int msix_disable = -1; |
| 85 | module_param(msix_disable, int, 0); |
| 86 | MODULE_PARM_DESC(msix_disable, " disable msix routed interrupts (default=0)"); |
| 87 | |
Suganath Prabu Subramani | 6403830 | 2016-02-08 22:13:39 +0530 | [diff] [blame] | 88 | static int smp_affinity_enable = 1; |
| 89 | module_param(smp_affinity_enable, int, S_IRUGO); |
Colin Ian King | 23b389c | 2018-04-29 13:31:49 +0100 | [diff] [blame] | 90 | MODULE_PARM_DESC(smp_affinity_enable, "SMP affinity feature enable/disable Default: enable(1)"); |
Suganath Prabu Subramani | 6403830 | 2016-02-08 22:13:39 +0530 | [diff] [blame] | 91 | |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 92 | static int max_msix_vectors = -1; |
Sreekanth Reddy | 9c50006 | 2013-08-14 18:23:20 +0530 | [diff] [blame] | 93 | module_param(max_msix_vectors, int, 0); |
| 94 | MODULE_PARM_DESC(max_msix_vectors, |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 95 | " max msix vectors"); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 96 | |
| 97 | static int mpt3sas_fwfault_debug; |
| 98 | MODULE_PARM_DESC(mpt3sas_fwfault_debug, |
| 99 | " enable detection of firmware fault and halt firmware - (default=0)"); |
| 100 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 101 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 102 | _base_get_ioc_facts(struct MPT3SAS_ADAPTER *ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug. |
| 106 | * |
| 107 | */ |
| 108 | static int |
Kees Cook | e4dca7b | 2017-10-17 19:04:42 -0700 | [diff] [blame] | 109 | _scsih_set_fwfault_debug(const char *val, const struct kernel_param *kp) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 110 | { |
| 111 | int ret = param_set_int(val, kp); |
| 112 | struct MPT3SAS_ADAPTER *ioc; |
| 113 | |
| 114 | if (ret) |
| 115 | return ret; |
| 116 | |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 117 | /* global ioc spinlock to protect controller list on list operations */ |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 118 | pr_info("setting fwfault_debug(%d)\n", mpt3sas_fwfault_debug); |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 119 | spin_lock(&gioc_lock); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 120 | list_for_each_entry(ioc, &mpt3sas_ioc_list, list) |
| 121 | ioc->fwfault_debug = mpt3sas_fwfault_debug; |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 122 | spin_unlock(&gioc_lock); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 123 | return 0; |
| 124 | } |
| 125 | module_param_call(mpt3sas_fwfault_debug, _scsih_set_fwfault_debug, |
| 126 | param_get_int, &mpt3sas_fwfault_debug, 0644); |
| 127 | |
| 128 | /** |
Suganath Prabu Subramani | b4472d7 | 2018-02-07 02:51:50 -0800 | [diff] [blame] | 129 | * _base_clone_reply_to_sys_mem - copies reply to reply free iomem |
| 130 | * in BAR0 space. |
| 131 | * |
| 132 | * @ioc: per adapter object |
| 133 | * @reply: reply message frame(lower 32bit addr) |
| 134 | * @index: System request message index. |
| 135 | * |
| 136 | * @Returns - Nothing |
| 137 | */ |
| 138 | static void |
| 139 | _base_clone_reply_to_sys_mem(struct MPT3SAS_ADAPTER *ioc, u32 reply, |
| 140 | u32 index) |
| 141 | { |
| 142 | /* |
| 143 | * 256 is offset within sys register. |
| 144 | * 256 offset MPI frame starts. Max MPI frame supported is 32. |
| 145 | * 32 * 128 = 4K. From here, Clone of reply free for mcpu starts |
| 146 | */ |
| 147 | u16 cmd_credit = ioc->facts.RequestCredit + 1; |
| 148 | void __iomem *reply_free_iomem = (void __iomem *)ioc->chip + |
| 149 | MPI_FRAME_START_OFFSET + |
| 150 | (cmd_credit * ioc->request_sz) + (index * sizeof(u32)); |
| 151 | |
| 152 | writel(reply, reply_free_iomem); |
| 153 | } |
| 154 | |
| 155 | /** |
Suganath Prabu Subramani | e574743 | 2018-02-07 02:51:49 -0800 | [diff] [blame] | 156 | * _base_clone_mpi_to_sys_mem - Writes/copies MPI frames |
| 157 | * to system/BAR0 region. |
| 158 | * |
| 159 | * @dst_iomem: Pointer to the destinaltion location in BAR0 space. |
| 160 | * @src: Pointer to the Source data. |
| 161 | * @size: Size of data to be copied. |
| 162 | */ |
| 163 | static void |
| 164 | _base_clone_mpi_to_sys_mem(void *dst_iomem, void *src, u32 size) |
| 165 | { |
| 166 | int i; |
| 167 | u32 *src_virt_mem = (u32 *)src; |
| 168 | |
| 169 | for (i = 0; i < size/4; i++) |
| 170 | writel((u32)src_virt_mem[i], |
| 171 | (void __iomem *)dst_iomem + (i * 4)); |
| 172 | } |
| 173 | |
| 174 | /** |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 175 | * _base_clone_to_sys_mem - Writes/copies data to system/BAR0 region |
| 176 | * |
| 177 | * @dst_iomem: Pointer to the destination location in BAR0 space. |
| 178 | * @src: Pointer to the Source data. |
| 179 | * @size: Size of data to be copied. |
| 180 | */ |
| 181 | static void |
| 182 | _base_clone_to_sys_mem(void __iomem *dst_iomem, void *src, u32 size) |
| 183 | { |
| 184 | int i; |
| 185 | u32 *src_virt_mem = (u32 *)(src); |
| 186 | |
| 187 | for (i = 0; i < size/4; i++) |
| 188 | writel((u32)src_virt_mem[i], |
| 189 | (void __iomem *)dst_iomem + (i * 4)); |
| 190 | } |
| 191 | |
| 192 | /** |
Suganath Prabu Subramani | 22ae5a3 | 2018-02-07 02:51:47 -0800 | [diff] [blame] | 193 | * _base_get_chain - Calculates and Returns virtual chain address |
| 194 | * for the provided smid in BAR0 space. |
| 195 | * |
| 196 | * @ioc: per adapter object |
| 197 | * @smid: system request message index |
| 198 | * @sge_chain_count: Scatter gather chain count. |
| 199 | * |
| 200 | * @Return: chain address. |
| 201 | */ |
| 202 | static inline void __iomem* |
| 203 | _base_get_chain(struct MPT3SAS_ADAPTER *ioc, u16 smid, |
| 204 | u8 sge_chain_count) |
| 205 | { |
| 206 | void __iomem *base_chain, *chain_virt; |
| 207 | u16 cmd_credit = ioc->facts.RequestCredit + 1; |
| 208 | |
| 209 | base_chain = (void __iomem *)ioc->chip + MPI_FRAME_START_OFFSET + |
| 210 | (cmd_credit * ioc->request_sz) + |
| 211 | REPLY_FREE_POOL_SIZE; |
| 212 | chain_virt = base_chain + (smid * ioc->facts.MaxChainDepth * |
| 213 | ioc->request_sz) + (sge_chain_count * ioc->request_sz); |
| 214 | return chain_virt; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * _base_get_chain_phys - Calculates and Returns physical address |
| 219 | * in BAR0 for scatter gather chains, for |
| 220 | * the provided smid. |
| 221 | * |
| 222 | * @ioc: per adapter object |
| 223 | * @smid: system request message index |
| 224 | * @sge_chain_count: Scatter gather chain count. |
| 225 | * |
| 226 | * @Return - Physical chain address. |
| 227 | */ |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 228 | static inline phys_addr_t |
Suganath Prabu Subramani | 22ae5a3 | 2018-02-07 02:51:47 -0800 | [diff] [blame] | 229 | _base_get_chain_phys(struct MPT3SAS_ADAPTER *ioc, u16 smid, |
| 230 | u8 sge_chain_count) |
| 231 | { |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 232 | phys_addr_t base_chain_phys, chain_phys; |
Suganath Prabu Subramani | 22ae5a3 | 2018-02-07 02:51:47 -0800 | [diff] [blame] | 233 | u16 cmd_credit = ioc->facts.RequestCredit + 1; |
| 234 | |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 235 | base_chain_phys = ioc->chip_phys + MPI_FRAME_START_OFFSET + |
Suganath Prabu Subramani | 22ae5a3 | 2018-02-07 02:51:47 -0800 | [diff] [blame] | 236 | (cmd_credit * ioc->request_sz) + |
| 237 | REPLY_FREE_POOL_SIZE; |
| 238 | chain_phys = base_chain_phys + (smid * ioc->facts.MaxChainDepth * |
| 239 | ioc->request_sz) + (sge_chain_count * ioc->request_sz); |
| 240 | return chain_phys; |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * _base_get_buffer_bar0 - Calculates and Returns BAR0 mapped Host |
| 245 | * buffer address for the provided smid. |
| 246 | * (Each smid can have 64K starts from 17024) |
| 247 | * |
| 248 | * @ioc: per adapter object |
| 249 | * @smid: system request message index |
| 250 | * |
| 251 | * @Returns - Pointer to buffer location in BAR0. |
| 252 | */ |
| 253 | |
| 254 | static void __iomem * |
| 255 | _base_get_buffer_bar0(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 256 | { |
| 257 | u16 cmd_credit = ioc->facts.RequestCredit + 1; |
| 258 | // Added extra 1 to reach end of chain. |
| 259 | void __iomem *chain_end = _base_get_chain(ioc, |
| 260 | cmd_credit + 1, |
| 261 | ioc->facts.MaxChainDepth); |
| 262 | return chain_end + (smid * 64 * 1024); |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * _base_get_buffer_phys_bar0 - Calculates and Returns BAR0 mapped |
| 267 | * Host buffer Physical address for the provided smid. |
| 268 | * (Each smid can have 64K starts from 17024) |
| 269 | * |
| 270 | * @ioc: per adapter object |
| 271 | * @smid: system request message index |
| 272 | * |
| 273 | * @Returns - Pointer to buffer location in BAR0. |
| 274 | */ |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 275 | static phys_addr_t |
Suganath Prabu Subramani | 22ae5a3 | 2018-02-07 02:51:47 -0800 | [diff] [blame] | 276 | _base_get_buffer_phys_bar0(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 277 | { |
| 278 | u16 cmd_credit = ioc->facts.RequestCredit + 1; |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 279 | phys_addr_t chain_end_phys = _base_get_chain_phys(ioc, |
Suganath Prabu Subramani | 22ae5a3 | 2018-02-07 02:51:47 -0800 | [diff] [blame] | 280 | cmd_credit + 1, |
| 281 | ioc->facts.MaxChainDepth); |
| 282 | return chain_end_phys + (smid * 64 * 1024); |
| 283 | } |
| 284 | |
| 285 | /** |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 286 | * _base_get_chain_buffer_dma_to_chain_buffer - Iterates chain |
| 287 | * lookup list and Provides chain_buffer |
| 288 | * address for the matching dma address. |
| 289 | * (Each smid can have 64K starts from 17024) |
| 290 | * |
| 291 | * @ioc: per adapter object |
| 292 | * @chain_buffer_dma: Chain buffer dma address. |
| 293 | * |
| 294 | * @Returns - Pointer to chain buffer. Or Null on Failure. |
| 295 | */ |
| 296 | static void * |
| 297 | _base_get_chain_buffer_dma_to_chain_buffer(struct MPT3SAS_ADAPTER *ioc, |
| 298 | dma_addr_t chain_buffer_dma) |
| 299 | { |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 300 | u16 index, j; |
| 301 | struct chain_tracker *ct; |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 302 | |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 303 | for (index = 0; index < ioc->scsiio_depth; index++) { |
| 304 | for (j = 0; j < ioc->chains_needed_per_io; j++) { |
| 305 | ct = &ioc->chain_lookup[index].chains_per_smid[j]; |
| 306 | if (ct && ct->chain_buffer_dma == chain_buffer_dma) |
| 307 | return ct->chain_buffer; |
| 308 | } |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 309 | } |
| 310 | pr_info(MPT3SAS_FMT |
| 311 | "Provided chain_buffer_dma address is not in the lookup list\n", |
| 312 | ioc->name); |
| 313 | return NULL; |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * _clone_sg_entries - MPI EP's scsiio and config requests |
| 318 | * are handled here. Base function for |
| 319 | * double buffering, before submitting |
| 320 | * the requests. |
| 321 | * |
| 322 | * @ioc: per adapter object. |
| 323 | * @mpi_request: mf request pointer. |
| 324 | * @smid: system request message index. |
| 325 | * |
| 326 | * @Returns: Nothing. |
| 327 | */ |
| 328 | static void _clone_sg_entries(struct MPT3SAS_ADAPTER *ioc, |
| 329 | void *mpi_request, u16 smid) |
| 330 | { |
| 331 | Mpi2SGESimple32_t *sgel, *sgel_next; |
| 332 | u32 sgl_flags, sge_chain_count = 0; |
| 333 | bool is_write = 0; |
| 334 | u16 i = 0; |
| 335 | void __iomem *buffer_iomem; |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 336 | phys_addr_t buffer_iomem_phys; |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 337 | void __iomem *buff_ptr; |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 338 | phys_addr_t buff_ptr_phys; |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 339 | void __iomem *dst_chain_addr[MCPU_MAX_CHAINS_PER_IO]; |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 340 | void *src_chain_addr[MCPU_MAX_CHAINS_PER_IO]; |
| 341 | phys_addr_t dst_addr_phys; |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 342 | MPI2RequestHeader_t *request_hdr; |
| 343 | struct scsi_cmnd *scmd; |
| 344 | struct scatterlist *sg_scmd = NULL; |
| 345 | int is_scsiio_req = 0; |
| 346 | |
| 347 | request_hdr = (MPI2RequestHeader_t *) mpi_request; |
| 348 | |
| 349 | if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST) { |
| 350 | Mpi25SCSIIORequest_t *scsiio_request = |
| 351 | (Mpi25SCSIIORequest_t *)mpi_request; |
| 352 | sgel = (Mpi2SGESimple32_t *) &scsiio_request->SGL; |
| 353 | is_scsiio_req = 1; |
| 354 | } else if (request_hdr->Function == MPI2_FUNCTION_CONFIG) { |
| 355 | Mpi2ConfigRequest_t *config_req = |
| 356 | (Mpi2ConfigRequest_t *)mpi_request; |
| 357 | sgel = (Mpi2SGESimple32_t *) &config_req->PageBufferSGE; |
| 358 | } else |
| 359 | return; |
| 360 | |
| 361 | /* From smid we can get scsi_cmd, once we have sg_scmd, |
| 362 | * we just need to get sg_virt and sg_next to get virual |
| 363 | * address associated with sgel->Address. |
| 364 | */ |
| 365 | |
| 366 | if (is_scsiio_req) { |
| 367 | /* Get scsi_cmd using smid */ |
| 368 | scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); |
| 369 | if (scmd == NULL) { |
| 370 | pr_err(MPT3SAS_FMT "scmd is NULL\n", ioc->name); |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | /* Get sg_scmd from scmd provided */ |
| 375 | sg_scmd = scsi_sglist(scmd); |
| 376 | } |
| 377 | |
| 378 | /* |
| 379 | * 0 - 255 System register |
| 380 | * 256 - 4352 MPI Frame. (This is based on maxCredit 32) |
| 381 | * 4352 - 4864 Reply_free pool (512 byte is reserved |
| 382 | * considering maxCredit 32. Reply need extra |
| 383 | * room, for mCPU case kept four times of |
| 384 | * maxCredit). |
| 385 | * 4864 - 17152 SGE chain element. (32cmd * 3 chain of |
| 386 | * 128 byte size = 12288) |
| 387 | * 17152 - x Host buffer mapped with smid. |
| 388 | * (Each smid can have 64K Max IO.) |
| 389 | * BAR0+Last 1K MSIX Addr and Data |
| 390 | * Total size in use 2113664 bytes of 4MB BAR0 |
| 391 | */ |
| 392 | |
| 393 | buffer_iomem = _base_get_buffer_bar0(ioc, smid); |
| 394 | buffer_iomem_phys = _base_get_buffer_phys_bar0(ioc, smid); |
| 395 | |
| 396 | buff_ptr = buffer_iomem; |
| 397 | buff_ptr_phys = buffer_iomem_phys; |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 398 | WARN_ON(buff_ptr_phys > U32_MAX); |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 399 | |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 400 | if (le32_to_cpu(sgel->FlagsLength) & |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 401 | (MPI2_SGE_FLAGS_HOST_TO_IOC << MPI2_SGE_FLAGS_SHIFT)) |
| 402 | is_write = 1; |
| 403 | |
| 404 | for (i = 0; i < MPT_MIN_PHYS_SEGMENTS + ioc->facts.MaxChainDepth; i++) { |
| 405 | |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 406 | sgl_flags = |
| 407 | (le32_to_cpu(sgel->FlagsLength) >> MPI2_SGE_FLAGS_SHIFT); |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 408 | |
| 409 | switch (sgl_flags & MPI2_SGE_FLAGS_ELEMENT_MASK) { |
| 410 | case MPI2_SGE_FLAGS_CHAIN_ELEMENT: |
| 411 | /* |
| 412 | * Helper function which on passing |
| 413 | * chain_buffer_dma returns chain_buffer. Get |
| 414 | * the virtual address for sgel->Address |
| 415 | */ |
| 416 | sgel_next = |
| 417 | _base_get_chain_buffer_dma_to_chain_buffer(ioc, |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 418 | le32_to_cpu(sgel->Address)); |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 419 | if (sgel_next == NULL) |
| 420 | return; |
| 421 | /* |
| 422 | * This is coping 128 byte chain |
| 423 | * frame (not a host buffer) |
| 424 | */ |
| 425 | dst_chain_addr[sge_chain_count] = |
| 426 | _base_get_chain(ioc, |
| 427 | smid, sge_chain_count); |
| 428 | src_chain_addr[sge_chain_count] = |
| 429 | (void *) sgel_next; |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 430 | dst_addr_phys = _base_get_chain_phys(ioc, |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 431 | smid, sge_chain_count); |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 432 | WARN_ON(dst_addr_phys > U32_MAX); |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 433 | sgel->Address = |
| 434 | cpu_to_le32(lower_32_bits(dst_addr_phys)); |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 435 | sgel = sgel_next; |
| 436 | sge_chain_count++; |
| 437 | break; |
| 438 | case MPI2_SGE_FLAGS_SIMPLE_ELEMENT: |
| 439 | if (is_write) { |
| 440 | if (is_scsiio_req) { |
| 441 | _base_clone_to_sys_mem(buff_ptr, |
| 442 | sg_virt(sg_scmd), |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 443 | (le32_to_cpu(sgel->FlagsLength) & |
| 444 | 0x00ffffff)); |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 445 | /* |
| 446 | * FIXME: this relies on a a zero |
| 447 | * PCI mem_offset. |
| 448 | */ |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 449 | sgel->Address = |
| 450 | cpu_to_le32((u32)buff_ptr_phys); |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 451 | } else { |
| 452 | _base_clone_to_sys_mem(buff_ptr, |
| 453 | ioc->config_vaddr, |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 454 | (le32_to_cpu(sgel->FlagsLength) & |
| 455 | 0x00ffffff)); |
| 456 | sgel->Address = |
| 457 | cpu_to_le32((u32)buff_ptr_phys); |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 458 | } |
| 459 | } |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 460 | buff_ptr += (le32_to_cpu(sgel->FlagsLength) & |
| 461 | 0x00ffffff); |
| 462 | buff_ptr_phys += (le32_to_cpu(sgel->FlagsLength) & |
| 463 | 0x00ffffff); |
| 464 | if ((le32_to_cpu(sgel->FlagsLength) & |
Suganath Prabu Subramani | 182ac78 | 2018-02-07 02:51:48 -0800 | [diff] [blame] | 465 | (MPI2_SGE_FLAGS_END_OF_BUFFER |
| 466 | << MPI2_SGE_FLAGS_SHIFT))) |
| 467 | goto eob_clone_chain; |
| 468 | else { |
| 469 | /* |
| 470 | * Every single element in MPT will have |
| 471 | * associated sg_next. Better to sanity that |
| 472 | * sg_next is not NULL, but it will be a bug |
| 473 | * if it is null. |
| 474 | */ |
| 475 | if (is_scsiio_req) { |
| 476 | sg_scmd = sg_next(sg_scmd); |
| 477 | if (sg_scmd) |
| 478 | sgel++; |
| 479 | else |
| 480 | goto eob_clone_chain; |
| 481 | } |
| 482 | } |
| 483 | break; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | eob_clone_chain: |
| 488 | for (i = 0; i < sge_chain_count; i++) { |
| 489 | if (is_scsiio_req) |
| 490 | _base_clone_to_sys_mem(dst_chain_addr[i], |
| 491 | src_chain_addr[i], ioc->request_sz); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 496 | * mpt3sas_remove_dead_ioc_func - kthread context to remove dead ioc |
| 497 | * @arg: input argument, used to derive ioc |
| 498 | * |
| 499 | * Return 0 if controller is removed from pci subsystem. |
| 500 | * Return -1 for other case. |
| 501 | */ |
| 502 | static int mpt3sas_remove_dead_ioc_func(void *arg) |
| 503 | { |
| 504 | struct MPT3SAS_ADAPTER *ioc = (struct MPT3SAS_ADAPTER *)arg; |
| 505 | struct pci_dev *pdev; |
| 506 | |
| 507 | if ((ioc == NULL)) |
| 508 | return -1; |
| 509 | |
| 510 | pdev = ioc->pdev; |
| 511 | if ((pdev == NULL)) |
| 512 | return -1; |
Rafael J. Wysocki | 64cdb41 | 2014-01-10 15:27:56 +0100 | [diff] [blame] | 513 | pci_stop_and_remove_bus_device_locked(pdev); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * _base_fault_reset_work - workq handling ioc fault conditions |
| 519 | * @work: input argument, used to derive ioc |
| 520 | * Context: sleep. |
| 521 | * |
| 522 | * Return nothing. |
| 523 | */ |
| 524 | static void |
| 525 | _base_fault_reset_work(struct work_struct *work) |
| 526 | { |
| 527 | struct MPT3SAS_ADAPTER *ioc = |
| 528 | container_of(work, struct MPT3SAS_ADAPTER, fault_reset_work.work); |
| 529 | unsigned long flags; |
| 530 | u32 doorbell; |
| 531 | int rc; |
| 532 | struct task_struct *p; |
| 533 | |
| 534 | |
| 535 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
Sreekanth Reddy | 16e179b | 2015-11-11 17:30:27 +0530 | [diff] [blame] | 536 | if (ioc->shost_recovery || ioc->pci_error_recovery) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 537 | goto rearm_timer; |
| 538 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 539 | |
| 540 | doorbell = mpt3sas_base_get_iocstate(ioc, 0); |
| 541 | if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_MASK) { |
| 542 | pr_err(MPT3SAS_FMT "SAS host is non-operational !!!!\n", |
| 543 | ioc->name); |
| 544 | |
Sreekanth Reddy | 16e179b | 2015-11-11 17:30:27 +0530 | [diff] [blame] | 545 | /* It may be possible that EEH recovery can resolve some of |
| 546 | * pci bus failure issues rather removing the dead ioc function |
| 547 | * by considering controller is in a non-operational state. So |
| 548 | * here priority is given to the EEH recovery. If it doesn't |
| 549 | * not resolve this issue, mpt3sas driver will consider this |
| 550 | * controller to non-operational state and remove the dead ioc |
| 551 | * function. |
| 552 | */ |
| 553 | if (ioc->non_operational_loop++ < 5) { |
| 554 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, |
| 555 | flags); |
| 556 | goto rearm_timer; |
| 557 | } |
| 558 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 559 | /* |
| 560 | * Call _scsih_flush_pending_cmds callback so that we flush all |
| 561 | * pending commands back to OS. This call is required to aovid |
| 562 | * deadlock at block layer. Dead IOC will fail to do diag reset, |
| 563 | * and this call is safe since dead ioc will never return any |
| 564 | * command back from HW. |
| 565 | */ |
| 566 | ioc->schedule_dead_ioc_flush_running_cmds(ioc); |
| 567 | /* |
| 568 | * Set remove_host flag early since kernel thread will |
| 569 | * take some time to execute. |
| 570 | */ |
| 571 | ioc->remove_host = 1; |
| 572 | /*Remove the Dead Host */ |
| 573 | p = kthread_run(mpt3sas_remove_dead_ioc_func, ioc, |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 574 | "%s_dead_ioc_%d", ioc->driver_name, ioc->id); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 575 | if (IS_ERR(p)) |
| 576 | pr_err(MPT3SAS_FMT |
| 577 | "%s: Running mpt3sas_dead_ioc thread failed !!!!\n", |
| 578 | ioc->name, __func__); |
| 579 | else |
| 580 | pr_err(MPT3SAS_FMT |
| 581 | "%s: Running mpt3sas_dead_ioc thread success !!!!\n", |
| 582 | ioc->name, __func__); |
| 583 | return; /* don't rearm timer */ |
| 584 | } |
| 585 | |
Sreekanth Reddy | 16e179b | 2015-11-11 17:30:27 +0530 | [diff] [blame] | 586 | ioc->non_operational_loop = 0; |
| 587 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 588 | if ((doorbell & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL) { |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 589 | rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 590 | pr_warn(MPT3SAS_FMT "%s: hard reset: %s\n", ioc->name, |
| 591 | __func__, (rc == 0) ? "success" : "failed"); |
| 592 | doorbell = mpt3sas_base_get_iocstate(ioc, 0); |
| 593 | if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) |
| 594 | mpt3sas_base_fault_info(ioc, doorbell & |
| 595 | MPI2_DOORBELL_DATA_MASK); |
| 596 | if (rc && (doorbell & MPI2_IOC_STATE_MASK) != |
| 597 | MPI2_IOC_STATE_OPERATIONAL) |
| 598 | return; /* don't rearm timer */ |
| 599 | } |
| 600 | |
| 601 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 602 | rearm_timer: |
| 603 | if (ioc->fault_reset_work_q) |
| 604 | queue_delayed_work(ioc->fault_reset_work_q, |
| 605 | &ioc->fault_reset_work, |
| 606 | msecs_to_jiffies(FAULT_POLLING_INTERVAL)); |
| 607 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * mpt3sas_base_start_watchdog - start the fault_reset_work_q |
| 612 | * @ioc: per adapter object |
| 613 | * Context: sleep. |
| 614 | * |
| 615 | * Return nothing. |
| 616 | */ |
| 617 | void |
| 618 | mpt3sas_base_start_watchdog(struct MPT3SAS_ADAPTER *ioc) |
| 619 | { |
| 620 | unsigned long flags; |
| 621 | |
| 622 | if (ioc->fault_reset_work_q) |
| 623 | return; |
| 624 | |
| 625 | /* initialize fault polling */ |
| 626 | |
| 627 | INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work); |
| 628 | snprintf(ioc->fault_reset_work_q_name, |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 629 | sizeof(ioc->fault_reset_work_q_name), "poll_%s%d_status", |
| 630 | ioc->driver_name, ioc->id); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 631 | ioc->fault_reset_work_q = |
| 632 | create_singlethread_workqueue(ioc->fault_reset_work_q_name); |
| 633 | if (!ioc->fault_reset_work_q) { |
| 634 | pr_err(MPT3SAS_FMT "%s: failed (line=%d)\n", |
| 635 | ioc->name, __func__, __LINE__); |
| 636 | return; |
| 637 | } |
| 638 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 639 | if (ioc->fault_reset_work_q) |
| 640 | queue_delayed_work(ioc->fault_reset_work_q, |
| 641 | &ioc->fault_reset_work, |
| 642 | msecs_to_jiffies(FAULT_POLLING_INTERVAL)); |
| 643 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 644 | } |
| 645 | |
| 646 | /** |
| 647 | * mpt3sas_base_stop_watchdog - stop the fault_reset_work_q |
| 648 | * @ioc: per adapter object |
| 649 | * Context: sleep. |
| 650 | * |
| 651 | * Return nothing. |
| 652 | */ |
| 653 | void |
| 654 | mpt3sas_base_stop_watchdog(struct MPT3SAS_ADAPTER *ioc) |
| 655 | { |
| 656 | unsigned long flags; |
| 657 | struct workqueue_struct *wq; |
| 658 | |
| 659 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 660 | wq = ioc->fault_reset_work_q; |
| 661 | ioc->fault_reset_work_q = NULL; |
| 662 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 663 | if (wq) { |
Reddy, Sreekanth | 4dc06fd | 2014-07-14 12:01:35 +0530 | [diff] [blame] | 664 | if (!cancel_delayed_work_sync(&ioc->fault_reset_work)) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 665 | flush_workqueue(wq); |
| 666 | destroy_workqueue(wq); |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * mpt3sas_base_fault_info - verbose translation of firmware FAULT code |
| 672 | * @ioc: per adapter object |
| 673 | * @fault_code: fault code |
| 674 | * |
| 675 | * Return nothing. |
| 676 | */ |
| 677 | void |
| 678 | mpt3sas_base_fault_info(struct MPT3SAS_ADAPTER *ioc , u16 fault_code) |
| 679 | { |
| 680 | pr_err(MPT3SAS_FMT "fault_state(0x%04x)!\n", |
| 681 | ioc->name, fault_code); |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * mpt3sas_halt_firmware - halt's mpt controller firmware |
| 686 | * @ioc: per adapter object |
| 687 | * |
| 688 | * For debugging timeout related issues. Writing 0xCOFFEE00 |
| 689 | * to the doorbell register will halt controller firmware. With |
| 690 | * the purpose to stop both driver and firmware, the enduser can |
| 691 | * obtain a ring buffer from controller UART. |
| 692 | */ |
| 693 | void |
| 694 | mpt3sas_halt_firmware(struct MPT3SAS_ADAPTER *ioc) |
| 695 | { |
| 696 | u32 doorbell; |
| 697 | |
| 698 | if (!ioc->fwfault_debug) |
| 699 | return; |
| 700 | |
| 701 | dump_stack(); |
| 702 | |
| 703 | doorbell = readl(&ioc->chip->Doorbell); |
| 704 | if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) |
| 705 | mpt3sas_base_fault_info(ioc , doorbell); |
| 706 | else { |
| 707 | writel(0xC0FFEE00, &ioc->chip->Doorbell); |
| 708 | pr_err(MPT3SAS_FMT "Firmware is halted due to command timeout\n", |
| 709 | ioc->name); |
| 710 | } |
| 711 | |
| 712 | if (ioc->fwfault_debug == 2) |
| 713 | for (;;) |
| 714 | ; |
| 715 | else |
| 716 | panic("panic in %s\n", __func__); |
| 717 | } |
| 718 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 719 | /** |
| 720 | * _base_sas_ioc_info - verbose translation of the ioc status |
| 721 | * @ioc: per adapter object |
| 722 | * @mpi_reply: reply mf payload returned from firmware |
| 723 | * @request_hdr: request mf |
| 724 | * |
| 725 | * Return nothing. |
| 726 | */ |
| 727 | static void |
| 728 | _base_sas_ioc_info(struct MPT3SAS_ADAPTER *ioc, MPI2DefaultReply_t *mpi_reply, |
| 729 | MPI2RequestHeader_t *request_hdr) |
| 730 | { |
| 731 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & |
| 732 | MPI2_IOCSTATUS_MASK; |
| 733 | char *desc = NULL; |
| 734 | u16 frame_sz; |
| 735 | char *func_str = NULL; |
| 736 | |
| 737 | /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */ |
| 738 | if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || |
| 739 | request_hdr->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH || |
| 740 | request_hdr->Function == MPI2_FUNCTION_EVENT_NOTIFICATION) |
| 741 | return; |
| 742 | |
| 743 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 744 | return; |
| 745 | |
| 746 | switch (ioc_status) { |
| 747 | |
| 748 | /**************************************************************************** |
| 749 | * Common IOCStatus values for all replies |
| 750 | ****************************************************************************/ |
| 751 | |
| 752 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 753 | desc = "invalid function"; |
| 754 | break; |
| 755 | case MPI2_IOCSTATUS_BUSY: |
| 756 | desc = "busy"; |
| 757 | break; |
| 758 | case MPI2_IOCSTATUS_INVALID_SGL: |
| 759 | desc = "invalid sgl"; |
| 760 | break; |
| 761 | case MPI2_IOCSTATUS_INTERNAL_ERROR: |
| 762 | desc = "internal error"; |
| 763 | break; |
| 764 | case MPI2_IOCSTATUS_INVALID_VPID: |
| 765 | desc = "invalid vpid"; |
| 766 | break; |
| 767 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: |
| 768 | desc = "insufficient resources"; |
| 769 | break; |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 770 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
| 771 | desc = "insufficient power"; |
| 772 | break; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 773 | case MPI2_IOCSTATUS_INVALID_FIELD: |
| 774 | desc = "invalid field"; |
| 775 | break; |
| 776 | case MPI2_IOCSTATUS_INVALID_STATE: |
| 777 | desc = "invalid state"; |
| 778 | break; |
| 779 | case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED: |
| 780 | desc = "op state not supported"; |
| 781 | break; |
| 782 | |
| 783 | /**************************************************************************** |
| 784 | * Config IOCStatus values |
| 785 | ****************************************************************************/ |
| 786 | |
| 787 | case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION: |
| 788 | desc = "config invalid action"; |
| 789 | break; |
| 790 | case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE: |
| 791 | desc = "config invalid type"; |
| 792 | break; |
| 793 | case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE: |
| 794 | desc = "config invalid page"; |
| 795 | break; |
| 796 | case MPI2_IOCSTATUS_CONFIG_INVALID_DATA: |
| 797 | desc = "config invalid data"; |
| 798 | break; |
| 799 | case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS: |
| 800 | desc = "config no defaults"; |
| 801 | break; |
| 802 | case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT: |
| 803 | desc = "config cant commit"; |
| 804 | break; |
| 805 | |
| 806 | /**************************************************************************** |
| 807 | * SCSI IO Reply |
| 808 | ****************************************************************************/ |
| 809 | |
| 810 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 811 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: |
| 812 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 813 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 814 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 815 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 816 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 817 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 818 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 819 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 820 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 821 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 822 | break; |
| 823 | |
| 824 | /**************************************************************************** |
| 825 | * For use by SCSI Initiator and SCSI Target end-to-end data protection |
| 826 | ****************************************************************************/ |
| 827 | |
| 828 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 829 | desc = "eedp guard error"; |
| 830 | break; |
| 831 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 832 | desc = "eedp ref tag error"; |
| 833 | break; |
| 834 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 835 | desc = "eedp app tag error"; |
| 836 | break; |
| 837 | |
| 838 | /**************************************************************************** |
| 839 | * SCSI Target values |
| 840 | ****************************************************************************/ |
| 841 | |
| 842 | case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX: |
| 843 | desc = "target invalid io index"; |
| 844 | break; |
| 845 | case MPI2_IOCSTATUS_TARGET_ABORTED: |
| 846 | desc = "target aborted"; |
| 847 | break; |
| 848 | case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE: |
| 849 | desc = "target no conn retryable"; |
| 850 | break; |
| 851 | case MPI2_IOCSTATUS_TARGET_NO_CONNECTION: |
| 852 | desc = "target no connection"; |
| 853 | break; |
| 854 | case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH: |
| 855 | desc = "target xfer count mismatch"; |
| 856 | break; |
| 857 | case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR: |
| 858 | desc = "target data offset error"; |
| 859 | break; |
| 860 | case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA: |
| 861 | desc = "target too much write data"; |
| 862 | break; |
| 863 | case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT: |
| 864 | desc = "target iu too short"; |
| 865 | break; |
| 866 | case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT: |
| 867 | desc = "target ack nak timeout"; |
| 868 | break; |
| 869 | case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED: |
| 870 | desc = "target nak received"; |
| 871 | break; |
| 872 | |
| 873 | /**************************************************************************** |
| 874 | * Serial Attached SCSI values |
| 875 | ****************************************************************************/ |
| 876 | |
| 877 | case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED: |
| 878 | desc = "smp request failed"; |
| 879 | break; |
| 880 | case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN: |
| 881 | desc = "smp data overrun"; |
| 882 | break; |
| 883 | |
| 884 | /**************************************************************************** |
| 885 | * Diagnostic Buffer Post / Diagnostic Release values |
| 886 | ****************************************************************************/ |
| 887 | |
| 888 | case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED: |
| 889 | desc = "diagnostic released"; |
| 890 | break; |
| 891 | default: |
| 892 | break; |
| 893 | } |
| 894 | |
| 895 | if (!desc) |
| 896 | return; |
| 897 | |
| 898 | switch (request_hdr->Function) { |
| 899 | case MPI2_FUNCTION_CONFIG: |
| 900 | frame_sz = sizeof(Mpi2ConfigRequest_t) + ioc->sge_size; |
| 901 | func_str = "config_page"; |
| 902 | break; |
| 903 | case MPI2_FUNCTION_SCSI_TASK_MGMT: |
| 904 | frame_sz = sizeof(Mpi2SCSITaskManagementRequest_t); |
| 905 | func_str = "task_mgmt"; |
| 906 | break; |
| 907 | case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL: |
| 908 | frame_sz = sizeof(Mpi2SasIoUnitControlRequest_t); |
| 909 | func_str = "sas_iounit_ctl"; |
| 910 | break; |
| 911 | case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR: |
| 912 | frame_sz = sizeof(Mpi2SepRequest_t); |
| 913 | func_str = "enclosure"; |
| 914 | break; |
| 915 | case MPI2_FUNCTION_IOC_INIT: |
| 916 | frame_sz = sizeof(Mpi2IOCInitRequest_t); |
| 917 | func_str = "ioc_init"; |
| 918 | break; |
| 919 | case MPI2_FUNCTION_PORT_ENABLE: |
| 920 | frame_sz = sizeof(Mpi2PortEnableRequest_t); |
| 921 | func_str = "port_enable"; |
| 922 | break; |
| 923 | case MPI2_FUNCTION_SMP_PASSTHROUGH: |
| 924 | frame_sz = sizeof(Mpi2SmpPassthroughRequest_t) + ioc->sge_size; |
| 925 | func_str = "smp_passthru"; |
| 926 | break; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 927 | case MPI2_FUNCTION_NVME_ENCAPSULATED: |
| 928 | frame_sz = sizeof(Mpi26NVMeEncapsulatedRequest_t) + |
| 929 | ioc->sge_size; |
| 930 | func_str = "nvme_encapsulated"; |
| 931 | break; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 932 | default: |
| 933 | frame_sz = 32; |
| 934 | func_str = "unknown"; |
| 935 | break; |
| 936 | } |
| 937 | |
| 938 | pr_warn(MPT3SAS_FMT "ioc_status: %s(0x%04x), request(0x%p),(%s)\n", |
| 939 | ioc->name, desc, ioc_status, request_hdr, func_str); |
| 940 | |
| 941 | _debug_dump_mf(request_hdr, frame_sz/4); |
| 942 | } |
| 943 | |
| 944 | /** |
| 945 | * _base_display_event_data - verbose translation of firmware asyn events |
| 946 | * @ioc: per adapter object |
| 947 | * @mpi_reply: reply mf payload returned from firmware |
| 948 | * |
| 949 | * Return nothing. |
| 950 | */ |
| 951 | static void |
| 952 | _base_display_event_data(struct MPT3SAS_ADAPTER *ioc, |
| 953 | Mpi2EventNotificationReply_t *mpi_reply) |
| 954 | { |
| 955 | char *desc = NULL; |
| 956 | u16 event; |
| 957 | |
| 958 | if (!(ioc->logging_level & MPT_DEBUG_EVENTS)) |
| 959 | return; |
| 960 | |
| 961 | event = le16_to_cpu(mpi_reply->Event); |
| 962 | |
| 963 | switch (event) { |
| 964 | case MPI2_EVENT_LOG_DATA: |
| 965 | desc = "Log Data"; |
| 966 | break; |
| 967 | case MPI2_EVENT_STATE_CHANGE: |
| 968 | desc = "Status Change"; |
| 969 | break; |
| 970 | case MPI2_EVENT_HARD_RESET_RECEIVED: |
| 971 | desc = "Hard Reset Received"; |
| 972 | break; |
| 973 | case MPI2_EVENT_EVENT_CHANGE: |
| 974 | desc = "Event Change"; |
| 975 | break; |
| 976 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 977 | desc = "Device Status Change"; |
| 978 | break; |
| 979 | case MPI2_EVENT_IR_OPERATION_STATUS: |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 980 | if (!ioc->hide_ir_msg) |
| 981 | desc = "IR Operation Status"; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 982 | break; |
| 983 | case MPI2_EVENT_SAS_DISCOVERY: |
| 984 | { |
| 985 | Mpi2EventDataSasDiscovery_t *event_data = |
| 986 | (Mpi2EventDataSasDiscovery_t *)mpi_reply->EventData; |
| 987 | pr_info(MPT3SAS_FMT "Discovery: (%s)", ioc->name, |
| 988 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? |
| 989 | "start" : "stop"); |
| 990 | if (event_data->DiscoveryStatus) |
Colin Ian King | bbaf61e | 2017-08-15 14:51:45 +0100 | [diff] [blame] | 991 | pr_cont(" discovery_status(0x%08x)", |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 992 | le32_to_cpu(event_data->DiscoveryStatus)); |
Colin Ian King | bbaf61e | 2017-08-15 14:51:45 +0100 | [diff] [blame] | 993 | pr_cont("\n"); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 994 | return; |
| 995 | } |
| 996 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 997 | desc = "SAS Broadcast Primitive"; |
| 998 | break; |
| 999 | case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE: |
| 1000 | desc = "SAS Init Device Status Change"; |
| 1001 | break; |
| 1002 | case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW: |
| 1003 | desc = "SAS Init Table Overflow"; |
| 1004 | break; |
| 1005 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 1006 | desc = "SAS Topology Change List"; |
| 1007 | break; |
| 1008 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 1009 | desc = "SAS Enclosure Device Status Change"; |
| 1010 | break; |
| 1011 | case MPI2_EVENT_IR_VOLUME: |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 1012 | if (!ioc->hide_ir_msg) |
| 1013 | desc = "IR Volume"; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1014 | break; |
| 1015 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 1016 | if (!ioc->hide_ir_msg) |
| 1017 | desc = "IR Physical Disk"; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1018 | break; |
| 1019 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 1020 | if (!ioc->hide_ir_msg) |
| 1021 | desc = "IR Configuration Change List"; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1022 | break; |
| 1023 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 1024 | if (!ioc->hide_ir_msg) |
| 1025 | desc = "Log Entry Added"; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1026 | break; |
Sreekanth Reddy | 2d8ce8c | 2015-01-12 11:38:56 +0530 | [diff] [blame] | 1027 | case MPI2_EVENT_TEMP_THRESHOLD: |
| 1028 | desc = "Temperature Threshold"; |
| 1029 | break; |
Chaitra P B | a470a51 | 2016-05-06 14:29:27 +0530 | [diff] [blame] | 1030 | case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION: |
Sreekanth Reddy | b99b199 | 2017-10-10 18:41:14 +0530 | [diff] [blame] | 1031 | desc = "Cable Event"; |
Chaitra P B | a470a51 | 2016-05-06 14:29:27 +0530 | [diff] [blame] | 1032 | break; |
Chaitra P B | 95540b8 | 2018-04-24 05:28:35 -0400 | [diff] [blame^] | 1033 | case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR: |
| 1034 | desc = "SAS Device Discovery Error"; |
| 1035 | break; |
Suganath Prabu Subramani | 4318c73 | 2017-10-31 18:02:32 +0530 | [diff] [blame] | 1036 | case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE: |
| 1037 | desc = "PCIE Device Status Change"; |
| 1038 | break; |
| 1039 | case MPI2_EVENT_PCIE_ENUMERATION: |
| 1040 | { |
| 1041 | Mpi26EventDataPCIeEnumeration_t *event_data = |
| 1042 | (Mpi26EventDataPCIeEnumeration_t *)mpi_reply->EventData; |
| 1043 | pr_info(MPT3SAS_FMT "PCIE Enumeration: (%s)", ioc->name, |
| 1044 | (event_data->ReasonCode == |
| 1045 | MPI26_EVENT_PCIE_ENUM_RC_STARTED) ? |
| 1046 | "start" : "stop"); |
| 1047 | if (event_data->EnumerationStatus) |
| 1048 | pr_info("enumeration_status(0x%08x)", |
| 1049 | le32_to_cpu(event_data->EnumerationStatus)); |
| 1050 | pr_info("\n"); |
| 1051 | return; |
| 1052 | } |
| 1053 | case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST: |
| 1054 | desc = "PCIE Topology Change List"; |
| 1055 | break; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | if (!desc) |
| 1059 | return; |
| 1060 | |
| 1061 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, desc); |
| 1062 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1063 | |
| 1064 | /** |
| 1065 | * _base_sas_log_info - verbose translation of firmware log info |
| 1066 | * @ioc: per adapter object |
| 1067 | * @log_info: log info |
| 1068 | * |
| 1069 | * Return nothing. |
| 1070 | */ |
| 1071 | static void |
| 1072 | _base_sas_log_info(struct MPT3SAS_ADAPTER *ioc , u32 log_info) |
| 1073 | { |
| 1074 | union loginfo_type { |
| 1075 | u32 loginfo; |
| 1076 | struct { |
| 1077 | u32 subcode:16; |
| 1078 | u32 code:8; |
| 1079 | u32 originator:4; |
| 1080 | u32 bus_type:4; |
| 1081 | } dw; |
| 1082 | }; |
| 1083 | union loginfo_type sas_loginfo; |
| 1084 | char *originator_str = NULL; |
| 1085 | |
| 1086 | sas_loginfo.loginfo = log_info; |
| 1087 | if (sas_loginfo.dw.bus_type != 3 /*SAS*/) |
| 1088 | return; |
| 1089 | |
| 1090 | /* each nexus loss loginfo */ |
| 1091 | if (log_info == 0x31170000) |
| 1092 | return; |
| 1093 | |
| 1094 | /* eat the loginfos associated with task aborts */ |
| 1095 | if (ioc->ignore_loginfos && (log_info == 0x30050000 || log_info == |
| 1096 | 0x31140000 || log_info == 0x31130000)) |
| 1097 | return; |
| 1098 | |
| 1099 | switch (sas_loginfo.dw.originator) { |
| 1100 | case 0: |
| 1101 | originator_str = "IOP"; |
| 1102 | break; |
| 1103 | case 1: |
| 1104 | originator_str = "PL"; |
| 1105 | break; |
| 1106 | case 2: |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 1107 | if (!ioc->hide_ir_msg) |
| 1108 | originator_str = "IR"; |
| 1109 | else |
| 1110 | originator_str = "WarpDrive"; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1111 | break; |
| 1112 | } |
| 1113 | |
| 1114 | pr_warn(MPT3SAS_FMT |
| 1115 | "log_info(0x%08x): originator(%s), code(0x%02x), sub_code(0x%04x)\n", |
| 1116 | ioc->name, log_info, |
| 1117 | originator_str, sas_loginfo.dw.code, |
| 1118 | sas_loginfo.dw.subcode); |
| 1119 | } |
| 1120 | |
| 1121 | /** |
| 1122 | * _base_display_reply_info - |
| 1123 | * @ioc: per adapter object |
| 1124 | * @smid: system request message index |
| 1125 | * @msix_index: MSIX table index supplied by the OS |
| 1126 | * @reply: reply message frame(lower 32bit addr) |
| 1127 | * |
| 1128 | * Return nothing. |
| 1129 | */ |
| 1130 | static void |
| 1131 | _base_display_reply_info(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 1132 | u32 reply) |
| 1133 | { |
| 1134 | MPI2DefaultReply_t *mpi_reply; |
| 1135 | u16 ioc_status; |
| 1136 | u32 loginfo = 0; |
| 1137 | |
| 1138 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 1139 | if (unlikely(!mpi_reply)) { |
| 1140 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 1141 | ioc->name, __FILE__, __LINE__, __func__); |
| 1142 | return; |
| 1143 | } |
| 1144 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); |
Sreekanth Reddy | af00941 | 2015-11-11 17:30:23 +0530 | [diff] [blame] | 1145 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1146 | if ((ioc_status & MPI2_IOCSTATUS_MASK) && |
| 1147 | (ioc->logging_level & MPT_DEBUG_REPLY)) { |
| 1148 | _base_sas_ioc_info(ioc , mpi_reply, |
| 1149 | mpt3sas_base_get_msg_frame(ioc, smid)); |
| 1150 | } |
Sreekanth Reddy | af00941 | 2015-11-11 17:30:23 +0530 | [diff] [blame] | 1151 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1152 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) { |
| 1153 | loginfo = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 1154 | _base_sas_log_info(ioc, loginfo); |
| 1155 | } |
| 1156 | |
| 1157 | if (ioc_status || loginfo) { |
| 1158 | ioc_status &= MPI2_IOCSTATUS_MASK; |
| 1159 | mpt3sas_trigger_mpi(ioc, ioc_status, loginfo); |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | /** |
| 1164 | * mpt3sas_base_done - base internal command completion routine |
| 1165 | * @ioc: per adapter object |
| 1166 | * @smid: system request message index |
| 1167 | * @msix_index: MSIX table index supplied by the OS |
| 1168 | * @reply: reply message frame(lower 32bit addr) |
| 1169 | * |
| 1170 | * Return 1 meaning mf should be freed from _base_interrupt |
| 1171 | * 0 means the mf is freed from this function. |
| 1172 | */ |
| 1173 | u8 |
| 1174 | mpt3sas_base_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 1175 | u32 reply) |
| 1176 | { |
| 1177 | MPI2DefaultReply_t *mpi_reply; |
| 1178 | |
| 1179 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 1180 | if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK) |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 1181 | return mpt3sas_check_for_pending_internal_cmds(ioc, smid); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1182 | |
| 1183 | if (ioc->base_cmds.status == MPT3_CMD_NOT_USED) |
| 1184 | return 1; |
| 1185 | |
| 1186 | ioc->base_cmds.status |= MPT3_CMD_COMPLETE; |
| 1187 | if (mpi_reply) { |
| 1188 | ioc->base_cmds.status |= MPT3_CMD_REPLY_VALID; |
| 1189 | memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 1190 | } |
| 1191 | ioc->base_cmds.status &= ~MPT3_CMD_PENDING; |
| 1192 | |
| 1193 | complete(&ioc->base_cmds.done); |
| 1194 | return 1; |
| 1195 | } |
| 1196 | |
| 1197 | /** |
| 1198 | * _base_async_event - main callback handler for firmware asyn events |
| 1199 | * @ioc: per adapter object |
| 1200 | * @msix_index: MSIX table index supplied by the OS |
| 1201 | * @reply: reply message frame(lower 32bit addr) |
| 1202 | * |
| 1203 | * Return 1 meaning mf should be freed from _base_interrupt |
| 1204 | * 0 means the mf is freed from this function. |
| 1205 | */ |
| 1206 | static u8 |
| 1207 | _base_async_event(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, u32 reply) |
| 1208 | { |
| 1209 | Mpi2EventNotificationReply_t *mpi_reply; |
| 1210 | Mpi2EventAckRequest_t *ack_request; |
| 1211 | u16 smid; |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 1212 | struct _event_ack_list *delayed_event_ack; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1213 | |
| 1214 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 1215 | if (!mpi_reply) |
| 1216 | return 1; |
| 1217 | if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION) |
| 1218 | return 1; |
Sreekanth Reddy | af00941 | 2015-11-11 17:30:23 +0530 | [diff] [blame] | 1219 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1220 | _base_display_event_data(ioc, mpi_reply); |
Sreekanth Reddy | af00941 | 2015-11-11 17:30:23 +0530 | [diff] [blame] | 1221 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1222 | if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED)) |
| 1223 | goto out; |
| 1224 | smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); |
| 1225 | if (!smid) { |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 1226 | delayed_event_ack = kzalloc(sizeof(*delayed_event_ack), |
| 1227 | GFP_ATOMIC); |
| 1228 | if (!delayed_event_ack) |
| 1229 | goto out; |
| 1230 | INIT_LIST_HEAD(&delayed_event_ack->list); |
| 1231 | delayed_event_ack->Event = mpi_reply->Event; |
| 1232 | delayed_event_ack->EventContext = mpi_reply->EventContext; |
| 1233 | list_add_tail(&delayed_event_ack->list, |
| 1234 | &ioc->delayed_event_ack_list); |
| 1235 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 1236 | "DELAYED: EVENT ACK: event (0x%04x)\n", |
| 1237 | ioc->name, le16_to_cpu(mpi_reply->Event))); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1238 | goto out; |
| 1239 | } |
| 1240 | |
| 1241 | ack_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 1242 | memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t)); |
| 1243 | ack_request->Function = MPI2_FUNCTION_EVENT_ACK; |
| 1244 | ack_request->Event = mpi_reply->Event; |
| 1245 | ack_request->EventContext = mpi_reply->EventContext; |
| 1246 | ack_request->VF_ID = 0; /* TODO */ |
| 1247 | ack_request->VP_ID = 0; |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 1248 | mpt3sas_base_put_smid_default(ioc, smid); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1249 | |
| 1250 | out: |
| 1251 | |
| 1252 | /* scsih callback handler */ |
| 1253 | mpt3sas_scsih_event_callback(ioc, msix_index, reply); |
| 1254 | |
| 1255 | /* ctl callback handler */ |
| 1256 | mpt3sas_ctl_event_callback(ioc, msix_index, reply); |
| 1257 | |
| 1258 | return 1; |
| 1259 | } |
| 1260 | |
Colin Ian King | 61dfb8a | 2018-01-11 16:55:39 +0000 | [diff] [blame] | 1261 | static struct scsiio_tracker * |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 1262 | _get_st_from_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
Hannes Reinecke | 12e7c678 | 2018-01-04 04:57:05 -0800 | [diff] [blame] | 1263 | { |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 1264 | struct scsi_cmnd *cmd; |
| 1265 | |
Hannes Reinecke | 12e7c678 | 2018-01-04 04:57:05 -0800 | [diff] [blame] | 1266 | if (WARN_ON(!smid) || |
| 1267 | WARN_ON(smid >= ioc->hi_priority_smid)) |
| 1268 | return NULL; |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 1269 | |
| 1270 | cmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); |
| 1271 | if (cmd) |
| 1272 | return scsi_cmd_priv(cmd); |
| 1273 | |
| 1274 | return NULL; |
Hannes Reinecke | 12e7c678 | 2018-01-04 04:57:05 -0800 | [diff] [blame] | 1275 | } |
| 1276 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1277 | /** |
| 1278 | * _base_get_cb_idx - obtain the callback index |
| 1279 | * @ioc: per adapter object |
| 1280 | * @smid: system request message index |
| 1281 | * |
| 1282 | * Return callback index. |
| 1283 | */ |
| 1284 | static u8 |
| 1285 | _base_get_cb_idx(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 1286 | { |
| 1287 | int i; |
Hannes Reinecke | b0cd285e | 2018-01-04 04:57:07 -0800 | [diff] [blame] | 1288 | u16 ctl_smid = ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT + 1; |
Hannes Reinecke | ba4494d | 2018-01-04 04:57:01 -0800 | [diff] [blame] | 1289 | u8 cb_idx = 0xFF; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1290 | |
| 1291 | if (smid < ioc->hi_priority_smid) { |
Hannes Reinecke | 12e7c678 | 2018-01-04 04:57:05 -0800 | [diff] [blame] | 1292 | struct scsiio_tracker *st; |
| 1293 | |
Hannes Reinecke | b0cd285e | 2018-01-04 04:57:07 -0800 | [diff] [blame] | 1294 | if (smid < ctl_smid) { |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 1295 | st = _get_st_from_smid(ioc, smid); |
Hannes Reinecke | b0cd285e | 2018-01-04 04:57:07 -0800 | [diff] [blame] | 1296 | if (st) |
| 1297 | cb_idx = st->cb_idx; |
| 1298 | } else if (smid == ctl_smid) |
| 1299 | cb_idx = ioc->ctl_cb_idx; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1300 | } else if (smid < ioc->internal_smid) { |
| 1301 | i = smid - ioc->hi_priority_smid; |
| 1302 | cb_idx = ioc->hpr_lookup[i].cb_idx; |
| 1303 | } else if (smid <= ioc->hba_queue_depth) { |
| 1304 | i = smid - ioc->internal_smid; |
| 1305 | cb_idx = ioc->internal_lookup[i].cb_idx; |
Hannes Reinecke | ba4494d | 2018-01-04 04:57:01 -0800 | [diff] [blame] | 1306 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1307 | return cb_idx; |
| 1308 | } |
| 1309 | |
| 1310 | /** |
| 1311 | * _base_mask_interrupts - disable interrupts |
| 1312 | * @ioc: per adapter object |
| 1313 | * |
| 1314 | * Disabling ResetIRQ, Reply and Doorbell Interrupts |
| 1315 | * |
| 1316 | * Return nothing. |
| 1317 | */ |
| 1318 | static void |
| 1319 | _base_mask_interrupts(struct MPT3SAS_ADAPTER *ioc) |
| 1320 | { |
| 1321 | u32 him_register; |
| 1322 | |
| 1323 | ioc->mask_interrupts = 1; |
| 1324 | him_register = readl(&ioc->chip->HostInterruptMask); |
| 1325 | him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK; |
| 1326 | writel(him_register, &ioc->chip->HostInterruptMask); |
| 1327 | readl(&ioc->chip->HostInterruptMask); |
| 1328 | } |
| 1329 | |
| 1330 | /** |
| 1331 | * _base_unmask_interrupts - enable interrupts |
| 1332 | * @ioc: per adapter object |
| 1333 | * |
| 1334 | * Enabling only Reply Interrupts |
| 1335 | * |
| 1336 | * Return nothing. |
| 1337 | */ |
| 1338 | static void |
| 1339 | _base_unmask_interrupts(struct MPT3SAS_ADAPTER *ioc) |
| 1340 | { |
| 1341 | u32 him_register; |
| 1342 | |
| 1343 | him_register = readl(&ioc->chip->HostInterruptMask); |
| 1344 | him_register &= ~MPI2_HIM_RIM; |
| 1345 | writel(him_register, &ioc->chip->HostInterruptMask); |
| 1346 | ioc->mask_interrupts = 0; |
| 1347 | } |
| 1348 | |
| 1349 | union reply_descriptor { |
| 1350 | u64 word; |
| 1351 | struct { |
| 1352 | u32 low; |
| 1353 | u32 high; |
| 1354 | } u; |
| 1355 | }; |
| 1356 | |
| 1357 | /** |
| 1358 | * _base_interrupt - MPT adapter (IOC) specific interrupt handler. |
| 1359 | * @irq: irq number (not used) |
| 1360 | * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure |
| 1361 | * @r: pt_regs pointer (not used) |
| 1362 | * |
| 1363 | * Return IRQ_HANDLE if processed, else IRQ_NONE. |
| 1364 | */ |
| 1365 | static irqreturn_t |
| 1366 | _base_interrupt(int irq, void *bus_id) |
| 1367 | { |
| 1368 | struct adapter_reply_queue *reply_q = bus_id; |
| 1369 | union reply_descriptor rd; |
| 1370 | u32 completed_cmds; |
| 1371 | u8 request_desript_type; |
| 1372 | u16 smid; |
| 1373 | u8 cb_idx; |
| 1374 | u32 reply; |
| 1375 | u8 msix_index = reply_q->msix_index; |
| 1376 | struct MPT3SAS_ADAPTER *ioc = reply_q->ioc; |
| 1377 | Mpi2ReplyDescriptorsUnion_t *rpf; |
| 1378 | u8 rc; |
| 1379 | |
| 1380 | if (ioc->mask_interrupts) |
| 1381 | return IRQ_NONE; |
| 1382 | |
| 1383 | if (!atomic_add_unless(&reply_q->busy, 1, 1)) |
| 1384 | return IRQ_NONE; |
| 1385 | |
| 1386 | rpf = &reply_q->reply_post_free[reply_q->reply_post_host_index]; |
| 1387 | request_desript_type = rpf->Default.ReplyFlags |
| 1388 | & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; |
| 1389 | if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) { |
| 1390 | atomic_dec(&reply_q->busy); |
| 1391 | return IRQ_NONE; |
| 1392 | } |
| 1393 | |
| 1394 | completed_cmds = 0; |
| 1395 | cb_idx = 0xFF; |
| 1396 | do { |
| 1397 | rd.word = le64_to_cpu(rpf->Words); |
| 1398 | if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX) |
| 1399 | goto out; |
| 1400 | reply = 0; |
| 1401 | smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1); |
| 1402 | if (request_desript_type == |
| 1403 | MPI25_RPY_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO_SUCCESS || |
| 1404 | request_desript_type == |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1405 | MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS || |
| 1406 | request_desript_type == |
| 1407 | MPI26_RPY_DESCRIPT_FLAGS_PCIE_ENCAPSULATED_SUCCESS) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1408 | cb_idx = _base_get_cb_idx(ioc, smid); |
| 1409 | if ((likely(cb_idx < MPT_MAX_CALLBACKS)) && |
| 1410 | (likely(mpt_callbacks[cb_idx] != NULL))) { |
| 1411 | rc = mpt_callbacks[cb_idx](ioc, smid, |
| 1412 | msix_index, 0); |
| 1413 | if (rc) |
| 1414 | mpt3sas_base_free_smid(ioc, smid); |
| 1415 | } |
| 1416 | } else if (request_desript_type == |
| 1417 | MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) { |
| 1418 | reply = le32_to_cpu( |
| 1419 | rpf->AddressReply.ReplyFrameAddress); |
| 1420 | if (reply > ioc->reply_dma_max_address || |
| 1421 | reply < ioc->reply_dma_min_address) |
| 1422 | reply = 0; |
| 1423 | if (smid) { |
| 1424 | cb_idx = _base_get_cb_idx(ioc, smid); |
| 1425 | if ((likely(cb_idx < MPT_MAX_CALLBACKS)) && |
| 1426 | (likely(mpt_callbacks[cb_idx] != NULL))) { |
| 1427 | rc = mpt_callbacks[cb_idx](ioc, smid, |
| 1428 | msix_index, reply); |
| 1429 | if (reply) |
| 1430 | _base_display_reply_info(ioc, |
| 1431 | smid, msix_index, reply); |
| 1432 | if (rc) |
| 1433 | mpt3sas_base_free_smid(ioc, |
| 1434 | smid); |
| 1435 | } |
| 1436 | } else { |
| 1437 | _base_async_event(ioc, msix_index, reply); |
| 1438 | } |
| 1439 | |
| 1440 | /* reply free queue handling */ |
| 1441 | if (reply) { |
| 1442 | ioc->reply_free_host_index = |
| 1443 | (ioc->reply_free_host_index == |
| 1444 | (ioc->reply_free_queue_depth - 1)) ? |
| 1445 | 0 : ioc->reply_free_host_index + 1; |
| 1446 | ioc->reply_free[ioc->reply_free_host_index] = |
| 1447 | cpu_to_le32(reply); |
Suganath Prabu Subramani | b4472d7 | 2018-02-07 02:51:50 -0800 | [diff] [blame] | 1448 | if (ioc->is_mcpu_endpoint) |
| 1449 | _base_clone_reply_to_sys_mem(ioc, |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 1450 | reply, |
Suganath Prabu Subramani | b4472d7 | 2018-02-07 02:51:50 -0800 | [diff] [blame] | 1451 | ioc->reply_free_host_index); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1452 | writel(ioc->reply_free_host_index, |
| 1453 | &ioc->chip->ReplyFreeHostIndex); |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | rpf->Words = cpu_to_le64(ULLONG_MAX); |
| 1458 | reply_q->reply_post_host_index = |
| 1459 | (reply_q->reply_post_host_index == |
| 1460 | (ioc->reply_post_queue_depth - 1)) ? 0 : |
| 1461 | reply_q->reply_post_host_index + 1; |
| 1462 | request_desript_type = |
| 1463 | reply_q->reply_post_free[reply_q->reply_post_host_index]. |
| 1464 | Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; |
| 1465 | completed_cmds++; |
Chaitra P B | 6b4c335 | 2017-01-23 15:26:09 +0530 | [diff] [blame] | 1466 | /* Update the reply post host index after continuously |
| 1467 | * processing the threshold number of Reply Descriptors. |
| 1468 | * So that FW can find enough entries to post the Reply |
| 1469 | * Descriptors in the reply descriptor post queue. |
| 1470 | */ |
| 1471 | if (completed_cmds > ioc->hba_queue_depth/3) { |
| 1472 | if (ioc->combined_reply_queue) { |
| 1473 | writel(reply_q->reply_post_host_index | |
| 1474 | ((msix_index & 7) << |
| 1475 | MPI2_RPHI_MSIX_INDEX_SHIFT), |
| 1476 | ioc->replyPostRegisterIndex[msix_index/8]); |
| 1477 | } else { |
| 1478 | writel(reply_q->reply_post_host_index | |
| 1479 | (msix_index << |
| 1480 | MPI2_RPHI_MSIX_INDEX_SHIFT), |
| 1481 | &ioc->chip->ReplyPostHostIndex); |
| 1482 | } |
| 1483 | completed_cmds = 1; |
| 1484 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1485 | if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) |
| 1486 | goto out; |
| 1487 | if (!reply_q->reply_post_host_index) |
| 1488 | rpf = reply_q->reply_post_free; |
| 1489 | else |
| 1490 | rpf++; |
| 1491 | } while (1); |
| 1492 | |
| 1493 | out: |
| 1494 | |
| 1495 | if (!completed_cmds) { |
| 1496 | atomic_dec(&reply_q->busy); |
| 1497 | return IRQ_NONE; |
| 1498 | } |
| 1499 | |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 1500 | if (ioc->is_warpdrive) { |
| 1501 | writel(reply_q->reply_post_host_index, |
| 1502 | ioc->reply_post_host_index[msix_index]); |
| 1503 | atomic_dec(&reply_q->busy); |
| 1504 | return IRQ_HANDLED; |
| 1505 | } |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 1506 | |
| 1507 | /* Update Reply Post Host Index. |
| 1508 | * For those HBA's which support combined reply queue feature |
| 1509 | * 1. Get the correct Supplemental Reply Post Host Index Register. |
| 1510 | * i.e. (msix_index / 8)th entry from Supplemental Reply Post Host |
| 1511 | * Index Register address bank i.e replyPostRegisterIndex[], |
| 1512 | * 2. Then update this register with new reply host index value |
| 1513 | * in ReplyPostIndex field and the MSIxIndex field with |
| 1514 | * msix_index value reduced to a value between 0 and 7, |
| 1515 | * using a modulo 8 operation. Since each Supplemental Reply Post |
| 1516 | * Host Index Register supports 8 MSI-X vectors. |
| 1517 | * |
| 1518 | * For other HBA's just update the Reply Post Host Index register with |
| 1519 | * new reply host index value in ReplyPostIndex Field and msix_index |
| 1520 | * value in MSIxIndex field. |
| 1521 | */ |
Suganath Prabu Subramani | 0bb337c | 2016-10-26 13:34:38 +0530 | [diff] [blame] | 1522 | if (ioc->combined_reply_queue) |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 1523 | writel(reply_q->reply_post_host_index | ((msix_index & 7) << |
| 1524 | MPI2_RPHI_MSIX_INDEX_SHIFT), |
| 1525 | ioc->replyPostRegisterIndex[msix_index/8]); |
| 1526 | else |
| 1527 | writel(reply_q->reply_post_host_index | (msix_index << |
| 1528 | MPI2_RPHI_MSIX_INDEX_SHIFT), |
| 1529 | &ioc->chip->ReplyPostHostIndex); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1530 | atomic_dec(&reply_q->busy); |
| 1531 | return IRQ_HANDLED; |
| 1532 | } |
| 1533 | |
| 1534 | /** |
| 1535 | * _base_is_controller_msix_enabled - is controller support muli-reply queues |
| 1536 | * @ioc: per adapter object |
| 1537 | * |
| 1538 | */ |
| 1539 | static inline int |
| 1540 | _base_is_controller_msix_enabled(struct MPT3SAS_ADAPTER *ioc) |
| 1541 | { |
| 1542 | return (ioc->facts.IOCCapabilities & |
| 1543 | MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable; |
| 1544 | } |
| 1545 | |
| 1546 | /** |
Chaitra P B | 5f0dfb7 | 2016-05-06 14:29:31 +0530 | [diff] [blame] | 1547 | * mpt3sas_base_sync_reply_irqs - flush pending MSIX interrupts |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1548 | * @ioc: per adapter object |
Chaitra P B | 5f0dfb7 | 2016-05-06 14:29:31 +0530 | [diff] [blame] | 1549 | * Context: non ISR conext |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1550 | * |
Chaitra P B | 5f0dfb7 | 2016-05-06 14:29:31 +0530 | [diff] [blame] | 1551 | * Called when a Task Management request has completed. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1552 | * |
| 1553 | * Return nothing. |
| 1554 | */ |
| 1555 | void |
Chaitra P B | 5f0dfb7 | 2016-05-06 14:29:31 +0530 | [diff] [blame] | 1556 | mpt3sas_base_sync_reply_irqs(struct MPT3SAS_ADAPTER *ioc) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1557 | { |
| 1558 | struct adapter_reply_queue *reply_q; |
| 1559 | |
| 1560 | /* If MSIX capability is turned off |
| 1561 | * then multi-queues are not enabled |
| 1562 | */ |
| 1563 | if (!_base_is_controller_msix_enabled(ioc)) |
| 1564 | return; |
| 1565 | |
| 1566 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { |
Chaitra P B | 5f0dfb7 | 2016-05-06 14:29:31 +0530 | [diff] [blame] | 1567 | if (ioc->shost_recovery || ioc->remove_host || |
| 1568 | ioc->pci_error_recovery) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1569 | return; |
| 1570 | /* TMs are on msix_index == 0 */ |
| 1571 | if (reply_q->msix_index == 0) |
| 1572 | continue; |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 1573 | synchronize_irq(pci_irq_vector(ioc->pdev, reply_q->msix_index)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | /** |
| 1578 | * mpt3sas_base_release_callback_handler - clear interrupt callback handler |
| 1579 | * @cb_idx: callback index |
| 1580 | * |
| 1581 | * Return nothing. |
| 1582 | */ |
| 1583 | void |
| 1584 | mpt3sas_base_release_callback_handler(u8 cb_idx) |
| 1585 | { |
| 1586 | mpt_callbacks[cb_idx] = NULL; |
| 1587 | } |
| 1588 | |
| 1589 | /** |
| 1590 | * mpt3sas_base_register_callback_handler - obtain index for the interrupt callback handler |
| 1591 | * @cb_func: callback function |
| 1592 | * |
| 1593 | * Returns cb_func. |
| 1594 | */ |
| 1595 | u8 |
| 1596 | mpt3sas_base_register_callback_handler(MPT_CALLBACK cb_func) |
| 1597 | { |
| 1598 | u8 cb_idx; |
| 1599 | |
| 1600 | for (cb_idx = MPT_MAX_CALLBACKS-1; cb_idx; cb_idx--) |
| 1601 | if (mpt_callbacks[cb_idx] == NULL) |
| 1602 | break; |
| 1603 | |
| 1604 | mpt_callbacks[cb_idx] = cb_func; |
| 1605 | return cb_idx; |
| 1606 | } |
| 1607 | |
| 1608 | /** |
| 1609 | * mpt3sas_base_initialize_callback_handler - initialize the interrupt callback handler |
| 1610 | * |
| 1611 | * Return nothing. |
| 1612 | */ |
| 1613 | void |
| 1614 | mpt3sas_base_initialize_callback_handler(void) |
| 1615 | { |
| 1616 | u8 cb_idx; |
| 1617 | |
| 1618 | for (cb_idx = 0; cb_idx < MPT_MAX_CALLBACKS; cb_idx++) |
| 1619 | mpt3sas_base_release_callback_handler(cb_idx); |
| 1620 | } |
| 1621 | |
| 1622 | |
| 1623 | /** |
| 1624 | * _base_build_zero_len_sge - build zero length sg entry |
| 1625 | * @ioc: per adapter object |
| 1626 | * @paddr: virtual address for SGE |
| 1627 | * |
| 1628 | * Create a zero length scatter gather entry to insure the IOCs hardware has |
| 1629 | * something to use if the target device goes brain dead and tries |
| 1630 | * to send data even when none is asked for. |
| 1631 | * |
| 1632 | * Return nothing. |
| 1633 | */ |
| 1634 | static void |
| 1635 | _base_build_zero_len_sge(struct MPT3SAS_ADAPTER *ioc, void *paddr) |
| 1636 | { |
| 1637 | u32 flags_length = (u32)((MPI2_SGE_FLAGS_LAST_ELEMENT | |
| 1638 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST | |
| 1639 | MPI2_SGE_FLAGS_SIMPLE_ELEMENT) << |
| 1640 | MPI2_SGE_FLAGS_SHIFT); |
| 1641 | ioc->base_add_sg_single(paddr, flags_length, -1); |
| 1642 | } |
| 1643 | |
| 1644 | /** |
| 1645 | * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr. |
| 1646 | * @paddr: virtual address for SGE |
| 1647 | * @flags_length: SGE flags and data transfer length |
| 1648 | * @dma_addr: Physical address |
| 1649 | * |
| 1650 | * Return nothing. |
| 1651 | */ |
| 1652 | static void |
| 1653 | _base_add_sg_single_32(void *paddr, u32 flags_length, dma_addr_t dma_addr) |
| 1654 | { |
| 1655 | Mpi2SGESimple32_t *sgel = paddr; |
| 1656 | |
| 1657 | flags_length |= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING | |
| 1658 | MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT; |
| 1659 | sgel->FlagsLength = cpu_to_le32(flags_length); |
| 1660 | sgel->Address = cpu_to_le32(dma_addr); |
| 1661 | } |
| 1662 | |
| 1663 | |
| 1664 | /** |
| 1665 | * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr. |
| 1666 | * @paddr: virtual address for SGE |
| 1667 | * @flags_length: SGE flags and data transfer length |
| 1668 | * @dma_addr: Physical address |
| 1669 | * |
| 1670 | * Return nothing. |
| 1671 | */ |
| 1672 | static void |
| 1673 | _base_add_sg_single_64(void *paddr, u32 flags_length, dma_addr_t dma_addr) |
| 1674 | { |
| 1675 | Mpi2SGESimple64_t *sgel = paddr; |
| 1676 | |
| 1677 | flags_length |= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING | |
| 1678 | MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT; |
| 1679 | sgel->FlagsLength = cpu_to_le32(flags_length); |
| 1680 | sgel->Address = cpu_to_le64(dma_addr); |
| 1681 | } |
| 1682 | |
| 1683 | /** |
| 1684 | * _base_get_chain_buffer_tracker - obtain chain tracker |
| 1685 | * @ioc: per adapter object |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 1686 | * @scmd: SCSI commands of the IO request |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1687 | * |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 1688 | * Returns chain tracker from chain_lookup table using key as |
| 1689 | * smid and smid's chain_offset. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1690 | */ |
| 1691 | static struct chain_tracker * |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 1692 | _base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER *ioc, |
| 1693 | struct scsi_cmnd *scmd) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1694 | { |
| 1695 | struct chain_tracker *chain_req; |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 1696 | struct scsiio_tracker *st = scsi_cmd_priv(scmd); |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 1697 | u16 smid = st->smid; |
| 1698 | u8 chain_offset = |
| 1699 | atomic_read(&ioc->chain_lookup[smid - 1].chain_offset); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1700 | |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 1701 | if (chain_offset == ioc->chains_needed_per_io) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1702 | return NULL; |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 1703 | |
| 1704 | chain_req = &ioc->chain_lookup[smid - 1].chains_per_smid[chain_offset]; |
| 1705 | atomic_inc(&ioc->chain_lookup[smid - 1].chain_offset); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1706 | return chain_req; |
| 1707 | } |
| 1708 | |
| 1709 | |
| 1710 | /** |
| 1711 | * _base_build_sg - build generic sg |
| 1712 | * @ioc: per adapter object |
| 1713 | * @psge: virtual address for SGE |
| 1714 | * @data_out_dma: physical address for WRITES |
| 1715 | * @data_out_sz: data xfer size for WRITES |
| 1716 | * @data_in_dma: physical address for READS |
| 1717 | * @data_in_sz: data xfer size for READS |
| 1718 | * |
| 1719 | * Return nothing. |
| 1720 | */ |
| 1721 | static void |
| 1722 | _base_build_sg(struct MPT3SAS_ADAPTER *ioc, void *psge, |
| 1723 | dma_addr_t data_out_dma, size_t data_out_sz, dma_addr_t data_in_dma, |
| 1724 | size_t data_in_sz) |
| 1725 | { |
| 1726 | u32 sgl_flags; |
| 1727 | |
| 1728 | if (!data_out_sz && !data_in_sz) { |
| 1729 | _base_build_zero_len_sge(ioc, psge); |
| 1730 | return; |
| 1731 | } |
| 1732 | |
| 1733 | if (data_out_sz && data_in_sz) { |
| 1734 | /* WRITE sgel first */ |
| 1735 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1736 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); |
| 1737 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1738 | ioc->base_add_sg_single(psge, sgl_flags | |
| 1739 | data_out_sz, data_out_dma); |
| 1740 | |
| 1741 | /* incr sgel */ |
| 1742 | psge += ioc->sge_size; |
| 1743 | |
| 1744 | /* READ sgel last */ |
| 1745 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1746 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 1747 | MPI2_SGE_FLAGS_END_OF_LIST); |
| 1748 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1749 | ioc->base_add_sg_single(psge, sgl_flags | |
| 1750 | data_in_sz, data_in_dma); |
| 1751 | } else if (data_out_sz) /* WRITE */ { |
| 1752 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1753 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 1754 | MPI2_SGE_FLAGS_END_OF_LIST | MPI2_SGE_FLAGS_HOST_TO_IOC); |
| 1755 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1756 | ioc->base_add_sg_single(psge, sgl_flags | |
| 1757 | data_out_sz, data_out_dma); |
| 1758 | } else if (data_in_sz) /* READ */ { |
| 1759 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1760 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 1761 | MPI2_SGE_FLAGS_END_OF_LIST); |
| 1762 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1763 | ioc->base_add_sg_single(psge, sgl_flags | |
| 1764 | data_in_sz, data_in_dma); |
| 1765 | } |
| 1766 | } |
| 1767 | |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1768 | /* IEEE format sgls */ |
| 1769 | |
| 1770 | /** |
| 1771 | * _base_build_nvme_prp - This function is called for NVMe end devices to build |
| 1772 | * a native SGL (NVMe PRP). The native SGL is built starting in the first PRP |
| 1773 | * entry of the NVMe message (PRP1). If the data buffer is small enough to be |
| 1774 | * described entirely using PRP1, then PRP2 is not used. If needed, PRP2 is |
| 1775 | * used to describe a larger data buffer. If the data buffer is too large to |
| 1776 | * describe using the two PRP entriess inside the NVMe message, then PRP1 |
| 1777 | * describes the first data memory segment, and PRP2 contains a pointer to a PRP |
| 1778 | * list located elsewhere in memory to describe the remaining data memory |
| 1779 | * segments. The PRP list will be contiguous. |
| 1780 | |
| 1781 | * The native SGL for NVMe devices is a Physical Region Page (PRP). A PRP |
| 1782 | * consists of a list of PRP entries to describe a number of noncontigous |
| 1783 | * physical memory segments as a single memory buffer, just as a SGL does. Note |
| 1784 | * however, that this function is only used by the IOCTL call, so the memory |
| 1785 | * given will be guaranteed to be contiguous. There is no need to translate |
| 1786 | * non-contiguous SGL into a PRP in this case. All PRPs will describe |
| 1787 | * contiguous space that is one page size each. |
| 1788 | * |
| 1789 | * Each NVMe message contains two PRP entries. The first (PRP1) either contains |
| 1790 | * a PRP list pointer or a PRP element, depending upon the command. PRP2 |
| 1791 | * contains the second PRP element if the memory being described fits within 2 |
| 1792 | * PRP entries, or a PRP list pointer if the PRP spans more than two entries. |
| 1793 | * |
| 1794 | * A PRP list pointer contains the address of a PRP list, structured as a linear |
| 1795 | * array of PRP entries. Each PRP entry in this list describes a segment of |
| 1796 | * physical memory. |
| 1797 | * |
| 1798 | * Each 64-bit PRP entry comprises an address and an offset field. The address |
| 1799 | * always points at the beginning of a 4KB physical memory page, and the offset |
| 1800 | * describes where within that 4KB page the memory segment begins. Only the |
| 1801 | * first element in a PRP list may contain a non-zero offest, implying that all |
| 1802 | * memory segments following the first begin at the start of a 4KB page. |
| 1803 | * |
| 1804 | * Each PRP element normally describes 4KB of physical memory, with exceptions |
| 1805 | * for the first and last elements in the list. If the memory being described |
| 1806 | * by the list begins at a non-zero offset within the first 4KB page, then the |
| 1807 | * first PRP element will contain a non-zero offset indicating where the region |
| 1808 | * begins within the 4KB page. The last memory segment may end before the end |
| 1809 | * of the 4KB segment, depending upon the overall size of the memory being |
| 1810 | * described by the PRP list. |
| 1811 | * |
| 1812 | * Since PRP entries lack any indication of size, the overall data buffer length |
| 1813 | * is used to determine where the end of the data memory buffer is located, and |
| 1814 | * how many PRP entries are required to describe it. |
| 1815 | * |
| 1816 | * @ioc: per adapter object |
| 1817 | * @smid: system request message index for getting asscociated SGL |
| 1818 | * @nvme_encap_request: the NVMe request msg frame pointer |
| 1819 | * @data_out_dma: physical address for WRITES |
| 1820 | * @data_out_sz: data xfer size for WRITES |
| 1821 | * @data_in_dma: physical address for READS |
| 1822 | * @data_in_sz: data xfer size for READS |
| 1823 | * |
| 1824 | * Returns nothing. |
| 1825 | */ |
| 1826 | static void |
| 1827 | _base_build_nvme_prp(struct MPT3SAS_ADAPTER *ioc, u16 smid, |
| 1828 | Mpi26NVMeEncapsulatedRequest_t *nvme_encap_request, |
| 1829 | dma_addr_t data_out_dma, size_t data_out_sz, dma_addr_t data_in_dma, |
| 1830 | size_t data_in_sz) |
| 1831 | { |
| 1832 | int prp_size = NVME_PRP_SIZE; |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1833 | __le64 *prp_entry, *prp1_entry, *prp2_entry; |
| 1834 | __le64 *prp_page; |
| 1835 | dma_addr_t prp_entry_dma, prp_page_dma, dma_addr; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1836 | u32 offset, entry_len; |
| 1837 | u32 page_mask_result, page_mask; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1838 | size_t length; |
| 1839 | |
| 1840 | /* |
| 1841 | * Not all commands require a data transfer. If no data, just return |
| 1842 | * without constructing any PRP. |
| 1843 | */ |
| 1844 | if (!data_in_sz && !data_out_sz) |
| 1845 | return; |
| 1846 | /* |
| 1847 | * Set pointers to PRP1 and PRP2, which are in the NVMe command. |
| 1848 | * PRP1 is located at a 24 byte offset from the start of the NVMe |
| 1849 | * command. Then set the current PRP entry pointer to PRP1. |
| 1850 | */ |
Suganath Prabu Subramani | 494f401 | 2017-10-31 18:02:38 +0530 | [diff] [blame] | 1851 | prp1_entry = (__le64 *)(nvme_encap_request->NVMe_Command + |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1852 | NVME_CMD_PRP1_OFFSET); |
Suganath Prabu Subramani | 494f401 | 2017-10-31 18:02:38 +0530 | [diff] [blame] | 1853 | prp2_entry = (__le64 *)(nvme_encap_request->NVMe_Command + |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1854 | NVME_CMD_PRP2_OFFSET); |
| 1855 | prp_entry = prp1_entry; |
| 1856 | /* |
| 1857 | * For the PRP entries, use the specially allocated buffer of |
| 1858 | * contiguous memory. |
| 1859 | */ |
Suganath Prabu Subramani | 494f401 | 2017-10-31 18:02:38 +0530 | [diff] [blame] | 1860 | prp_page = (__le64 *)mpt3sas_base_get_pcie_sgl(ioc, smid); |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1861 | prp_page_dma = mpt3sas_base_get_pcie_sgl_dma(ioc, smid); |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1862 | |
| 1863 | /* |
| 1864 | * Check if we are within 1 entry of a page boundary we don't |
| 1865 | * want our first entry to be a PRP List entry. |
| 1866 | */ |
| 1867 | page_mask = ioc->page_size - 1; |
| 1868 | page_mask_result = (uintptr_t)((u8 *)prp_page + prp_size) & page_mask; |
| 1869 | if (!page_mask_result) { |
| 1870 | /* Bump up to next page boundary. */ |
Suganath Prabu Subramani | 494f401 | 2017-10-31 18:02:38 +0530 | [diff] [blame] | 1871 | prp_page = (__le64 *)((u8 *)prp_page + prp_size); |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1872 | prp_page_dma = prp_page_dma + prp_size; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | /* |
| 1876 | * Set PRP physical pointer, which initially points to the current PRP |
| 1877 | * DMA memory page. |
| 1878 | */ |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1879 | prp_entry_dma = prp_page_dma; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1880 | |
| 1881 | /* Get physical address and length of the data buffer. */ |
| 1882 | if (data_in_sz) { |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1883 | dma_addr = data_in_dma; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1884 | length = data_in_sz; |
| 1885 | } else { |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1886 | dma_addr = data_out_dma; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1887 | length = data_out_sz; |
| 1888 | } |
| 1889 | |
| 1890 | /* Loop while the length is not zero. */ |
| 1891 | while (length) { |
| 1892 | /* |
| 1893 | * Check if we need to put a list pointer here if we are at |
| 1894 | * page boundary - prp_size (8 bytes). |
| 1895 | */ |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1896 | page_mask_result = (prp_entry_dma + prp_size) & page_mask; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1897 | if (!page_mask_result) { |
| 1898 | /* |
| 1899 | * This is the last entry in a PRP List, so we need to |
| 1900 | * put a PRP list pointer here. What this does is: |
| 1901 | * - bump the current memory pointer to the next |
| 1902 | * address, which will be the next full page. |
| 1903 | * - set the PRP Entry to point to that page. This |
| 1904 | * is now the PRP List pointer. |
| 1905 | * - bump the PRP Entry pointer the start of the |
| 1906 | * next page. Since all of this PRP memory is |
| 1907 | * contiguous, no need to get a new page - it's |
| 1908 | * just the next address. |
| 1909 | */ |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1910 | prp_entry_dma++; |
| 1911 | *prp_entry = cpu_to_le64(prp_entry_dma); |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1912 | prp_entry++; |
| 1913 | } |
| 1914 | |
| 1915 | /* Need to handle if entry will be part of a page. */ |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1916 | offset = dma_addr & page_mask; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1917 | entry_len = ioc->page_size - offset; |
| 1918 | |
| 1919 | if (prp_entry == prp1_entry) { |
| 1920 | /* |
| 1921 | * Must fill in the first PRP pointer (PRP1) before |
| 1922 | * moving on. |
| 1923 | */ |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1924 | *prp1_entry = cpu_to_le64(dma_addr); |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1925 | |
| 1926 | /* |
| 1927 | * Now point to the second PRP entry within the |
| 1928 | * command (PRP2). |
| 1929 | */ |
| 1930 | prp_entry = prp2_entry; |
| 1931 | } else if (prp_entry == prp2_entry) { |
| 1932 | /* |
| 1933 | * Should the PRP2 entry be a PRP List pointer or just |
| 1934 | * a regular PRP pointer? If there is more than one |
| 1935 | * more page of data, must use a PRP List pointer. |
| 1936 | */ |
| 1937 | if (length > ioc->page_size) { |
| 1938 | /* |
| 1939 | * PRP2 will contain a PRP List pointer because |
| 1940 | * more PRP's are needed with this command. The |
| 1941 | * list will start at the beginning of the |
| 1942 | * contiguous buffer. |
| 1943 | */ |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1944 | *prp2_entry = cpu_to_le64(prp_entry_dma); |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1945 | |
| 1946 | /* |
| 1947 | * The next PRP Entry will be the start of the |
| 1948 | * first PRP List. |
| 1949 | */ |
| 1950 | prp_entry = prp_page; |
| 1951 | } else { |
| 1952 | /* |
| 1953 | * After this, the PRP Entries are complete. |
| 1954 | * This command uses 2 PRP's and no PRP list. |
| 1955 | */ |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1956 | *prp2_entry = cpu_to_le64(dma_addr); |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1957 | } |
| 1958 | } else { |
| 1959 | /* |
| 1960 | * Put entry in list and bump the addresses. |
| 1961 | * |
| 1962 | * After PRP1 and PRP2 are filled in, this will fill in |
| 1963 | * all remaining PRP entries in a PRP List, one per |
| 1964 | * each time through the loop. |
| 1965 | */ |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1966 | *prp_entry = cpu_to_le64(dma_addr); |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1967 | prp_entry++; |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1968 | prp_entry_dma++; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | /* |
| 1972 | * Bump the phys address of the command's data buffer by the |
| 1973 | * entry_len. |
| 1974 | */ |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 1975 | dma_addr += entry_len; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1976 | |
| 1977 | /* Decrement length accounting for last partial page. */ |
| 1978 | if (entry_len > length) |
| 1979 | length = 0; |
| 1980 | else |
| 1981 | length -= entry_len; |
| 1982 | } |
| 1983 | } |
| 1984 | |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 1985 | /** |
| 1986 | * base_make_prp_nvme - |
| 1987 | * Prepare PRPs(Physical Region Page)- SGLs specific to NVMe drives only |
| 1988 | * |
| 1989 | * @ioc: per adapter object |
| 1990 | * @scmd: SCSI command from the mid-layer |
| 1991 | * @mpi_request: mpi request |
| 1992 | * @smid: msg Index |
| 1993 | * @sge_count: scatter gather element count. |
| 1994 | * |
| 1995 | * Returns: true: PRPs are built |
| 1996 | * false: IEEE SGLs needs to be built |
| 1997 | */ |
Suganath Prabu Subramani | 494f401 | 2017-10-31 18:02:38 +0530 | [diff] [blame] | 1998 | static void |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 1999 | base_make_prp_nvme(struct MPT3SAS_ADAPTER *ioc, |
| 2000 | struct scsi_cmnd *scmd, |
| 2001 | Mpi25SCSIIORequest_t *mpi_request, |
| 2002 | u16 smid, int sge_count) |
| 2003 | { |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 2004 | int sge_len, num_prp_in_chain = 0; |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2005 | Mpi25IeeeSgeChain64_t *main_chain_element, *ptr_first_sgl; |
Suganath Prabu Subramani | 494f401 | 2017-10-31 18:02:38 +0530 | [diff] [blame] | 2006 | __le64 *curr_buff; |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 2007 | dma_addr_t msg_dma, sge_addr, offset; |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2008 | u32 page_mask, page_mask_result; |
| 2009 | struct scatterlist *sg_scmd; |
| 2010 | u32 first_prp_len; |
| 2011 | int data_len = scsi_bufflen(scmd); |
| 2012 | u32 nvme_pg_size; |
| 2013 | |
| 2014 | nvme_pg_size = max_t(u32, ioc->page_size, NVME_PRP_PAGE_SIZE); |
| 2015 | /* |
| 2016 | * Nvme has a very convoluted prp format. One prp is required |
| 2017 | * for each page or partial page. Driver need to split up OS sg_list |
| 2018 | * entries if it is longer than one page or cross a page |
| 2019 | * boundary. Driver also have to insert a PRP list pointer entry as |
| 2020 | * the last entry in each physical page of the PRP list. |
| 2021 | * |
| 2022 | * NOTE: The first PRP "entry" is actually placed in the first |
| 2023 | * SGL entry in the main message as IEEE 64 format. The 2nd |
| 2024 | * entry in the main message is the chain element, and the rest |
| 2025 | * of the PRP entries are built in the contiguous pcie buffer. |
| 2026 | */ |
| 2027 | page_mask = nvme_pg_size - 1; |
| 2028 | |
| 2029 | /* |
| 2030 | * Native SGL is needed. |
| 2031 | * Put a chain element in main message frame that points to the first |
| 2032 | * chain buffer. |
| 2033 | * |
| 2034 | * NOTE: The ChainOffset field must be 0 when using a chain pointer to |
| 2035 | * a native SGL. |
| 2036 | */ |
| 2037 | |
| 2038 | /* Set main message chain element pointer */ |
| 2039 | main_chain_element = (pMpi25IeeeSgeChain64_t)&mpi_request->SGL; |
| 2040 | /* |
| 2041 | * For NVMe the chain element needs to be the 2nd SG entry in the main |
| 2042 | * message. |
| 2043 | */ |
| 2044 | main_chain_element = (Mpi25IeeeSgeChain64_t *) |
| 2045 | ((u8 *)main_chain_element + sizeof(MPI25_IEEE_SGE_CHAIN64)); |
| 2046 | |
| 2047 | /* |
| 2048 | * For the PRP entries, use the specially allocated buffer of |
| 2049 | * contiguous memory. Normal chain buffers can't be used |
| 2050 | * because each chain buffer would need to be the size of an OS |
| 2051 | * page (4k). |
| 2052 | */ |
| 2053 | curr_buff = mpt3sas_base_get_pcie_sgl(ioc, smid); |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 2054 | msg_dma = mpt3sas_base_get_pcie_sgl_dma(ioc, smid); |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2055 | |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 2056 | main_chain_element->Address = cpu_to_le64(msg_dma); |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2057 | main_chain_element->NextChainOffset = 0; |
| 2058 | main_chain_element->Flags = MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT | |
| 2059 | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR | |
| 2060 | MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP; |
| 2061 | |
| 2062 | /* Build first prp, sge need not to be page aligned*/ |
| 2063 | ptr_first_sgl = (pMpi25IeeeSgeChain64_t)&mpi_request->SGL; |
| 2064 | sg_scmd = scsi_sglist(scmd); |
| 2065 | sge_addr = sg_dma_address(sg_scmd); |
| 2066 | sge_len = sg_dma_len(sg_scmd); |
| 2067 | |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 2068 | offset = sge_addr & page_mask; |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2069 | first_prp_len = nvme_pg_size - offset; |
| 2070 | |
| 2071 | ptr_first_sgl->Address = cpu_to_le64(sge_addr); |
| 2072 | ptr_first_sgl->Length = cpu_to_le32(first_prp_len); |
| 2073 | |
| 2074 | data_len -= first_prp_len; |
| 2075 | |
| 2076 | if (sge_len > first_prp_len) { |
| 2077 | sge_addr += first_prp_len; |
| 2078 | sge_len -= first_prp_len; |
| 2079 | } else if (data_len && (sge_len == first_prp_len)) { |
| 2080 | sg_scmd = sg_next(sg_scmd); |
| 2081 | sge_addr = sg_dma_address(sg_scmd); |
| 2082 | sge_len = sg_dma_len(sg_scmd); |
| 2083 | } |
| 2084 | |
| 2085 | for (;;) { |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 2086 | offset = sge_addr & page_mask; |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2087 | |
| 2088 | /* Put PRP pointer due to page boundary*/ |
| 2089 | page_mask_result = (uintptr_t)(curr_buff + 1) & page_mask; |
| 2090 | if (unlikely(!page_mask_result)) { |
| 2091 | scmd_printk(KERN_NOTICE, |
| 2092 | scmd, "page boundary curr_buff: 0x%p\n", |
| 2093 | curr_buff); |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 2094 | msg_dma += 8; |
| 2095 | *curr_buff = cpu_to_le64(msg_dma); |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2096 | curr_buff++; |
| 2097 | num_prp_in_chain++; |
| 2098 | } |
| 2099 | |
| 2100 | *curr_buff = cpu_to_le64(sge_addr); |
| 2101 | curr_buff++; |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 2102 | msg_dma += 8; |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2103 | num_prp_in_chain++; |
| 2104 | |
| 2105 | sge_addr += nvme_pg_size; |
| 2106 | sge_len -= nvme_pg_size; |
| 2107 | data_len -= nvme_pg_size; |
| 2108 | |
| 2109 | if (data_len <= 0) |
| 2110 | break; |
| 2111 | |
| 2112 | if (sge_len > 0) |
| 2113 | continue; |
| 2114 | |
| 2115 | sg_scmd = sg_next(sg_scmd); |
| 2116 | sge_addr = sg_dma_address(sg_scmd); |
| 2117 | sge_len = sg_dma_len(sg_scmd); |
| 2118 | } |
| 2119 | |
| 2120 | main_chain_element->Length = |
| 2121 | cpu_to_le32(num_prp_in_chain * sizeof(u64)); |
| 2122 | return; |
| 2123 | } |
| 2124 | |
| 2125 | static bool |
| 2126 | base_is_prp_possible(struct MPT3SAS_ADAPTER *ioc, |
| 2127 | struct _pcie_device *pcie_device, struct scsi_cmnd *scmd, int sge_count) |
| 2128 | { |
| 2129 | u32 data_length = 0; |
| 2130 | struct scatterlist *sg_scmd; |
| 2131 | bool build_prp = true; |
| 2132 | |
Suganath Prabu Subramani | 494f401 | 2017-10-31 18:02:38 +0530 | [diff] [blame] | 2133 | data_length = scsi_bufflen(scmd); |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2134 | sg_scmd = scsi_sglist(scmd); |
| 2135 | |
| 2136 | /* If Datalenth is <= 16K and number of SGE’s entries are <= 2 |
| 2137 | * we built IEEE SGL |
| 2138 | */ |
| 2139 | if ((data_length <= NVME_PRP_PAGE_SIZE*4) && (sge_count <= 2)) |
| 2140 | build_prp = false; |
| 2141 | |
| 2142 | return build_prp; |
| 2143 | } |
| 2144 | |
| 2145 | /** |
| 2146 | * _base_check_pcie_native_sgl - This function is called for PCIe end devices to |
| 2147 | * determine if the driver needs to build a native SGL. If so, that native |
| 2148 | * SGL is built in the special contiguous buffers allocated especially for |
| 2149 | * PCIe SGL creation. If the driver will not build a native SGL, return |
| 2150 | * TRUE and a normal IEEE SGL will be built. Currently this routine |
| 2151 | * supports NVMe. |
| 2152 | * @ioc: per adapter object |
| 2153 | * @mpi_request: mf request pointer |
| 2154 | * @smid: system request message index |
| 2155 | * @scmd: scsi command |
| 2156 | * @pcie_device: points to the PCIe device's info |
| 2157 | * |
| 2158 | * Returns 0 if native SGL was built, 1 if no SGL was built |
| 2159 | */ |
| 2160 | static int |
| 2161 | _base_check_pcie_native_sgl(struct MPT3SAS_ADAPTER *ioc, |
| 2162 | Mpi25SCSIIORequest_t *mpi_request, u16 smid, struct scsi_cmnd *scmd, |
| 2163 | struct _pcie_device *pcie_device) |
| 2164 | { |
| 2165 | struct scatterlist *sg_scmd; |
| 2166 | int sges_left; |
| 2167 | |
| 2168 | /* Get the SG list pointer and info. */ |
| 2169 | sg_scmd = scsi_sglist(scmd); |
| 2170 | sges_left = scsi_dma_map(scmd); |
| 2171 | if (sges_left < 0) { |
| 2172 | sdev_printk(KERN_ERR, scmd->device, |
| 2173 | "scsi_dma_map failed: request for %d bytes!\n", |
| 2174 | scsi_bufflen(scmd)); |
| 2175 | return 1; |
| 2176 | } |
| 2177 | |
| 2178 | /* Check if we need to build a native SG list. */ |
| 2179 | if (base_is_prp_possible(ioc, pcie_device, |
| 2180 | scmd, sges_left) == 0) { |
| 2181 | /* We built a native SG list, just return. */ |
| 2182 | goto out; |
| 2183 | } |
| 2184 | |
| 2185 | /* |
| 2186 | * Build native NVMe PRP. |
| 2187 | */ |
| 2188 | base_make_prp_nvme(ioc, scmd, mpi_request, |
| 2189 | smid, sges_left); |
| 2190 | |
| 2191 | return 0; |
| 2192 | out: |
| 2193 | scsi_dma_unmap(scmd); |
| 2194 | return 1; |
| 2195 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2196 | |
| 2197 | /** |
| 2198 | * _base_add_sg_single_ieee - add sg element for IEEE format |
| 2199 | * @paddr: virtual address for SGE |
| 2200 | * @flags: SGE flags |
| 2201 | * @chain_offset: number of 128 byte elements from start of segment |
| 2202 | * @length: data transfer length |
| 2203 | * @dma_addr: Physical address |
| 2204 | * |
| 2205 | * Return nothing. |
| 2206 | */ |
| 2207 | static void |
| 2208 | _base_add_sg_single_ieee(void *paddr, u8 flags, u8 chain_offset, u32 length, |
| 2209 | dma_addr_t dma_addr) |
| 2210 | { |
| 2211 | Mpi25IeeeSgeChain64_t *sgel = paddr; |
| 2212 | |
| 2213 | sgel->Flags = flags; |
| 2214 | sgel->NextChainOffset = chain_offset; |
| 2215 | sgel->Length = cpu_to_le32(length); |
| 2216 | sgel->Address = cpu_to_le64(dma_addr); |
| 2217 | } |
| 2218 | |
| 2219 | /** |
| 2220 | * _base_build_zero_len_sge_ieee - build zero length sg entry for IEEE format |
| 2221 | * @ioc: per adapter object |
| 2222 | * @paddr: virtual address for SGE |
| 2223 | * |
| 2224 | * Create a zero length scatter gather entry to insure the IOCs hardware has |
| 2225 | * something to use if the target device goes brain dead and tries |
| 2226 | * to send data even when none is asked for. |
| 2227 | * |
| 2228 | * Return nothing. |
| 2229 | */ |
| 2230 | static void |
| 2231 | _base_build_zero_len_sge_ieee(struct MPT3SAS_ADAPTER *ioc, void *paddr) |
| 2232 | { |
| 2233 | u8 sgl_flags = (MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | |
| 2234 | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR | |
| 2235 | MPI25_IEEE_SGE_FLAGS_END_OF_LIST); |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 2236 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2237 | _base_add_sg_single_ieee(paddr, sgl_flags, 0, 0, -1); |
| 2238 | } |
| 2239 | |
| 2240 | /** |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 2241 | * _base_build_sg_scmd - main sg creation routine |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2242 | * pcie_device is unused here! |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 2243 | * @ioc: per adapter object |
| 2244 | * @scmd: scsi command |
| 2245 | * @smid: system request message index |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2246 | * @unused: unused pcie_device pointer |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 2247 | * Context: none. |
| 2248 | * |
| 2249 | * The main routine that builds scatter gather table from a given |
| 2250 | * scsi request sent via the .queuecommand main handler. |
| 2251 | * |
| 2252 | * Returns 0 success, anything else error |
| 2253 | */ |
| 2254 | static int |
| 2255 | _base_build_sg_scmd(struct MPT3SAS_ADAPTER *ioc, |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2256 | struct scsi_cmnd *scmd, u16 smid, struct _pcie_device *unused) |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 2257 | { |
| 2258 | Mpi2SCSIIORequest_t *mpi_request; |
| 2259 | dma_addr_t chain_dma; |
| 2260 | struct scatterlist *sg_scmd; |
| 2261 | void *sg_local, *chain; |
| 2262 | u32 chain_offset; |
| 2263 | u32 chain_length; |
| 2264 | u32 chain_flags; |
| 2265 | int sges_left; |
| 2266 | u32 sges_in_segment; |
| 2267 | u32 sgl_flags; |
| 2268 | u32 sgl_flags_last_element; |
| 2269 | u32 sgl_flags_end_buffer; |
| 2270 | struct chain_tracker *chain_req; |
| 2271 | |
| 2272 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 2273 | |
| 2274 | /* init scatter gather flags */ |
| 2275 | sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT; |
| 2276 | if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 2277 | sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC; |
| 2278 | sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT) |
| 2279 | << MPI2_SGE_FLAGS_SHIFT; |
| 2280 | sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT | |
| 2281 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST) |
| 2282 | << MPI2_SGE_FLAGS_SHIFT; |
| 2283 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 2284 | |
| 2285 | sg_scmd = scsi_sglist(scmd); |
| 2286 | sges_left = scsi_dma_map(scmd); |
| 2287 | if (sges_left < 0) { |
| 2288 | sdev_printk(KERN_ERR, scmd->device, |
| 2289 | "pci_map_sg failed: request for %d bytes!\n", |
| 2290 | scsi_bufflen(scmd)); |
| 2291 | return -ENOMEM; |
| 2292 | } |
| 2293 | |
| 2294 | sg_local = &mpi_request->SGL; |
| 2295 | sges_in_segment = ioc->max_sges_in_main_message; |
| 2296 | if (sges_left <= sges_in_segment) |
| 2297 | goto fill_in_last_segment; |
| 2298 | |
| 2299 | mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) + |
| 2300 | (sges_in_segment * ioc->sge_size))/4; |
| 2301 | |
| 2302 | /* fill in main message segment when there is a chain following */ |
| 2303 | while (sges_in_segment) { |
| 2304 | if (sges_in_segment == 1) |
| 2305 | ioc->base_add_sg_single(sg_local, |
| 2306 | sgl_flags_last_element | sg_dma_len(sg_scmd), |
| 2307 | sg_dma_address(sg_scmd)); |
| 2308 | else |
| 2309 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 2310 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 2311 | sg_scmd = sg_next(sg_scmd); |
| 2312 | sg_local += ioc->sge_size; |
| 2313 | sges_left--; |
| 2314 | sges_in_segment--; |
| 2315 | } |
| 2316 | |
| 2317 | /* initializing the chain flags and pointers */ |
| 2318 | chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT; |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 2319 | chain_req = _base_get_chain_buffer_tracker(ioc, scmd); |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 2320 | if (!chain_req) |
| 2321 | return -1; |
| 2322 | chain = chain_req->chain_buffer; |
| 2323 | chain_dma = chain_req->chain_buffer_dma; |
| 2324 | do { |
| 2325 | sges_in_segment = (sges_left <= |
| 2326 | ioc->max_sges_in_chain_message) ? sges_left : |
| 2327 | ioc->max_sges_in_chain_message; |
| 2328 | chain_offset = (sges_left == sges_in_segment) ? |
| 2329 | 0 : (sges_in_segment * ioc->sge_size)/4; |
| 2330 | chain_length = sges_in_segment * ioc->sge_size; |
| 2331 | if (chain_offset) { |
| 2332 | chain_offset = chain_offset << |
| 2333 | MPI2_SGE_CHAIN_OFFSET_SHIFT; |
| 2334 | chain_length += ioc->sge_size; |
| 2335 | } |
| 2336 | ioc->base_add_sg_single(sg_local, chain_flags | chain_offset | |
| 2337 | chain_length, chain_dma); |
| 2338 | sg_local = chain; |
| 2339 | if (!chain_offset) |
| 2340 | goto fill_in_last_segment; |
| 2341 | |
| 2342 | /* fill in chain segments */ |
| 2343 | while (sges_in_segment) { |
| 2344 | if (sges_in_segment == 1) |
| 2345 | ioc->base_add_sg_single(sg_local, |
| 2346 | sgl_flags_last_element | |
| 2347 | sg_dma_len(sg_scmd), |
| 2348 | sg_dma_address(sg_scmd)); |
| 2349 | else |
| 2350 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 2351 | sg_dma_len(sg_scmd), |
| 2352 | sg_dma_address(sg_scmd)); |
| 2353 | sg_scmd = sg_next(sg_scmd); |
| 2354 | sg_local += ioc->sge_size; |
| 2355 | sges_left--; |
| 2356 | sges_in_segment--; |
| 2357 | } |
| 2358 | |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 2359 | chain_req = _base_get_chain_buffer_tracker(ioc, scmd); |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 2360 | if (!chain_req) |
| 2361 | return -1; |
| 2362 | chain = chain_req->chain_buffer; |
| 2363 | chain_dma = chain_req->chain_buffer_dma; |
| 2364 | } while (1); |
| 2365 | |
| 2366 | |
| 2367 | fill_in_last_segment: |
| 2368 | |
| 2369 | /* fill the last segment */ |
| 2370 | while (sges_left) { |
| 2371 | if (sges_left == 1) |
| 2372 | ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer | |
| 2373 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 2374 | else |
| 2375 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 2376 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 2377 | sg_scmd = sg_next(sg_scmd); |
| 2378 | sg_local += ioc->sge_size; |
| 2379 | sges_left--; |
| 2380 | } |
| 2381 | |
| 2382 | return 0; |
| 2383 | } |
| 2384 | |
| 2385 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2386 | * _base_build_sg_scmd_ieee - main sg creation routine for IEEE format |
| 2387 | * @ioc: per adapter object |
| 2388 | * @scmd: scsi command |
| 2389 | * @smid: system request message index |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2390 | * @pcie_device: Pointer to pcie_device. If set, the pcie native sgl will be |
| 2391 | * constructed on need. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2392 | * Context: none. |
| 2393 | * |
| 2394 | * The main routine that builds scatter gather table from a given |
| 2395 | * scsi request sent via the .queuecommand main handler. |
| 2396 | * |
| 2397 | * Returns 0 success, anything else error |
| 2398 | */ |
| 2399 | static int |
| 2400 | _base_build_sg_scmd_ieee(struct MPT3SAS_ADAPTER *ioc, |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2401 | struct scsi_cmnd *scmd, u16 smid, struct _pcie_device *pcie_device) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2402 | { |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2403 | Mpi25SCSIIORequest_t *mpi_request; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2404 | dma_addr_t chain_dma; |
| 2405 | struct scatterlist *sg_scmd; |
| 2406 | void *sg_local, *chain; |
| 2407 | u32 chain_offset; |
| 2408 | u32 chain_length; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2409 | int sges_left; |
| 2410 | u32 sges_in_segment; |
| 2411 | u8 simple_sgl_flags; |
| 2412 | u8 simple_sgl_flags_last; |
| 2413 | u8 chain_sgl_flags; |
| 2414 | struct chain_tracker *chain_req; |
| 2415 | |
| 2416 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 2417 | |
| 2418 | /* init scatter gather flags */ |
| 2419 | simple_sgl_flags = MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | |
| 2420 | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; |
| 2421 | simple_sgl_flags_last = simple_sgl_flags | |
| 2422 | MPI25_IEEE_SGE_FLAGS_END_OF_LIST; |
| 2423 | chain_sgl_flags = MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT | |
| 2424 | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; |
| 2425 | |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2426 | /* Check if we need to build a native SG list. */ |
| 2427 | if ((pcie_device) && (_base_check_pcie_native_sgl(ioc, mpi_request, |
| 2428 | smid, scmd, pcie_device) == 0)) { |
| 2429 | /* We built a native SG list, just return. */ |
| 2430 | return 0; |
| 2431 | } |
| 2432 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2433 | sg_scmd = scsi_sglist(scmd); |
| 2434 | sges_left = scsi_dma_map(scmd); |
Sreekanth Reddy | 62f5c74 | 2015-06-30 12:25:01 +0530 | [diff] [blame] | 2435 | if (sges_left < 0) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2436 | sdev_printk(KERN_ERR, scmd->device, |
| 2437 | "pci_map_sg failed: request for %d bytes!\n", |
| 2438 | scsi_bufflen(scmd)); |
| 2439 | return -ENOMEM; |
| 2440 | } |
| 2441 | |
| 2442 | sg_local = &mpi_request->SGL; |
| 2443 | sges_in_segment = (ioc->request_sz - |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2444 | offsetof(Mpi25SCSIIORequest_t, SGL))/ioc->sge_size_ieee; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2445 | if (sges_left <= sges_in_segment) |
| 2446 | goto fill_in_last_segment; |
| 2447 | |
| 2448 | mpi_request->ChainOffset = (sges_in_segment - 1 /* chain element */) + |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 2449 | (offsetof(Mpi25SCSIIORequest_t, SGL)/ioc->sge_size_ieee); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2450 | |
| 2451 | /* fill in main message segment when there is a chain following */ |
| 2452 | while (sges_in_segment > 1) { |
| 2453 | _base_add_sg_single_ieee(sg_local, simple_sgl_flags, 0, |
| 2454 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 2455 | sg_scmd = sg_next(sg_scmd); |
| 2456 | sg_local += ioc->sge_size_ieee; |
| 2457 | sges_left--; |
| 2458 | sges_in_segment--; |
| 2459 | } |
| 2460 | |
Wei Yongjun | 25ef16d | 2012-12-12 02:26:51 +0530 | [diff] [blame] | 2461 | /* initializing the pointers */ |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 2462 | chain_req = _base_get_chain_buffer_tracker(ioc, scmd); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2463 | if (!chain_req) |
| 2464 | return -1; |
| 2465 | chain = chain_req->chain_buffer; |
| 2466 | chain_dma = chain_req->chain_buffer_dma; |
| 2467 | do { |
| 2468 | sges_in_segment = (sges_left <= |
| 2469 | ioc->max_sges_in_chain_message) ? sges_left : |
| 2470 | ioc->max_sges_in_chain_message; |
| 2471 | chain_offset = (sges_left == sges_in_segment) ? |
| 2472 | 0 : sges_in_segment; |
| 2473 | chain_length = sges_in_segment * ioc->sge_size_ieee; |
| 2474 | if (chain_offset) |
| 2475 | chain_length += ioc->sge_size_ieee; |
| 2476 | _base_add_sg_single_ieee(sg_local, chain_sgl_flags, |
| 2477 | chain_offset, chain_length, chain_dma); |
| 2478 | |
| 2479 | sg_local = chain; |
| 2480 | if (!chain_offset) |
| 2481 | goto fill_in_last_segment; |
| 2482 | |
| 2483 | /* fill in chain segments */ |
| 2484 | while (sges_in_segment) { |
| 2485 | _base_add_sg_single_ieee(sg_local, simple_sgl_flags, 0, |
| 2486 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 2487 | sg_scmd = sg_next(sg_scmd); |
| 2488 | sg_local += ioc->sge_size_ieee; |
| 2489 | sges_left--; |
| 2490 | sges_in_segment--; |
| 2491 | } |
| 2492 | |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 2493 | chain_req = _base_get_chain_buffer_tracker(ioc, scmd); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2494 | if (!chain_req) |
| 2495 | return -1; |
| 2496 | chain = chain_req->chain_buffer; |
| 2497 | chain_dma = chain_req->chain_buffer_dma; |
| 2498 | } while (1); |
| 2499 | |
| 2500 | |
| 2501 | fill_in_last_segment: |
| 2502 | |
| 2503 | /* fill the last segment */ |
Sreekanth Reddy | 62f5c74 | 2015-06-30 12:25:01 +0530 | [diff] [blame] | 2504 | while (sges_left > 0) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2505 | if (sges_left == 1) |
| 2506 | _base_add_sg_single_ieee(sg_local, |
| 2507 | simple_sgl_flags_last, 0, sg_dma_len(sg_scmd), |
| 2508 | sg_dma_address(sg_scmd)); |
| 2509 | else |
| 2510 | _base_add_sg_single_ieee(sg_local, simple_sgl_flags, 0, |
| 2511 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 2512 | sg_scmd = sg_next(sg_scmd); |
| 2513 | sg_local += ioc->sge_size_ieee; |
| 2514 | sges_left--; |
| 2515 | } |
| 2516 | |
| 2517 | return 0; |
| 2518 | } |
| 2519 | |
| 2520 | /** |
| 2521 | * _base_build_sg_ieee - build generic sg for IEEE format |
| 2522 | * @ioc: per adapter object |
| 2523 | * @psge: virtual address for SGE |
| 2524 | * @data_out_dma: physical address for WRITES |
| 2525 | * @data_out_sz: data xfer size for WRITES |
| 2526 | * @data_in_dma: physical address for READS |
| 2527 | * @data_in_sz: data xfer size for READS |
| 2528 | * |
| 2529 | * Return nothing. |
| 2530 | */ |
| 2531 | static void |
| 2532 | _base_build_sg_ieee(struct MPT3SAS_ADAPTER *ioc, void *psge, |
| 2533 | dma_addr_t data_out_dma, size_t data_out_sz, dma_addr_t data_in_dma, |
| 2534 | size_t data_in_sz) |
| 2535 | { |
| 2536 | u8 sgl_flags; |
| 2537 | |
| 2538 | if (!data_out_sz && !data_in_sz) { |
| 2539 | _base_build_zero_len_sge_ieee(ioc, psge); |
| 2540 | return; |
| 2541 | } |
| 2542 | |
| 2543 | if (data_out_sz && data_in_sz) { |
| 2544 | /* WRITE sgel first */ |
| 2545 | sgl_flags = MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | |
| 2546 | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; |
| 2547 | _base_add_sg_single_ieee(psge, sgl_flags, 0, data_out_sz, |
| 2548 | data_out_dma); |
| 2549 | |
| 2550 | /* incr sgel */ |
| 2551 | psge += ioc->sge_size_ieee; |
| 2552 | |
| 2553 | /* READ sgel last */ |
| 2554 | sgl_flags |= MPI25_IEEE_SGE_FLAGS_END_OF_LIST; |
| 2555 | _base_add_sg_single_ieee(psge, sgl_flags, 0, data_in_sz, |
| 2556 | data_in_dma); |
| 2557 | } else if (data_out_sz) /* WRITE */ { |
| 2558 | sgl_flags = MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | |
| 2559 | MPI25_IEEE_SGE_FLAGS_END_OF_LIST | |
| 2560 | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; |
| 2561 | _base_add_sg_single_ieee(psge, sgl_flags, 0, data_out_sz, |
| 2562 | data_out_dma); |
| 2563 | } else if (data_in_sz) /* READ */ { |
| 2564 | sgl_flags = MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | |
| 2565 | MPI25_IEEE_SGE_FLAGS_END_OF_LIST | |
| 2566 | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; |
| 2567 | _base_add_sg_single_ieee(psge, sgl_flags, 0, data_in_sz, |
| 2568 | data_in_dma); |
| 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10)) |
| 2573 | |
| 2574 | /** |
| 2575 | * _base_config_dma_addressing - set dma addressing |
| 2576 | * @ioc: per adapter object |
| 2577 | * @pdev: PCI device struct |
| 2578 | * |
| 2579 | * Returns 0 for success, non-zero for failure. |
| 2580 | */ |
| 2581 | static int |
| 2582 | _base_config_dma_addressing(struct MPT3SAS_ADAPTER *ioc, struct pci_dev *pdev) |
| 2583 | { |
| 2584 | struct sysinfo s; |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 2585 | u64 consistent_dma_mask; |
| 2586 | |
Suganath Prabu Subramani | 0448f01 | 2018-02-07 02:51:46 -0800 | [diff] [blame] | 2587 | if (ioc->is_mcpu_endpoint) |
| 2588 | goto try_32bit; |
| 2589 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 2590 | if (ioc->dma_mask) |
| 2591 | consistent_dma_mask = DMA_BIT_MASK(64); |
| 2592 | else |
| 2593 | consistent_dma_mask = DMA_BIT_MASK(32); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2594 | |
| 2595 | if (sizeof(dma_addr_t) > 4) { |
| 2596 | const uint64_t required_mask = |
| 2597 | dma_get_required_mask(&pdev->dev); |
| 2598 | if ((required_mask > DMA_BIT_MASK(32)) && |
| 2599 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 2600 | !pci_set_consistent_dma_mask(pdev, consistent_dma_mask)) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2601 | ioc->base_add_sg_single = &_base_add_sg_single_64; |
| 2602 | ioc->sge_size = sizeof(Mpi2SGESimple64_t); |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 2603 | ioc->dma_mask = 64; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2604 | goto out; |
| 2605 | } |
| 2606 | } |
| 2607 | |
Suganath Prabu Subramani | 0448f01 | 2018-02-07 02:51:46 -0800 | [diff] [blame] | 2608 | try_32bit: |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2609 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) |
| 2610 | && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) { |
| 2611 | ioc->base_add_sg_single = &_base_add_sg_single_32; |
| 2612 | ioc->sge_size = sizeof(Mpi2SGESimple32_t); |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 2613 | ioc->dma_mask = 32; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2614 | } else |
| 2615 | return -ENODEV; |
| 2616 | |
| 2617 | out: |
| 2618 | si_meminfo(&s); |
| 2619 | pr_info(MPT3SAS_FMT |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 2620 | "%d BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (%ld kB)\n", |
| 2621 | ioc->name, ioc->dma_mask, convert_to_kb(s.totalram)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2622 | |
| 2623 | return 0; |
| 2624 | } |
| 2625 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 2626 | static int |
| 2627 | _base_change_consistent_dma_mask(struct MPT3SAS_ADAPTER *ioc, |
| 2628 | struct pci_dev *pdev) |
| 2629 | { |
| 2630 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
| 2631 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) |
| 2632 | return -ENODEV; |
| 2633 | } |
| 2634 | return 0; |
| 2635 | } |
| 2636 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2637 | /** |
| 2638 | * _base_check_enable_msix - checks MSIX capabable. |
| 2639 | * @ioc: per adapter object |
| 2640 | * |
| 2641 | * Check to see if card is capable of MSIX, and set number |
| 2642 | * of available msix vectors |
| 2643 | */ |
| 2644 | static int |
| 2645 | _base_check_enable_msix(struct MPT3SAS_ADAPTER *ioc) |
| 2646 | { |
| 2647 | int base; |
| 2648 | u16 message_control; |
| 2649 | |
Sreekanth Reddy | 4208117 | 2015-11-11 17:30:26 +0530 | [diff] [blame] | 2650 | /* Check whether controller SAS2008 B0 controller, |
| 2651 | * if it is SAS2008 B0 controller use IO-APIC instead of MSIX |
| 2652 | */ |
| 2653 | if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 && |
| 2654 | ioc->pdev->revision == SAS2_PCI_DEVICE_B0_REVISION) { |
| 2655 | return -EINVAL; |
| 2656 | } |
| 2657 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2658 | base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX); |
| 2659 | if (!base) { |
| 2660 | dfailprintk(ioc, pr_info(MPT3SAS_FMT "msix not supported\n", |
| 2661 | ioc->name)); |
| 2662 | return -EINVAL; |
| 2663 | } |
| 2664 | |
| 2665 | /* get msix vector count */ |
Sreekanth Reddy | 4208117 | 2015-11-11 17:30:26 +0530 | [diff] [blame] | 2666 | /* NUMA_IO not supported for older controllers */ |
| 2667 | if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2004 || |
| 2668 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 || |
| 2669 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_1 || |
| 2670 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_2 || |
| 2671 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_3 || |
| 2672 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_1 || |
| 2673 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_2) |
| 2674 | ioc->msix_vector_count = 1; |
| 2675 | else { |
| 2676 | pci_read_config_word(ioc->pdev, base + 2, &message_control); |
| 2677 | ioc->msix_vector_count = (message_control & 0x3FF) + 1; |
| 2678 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2679 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 2680 | "msix is supported, vector_count(%d)\n", |
| 2681 | ioc->name, ioc->msix_vector_count)); |
| 2682 | return 0; |
| 2683 | } |
| 2684 | |
| 2685 | /** |
| 2686 | * _base_free_irq - free irq |
| 2687 | * @ioc: per adapter object |
| 2688 | * |
| 2689 | * Freeing respective reply_queue from the list. |
| 2690 | */ |
| 2691 | static void |
| 2692 | _base_free_irq(struct MPT3SAS_ADAPTER *ioc) |
| 2693 | { |
| 2694 | struct adapter_reply_queue *reply_q, *next; |
| 2695 | |
| 2696 | if (list_empty(&ioc->reply_queue_list)) |
| 2697 | return; |
| 2698 | |
| 2699 | list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) { |
| 2700 | list_del(&reply_q->list); |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2701 | free_irq(pci_irq_vector(ioc->pdev, reply_q->msix_index), |
| 2702 | reply_q); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2703 | kfree(reply_q); |
| 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | /** |
| 2708 | * _base_request_irq - request irq |
| 2709 | * @ioc: per adapter object |
| 2710 | * @index: msix index into vector table |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2711 | * |
| 2712 | * Inserting respective reply_queue into the list. |
| 2713 | */ |
| 2714 | static int |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2715 | _base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2716 | { |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2717 | struct pci_dev *pdev = ioc->pdev; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2718 | struct adapter_reply_queue *reply_q; |
| 2719 | int r; |
| 2720 | |
| 2721 | reply_q = kzalloc(sizeof(struct adapter_reply_queue), GFP_KERNEL); |
| 2722 | if (!reply_q) { |
| 2723 | pr_err(MPT3SAS_FMT "unable to allocate memory %d!\n", |
| 2724 | ioc->name, (int)sizeof(struct adapter_reply_queue)); |
| 2725 | return -ENOMEM; |
| 2726 | } |
| 2727 | reply_q->ioc = ioc; |
| 2728 | reply_q->msix_index = index; |
Sreekanth Reddy | 14b3114 | 2015-01-12 11:39:03 +0530 | [diff] [blame] | 2729 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2730 | atomic_set(&reply_q->busy, 0); |
| 2731 | if (ioc->msix_enable) |
| 2732 | snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d", |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2733 | ioc->driver_name, ioc->id, index); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2734 | else |
| 2735 | snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d", |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2736 | ioc->driver_name, ioc->id); |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2737 | r = request_irq(pci_irq_vector(pdev, index), _base_interrupt, |
| 2738 | IRQF_SHARED, reply_q->name, reply_q); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2739 | if (r) { |
| 2740 | pr_err(MPT3SAS_FMT "unable to allocate interrupt %d!\n", |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2741 | reply_q->name, pci_irq_vector(pdev, index)); |
Suganath prabu Subramani | da3cec2 | 2016-02-11 15:02:55 +0530 | [diff] [blame] | 2742 | kfree(reply_q); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2743 | return -EBUSY; |
| 2744 | } |
| 2745 | |
| 2746 | INIT_LIST_HEAD(&reply_q->list); |
| 2747 | list_add_tail(&reply_q->list, &ioc->reply_queue_list); |
| 2748 | return 0; |
| 2749 | } |
| 2750 | |
| 2751 | /** |
| 2752 | * _base_assign_reply_queues - assigning msix index for each cpu |
| 2753 | * @ioc: per adapter object |
| 2754 | * |
| 2755 | * The enduser would need to set the affinity via /proc/irq/#/smp_affinity |
| 2756 | * |
| 2757 | * It would nice if we could call irq_set_affinity, however it is not |
| 2758 | * an exported symbol |
| 2759 | */ |
| 2760 | static void |
| 2761 | _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc) |
| 2762 | { |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 2763 | unsigned int cpu, nr_cpus, nr_msix, index = 0; |
Sreekanth Reddy | 14b3114 | 2015-01-12 11:39:03 +0530 | [diff] [blame] | 2764 | struct adapter_reply_queue *reply_q; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2765 | |
| 2766 | if (!_base_is_controller_msix_enabled(ioc)) |
| 2767 | return; |
| 2768 | |
| 2769 | memset(ioc->cpu_msix_table, 0, ioc->cpu_msix_table_sz); |
| 2770 | |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 2771 | nr_cpus = num_online_cpus(); |
| 2772 | nr_msix = ioc->reply_queue_count = min(ioc->reply_queue_count, |
| 2773 | ioc->facts.MaxMSIxVectors); |
| 2774 | if (!nr_msix) |
| 2775 | return; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2776 | |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2777 | if (smp_affinity_enable) { |
| 2778 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { |
| 2779 | const cpumask_t *mask = pci_irq_get_affinity(ioc->pdev, |
| 2780 | reply_q->msix_index); |
| 2781 | if (!mask) { |
| 2782 | pr_warn(MPT3SAS_FMT "no affinity for msi %x\n", |
| 2783 | ioc->name, reply_q->msix_index); |
| 2784 | continue; |
| 2785 | } |
| 2786 | |
Tomas Henzl | 4a8842d | 2018-01-19 16:22:05 +0100 | [diff] [blame] | 2787 | for_each_cpu_and(cpu, mask, cpu_online_mask) { |
| 2788 | if (cpu >= ioc->cpu_msix_table_sz) |
| 2789 | break; |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2790 | ioc->cpu_msix_table[cpu] = reply_q->msix_index; |
Tomas Henzl | 4a8842d | 2018-01-19 16:22:05 +0100 | [diff] [blame] | 2791 | } |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2792 | } |
| 2793 | return; |
| 2794 | } |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 2795 | cpu = cpumask_first(cpu_online_mask); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2796 | |
Sreekanth Reddy | 14b3114 | 2015-01-12 11:39:03 +0530 | [diff] [blame] | 2797 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { |
| 2798 | |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 2799 | unsigned int i, group = nr_cpus / nr_msix; |
| 2800 | |
Sreekanth Reddy | 14b3114 | 2015-01-12 11:39:03 +0530 | [diff] [blame] | 2801 | if (cpu >= nr_cpus) |
| 2802 | break; |
| 2803 | |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 2804 | if (index < nr_cpus % nr_msix) |
| 2805 | group++; |
| 2806 | |
| 2807 | for (i = 0 ; i < group ; i++) { |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2808 | ioc->cpu_msix_table[cpu] = reply_q->msix_index; |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 2809 | cpu = cpumask_next(cpu, cpu_online_mask); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2810 | } |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 2811 | index++; |
Sreekanth Reddy | 14b3114 | 2015-01-12 11:39:03 +0530 | [diff] [blame] | 2812 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | /** |
| 2816 | * _base_disable_msix - disables msix |
| 2817 | * @ioc: per adapter object |
| 2818 | * |
| 2819 | */ |
| 2820 | static void |
| 2821 | _base_disable_msix(struct MPT3SAS_ADAPTER *ioc) |
| 2822 | { |
| 2823 | if (!ioc->msix_enable) |
| 2824 | return; |
| 2825 | pci_disable_msix(ioc->pdev); |
| 2826 | ioc->msix_enable = 0; |
| 2827 | } |
| 2828 | |
| 2829 | /** |
| 2830 | * _base_enable_msix - enables msix, failback to io_apic |
| 2831 | * @ioc: per adapter object |
| 2832 | * |
| 2833 | */ |
| 2834 | static int |
| 2835 | _base_enable_msix(struct MPT3SAS_ADAPTER *ioc) |
| 2836 | { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2837 | int r; |
Suganath Prabu Subramani | bb35066 | 2016-10-26 13:34:33 +0530 | [diff] [blame] | 2838 | int i, local_max_msix_vectors; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2839 | u8 try_msix = 0; |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2840 | unsigned int irq_flags = PCI_IRQ_MSIX; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2841 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2842 | if (msix_disable == -1 || msix_disable == 0) |
| 2843 | try_msix = 1; |
| 2844 | |
| 2845 | if (!try_msix) |
| 2846 | goto try_ioapic; |
| 2847 | |
| 2848 | if (_base_check_enable_msix(ioc) != 0) |
| 2849 | goto try_ioapic; |
| 2850 | |
| 2851 | ioc->reply_queue_count = min_t(int, ioc->cpu_count, |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2852 | ioc->msix_vector_count); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2853 | |
Sreekanth Reddy | 9c50006 | 2013-08-14 18:23:20 +0530 | [diff] [blame] | 2854 | printk(MPT3SAS_FMT "MSI-X vectors supported: %d, no of cores" |
| 2855 | ": %d, max_msix_vectors: %d\n", ioc->name, ioc->msix_vector_count, |
| 2856 | ioc->cpu_count, max_msix_vectors); |
| 2857 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 2858 | if (!ioc->rdpq_array_enable && max_msix_vectors == -1) |
Sreekanth Reddy | 06f5f97 | 2017-10-10 18:41:16 +0530 | [diff] [blame] | 2859 | local_max_msix_vectors = (reset_devices) ? 1 : 8; |
Suganath Prabu Subramani | bb35066 | 2016-10-26 13:34:33 +0530 | [diff] [blame] | 2860 | else |
| 2861 | local_max_msix_vectors = max_msix_vectors; |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 2862 | |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2863 | if (local_max_msix_vectors > 0) |
Suganath Prabu Subramani | bb35066 | 2016-10-26 13:34:33 +0530 | [diff] [blame] | 2864 | ioc->reply_queue_count = min_t(int, local_max_msix_vectors, |
Sreekanth Reddy | 9c50006 | 2013-08-14 18:23:20 +0530 | [diff] [blame] | 2865 | ioc->reply_queue_count); |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2866 | else if (local_max_msix_vectors == 0) |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 2867 | goto try_ioapic; |
Sreekanth Reddy | 9c50006 | 2013-08-14 18:23:20 +0530 | [diff] [blame] | 2868 | |
Suganath Prabu Subramani | 6403830 | 2016-02-08 22:13:39 +0530 | [diff] [blame] | 2869 | if (ioc->msix_vector_count < ioc->cpu_count) |
| 2870 | smp_affinity_enable = 0; |
| 2871 | |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2872 | if (smp_affinity_enable) |
| 2873 | irq_flags |= PCI_IRQ_AFFINITY; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2874 | |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2875 | r = pci_alloc_irq_vectors(ioc->pdev, 1, ioc->reply_queue_count, |
| 2876 | irq_flags); |
| 2877 | if (r < 0) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2878 | dfailprintk(ioc, pr_info(MPT3SAS_FMT |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2879 | "pci_alloc_irq_vectors failed (r=%d) !!!\n", |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2880 | ioc->name, r)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2881 | goto try_ioapic; |
| 2882 | } |
| 2883 | |
| 2884 | ioc->msix_enable = 1; |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2885 | ioc->reply_queue_count = r; |
| 2886 | for (i = 0; i < ioc->reply_queue_count; i++) { |
| 2887 | r = _base_request_irq(ioc, i); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2888 | if (r) { |
| 2889 | _base_free_irq(ioc); |
| 2890 | _base_disable_msix(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2891 | goto try_ioapic; |
| 2892 | } |
| 2893 | } |
| 2894 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2895 | return 0; |
| 2896 | |
| 2897 | /* failback to io_apic interrupt routing */ |
| 2898 | try_ioapic: |
| 2899 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 2900 | ioc->reply_queue_count = 1; |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 2901 | r = pci_alloc_irq_vectors(ioc->pdev, 1, 1, PCI_IRQ_LEGACY); |
| 2902 | if (r < 0) { |
| 2903 | dfailprintk(ioc, pr_info(MPT3SAS_FMT |
| 2904 | "pci_alloc_irq_vector(legacy) failed (r=%d) !!!\n", |
| 2905 | ioc->name, r)); |
| 2906 | } else |
| 2907 | r = _base_request_irq(ioc, 0); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2908 | |
| 2909 | return r; |
| 2910 | } |
| 2911 | |
| 2912 | /** |
Sreekanth Reddy | 580d4e3 | 2015-06-30 12:24:50 +0530 | [diff] [blame] | 2913 | * mpt3sas_base_unmap_resources - free controller resources |
| 2914 | * @ioc: per adapter object |
| 2915 | */ |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 2916 | static void |
Sreekanth Reddy | 580d4e3 | 2015-06-30 12:24:50 +0530 | [diff] [blame] | 2917 | mpt3sas_base_unmap_resources(struct MPT3SAS_ADAPTER *ioc) |
| 2918 | { |
| 2919 | struct pci_dev *pdev = ioc->pdev; |
| 2920 | |
| 2921 | dexitprintk(ioc, printk(MPT3SAS_FMT "%s\n", |
| 2922 | ioc->name, __func__)); |
| 2923 | |
| 2924 | _base_free_irq(ioc); |
| 2925 | _base_disable_msix(ioc); |
| 2926 | |
Suganath Prabu Subramani | 0bb337c | 2016-10-26 13:34:38 +0530 | [diff] [blame] | 2927 | if (ioc->combined_reply_queue) { |
Sreekanth Reddy | 580d4e3 | 2015-06-30 12:24:50 +0530 | [diff] [blame] | 2928 | kfree(ioc->replyPostRegisterIndex); |
Tomas Henzl | 5f985d8 | 2015-12-23 14:21:47 +0100 | [diff] [blame] | 2929 | ioc->replyPostRegisterIndex = NULL; |
| 2930 | } |
Sreekanth Reddy | 580d4e3 | 2015-06-30 12:24:50 +0530 | [diff] [blame] | 2931 | |
| 2932 | if (ioc->chip_phys) { |
| 2933 | iounmap(ioc->chip); |
| 2934 | ioc->chip_phys = 0; |
| 2935 | } |
| 2936 | |
| 2937 | if (pci_is_enabled(pdev)) { |
| 2938 | pci_release_selected_regions(ioc->pdev, ioc->bars); |
| 2939 | pci_disable_pcie_error_reporting(pdev); |
| 2940 | pci_disable_device(pdev); |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2945 | * mpt3sas_base_map_resources - map in controller resources (io/irq/memap) |
| 2946 | * @ioc: per adapter object |
| 2947 | * |
| 2948 | * Returns 0 for success, non-zero for failure. |
| 2949 | */ |
| 2950 | int |
| 2951 | mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc) |
| 2952 | { |
| 2953 | struct pci_dev *pdev = ioc->pdev; |
| 2954 | u32 memap_sz; |
| 2955 | u32 pio_sz; |
| 2956 | int i, r = 0; |
| 2957 | u64 pio_chip = 0; |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 2958 | phys_addr_t chip_phys = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2959 | struct adapter_reply_queue *reply_q; |
| 2960 | |
| 2961 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", |
| 2962 | ioc->name, __func__)); |
| 2963 | |
| 2964 | ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 2965 | if (pci_enable_device_mem(pdev)) { |
| 2966 | pr_warn(MPT3SAS_FMT "pci_enable_device_mem: failed\n", |
| 2967 | ioc->name); |
Joe Lawrence | cf9bd21a | 2013-08-08 16:45:39 -0400 | [diff] [blame] | 2968 | ioc->bars = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2969 | return -ENODEV; |
| 2970 | } |
| 2971 | |
| 2972 | |
| 2973 | if (pci_request_selected_regions(pdev, ioc->bars, |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2974 | ioc->driver_name)) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2975 | pr_warn(MPT3SAS_FMT "pci_request_selected_regions: failed\n", |
| 2976 | ioc->name); |
Joe Lawrence | cf9bd21a | 2013-08-08 16:45:39 -0400 | [diff] [blame] | 2977 | ioc->bars = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2978 | r = -ENODEV; |
| 2979 | goto out_fail; |
| 2980 | } |
| 2981 | |
| 2982 | /* AER (Advanced Error Reporting) hooks */ |
| 2983 | pci_enable_pcie_error_reporting(pdev); |
| 2984 | |
| 2985 | pci_set_master(pdev); |
| 2986 | |
| 2987 | |
| 2988 | if (_base_config_dma_addressing(ioc, pdev) != 0) { |
| 2989 | pr_warn(MPT3SAS_FMT "no suitable DMA mask for %s\n", |
| 2990 | ioc->name, pci_name(pdev)); |
| 2991 | r = -ENODEV; |
| 2992 | goto out_fail; |
| 2993 | } |
| 2994 | |
Sreekanth Reddy | 5aeeb78 | 2015-07-15 10:19:56 +0530 | [diff] [blame] | 2995 | for (i = 0, memap_sz = 0, pio_sz = 0; (i < DEVICE_COUNT_RESOURCE) && |
| 2996 | (!memap_sz || !pio_sz); i++) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2997 | if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { |
| 2998 | if (pio_sz) |
| 2999 | continue; |
| 3000 | pio_chip = (u64)pci_resource_start(pdev, i); |
| 3001 | pio_sz = pci_resource_len(pdev, i); |
| 3002 | } else if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) { |
| 3003 | if (memap_sz) |
| 3004 | continue; |
| 3005 | ioc->chip_phys = pci_resource_start(pdev, i); |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 3006 | chip_phys = ioc->chip_phys; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3007 | memap_sz = pci_resource_len(pdev, i); |
| 3008 | ioc->chip = ioremap(ioc->chip_phys, memap_sz); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3009 | } |
| 3010 | } |
| 3011 | |
Sreekanth Reddy | 5aeeb78 | 2015-07-15 10:19:56 +0530 | [diff] [blame] | 3012 | if (ioc->chip == NULL) { |
| 3013 | pr_err(MPT3SAS_FMT "unable to map adapter memory! " |
| 3014 | " or resource not found\n", ioc->name); |
| 3015 | r = -EINVAL; |
| 3016 | goto out_fail; |
| 3017 | } |
| 3018 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3019 | _base_mask_interrupts(ioc); |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 3020 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 3021 | r = _base_get_ioc_facts(ioc); |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 3022 | if (r) |
| 3023 | goto out_fail; |
| 3024 | |
| 3025 | if (!ioc->rdpq_array_enable_assigned) { |
| 3026 | ioc->rdpq_array_enable = ioc->rdpq_array_capable; |
| 3027 | ioc->rdpq_array_enable_assigned = 1; |
| 3028 | } |
| 3029 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3030 | r = _base_enable_msix(ioc); |
| 3031 | if (r) |
| 3032 | goto out_fail; |
| 3033 | |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 3034 | /* Use the Combined reply queue feature only for SAS3 C0 & higher |
| 3035 | * revision HBAs and also only when reply queue count is greater than 8 |
| 3036 | */ |
Suganath Prabu Subramani | 0bb337c | 2016-10-26 13:34:38 +0530 | [diff] [blame] | 3037 | if (ioc->combined_reply_queue && ioc->reply_queue_count > 8) { |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 3038 | /* Determine the Supplemental Reply Post Host Index Registers |
| 3039 | * Addresse. Supplemental Reply Post Host Index Registers |
| 3040 | * starts at offset MPI25_SUP_REPLY_POST_HOST_INDEX_OFFSET and |
| 3041 | * each register is at offset bytes of |
| 3042 | * MPT3_SUP_REPLY_POST_HOST_INDEX_REG_OFFSET from previous one. |
| 3043 | */ |
| 3044 | ioc->replyPostRegisterIndex = kcalloc( |
Suganath Prabu Subramani | 0bb337c | 2016-10-26 13:34:38 +0530 | [diff] [blame] | 3045 | ioc->combined_reply_index_count, |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 3046 | sizeof(resource_size_t *), GFP_KERNEL); |
| 3047 | if (!ioc->replyPostRegisterIndex) { |
| 3048 | dfailprintk(ioc, printk(MPT3SAS_FMT |
| 3049 | "allocation for reply Post Register Index failed!!!\n", |
| 3050 | ioc->name)); |
| 3051 | r = -ENOMEM; |
| 3052 | goto out_fail; |
| 3053 | } |
| 3054 | |
Suganath Prabu Subramani | 0bb337c | 2016-10-26 13:34:38 +0530 | [diff] [blame] | 3055 | for (i = 0; i < ioc->combined_reply_index_count; i++) { |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 3056 | ioc->replyPostRegisterIndex[i] = (resource_size_t *) |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 3057 | ((u8 __force *)&ioc->chip->Doorbell + |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 3058 | MPI25_SUP_REPLY_POST_HOST_INDEX_OFFSET + |
| 3059 | (i * MPT3_SUP_REPLY_POST_HOST_INDEX_REG_OFFSET)); |
| 3060 | } |
| 3061 | } else |
Suganath Prabu Subramani | 0bb337c | 2016-10-26 13:34:38 +0530 | [diff] [blame] | 3062 | ioc->combined_reply_queue = 0; |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 3063 | |
Greg Edwards | ce7c6c9 | 2016-07-30 10:06:26 -0600 | [diff] [blame] | 3064 | if (ioc->is_warpdrive) { |
| 3065 | ioc->reply_post_host_index[0] = (resource_size_t __iomem *) |
| 3066 | &ioc->chip->ReplyPostHostIndex; |
| 3067 | |
| 3068 | for (i = 1; i < ioc->cpu_msix_table_sz; i++) |
| 3069 | ioc->reply_post_host_index[i] = |
| 3070 | (resource_size_t __iomem *) |
| 3071 | ((u8 __iomem *)&ioc->chip->Doorbell + (0x4000 + ((i - 1) |
| 3072 | * 4))); |
| 3073 | } |
| 3074 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3075 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) |
| 3076 | pr_info(MPT3SAS_FMT "%s: IRQ %d\n", |
| 3077 | reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" : |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 3078 | "IO-APIC enabled"), |
| 3079 | pci_irq_vector(ioc->pdev, reply_q->msix_index)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3080 | |
Arnd Bergmann | 6f9e09f | 2018-03-01 14:07:07 +0100 | [diff] [blame] | 3081 | pr_info(MPT3SAS_FMT "iomem(%pap), mapped(0x%p), size(%d)\n", |
| 3082 | ioc->name, &chip_phys, ioc->chip, memap_sz); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3083 | pr_info(MPT3SAS_FMT "ioport(0x%016llx), size(%d)\n", |
| 3084 | ioc->name, (unsigned long long)pio_chip, pio_sz); |
| 3085 | |
| 3086 | /* Save PCI configuration state for recovery from PCI AER/EEH errors */ |
| 3087 | pci_save_state(pdev); |
| 3088 | return 0; |
| 3089 | |
| 3090 | out_fail: |
Sreekanth Reddy | 580d4e3 | 2015-06-30 12:24:50 +0530 | [diff] [blame] | 3091 | mpt3sas_base_unmap_resources(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3092 | return r; |
| 3093 | } |
| 3094 | |
| 3095 | /** |
| 3096 | * mpt3sas_base_get_msg_frame - obtain request mf pointer |
| 3097 | * @ioc: per adapter object |
| 3098 | * @smid: system request message index(smid zero is invalid) |
| 3099 | * |
| 3100 | * Returns virt pointer to message frame. |
| 3101 | */ |
| 3102 | void * |
| 3103 | mpt3sas_base_get_msg_frame(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 3104 | { |
| 3105 | return (void *)(ioc->request + (smid * ioc->request_sz)); |
| 3106 | } |
| 3107 | |
| 3108 | /** |
| 3109 | * mpt3sas_base_get_sense_buffer - obtain a sense buffer virt addr |
| 3110 | * @ioc: per adapter object |
| 3111 | * @smid: system request message index |
| 3112 | * |
| 3113 | * Returns virt pointer to sense buffer. |
| 3114 | */ |
| 3115 | void * |
| 3116 | mpt3sas_base_get_sense_buffer(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 3117 | { |
| 3118 | return (void *)(ioc->sense + ((smid - 1) * SCSI_SENSE_BUFFERSIZE)); |
| 3119 | } |
| 3120 | |
| 3121 | /** |
| 3122 | * mpt3sas_base_get_sense_buffer_dma - obtain a sense buffer dma addr |
| 3123 | * @ioc: per adapter object |
| 3124 | * @smid: system request message index |
| 3125 | * |
| 3126 | * Returns phys pointer to the low 32bit address of the sense buffer. |
| 3127 | */ |
| 3128 | __le32 |
| 3129 | mpt3sas_base_get_sense_buffer_dma(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 3130 | { |
| 3131 | return cpu_to_le32(ioc->sense_dma + ((smid - 1) * |
| 3132 | SCSI_SENSE_BUFFERSIZE)); |
| 3133 | } |
| 3134 | |
| 3135 | /** |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 3136 | * mpt3sas_base_get_pcie_sgl - obtain a PCIe SGL virt addr |
| 3137 | * @ioc: per adapter object |
| 3138 | * @smid: system request message index |
| 3139 | * |
| 3140 | * Returns virt pointer to a PCIe SGL. |
| 3141 | */ |
| 3142 | void * |
| 3143 | mpt3sas_base_get_pcie_sgl(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 3144 | { |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 3145 | return (void *)(ioc->pcie_sg_lookup[smid - 1].pcie_sgl); |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | /** |
| 3149 | * mpt3sas_base_get_pcie_sgl_dma - obtain a PCIe SGL dma addr |
| 3150 | * @ioc: per adapter object |
| 3151 | * @smid: system request message index |
| 3152 | * |
| 3153 | * Returns phys pointer to the address of the PCIe buffer. |
| 3154 | */ |
Arnd Bergmann | d8335ae | 2017-11-06 14:35:16 +0100 | [diff] [blame] | 3155 | dma_addr_t |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 3156 | mpt3sas_base_get_pcie_sgl_dma(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 3157 | { |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 3158 | return ioc->pcie_sg_lookup[smid - 1].pcie_sgl_dma; |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3162 | * mpt3sas_base_get_reply_virt_addr - obtain reply frames virt address |
| 3163 | * @ioc: per adapter object |
| 3164 | * @phys_addr: lower 32 physical addr of the reply |
| 3165 | * |
| 3166 | * Converts 32bit lower physical addr into a virt address. |
| 3167 | */ |
| 3168 | void * |
| 3169 | mpt3sas_base_get_reply_virt_addr(struct MPT3SAS_ADAPTER *ioc, u32 phys_addr) |
| 3170 | { |
| 3171 | if (!phys_addr) |
| 3172 | return NULL; |
| 3173 | return ioc->reply + (phys_addr - (u32)ioc->reply_dma); |
| 3174 | } |
| 3175 | |
Suganath prabu Subramani | 03d1fb3 | 2016-01-28 12:07:06 +0530 | [diff] [blame] | 3176 | static inline u8 |
| 3177 | _base_get_msix_index(struct MPT3SAS_ADAPTER *ioc) |
| 3178 | { |
| 3179 | return ioc->cpu_msix_table[raw_smp_processor_id()]; |
| 3180 | } |
| 3181 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3182 | /** |
| 3183 | * mpt3sas_base_get_smid - obtain a free smid from internal queue |
| 3184 | * @ioc: per adapter object |
| 3185 | * @cb_idx: callback index |
| 3186 | * |
| 3187 | * Returns smid (zero is invalid) |
| 3188 | */ |
| 3189 | u16 |
| 3190 | mpt3sas_base_get_smid(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx) |
| 3191 | { |
| 3192 | unsigned long flags; |
| 3193 | struct request_tracker *request; |
| 3194 | u16 smid; |
| 3195 | |
| 3196 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 3197 | if (list_empty(&ioc->internal_free_list)) { |
| 3198 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 3199 | pr_err(MPT3SAS_FMT "%s: smid not available\n", |
| 3200 | ioc->name, __func__); |
| 3201 | return 0; |
| 3202 | } |
| 3203 | |
| 3204 | request = list_entry(ioc->internal_free_list.next, |
| 3205 | struct request_tracker, tracker_list); |
| 3206 | request->cb_idx = cb_idx; |
| 3207 | smid = request->smid; |
| 3208 | list_del(&request->tracker_list); |
| 3209 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 3210 | return smid; |
| 3211 | } |
| 3212 | |
| 3213 | /** |
| 3214 | * mpt3sas_base_get_smid_scsiio - obtain a free smid from scsiio queue |
| 3215 | * @ioc: per adapter object |
| 3216 | * @cb_idx: callback index |
| 3217 | * @scmd: pointer to scsi command object |
| 3218 | * |
| 3219 | * Returns smid (zero is invalid) |
| 3220 | */ |
| 3221 | u16 |
| 3222 | mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx, |
| 3223 | struct scsi_cmnd *scmd) |
| 3224 | { |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 3225 | struct scsiio_tracker *request = scsi_cmd_priv(scmd); |
| 3226 | unsigned int tag = scmd->request->tag; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3227 | u16 smid; |
| 3228 | |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 3229 | smid = tag + 1; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3230 | request->cb_idx = cb_idx; |
Suganath prabu Subramani | 03d1fb3 | 2016-01-28 12:07:06 +0530 | [diff] [blame] | 3231 | request->msix_io = _base_get_msix_index(ioc); |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 3232 | request->smid = smid; |
| 3233 | INIT_LIST_HEAD(&request->chain_list); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3234 | return smid; |
| 3235 | } |
| 3236 | |
| 3237 | /** |
| 3238 | * mpt3sas_base_get_smid_hpr - obtain a free smid from hi-priority queue |
| 3239 | * @ioc: per adapter object |
| 3240 | * @cb_idx: callback index |
| 3241 | * |
| 3242 | * Returns smid (zero is invalid) |
| 3243 | */ |
| 3244 | u16 |
| 3245 | mpt3sas_base_get_smid_hpr(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx) |
| 3246 | { |
| 3247 | unsigned long flags; |
| 3248 | struct request_tracker *request; |
| 3249 | u16 smid; |
| 3250 | |
| 3251 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 3252 | if (list_empty(&ioc->hpr_free_list)) { |
| 3253 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 3254 | return 0; |
| 3255 | } |
| 3256 | |
| 3257 | request = list_entry(ioc->hpr_free_list.next, |
| 3258 | struct request_tracker, tracker_list); |
| 3259 | request->cb_idx = cb_idx; |
| 3260 | smid = request->smid; |
| 3261 | list_del(&request->tracker_list); |
| 3262 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 3263 | return smid; |
| 3264 | } |
| 3265 | |
Hannes Reinecke | 6a2d461 | 2018-01-04 04:57:03 -0800 | [diff] [blame] | 3266 | static void |
| 3267 | _base_recovery_check(struct MPT3SAS_ADAPTER *ioc) |
| 3268 | { |
| 3269 | /* |
| 3270 | * See _wait_for_commands_to_complete() call with regards to this code. |
| 3271 | */ |
| 3272 | if (ioc->shost_recovery && ioc->pending_io_count) { |
Hannes Reinecke | 272e253 | 2018-01-04 04:57:10 -0800 | [diff] [blame] | 3273 | ioc->pending_io_count = atomic_read(&ioc->shost->host_busy); |
| 3274 | if (ioc->pending_io_count == 0) |
Hannes Reinecke | 6a2d461 | 2018-01-04 04:57:03 -0800 | [diff] [blame] | 3275 | wake_up(&ioc->reset_wq); |
Hannes Reinecke | 6a2d461 | 2018-01-04 04:57:03 -0800 | [diff] [blame] | 3276 | } |
| 3277 | } |
| 3278 | |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 3279 | void mpt3sas_base_clear_st(struct MPT3SAS_ADAPTER *ioc, |
| 3280 | struct scsiio_tracker *st) |
| 3281 | { |
| 3282 | if (WARN_ON(st->smid == 0)) |
| 3283 | return; |
| 3284 | st->cb_idx = 0xFF; |
| 3285 | st->direct_io = 0; |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 3286 | atomic_set(&ioc->chain_lookup[st->smid - 1].chain_offset, 0); |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 3287 | } |
| 3288 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3289 | /** |
| 3290 | * mpt3sas_base_free_smid - put smid back on free_list |
| 3291 | * @ioc: per adapter object |
| 3292 | * @smid: system request message index |
| 3293 | * |
| 3294 | * Return nothing. |
| 3295 | */ |
| 3296 | void |
| 3297 | mpt3sas_base_free_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 3298 | { |
| 3299 | unsigned long flags; |
| 3300 | int i; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3301 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3302 | if (smid < ioc->hi_priority_smid) { |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 3303 | struct scsiio_tracker *st; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3304 | |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 3305 | st = _get_st_from_smid(ioc, smid); |
| 3306 | if (!st) { |
| 3307 | _base_recovery_check(ioc); |
| 3308 | return; |
| 3309 | } |
| 3310 | mpt3sas_base_clear_st(ioc, st); |
Hannes Reinecke | 6a2d461 | 2018-01-04 04:57:03 -0800 | [diff] [blame] | 3311 | _base_recovery_check(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3312 | return; |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 3313 | } |
| 3314 | |
| 3315 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 3316 | if (smid < ioc->internal_smid) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3317 | /* hi-priority */ |
| 3318 | i = smid - ioc->hi_priority_smid; |
| 3319 | ioc->hpr_lookup[i].cb_idx = 0xFF; |
| 3320 | list_add(&ioc->hpr_lookup[i].tracker_list, &ioc->hpr_free_list); |
| 3321 | } else if (smid <= ioc->hba_queue_depth) { |
| 3322 | /* internal queue */ |
| 3323 | i = smid - ioc->internal_smid; |
| 3324 | ioc->internal_lookup[i].cb_idx = 0xFF; |
| 3325 | list_add(&ioc->internal_lookup[i].tracker_list, |
| 3326 | &ioc->internal_free_list); |
| 3327 | } |
| 3328 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 3329 | } |
| 3330 | |
| 3331 | /** |
Suganath Prabu Subramani | e574743 | 2018-02-07 02:51:49 -0800 | [diff] [blame] | 3332 | * _base_mpi_ep_writeq - 32 bit write to MMIO |
| 3333 | * @b: data payload |
| 3334 | * @addr: address in MMIO space |
| 3335 | * @writeq_lock: spin lock |
| 3336 | * |
| 3337 | * This special handling for MPI EP to take care of 32 bit |
| 3338 | * environment where its not quarenteed to send the entire word |
| 3339 | * in one transfer. |
| 3340 | */ |
| 3341 | static inline void |
| 3342 | _base_mpi_ep_writeq(__u64 b, volatile void __iomem *addr, |
| 3343 | spinlock_t *writeq_lock) |
| 3344 | { |
| 3345 | unsigned long flags; |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 3346 | __u64 data_out = b; |
Suganath Prabu Subramani | e574743 | 2018-02-07 02:51:49 -0800 | [diff] [blame] | 3347 | |
| 3348 | spin_lock_irqsave(writeq_lock, flags); |
| 3349 | writel((u32)(data_out), addr); |
| 3350 | writel((u32)(data_out >> 32), (addr + 4)); |
| 3351 | spin_unlock_irqrestore(writeq_lock, flags); |
| 3352 | } |
| 3353 | |
| 3354 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3355 | * _base_writeq - 64 bit write to MMIO |
| 3356 | * @ioc: per adapter object |
| 3357 | * @b: data payload |
| 3358 | * @addr: address in MMIO space |
| 3359 | * @writeq_lock: spin lock |
| 3360 | * |
| 3361 | * Glue for handling an atomic 64 bit word to MMIO. This special handling takes |
| 3362 | * care of 32 bit environment where its not quarenteed to send the entire word |
| 3363 | * in one transfer. |
| 3364 | */ |
| 3365 | #if defined(writeq) && defined(CONFIG_64BIT) |
| 3366 | static inline void |
| 3367 | _base_writeq(__u64 b, volatile void __iomem *addr, spinlock_t *writeq_lock) |
| 3368 | { |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 3369 | writeq(b, addr); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3370 | } |
| 3371 | #else |
| 3372 | static inline void |
| 3373 | _base_writeq(__u64 b, volatile void __iomem *addr, spinlock_t *writeq_lock) |
| 3374 | { |
Suganath Prabu Subramani | e574743 | 2018-02-07 02:51:49 -0800 | [diff] [blame] | 3375 | _base_mpi_ep_writeq(b, addr, writeq_lock); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3376 | } |
| 3377 | #endif |
| 3378 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3379 | /** |
Suganath Prabu Subramani | e574743 | 2018-02-07 02:51:49 -0800 | [diff] [blame] | 3380 | * _base_put_smid_mpi_ep_scsi_io - send SCSI_IO request to firmware |
| 3381 | * @ioc: per adapter object |
| 3382 | * @smid: system request message index |
| 3383 | * @handle: device handle |
| 3384 | * |
| 3385 | * Return nothing. |
| 3386 | */ |
| 3387 | static void |
| 3388 | _base_put_smid_mpi_ep_scsi_io(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 handle) |
| 3389 | { |
| 3390 | Mpi2RequestDescriptorUnion_t descriptor; |
| 3391 | u64 *request = (u64 *)&descriptor; |
| 3392 | void *mpi_req_iomem; |
| 3393 | __le32 *mfp = (__le32 *)mpt3sas_base_get_msg_frame(ioc, smid); |
| 3394 | |
| 3395 | _clone_sg_entries(ioc, (void *) mfp, smid); |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 3396 | mpi_req_iomem = (void __force *)ioc->chip + |
Suganath Prabu Subramani | e574743 | 2018-02-07 02:51:49 -0800 | [diff] [blame] | 3397 | MPI_FRAME_START_OFFSET + (smid * ioc->request_sz); |
| 3398 | _base_clone_mpi_to_sys_mem(mpi_req_iomem, (void *)mfp, |
| 3399 | ioc->request_sz); |
| 3400 | descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO; |
| 3401 | descriptor.SCSIIO.MSIxIndex = _base_get_msix_index(ioc); |
| 3402 | descriptor.SCSIIO.SMID = cpu_to_le16(smid); |
| 3403 | descriptor.SCSIIO.DevHandle = cpu_to_le16(handle); |
| 3404 | descriptor.SCSIIO.LMID = 0; |
| 3405 | _base_mpi_ep_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 3406 | &ioc->scsi_lookup_lock); |
| 3407 | } |
| 3408 | |
| 3409 | /** |
Suganath Prabu Subramani | 81c16f8 | 2016-10-26 13:34:40 +0530 | [diff] [blame] | 3410 | * _base_put_smid_scsi_io - send SCSI_IO request to firmware |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3411 | * @ioc: per adapter object |
| 3412 | * @smid: system request message index |
| 3413 | * @handle: device handle |
| 3414 | * |
| 3415 | * Return nothing. |
| 3416 | */ |
Suganath Prabu Subramani | 81c16f8 | 2016-10-26 13:34:40 +0530 | [diff] [blame] | 3417 | static void |
| 3418 | _base_put_smid_scsi_io(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 handle) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3419 | { |
| 3420 | Mpi2RequestDescriptorUnion_t descriptor; |
| 3421 | u64 *request = (u64 *)&descriptor; |
| 3422 | |
| 3423 | |
| 3424 | descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO; |
| 3425 | descriptor.SCSIIO.MSIxIndex = _base_get_msix_index(ioc); |
| 3426 | descriptor.SCSIIO.SMID = cpu_to_le16(smid); |
| 3427 | descriptor.SCSIIO.DevHandle = cpu_to_le16(handle); |
| 3428 | descriptor.SCSIIO.LMID = 0; |
| 3429 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 3430 | &ioc->scsi_lookup_lock); |
| 3431 | } |
| 3432 | |
| 3433 | /** |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 3434 | * mpt3sas_base_put_smid_fast_path - send fast path request to firmware |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3435 | * @ioc: per adapter object |
| 3436 | * @smid: system request message index |
| 3437 | * @handle: device handle |
| 3438 | * |
| 3439 | * Return nothing. |
| 3440 | */ |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 3441 | void |
| 3442 | mpt3sas_base_put_smid_fast_path(struct MPT3SAS_ADAPTER *ioc, u16 smid, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3443 | u16 handle) |
| 3444 | { |
| 3445 | Mpi2RequestDescriptorUnion_t descriptor; |
| 3446 | u64 *request = (u64 *)&descriptor; |
| 3447 | |
| 3448 | descriptor.SCSIIO.RequestFlags = |
| 3449 | MPI25_REQ_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO; |
| 3450 | descriptor.SCSIIO.MSIxIndex = _base_get_msix_index(ioc); |
| 3451 | descriptor.SCSIIO.SMID = cpu_to_le16(smid); |
| 3452 | descriptor.SCSIIO.DevHandle = cpu_to_le16(handle); |
| 3453 | descriptor.SCSIIO.LMID = 0; |
| 3454 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 3455 | &ioc->scsi_lookup_lock); |
| 3456 | } |
| 3457 | |
| 3458 | /** |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 3459 | * mpt3sas_base_put_smid_hi_priority - send Task Management request to firmware |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3460 | * @ioc: per adapter object |
| 3461 | * @smid: system request message index |
Suganath prabu Subramani | 03d1fb3 | 2016-01-28 12:07:06 +0530 | [diff] [blame] | 3462 | * @msix_task: msix_task will be same as msix of IO incase of task abort else 0. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3463 | * Return nothing. |
| 3464 | */ |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 3465 | void |
| 3466 | mpt3sas_base_put_smid_hi_priority(struct MPT3SAS_ADAPTER *ioc, u16 smid, |
Suganath prabu Subramani | 03d1fb3 | 2016-01-28 12:07:06 +0530 | [diff] [blame] | 3467 | u16 msix_task) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3468 | { |
| 3469 | Mpi2RequestDescriptorUnion_t descriptor; |
Suganath Prabu Subramani | e574743 | 2018-02-07 02:51:49 -0800 | [diff] [blame] | 3470 | void *mpi_req_iomem; |
| 3471 | u64 *request; |
| 3472 | |
| 3473 | if (ioc->is_mcpu_endpoint) { |
| 3474 | MPI2RequestHeader_t *request_hdr; |
| 3475 | |
| 3476 | __le32 *mfp = (__le32 *)mpt3sas_base_get_msg_frame(ioc, smid); |
| 3477 | |
| 3478 | request_hdr = (MPI2RequestHeader_t *)mfp; |
| 3479 | /* TBD 256 is offset within sys register. */ |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 3480 | mpi_req_iomem = (void __force *)ioc->chip |
| 3481 | + MPI_FRAME_START_OFFSET |
Suganath Prabu Subramani | e574743 | 2018-02-07 02:51:49 -0800 | [diff] [blame] | 3482 | + (smid * ioc->request_sz); |
| 3483 | _base_clone_mpi_to_sys_mem(mpi_req_iomem, (void *)mfp, |
| 3484 | ioc->request_sz); |
| 3485 | } |
| 3486 | |
| 3487 | request = (u64 *)&descriptor; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3488 | |
| 3489 | descriptor.HighPriority.RequestFlags = |
| 3490 | MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY; |
Suganath prabu Subramani | 03d1fb3 | 2016-01-28 12:07:06 +0530 | [diff] [blame] | 3491 | descriptor.HighPriority.MSIxIndex = msix_task; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3492 | descriptor.HighPriority.SMID = cpu_to_le16(smid); |
| 3493 | descriptor.HighPriority.LMID = 0; |
| 3494 | descriptor.HighPriority.Reserved1 = 0; |
Suganath Prabu Subramani | e574743 | 2018-02-07 02:51:49 -0800 | [diff] [blame] | 3495 | if (ioc->is_mcpu_endpoint) |
| 3496 | _base_mpi_ep_writeq(*request, |
| 3497 | &ioc->chip->RequestDescriptorPostLow, |
| 3498 | &ioc->scsi_lookup_lock); |
| 3499 | else |
| 3500 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 3501 | &ioc->scsi_lookup_lock); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | /** |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 3505 | * mpt3sas_base_put_smid_nvme_encap - send NVMe encapsulated request to |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 3506 | * firmware |
| 3507 | * @ioc: per adapter object |
| 3508 | * @smid: system request message index |
| 3509 | * |
| 3510 | * Return nothing. |
| 3511 | */ |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 3512 | void |
| 3513 | mpt3sas_base_put_smid_nvme_encap(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 3514 | { |
| 3515 | Mpi2RequestDescriptorUnion_t descriptor; |
| 3516 | u64 *request = (u64 *)&descriptor; |
| 3517 | |
| 3518 | descriptor.Default.RequestFlags = |
| 3519 | MPI26_REQ_DESCRIPT_FLAGS_PCIE_ENCAPSULATED; |
| 3520 | descriptor.Default.MSIxIndex = _base_get_msix_index(ioc); |
| 3521 | descriptor.Default.SMID = cpu_to_le16(smid); |
| 3522 | descriptor.Default.LMID = 0; |
| 3523 | descriptor.Default.DescriptorTypeDependent = 0; |
| 3524 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 3525 | &ioc->scsi_lookup_lock); |
| 3526 | } |
| 3527 | |
| 3528 | /** |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 3529 | * mpt3sas_base_put_smid_default - Default, primarily used for config pages |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3530 | * @ioc: per adapter object |
| 3531 | * @smid: system request message index |
| 3532 | * |
| 3533 | * Return nothing. |
| 3534 | */ |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 3535 | void |
| 3536 | mpt3sas_base_put_smid_default(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3537 | { |
| 3538 | Mpi2RequestDescriptorUnion_t descriptor; |
Suganath Prabu Subramani | e574743 | 2018-02-07 02:51:49 -0800 | [diff] [blame] | 3539 | void *mpi_req_iomem; |
| 3540 | u64 *request; |
| 3541 | MPI2RequestHeader_t *request_hdr; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3542 | |
Suganath Prabu Subramani | e574743 | 2018-02-07 02:51:49 -0800 | [diff] [blame] | 3543 | if (ioc->is_mcpu_endpoint) { |
| 3544 | __le32 *mfp = (__le32 *)mpt3sas_base_get_msg_frame(ioc, smid); |
| 3545 | |
| 3546 | request_hdr = (MPI2RequestHeader_t *)mfp; |
| 3547 | |
| 3548 | _clone_sg_entries(ioc, (void *) mfp, smid); |
| 3549 | /* TBD 256 is offset within sys register */ |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 3550 | mpi_req_iomem = (void __force *)ioc->chip + |
Suganath Prabu Subramani | e574743 | 2018-02-07 02:51:49 -0800 | [diff] [blame] | 3551 | MPI_FRAME_START_OFFSET + (smid * ioc->request_sz); |
| 3552 | _base_clone_mpi_to_sys_mem(mpi_req_iomem, (void *)mfp, |
| 3553 | ioc->request_sz); |
| 3554 | } |
| 3555 | request = (u64 *)&descriptor; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3556 | descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE; |
| 3557 | descriptor.Default.MSIxIndex = _base_get_msix_index(ioc); |
| 3558 | descriptor.Default.SMID = cpu_to_le16(smid); |
| 3559 | descriptor.Default.LMID = 0; |
| 3560 | descriptor.Default.DescriptorTypeDependent = 0; |
Suganath Prabu Subramani | e574743 | 2018-02-07 02:51:49 -0800 | [diff] [blame] | 3561 | if (ioc->is_mcpu_endpoint) |
| 3562 | _base_mpi_ep_writeq(*request, |
| 3563 | &ioc->chip->RequestDescriptorPostLow, |
| 3564 | &ioc->scsi_lookup_lock); |
| 3565 | else |
| 3566 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 3567 | &ioc->scsi_lookup_lock); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3568 | } |
| 3569 | |
Sreekanth Reddy | 1117b31 | 2014-09-12 15:35:30 +0530 | [diff] [blame] | 3570 | /** |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 3571 | * _base_display_OEMs_branding - Display branding string |
Sreekanth Reddy | 1117b31 | 2014-09-12 15:35:30 +0530 | [diff] [blame] | 3572 | * @ioc: per adapter object |
| 3573 | * |
| 3574 | * Return nothing. |
| 3575 | */ |
| 3576 | static void |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 3577 | _base_display_OEMs_branding(struct MPT3SAS_ADAPTER *ioc) |
Sreekanth Reddy | 1117b31 | 2014-09-12 15:35:30 +0530 | [diff] [blame] | 3578 | { |
| 3579 | if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL) |
| 3580 | return; |
| 3581 | |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 3582 | switch (ioc->pdev->subsystem_vendor) { |
| 3583 | case PCI_VENDOR_ID_INTEL: |
| 3584 | switch (ioc->pdev->device) { |
| 3585 | case MPI2_MFGPAGE_DEVID_SAS2008: |
| 3586 | switch (ioc->pdev->subsystem_device) { |
| 3587 | case MPT2SAS_INTEL_RMS2LL080_SSDID: |
| 3588 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3589 | MPT2SAS_INTEL_RMS2LL080_BRANDING); |
| 3590 | break; |
| 3591 | case MPT2SAS_INTEL_RMS2LL040_SSDID: |
| 3592 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3593 | MPT2SAS_INTEL_RMS2LL040_BRANDING); |
| 3594 | break; |
| 3595 | case MPT2SAS_INTEL_SSD910_SSDID: |
| 3596 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3597 | MPT2SAS_INTEL_SSD910_BRANDING); |
| 3598 | break; |
| 3599 | default: |
| 3600 | pr_info(MPT3SAS_FMT |
| 3601 | "Intel(R) Controller: Subsystem ID: 0x%X\n", |
| 3602 | ioc->name, ioc->pdev->subsystem_device); |
| 3603 | break; |
| 3604 | } |
| 3605 | case MPI2_MFGPAGE_DEVID_SAS2308_2: |
| 3606 | switch (ioc->pdev->subsystem_device) { |
| 3607 | case MPT2SAS_INTEL_RS25GB008_SSDID: |
| 3608 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3609 | MPT2SAS_INTEL_RS25GB008_BRANDING); |
| 3610 | break; |
| 3611 | case MPT2SAS_INTEL_RMS25JB080_SSDID: |
| 3612 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3613 | MPT2SAS_INTEL_RMS25JB080_BRANDING); |
| 3614 | break; |
| 3615 | case MPT2SAS_INTEL_RMS25JB040_SSDID: |
| 3616 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3617 | MPT2SAS_INTEL_RMS25JB040_BRANDING); |
| 3618 | break; |
| 3619 | case MPT2SAS_INTEL_RMS25KB080_SSDID: |
| 3620 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3621 | MPT2SAS_INTEL_RMS25KB080_BRANDING); |
| 3622 | break; |
| 3623 | case MPT2SAS_INTEL_RMS25KB040_SSDID: |
| 3624 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3625 | MPT2SAS_INTEL_RMS25KB040_BRANDING); |
| 3626 | break; |
| 3627 | case MPT2SAS_INTEL_RMS25LB040_SSDID: |
| 3628 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3629 | MPT2SAS_INTEL_RMS25LB040_BRANDING); |
| 3630 | break; |
| 3631 | case MPT2SAS_INTEL_RMS25LB080_SSDID: |
| 3632 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3633 | MPT2SAS_INTEL_RMS25LB080_BRANDING); |
| 3634 | break; |
| 3635 | default: |
| 3636 | pr_info(MPT3SAS_FMT |
| 3637 | "Intel(R) Controller: Subsystem ID: 0x%X\n", |
| 3638 | ioc->name, ioc->pdev->subsystem_device); |
| 3639 | break; |
| 3640 | } |
| 3641 | case MPI25_MFGPAGE_DEVID_SAS3008: |
| 3642 | switch (ioc->pdev->subsystem_device) { |
| 3643 | case MPT3SAS_INTEL_RMS3JC080_SSDID: |
| 3644 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3645 | MPT3SAS_INTEL_RMS3JC080_BRANDING); |
| 3646 | break; |
Sreekanth Reddy | 1117b31 | 2014-09-12 15:35:30 +0530 | [diff] [blame] | 3647 | |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 3648 | case MPT3SAS_INTEL_RS3GC008_SSDID: |
| 3649 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3650 | MPT3SAS_INTEL_RS3GC008_BRANDING); |
| 3651 | break; |
| 3652 | case MPT3SAS_INTEL_RS3FC044_SSDID: |
| 3653 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3654 | MPT3SAS_INTEL_RS3FC044_BRANDING); |
| 3655 | break; |
| 3656 | case MPT3SAS_INTEL_RS3UC080_SSDID: |
| 3657 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3658 | MPT3SAS_INTEL_RS3UC080_BRANDING); |
| 3659 | break; |
| 3660 | default: |
| 3661 | pr_info(MPT3SAS_FMT |
| 3662 | "Intel(R) Controller: Subsystem ID: 0x%X\n", |
| 3663 | ioc->name, ioc->pdev->subsystem_device); |
| 3664 | break; |
| 3665 | } |
Sreekanth Reddy | 1117b31 | 2014-09-12 15:35:30 +0530 | [diff] [blame] | 3666 | break; |
| 3667 | default: |
| 3668 | pr_info(MPT3SAS_FMT |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 3669 | "Intel(R) Controller: Subsystem ID: 0x%X\n", |
Sreekanth Reddy | d8eb4a4 | 2015-06-30 12:25:02 +0530 | [diff] [blame] | 3670 | ioc->name, ioc->pdev->subsystem_device); |
| 3671 | break; |
| 3672 | } |
| 3673 | break; |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 3674 | case PCI_VENDOR_ID_DELL: |
| 3675 | switch (ioc->pdev->device) { |
| 3676 | case MPI2_MFGPAGE_DEVID_SAS2008: |
| 3677 | switch (ioc->pdev->subsystem_device) { |
| 3678 | case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID: |
| 3679 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3680 | MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING); |
| 3681 | break; |
| 3682 | case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID: |
| 3683 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3684 | MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING); |
| 3685 | break; |
| 3686 | case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID: |
| 3687 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3688 | MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING); |
| 3689 | break; |
| 3690 | case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID: |
| 3691 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3692 | MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING); |
| 3693 | break; |
| 3694 | case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID: |
| 3695 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3696 | MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING); |
| 3697 | break; |
| 3698 | case MPT2SAS_DELL_PERC_H200_SSDID: |
| 3699 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3700 | MPT2SAS_DELL_PERC_H200_BRANDING); |
| 3701 | break; |
| 3702 | case MPT2SAS_DELL_6GBPS_SAS_SSDID: |
| 3703 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3704 | MPT2SAS_DELL_6GBPS_SAS_BRANDING); |
| 3705 | break; |
| 3706 | default: |
| 3707 | pr_info(MPT3SAS_FMT |
| 3708 | "Dell 6Gbps HBA: Subsystem ID: 0x%X\n", |
| 3709 | ioc->name, ioc->pdev->subsystem_device); |
| 3710 | break; |
| 3711 | } |
| 3712 | break; |
| 3713 | case MPI25_MFGPAGE_DEVID_SAS3008: |
| 3714 | switch (ioc->pdev->subsystem_device) { |
| 3715 | case MPT3SAS_DELL_12G_HBA_SSDID: |
| 3716 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3717 | MPT3SAS_DELL_12G_HBA_BRANDING); |
| 3718 | break; |
| 3719 | default: |
| 3720 | pr_info(MPT3SAS_FMT |
| 3721 | "Dell 12Gbps HBA: Subsystem ID: 0x%X\n", |
| 3722 | ioc->name, ioc->pdev->subsystem_device); |
| 3723 | break; |
| 3724 | } |
| 3725 | break; |
| 3726 | default: |
| 3727 | pr_info(MPT3SAS_FMT |
| 3728 | "Dell HBA: Subsystem ID: 0x%X\n", ioc->name, |
| 3729 | ioc->pdev->subsystem_device); |
| 3730 | break; |
| 3731 | } |
| 3732 | break; |
| 3733 | case PCI_VENDOR_ID_CISCO: |
| 3734 | switch (ioc->pdev->device) { |
| 3735 | case MPI25_MFGPAGE_DEVID_SAS3008: |
| 3736 | switch (ioc->pdev->subsystem_device) { |
| 3737 | case MPT3SAS_CISCO_12G_8E_HBA_SSDID: |
| 3738 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3739 | MPT3SAS_CISCO_12G_8E_HBA_BRANDING); |
| 3740 | break; |
| 3741 | case MPT3SAS_CISCO_12G_8I_HBA_SSDID: |
| 3742 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3743 | MPT3SAS_CISCO_12G_8I_HBA_BRANDING); |
| 3744 | break; |
| 3745 | case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID: |
| 3746 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3747 | MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING); |
| 3748 | break; |
| 3749 | default: |
| 3750 | pr_info(MPT3SAS_FMT |
| 3751 | "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n", |
| 3752 | ioc->name, ioc->pdev->subsystem_device); |
| 3753 | break; |
| 3754 | } |
| 3755 | break; |
| 3756 | case MPI25_MFGPAGE_DEVID_SAS3108_1: |
| 3757 | switch (ioc->pdev->subsystem_device) { |
| 3758 | case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID: |
| 3759 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3760 | MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING); |
| 3761 | break; |
| 3762 | case MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_SSDID: |
| 3763 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3764 | MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_BRANDING |
| 3765 | ); |
| 3766 | break; |
| 3767 | default: |
| 3768 | pr_info(MPT3SAS_FMT |
| 3769 | "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n", |
| 3770 | ioc->name, ioc->pdev->subsystem_device); |
| 3771 | break; |
| 3772 | } |
| 3773 | break; |
| 3774 | default: |
| 3775 | pr_info(MPT3SAS_FMT |
| 3776 | "Cisco SAS HBA: Subsystem ID: 0x%X\n", |
| 3777 | ioc->name, ioc->pdev->subsystem_device); |
| 3778 | break; |
| 3779 | } |
| 3780 | break; |
| 3781 | case MPT2SAS_HP_3PAR_SSVID: |
| 3782 | switch (ioc->pdev->device) { |
| 3783 | case MPI2_MFGPAGE_DEVID_SAS2004: |
| 3784 | switch (ioc->pdev->subsystem_device) { |
| 3785 | case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID: |
| 3786 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3787 | MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING); |
| 3788 | break; |
| 3789 | default: |
| 3790 | pr_info(MPT3SAS_FMT |
| 3791 | "HP 6Gbps SAS HBA: Subsystem ID: 0x%X\n", |
| 3792 | ioc->name, ioc->pdev->subsystem_device); |
| 3793 | break; |
| 3794 | } |
| 3795 | case MPI2_MFGPAGE_DEVID_SAS2308_2: |
| 3796 | switch (ioc->pdev->subsystem_device) { |
| 3797 | case MPT2SAS_HP_2_4_INTERNAL_SSDID: |
| 3798 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3799 | MPT2SAS_HP_2_4_INTERNAL_BRANDING); |
| 3800 | break; |
| 3801 | case MPT2SAS_HP_2_4_EXTERNAL_SSDID: |
| 3802 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3803 | MPT2SAS_HP_2_4_EXTERNAL_BRANDING); |
| 3804 | break; |
| 3805 | case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID: |
| 3806 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3807 | MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING); |
| 3808 | break; |
| 3809 | case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID: |
| 3810 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3811 | MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING); |
| 3812 | break; |
| 3813 | default: |
| 3814 | pr_info(MPT3SAS_FMT |
| 3815 | "HP 6Gbps SAS HBA: Subsystem ID: 0x%X\n", |
| 3816 | ioc->name, ioc->pdev->subsystem_device); |
| 3817 | break; |
| 3818 | } |
| 3819 | default: |
| 3820 | pr_info(MPT3SAS_FMT |
| 3821 | "HP SAS HBA: Subsystem ID: 0x%X\n", |
| 3822 | ioc->name, ioc->pdev->subsystem_device); |
| 3823 | break; |
| 3824 | } |
Sreekanth Reddy | 38e4141 | 2015-06-30 12:24:57 +0530 | [diff] [blame] | 3825 | default: |
Sreekanth Reddy | 38e4141 | 2015-06-30 12:24:57 +0530 | [diff] [blame] | 3826 | break; |
| 3827 | } |
| 3828 | } |
Sreekanth Reddy | fb84dfc | 2015-06-30 12:24:56 +0530 | [diff] [blame] | 3829 | |
| 3830 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3831 | * _base_display_ioc_capabilities - Disply IOC's capabilities. |
| 3832 | * @ioc: per adapter object |
| 3833 | * |
| 3834 | * Return nothing. |
| 3835 | */ |
| 3836 | static void |
| 3837 | _base_display_ioc_capabilities(struct MPT3SAS_ADAPTER *ioc) |
| 3838 | { |
| 3839 | int i = 0; |
| 3840 | char desc[16]; |
| 3841 | u32 iounit_pg1_flags; |
| 3842 | u32 bios_version; |
| 3843 | |
| 3844 | bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion); |
| 3845 | strncpy(desc, ioc->manu_pg0.ChipName, 16); |
| 3846 | pr_info(MPT3SAS_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), "\ |
| 3847 | "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n", |
| 3848 | ioc->name, desc, |
| 3849 | (ioc->facts.FWVersion.Word & 0xFF000000) >> 24, |
| 3850 | (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16, |
| 3851 | (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8, |
| 3852 | ioc->facts.FWVersion.Word & 0x000000FF, |
| 3853 | ioc->pdev->revision, |
| 3854 | (bios_version & 0xFF000000) >> 24, |
| 3855 | (bios_version & 0x00FF0000) >> 16, |
| 3856 | (bios_version & 0x0000FF00) >> 8, |
| 3857 | bios_version & 0x000000FF); |
| 3858 | |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 3859 | _base_display_OEMs_branding(ioc); |
Sreekanth Reddy | 1117b31 | 2014-09-12 15:35:30 +0530 | [diff] [blame] | 3860 | |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 3861 | if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_NVME_DEVICES) { |
| 3862 | pr_info("%sNVMe", i ? "," : ""); |
| 3863 | i++; |
| 3864 | } |
| 3865 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3866 | pr_info(MPT3SAS_FMT "Protocol=(", ioc->name); |
| 3867 | |
| 3868 | if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) { |
| 3869 | pr_info("Initiator"); |
| 3870 | i++; |
| 3871 | } |
| 3872 | |
| 3873 | if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) { |
| 3874 | pr_info("%sTarget", i ? "," : ""); |
| 3875 | i++; |
| 3876 | } |
| 3877 | |
| 3878 | i = 0; |
| 3879 | pr_info("), "); |
| 3880 | pr_info("Capabilities=("); |
| 3881 | |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 3882 | if (!ioc->hide_ir_msg) { |
| 3883 | if (ioc->facts.IOCCapabilities & |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3884 | MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) { |
| 3885 | pr_info("Raid"); |
| 3886 | i++; |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 3887 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3888 | } |
| 3889 | |
| 3890 | if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) { |
| 3891 | pr_info("%sTLR", i ? "," : ""); |
| 3892 | i++; |
| 3893 | } |
| 3894 | |
| 3895 | if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) { |
| 3896 | pr_info("%sMulticast", i ? "," : ""); |
| 3897 | i++; |
| 3898 | } |
| 3899 | |
| 3900 | if (ioc->facts.IOCCapabilities & |
| 3901 | MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) { |
| 3902 | pr_info("%sBIDI Target", i ? "," : ""); |
| 3903 | i++; |
| 3904 | } |
| 3905 | |
| 3906 | if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) { |
| 3907 | pr_info("%sEEDP", i ? "," : ""); |
| 3908 | i++; |
| 3909 | } |
| 3910 | |
| 3911 | if (ioc->facts.IOCCapabilities & |
| 3912 | MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) { |
| 3913 | pr_info("%sSnapshot Buffer", i ? "," : ""); |
| 3914 | i++; |
| 3915 | } |
| 3916 | |
| 3917 | if (ioc->facts.IOCCapabilities & |
| 3918 | MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) { |
| 3919 | pr_info("%sDiag Trace Buffer", i ? "," : ""); |
| 3920 | i++; |
| 3921 | } |
| 3922 | |
| 3923 | if (ioc->facts.IOCCapabilities & |
| 3924 | MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) { |
| 3925 | pr_info("%sDiag Extended Buffer", i ? "," : ""); |
| 3926 | i++; |
| 3927 | } |
| 3928 | |
| 3929 | if (ioc->facts.IOCCapabilities & |
| 3930 | MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) { |
| 3931 | pr_info("%sTask Set Full", i ? "," : ""); |
| 3932 | i++; |
| 3933 | } |
| 3934 | |
| 3935 | iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags); |
| 3936 | if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) { |
| 3937 | pr_info("%sNCQ", i ? "," : ""); |
| 3938 | i++; |
| 3939 | } |
| 3940 | |
| 3941 | pr_info(")\n"); |
| 3942 | } |
| 3943 | |
| 3944 | /** |
| 3945 | * mpt3sas_base_update_missing_delay - change the missing delay timers |
| 3946 | * @ioc: per adapter object |
| 3947 | * @device_missing_delay: amount of time till device is reported missing |
| 3948 | * @io_missing_delay: interval IO is returned when there is a missing device |
| 3949 | * |
| 3950 | * Return nothing. |
| 3951 | * |
| 3952 | * Passed on the command line, this function will modify the device missing |
| 3953 | * delay, as well as the io missing delay. This should be called at driver |
| 3954 | * load time. |
| 3955 | */ |
| 3956 | void |
| 3957 | mpt3sas_base_update_missing_delay(struct MPT3SAS_ADAPTER *ioc, |
| 3958 | u16 device_missing_delay, u8 io_missing_delay) |
| 3959 | { |
| 3960 | u16 dmd, dmd_new, dmd_orignal; |
| 3961 | u8 io_missing_delay_original; |
| 3962 | u16 sz; |
| 3963 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; |
| 3964 | Mpi2ConfigReply_t mpi_reply; |
| 3965 | u8 num_phys = 0; |
| 3966 | u16 ioc_status; |
| 3967 | |
| 3968 | mpt3sas_config_get_number_hba_phys(ioc, &num_phys); |
| 3969 | if (!num_phys) |
| 3970 | return; |
| 3971 | |
| 3972 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (num_phys * |
| 3973 | sizeof(Mpi2SasIOUnit1PhyData_t)); |
| 3974 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); |
| 3975 | if (!sas_iounit_pg1) { |
| 3976 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 3977 | ioc->name, __FILE__, __LINE__, __func__); |
| 3978 | goto out; |
| 3979 | } |
| 3980 | if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, |
| 3981 | sas_iounit_pg1, sz))) { |
| 3982 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 3983 | ioc->name, __FILE__, __LINE__, __func__); |
| 3984 | goto out; |
| 3985 | } |
| 3986 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 3987 | MPI2_IOCSTATUS_MASK; |
| 3988 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 3989 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 3990 | ioc->name, __FILE__, __LINE__, __func__); |
| 3991 | goto out; |
| 3992 | } |
| 3993 | |
| 3994 | /* device missing delay */ |
| 3995 | dmd = sas_iounit_pg1->ReportDeviceMissingDelay; |
| 3996 | if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) |
| 3997 | dmd = (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; |
| 3998 | else |
| 3999 | dmd = dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 4000 | dmd_orignal = dmd; |
| 4001 | if (device_missing_delay > 0x7F) { |
| 4002 | dmd = (device_missing_delay > 0x7F0) ? 0x7F0 : |
| 4003 | device_missing_delay; |
| 4004 | dmd = dmd / 16; |
| 4005 | dmd |= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16; |
| 4006 | } else |
| 4007 | dmd = device_missing_delay; |
| 4008 | sas_iounit_pg1->ReportDeviceMissingDelay = dmd; |
| 4009 | |
| 4010 | /* io missing delay */ |
| 4011 | io_missing_delay_original = sas_iounit_pg1->IODeviceMissingDelay; |
| 4012 | sas_iounit_pg1->IODeviceMissingDelay = io_missing_delay; |
| 4013 | |
| 4014 | if (!mpt3sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, |
| 4015 | sz)) { |
| 4016 | if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) |
| 4017 | dmd_new = (dmd & |
| 4018 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; |
| 4019 | else |
| 4020 | dmd_new = |
| 4021 | dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 4022 | pr_info(MPT3SAS_FMT "device_missing_delay: old(%d), new(%d)\n", |
| 4023 | ioc->name, dmd_orignal, dmd_new); |
| 4024 | pr_info(MPT3SAS_FMT "ioc_missing_delay: old(%d), new(%d)\n", |
| 4025 | ioc->name, io_missing_delay_original, |
| 4026 | io_missing_delay); |
| 4027 | ioc->device_missing_delay = dmd_new; |
| 4028 | ioc->io_missing_delay = io_missing_delay; |
| 4029 | } |
| 4030 | |
| 4031 | out: |
| 4032 | kfree(sas_iounit_pg1); |
| 4033 | } |
| 4034 | /** |
| 4035 | * _base_static_config_pages - static start of day config pages |
| 4036 | * @ioc: per adapter object |
| 4037 | * |
| 4038 | * Return nothing. |
| 4039 | */ |
| 4040 | static void |
| 4041 | _base_static_config_pages(struct MPT3SAS_ADAPTER *ioc) |
| 4042 | { |
| 4043 | Mpi2ConfigReply_t mpi_reply; |
| 4044 | u32 iounit_pg1_flags; |
| 4045 | |
| 4046 | mpt3sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0); |
| 4047 | if (ioc->ir_firmware) |
| 4048 | mpt3sas_config_get_manufacturing_pg10(ioc, &mpi_reply, |
| 4049 | &ioc->manu_pg10); |
| 4050 | |
| 4051 | /* |
| 4052 | * Ensure correct T10 PI operation if vendor left EEDPTagMode |
| 4053 | * flag unset in NVDATA. |
| 4054 | */ |
| 4055 | mpt3sas_config_get_manufacturing_pg11(ioc, &mpi_reply, &ioc->manu_pg11); |
| 4056 | if (ioc->manu_pg11.EEDPTagMode == 0) { |
| 4057 | pr_err("%s: overriding NVDATA EEDPTagMode setting\n", |
| 4058 | ioc->name); |
| 4059 | ioc->manu_pg11.EEDPTagMode &= ~0x3; |
| 4060 | ioc->manu_pg11.EEDPTagMode |= 0x1; |
| 4061 | mpt3sas_config_set_manufacturing_pg11(ioc, &mpi_reply, |
| 4062 | &ioc->manu_pg11); |
| 4063 | } |
| 4064 | |
| 4065 | mpt3sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2); |
| 4066 | mpt3sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3); |
| 4067 | mpt3sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8); |
| 4068 | mpt3sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0); |
| 4069 | mpt3sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1); |
Sreekanth Reddy | 2d8ce8c | 2015-01-12 11:38:56 +0530 | [diff] [blame] | 4070 | mpt3sas_config_get_iounit_pg8(ioc, &mpi_reply, &ioc->iounit_pg8); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4071 | _base_display_ioc_capabilities(ioc); |
| 4072 | |
| 4073 | /* |
| 4074 | * Enable task_set_full handling in iounit_pg1 when the |
| 4075 | * facts capabilities indicate that its supported. |
| 4076 | */ |
| 4077 | iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags); |
| 4078 | if ((ioc->facts.IOCCapabilities & |
| 4079 | MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING)) |
| 4080 | iounit_pg1_flags &= |
| 4081 | ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING; |
| 4082 | else |
| 4083 | iounit_pg1_flags |= |
| 4084 | MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING; |
| 4085 | ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags); |
| 4086 | mpt3sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1); |
Sreekanth Reddy | 2d8ce8c | 2015-01-12 11:38:56 +0530 | [diff] [blame] | 4087 | |
| 4088 | if (ioc->iounit_pg8.NumSensors) |
| 4089 | ioc->temp_sensors_count = ioc->iounit_pg8.NumSensors; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | /** |
| 4093 | * _base_release_memory_pools - release memory |
| 4094 | * @ioc: per adapter object |
| 4095 | * |
| 4096 | * Free memory allocated from _base_allocate_memory_pools. |
| 4097 | * |
| 4098 | * Return nothing. |
| 4099 | */ |
| 4100 | static void |
| 4101 | _base_release_memory_pools(struct MPT3SAS_ADAPTER *ioc) |
| 4102 | { |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4103 | int i = 0; |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 4104 | int j = 0; |
| 4105 | struct chain_tracker *ct; |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4106 | struct reply_post_struct *rps; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4107 | |
| 4108 | dexitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 4109 | __func__)); |
| 4110 | |
| 4111 | if (ioc->request) { |
| 4112 | pci_free_consistent(ioc->pdev, ioc->request_dma_sz, |
| 4113 | ioc->request, ioc->request_dma); |
| 4114 | dexitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4115 | "request_pool(0x%p): free\n", |
| 4116 | ioc->name, ioc->request)); |
| 4117 | ioc->request = NULL; |
| 4118 | } |
| 4119 | |
| 4120 | if (ioc->sense) { |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4121 | dma_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma); |
| 4122 | dma_pool_destroy(ioc->sense_dma_pool); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4123 | dexitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4124 | "sense_pool(0x%p): free\n", |
| 4125 | ioc->name, ioc->sense)); |
| 4126 | ioc->sense = NULL; |
| 4127 | } |
| 4128 | |
| 4129 | if (ioc->reply) { |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4130 | dma_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma); |
| 4131 | dma_pool_destroy(ioc->reply_dma_pool); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4132 | dexitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4133 | "reply_pool(0x%p): free\n", |
| 4134 | ioc->name, ioc->reply)); |
| 4135 | ioc->reply = NULL; |
| 4136 | } |
| 4137 | |
| 4138 | if (ioc->reply_free) { |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4139 | dma_pool_free(ioc->reply_free_dma_pool, ioc->reply_free, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4140 | ioc->reply_free_dma); |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4141 | dma_pool_destroy(ioc->reply_free_dma_pool); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4142 | dexitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4143 | "reply_free_pool(0x%p): free\n", |
| 4144 | ioc->name, ioc->reply_free)); |
| 4145 | ioc->reply_free = NULL; |
| 4146 | } |
| 4147 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4148 | if (ioc->reply_post) { |
| 4149 | do { |
| 4150 | rps = &ioc->reply_post[i]; |
| 4151 | if (rps->reply_post_free) { |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4152 | dma_pool_free( |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4153 | ioc->reply_post_free_dma_pool, |
| 4154 | rps->reply_post_free, |
| 4155 | rps->reply_post_free_dma); |
| 4156 | dexitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4157 | "reply_post_free_pool(0x%p): free\n", |
| 4158 | ioc->name, rps->reply_post_free)); |
| 4159 | rps->reply_post_free = NULL; |
| 4160 | } |
| 4161 | } while (ioc->rdpq_array_enable && |
| 4162 | (++i < ioc->reply_queue_count)); |
Chaitra P B | cd33223 | 2018-04-24 05:28:31 -0400 | [diff] [blame] | 4163 | if (ioc->reply_post_free_array && |
| 4164 | ioc->rdpq_array_enable) { |
| 4165 | dma_pool_free(ioc->reply_post_free_array_dma_pool, |
| 4166 | ioc->reply_post_free_array, |
| 4167 | ioc->reply_post_free_array_dma); |
| 4168 | ioc->reply_post_free_array = NULL; |
| 4169 | } |
| 4170 | dma_pool_destroy(ioc->reply_post_free_array_dma_pool); |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4171 | dma_pool_destroy(ioc->reply_post_free_dma_pool); |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4172 | kfree(ioc->reply_post); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4173 | } |
| 4174 | |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4175 | if (ioc->pcie_sgl_dma_pool) { |
| 4176 | for (i = 0; i < ioc->scsiio_depth; i++) { |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 4177 | dma_pool_free(ioc->pcie_sgl_dma_pool, |
| 4178 | ioc->pcie_sg_lookup[i].pcie_sgl, |
| 4179 | ioc->pcie_sg_lookup[i].pcie_sgl_dma); |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4180 | } |
| 4181 | if (ioc->pcie_sgl_dma_pool) |
Romain Perier | 13a0640 | 2017-11-20 20:32:46 +0100 | [diff] [blame] | 4182 | dma_pool_destroy(ioc->pcie_sgl_dma_pool); |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4183 | } |
| 4184 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4185 | if (ioc->config_page) { |
| 4186 | dexitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4187 | "config_page(0x%p): free\n", ioc->name, |
| 4188 | ioc->config_page)); |
| 4189 | pci_free_consistent(ioc->pdev, ioc->config_page_sz, |
| 4190 | ioc->config_page, ioc->config_page_dma); |
| 4191 | } |
| 4192 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4193 | kfree(ioc->hpr_lookup); |
| 4194 | kfree(ioc->internal_lookup); |
| 4195 | if (ioc->chain_lookup) { |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 4196 | for (i = 0; i < ioc->scsiio_depth; i++) { |
Chaitra P B | 74522a9 | 2018-04-24 05:28:33 -0400 | [diff] [blame] | 4197 | for (j = ioc->chains_per_prp_buffer; |
| 4198 | j < ioc->chains_needed_per_io; j++) { |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 4199 | ct = &ioc->chain_lookup[i].chains_per_smid[j]; |
| 4200 | if (ct && ct->chain_buffer) |
| 4201 | dma_pool_free(ioc->chain_dma_pool, |
| 4202 | ct->chain_buffer, |
| 4203 | ct->chain_buffer_dma); |
| 4204 | } |
| 4205 | kfree(ioc->chain_lookup[i].chains_per_smid); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4206 | } |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4207 | dma_pool_destroy(ioc->chain_dma_pool); |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 4208 | kfree(ioc->chain_lookup); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4209 | ioc->chain_lookup = NULL; |
| 4210 | } |
| 4211 | } |
| 4212 | |
| 4213 | /** |
Chaitra P B | e21fef6 | 2018-04-24 05:28:34 -0400 | [diff] [blame] | 4214 | * is_MSB_are_same - checks whether all reply queues in a set are |
| 4215 | * having same upper 32bits in their base memory address. |
| 4216 | * @reply_pool_start_address: Base address of a reply queue set |
| 4217 | * @pool_sz: Size of single Reply Descriptor Post Queues pool size |
| 4218 | * |
| 4219 | * Returns 1 if reply queues in a set have a same upper 32bits |
| 4220 | * in their base memory address, |
| 4221 | * else 0 |
| 4222 | */ |
| 4223 | |
| 4224 | static int |
| 4225 | is_MSB_are_same(long reply_pool_start_address, u32 pool_sz) |
| 4226 | { |
| 4227 | long reply_pool_end_address; |
| 4228 | |
| 4229 | reply_pool_end_address = reply_pool_start_address + pool_sz; |
| 4230 | |
| 4231 | if (upper_32_bits(reply_pool_start_address) == |
| 4232 | upper_32_bits(reply_pool_end_address)) |
| 4233 | return 1; |
| 4234 | else |
| 4235 | return 0; |
| 4236 | } |
| 4237 | |
| 4238 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4239 | * _base_allocate_memory_pools - allocate start of day memory pools |
| 4240 | * @ioc: per adapter object |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4241 | * |
| 4242 | * Returns 0 success, anything else error |
| 4243 | */ |
| 4244 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 4245 | _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4246 | { |
| 4247 | struct mpt3sas_facts *facts; |
| 4248 | u16 max_sge_elements; |
| 4249 | u16 chains_needed_per_io; |
Chaitra P B | cd33223 | 2018-04-24 05:28:31 -0400 | [diff] [blame] | 4250 | u32 sz, total_sz, reply_post_free_sz, reply_post_free_array_sz; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4251 | u32 retry_sz; |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4252 | u16 max_request_credit, nvme_blocks_needed; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4253 | unsigned short sg_tablesize; |
| 4254 | u16 sge_size; |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 4255 | int i, j; |
| 4256 | struct chain_tracker *ct; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4257 | |
| 4258 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 4259 | __func__)); |
| 4260 | |
| 4261 | |
| 4262 | retry_sz = 0; |
| 4263 | facts = &ioc->facts; |
| 4264 | |
| 4265 | /* command line tunables for max sgl entries */ |
| 4266 | if (max_sgl_entries != -1) |
| 4267 | sg_tablesize = max_sgl_entries; |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 4268 | else { |
| 4269 | if (ioc->hba_mpi_version_belonged == MPI2_VERSION) |
| 4270 | sg_tablesize = MPT2SAS_SG_DEPTH; |
| 4271 | else |
| 4272 | sg_tablesize = MPT3SAS_SG_DEPTH; |
| 4273 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4274 | |
Sreekanth Reddy | 06f5f97 | 2017-10-10 18:41:16 +0530 | [diff] [blame] | 4275 | /* max sgl entries <= MPT_KDUMP_MIN_PHYS_SEGMENTS in KDUMP mode */ |
| 4276 | if (reset_devices) |
| 4277 | sg_tablesize = min_t(unsigned short, sg_tablesize, |
| 4278 | MPT_KDUMP_MIN_PHYS_SEGMENTS); |
| 4279 | |
Suganath Prabu Subramani | 0448f01 | 2018-02-07 02:51:46 -0800 | [diff] [blame] | 4280 | if (ioc->is_mcpu_endpoint) |
| 4281 | ioc->shost->sg_tablesize = MPT_MIN_PHYS_SEGMENTS; |
| 4282 | else { |
| 4283 | if (sg_tablesize < MPT_MIN_PHYS_SEGMENTS) |
| 4284 | sg_tablesize = MPT_MIN_PHYS_SEGMENTS; |
| 4285 | else if (sg_tablesize > MPT_MAX_PHYS_SEGMENTS) { |
| 4286 | sg_tablesize = min_t(unsigned short, sg_tablesize, |
| 4287 | SG_MAX_SEGMENTS); |
| 4288 | pr_warn(MPT3SAS_FMT |
| 4289 | "sg_tablesize(%u) is bigger than kernel " |
| 4290 | "defined SG_CHUNK_SIZE(%u)\n", ioc->name, |
| 4291 | sg_tablesize, MPT_MAX_PHYS_SEGMENTS); |
| 4292 | } |
| 4293 | ioc->shost->sg_tablesize = sg_tablesize; |
Sreekanth Reddy | ad666a0 | 2015-01-12 11:39:00 +0530 | [diff] [blame] | 4294 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4295 | |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 4296 | ioc->internal_depth = min_t(int, (facts->HighPriorityCredit + (5)), |
| 4297 | (facts->RequestCredit / 4)); |
| 4298 | if (ioc->internal_depth < INTERNAL_CMDS_COUNT) { |
| 4299 | if (facts->RequestCredit <= (INTERNAL_CMDS_COUNT + |
| 4300 | INTERNAL_SCSIIO_CMDS_COUNT)) { |
| 4301 | pr_err(MPT3SAS_FMT "IOC doesn't have enough Request \ |
| 4302 | Credits, it has just %d number of credits\n", |
| 4303 | ioc->name, facts->RequestCredit); |
| 4304 | return -ENOMEM; |
| 4305 | } |
| 4306 | ioc->internal_depth = 10; |
| 4307 | } |
| 4308 | |
| 4309 | ioc->hi_priority_depth = ioc->internal_depth - (5); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4310 | /* command line tunables for max controller queue depth */ |
| 4311 | if (max_queue_depth != -1 && max_queue_depth != 0) { |
| 4312 | max_request_credit = min_t(u16, max_queue_depth + |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 4313 | ioc->internal_depth, facts->RequestCredit); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4314 | if (max_request_credit > MAX_HBA_QUEUE_DEPTH) |
| 4315 | max_request_credit = MAX_HBA_QUEUE_DEPTH; |
Sreekanth Reddy | 06f5f97 | 2017-10-10 18:41:16 +0530 | [diff] [blame] | 4316 | } else if (reset_devices) |
| 4317 | max_request_credit = min_t(u16, facts->RequestCredit, |
| 4318 | (MPT3SAS_KDUMP_SCSI_IO_DEPTH + ioc->internal_depth)); |
| 4319 | else |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4320 | max_request_credit = min_t(u16, facts->RequestCredit, |
| 4321 | MAX_HBA_QUEUE_DEPTH); |
| 4322 | |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 4323 | /* Firmware maintains additional facts->HighPriorityCredit number of |
| 4324 | * credits for HiPriprity Request messages, so hba queue depth will be |
| 4325 | * sum of max_request_credit and high priority queue depth. |
| 4326 | */ |
| 4327 | ioc->hba_queue_depth = max_request_credit + ioc->hi_priority_depth; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4328 | |
| 4329 | /* request frame size */ |
| 4330 | ioc->request_sz = facts->IOCRequestFrameSize * 4; |
| 4331 | |
| 4332 | /* reply frame size */ |
| 4333 | ioc->reply_sz = facts->ReplyFrameSize * 4; |
| 4334 | |
Suganath prabu Subramani | ebb3024 | 2016-01-28 12:07:04 +0530 | [diff] [blame] | 4335 | /* chain segment size */ |
| 4336 | if (ioc->hba_mpi_version_belonged != MPI2_VERSION) { |
| 4337 | if (facts->IOCMaxChainSegmentSize) |
| 4338 | ioc->chain_segment_sz = |
| 4339 | facts->IOCMaxChainSegmentSize * |
| 4340 | MAX_CHAIN_ELEMT_SZ; |
| 4341 | else |
| 4342 | /* set to 128 bytes size if IOCMaxChainSegmentSize is zero */ |
| 4343 | ioc->chain_segment_sz = DEFAULT_NUM_FWCHAIN_ELEMTS * |
| 4344 | MAX_CHAIN_ELEMT_SZ; |
| 4345 | } else |
| 4346 | ioc->chain_segment_sz = ioc->request_sz; |
| 4347 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4348 | /* calculate the max scatter element size */ |
| 4349 | sge_size = max_t(u16, ioc->sge_size, ioc->sge_size_ieee); |
| 4350 | |
| 4351 | retry_allocation: |
| 4352 | total_sz = 0; |
| 4353 | /* calculate number of sg elements left over in the 1st frame */ |
| 4354 | max_sge_elements = ioc->request_sz - ((sizeof(Mpi2SCSIIORequest_t) - |
| 4355 | sizeof(Mpi2SGEIOUnion_t)) + sge_size); |
| 4356 | ioc->max_sges_in_main_message = max_sge_elements/sge_size; |
| 4357 | |
| 4358 | /* now do the same for a chain buffer */ |
Suganath prabu Subramani | ebb3024 | 2016-01-28 12:07:04 +0530 | [diff] [blame] | 4359 | max_sge_elements = ioc->chain_segment_sz - sge_size; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4360 | ioc->max_sges_in_chain_message = max_sge_elements/sge_size; |
| 4361 | |
| 4362 | /* |
| 4363 | * MPT3SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE |
| 4364 | */ |
| 4365 | chains_needed_per_io = ((ioc->shost->sg_tablesize - |
| 4366 | ioc->max_sges_in_main_message)/ioc->max_sges_in_chain_message) |
| 4367 | + 1; |
| 4368 | if (chains_needed_per_io > facts->MaxChainDepth) { |
| 4369 | chains_needed_per_io = facts->MaxChainDepth; |
| 4370 | ioc->shost->sg_tablesize = min_t(u16, |
| 4371 | ioc->max_sges_in_main_message + (ioc->max_sges_in_chain_message |
| 4372 | * chains_needed_per_io), ioc->shost->sg_tablesize); |
| 4373 | } |
| 4374 | ioc->chains_needed_per_io = chains_needed_per_io; |
| 4375 | |
| 4376 | /* reply free queue sizing - taking into account for 64 FW events */ |
| 4377 | ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64; |
| 4378 | |
Suganath Prabu Subramani | 0448f01 | 2018-02-07 02:51:46 -0800 | [diff] [blame] | 4379 | /* mCPU manage single counters for simplicity */ |
| 4380 | if (ioc->is_mcpu_endpoint) |
| 4381 | ioc->reply_post_queue_depth = ioc->reply_free_queue_depth; |
| 4382 | else { |
| 4383 | /* calculate reply descriptor post queue depth */ |
| 4384 | ioc->reply_post_queue_depth = ioc->hba_queue_depth + |
| 4385 | ioc->reply_free_queue_depth + 1; |
| 4386 | /* align the reply post queue on the next 16 count boundary */ |
| 4387 | if (ioc->reply_post_queue_depth % 16) |
| 4388 | ioc->reply_post_queue_depth += 16 - |
| 4389 | (ioc->reply_post_queue_depth % 16); |
| 4390 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4391 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4392 | if (ioc->reply_post_queue_depth > |
| 4393 | facts->MaxReplyDescriptorPostQueueDepth) { |
| 4394 | ioc->reply_post_queue_depth = |
| 4395 | facts->MaxReplyDescriptorPostQueueDepth - |
| 4396 | (facts->MaxReplyDescriptorPostQueueDepth % 16); |
| 4397 | ioc->hba_queue_depth = |
| 4398 | ((ioc->reply_post_queue_depth - 64) / 2) - 1; |
| 4399 | ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64; |
| 4400 | } |
| 4401 | |
| 4402 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "scatter gather: " \ |
| 4403 | "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), " |
| 4404 | "chains_per_io(%d)\n", ioc->name, ioc->max_sges_in_main_message, |
| 4405 | ioc->max_sges_in_chain_message, ioc->shost->sg_tablesize, |
| 4406 | ioc->chains_needed_per_io)); |
| 4407 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4408 | /* reply post queue, 16 byte align */ |
| 4409 | reply_post_free_sz = ioc->reply_post_queue_depth * |
| 4410 | sizeof(Mpi2DefaultReplyDescriptor_t); |
| 4411 | |
| 4412 | sz = reply_post_free_sz; |
| 4413 | if (_base_is_controller_msix_enabled(ioc) && !ioc->rdpq_array_enable) |
| 4414 | sz *= ioc->reply_queue_count; |
| 4415 | |
| 4416 | ioc->reply_post = kcalloc((ioc->rdpq_array_enable) ? |
| 4417 | (ioc->reply_queue_count):1, |
| 4418 | sizeof(struct reply_post_struct), GFP_KERNEL); |
| 4419 | |
| 4420 | if (!ioc->reply_post) { |
| 4421 | pr_err(MPT3SAS_FMT "reply_post_free pool: kcalloc failed\n", |
| 4422 | ioc->name); |
| 4423 | goto out; |
| 4424 | } |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4425 | ioc->reply_post_free_dma_pool = dma_pool_create("reply_post_free pool", |
| 4426 | &ioc->pdev->dev, sz, 16, 0); |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4427 | if (!ioc->reply_post_free_dma_pool) { |
| 4428 | pr_err(MPT3SAS_FMT |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4429 | "reply_post_free pool: dma_pool_create failed\n", |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4430 | ioc->name); |
| 4431 | goto out; |
| 4432 | } |
| 4433 | i = 0; |
| 4434 | do { |
| 4435 | ioc->reply_post[i].reply_post_free = |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4436 | dma_pool_alloc(ioc->reply_post_free_dma_pool, |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4437 | GFP_KERNEL, |
| 4438 | &ioc->reply_post[i].reply_post_free_dma); |
| 4439 | if (!ioc->reply_post[i].reply_post_free) { |
| 4440 | pr_err(MPT3SAS_FMT |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4441 | "reply_post_free pool: dma_pool_alloc failed\n", |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4442 | ioc->name); |
| 4443 | goto out; |
| 4444 | } |
| 4445 | memset(ioc->reply_post[i].reply_post_free, 0, sz); |
| 4446 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4447 | "reply post free pool (0x%p): depth(%d)," |
| 4448 | "element_size(%d), pool_size(%d kB)\n", ioc->name, |
| 4449 | ioc->reply_post[i].reply_post_free, |
| 4450 | ioc->reply_post_queue_depth, 8, sz/1024)); |
| 4451 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4452 | "reply_post_free_dma = (0x%llx)\n", ioc->name, |
| 4453 | (unsigned long long) |
| 4454 | ioc->reply_post[i].reply_post_free_dma)); |
| 4455 | total_sz += sz; |
| 4456 | } while (ioc->rdpq_array_enable && (++i < ioc->reply_queue_count)); |
| 4457 | |
| 4458 | if (ioc->dma_mask == 64) { |
| 4459 | if (_base_change_consistent_dma_mask(ioc, ioc->pdev) != 0) { |
| 4460 | pr_warn(MPT3SAS_FMT |
| 4461 | "no suitable consistent DMA mask for %s\n", |
| 4462 | ioc->name, pci_name(ioc->pdev)); |
| 4463 | goto out; |
| 4464 | } |
| 4465 | } |
| 4466 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4467 | ioc->scsiio_depth = ioc->hba_queue_depth - |
| 4468 | ioc->hi_priority_depth - ioc->internal_depth; |
| 4469 | |
| 4470 | /* set the scsi host can_queue depth |
| 4471 | * with some internal commands that could be outstanding |
| 4472 | */ |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 4473 | ioc->shost->can_queue = ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4474 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4475 | "scsi host: can_queue depth (%d)\n", |
| 4476 | ioc->name, ioc->shost->can_queue)); |
| 4477 | |
| 4478 | |
| 4479 | /* contiguous pool for request and chains, 16 byte align, one extra " |
| 4480 | * "frame for smid=0 |
| 4481 | */ |
| 4482 | ioc->chain_depth = ioc->chains_needed_per_io * ioc->scsiio_depth; |
| 4483 | sz = ((ioc->scsiio_depth + 1) * ioc->request_sz); |
| 4484 | |
| 4485 | /* hi-priority queue */ |
| 4486 | sz += (ioc->hi_priority_depth * ioc->request_sz); |
| 4487 | |
| 4488 | /* internal queue */ |
| 4489 | sz += (ioc->internal_depth * ioc->request_sz); |
| 4490 | |
| 4491 | ioc->request_dma_sz = sz; |
| 4492 | ioc->request = pci_alloc_consistent(ioc->pdev, sz, &ioc->request_dma); |
| 4493 | if (!ioc->request) { |
| 4494 | pr_err(MPT3SAS_FMT "request pool: pci_alloc_consistent " \ |
| 4495 | "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), " |
| 4496 | "total(%d kB)\n", ioc->name, ioc->hba_queue_depth, |
| 4497 | ioc->chains_needed_per_io, ioc->request_sz, sz/1024); |
| 4498 | if (ioc->scsiio_depth < MPT3SAS_SAS_QUEUE_DEPTH) |
| 4499 | goto out; |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 4500 | retry_sz = 64; |
| 4501 | ioc->hba_queue_depth -= retry_sz; |
Suganath prabu Subramani | 8ff045c | 2016-02-18 14:09:45 +0530 | [diff] [blame] | 4502 | _base_release_memory_pools(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4503 | goto retry_allocation; |
| 4504 | } |
| 4505 | |
| 4506 | if (retry_sz) |
| 4507 | pr_err(MPT3SAS_FMT "request pool: pci_alloc_consistent " \ |
| 4508 | "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), " |
| 4509 | "total(%d kb)\n", ioc->name, ioc->hba_queue_depth, |
| 4510 | ioc->chains_needed_per_io, ioc->request_sz, sz/1024); |
| 4511 | |
| 4512 | /* hi-priority queue */ |
| 4513 | ioc->hi_priority = ioc->request + ((ioc->scsiio_depth + 1) * |
| 4514 | ioc->request_sz); |
| 4515 | ioc->hi_priority_dma = ioc->request_dma + ((ioc->scsiio_depth + 1) * |
| 4516 | ioc->request_sz); |
| 4517 | |
| 4518 | /* internal queue */ |
| 4519 | ioc->internal = ioc->hi_priority + (ioc->hi_priority_depth * |
| 4520 | ioc->request_sz); |
| 4521 | ioc->internal_dma = ioc->hi_priority_dma + (ioc->hi_priority_depth * |
| 4522 | ioc->request_sz); |
| 4523 | |
| 4524 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4525 | "request pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB)\n", |
| 4526 | ioc->name, ioc->request, ioc->hba_queue_depth, ioc->request_sz, |
| 4527 | (ioc->hba_queue_depth * ioc->request_sz)/1024)); |
| 4528 | |
| 4529 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "request pool: dma(0x%llx)\n", |
| 4530 | ioc->name, (unsigned long long) ioc->request_dma)); |
| 4531 | total_sz += sz; |
| 4532 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4533 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "scsiio(0x%p): depth(%d)\n", |
| 4534 | ioc->name, ioc->request, ioc->scsiio_depth)); |
| 4535 | |
| 4536 | ioc->chain_depth = min_t(u32, ioc->chain_depth, MAX_CHAIN_DEPTH); |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 4537 | sz = ioc->scsiio_depth * sizeof(struct chain_lookup); |
| 4538 | ioc->chain_lookup = kzalloc(sz, GFP_KERNEL); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4539 | if (!ioc->chain_lookup) { |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 4540 | pr_err(MPT3SAS_FMT "chain_lookup: __get_free_pages " |
Chaitra P B | 74522a9 | 2018-04-24 05:28:33 -0400 | [diff] [blame] | 4541 | "failed\n", ioc->name); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4542 | goto out; |
| 4543 | } |
Chaitra P B | 93204b7 | 2018-04-24 05:28:32 -0400 | [diff] [blame] | 4544 | |
| 4545 | sz = ioc->chains_needed_per_io * sizeof(struct chain_tracker); |
| 4546 | for (i = 0; i < ioc->scsiio_depth; i++) { |
| 4547 | ioc->chain_lookup[i].chains_per_smid = kzalloc(sz, GFP_KERNEL); |
| 4548 | if (!ioc->chain_lookup[i].chains_per_smid) { |
| 4549 | pr_err(MPT3SAS_FMT "chain_lookup: " |
| 4550 | " kzalloc failed\n", ioc->name); |
| 4551 | goto out; |
| 4552 | } |
| 4553 | } |
| 4554 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4555 | /* initialize hi-priority queue smid's */ |
| 4556 | ioc->hpr_lookup = kcalloc(ioc->hi_priority_depth, |
| 4557 | sizeof(struct request_tracker), GFP_KERNEL); |
| 4558 | if (!ioc->hpr_lookup) { |
| 4559 | pr_err(MPT3SAS_FMT "hpr_lookup: kcalloc failed\n", |
| 4560 | ioc->name); |
| 4561 | goto out; |
| 4562 | } |
| 4563 | ioc->hi_priority_smid = ioc->scsiio_depth + 1; |
| 4564 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4565 | "hi_priority(0x%p): depth(%d), start smid(%d)\n", |
| 4566 | ioc->name, ioc->hi_priority, |
| 4567 | ioc->hi_priority_depth, ioc->hi_priority_smid)); |
| 4568 | |
| 4569 | /* initialize internal queue smid's */ |
| 4570 | ioc->internal_lookup = kcalloc(ioc->internal_depth, |
| 4571 | sizeof(struct request_tracker), GFP_KERNEL); |
| 4572 | if (!ioc->internal_lookup) { |
| 4573 | pr_err(MPT3SAS_FMT "internal_lookup: kcalloc failed\n", |
| 4574 | ioc->name); |
| 4575 | goto out; |
| 4576 | } |
| 4577 | ioc->internal_smid = ioc->hi_priority_smid + ioc->hi_priority_depth; |
| 4578 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4579 | "internal(0x%p): depth(%d), start smid(%d)\n", |
| 4580 | ioc->name, ioc->internal, |
| 4581 | ioc->internal_depth, ioc->internal_smid)); |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4582 | /* |
| 4583 | * The number of NVMe page sized blocks needed is: |
| 4584 | * (((sg_tablesize * 8) - 1) / (page_size - 8)) + 1 |
| 4585 | * ((sg_tablesize * 8) - 1) is the max PRP's minus the first PRP entry |
| 4586 | * that is placed in the main message frame. 8 is the size of each PRP |
| 4587 | * entry or PRP list pointer entry. 8 is subtracted from page_size |
| 4588 | * because of the PRP list pointer entry at the end of a page, so this |
| 4589 | * is not counted as a PRP entry. The 1 added page is a round up. |
| 4590 | * |
| 4591 | * To avoid allocation failures due to the amount of memory that could |
| 4592 | * be required for NVMe PRP's, only each set of NVMe blocks will be |
| 4593 | * contiguous, so a new set is allocated for each possible I/O. |
| 4594 | */ |
Chaitra P B | 74522a9 | 2018-04-24 05:28:33 -0400 | [diff] [blame] | 4595 | ioc->chains_per_prp_buffer = 0; |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4596 | if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_NVME_DEVICES) { |
| 4597 | nvme_blocks_needed = |
| 4598 | (ioc->shost->sg_tablesize * NVME_PRP_SIZE) - 1; |
| 4599 | nvme_blocks_needed /= (ioc->page_size - NVME_PRP_SIZE); |
| 4600 | nvme_blocks_needed++; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4601 | |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 4602 | sz = sizeof(struct pcie_sg_list) * ioc->scsiio_depth; |
| 4603 | ioc->pcie_sg_lookup = kzalloc(sz, GFP_KERNEL); |
| 4604 | if (!ioc->pcie_sg_lookup) { |
| 4605 | pr_info(MPT3SAS_FMT |
| 4606 | "PCIe SGL lookup: kzalloc failed\n", ioc->name); |
| 4607 | goto out; |
| 4608 | } |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4609 | sz = nvme_blocks_needed * ioc->page_size; |
| 4610 | ioc->pcie_sgl_dma_pool = |
Romain Perier | 13a0640 | 2017-11-20 20:32:46 +0100 | [diff] [blame] | 4611 | dma_pool_create("PCIe SGL pool", &ioc->pdev->dev, sz, 16, 0); |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4612 | if (!ioc->pcie_sgl_dma_pool) { |
| 4613 | pr_info(MPT3SAS_FMT |
Romain Perier | 13a0640 | 2017-11-20 20:32:46 +0100 | [diff] [blame] | 4614 | "PCIe SGL pool: dma_pool_create failed\n", |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4615 | ioc->name); |
| 4616 | goto out; |
| 4617 | } |
Chaitra P B | 74522a9 | 2018-04-24 05:28:33 -0400 | [diff] [blame] | 4618 | |
| 4619 | ioc->chains_per_prp_buffer = sz/ioc->chain_segment_sz; |
| 4620 | ioc->chains_per_prp_buffer = min(ioc->chains_per_prp_buffer, |
| 4621 | ioc->chains_needed_per_io); |
| 4622 | |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4623 | for (i = 0; i < ioc->scsiio_depth; i++) { |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 4624 | ioc->pcie_sg_lookup[i].pcie_sgl = dma_pool_alloc( |
| 4625 | ioc->pcie_sgl_dma_pool, GFP_KERNEL, |
| 4626 | &ioc->pcie_sg_lookup[i].pcie_sgl_dma); |
| 4627 | if (!ioc->pcie_sg_lookup[i].pcie_sgl) { |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4628 | pr_info(MPT3SAS_FMT |
Romain Perier | 13a0640 | 2017-11-20 20:32:46 +0100 | [diff] [blame] | 4629 | "PCIe SGL pool: dma_pool_alloc failed\n", |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4630 | ioc->name); |
| 4631 | goto out; |
| 4632 | } |
Chaitra P B | 74522a9 | 2018-04-24 05:28:33 -0400 | [diff] [blame] | 4633 | for (j = 0; j < ioc->chains_per_prp_buffer; j++) { |
| 4634 | ct = &ioc->chain_lookup[i].chains_per_smid[j]; |
| 4635 | ct->chain_buffer = |
| 4636 | ioc->pcie_sg_lookup[i].pcie_sgl + |
| 4637 | (j * ioc->chain_segment_sz); |
| 4638 | ct->chain_buffer_dma = |
| 4639 | ioc->pcie_sg_lookup[i].pcie_sgl_dma + |
| 4640 | (j * ioc->chain_segment_sz); |
| 4641 | } |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "PCIe sgl pool depth(%d), " |
| 4645 | "element_size(%d), pool_size(%d kB)\n", ioc->name, |
| 4646 | ioc->scsiio_depth, sz, (sz * ioc->scsiio_depth)/1024)); |
Chaitra P B | 74522a9 | 2018-04-24 05:28:33 -0400 | [diff] [blame] | 4647 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "Number of chains can " |
| 4648 | "fit in a PRP page(%d)\n", ioc->name, |
| 4649 | ioc->chains_per_prp_buffer)); |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 4650 | total_sz += sz * ioc->scsiio_depth; |
| 4651 | } |
Chaitra P B | 74522a9 | 2018-04-24 05:28:33 -0400 | [diff] [blame] | 4652 | |
| 4653 | ioc->chain_dma_pool = dma_pool_create("chain pool", &ioc->pdev->dev, |
| 4654 | ioc->chain_segment_sz, 16, 0); |
| 4655 | if (!ioc->chain_dma_pool) { |
| 4656 | pr_err(MPT3SAS_FMT "chain_dma_pool: dma_pool_create failed\n", |
| 4657 | ioc->name); |
| 4658 | goto out; |
| 4659 | } |
| 4660 | for (i = 0; i < ioc->scsiio_depth; i++) { |
| 4661 | for (j = ioc->chains_per_prp_buffer; |
| 4662 | j < ioc->chains_needed_per_io; j++) { |
| 4663 | ct = &ioc->chain_lookup[i].chains_per_smid[j]; |
| 4664 | ct->chain_buffer = dma_pool_alloc( |
| 4665 | ioc->chain_dma_pool, GFP_KERNEL, |
| 4666 | &ct->chain_buffer_dma); |
| 4667 | if (!ct->chain_buffer) { |
| 4668 | pr_err(MPT3SAS_FMT "chain_lookup: " |
| 4669 | " pci_pool_alloc failed\n", ioc->name); |
| 4670 | _base_release_memory_pools(ioc); |
| 4671 | goto out; |
| 4672 | } |
| 4673 | } |
| 4674 | total_sz += ioc->chain_segment_sz; |
| 4675 | } |
| 4676 | |
| 4677 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4678 | "chain pool depth(%d), frame_size(%d), pool_size(%d kB)\n", |
| 4679 | ioc->name, ioc->chain_depth, ioc->chain_segment_sz, |
| 4680 | ((ioc->chain_depth * ioc->chain_segment_sz))/1024)); |
| 4681 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4682 | /* sense buffers, 4 byte align */ |
| 4683 | sz = ioc->scsiio_depth * SCSI_SENSE_BUFFERSIZE; |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4684 | ioc->sense_dma_pool = dma_pool_create("sense pool", &ioc->pdev->dev, sz, |
| 4685 | 4, 0); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4686 | if (!ioc->sense_dma_pool) { |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4687 | pr_err(MPT3SAS_FMT "sense pool: dma_pool_create failed\n", |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4688 | ioc->name); |
| 4689 | goto out; |
| 4690 | } |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4691 | ioc->sense = dma_pool_alloc(ioc->sense_dma_pool, GFP_KERNEL, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4692 | &ioc->sense_dma); |
| 4693 | if (!ioc->sense) { |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4694 | pr_err(MPT3SAS_FMT "sense pool: dma_pool_alloc failed\n", |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4695 | ioc->name); |
| 4696 | goto out; |
| 4697 | } |
Chaitra P B | e21fef6 | 2018-04-24 05:28:34 -0400 | [diff] [blame] | 4698 | /* sense buffer requires to be in same 4 gb region. |
| 4699 | * Below function will check the same. |
| 4700 | * In case of failure, new pci pool will be created with updated |
| 4701 | * alignment. Older allocation and pool will be destroyed. |
| 4702 | * Alignment will be used such a way that next allocation if |
| 4703 | * success, will always meet same 4gb region requirement. |
| 4704 | * Actual requirement is not alignment, but we need start and end of |
| 4705 | * DMA address must have same upper 32 bit address. |
| 4706 | */ |
| 4707 | if (!is_MSB_are_same((long)ioc->sense, sz)) { |
| 4708 | //Release Sense pool & Reallocate |
| 4709 | dma_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma); |
| 4710 | dma_pool_destroy(ioc->sense_dma_pool); |
| 4711 | ioc->sense = NULL; |
| 4712 | |
| 4713 | ioc->sense_dma_pool = |
| 4714 | dma_pool_create("sense pool", &ioc->pdev->dev, sz, |
| 4715 | roundup_pow_of_two(sz), 0); |
| 4716 | if (!ioc->sense_dma_pool) { |
| 4717 | pr_err(MPT3SAS_FMT "sense pool: pci_pool_create failed\n", |
| 4718 | ioc->name); |
| 4719 | goto out; |
| 4720 | } |
| 4721 | ioc->sense = dma_pool_alloc(ioc->sense_dma_pool, GFP_KERNEL, |
| 4722 | &ioc->sense_dma); |
| 4723 | if (!ioc->sense) { |
| 4724 | pr_err(MPT3SAS_FMT "sense pool: pci_pool_alloc failed\n", |
| 4725 | ioc->name); |
| 4726 | goto out; |
| 4727 | } |
| 4728 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4729 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4730 | "sense pool(0x%p): depth(%d), element_size(%d), pool_size" |
| 4731 | "(%d kB)\n", ioc->name, ioc->sense, ioc->scsiio_depth, |
| 4732 | SCSI_SENSE_BUFFERSIZE, sz/1024)); |
| 4733 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "sense_dma(0x%llx)\n", |
| 4734 | ioc->name, (unsigned long long)ioc->sense_dma)); |
| 4735 | total_sz += sz; |
| 4736 | |
| 4737 | /* reply pool, 4 byte align */ |
| 4738 | sz = ioc->reply_free_queue_depth * ioc->reply_sz; |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4739 | ioc->reply_dma_pool = dma_pool_create("reply pool", &ioc->pdev->dev, sz, |
| 4740 | 4, 0); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4741 | if (!ioc->reply_dma_pool) { |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4742 | pr_err(MPT3SAS_FMT "reply pool: dma_pool_create failed\n", |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4743 | ioc->name); |
| 4744 | goto out; |
| 4745 | } |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4746 | ioc->reply = dma_pool_alloc(ioc->reply_dma_pool, GFP_KERNEL, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4747 | &ioc->reply_dma); |
| 4748 | if (!ioc->reply) { |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4749 | pr_err(MPT3SAS_FMT "reply pool: dma_pool_alloc failed\n", |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4750 | ioc->name); |
| 4751 | goto out; |
| 4752 | } |
| 4753 | ioc->reply_dma_min_address = (u32)(ioc->reply_dma); |
| 4754 | ioc->reply_dma_max_address = (u32)(ioc->reply_dma) + sz; |
| 4755 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4756 | "reply pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB)\n", |
| 4757 | ioc->name, ioc->reply, |
| 4758 | ioc->reply_free_queue_depth, ioc->reply_sz, sz/1024)); |
| 4759 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "reply_dma(0x%llx)\n", |
| 4760 | ioc->name, (unsigned long long)ioc->reply_dma)); |
| 4761 | total_sz += sz; |
| 4762 | |
| 4763 | /* reply free queue, 16 byte align */ |
| 4764 | sz = ioc->reply_free_queue_depth * 4; |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4765 | ioc->reply_free_dma_pool = dma_pool_create("reply_free pool", |
| 4766 | &ioc->pdev->dev, sz, 16, 0); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4767 | if (!ioc->reply_free_dma_pool) { |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4768 | pr_err(MPT3SAS_FMT "reply_free pool: dma_pool_create failed\n", |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4769 | ioc->name); |
| 4770 | goto out; |
| 4771 | } |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4772 | ioc->reply_free = dma_pool_alloc(ioc->reply_free_dma_pool, GFP_KERNEL, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4773 | &ioc->reply_free_dma); |
| 4774 | if (!ioc->reply_free) { |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4775 | pr_err(MPT3SAS_FMT "reply_free pool: dma_pool_alloc failed\n", |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4776 | ioc->name); |
| 4777 | goto out; |
| 4778 | } |
| 4779 | memset(ioc->reply_free, 0, sz); |
| 4780 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "reply_free pool(0x%p): " \ |
| 4781 | "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->name, |
| 4782 | ioc->reply_free, ioc->reply_free_queue_depth, 4, sz/1024)); |
| 4783 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4784 | "reply_free_dma (0x%llx)\n", |
| 4785 | ioc->name, (unsigned long long)ioc->reply_free_dma)); |
| 4786 | total_sz += sz; |
| 4787 | |
Chaitra P B | cd33223 | 2018-04-24 05:28:31 -0400 | [diff] [blame] | 4788 | if (ioc->rdpq_array_enable) { |
| 4789 | reply_post_free_array_sz = ioc->reply_queue_count * |
| 4790 | sizeof(Mpi2IOCInitRDPQArrayEntry); |
| 4791 | ioc->reply_post_free_array_dma_pool = |
| 4792 | dma_pool_create("reply_post_free_array pool", |
| 4793 | &ioc->pdev->dev, reply_post_free_array_sz, 16, 0); |
| 4794 | if (!ioc->reply_post_free_array_dma_pool) { |
| 4795 | dinitprintk(ioc, |
| 4796 | pr_info(MPT3SAS_FMT "reply_post_free_array pool: " |
| 4797 | "dma_pool_create failed\n", ioc->name)); |
| 4798 | goto out; |
| 4799 | } |
| 4800 | ioc->reply_post_free_array = |
| 4801 | dma_pool_alloc(ioc->reply_post_free_array_dma_pool, |
| 4802 | GFP_KERNEL, &ioc->reply_post_free_array_dma); |
| 4803 | if (!ioc->reply_post_free_array) { |
| 4804 | dinitprintk(ioc, |
| 4805 | pr_info(MPT3SAS_FMT "reply_post_free_array pool: " |
| 4806 | "dma_pool_alloc failed\n", ioc->name)); |
| 4807 | goto out; |
| 4808 | } |
| 4809 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4810 | ioc->config_page_sz = 512; |
| 4811 | ioc->config_page = pci_alloc_consistent(ioc->pdev, |
| 4812 | ioc->config_page_sz, &ioc->config_page_dma); |
| 4813 | if (!ioc->config_page) { |
| 4814 | pr_err(MPT3SAS_FMT |
Romain Perier | e9d9841 | 2017-07-06 10:13:07 +0200 | [diff] [blame] | 4815 | "config page: dma_pool_alloc failed\n", |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4816 | ioc->name); |
| 4817 | goto out; |
| 4818 | } |
| 4819 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4820 | "config page(0x%p): size(%d)\n", |
| 4821 | ioc->name, ioc->config_page, ioc->config_page_sz)); |
| 4822 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "config_page_dma(0x%llx)\n", |
| 4823 | ioc->name, (unsigned long long)ioc->config_page_dma)); |
| 4824 | total_sz += ioc->config_page_sz; |
| 4825 | |
| 4826 | pr_info(MPT3SAS_FMT "Allocated physical memory: size(%d kB)\n", |
| 4827 | ioc->name, total_sz/1024); |
| 4828 | pr_info(MPT3SAS_FMT |
| 4829 | "Current Controller Queue Depth(%d),Max Controller Queue Depth(%d)\n", |
| 4830 | ioc->name, ioc->shost->can_queue, facts->RequestCredit); |
| 4831 | pr_info(MPT3SAS_FMT "Scatter Gather Elements per IO(%d)\n", |
| 4832 | ioc->name, ioc->shost->sg_tablesize); |
| 4833 | return 0; |
| 4834 | |
| 4835 | out: |
| 4836 | return -ENOMEM; |
| 4837 | } |
| 4838 | |
| 4839 | /** |
| 4840 | * mpt3sas_base_get_iocstate - Get the current state of a MPT adapter. |
| 4841 | * @ioc: Pointer to MPT_ADAPTER structure |
| 4842 | * @cooked: Request raw or cooked IOC state |
| 4843 | * |
| 4844 | * Returns all IOC Doorbell register bits if cooked==0, else just the |
| 4845 | * Doorbell bits in MPI_IOC_STATE_MASK. |
| 4846 | */ |
| 4847 | u32 |
| 4848 | mpt3sas_base_get_iocstate(struct MPT3SAS_ADAPTER *ioc, int cooked) |
| 4849 | { |
| 4850 | u32 s, sc; |
| 4851 | |
| 4852 | s = readl(&ioc->chip->Doorbell); |
| 4853 | sc = s & MPI2_IOC_STATE_MASK; |
| 4854 | return cooked ? sc : s; |
| 4855 | } |
| 4856 | |
| 4857 | /** |
| 4858 | * _base_wait_on_iocstate - waiting on a particular ioc state |
| 4859 | * @ioc_state: controller state { READY, OPERATIONAL, or RESET } |
| 4860 | * @timeout: timeout in second |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4861 | * |
| 4862 | * Returns 0 for success, non-zero for failure. |
| 4863 | */ |
| 4864 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 4865 | _base_wait_on_iocstate(struct MPT3SAS_ADAPTER *ioc, u32 ioc_state, int timeout) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4866 | { |
| 4867 | u32 count, cntdn; |
| 4868 | u32 current_state; |
| 4869 | |
| 4870 | count = 0; |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 4871 | cntdn = 1000 * timeout; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4872 | do { |
| 4873 | current_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 4874 | if (current_state == ioc_state) |
| 4875 | return 0; |
| 4876 | if (count && current_state == MPI2_IOC_STATE_FAULT) |
| 4877 | break; |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 4878 | |
| 4879 | usleep_range(1000, 1500); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4880 | count++; |
| 4881 | } while (--cntdn); |
| 4882 | |
| 4883 | return current_state; |
| 4884 | } |
| 4885 | |
| 4886 | /** |
| 4887 | * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by |
| 4888 | * a write to the doorbell) |
| 4889 | * @ioc: per adapter object |
| 4890 | * @timeout: timeout in second |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4891 | * |
| 4892 | * Returns 0 for success, non-zero for failure. |
| 4893 | * |
| 4894 | * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell. |
| 4895 | */ |
| 4896 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 4897 | _base_diag_reset(struct MPT3SAS_ADAPTER *ioc); |
Sreekanth Reddy | 4dc8c80 | 2015-06-30 12:24:48 +0530 | [diff] [blame] | 4898 | |
| 4899 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 4900 | _base_wait_for_doorbell_int(struct MPT3SAS_ADAPTER *ioc, int timeout) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4901 | { |
| 4902 | u32 cntdn, count; |
| 4903 | u32 int_status; |
| 4904 | |
| 4905 | count = 0; |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 4906 | cntdn = 1000 * timeout; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4907 | do { |
| 4908 | int_status = readl(&ioc->chip->HostInterruptStatus); |
| 4909 | if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) { |
| 4910 | dhsprintk(ioc, pr_info(MPT3SAS_FMT |
| 4911 | "%s: successful count(%d), timeout(%d)\n", |
| 4912 | ioc->name, __func__, count, timeout)); |
| 4913 | return 0; |
| 4914 | } |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 4915 | |
| 4916 | usleep_range(1000, 1500); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4917 | count++; |
| 4918 | } while (--cntdn); |
| 4919 | |
| 4920 | pr_err(MPT3SAS_FMT |
| 4921 | "%s: failed due to timeout count(%d), int_status(%x)!\n", |
| 4922 | ioc->name, __func__, count, int_status); |
| 4923 | return -EFAULT; |
| 4924 | } |
| 4925 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 4926 | static int |
| 4927 | _base_spin_on_doorbell_int(struct MPT3SAS_ADAPTER *ioc, int timeout) |
| 4928 | { |
| 4929 | u32 cntdn, count; |
| 4930 | u32 int_status; |
| 4931 | |
| 4932 | count = 0; |
| 4933 | cntdn = 2000 * timeout; |
| 4934 | do { |
| 4935 | int_status = readl(&ioc->chip->HostInterruptStatus); |
| 4936 | if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) { |
| 4937 | dhsprintk(ioc, pr_info(MPT3SAS_FMT |
| 4938 | "%s: successful count(%d), timeout(%d)\n", |
| 4939 | ioc->name, __func__, count, timeout)); |
| 4940 | return 0; |
| 4941 | } |
| 4942 | |
| 4943 | udelay(500); |
| 4944 | count++; |
| 4945 | } while (--cntdn); |
| 4946 | |
| 4947 | pr_err(MPT3SAS_FMT |
| 4948 | "%s: failed due to timeout count(%d), int_status(%x)!\n", |
| 4949 | ioc->name, __func__, count, int_status); |
| 4950 | return -EFAULT; |
| 4951 | |
| 4952 | } |
| 4953 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4954 | /** |
| 4955 | * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell. |
| 4956 | * @ioc: per adapter object |
| 4957 | * @timeout: timeout in second |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4958 | * |
| 4959 | * Returns 0 for success, non-zero for failure. |
| 4960 | * |
| 4961 | * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to |
| 4962 | * doorbell. |
| 4963 | */ |
| 4964 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 4965 | _base_wait_for_doorbell_ack(struct MPT3SAS_ADAPTER *ioc, int timeout) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4966 | { |
| 4967 | u32 cntdn, count; |
| 4968 | u32 int_status; |
| 4969 | u32 doorbell; |
| 4970 | |
| 4971 | count = 0; |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 4972 | cntdn = 1000 * timeout; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4973 | do { |
| 4974 | int_status = readl(&ioc->chip->HostInterruptStatus); |
| 4975 | if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) { |
| 4976 | dhsprintk(ioc, pr_info(MPT3SAS_FMT |
| 4977 | "%s: successful count(%d), timeout(%d)\n", |
| 4978 | ioc->name, __func__, count, timeout)); |
| 4979 | return 0; |
| 4980 | } else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) { |
| 4981 | doorbell = readl(&ioc->chip->Doorbell); |
| 4982 | if ((doorbell & MPI2_IOC_STATE_MASK) == |
| 4983 | MPI2_IOC_STATE_FAULT) { |
| 4984 | mpt3sas_base_fault_info(ioc , doorbell); |
| 4985 | return -EFAULT; |
| 4986 | } |
| 4987 | } else if (int_status == 0xFFFFFFFF) |
| 4988 | goto out; |
| 4989 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 4990 | usleep_range(1000, 1500); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4991 | count++; |
| 4992 | } while (--cntdn); |
| 4993 | |
| 4994 | out: |
| 4995 | pr_err(MPT3SAS_FMT |
| 4996 | "%s: failed due to timeout count(%d), int_status(%x)!\n", |
| 4997 | ioc->name, __func__, count, int_status); |
| 4998 | return -EFAULT; |
| 4999 | } |
| 5000 | |
| 5001 | /** |
| 5002 | * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use |
| 5003 | * @ioc: per adapter object |
| 5004 | * @timeout: timeout in second |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5005 | * |
| 5006 | * Returns 0 for success, non-zero for failure. |
| 5007 | * |
| 5008 | */ |
| 5009 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5010 | _base_wait_for_doorbell_not_used(struct MPT3SAS_ADAPTER *ioc, int timeout) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5011 | { |
| 5012 | u32 cntdn, count; |
| 5013 | u32 doorbell_reg; |
| 5014 | |
| 5015 | count = 0; |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5016 | cntdn = 1000 * timeout; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5017 | do { |
| 5018 | doorbell_reg = readl(&ioc->chip->Doorbell); |
| 5019 | if (!(doorbell_reg & MPI2_DOORBELL_USED)) { |
| 5020 | dhsprintk(ioc, pr_info(MPT3SAS_FMT |
| 5021 | "%s: successful count(%d), timeout(%d)\n", |
| 5022 | ioc->name, __func__, count, timeout)); |
| 5023 | return 0; |
| 5024 | } |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5025 | |
| 5026 | usleep_range(1000, 1500); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5027 | count++; |
| 5028 | } while (--cntdn); |
| 5029 | |
| 5030 | pr_err(MPT3SAS_FMT |
| 5031 | "%s: failed due to timeout count(%d), doorbell_reg(%x)!\n", |
| 5032 | ioc->name, __func__, count, doorbell_reg); |
| 5033 | return -EFAULT; |
| 5034 | } |
| 5035 | |
| 5036 | /** |
| 5037 | * _base_send_ioc_reset - send doorbell reset |
| 5038 | * @ioc: per adapter object |
| 5039 | * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET |
| 5040 | * @timeout: timeout in second |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5041 | * |
| 5042 | * Returns 0 for success, non-zero for failure. |
| 5043 | */ |
| 5044 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5045 | _base_send_ioc_reset(struct MPT3SAS_ADAPTER *ioc, u8 reset_type, int timeout) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5046 | { |
| 5047 | u32 ioc_state; |
| 5048 | int r = 0; |
| 5049 | |
| 5050 | if (reset_type != MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET) { |
| 5051 | pr_err(MPT3SAS_FMT "%s: unknown reset_type\n", |
| 5052 | ioc->name, __func__); |
| 5053 | return -EFAULT; |
| 5054 | } |
| 5055 | |
| 5056 | if (!(ioc->facts.IOCCapabilities & |
| 5057 | MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY)) |
| 5058 | return -EFAULT; |
| 5059 | |
| 5060 | pr_info(MPT3SAS_FMT "sending message unit reset !!\n", ioc->name); |
| 5061 | |
| 5062 | writel(reset_type << MPI2_DOORBELL_FUNCTION_SHIFT, |
| 5063 | &ioc->chip->Doorbell); |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5064 | if ((_base_wait_for_doorbell_ack(ioc, 15))) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5065 | r = -EFAULT; |
| 5066 | goto out; |
| 5067 | } |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5068 | ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, timeout); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5069 | if (ioc_state) { |
| 5070 | pr_err(MPT3SAS_FMT |
| 5071 | "%s: failed going to ready state (ioc_state=0x%x)\n", |
| 5072 | ioc->name, __func__, ioc_state); |
| 5073 | r = -EFAULT; |
| 5074 | goto out; |
| 5075 | } |
| 5076 | out: |
| 5077 | pr_info(MPT3SAS_FMT "message unit reset: %s\n", |
| 5078 | ioc->name, ((r == 0) ? "SUCCESS" : "FAILED")); |
| 5079 | return r; |
| 5080 | } |
| 5081 | |
| 5082 | /** |
| 5083 | * _base_handshake_req_reply_wait - send request thru doorbell interface |
| 5084 | * @ioc: per adapter object |
| 5085 | * @request_bytes: request length |
| 5086 | * @request: pointer having request payload |
| 5087 | * @reply_bytes: reply length |
| 5088 | * @reply: pointer to reply payload |
| 5089 | * @timeout: timeout in second |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5090 | * |
| 5091 | * Returns 0 for success, non-zero for failure. |
| 5092 | */ |
| 5093 | static int |
| 5094 | _base_handshake_req_reply_wait(struct MPT3SAS_ADAPTER *ioc, int request_bytes, |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5095 | u32 *request, int reply_bytes, u16 *reply, int timeout) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5096 | { |
| 5097 | MPI2DefaultReply_t *default_reply = (MPI2DefaultReply_t *)reply; |
| 5098 | int i; |
| 5099 | u8 failed; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5100 | __le32 *mfp; |
| 5101 | |
| 5102 | /* make sure doorbell is not in use */ |
| 5103 | if ((readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_USED)) { |
| 5104 | pr_err(MPT3SAS_FMT |
| 5105 | "doorbell is in use (line=%d)\n", |
| 5106 | ioc->name, __LINE__); |
| 5107 | return -EFAULT; |
| 5108 | } |
| 5109 | |
| 5110 | /* clear pending doorbell interrupts from previous state changes */ |
| 5111 | if (readl(&ioc->chip->HostInterruptStatus) & |
| 5112 | MPI2_HIS_IOC2SYS_DB_STATUS) |
| 5113 | writel(0, &ioc->chip->HostInterruptStatus); |
| 5114 | |
| 5115 | /* send message to ioc */ |
| 5116 | writel(((MPI2_FUNCTION_HANDSHAKE<<MPI2_DOORBELL_FUNCTION_SHIFT) | |
| 5117 | ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)), |
| 5118 | &ioc->chip->Doorbell); |
| 5119 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5120 | if ((_base_spin_on_doorbell_int(ioc, 5))) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5121 | pr_err(MPT3SAS_FMT |
| 5122 | "doorbell handshake int failed (line=%d)\n", |
| 5123 | ioc->name, __LINE__); |
| 5124 | return -EFAULT; |
| 5125 | } |
| 5126 | writel(0, &ioc->chip->HostInterruptStatus); |
| 5127 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5128 | if ((_base_wait_for_doorbell_ack(ioc, 5))) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5129 | pr_err(MPT3SAS_FMT |
| 5130 | "doorbell handshake ack failed (line=%d)\n", |
| 5131 | ioc->name, __LINE__); |
| 5132 | return -EFAULT; |
| 5133 | } |
| 5134 | |
| 5135 | /* send message 32-bits at a time */ |
| 5136 | for (i = 0, failed = 0; i < request_bytes/4 && !failed; i++) { |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 5137 | writel((u32)(request[i]), &ioc->chip->Doorbell); |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5138 | if ((_base_wait_for_doorbell_ack(ioc, 5))) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5139 | failed = 1; |
| 5140 | } |
| 5141 | |
| 5142 | if (failed) { |
| 5143 | pr_err(MPT3SAS_FMT |
| 5144 | "doorbell handshake sending request failed (line=%d)\n", |
| 5145 | ioc->name, __LINE__); |
| 5146 | return -EFAULT; |
| 5147 | } |
| 5148 | |
| 5149 | /* now wait for the reply */ |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5150 | if ((_base_wait_for_doorbell_int(ioc, timeout))) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5151 | pr_err(MPT3SAS_FMT |
| 5152 | "doorbell handshake int failed (line=%d)\n", |
| 5153 | ioc->name, __LINE__); |
| 5154 | return -EFAULT; |
| 5155 | } |
| 5156 | |
| 5157 | /* read the first two 16-bits, it gives the total length of the reply */ |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 5158 | reply[0] = (u16)(readl(&ioc->chip->Doorbell) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5159 | & MPI2_DOORBELL_DATA_MASK); |
| 5160 | writel(0, &ioc->chip->HostInterruptStatus); |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5161 | if ((_base_wait_for_doorbell_int(ioc, 5))) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5162 | pr_err(MPT3SAS_FMT |
| 5163 | "doorbell handshake int failed (line=%d)\n", |
| 5164 | ioc->name, __LINE__); |
| 5165 | return -EFAULT; |
| 5166 | } |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 5167 | reply[1] = (u16)(readl(&ioc->chip->Doorbell) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5168 | & MPI2_DOORBELL_DATA_MASK); |
| 5169 | writel(0, &ioc->chip->HostInterruptStatus); |
| 5170 | |
| 5171 | for (i = 2; i < default_reply->MsgLength * 2; i++) { |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5172 | if ((_base_wait_for_doorbell_int(ioc, 5))) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5173 | pr_err(MPT3SAS_FMT |
| 5174 | "doorbell handshake int failed (line=%d)\n", |
| 5175 | ioc->name, __LINE__); |
| 5176 | return -EFAULT; |
| 5177 | } |
| 5178 | if (i >= reply_bytes/2) /* overflow case */ |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 5179 | readl(&ioc->chip->Doorbell); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5180 | else |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 5181 | reply[i] = (u16)(readl(&ioc->chip->Doorbell) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5182 | & MPI2_DOORBELL_DATA_MASK); |
| 5183 | writel(0, &ioc->chip->HostInterruptStatus); |
| 5184 | } |
| 5185 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5186 | _base_wait_for_doorbell_int(ioc, 5); |
| 5187 | if (_base_wait_for_doorbell_not_used(ioc, 5) != 0) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5188 | dhsprintk(ioc, pr_info(MPT3SAS_FMT |
| 5189 | "doorbell is in use (line=%d)\n", ioc->name, __LINE__)); |
| 5190 | } |
| 5191 | writel(0, &ioc->chip->HostInterruptStatus); |
| 5192 | |
| 5193 | if (ioc->logging_level & MPT_DEBUG_INIT) { |
| 5194 | mfp = (__le32 *)reply; |
| 5195 | pr_info("\toffset:data\n"); |
| 5196 | for (i = 0; i < reply_bytes/4; i++) |
| 5197 | pr_info("\t[0x%02x]:%08x\n", i*4, |
| 5198 | le32_to_cpu(mfp[i])); |
| 5199 | } |
| 5200 | return 0; |
| 5201 | } |
| 5202 | |
| 5203 | /** |
| 5204 | * mpt3sas_base_sas_iounit_control - send sas iounit control to FW |
| 5205 | * @ioc: per adapter object |
| 5206 | * @mpi_reply: the reply payload from FW |
| 5207 | * @mpi_request: the request payload sent to FW |
| 5208 | * |
| 5209 | * The SAS IO Unit Control Request message allows the host to perform low-level |
| 5210 | * operations, such as resets on the PHYs of the IO Unit, also allows the host |
| 5211 | * to obtain the IOC assigned device handles for a device if it has other |
| 5212 | * identifying information about the device, in addition allows the host to |
| 5213 | * remove IOC resources associated with the device. |
| 5214 | * |
| 5215 | * Returns 0 for success, non-zero for failure. |
| 5216 | */ |
| 5217 | int |
| 5218 | mpt3sas_base_sas_iounit_control(struct MPT3SAS_ADAPTER *ioc, |
| 5219 | Mpi2SasIoUnitControlReply_t *mpi_reply, |
| 5220 | Mpi2SasIoUnitControlRequest_t *mpi_request) |
| 5221 | { |
| 5222 | u16 smid; |
| 5223 | u32 ioc_state; |
Dan Carpenter | eb44552 | 2014-12-04 13:57:05 +0300 | [diff] [blame] | 5224 | bool issue_reset = false; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5225 | int rc; |
| 5226 | void *request; |
| 5227 | u16 wait_state_count; |
| 5228 | |
| 5229 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 5230 | __func__)); |
| 5231 | |
| 5232 | mutex_lock(&ioc->base_cmds.mutex); |
| 5233 | |
| 5234 | if (ioc->base_cmds.status != MPT3_CMD_NOT_USED) { |
| 5235 | pr_err(MPT3SAS_FMT "%s: base_cmd in use\n", |
| 5236 | ioc->name, __func__); |
| 5237 | rc = -EAGAIN; |
| 5238 | goto out; |
| 5239 | } |
| 5240 | |
| 5241 | wait_state_count = 0; |
| 5242 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 5243 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 5244 | if (wait_state_count++ == 10) { |
| 5245 | pr_err(MPT3SAS_FMT |
| 5246 | "%s: failed due to ioc not operational\n", |
| 5247 | ioc->name, __func__); |
| 5248 | rc = -EFAULT; |
| 5249 | goto out; |
| 5250 | } |
| 5251 | ssleep(1); |
| 5252 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 5253 | pr_info(MPT3SAS_FMT |
| 5254 | "%s: waiting for operational state(count=%d)\n", |
| 5255 | ioc->name, __func__, wait_state_count); |
| 5256 | } |
| 5257 | |
| 5258 | smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); |
| 5259 | if (!smid) { |
| 5260 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 5261 | ioc->name, __func__); |
| 5262 | rc = -EAGAIN; |
| 5263 | goto out; |
| 5264 | } |
| 5265 | |
| 5266 | rc = 0; |
| 5267 | ioc->base_cmds.status = MPT3_CMD_PENDING; |
| 5268 | request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 5269 | ioc->base_cmds.smid = smid; |
| 5270 | memcpy(request, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t)); |
| 5271 | if (mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET || |
| 5272 | mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) |
| 5273 | ioc->ioc_link_reset_in_progress = 1; |
| 5274 | init_completion(&ioc->base_cmds.done); |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 5275 | mpt3sas_base_put_smid_default(ioc, smid); |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 5276 | wait_for_completion_timeout(&ioc->base_cmds.done, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5277 | msecs_to_jiffies(10000)); |
| 5278 | if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET || |
| 5279 | mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) && |
| 5280 | ioc->ioc_link_reset_in_progress) |
| 5281 | ioc->ioc_link_reset_in_progress = 0; |
| 5282 | if (!(ioc->base_cmds.status & MPT3_CMD_COMPLETE)) { |
| 5283 | pr_err(MPT3SAS_FMT "%s: timeout\n", |
| 5284 | ioc->name, __func__); |
| 5285 | _debug_dump_mf(mpi_request, |
| 5286 | sizeof(Mpi2SasIoUnitControlRequest_t)/4); |
| 5287 | if (!(ioc->base_cmds.status & MPT3_CMD_RESET)) |
Dan Carpenter | eb44552 | 2014-12-04 13:57:05 +0300 | [diff] [blame] | 5288 | issue_reset = true; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5289 | goto issue_host_reset; |
| 5290 | } |
| 5291 | if (ioc->base_cmds.status & MPT3_CMD_REPLY_VALID) |
| 5292 | memcpy(mpi_reply, ioc->base_cmds.reply, |
| 5293 | sizeof(Mpi2SasIoUnitControlReply_t)); |
| 5294 | else |
| 5295 | memset(mpi_reply, 0, sizeof(Mpi2SasIoUnitControlReply_t)); |
| 5296 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 5297 | goto out; |
| 5298 | |
| 5299 | issue_host_reset: |
| 5300 | if (issue_reset) |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5301 | mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5302 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 5303 | rc = -EFAULT; |
| 5304 | out: |
| 5305 | mutex_unlock(&ioc->base_cmds.mutex); |
| 5306 | return rc; |
| 5307 | } |
| 5308 | |
| 5309 | /** |
| 5310 | * mpt3sas_base_scsi_enclosure_processor - sending request to sep device |
| 5311 | * @ioc: per adapter object |
| 5312 | * @mpi_reply: the reply payload from FW |
| 5313 | * @mpi_request: the request payload sent to FW |
| 5314 | * |
| 5315 | * The SCSI Enclosure Processor request message causes the IOC to |
| 5316 | * communicate with SES devices to control LED status signals. |
| 5317 | * |
| 5318 | * Returns 0 for success, non-zero for failure. |
| 5319 | */ |
| 5320 | int |
| 5321 | mpt3sas_base_scsi_enclosure_processor(struct MPT3SAS_ADAPTER *ioc, |
| 5322 | Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request) |
| 5323 | { |
| 5324 | u16 smid; |
| 5325 | u32 ioc_state; |
Dan Carpenter | eb44552 | 2014-12-04 13:57:05 +0300 | [diff] [blame] | 5326 | bool issue_reset = false; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5327 | int rc; |
| 5328 | void *request; |
| 5329 | u16 wait_state_count; |
| 5330 | |
| 5331 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 5332 | __func__)); |
| 5333 | |
| 5334 | mutex_lock(&ioc->base_cmds.mutex); |
| 5335 | |
| 5336 | if (ioc->base_cmds.status != MPT3_CMD_NOT_USED) { |
| 5337 | pr_err(MPT3SAS_FMT "%s: base_cmd in use\n", |
| 5338 | ioc->name, __func__); |
| 5339 | rc = -EAGAIN; |
| 5340 | goto out; |
| 5341 | } |
| 5342 | |
| 5343 | wait_state_count = 0; |
| 5344 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 5345 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 5346 | if (wait_state_count++ == 10) { |
| 5347 | pr_err(MPT3SAS_FMT |
| 5348 | "%s: failed due to ioc not operational\n", |
| 5349 | ioc->name, __func__); |
| 5350 | rc = -EFAULT; |
| 5351 | goto out; |
| 5352 | } |
| 5353 | ssleep(1); |
| 5354 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 5355 | pr_info(MPT3SAS_FMT |
| 5356 | "%s: waiting for operational state(count=%d)\n", |
| 5357 | ioc->name, |
| 5358 | __func__, wait_state_count); |
| 5359 | } |
| 5360 | |
| 5361 | smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); |
| 5362 | if (!smid) { |
| 5363 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 5364 | ioc->name, __func__); |
| 5365 | rc = -EAGAIN; |
| 5366 | goto out; |
| 5367 | } |
| 5368 | |
| 5369 | rc = 0; |
| 5370 | ioc->base_cmds.status = MPT3_CMD_PENDING; |
| 5371 | request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 5372 | ioc->base_cmds.smid = smid; |
| 5373 | memcpy(request, mpi_request, sizeof(Mpi2SepReply_t)); |
| 5374 | init_completion(&ioc->base_cmds.done); |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 5375 | mpt3sas_base_put_smid_default(ioc, smid); |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 5376 | wait_for_completion_timeout(&ioc->base_cmds.done, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5377 | msecs_to_jiffies(10000)); |
| 5378 | if (!(ioc->base_cmds.status & MPT3_CMD_COMPLETE)) { |
| 5379 | pr_err(MPT3SAS_FMT "%s: timeout\n", |
| 5380 | ioc->name, __func__); |
| 5381 | _debug_dump_mf(mpi_request, |
| 5382 | sizeof(Mpi2SepRequest_t)/4); |
| 5383 | if (!(ioc->base_cmds.status & MPT3_CMD_RESET)) |
Dan Carpenter | eb44552 | 2014-12-04 13:57:05 +0300 | [diff] [blame] | 5384 | issue_reset = false; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5385 | goto issue_host_reset; |
| 5386 | } |
| 5387 | if (ioc->base_cmds.status & MPT3_CMD_REPLY_VALID) |
| 5388 | memcpy(mpi_reply, ioc->base_cmds.reply, |
| 5389 | sizeof(Mpi2SepReply_t)); |
| 5390 | else |
| 5391 | memset(mpi_reply, 0, sizeof(Mpi2SepReply_t)); |
| 5392 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 5393 | goto out; |
| 5394 | |
| 5395 | issue_host_reset: |
| 5396 | if (issue_reset) |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5397 | mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5398 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 5399 | rc = -EFAULT; |
| 5400 | out: |
| 5401 | mutex_unlock(&ioc->base_cmds.mutex); |
| 5402 | return rc; |
| 5403 | } |
| 5404 | |
| 5405 | /** |
| 5406 | * _base_get_port_facts - obtain port facts reply and save in ioc |
| 5407 | * @ioc: per adapter object |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5408 | * |
| 5409 | * Returns 0 for success, non-zero for failure. |
| 5410 | */ |
| 5411 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5412 | _base_get_port_facts(struct MPT3SAS_ADAPTER *ioc, int port) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5413 | { |
| 5414 | Mpi2PortFactsRequest_t mpi_request; |
| 5415 | Mpi2PortFactsReply_t mpi_reply; |
| 5416 | struct mpt3sas_port_facts *pfacts; |
| 5417 | int mpi_reply_sz, mpi_request_sz, r; |
| 5418 | |
| 5419 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 5420 | __func__)); |
| 5421 | |
| 5422 | mpi_reply_sz = sizeof(Mpi2PortFactsReply_t); |
| 5423 | mpi_request_sz = sizeof(Mpi2PortFactsRequest_t); |
| 5424 | memset(&mpi_request, 0, mpi_request_sz); |
| 5425 | mpi_request.Function = MPI2_FUNCTION_PORT_FACTS; |
| 5426 | mpi_request.PortNumber = port; |
| 5427 | r = _base_handshake_req_reply_wait(ioc, mpi_request_sz, |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5428 | (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5429 | |
| 5430 | if (r != 0) { |
| 5431 | pr_err(MPT3SAS_FMT "%s: handshake failed (r=%d)\n", |
| 5432 | ioc->name, __func__, r); |
| 5433 | return r; |
| 5434 | } |
| 5435 | |
| 5436 | pfacts = &ioc->pfacts[port]; |
| 5437 | memset(pfacts, 0, sizeof(struct mpt3sas_port_facts)); |
| 5438 | pfacts->PortNumber = mpi_reply.PortNumber; |
| 5439 | pfacts->VP_ID = mpi_reply.VP_ID; |
| 5440 | pfacts->VF_ID = mpi_reply.VF_ID; |
| 5441 | pfacts->MaxPostedCmdBuffers = |
| 5442 | le16_to_cpu(mpi_reply.MaxPostedCmdBuffers); |
| 5443 | |
| 5444 | return 0; |
| 5445 | } |
| 5446 | |
| 5447 | /** |
Sreekanth Reddy | 4dc8c80 | 2015-06-30 12:24:48 +0530 | [diff] [blame] | 5448 | * _base_wait_for_iocstate - Wait until the card is in READY or OPERATIONAL |
| 5449 | * @ioc: per adapter object |
| 5450 | * @timeout: |
Sreekanth Reddy | 4dc8c80 | 2015-06-30 12:24:48 +0530 | [diff] [blame] | 5451 | * |
| 5452 | * Returns 0 for success, non-zero for failure. |
| 5453 | */ |
| 5454 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5455 | _base_wait_for_iocstate(struct MPT3SAS_ADAPTER *ioc, int timeout) |
Sreekanth Reddy | 4dc8c80 | 2015-06-30 12:24:48 +0530 | [diff] [blame] | 5456 | { |
| 5457 | u32 ioc_state; |
| 5458 | int rc; |
| 5459 | |
| 5460 | dinitprintk(ioc, printk(MPT3SAS_FMT "%s\n", ioc->name, |
| 5461 | __func__)); |
| 5462 | |
| 5463 | if (ioc->pci_error_recovery) { |
| 5464 | dfailprintk(ioc, printk(MPT3SAS_FMT |
| 5465 | "%s: host in pci error recovery\n", ioc->name, __func__)); |
| 5466 | return -EFAULT; |
| 5467 | } |
| 5468 | |
| 5469 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); |
| 5470 | dhsprintk(ioc, printk(MPT3SAS_FMT "%s: ioc_state(0x%08x)\n", |
| 5471 | ioc->name, __func__, ioc_state)); |
| 5472 | |
| 5473 | if (((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY) || |
| 5474 | (ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL) |
| 5475 | return 0; |
| 5476 | |
| 5477 | if (ioc_state & MPI2_DOORBELL_USED) { |
| 5478 | dhsprintk(ioc, printk(MPT3SAS_FMT |
| 5479 | "unexpected doorbell active!\n", ioc->name)); |
| 5480 | goto issue_diag_reset; |
| 5481 | } |
| 5482 | |
| 5483 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 5484 | mpt3sas_base_fault_info(ioc, ioc_state & |
| 5485 | MPI2_DOORBELL_DATA_MASK); |
| 5486 | goto issue_diag_reset; |
| 5487 | } |
| 5488 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5489 | ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, timeout); |
Sreekanth Reddy | 4dc8c80 | 2015-06-30 12:24:48 +0530 | [diff] [blame] | 5490 | if (ioc_state) { |
| 5491 | dfailprintk(ioc, printk(MPT3SAS_FMT |
| 5492 | "%s: failed going to ready state (ioc_state=0x%x)\n", |
| 5493 | ioc->name, __func__, ioc_state)); |
| 5494 | return -EFAULT; |
| 5495 | } |
| 5496 | |
| 5497 | issue_diag_reset: |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5498 | rc = _base_diag_reset(ioc); |
Sreekanth Reddy | 4dc8c80 | 2015-06-30 12:24:48 +0530 | [diff] [blame] | 5499 | return rc; |
| 5500 | } |
| 5501 | |
| 5502 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5503 | * _base_get_ioc_facts - obtain ioc facts reply and save in ioc |
| 5504 | * @ioc: per adapter object |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5505 | * |
| 5506 | * Returns 0 for success, non-zero for failure. |
| 5507 | */ |
| 5508 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5509 | _base_get_ioc_facts(struct MPT3SAS_ADAPTER *ioc) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5510 | { |
| 5511 | Mpi2IOCFactsRequest_t mpi_request; |
| 5512 | Mpi2IOCFactsReply_t mpi_reply; |
| 5513 | struct mpt3sas_facts *facts; |
| 5514 | int mpi_reply_sz, mpi_request_sz, r; |
| 5515 | |
| 5516 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 5517 | __func__)); |
| 5518 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5519 | r = _base_wait_for_iocstate(ioc, 10); |
Sreekanth Reddy | 4dc8c80 | 2015-06-30 12:24:48 +0530 | [diff] [blame] | 5520 | if (r) { |
| 5521 | dfailprintk(ioc, printk(MPT3SAS_FMT |
| 5522 | "%s: failed getting to correct state\n", |
| 5523 | ioc->name, __func__)); |
| 5524 | return r; |
| 5525 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5526 | mpi_reply_sz = sizeof(Mpi2IOCFactsReply_t); |
| 5527 | mpi_request_sz = sizeof(Mpi2IOCFactsRequest_t); |
| 5528 | memset(&mpi_request, 0, mpi_request_sz); |
| 5529 | mpi_request.Function = MPI2_FUNCTION_IOC_FACTS; |
| 5530 | r = _base_handshake_req_reply_wait(ioc, mpi_request_sz, |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5531 | (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5532 | |
| 5533 | if (r != 0) { |
| 5534 | pr_err(MPT3SAS_FMT "%s: handshake failed (r=%d)\n", |
| 5535 | ioc->name, __func__, r); |
| 5536 | return r; |
| 5537 | } |
| 5538 | |
| 5539 | facts = &ioc->facts; |
| 5540 | memset(facts, 0, sizeof(struct mpt3sas_facts)); |
| 5541 | facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion); |
| 5542 | facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion); |
| 5543 | facts->VP_ID = mpi_reply.VP_ID; |
| 5544 | facts->VF_ID = mpi_reply.VF_ID; |
| 5545 | facts->IOCExceptions = le16_to_cpu(mpi_reply.IOCExceptions); |
| 5546 | facts->MaxChainDepth = mpi_reply.MaxChainDepth; |
| 5547 | facts->WhoInit = mpi_reply.WhoInit; |
| 5548 | facts->NumberOfPorts = mpi_reply.NumberOfPorts; |
| 5549 | facts->MaxMSIxVectors = mpi_reply.MaxMSIxVectors; |
| 5550 | facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit); |
| 5551 | facts->MaxReplyDescriptorPostQueueDepth = |
| 5552 | le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth); |
| 5553 | facts->ProductID = le16_to_cpu(mpi_reply.ProductID); |
| 5554 | facts->IOCCapabilities = le32_to_cpu(mpi_reply.IOCCapabilities); |
| 5555 | if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID)) |
| 5556 | ioc->ir_firmware = 1; |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 5557 | if ((facts->IOCCapabilities & |
Sreekanth Reddy | 06f5f97 | 2017-10-10 18:41:16 +0530 | [diff] [blame] | 5558 | MPI2_IOCFACTS_CAPABILITY_RDPQ_ARRAY_CAPABLE) && (!reset_devices)) |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 5559 | ioc->rdpq_array_capable = 1; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5560 | facts->FWVersion.Word = le32_to_cpu(mpi_reply.FWVersion.Word); |
| 5561 | facts->IOCRequestFrameSize = |
| 5562 | le16_to_cpu(mpi_reply.IOCRequestFrameSize); |
Suganath prabu Subramani | ebb3024 | 2016-01-28 12:07:04 +0530 | [diff] [blame] | 5563 | if (ioc->hba_mpi_version_belonged != MPI2_VERSION) { |
| 5564 | facts->IOCMaxChainSegmentSize = |
| 5565 | le16_to_cpu(mpi_reply.IOCMaxChainSegmentSize); |
| 5566 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5567 | facts->MaxInitiators = le16_to_cpu(mpi_reply.MaxInitiators); |
| 5568 | facts->MaxTargets = le16_to_cpu(mpi_reply.MaxTargets); |
| 5569 | ioc->shost->max_id = -1; |
| 5570 | facts->MaxSasExpanders = le16_to_cpu(mpi_reply.MaxSasExpanders); |
| 5571 | facts->MaxEnclosures = le16_to_cpu(mpi_reply.MaxEnclosures); |
| 5572 | facts->ProtocolFlags = le16_to_cpu(mpi_reply.ProtocolFlags); |
| 5573 | facts->HighPriorityCredit = |
| 5574 | le16_to_cpu(mpi_reply.HighPriorityCredit); |
| 5575 | facts->ReplyFrameSize = mpi_reply.ReplyFrameSize; |
| 5576 | facts->MaxDevHandle = le16_to_cpu(mpi_reply.MaxDevHandle); |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 5577 | facts->CurrentHostPageSize = mpi_reply.CurrentHostPageSize; |
| 5578 | |
| 5579 | /* |
| 5580 | * Get the Page Size from IOC Facts. If it's 0, default to 4k. |
| 5581 | */ |
| 5582 | ioc->page_size = 1 << facts->CurrentHostPageSize; |
| 5583 | if (ioc->page_size == 1) { |
| 5584 | pr_info(MPT3SAS_FMT "CurrentHostPageSize is 0: Setting " |
| 5585 | "default host page size to 4k\n", ioc->name); |
| 5586 | ioc->page_size = 1 << MPT3SAS_HOST_PAGE_SIZE_4K; |
| 5587 | } |
| 5588 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "CurrentHostPageSize(%d)\n", |
| 5589 | ioc->name, facts->CurrentHostPageSize)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5590 | |
| 5591 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 5592 | "hba queue depth(%d), max chains per io(%d)\n", |
| 5593 | ioc->name, facts->RequestCredit, |
| 5594 | facts->MaxChainDepth)); |
| 5595 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 5596 | "request frame size(%d), reply frame size(%d)\n", ioc->name, |
| 5597 | facts->IOCRequestFrameSize * 4, facts->ReplyFrameSize * 4)); |
| 5598 | return 0; |
| 5599 | } |
| 5600 | |
| 5601 | /** |
| 5602 | * _base_send_ioc_init - send ioc_init to firmware |
| 5603 | * @ioc: per adapter object |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5604 | * |
| 5605 | * Returns 0 for success, non-zero for failure. |
| 5606 | */ |
| 5607 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5608 | _base_send_ioc_init(struct MPT3SAS_ADAPTER *ioc) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5609 | { |
| 5610 | Mpi2IOCInitRequest_t mpi_request; |
| 5611 | Mpi2IOCInitReply_t mpi_reply; |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 5612 | int i, r = 0; |
Tina Ruchandani | 23409bd | 2016-04-13 00:01:40 -0700 | [diff] [blame] | 5613 | ktime_t current_time; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5614 | u16 ioc_status; |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 5615 | u32 reply_post_free_array_sz = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5616 | |
| 5617 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 5618 | __func__)); |
| 5619 | |
| 5620 | memset(&mpi_request, 0, sizeof(Mpi2IOCInitRequest_t)); |
| 5621 | mpi_request.Function = MPI2_FUNCTION_IOC_INIT; |
| 5622 | mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER; |
| 5623 | mpi_request.VF_ID = 0; /* TODO */ |
| 5624 | mpi_request.VP_ID = 0; |
Sreekanth Reddy | d357e84 | 2015-11-11 17:30:22 +0530 | [diff] [blame] | 5625 | mpi_request.MsgVersion = cpu_to_le16(ioc->hba_mpi_version_belonged); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5626 | mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION); |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 5627 | mpi_request.HostPageSize = MPT3SAS_HOST_PAGE_SIZE_4K; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5628 | |
| 5629 | if (_base_is_controller_msix_enabled(ioc)) |
| 5630 | mpi_request.HostMSIxVectors = ioc->reply_queue_count; |
| 5631 | mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4); |
| 5632 | mpi_request.ReplyDescriptorPostQueueDepth = |
| 5633 | cpu_to_le16(ioc->reply_post_queue_depth); |
| 5634 | mpi_request.ReplyFreeQueueDepth = |
| 5635 | cpu_to_le16(ioc->reply_free_queue_depth); |
| 5636 | |
| 5637 | mpi_request.SenseBufferAddressHigh = |
| 5638 | cpu_to_le32((u64)ioc->sense_dma >> 32); |
| 5639 | mpi_request.SystemReplyAddressHigh = |
| 5640 | cpu_to_le32((u64)ioc->reply_dma >> 32); |
| 5641 | mpi_request.SystemRequestFrameBaseAddress = |
| 5642 | cpu_to_le64((u64)ioc->request_dma); |
| 5643 | mpi_request.ReplyFreeQueueAddress = |
| 5644 | cpu_to_le64((u64)ioc->reply_free_dma); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5645 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 5646 | if (ioc->rdpq_array_enable) { |
| 5647 | reply_post_free_array_sz = ioc->reply_queue_count * |
| 5648 | sizeof(Mpi2IOCInitRDPQArrayEntry); |
Chaitra P B | cd33223 | 2018-04-24 05:28:31 -0400 | [diff] [blame] | 5649 | memset(ioc->reply_post_free_array, 0, reply_post_free_array_sz); |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 5650 | for (i = 0; i < ioc->reply_queue_count; i++) |
Chaitra P B | cd33223 | 2018-04-24 05:28:31 -0400 | [diff] [blame] | 5651 | ioc->reply_post_free_array[i].RDPQBaseAddress = |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 5652 | cpu_to_le64( |
| 5653 | (u64)ioc->reply_post[i].reply_post_free_dma); |
| 5654 | mpi_request.MsgFlags = MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE; |
| 5655 | mpi_request.ReplyDescriptorPostQueueAddress = |
Chaitra P B | cd33223 | 2018-04-24 05:28:31 -0400 | [diff] [blame] | 5656 | cpu_to_le64((u64)ioc->reply_post_free_array_dma); |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 5657 | } else { |
| 5658 | mpi_request.ReplyDescriptorPostQueueAddress = |
| 5659 | cpu_to_le64((u64)ioc->reply_post[0].reply_post_free_dma); |
| 5660 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5661 | |
| 5662 | /* This time stamp specifies number of milliseconds |
| 5663 | * since epoch ~ midnight January 1, 1970. |
| 5664 | */ |
Tina Ruchandani | 23409bd | 2016-04-13 00:01:40 -0700 | [diff] [blame] | 5665 | current_time = ktime_get_real(); |
| 5666 | mpi_request.TimeStamp = cpu_to_le64(ktime_to_ms(current_time)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5667 | |
| 5668 | if (ioc->logging_level & MPT_DEBUG_INIT) { |
| 5669 | __le32 *mfp; |
| 5670 | int i; |
| 5671 | |
| 5672 | mfp = (__le32 *)&mpi_request; |
| 5673 | pr_info("\toffset:data\n"); |
| 5674 | for (i = 0; i < sizeof(Mpi2IOCInitRequest_t)/4; i++) |
| 5675 | pr_info("\t[0x%02x]:%08x\n", i*4, |
| 5676 | le32_to_cpu(mfp[i])); |
| 5677 | } |
| 5678 | |
| 5679 | r = _base_handshake_req_reply_wait(ioc, |
| 5680 | sizeof(Mpi2IOCInitRequest_t), (u32 *)&mpi_request, |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5681 | sizeof(Mpi2IOCInitReply_t), (u16 *)&mpi_reply, 10); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5682 | |
| 5683 | if (r != 0) { |
| 5684 | pr_err(MPT3SAS_FMT "%s: handshake failed (r=%d)\n", |
| 5685 | ioc->name, __func__, r); |
Chaitra P B | cd33223 | 2018-04-24 05:28:31 -0400 | [diff] [blame] | 5686 | return r; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5687 | } |
| 5688 | |
| 5689 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 5690 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS || |
| 5691 | mpi_reply.IOCLogInfo) { |
| 5692 | pr_err(MPT3SAS_FMT "%s: failed\n", ioc->name, __func__); |
| 5693 | r = -EIO; |
| 5694 | } |
| 5695 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 5696 | return r; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5697 | } |
| 5698 | |
| 5699 | /** |
| 5700 | * mpt3sas_port_enable_done - command completion routine for port enable |
| 5701 | * @ioc: per adapter object |
| 5702 | * @smid: system request message index |
| 5703 | * @msix_index: MSIX table index supplied by the OS |
| 5704 | * @reply: reply message frame(lower 32bit addr) |
| 5705 | * |
| 5706 | * Return 1 meaning mf should be freed from _base_interrupt |
| 5707 | * 0 means the mf is freed from this function. |
| 5708 | */ |
| 5709 | u8 |
| 5710 | mpt3sas_port_enable_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 5711 | u32 reply) |
| 5712 | { |
| 5713 | MPI2DefaultReply_t *mpi_reply; |
| 5714 | u16 ioc_status; |
| 5715 | |
| 5716 | if (ioc->port_enable_cmds.status == MPT3_CMD_NOT_USED) |
| 5717 | return 1; |
| 5718 | |
| 5719 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 5720 | if (!mpi_reply) |
| 5721 | return 1; |
| 5722 | |
| 5723 | if (mpi_reply->Function != MPI2_FUNCTION_PORT_ENABLE) |
| 5724 | return 1; |
| 5725 | |
| 5726 | ioc->port_enable_cmds.status &= ~MPT3_CMD_PENDING; |
| 5727 | ioc->port_enable_cmds.status |= MPT3_CMD_COMPLETE; |
| 5728 | ioc->port_enable_cmds.status |= MPT3_CMD_REPLY_VALID; |
| 5729 | memcpy(ioc->port_enable_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 5730 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 5731 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 5732 | ioc->port_enable_failed = 1; |
| 5733 | |
| 5734 | if (ioc->is_driver_loading) { |
| 5735 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 5736 | mpt3sas_port_enable_complete(ioc); |
| 5737 | return 1; |
| 5738 | } else { |
| 5739 | ioc->start_scan_failed = ioc_status; |
| 5740 | ioc->start_scan = 0; |
| 5741 | return 1; |
| 5742 | } |
| 5743 | } |
| 5744 | complete(&ioc->port_enable_cmds.done); |
| 5745 | return 1; |
| 5746 | } |
| 5747 | |
| 5748 | /** |
| 5749 | * _base_send_port_enable - send port_enable(discovery stuff) to firmware |
| 5750 | * @ioc: per adapter object |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5751 | * |
| 5752 | * Returns 0 for success, non-zero for failure. |
| 5753 | */ |
| 5754 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5755 | _base_send_port_enable(struct MPT3SAS_ADAPTER *ioc) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5756 | { |
| 5757 | Mpi2PortEnableRequest_t *mpi_request; |
| 5758 | Mpi2PortEnableReply_t *mpi_reply; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5759 | int r = 0; |
| 5760 | u16 smid; |
| 5761 | u16 ioc_status; |
| 5762 | |
| 5763 | pr_info(MPT3SAS_FMT "sending port enable !!\n", ioc->name); |
| 5764 | |
| 5765 | if (ioc->port_enable_cmds.status & MPT3_CMD_PENDING) { |
| 5766 | pr_err(MPT3SAS_FMT "%s: internal command already in use\n", |
| 5767 | ioc->name, __func__); |
| 5768 | return -EAGAIN; |
| 5769 | } |
| 5770 | |
| 5771 | smid = mpt3sas_base_get_smid(ioc, ioc->port_enable_cb_idx); |
| 5772 | if (!smid) { |
| 5773 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 5774 | ioc->name, __func__); |
| 5775 | return -EAGAIN; |
| 5776 | } |
| 5777 | |
| 5778 | ioc->port_enable_cmds.status = MPT3_CMD_PENDING; |
| 5779 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 5780 | ioc->port_enable_cmds.smid = smid; |
| 5781 | memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t)); |
| 5782 | mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE; |
| 5783 | |
| 5784 | init_completion(&ioc->port_enable_cmds.done); |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 5785 | mpt3sas_base_put_smid_default(ioc, smid); |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 5786 | wait_for_completion_timeout(&ioc->port_enable_cmds.done, 300*HZ); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5787 | if (!(ioc->port_enable_cmds.status & MPT3_CMD_COMPLETE)) { |
| 5788 | pr_err(MPT3SAS_FMT "%s: timeout\n", |
| 5789 | ioc->name, __func__); |
| 5790 | _debug_dump_mf(mpi_request, |
| 5791 | sizeof(Mpi2PortEnableRequest_t)/4); |
| 5792 | if (ioc->port_enable_cmds.status & MPT3_CMD_RESET) |
| 5793 | r = -EFAULT; |
| 5794 | else |
| 5795 | r = -ETIME; |
| 5796 | goto out; |
| 5797 | } |
| 5798 | |
| 5799 | mpi_reply = ioc->port_enable_cmds.reply; |
| 5800 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 5801 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 5802 | pr_err(MPT3SAS_FMT "%s: failed with (ioc_status=0x%08x)\n", |
| 5803 | ioc->name, __func__, ioc_status); |
| 5804 | r = -EFAULT; |
| 5805 | goto out; |
| 5806 | } |
| 5807 | |
| 5808 | out: |
| 5809 | ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED; |
| 5810 | pr_info(MPT3SAS_FMT "port enable: %s\n", ioc->name, ((r == 0) ? |
| 5811 | "SUCCESS" : "FAILED")); |
| 5812 | return r; |
| 5813 | } |
| 5814 | |
| 5815 | /** |
| 5816 | * mpt3sas_port_enable - initiate firmware discovery (don't wait for reply) |
| 5817 | * @ioc: per adapter object |
| 5818 | * |
| 5819 | * Returns 0 for success, non-zero for failure. |
| 5820 | */ |
| 5821 | int |
| 5822 | mpt3sas_port_enable(struct MPT3SAS_ADAPTER *ioc) |
| 5823 | { |
| 5824 | Mpi2PortEnableRequest_t *mpi_request; |
| 5825 | u16 smid; |
| 5826 | |
| 5827 | pr_info(MPT3SAS_FMT "sending port enable !!\n", ioc->name); |
| 5828 | |
| 5829 | if (ioc->port_enable_cmds.status & MPT3_CMD_PENDING) { |
| 5830 | pr_err(MPT3SAS_FMT "%s: internal command already in use\n", |
| 5831 | ioc->name, __func__); |
| 5832 | return -EAGAIN; |
| 5833 | } |
| 5834 | |
| 5835 | smid = mpt3sas_base_get_smid(ioc, ioc->port_enable_cb_idx); |
| 5836 | if (!smid) { |
| 5837 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 5838 | ioc->name, __func__); |
| 5839 | return -EAGAIN; |
| 5840 | } |
| 5841 | |
| 5842 | ioc->port_enable_cmds.status = MPT3_CMD_PENDING; |
| 5843 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 5844 | ioc->port_enable_cmds.smid = smid; |
| 5845 | memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t)); |
| 5846 | mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE; |
| 5847 | |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 5848 | mpt3sas_base_put_smid_default(ioc, smid); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5849 | return 0; |
| 5850 | } |
| 5851 | |
| 5852 | /** |
| 5853 | * _base_determine_wait_on_discovery - desposition |
| 5854 | * @ioc: per adapter object |
| 5855 | * |
| 5856 | * Decide whether to wait on discovery to complete. Used to either |
| 5857 | * locate boot device, or report volumes ahead of physical devices. |
| 5858 | * |
| 5859 | * Returns 1 for wait, 0 for don't wait |
| 5860 | */ |
| 5861 | static int |
| 5862 | _base_determine_wait_on_discovery(struct MPT3SAS_ADAPTER *ioc) |
| 5863 | { |
| 5864 | /* We wait for discovery to complete if IR firmware is loaded. |
| 5865 | * The sas topology events arrive before PD events, so we need time to |
| 5866 | * turn on the bit in ioc->pd_handles to indicate PD |
| 5867 | * Also, it maybe required to report Volumes ahead of physical |
| 5868 | * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set. |
| 5869 | */ |
| 5870 | if (ioc->ir_firmware) |
| 5871 | return 1; |
| 5872 | |
| 5873 | /* if no Bios, then we don't need to wait */ |
| 5874 | if (!ioc->bios_pg3.BiosVersion) |
| 5875 | return 0; |
| 5876 | |
| 5877 | /* Bios is present, then we drop down here. |
| 5878 | * |
| 5879 | * If there any entries in the Bios Page 2, then we wait |
| 5880 | * for discovery to complete. |
| 5881 | */ |
| 5882 | |
| 5883 | /* Current Boot Device */ |
| 5884 | if ((ioc->bios_pg2.CurrentBootDeviceForm & |
| 5885 | MPI2_BIOSPAGE2_FORM_MASK) == |
| 5886 | MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED && |
| 5887 | /* Request Boot Device */ |
| 5888 | (ioc->bios_pg2.ReqBootDeviceForm & |
| 5889 | MPI2_BIOSPAGE2_FORM_MASK) == |
| 5890 | MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED && |
| 5891 | /* Alternate Request Boot Device */ |
| 5892 | (ioc->bios_pg2.ReqAltBootDeviceForm & |
| 5893 | MPI2_BIOSPAGE2_FORM_MASK) == |
| 5894 | MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED) |
| 5895 | return 0; |
| 5896 | |
| 5897 | return 1; |
| 5898 | } |
| 5899 | |
| 5900 | /** |
| 5901 | * _base_unmask_events - turn on notification for this event |
| 5902 | * @ioc: per adapter object |
| 5903 | * @event: firmware event |
| 5904 | * |
| 5905 | * The mask is stored in ioc->event_masks. |
| 5906 | */ |
| 5907 | static void |
| 5908 | _base_unmask_events(struct MPT3SAS_ADAPTER *ioc, u16 event) |
| 5909 | { |
| 5910 | u32 desired_event; |
| 5911 | |
| 5912 | if (event >= 128) |
| 5913 | return; |
| 5914 | |
| 5915 | desired_event = (1 << (event % 32)); |
| 5916 | |
| 5917 | if (event < 32) |
| 5918 | ioc->event_masks[0] &= ~desired_event; |
| 5919 | else if (event < 64) |
| 5920 | ioc->event_masks[1] &= ~desired_event; |
| 5921 | else if (event < 96) |
| 5922 | ioc->event_masks[2] &= ~desired_event; |
| 5923 | else if (event < 128) |
| 5924 | ioc->event_masks[3] &= ~desired_event; |
| 5925 | } |
| 5926 | |
| 5927 | /** |
| 5928 | * _base_event_notification - send event notification |
| 5929 | * @ioc: per adapter object |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5930 | * |
| 5931 | * Returns 0 for success, non-zero for failure. |
| 5932 | */ |
| 5933 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 5934 | _base_event_notification(struct MPT3SAS_ADAPTER *ioc) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5935 | { |
| 5936 | Mpi2EventNotificationRequest_t *mpi_request; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5937 | u16 smid; |
| 5938 | int r = 0; |
| 5939 | int i; |
| 5940 | |
| 5941 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 5942 | __func__)); |
| 5943 | |
| 5944 | if (ioc->base_cmds.status & MPT3_CMD_PENDING) { |
| 5945 | pr_err(MPT3SAS_FMT "%s: internal command already in use\n", |
| 5946 | ioc->name, __func__); |
| 5947 | return -EAGAIN; |
| 5948 | } |
| 5949 | |
| 5950 | smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); |
| 5951 | if (!smid) { |
| 5952 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 5953 | ioc->name, __func__); |
| 5954 | return -EAGAIN; |
| 5955 | } |
| 5956 | ioc->base_cmds.status = MPT3_CMD_PENDING; |
| 5957 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 5958 | ioc->base_cmds.smid = smid; |
| 5959 | memset(mpi_request, 0, sizeof(Mpi2EventNotificationRequest_t)); |
| 5960 | mpi_request->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; |
| 5961 | mpi_request->VF_ID = 0; /* TODO */ |
| 5962 | mpi_request->VP_ID = 0; |
| 5963 | for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) |
| 5964 | mpi_request->EventMasks[i] = |
| 5965 | cpu_to_le32(ioc->event_masks[i]); |
| 5966 | init_completion(&ioc->base_cmds.done); |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 5967 | mpt3sas_base_put_smid_default(ioc, smid); |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 5968 | wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5969 | if (!(ioc->base_cmds.status & MPT3_CMD_COMPLETE)) { |
| 5970 | pr_err(MPT3SAS_FMT "%s: timeout\n", |
| 5971 | ioc->name, __func__); |
| 5972 | _debug_dump_mf(mpi_request, |
| 5973 | sizeof(Mpi2EventNotificationRequest_t)/4); |
| 5974 | if (ioc->base_cmds.status & MPT3_CMD_RESET) |
| 5975 | r = -EFAULT; |
| 5976 | else |
| 5977 | r = -ETIME; |
| 5978 | } else |
| 5979 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s: complete\n", |
| 5980 | ioc->name, __func__)); |
| 5981 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 5982 | return r; |
| 5983 | } |
| 5984 | |
| 5985 | /** |
| 5986 | * mpt3sas_base_validate_event_type - validating event types |
| 5987 | * @ioc: per adapter object |
| 5988 | * @event: firmware event |
| 5989 | * |
| 5990 | * This will turn on firmware event notification when application |
| 5991 | * ask for that event. We don't mask events that are already enabled. |
| 5992 | */ |
| 5993 | void |
| 5994 | mpt3sas_base_validate_event_type(struct MPT3SAS_ADAPTER *ioc, u32 *event_type) |
| 5995 | { |
| 5996 | int i, j; |
| 5997 | u32 event_mask, desired_event; |
| 5998 | u8 send_update_to_fw; |
| 5999 | |
| 6000 | for (i = 0, send_update_to_fw = 0; i < |
| 6001 | MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) { |
| 6002 | event_mask = ~event_type[i]; |
| 6003 | desired_event = 1; |
| 6004 | for (j = 0; j < 32; j++) { |
| 6005 | if (!(event_mask & desired_event) && |
| 6006 | (ioc->event_masks[i] & desired_event)) { |
| 6007 | ioc->event_masks[i] &= ~desired_event; |
| 6008 | send_update_to_fw = 1; |
| 6009 | } |
| 6010 | desired_event = (desired_event << 1); |
| 6011 | } |
| 6012 | } |
| 6013 | |
| 6014 | if (!send_update_to_fw) |
| 6015 | return; |
| 6016 | |
| 6017 | mutex_lock(&ioc->base_cmds.mutex); |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6018 | _base_event_notification(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6019 | mutex_unlock(&ioc->base_cmds.mutex); |
| 6020 | } |
| 6021 | |
| 6022 | /** |
| 6023 | * _base_diag_reset - the "big hammer" start of day reset |
| 6024 | * @ioc: per adapter object |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6025 | * |
| 6026 | * Returns 0 for success, non-zero for failure. |
| 6027 | */ |
| 6028 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6029 | _base_diag_reset(struct MPT3SAS_ADAPTER *ioc) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6030 | { |
| 6031 | u32 host_diagnostic; |
| 6032 | u32 ioc_state; |
| 6033 | u32 count; |
| 6034 | u32 hcb_size; |
| 6035 | |
| 6036 | pr_info(MPT3SAS_FMT "sending diag reset !!\n", ioc->name); |
| 6037 | |
| 6038 | drsprintk(ioc, pr_info(MPT3SAS_FMT "clear interrupts\n", |
| 6039 | ioc->name)); |
| 6040 | |
| 6041 | count = 0; |
| 6042 | do { |
| 6043 | /* Write magic sequence to WriteSequence register |
| 6044 | * Loop until in diagnostic mode |
| 6045 | */ |
| 6046 | drsprintk(ioc, pr_info(MPT3SAS_FMT |
| 6047 | "write magic sequence\n", ioc->name)); |
| 6048 | writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 6049 | writel(MPI2_WRSEQ_1ST_KEY_VALUE, &ioc->chip->WriteSequence); |
| 6050 | writel(MPI2_WRSEQ_2ND_KEY_VALUE, &ioc->chip->WriteSequence); |
| 6051 | writel(MPI2_WRSEQ_3RD_KEY_VALUE, &ioc->chip->WriteSequence); |
| 6052 | writel(MPI2_WRSEQ_4TH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 6053 | writel(MPI2_WRSEQ_5TH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 6054 | writel(MPI2_WRSEQ_6TH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 6055 | |
| 6056 | /* wait 100 msec */ |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6057 | msleep(100); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6058 | |
| 6059 | if (count++ > 20) |
| 6060 | goto out; |
| 6061 | |
| 6062 | host_diagnostic = readl(&ioc->chip->HostDiagnostic); |
| 6063 | drsprintk(ioc, pr_info(MPT3SAS_FMT |
| 6064 | "wrote magic sequence: count(%d), host_diagnostic(0x%08x)\n", |
| 6065 | ioc->name, count, host_diagnostic)); |
| 6066 | |
| 6067 | } while ((host_diagnostic & MPI2_DIAG_DIAG_WRITE_ENABLE) == 0); |
| 6068 | |
| 6069 | hcb_size = readl(&ioc->chip->HCBSize); |
| 6070 | |
| 6071 | drsprintk(ioc, pr_info(MPT3SAS_FMT "diag reset: issued\n", |
| 6072 | ioc->name)); |
| 6073 | writel(host_diagnostic | MPI2_DIAG_RESET_ADAPTER, |
| 6074 | &ioc->chip->HostDiagnostic); |
| 6075 | |
Sreekanth Reddy | b453ff8 | 2013-06-29 03:51:19 +0530 | [diff] [blame] | 6076 | /*This delay allows the chip PCIe hardware time to finish reset tasks*/ |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6077 | msleep(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC/1000); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6078 | |
Sreekanth Reddy | b453ff8 | 2013-06-29 03:51:19 +0530 | [diff] [blame] | 6079 | /* Approximately 300 second max wait */ |
| 6080 | for (count = 0; count < (300000000 / |
| 6081 | MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC); count++) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6082 | |
| 6083 | host_diagnostic = readl(&ioc->chip->HostDiagnostic); |
| 6084 | |
| 6085 | if (host_diagnostic == 0xFFFFFFFF) |
| 6086 | goto out; |
| 6087 | if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER)) |
| 6088 | break; |
| 6089 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6090 | msleep(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC / 1000); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6091 | } |
| 6092 | |
| 6093 | if (host_diagnostic & MPI2_DIAG_HCB_MODE) { |
| 6094 | |
| 6095 | drsprintk(ioc, pr_info(MPT3SAS_FMT |
| 6096 | "restart the adapter assuming the HCB Address points to good F/W\n", |
| 6097 | ioc->name)); |
| 6098 | host_diagnostic &= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK; |
| 6099 | host_diagnostic |= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW; |
| 6100 | writel(host_diagnostic, &ioc->chip->HostDiagnostic); |
| 6101 | |
| 6102 | drsprintk(ioc, pr_info(MPT3SAS_FMT |
| 6103 | "re-enable the HCDW\n", ioc->name)); |
| 6104 | writel(hcb_size | MPI2_HCB_SIZE_HCB_ENABLE, |
| 6105 | &ioc->chip->HCBSize); |
| 6106 | } |
| 6107 | |
| 6108 | drsprintk(ioc, pr_info(MPT3SAS_FMT "restart the adapter\n", |
| 6109 | ioc->name)); |
| 6110 | writel(host_diagnostic & ~MPI2_DIAG_HOLD_IOC_RESET, |
| 6111 | &ioc->chip->HostDiagnostic); |
| 6112 | |
| 6113 | drsprintk(ioc, pr_info(MPT3SAS_FMT |
| 6114 | "disable writes to the diagnostic register\n", ioc->name)); |
| 6115 | writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 6116 | |
| 6117 | drsprintk(ioc, pr_info(MPT3SAS_FMT |
| 6118 | "Wait for FW to go to the READY state\n", ioc->name)); |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6119 | ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, 20); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6120 | if (ioc_state) { |
| 6121 | pr_err(MPT3SAS_FMT |
| 6122 | "%s: failed going to ready state (ioc_state=0x%x)\n", |
| 6123 | ioc->name, __func__, ioc_state); |
| 6124 | goto out; |
| 6125 | } |
| 6126 | |
| 6127 | pr_info(MPT3SAS_FMT "diag reset: SUCCESS\n", ioc->name); |
| 6128 | return 0; |
| 6129 | |
| 6130 | out: |
| 6131 | pr_err(MPT3SAS_FMT "diag reset: FAILED\n", ioc->name); |
| 6132 | return -EFAULT; |
| 6133 | } |
| 6134 | |
| 6135 | /** |
| 6136 | * _base_make_ioc_ready - put controller in READY state |
| 6137 | * @ioc: per adapter object |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6138 | * @type: FORCE_BIG_HAMMER or SOFT_RESET |
| 6139 | * |
| 6140 | * Returns 0 for success, non-zero for failure. |
| 6141 | */ |
| 6142 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6143 | _base_make_ioc_ready(struct MPT3SAS_ADAPTER *ioc, enum reset_type type) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6144 | { |
| 6145 | u32 ioc_state; |
| 6146 | int rc; |
| 6147 | int count; |
| 6148 | |
| 6149 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 6150 | __func__)); |
| 6151 | |
| 6152 | if (ioc->pci_error_recovery) |
| 6153 | return 0; |
| 6154 | |
| 6155 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); |
| 6156 | dhsprintk(ioc, pr_info(MPT3SAS_FMT "%s: ioc_state(0x%08x)\n", |
| 6157 | ioc->name, __func__, ioc_state)); |
| 6158 | |
| 6159 | /* if in RESET state, it should move to READY state shortly */ |
| 6160 | count = 0; |
| 6161 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_RESET) { |
| 6162 | while ((ioc_state & MPI2_IOC_STATE_MASK) != |
| 6163 | MPI2_IOC_STATE_READY) { |
| 6164 | if (count++ == 10) { |
| 6165 | pr_err(MPT3SAS_FMT |
| 6166 | "%s: failed going to ready state (ioc_state=0x%x)\n", |
| 6167 | ioc->name, __func__, ioc_state); |
| 6168 | return -EFAULT; |
| 6169 | } |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6170 | ssleep(1); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6171 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); |
| 6172 | } |
| 6173 | } |
| 6174 | |
| 6175 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY) |
| 6176 | return 0; |
| 6177 | |
| 6178 | if (ioc_state & MPI2_DOORBELL_USED) { |
| 6179 | dhsprintk(ioc, pr_info(MPT3SAS_FMT |
| 6180 | "unexpected doorbell active!\n", |
| 6181 | ioc->name)); |
| 6182 | goto issue_diag_reset; |
| 6183 | } |
| 6184 | |
| 6185 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 6186 | mpt3sas_base_fault_info(ioc, ioc_state & |
| 6187 | MPI2_DOORBELL_DATA_MASK); |
| 6188 | goto issue_diag_reset; |
| 6189 | } |
| 6190 | |
| 6191 | if (type == FORCE_BIG_HAMMER) |
| 6192 | goto issue_diag_reset; |
| 6193 | |
| 6194 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL) |
| 6195 | if (!(_base_send_ioc_reset(ioc, |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6196 | MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET, 15))) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6197 | return 0; |
| 6198 | } |
| 6199 | |
| 6200 | issue_diag_reset: |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6201 | rc = _base_diag_reset(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6202 | return rc; |
| 6203 | } |
| 6204 | |
| 6205 | /** |
| 6206 | * _base_make_ioc_operational - put controller in OPERATIONAL state |
| 6207 | * @ioc: per adapter object |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6208 | * |
| 6209 | * Returns 0 for success, non-zero for failure. |
| 6210 | */ |
| 6211 | static int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6212 | _base_make_ioc_operational(struct MPT3SAS_ADAPTER *ioc) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6213 | { |
Calvin Owens | 5ec8a17 | 2016-03-18 12:45:42 -0700 | [diff] [blame] | 6214 | int r, i, index; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6215 | unsigned long flags; |
| 6216 | u32 reply_address; |
| 6217 | u16 smid; |
| 6218 | struct _tr_list *delayed_tr, *delayed_tr_next; |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 6219 | struct _sc_list *delayed_sc, *delayed_sc_next; |
| 6220 | struct _event_ack_list *delayed_event_ack, *delayed_event_ack_next; |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 6221 | u8 hide_flag; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6222 | struct adapter_reply_queue *reply_q; |
Calvin Owens | 5ec8a17 | 2016-03-18 12:45:42 -0700 | [diff] [blame] | 6223 | Mpi2ReplyDescriptorsUnion_t *reply_post_free_contig; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6224 | |
| 6225 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 6226 | __func__)); |
| 6227 | |
| 6228 | /* clean the delayed target reset list */ |
| 6229 | list_for_each_entry_safe(delayed_tr, delayed_tr_next, |
| 6230 | &ioc->delayed_tr_list, list) { |
| 6231 | list_del(&delayed_tr->list); |
| 6232 | kfree(delayed_tr); |
| 6233 | } |
| 6234 | |
| 6235 | |
| 6236 | list_for_each_entry_safe(delayed_tr, delayed_tr_next, |
| 6237 | &ioc->delayed_tr_volume_list, list) { |
| 6238 | list_del(&delayed_tr->list); |
| 6239 | kfree(delayed_tr); |
| 6240 | } |
| 6241 | |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 6242 | list_for_each_entry_safe(delayed_sc, delayed_sc_next, |
| 6243 | &ioc->delayed_sc_list, list) { |
| 6244 | list_del(&delayed_sc->list); |
| 6245 | kfree(delayed_sc); |
| 6246 | } |
| 6247 | |
| 6248 | list_for_each_entry_safe(delayed_event_ack, delayed_event_ack_next, |
| 6249 | &ioc->delayed_event_ack_list, list) { |
| 6250 | list_del(&delayed_event_ack->list); |
| 6251 | kfree(delayed_event_ack); |
| 6252 | } |
| 6253 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6254 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6255 | |
| 6256 | /* hi-priority queue */ |
| 6257 | INIT_LIST_HEAD(&ioc->hpr_free_list); |
| 6258 | smid = ioc->hi_priority_smid; |
| 6259 | for (i = 0; i < ioc->hi_priority_depth; i++, smid++) { |
| 6260 | ioc->hpr_lookup[i].cb_idx = 0xFF; |
| 6261 | ioc->hpr_lookup[i].smid = smid; |
| 6262 | list_add_tail(&ioc->hpr_lookup[i].tracker_list, |
| 6263 | &ioc->hpr_free_list); |
| 6264 | } |
| 6265 | |
| 6266 | /* internal queue */ |
| 6267 | INIT_LIST_HEAD(&ioc->internal_free_list); |
| 6268 | smid = ioc->internal_smid; |
| 6269 | for (i = 0; i < ioc->internal_depth; i++, smid++) { |
| 6270 | ioc->internal_lookup[i].cb_idx = 0xFF; |
| 6271 | ioc->internal_lookup[i].smid = smid; |
| 6272 | list_add_tail(&ioc->internal_lookup[i].tracker_list, |
| 6273 | &ioc->internal_free_list); |
| 6274 | } |
| 6275 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6276 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 6277 | |
| 6278 | /* initialize Reply Free Queue */ |
| 6279 | for (i = 0, reply_address = (u32)ioc->reply_dma ; |
| 6280 | i < ioc->reply_free_queue_depth ; i++, reply_address += |
Suganath Prabu Subramani | b4472d7 | 2018-02-07 02:51:50 -0800 | [diff] [blame] | 6281 | ioc->reply_sz) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6282 | ioc->reply_free[i] = cpu_to_le32(reply_address); |
Suganath Prabu Subramani | b4472d7 | 2018-02-07 02:51:50 -0800 | [diff] [blame] | 6283 | if (ioc->is_mcpu_endpoint) |
| 6284 | _base_clone_reply_to_sys_mem(ioc, |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 6285 | reply_address, i); |
Suganath Prabu Subramani | b4472d7 | 2018-02-07 02:51:50 -0800 | [diff] [blame] | 6286 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6287 | |
| 6288 | /* initialize reply queues */ |
| 6289 | if (ioc->is_driver_loading) |
| 6290 | _base_assign_reply_queues(ioc); |
| 6291 | |
| 6292 | /* initialize Reply Post Free Queue */ |
Calvin Owens | 5ec8a17 | 2016-03-18 12:45:42 -0700 | [diff] [blame] | 6293 | index = 0; |
| 6294 | reply_post_free_contig = ioc->reply_post[0].reply_post_free; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6295 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { |
Calvin Owens | 5ec8a17 | 2016-03-18 12:45:42 -0700 | [diff] [blame] | 6296 | /* |
| 6297 | * If RDPQ is enabled, switch to the next allocation. |
| 6298 | * Otherwise advance within the contiguous region. |
| 6299 | */ |
| 6300 | if (ioc->rdpq_array_enable) { |
| 6301 | reply_q->reply_post_free = |
| 6302 | ioc->reply_post[index++].reply_post_free; |
| 6303 | } else { |
| 6304 | reply_q->reply_post_free = reply_post_free_contig; |
| 6305 | reply_post_free_contig += ioc->reply_post_queue_depth; |
| 6306 | } |
| 6307 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6308 | reply_q->reply_post_host_index = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6309 | for (i = 0; i < ioc->reply_post_queue_depth; i++) |
| 6310 | reply_q->reply_post_free[i].Words = |
| 6311 | cpu_to_le64(ULLONG_MAX); |
| 6312 | if (!_base_is_controller_msix_enabled(ioc)) |
| 6313 | goto skip_init_reply_post_free_queue; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6314 | } |
| 6315 | skip_init_reply_post_free_queue: |
| 6316 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6317 | r = _base_send_ioc_init(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6318 | if (r) |
| 6319 | return r; |
| 6320 | |
| 6321 | /* initialize reply free host index */ |
| 6322 | ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1; |
| 6323 | writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex); |
| 6324 | |
| 6325 | /* initialize reply post host index */ |
| 6326 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { |
Suganath Prabu Subramani | 0bb337c | 2016-10-26 13:34:38 +0530 | [diff] [blame] | 6327 | if (ioc->combined_reply_queue) |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 6328 | writel((reply_q->msix_index & 7)<< |
| 6329 | MPI2_RPHI_MSIX_INDEX_SHIFT, |
| 6330 | ioc->replyPostRegisterIndex[reply_q->msix_index/8]); |
| 6331 | else |
| 6332 | writel(reply_q->msix_index << |
| 6333 | MPI2_RPHI_MSIX_INDEX_SHIFT, |
| 6334 | &ioc->chip->ReplyPostHostIndex); |
| 6335 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6336 | if (!_base_is_controller_msix_enabled(ioc)) |
| 6337 | goto skip_init_reply_post_host_index; |
| 6338 | } |
| 6339 | |
| 6340 | skip_init_reply_post_host_index: |
| 6341 | |
| 6342 | _base_unmask_interrupts(ioc); |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6343 | r = _base_event_notification(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6344 | if (r) |
| 6345 | return r; |
| 6346 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6347 | _base_static_config_pages(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6348 | |
| 6349 | if (ioc->is_driver_loading) { |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 6350 | |
| 6351 | if (ioc->is_warpdrive && ioc->manu_pg10.OEMIdentifier |
| 6352 | == 0x80) { |
| 6353 | hide_flag = (u8) ( |
| 6354 | le32_to_cpu(ioc->manu_pg10.OEMSpecificFlags0) & |
| 6355 | MFG_PAGE10_HIDE_SSDS_MASK); |
| 6356 | if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK) |
| 6357 | ioc->mfg_pg10_hide_flag = hide_flag; |
| 6358 | } |
| 6359 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6360 | ioc->wait_for_discovery_to_complete = |
| 6361 | _base_determine_wait_on_discovery(ioc); |
| 6362 | |
| 6363 | return r; /* scan_start and scan_finished support */ |
| 6364 | } |
| 6365 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6366 | r = _base_send_port_enable(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6367 | if (r) |
| 6368 | return r; |
| 6369 | |
| 6370 | return r; |
| 6371 | } |
| 6372 | |
| 6373 | /** |
| 6374 | * mpt3sas_base_free_resources - free resources controller resources |
| 6375 | * @ioc: per adapter object |
| 6376 | * |
| 6377 | * Return nothing. |
| 6378 | */ |
| 6379 | void |
| 6380 | mpt3sas_base_free_resources(struct MPT3SAS_ADAPTER *ioc) |
| 6381 | { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6382 | dexitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 6383 | __func__)); |
| 6384 | |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 6385 | /* synchronizing freeing resource with pci_access_mutex lock */ |
| 6386 | mutex_lock(&ioc->pci_access_mutex); |
Joe Lawrence | cf9bd21a | 2013-08-08 16:45:39 -0400 | [diff] [blame] | 6387 | if (ioc->chip_phys && ioc->chip) { |
| 6388 | _base_mask_interrupts(ioc); |
| 6389 | ioc->shost_recovery = 1; |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6390 | _base_make_ioc_ready(ioc, SOFT_RESET); |
Joe Lawrence | cf9bd21a | 2013-08-08 16:45:39 -0400 | [diff] [blame] | 6391 | ioc->shost_recovery = 0; |
| 6392 | } |
| 6393 | |
Sreekanth Reddy | 580d4e3 | 2015-06-30 12:24:50 +0530 | [diff] [blame] | 6394 | mpt3sas_base_unmap_resources(ioc); |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 6395 | mutex_unlock(&ioc->pci_access_mutex); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6396 | return; |
| 6397 | } |
| 6398 | |
| 6399 | /** |
| 6400 | * mpt3sas_base_attach - attach controller instance |
| 6401 | * @ioc: per adapter object |
| 6402 | * |
| 6403 | * Returns 0 for success, non-zero for failure. |
| 6404 | */ |
| 6405 | int |
| 6406 | mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc) |
| 6407 | { |
| 6408 | int r, i; |
| 6409 | int cpu_id, last_cpu_id = 0; |
| 6410 | |
| 6411 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 6412 | __func__)); |
| 6413 | |
| 6414 | /* setup cpu_msix_table */ |
| 6415 | ioc->cpu_count = num_online_cpus(); |
| 6416 | for_each_online_cpu(cpu_id) |
| 6417 | last_cpu_id = cpu_id; |
| 6418 | ioc->cpu_msix_table_sz = last_cpu_id + 1; |
| 6419 | ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL); |
| 6420 | ioc->reply_queue_count = 1; |
| 6421 | if (!ioc->cpu_msix_table) { |
| 6422 | dfailprintk(ioc, pr_info(MPT3SAS_FMT |
| 6423 | "allocation for cpu_msix_table failed!!!\n", |
| 6424 | ioc->name)); |
| 6425 | r = -ENOMEM; |
| 6426 | goto out_free_resources; |
| 6427 | } |
| 6428 | |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 6429 | if (ioc->is_warpdrive) { |
| 6430 | ioc->reply_post_host_index = kcalloc(ioc->cpu_msix_table_sz, |
| 6431 | sizeof(resource_size_t *), GFP_KERNEL); |
| 6432 | if (!ioc->reply_post_host_index) { |
| 6433 | dfailprintk(ioc, pr_info(MPT3SAS_FMT "allocation " |
Hannes Reinecke | 1d55abc | 2017-02-22 11:31:41 +0100 | [diff] [blame] | 6434 | "for reply_post_host_index failed!!!\n", |
| 6435 | ioc->name)); |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 6436 | r = -ENOMEM; |
| 6437 | goto out_free_resources; |
| 6438 | } |
| 6439 | } |
| 6440 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 6441 | ioc->rdpq_array_enable_assigned = 0; |
| 6442 | ioc->dma_mask = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6443 | r = mpt3sas_base_map_resources(ioc); |
| 6444 | if (r) |
| 6445 | goto out_free_resources; |
| 6446 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6447 | pci_set_drvdata(ioc->pdev, ioc->shost); |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6448 | r = _base_get_ioc_facts(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6449 | if (r) |
| 6450 | goto out_free_resources; |
| 6451 | |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 6452 | switch (ioc->hba_mpi_version_belonged) { |
| 6453 | case MPI2_VERSION: |
| 6454 | ioc->build_sg_scmd = &_base_build_sg_scmd; |
| 6455 | ioc->build_sg = &_base_build_sg; |
| 6456 | ioc->build_zero_len_sge = &_base_build_zero_len_sge; |
| 6457 | break; |
| 6458 | case MPI25_VERSION: |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 6459 | case MPI26_VERSION: |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 6460 | /* |
| 6461 | * In SAS3.0, |
| 6462 | * SCSI_IO, SMP_PASSTHRU, SATA_PASSTHRU, Target Assist, and |
| 6463 | * Target Status - all require the IEEE formated scatter gather |
| 6464 | * elements. |
| 6465 | */ |
| 6466 | ioc->build_sg_scmd = &_base_build_sg_scmd_ieee; |
| 6467 | ioc->build_sg = &_base_build_sg_ieee; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 6468 | ioc->build_nvme_prp = &_base_build_nvme_prp; |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 6469 | ioc->build_zero_len_sge = &_base_build_zero_len_sge_ieee; |
| 6470 | ioc->sge_size_ieee = sizeof(Mpi2IeeeSgeSimple64_t); |
Suganath Prabu Subramani | 81c16f8 | 2016-10-26 13:34:40 +0530 | [diff] [blame] | 6471 | |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 6472 | break; |
| 6473 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6474 | |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 6475 | if (ioc->is_mcpu_endpoint) |
| 6476 | ioc->put_smid_scsi_io = &_base_put_smid_mpi_ep_scsi_io; |
| 6477 | else |
| 6478 | ioc->put_smid_scsi_io = &_base_put_smid_scsi_io; |
Suganath Prabu Subramani | 81c16f8 | 2016-10-26 13:34:40 +0530 | [diff] [blame] | 6479 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6480 | /* |
| 6481 | * These function pointers for other requests that don't |
| 6482 | * the require IEEE scatter gather elements. |
| 6483 | * |
| 6484 | * For example Configuration Pages and SAS IOUNIT Control don't. |
| 6485 | */ |
| 6486 | ioc->build_sg_mpi = &_base_build_sg; |
| 6487 | ioc->build_zero_len_sge_mpi = &_base_build_zero_len_sge; |
| 6488 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6489 | r = _base_make_ioc_ready(ioc, SOFT_RESET); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6490 | if (r) |
| 6491 | goto out_free_resources; |
| 6492 | |
| 6493 | ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts, |
| 6494 | sizeof(struct mpt3sas_port_facts), GFP_KERNEL); |
| 6495 | if (!ioc->pfacts) { |
| 6496 | r = -ENOMEM; |
| 6497 | goto out_free_resources; |
| 6498 | } |
| 6499 | |
| 6500 | for (i = 0 ; i < ioc->facts.NumberOfPorts; i++) { |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6501 | r = _base_get_port_facts(ioc, i); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6502 | if (r) |
| 6503 | goto out_free_resources; |
| 6504 | } |
| 6505 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6506 | r = _base_allocate_memory_pools(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6507 | if (r) |
| 6508 | goto out_free_resources; |
| 6509 | |
| 6510 | init_waitqueue_head(&ioc->reset_wq); |
| 6511 | |
| 6512 | /* allocate memory pd handle bitmask list */ |
| 6513 | ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8); |
| 6514 | if (ioc->facts.MaxDevHandle % 8) |
| 6515 | ioc->pd_handles_sz++; |
| 6516 | ioc->pd_handles = kzalloc(ioc->pd_handles_sz, |
| 6517 | GFP_KERNEL); |
| 6518 | if (!ioc->pd_handles) { |
| 6519 | r = -ENOMEM; |
| 6520 | goto out_free_resources; |
| 6521 | } |
| 6522 | ioc->blocking_handles = kzalloc(ioc->pd_handles_sz, |
| 6523 | GFP_KERNEL); |
| 6524 | if (!ioc->blocking_handles) { |
| 6525 | r = -ENOMEM; |
| 6526 | goto out_free_resources; |
| 6527 | } |
| 6528 | |
Suganath Prabu Subramani | c696f7b | 2016-10-26 13:34:34 +0530 | [diff] [blame] | 6529 | /* allocate memory for pending OS device add list */ |
| 6530 | ioc->pend_os_device_add_sz = (ioc->facts.MaxDevHandle / 8); |
| 6531 | if (ioc->facts.MaxDevHandle % 8) |
| 6532 | ioc->pend_os_device_add_sz++; |
| 6533 | ioc->pend_os_device_add = kzalloc(ioc->pend_os_device_add_sz, |
| 6534 | GFP_KERNEL); |
| 6535 | if (!ioc->pend_os_device_add) |
| 6536 | goto out_free_resources; |
| 6537 | |
| 6538 | ioc->device_remove_in_progress_sz = ioc->pend_os_device_add_sz; |
| 6539 | ioc->device_remove_in_progress = |
| 6540 | kzalloc(ioc->device_remove_in_progress_sz, GFP_KERNEL); |
| 6541 | if (!ioc->device_remove_in_progress) |
| 6542 | goto out_free_resources; |
| 6543 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6544 | ioc->fwfault_debug = mpt3sas_fwfault_debug; |
| 6545 | |
| 6546 | /* base internal command bits */ |
| 6547 | mutex_init(&ioc->base_cmds.mutex); |
| 6548 | ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 6549 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 6550 | |
| 6551 | /* port_enable command bits */ |
| 6552 | ioc->port_enable_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 6553 | ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED; |
| 6554 | |
| 6555 | /* transport internal command bits */ |
| 6556 | ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 6557 | ioc->transport_cmds.status = MPT3_CMD_NOT_USED; |
| 6558 | mutex_init(&ioc->transport_cmds.mutex); |
| 6559 | |
| 6560 | /* scsih internal command bits */ |
| 6561 | ioc->scsih_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 6562 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; |
| 6563 | mutex_init(&ioc->scsih_cmds.mutex); |
| 6564 | |
| 6565 | /* task management internal command bits */ |
| 6566 | ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 6567 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; |
| 6568 | mutex_init(&ioc->tm_cmds.mutex); |
| 6569 | |
| 6570 | /* config page internal command bits */ |
| 6571 | ioc->config_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 6572 | ioc->config_cmds.status = MPT3_CMD_NOT_USED; |
| 6573 | mutex_init(&ioc->config_cmds.mutex); |
| 6574 | |
| 6575 | /* ctl module internal command bits */ |
| 6576 | ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 6577 | ioc->ctl_cmds.sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); |
| 6578 | ioc->ctl_cmds.status = MPT3_CMD_NOT_USED; |
| 6579 | mutex_init(&ioc->ctl_cmds.mutex); |
| 6580 | |
Christophe JAILLET | a5dd7ef | 2017-08-07 00:51:29 +0200 | [diff] [blame] | 6581 | if (!ioc->base_cmds.reply || !ioc->port_enable_cmds.reply || |
| 6582 | !ioc->transport_cmds.reply || !ioc->scsih_cmds.reply || |
| 6583 | !ioc->tm_cmds.reply || !ioc->config_cmds.reply || |
| 6584 | !ioc->ctl_cmds.reply || !ioc->ctl_cmds.sense) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6585 | r = -ENOMEM; |
| 6586 | goto out_free_resources; |
| 6587 | } |
| 6588 | |
| 6589 | for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) |
| 6590 | ioc->event_masks[i] = -1; |
| 6591 | |
| 6592 | /* here we enable the events we care about */ |
| 6593 | _base_unmask_events(ioc, MPI2_EVENT_SAS_DISCOVERY); |
| 6594 | _base_unmask_events(ioc, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE); |
| 6595 | _base_unmask_events(ioc, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST); |
| 6596 | _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); |
| 6597 | _base_unmask_events(ioc, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE); |
| 6598 | _base_unmask_events(ioc, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST); |
| 6599 | _base_unmask_events(ioc, MPI2_EVENT_IR_VOLUME); |
| 6600 | _base_unmask_events(ioc, MPI2_EVENT_IR_PHYSICAL_DISK); |
| 6601 | _base_unmask_events(ioc, MPI2_EVENT_IR_OPERATION_STATUS); |
| 6602 | _base_unmask_events(ioc, MPI2_EVENT_LOG_ENTRY_ADDED); |
Sreekanth Reddy | 2d8ce8c | 2015-01-12 11:38:56 +0530 | [diff] [blame] | 6603 | _base_unmask_events(ioc, MPI2_EVENT_TEMP_THRESHOLD); |
Sreekanth Reddy | b99b199 | 2017-10-10 18:41:14 +0530 | [diff] [blame] | 6604 | _base_unmask_events(ioc, MPI2_EVENT_ACTIVE_CABLE_EXCEPTION); |
Chaitra P B | 95540b8 | 2018-04-24 05:28:35 -0400 | [diff] [blame^] | 6605 | _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR); |
Suganath Prabu Subramani | 4318c73 | 2017-10-31 18:02:32 +0530 | [diff] [blame] | 6606 | if (ioc->hba_mpi_version_belonged == MPI26_VERSION) { |
| 6607 | if (ioc->is_gen35_ioc) { |
| 6608 | _base_unmask_events(ioc, |
| 6609 | MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE); |
| 6610 | _base_unmask_events(ioc, MPI2_EVENT_PCIE_ENUMERATION); |
| 6611 | _base_unmask_events(ioc, |
| 6612 | MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST); |
| 6613 | } |
| 6614 | } |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6615 | r = _base_make_ioc_operational(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6616 | if (r) |
| 6617 | goto out_free_resources; |
| 6618 | |
Sreekanth Reddy | 16e179b | 2015-11-11 17:30:27 +0530 | [diff] [blame] | 6619 | ioc->non_operational_loop = 0; |
Chaitra P B | 459325c | 2017-01-23 15:26:08 +0530 | [diff] [blame] | 6620 | ioc->got_task_abort_from_ioctl = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6621 | return 0; |
| 6622 | |
| 6623 | out_free_resources: |
| 6624 | |
| 6625 | ioc->remove_host = 1; |
| 6626 | |
| 6627 | mpt3sas_base_free_resources(ioc); |
| 6628 | _base_release_memory_pools(ioc); |
| 6629 | pci_set_drvdata(ioc->pdev, NULL); |
| 6630 | kfree(ioc->cpu_msix_table); |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 6631 | if (ioc->is_warpdrive) |
| 6632 | kfree(ioc->reply_post_host_index); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6633 | kfree(ioc->pd_handles); |
| 6634 | kfree(ioc->blocking_handles); |
Suganath Prabu Subramani | c696f7b | 2016-10-26 13:34:34 +0530 | [diff] [blame] | 6635 | kfree(ioc->device_remove_in_progress); |
| 6636 | kfree(ioc->pend_os_device_add); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6637 | kfree(ioc->tm_cmds.reply); |
| 6638 | kfree(ioc->transport_cmds.reply); |
| 6639 | kfree(ioc->scsih_cmds.reply); |
| 6640 | kfree(ioc->config_cmds.reply); |
| 6641 | kfree(ioc->base_cmds.reply); |
| 6642 | kfree(ioc->port_enable_cmds.reply); |
| 6643 | kfree(ioc->ctl_cmds.reply); |
| 6644 | kfree(ioc->ctl_cmds.sense); |
| 6645 | kfree(ioc->pfacts); |
| 6646 | ioc->ctl_cmds.reply = NULL; |
| 6647 | ioc->base_cmds.reply = NULL; |
| 6648 | ioc->tm_cmds.reply = NULL; |
| 6649 | ioc->scsih_cmds.reply = NULL; |
| 6650 | ioc->transport_cmds.reply = NULL; |
| 6651 | ioc->config_cmds.reply = NULL; |
| 6652 | ioc->pfacts = NULL; |
| 6653 | return r; |
| 6654 | } |
| 6655 | |
| 6656 | |
| 6657 | /** |
| 6658 | * mpt3sas_base_detach - remove controller instance |
| 6659 | * @ioc: per adapter object |
| 6660 | * |
| 6661 | * Return nothing. |
| 6662 | */ |
| 6663 | void |
| 6664 | mpt3sas_base_detach(struct MPT3SAS_ADAPTER *ioc) |
| 6665 | { |
| 6666 | dexitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 6667 | __func__)); |
| 6668 | |
| 6669 | mpt3sas_base_stop_watchdog(ioc); |
| 6670 | mpt3sas_base_free_resources(ioc); |
| 6671 | _base_release_memory_pools(ioc); |
| 6672 | pci_set_drvdata(ioc->pdev, NULL); |
| 6673 | kfree(ioc->cpu_msix_table); |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 6674 | if (ioc->is_warpdrive) |
| 6675 | kfree(ioc->reply_post_host_index); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6676 | kfree(ioc->pd_handles); |
| 6677 | kfree(ioc->blocking_handles); |
Suganath Prabu Subramani | c696f7b | 2016-10-26 13:34:34 +0530 | [diff] [blame] | 6678 | kfree(ioc->device_remove_in_progress); |
| 6679 | kfree(ioc->pend_os_device_add); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6680 | kfree(ioc->pfacts); |
| 6681 | kfree(ioc->ctl_cmds.reply); |
| 6682 | kfree(ioc->ctl_cmds.sense); |
| 6683 | kfree(ioc->base_cmds.reply); |
| 6684 | kfree(ioc->port_enable_cmds.reply); |
| 6685 | kfree(ioc->tm_cmds.reply); |
| 6686 | kfree(ioc->transport_cmds.reply); |
| 6687 | kfree(ioc->scsih_cmds.reply); |
| 6688 | kfree(ioc->config_cmds.reply); |
| 6689 | } |
| 6690 | |
| 6691 | /** |
| 6692 | * _base_reset_handler - reset callback handler (for base) |
| 6693 | * @ioc: per adapter object |
| 6694 | * @reset_phase: phase |
| 6695 | * |
| 6696 | * The handler for doing any required cleanup or initialization. |
| 6697 | * |
| 6698 | * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET, |
| 6699 | * MPT3_IOC_DONE_RESET |
| 6700 | * |
| 6701 | * Return nothing. |
| 6702 | */ |
| 6703 | static void |
| 6704 | _base_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase) |
| 6705 | { |
| 6706 | mpt3sas_scsih_reset_handler(ioc, reset_phase); |
| 6707 | mpt3sas_ctl_reset_handler(ioc, reset_phase); |
| 6708 | switch (reset_phase) { |
| 6709 | case MPT3_IOC_PRE_RESET: |
| 6710 | dtmprintk(ioc, pr_info(MPT3SAS_FMT |
| 6711 | "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__)); |
| 6712 | break; |
| 6713 | case MPT3_IOC_AFTER_RESET: |
| 6714 | dtmprintk(ioc, pr_info(MPT3SAS_FMT |
| 6715 | "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__)); |
| 6716 | if (ioc->transport_cmds.status & MPT3_CMD_PENDING) { |
| 6717 | ioc->transport_cmds.status |= MPT3_CMD_RESET; |
| 6718 | mpt3sas_base_free_smid(ioc, ioc->transport_cmds.smid); |
| 6719 | complete(&ioc->transport_cmds.done); |
| 6720 | } |
| 6721 | if (ioc->base_cmds.status & MPT3_CMD_PENDING) { |
| 6722 | ioc->base_cmds.status |= MPT3_CMD_RESET; |
| 6723 | mpt3sas_base_free_smid(ioc, ioc->base_cmds.smid); |
| 6724 | complete(&ioc->base_cmds.done); |
| 6725 | } |
| 6726 | if (ioc->port_enable_cmds.status & MPT3_CMD_PENDING) { |
| 6727 | ioc->port_enable_failed = 1; |
| 6728 | ioc->port_enable_cmds.status |= MPT3_CMD_RESET; |
| 6729 | mpt3sas_base_free_smid(ioc, ioc->port_enable_cmds.smid); |
| 6730 | if (ioc->is_driver_loading) { |
| 6731 | ioc->start_scan_failed = |
| 6732 | MPI2_IOCSTATUS_INTERNAL_ERROR; |
| 6733 | ioc->start_scan = 0; |
| 6734 | ioc->port_enable_cmds.status = |
| 6735 | MPT3_CMD_NOT_USED; |
| 6736 | } else |
| 6737 | complete(&ioc->port_enable_cmds.done); |
| 6738 | } |
| 6739 | if (ioc->config_cmds.status & MPT3_CMD_PENDING) { |
| 6740 | ioc->config_cmds.status |= MPT3_CMD_RESET; |
| 6741 | mpt3sas_base_free_smid(ioc, ioc->config_cmds.smid); |
| 6742 | ioc->config_cmds.smid = USHRT_MAX; |
| 6743 | complete(&ioc->config_cmds.done); |
| 6744 | } |
| 6745 | break; |
| 6746 | case MPT3_IOC_DONE_RESET: |
| 6747 | dtmprintk(ioc, pr_info(MPT3SAS_FMT |
| 6748 | "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__)); |
| 6749 | break; |
| 6750 | } |
| 6751 | } |
| 6752 | |
| 6753 | /** |
Sreekanth Reddy | c666d3b | 2018-02-16 20:39:58 -0200 | [diff] [blame] | 6754 | * mpt3sas_wait_for_commands_to_complete - reset controller |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6755 | * @ioc: Pointer to MPT_ADAPTER structure |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6756 | * |
Hannes Reinecke | 272e253 | 2018-01-04 04:57:10 -0800 | [diff] [blame] | 6757 | * This function is waiting 10s for all pending commands to complete |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6758 | * prior to putting controller in reset. |
| 6759 | */ |
Sreekanth Reddy | c666d3b | 2018-02-16 20:39:58 -0200 | [diff] [blame] | 6760 | void |
| 6761 | mpt3sas_wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6762 | { |
| 6763 | u32 ioc_state; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6764 | |
| 6765 | ioc->pending_io_count = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6766 | |
| 6767 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); |
| 6768 | if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL) |
| 6769 | return; |
| 6770 | |
| 6771 | /* pending command count */ |
Hannes Reinecke | 272e253 | 2018-01-04 04:57:10 -0800 | [diff] [blame] | 6772 | ioc->pending_io_count = atomic_read(&ioc->shost->host_busy); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6773 | |
| 6774 | if (!ioc->pending_io_count) |
| 6775 | return; |
| 6776 | |
| 6777 | /* wait for pending commands to complete */ |
| 6778 | wait_event_timeout(ioc->reset_wq, ioc->pending_io_count == 0, 10 * HZ); |
| 6779 | } |
| 6780 | |
| 6781 | /** |
| 6782 | * mpt3sas_base_hard_reset_handler - reset controller |
| 6783 | * @ioc: Pointer to MPT_ADAPTER structure |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6784 | * @type: FORCE_BIG_HAMMER or SOFT_RESET |
| 6785 | * |
| 6786 | * Returns 0 for success, non-zero for failure. |
| 6787 | */ |
| 6788 | int |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6789 | mpt3sas_base_hard_reset_handler(struct MPT3SAS_ADAPTER *ioc, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6790 | enum reset_type type) |
| 6791 | { |
| 6792 | int r; |
| 6793 | unsigned long flags; |
| 6794 | u32 ioc_state; |
| 6795 | u8 is_fault = 0, is_trigger = 0; |
| 6796 | |
| 6797 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name, |
| 6798 | __func__)); |
| 6799 | |
| 6800 | if (ioc->pci_error_recovery) { |
| 6801 | pr_err(MPT3SAS_FMT "%s: pci error recovery reset\n", |
| 6802 | ioc->name, __func__); |
| 6803 | r = 0; |
| 6804 | goto out_unlocked; |
| 6805 | } |
| 6806 | |
| 6807 | if (mpt3sas_fwfault_debug) |
| 6808 | mpt3sas_halt_firmware(ioc); |
| 6809 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6810 | /* wait for an active reset in progress to complete */ |
| 6811 | if (!mutex_trylock(&ioc->reset_in_progress_mutex)) { |
| 6812 | do { |
| 6813 | ssleep(1); |
| 6814 | } while (ioc->shost_recovery == 1); |
| 6815 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name, |
| 6816 | __func__)); |
| 6817 | return ioc->ioc_reset_in_progress_status; |
| 6818 | } |
| 6819 | |
| 6820 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 6821 | ioc->shost_recovery = 1; |
| 6822 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 6823 | |
| 6824 | if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & |
| 6825 | MPT3_DIAG_BUFFER_IS_REGISTERED) && |
| 6826 | (!(ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & |
| 6827 | MPT3_DIAG_BUFFER_IS_RELEASED))) { |
| 6828 | is_trigger = 1; |
| 6829 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); |
| 6830 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) |
| 6831 | is_fault = 1; |
| 6832 | } |
| 6833 | _base_reset_handler(ioc, MPT3_IOC_PRE_RESET); |
Sreekanth Reddy | c666d3b | 2018-02-16 20:39:58 -0200 | [diff] [blame] | 6834 | mpt3sas_wait_for_commands_to_complete(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6835 | _base_mask_interrupts(ioc); |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6836 | r = _base_make_ioc_ready(ioc, type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6837 | if (r) |
| 6838 | goto out; |
| 6839 | _base_reset_handler(ioc, MPT3_IOC_AFTER_RESET); |
| 6840 | |
| 6841 | /* If this hard reset is called while port enable is active, then |
| 6842 | * there is no reason to call make_ioc_operational |
| 6843 | */ |
| 6844 | if (ioc->is_driver_loading && ioc->port_enable_failed) { |
| 6845 | ioc->remove_host = 1; |
| 6846 | r = -EFAULT; |
| 6847 | goto out; |
| 6848 | } |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6849 | r = _base_get_ioc_facts(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6850 | if (r) |
| 6851 | goto out; |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 6852 | |
| 6853 | if (ioc->rdpq_array_enable && !ioc->rdpq_array_capable) |
| 6854 | panic("%s: Issue occurred with flashing controller firmware." |
| 6855 | "Please reboot the system and ensure that the correct" |
| 6856 | " firmware version is running\n", ioc->name); |
| 6857 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 6858 | r = _base_make_ioc_operational(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 6859 | if (!r) |
| 6860 | _base_reset_handler(ioc, MPT3_IOC_DONE_RESET); |
| 6861 | |
| 6862 | out: |
| 6863 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "%s: %s\n", |
| 6864 | ioc->name, __func__, ((r == 0) ? "SUCCESS" : "FAILED"))); |
| 6865 | |
| 6866 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 6867 | ioc->ioc_reset_in_progress_status = r; |
| 6868 | ioc->shost_recovery = 0; |
| 6869 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 6870 | ioc->ioc_reset_count++; |
| 6871 | mutex_unlock(&ioc->reset_in_progress_mutex); |
| 6872 | |
| 6873 | out_unlocked: |
| 6874 | if ((r == 0) && is_trigger) { |
| 6875 | if (is_fault) |
| 6876 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_FW_FAULT); |
| 6877 | else |
| 6878 | mpt3sas_trigger_master(ioc, |
| 6879 | MASTER_TRIGGER_ADAPTER_RESET); |
| 6880 | } |
| 6881 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name, |
| 6882 | __func__)); |
| 6883 | return r; |
| 6884 | } |