| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 128bdda | 2018-01-30 15:59:03 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term * |
James Smart | 3e21d1c | 2018-05-04 20:37:59 -0700 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 12 | * modify it under the terms of version 2 of the GNU General * |
| 13 | * Public License as published by the Free Software Foundation. * |
| 14 | * This program is distributed in the hope that it will be useful. * |
| 15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 20 | * more details, a copy of which can be found in the file COPYING * |
| 21 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
| 23 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/blkdev.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 29 | #include <linux/lockdep.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 30 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 31 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | #include <scsi/scsi_cmnd.h> |
| 33 | #include <scsi/scsi_device.h> |
| 34 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 35 | #include <scsi/scsi_transport_fc.h> |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 36 | #include <scsi/fc/fc_fs.h> |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 37 | #include <linux/aer.h> |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 38 | #ifdef CONFIG_X86 |
| 39 | #include <asm/set_memory.h> |
| 40 | #endif |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 42 | #include <linux/nvme-fc-driver.h> |
| 43 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 44 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | #include "lpfc_hw.h" |
| 46 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 47 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 48 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 50 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 51 | #include "lpfc_scsi.h" |
| 52 | #include "lpfc_nvme.h" |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 53 | #include "lpfc_nvmet.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | #include "lpfc_crtn.h" |
| 55 | #include "lpfc_logmsg.h" |
| 56 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 57 | #include "lpfc_debugfs.h" |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 58 | #include "lpfc_vport.h" |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 59 | #include "lpfc_version.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 60 | |
| 61 | /* There are only four IOCB completion types. */ |
| 62 | typedef enum _lpfc_iocb_type { |
| 63 | LPFC_UNKNOWN_IOCB, |
| 64 | LPFC_UNSOL_IOCB, |
| 65 | LPFC_SOL_IOCB, |
| 66 | LPFC_ABORT_IOCB |
| 67 | } lpfc_iocb_type; |
| 68 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 69 | |
| 70 | /* Provide function prototypes local to this module. */ |
| 71 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, |
| 72 | uint32_t); |
| 73 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 74 | uint8_t *, uint32_t *); |
| 75 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, |
| 76 | struct lpfc_iocbq *); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 77 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
| 78 | struct hbq_dmabuf *); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 79 | static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 80 | struct hbq_dmabuf *dmabuf); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 81 | static int lpfc_sli4_fp_handle_cqe(struct lpfc_hba *, struct lpfc_queue *, |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 82 | struct lpfc_cqe *); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 83 | static int lpfc_sli4_post_sgl_list(struct lpfc_hba *, struct list_head *, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 84 | int); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 85 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, |
| 86 | struct lpfc_eqe *eqe, uint32_t qidx); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 87 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
| 88 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 89 | static int lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, |
| 90 | struct lpfc_sli_ring *pring, |
| 91 | struct lpfc_iocbq *cmdiocb); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 92 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 93 | static IOCB_t * |
| 94 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 95 | { |
| 96 | return &iocbq->iocb; |
| 97 | } |
| 98 | |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 99 | #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN) |
| 100 | /** |
| 101 | * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function |
| 102 | * @srcp: Source memory pointer. |
| 103 | * @destp: Destination memory pointer. |
| 104 | * @cnt: Number of words required to be copied. |
| 105 | * Must be a multiple of sizeof(uint64_t) |
| 106 | * |
| 107 | * This function is used for copying data between driver memory |
| 108 | * and the SLI WQ. This function also changes the endianness |
| 109 | * of each word if native endianness is different from SLI |
| 110 | * endianness. This function can be called with or without |
| 111 | * lock. |
| 112 | **/ |
| 113 | void |
| 114 | lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 115 | { |
| 116 | uint64_t *src = srcp; |
| 117 | uint64_t *dest = destp; |
| 118 | int i; |
| 119 | |
| 120 | for (i = 0; i < (int)cnt; i += sizeof(uint64_t)) |
| 121 | *dest++ = *src++; |
| 122 | } |
| 123 | #else |
| 124 | #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c) |
| 125 | #endif |
| 126 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 127 | /** |
| 128 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 129 | * @q: The Work Queue to operate on. |
| 130 | * @wqe: The work Queue Entry to put on the Work queue. |
| 131 | * |
| 132 | * This routine will copy the contents of @wqe to the next available entry on |
| 133 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 134 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 135 | * successful. If no entries are available on @q then this function will return |
| 136 | * -ENOMEM. |
| 137 | * The caller is expected to hold the hbalock when calling this routine. |
| 138 | **/ |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 139 | static int |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 140 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 141 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 142 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 143 | struct lpfc_register doorbell; |
| 144 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 145 | uint32_t idx; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 146 | uint32_t i = 0; |
| 147 | uint8_t *tmp; |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame] | 148 | u32 if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 149 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 150 | /* sanity check on queue memory */ |
| 151 | if (unlikely(!q)) |
| 152 | return -ENOMEM; |
| 153 | temp_wqe = q->qe[q->host_index].wqe; |
| 154 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 155 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 156 | idx = ((q->host_index + 1) % q->entry_count); |
| 157 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 158 | q->WQ_overflow++; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 159 | return -EBUSY; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 160 | } |
| 161 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 162 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 163 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 164 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | 04673e3 | 2018-01-30 15:58:45 -0800 | [diff] [blame] | 165 | else |
| 166 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 0); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 167 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 168 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 169 | lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 170 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 171 | /* write to DPP aperture taking advatage of Combined Writes */ |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 172 | tmp = (uint8_t *)temp_wqe; |
| 173 | #ifdef __raw_writeq |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 174 | for (i = 0; i < q->entry_size; i += sizeof(uint64_t)) |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 175 | __raw_writeq(*((uint64_t *)(tmp + i)), |
| 176 | q->dpp_regaddr + i); |
| 177 | #else |
| 178 | for (i = 0; i < q->entry_size; i += sizeof(uint32_t)) |
| 179 | __raw_writel(*((uint32_t *)(tmp + i)), |
| 180 | q->dpp_regaddr + i); |
| 181 | #endif |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 182 | } |
| 183 | /* ensure WQE bcopy and DPP flushed before doorbell write */ |
James Smart | 6b3b3bd | 2016-12-19 15:07:30 -0800 | [diff] [blame] | 184 | wmb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 185 | |
| 186 | /* Update the host index before invoking device */ |
| 187 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 188 | |
| 189 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 190 | |
| 191 | /* Ring Doorbell */ |
| 192 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 193 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 194 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 195 | bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1); |
| 196 | bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1); |
| 197 | bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell, |
| 198 | q->dpp_id); |
| 199 | bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell, |
| 200 | q->queue_id); |
| 201 | } else { |
| 202 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 203 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame] | 204 | |
| 205 | /* Leave bits <23:16> clear for if_type 6 dpp */ |
| 206 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 207 | &q->phba->sli4_hba.sli_intf); |
| 208 | if (if_type != LPFC_SLI_INTF_IF_TYPE_6) |
| 209 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, |
| 210 | host_index); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 211 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 212 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 213 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 214 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 215 | } else { |
| 216 | return -EINVAL; |
| 217 | } |
| 218 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 219 | |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 225 | * @q: The Work Queue to operate on. |
| 226 | * @index: The index to advance the hba index to. |
| 227 | * |
| 228 | * This routine will update the HBA index of a queue to reflect consumption of |
| 229 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 230 | * an entry the host calls this function to update the queue's internal |
| 231 | * pointers. This routine returns the number of entries that were consumed by |
| 232 | * the HBA. |
| 233 | **/ |
| 234 | static uint32_t |
| 235 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 236 | { |
| 237 | uint32_t released = 0; |
| 238 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 239 | /* sanity check on queue memory */ |
| 240 | if (unlikely(!q)) |
| 241 | return 0; |
| 242 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 243 | if (q->hba_index == index) |
| 244 | return 0; |
| 245 | do { |
| 246 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 247 | released++; |
| 248 | } while (q->hba_index != index); |
| 249 | return released; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 254 | * @q: The Mailbox Queue to operate on. |
| 255 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 256 | * |
| 257 | * This routine will copy the contents of @mqe to the next available entry on |
| 258 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 259 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 260 | * successful. If no entries are available on @q then this function will return |
| 261 | * -ENOMEM. |
| 262 | * The caller is expected to hold the hbalock when calling this routine. |
| 263 | **/ |
| 264 | static uint32_t |
| 265 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 266 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 267 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 268 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 269 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 270 | /* sanity check on queue memory */ |
| 271 | if (unlikely(!q)) |
| 272 | return -ENOMEM; |
| 273 | temp_mqe = q->qe[q->host_index].mqe; |
| 274 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 275 | /* If the host has not yet processed the next entry then we are done */ |
| 276 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 277 | return -ENOMEM; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 278 | lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 279 | /* Save off the mailbox pointer for completion */ |
| 280 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 281 | |
| 282 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 283 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 284 | |
| 285 | /* Ring Doorbell */ |
| 286 | doorbell.word0 = 0; |
| 287 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 288 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 289 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 295 | * @q: The Mailbox Queue to operate on. |
| 296 | * |
| 297 | * This routine will update the HBA index of a queue to reflect consumption of |
| 298 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 299 | * an entry the host calls this function to update the queue's internal |
| 300 | * pointers. This routine returns the number of entries that were consumed by |
| 301 | * the HBA. |
| 302 | **/ |
| 303 | static uint32_t |
| 304 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 305 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 306 | /* sanity check on queue memory */ |
| 307 | if (unlikely(!q)) |
| 308 | return 0; |
| 309 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 310 | /* Clear the mailbox pointer for completion */ |
| 311 | q->phba->mbox = NULL; |
| 312 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 313 | return 1; |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 318 | * @q: The Event Queue to get the first valid EQE from |
| 319 | * |
| 320 | * This routine will get the first valid Event Queue Entry from @q, update |
| 321 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 322 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 323 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 324 | **/ |
| 325 | static struct lpfc_eqe * |
| 326 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 327 | { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 328 | struct lpfc_hba *phba; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 329 | struct lpfc_eqe *eqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 330 | uint32_t idx; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 331 | |
| 332 | /* sanity check on queue memory */ |
| 333 | if (unlikely(!q)) |
| 334 | return NULL; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 335 | phba = q->phba; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 336 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 337 | |
| 338 | /* If the next EQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 339 | if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 340 | return NULL; |
| 341 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 342 | idx = ((q->hba_index + 1) % q->entry_count); |
| 343 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 344 | return NULL; |
| 345 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 346 | q->hba_index = idx; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 347 | /* if the index wrapped around, toggle the valid bit */ |
| 348 | if (phba->sli4_hba.pc_sli4_params.eqav && !q->hba_index) |
| 349 | q->qe_valid = (q->qe_valid) ? 0 : 1; |
| 350 | |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 351 | |
| 352 | /* |
| 353 | * insert barrier for instruction interlock : data from the hardware |
| 354 | * must have the valid bit checked before it can be copied and acted |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 355 | * upon. Speculative instructions were allowing a bcopy at the start |
| 356 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 357 | * after our return, to copy data before the valid bit check above |
| 358 | * was done. As such, some of the copied data was stale. The barrier |
| 359 | * ensures the check is before any data is copied. |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 360 | */ |
| 361 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 362 | return eqe; |
| 363 | } |
| 364 | |
| 365 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 366 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 367 | * @q: The Event Queue to disable interrupts |
| 368 | * |
| 369 | **/ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 370 | inline void |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 371 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 372 | { |
| 373 | struct lpfc_register doorbell; |
| 374 | |
| 375 | doorbell.word0 = 0; |
| 376 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 377 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 378 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 379 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 380 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 381 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 385 | * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ |
| 386 | * @q: The Event Queue to disable interrupts |
| 387 | * |
| 388 | **/ |
| 389 | inline void |
| 390 | lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q) |
| 391 | { |
| 392 | struct lpfc_register doorbell; |
| 393 | |
| 394 | doorbell.word0 = 0; |
James Smart | aad59d5 | 2018-09-10 10:30:47 -0700 | [diff] [blame] | 395 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 396 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 397 | } |
| 398 | |
| 399 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 400 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 401 | * @q: The Event Queue that the host has completed processing for. |
| 402 | * @arm: Indicates whether the host wants to arms this CQ. |
| 403 | * |
| 404 | * This routine will mark all Event Queue Entries on @q, from the last |
| 405 | * known completed entry to the last entry that was processed, as completed |
| 406 | * by clearing the valid bit for each completion queue entry. Then it will |
| 407 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 408 | * The internal host index in the @q will be updated by this routine to indicate |
| 409 | * that the host has finished processing the entries. The @arm parameter |
| 410 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 411 | * |
| 412 | * This function will return the number of EQEs that were popped. |
| 413 | **/ |
| 414 | uint32_t |
| 415 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 416 | { |
| 417 | uint32_t released = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 418 | struct lpfc_hba *phba; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 419 | struct lpfc_eqe *temp_eqe; |
| 420 | struct lpfc_register doorbell; |
| 421 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 422 | /* sanity check on queue memory */ |
| 423 | if (unlikely(!q)) |
| 424 | return 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 425 | phba = q->phba; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 426 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 427 | /* while there are valid entries */ |
| 428 | while (q->hba_index != q->host_index) { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 429 | if (!phba->sli4_hba.pc_sli4_params.eqav) { |
| 430 | temp_eqe = q->qe[q->host_index].eqe; |
| 431 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
| 432 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 433 | released++; |
| 434 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 435 | } |
| 436 | if (unlikely(released == 0 && !arm)) |
| 437 | return 0; |
| 438 | |
| 439 | /* ring doorbell for number popped */ |
| 440 | doorbell.word0 = 0; |
| 441 | if (arm) { |
| 442 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 443 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 444 | } |
| 445 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 446 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 447 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 448 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 449 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 450 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 451 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 452 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 453 | readl(q->phba->sli4_hba.EQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 454 | return released; |
| 455 | } |
| 456 | |
| 457 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 458 | * lpfc_sli4_if6_eq_release - Indicates the host has finished processing an EQ |
| 459 | * @q: The Event Queue that the host has completed processing for. |
| 460 | * @arm: Indicates whether the host wants to arms this CQ. |
| 461 | * |
| 462 | * This routine will mark all Event Queue Entries on @q, from the last |
| 463 | * known completed entry to the last entry that was processed, as completed |
| 464 | * by clearing the valid bit for each completion queue entry. Then it will |
| 465 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 466 | * The internal host index in the @q will be updated by this routine to indicate |
| 467 | * that the host has finished processing the entries. The @arm parameter |
| 468 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 469 | * |
| 470 | * This function will return the number of EQEs that were popped. |
| 471 | **/ |
| 472 | uint32_t |
| 473 | lpfc_sli4_if6_eq_release(struct lpfc_queue *q, bool arm) |
| 474 | { |
| 475 | uint32_t released = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 476 | struct lpfc_hba *phba; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 477 | struct lpfc_eqe *temp_eqe; |
| 478 | struct lpfc_register doorbell; |
| 479 | |
| 480 | /* sanity check on queue memory */ |
| 481 | if (unlikely(!q)) |
| 482 | return 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 483 | phba = q->phba; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 484 | |
| 485 | /* while there are valid entries */ |
| 486 | while (q->hba_index != q->host_index) { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 487 | if (!phba->sli4_hba.pc_sli4_params.eqav) { |
| 488 | temp_eqe = q->qe[q->host_index].eqe; |
| 489 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
| 490 | } |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 491 | released++; |
| 492 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 493 | } |
| 494 | if (unlikely(released == 0 && !arm)) |
| 495 | return 0; |
| 496 | |
| 497 | /* ring doorbell for number popped */ |
| 498 | doorbell.word0 = 0; |
| 499 | if (arm) |
| 500 | bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1); |
| 501 | bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, released); |
| 502 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
| 503 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 504 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 505 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 506 | readl(q->phba->sli4_hba.EQDBregaddr); |
| 507 | return released; |
| 508 | } |
| 509 | |
| 510 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 511 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 512 | * @q: The Completion Queue to get the first valid CQE from |
| 513 | * |
| 514 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 515 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 516 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 517 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 518 | **/ |
| 519 | static struct lpfc_cqe * |
| 520 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 521 | { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 522 | struct lpfc_hba *phba; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 523 | struct lpfc_cqe *cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 524 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 525 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 526 | /* sanity check on queue memory */ |
| 527 | if (unlikely(!q)) |
| 528 | return NULL; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 529 | phba = q->phba; |
| 530 | cqe = q->qe[q->hba_index].cqe; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 531 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 532 | /* If the next CQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 533 | if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 534 | return NULL; |
| 535 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 536 | idx = ((q->hba_index + 1) % q->entry_count); |
| 537 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 538 | return NULL; |
| 539 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 540 | q->hba_index = idx; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 541 | /* if the index wrapped around, toggle the valid bit */ |
| 542 | if (phba->sli4_hba.pc_sli4_params.cqav && !q->hba_index) |
| 543 | q->qe_valid = (q->qe_valid) ? 0 : 1; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 544 | |
| 545 | /* |
| 546 | * insert barrier for instruction interlock : data from the hardware |
| 547 | * must have the valid bit checked before it can be copied and acted |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 548 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 549 | * instructions allowing action on content before valid bit checked, |
| 550 | * add barrier here as well. May not be needed as "content" is a |
| 551 | * single 32-bit entity here (vs multi word structure for cq's). |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 552 | */ |
| 553 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 554 | return cqe; |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 559 | * @q: The Completion Queue that the host has completed processing for. |
| 560 | * @arm: Indicates whether the host wants to arms this CQ. |
| 561 | * |
| 562 | * This routine will mark all Completion queue entries on @q, from the last |
| 563 | * known completed entry to the last entry that was processed, as completed |
| 564 | * by clearing the valid bit for each completion queue entry. Then it will |
| 565 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 566 | * The internal host index in the @q will be updated by this routine to indicate |
| 567 | * that the host has finished processing the entries. The @arm parameter |
| 568 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 569 | * |
| 570 | * This function will return the number of CQEs that were released. |
| 571 | **/ |
| 572 | uint32_t |
| 573 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 574 | { |
| 575 | uint32_t released = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 576 | struct lpfc_hba *phba; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 577 | struct lpfc_cqe *temp_qe; |
| 578 | struct lpfc_register doorbell; |
| 579 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 580 | /* sanity check on queue memory */ |
| 581 | if (unlikely(!q)) |
| 582 | return 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 583 | phba = q->phba; |
| 584 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 585 | /* while there are valid entries */ |
| 586 | while (q->hba_index != q->host_index) { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 587 | if (!phba->sli4_hba.pc_sli4_params.cqav) { |
| 588 | temp_qe = q->qe[q->host_index].cqe; |
| 589 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
| 590 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 591 | released++; |
| 592 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 593 | } |
| 594 | if (unlikely(released == 0 && !arm)) |
| 595 | return 0; |
| 596 | |
| 597 | /* ring doorbell for number popped */ |
| 598 | doorbell.word0 = 0; |
| 599 | if (arm) |
| 600 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 601 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 602 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 603 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 604 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 605 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 606 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 607 | return released; |
| 608 | } |
| 609 | |
| 610 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 611 | * lpfc_sli4_if6_cq_release - Indicates the host has finished processing a CQ |
| 612 | * @q: The Completion Queue that the host has completed processing for. |
| 613 | * @arm: Indicates whether the host wants to arms this CQ. |
| 614 | * |
| 615 | * This routine will mark all Completion queue entries on @q, from the last |
| 616 | * known completed entry to the last entry that was processed, as completed |
| 617 | * by clearing the valid bit for each completion queue entry. Then it will |
| 618 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 619 | * The internal host index in the @q will be updated by this routine to indicate |
| 620 | * that the host has finished processing the entries. The @arm parameter |
| 621 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 622 | * |
| 623 | * This function will return the number of CQEs that were released. |
| 624 | **/ |
| 625 | uint32_t |
| 626 | lpfc_sli4_if6_cq_release(struct lpfc_queue *q, bool arm) |
| 627 | { |
| 628 | uint32_t released = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 629 | struct lpfc_hba *phba; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 630 | struct lpfc_cqe *temp_qe; |
| 631 | struct lpfc_register doorbell; |
| 632 | |
| 633 | /* sanity check on queue memory */ |
| 634 | if (unlikely(!q)) |
| 635 | return 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 636 | phba = q->phba; |
| 637 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 638 | /* while there are valid entries */ |
| 639 | while (q->hba_index != q->host_index) { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 640 | if (!phba->sli4_hba.pc_sli4_params.cqav) { |
| 641 | temp_qe = q->qe[q->host_index].cqe; |
| 642 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
| 643 | } |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 644 | released++; |
| 645 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 646 | } |
| 647 | if (unlikely(released == 0 && !arm)) |
| 648 | return 0; |
| 649 | |
| 650 | /* ring doorbell for number popped */ |
| 651 | doorbell.word0 = 0; |
| 652 | if (arm) |
| 653 | bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1); |
| 654 | bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, released); |
| 655 | bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id); |
| 656 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
| 657 | return released; |
| 658 | } |
| 659 | |
| 660 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 661 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 662 | * @q: The Header Receive Queue to operate on. |
| 663 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 664 | * |
| 665 | * This routine will copy the contents of @wqe to the next available entry on |
| 666 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 667 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 668 | * index that the rqe was copied to if successful. If no entries are available |
| 669 | * on @q then this function will return -ENOMEM. |
| 670 | * The caller is expected to hold the hbalock when calling this routine. |
| 671 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 672 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 673 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 674 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 675 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 676 | struct lpfc_rqe *temp_hrqe; |
| 677 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 678 | struct lpfc_register doorbell; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 679 | int hq_put_index; |
| 680 | int dq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 681 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 682 | /* sanity check on queue memory */ |
| 683 | if (unlikely(!hq) || unlikely(!dq)) |
| 684 | return -ENOMEM; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 685 | hq_put_index = hq->host_index; |
| 686 | dq_put_index = dq->host_index; |
| 687 | temp_hrqe = hq->qe[hq_put_index].rqe; |
| 688 | temp_drqe = dq->qe[dq_put_index].rqe; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 689 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 690 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 691 | return -EINVAL; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 692 | if (hq_put_index != dq_put_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 693 | return -EINVAL; |
| 694 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 695 | if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 696 | return -EBUSY; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 697 | lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 698 | lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 699 | |
| 700 | /* Update the host index to point to the next slot */ |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 701 | hq->host_index = ((hq_put_index + 1) % hq->entry_count); |
| 702 | dq->host_index = ((dq_put_index + 1) % dq->entry_count); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 703 | hq->RQ_buf_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 704 | |
| 705 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 706 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 707 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 708 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 709 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
| 710 | hq->entry_repost); |
| 711 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 712 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 713 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
| 714 | hq->entry_repost); |
| 715 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 716 | hq->host_index); |
| 717 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 718 | } else { |
| 719 | return -EINVAL; |
| 720 | } |
| 721 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 722 | } |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 723 | return hq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | /** |
| 727 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 728 | * @q: The Header Receive Queue to operate on. |
| 729 | * |
| 730 | * This routine will update the HBA index of a queue to reflect consumption of |
| 731 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 732 | * consumed an entry the host calls this function to update the queue's |
| 733 | * internal pointers. This routine returns the number of entries that were |
| 734 | * consumed by the HBA. |
| 735 | **/ |
| 736 | static uint32_t |
| 737 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 738 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 739 | /* sanity check on queue memory */ |
| 740 | if (unlikely(!hq) || unlikely(!dq)) |
| 741 | return 0; |
| 742 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 743 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 744 | return 0; |
| 745 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 746 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 747 | return 1; |
| 748 | } |
| 749 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 750 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 751 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 752 | * @phba: Pointer to HBA context object. |
| 753 | * @pring: Pointer to driver SLI ring object. |
| 754 | * |
| 755 | * This function returns pointer to next command iocb entry |
| 756 | * in the command ring. The caller must hold hbalock to prevent |
| 757 | * other threads consume the next command iocb. |
| 758 | * SLI-2/SLI-3 provide different sized iocbs. |
| 759 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 760 | static inline IOCB_t * |
| 761 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 762 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 763 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 764 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 765 | } |
| 766 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 767 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 768 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 769 | * @phba: Pointer to HBA context object. |
| 770 | * @pring: Pointer to driver SLI ring object. |
| 771 | * |
| 772 | * This function returns pointer to next response iocb entry |
| 773 | * in the response ring. The caller must hold hbalock to make sure |
| 774 | * that no other thread consume the next response iocb. |
| 775 | * SLI-2/SLI-3 provide different sized iocbs. |
| 776 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 777 | static inline IOCB_t * |
| 778 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 779 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 780 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 781 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 782 | } |
| 783 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 784 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 785 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 786 | * @phba: Pointer to HBA context object. |
| 787 | * |
| 788 | * This function is called with hbalock held. This function |
| 789 | * allocates a new driver iocb object from the iocb pool. If the |
| 790 | * allocation is successful, it returns pointer to the newly |
| 791 | * allocated iocb object else it returns NULL. |
| 792 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 793 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 794 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 795 | { |
| 796 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 797 | struct lpfc_iocbq * iocbq = NULL; |
| 798 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 799 | lockdep_assert_held(&phba->hbalock); |
| 800 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 801 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 802 | if (iocbq) |
| 803 | phba->iocb_cnt++; |
| 804 | if (phba->iocb_cnt > phba->iocb_max) |
| 805 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 806 | return iocbq; |
| 807 | } |
| 808 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 809 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 810 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 811 | * @phba: Pointer to HBA context object. |
| 812 | * @xritag: XRI value. |
| 813 | * |
| 814 | * This function clears the sglq pointer from the array of acive |
| 815 | * sglq's. The xritag that is passed in is used to index into the |
| 816 | * array. Before the xritag can be used it needs to be adjusted |
| 817 | * by subtracting the xribase. |
| 818 | * |
| 819 | * Returns sglq ponter = success, NULL = Failure. |
| 820 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 821 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 822 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 823 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 824 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 825 | |
| 826 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 827 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 828 | return sglq; |
| 829 | } |
| 830 | |
| 831 | /** |
| 832 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 833 | * @phba: Pointer to HBA context object. |
| 834 | * @xritag: XRI value. |
| 835 | * |
| 836 | * This function returns the sglq pointer from the array of acive |
| 837 | * sglq's. The xritag that is passed in is used to index into the |
| 838 | * array. Before the xritag can be used it needs to be adjusted |
| 839 | * by subtracting the xribase. |
| 840 | * |
| 841 | * Returns sglq ponter = success, NULL = Failure. |
| 842 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 843 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 844 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 845 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 846 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 847 | |
| 848 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 849 | return sglq; |
| 850 | } |
| 851 | |
| 852 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 853 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 854 | * @phba: Pointer to HBA context object. |
| 855 | * @xritag: xri used in this exchange. |
| 856 | * @rrq: The RRQ to be cleared. |
| 857 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 858 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 859 | void |
| 860 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 861 | uint16_t xritag, |
| 862 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 863 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 864 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 865 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 866 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 867 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 868 | |
| 869 | /* The target DID could have been swapped (cable swap) |
| 870 | * we should use the ndlp from the findnode if it is |
| 871 | * available. |
| 872 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 873 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 874 | ndlp = rrq->ndlp; |
| 875 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 876 | if (!ndlp) |
| 877 | goto out; |
| 878 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 879 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 880 | rrq->send_rrq = 0; |
| 881 | rrq->xritag = 0; |
| 882 | rrq->rrq_stop_time = 0; |
| 883 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 884 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 885 | mempool_free(rrq, phba->rrq_pool); |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 890 | * @phba: Pointer to HBA context object. |
| 891 | * |
| 892 | * This function is called with hbalock held. This function |
| 893 | * Checks if stop_time (ratov from setting rrq active) has |
| 894 | * been reached, if it has and the send_rrq flag is set then |
| 895 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 896 | * then it will just call the routine to clear the rrq and |
| 897 | * free the rrq resource. |
| 898 | * The timer is set to the next rrq that is going to expire before |
| 899 | * leaving the routine. |
| 900 | * |
| 901 | **/ |
| 902 | void |
| 903 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 904 | { |
| 905 | struct lpfc_node_rrq *rrq; |
| 906 | struct lpfc_node_rrq *nextrrq; |
| 907 | unsigned long next_time; |
| 908 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 909 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 910 | |
| 911 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 912 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 913 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 914 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 915 | &phba->active_rrq_list, list) { |
| 916 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 917 | list_move(&rrq->list, &send_rrq); |
| 918 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 919 | next_time = rrq->rrq_stop_time; |
| 920 | } |
| 921 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 922 | if ((!list_empty(&phba->active_rrq_list)) && |
| 923 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 924 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 925 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 926 | list_del(&rrq->list); |
| 927 | if (!rrq->send_rrq) |
| 928 | /* this call will free the rrq */ |
| 929 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 930 | else if (lpfc_send_rrq(phba, rrq)) { |
| 931 | /* if we send the rrq then the completion handler |
| 932 | * will clear the bit in the xribitmap. |
| 933 | */ |
| 934 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 935 | rrq); |
| 936 | } |
| 937 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | /** |
| 941 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 942 | * @vport: Pointer to vport context object. |
| 943 | * @xri: The xri used in the exchange. |
| 944 | * @did: The targets DID for this exchange. |
| 945 | * |
| 946 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 947 | * rrq = rrq for this xri and target. |
| 948 | **/ |
| 949 | struct lpfc_node_rrq * |
| 950 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 951 | { |
| 952 | struct lpfc_hba *phba = vport->phba; |
| 953 | struct lpfc_node_rrq *rrq; |
| 954 | struct lpfc_node_rrq *nextrrq; |
| 955 | unsigned long iflags; |
| 956 | |
| 957 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 958 | return NULL; |
| 959 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 960 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 961 | if (rrq->vport == vport && rrq->xritag == xri && |
| 962 | rrq->nlp_DID == did){ |
| 963 | list_del(&rrq->list); |
| 964 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 965 | return rrq; |
| 966 | } |
| 967 | } |
| 968 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 969 | return NULL; |
| 970 | } |
| 971 | |
| 972 | /** |
| 973 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 974 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 975 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 976 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 977 | * phba->active_rrq_list and clear the rrq. |
| 978 | * If ndlp is not NULL then only remove rrqs for this vport & this ndlp. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 979 | **/ |
| 980 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 981 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 982 | |
| 983 | { |
| 984 | struct lpfc_hba *phba = vport->phba; |
| 985 | struct lpfc_node_rrq *rrq; |
| 986 | struct lpfc_node_rrq *nextrrq; |
| 987 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 988 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 989 | |
| 990 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 991 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 992 | if (!ndlp) { |
| 993 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 994 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 995 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 996 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 997 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 998 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 999 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1000 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1001 | |
| 1002 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 1003 | list_del(&rrq->list); |
| 1004 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1005 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1009 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1010 | * @phba: Pointer to HBA context object. |
| 1011 | * @ndlp: Targets nodelist pointer for this exchange. |
| 1012 | * @xritag the xri in the bitmap to test. |
| 1013 | * |
| 1014 | * This function is called with hbalock held. This function |
| 1015 | * returns 0 = rrq not active for this xri |
| 1016 | * 1 = rrq is valid for this xri. |
| 1017 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1018 | int |
| 1019 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1020 | uint16_t xritag) |
| 1021 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1022 | lockdep_assert_held(&phba->hbalock); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1023 | if (!ndlp) |
| 1024 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1025 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1026 | return 0; |
| 1027 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1028 | return 1; |
| 1029 | else |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | /** |
| 1034 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 1035 | * @phba: Pointer to HBA context object. |
| 1036 | * @ndlp: nodelist pointer for this target. |
| 1037 | * @xritag: xri used in this exchange. |
| 1038 | * @rxid: Remote Exchange ID. |
| 1039 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 1040 | * |
| 1041 | * This function takes the hbalock. |
| 1042 | * The active bit is always set in the active rrq xri_bitmap even |
| 1043 | * if there is no slot avaiable for the other rrq information. |
| 1044 | * |
| 1045 | * returns 0 rrq actived for this xri |
| 1046 | * < 0 No memory or invalid ndlp. |
| 1047 | **/ |
| 1048 | int |
| 1049 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1050 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1051 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1052 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1053 | struct lpfc_node_rrq *rrq; |
| 1054 | int empty; |
| 1055 | |
| 1056 | if (!ndlp) |
| 1057 | return -EINVAL; |
| 1058 | |
| 1059 | if (!phba->cfg_enable_rrq) |
| 1060 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1061 | |
| 1062 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1063 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1064 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 1065 | goto out; |
| 1066 | } |
| 1067 | |
| 1068 | /* |
| 1069 | * set the active bit even if there is no mem available. |
| 1070 | */ |
| 1071 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 1072 | goto out; |
| 1073 | |
| 1074 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 1075 | goto out; |
| 1076 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1077 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1078 | goto out; |
| 1079 | |
| 1080 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1081 | goto out; |
| 1082 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1083 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1084 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 1085 | if (!rrq) { |
| 1086 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1087 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 1088 | " DID:0x%x Send:%d\n", |
| 1089 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1090 | return -EINVAL; |
| 1091 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 1092 | if (phba->cfg_enable_rrq == 1) |
| 1093 | rrq->send_rrq = send_rrq; |
| 1094 | else |
| 1095 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1096 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1097 | rrq->rrq_stop_time = jiffies + |
| 1098 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1099 | rrq->ndlp = ndlp; |
| 1100 | rrq->nlp_DID = ndlp->nlp_DID; |
| 1101 | rrq->vport = ndlp->vport; |
| 1102 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1103 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1104 | empty = list_empty(&phba->active_rrq_list); |
| 1105 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 1106 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1107 | if (empty) |
| 1108 | lpfc_worker_wake_up(phba); |
| 1109 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1110 | return 0; |
| 1111 | out: |
| 1112 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1113 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1114 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 1115 | " DID:0x%x Send:%d\n", |
| 1116 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1117 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1121 | * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1122 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1123 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1124 | * |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1125 | * This function is called with the ring lock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1126 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1127 | * list is not empty then it is successful, it returns pointer to the newly |
| 1128 | * allocated sglq object else it returns NULL. |
| 1129 | **/ |
| 1130 | static struct lpfc_sglq * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1131 | __lpfc_sli_get_els_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1132 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1133 | struct list_head *lpfc_els_sgl_list = &phba->sli4_hba.lpfc_els_sgl_list; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1134 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1135 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1136 | struct lpfc_scsi_buf *lpfc_cmd; |
| 1137 | struct lpfc_nodelist *ndlp; |
| 1138 | int found = 0; |
| 1139 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1140 | lockdep_assert_held(&phba->hbalock); |
| 1141 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1142 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 1143 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 1144 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 1145 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1146 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1147 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1148 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 1149 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 1150 | ndlp = NULL; |
| 1151 | else |
| 1152 | ndlp = piocbq->context_un.ndlp; |
| 1153 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1154 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1155 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1156 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1157 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 1158 | list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1159 | start_sglq = sglq; |
| 1160 | while (!found) { |
| 1161 | if (!sglq) |
James Smart | d11f54b | 2017-03-04 09:30:24 -0800 | [diff] [blame] | 1162 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1163 | if (ndlp && ndlp->active_rrqs_xri_bitmap && |
| 1164 | test_bit(sglq->sli4_lxritag, |
| 1165 | ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1166 | /* This xri has an rrq outstanding for this DID. |
| 1167 | * put it back in the list and get another xri. |
| 1168 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1169 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1170 | sglq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1171 | list_remove_head(lpfc_els_sgl_list, sglq, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1172 | struct lpfc_sglq, list); |
| 1173 | if (sglq == start_sglq) { |
James Smart | 14041bd | 2017-06-01 21:07:01 -0700 | [diff] [blame] | 1174 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1175 | sglq = NULL; |
| 1176 | break; |
| 1177 | } else |
| 1178 | continue; |
| 1179 | } |
| 1180 | sglq->ndlp = ndlp; |
| 1181 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1182 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1183 | sglq->state = SGL_ALLOCATED; |
| 1184 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1185 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1186 | return sglq; |
| 1187 | } |
| 1188 | |
| 1189 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1190 | * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool |
| 1191 | * @phba: Pointer to HBA context object. |
| 1192 | * @piocb: Pointer to the iocbq. |
| 1193 | * |
| 1194 | * This function is called with the sgl_list lock held. This function |
| 1195 | * gets a new driver sglq object from the sglq list. If the |
| 1196 | * list is not empty then it is successful, it returns pointer to the newly |
| 1197 | * allocated sglq object else it returns NULL. |
| 1198 | **/ |
| 1199 | struct lpfc_sglq * |
| 1200 | __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
| 1201 | { |
| 1202 | struct list_head *lpfc_nvmet_sgl_list; |
| 1203 | struct lpfc_sglq *sglq = NULL; |
| 1204 | |
| 1205 | lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list; |
| 1206 | |
| 1207 | lockdep_assert_held(&phba->sli4_hba.sgl_list_lock); |
| 1208 | |
| 1209 | list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list); |
| 1210 | if (!sglq) |
| 1211 | return NULL; |
| 1212 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
| 1213 | sglq->state = SGL_ALLOCATED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1214 | return sglq; |
| 1215 | } |
| 1216 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1217 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1218 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1219 | * @phba: Pointer to HBA context object. |
| 1220 | * |
| 1221 | * This function is called with no lock held. This function |
| 1222 | * allocates a new driver iocb object from the iocb pool. If the |
| 1223 | * allocation is successful, it returns pointer to the newly |
| 1224 | * allocated iocb object else it returns NULL. |
| 1225 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1226 | struct lpfc_iocbq * |
| 1227 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1228 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1229 | struct lpfc_iocbq * iocbq = NULL; |
| 1230 | unsigned long iflags; |
| 1231 | |
| 1232 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1233 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 1234 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1235 | return iocbq; |
| 1236 | } |
| 1237 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1238 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1239 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 1240 | * @phba: Pointer to HBA context object. |
| 1241 | * @iocbq: Pointer to driver iocb object. |
| 1242 | * |
| 1243 | * This function is called with hbalock held to release driver |
| 1244 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1245 | * does not change for each use of the iocb object. This function |
| 1246 | * clears all other fields of the iocb object when it is freed. |
| 1247 | * The sqlq structure that holds the xritag and phys and virtual |
| 1248 | * mappings for the scatter gather list is retrieved from the |
| 1249 | * active array of sglq. The get of the sglq pointer also clears |
| 1250 | * the entry in the array. If the status of the IO indiactes that |
| 1251 | * this IO was aborted then the sglq entry it put on the |
| 1252 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1253 | * IO has good status or fails for any other reason then the sglq |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1254 | * entry is added to the free list (lpfc_els_sgl_list). |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1255 | **/ |
| 1256 | static void |
| 1257 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1258 | { |
| 1259 | struct lpfc_sglq *sglq; |
| 1260 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1261 | unsigned long iflag = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1262 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1263 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1264 | lockdep_assert_held(&phba->hbalock); |
| 1265 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1266 | if (iocbq->sli4_xritag == NO_XRI) |
| 1267 | sglq = NULL; |
| 1268 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1269 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1270 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1271 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1272 | if (sglq) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1273 | if (iocbq->iocb_flag & LPFC_IO_NVMET) { |
| 1274 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1275 | iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1276 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1277 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1278 | list_add_tail(&sglq->list, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1279 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 1280 | spin_unlock_irqrestore( |
| 1281 | &phba->sli4_hba.sgl_list_lock, iflag); |
| 1282 | goto out; |
| 1283 | } |
| 1284 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1285 | pring = phba->sli4_hba.els_wq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1286 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1287 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1288 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1289 | iflag); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1290 | list_add(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1291 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1292 | spin_unlock_irqrestore( |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1293 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1294 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1295 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1296 | iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1297 | sglq->state = SGL_FREED; |
| 1298 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1299 | list_add_tail(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1300 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1301 | spin_unlock_irqrestore( |
| 1302 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1303 | |
| 1304 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1305 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1306 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1307 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1308 | } |
| 1309 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1310 | out: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1311 | /* |
| 1312 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1313 | */ |
| 1314 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1315 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1316 | iocbq->sli4_xritag = NO_XRI; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1317 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | |
| 1318 | LPFC_IO_NVME_LS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1319 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1320 | } |
| 1321 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1322 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1323 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1324 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1325 | * @phba: Pointer to HBA context object. |
| 1326 | * @iocbq: Pointer to driver iocb object. |
| 1327 | * |
| 1328 | * This function is called with hbalock held to release driver |
| 1329 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1330 | * does not change for each use of the iocb object. This function |
| 1331 | * clears all other fields of the iocb object when it is freed. |
| 1332 | **/ |
| 1333 | static void |
| 1334 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1335 | { |
| 1336 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1337 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1338 | lockdep_assert_held(&phba->hbalock); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1339 | |
| 1340 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1341 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1342 | */ |
| 1343 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1344 | iocbq->sli4_xritag = NO_XRI; |
| 1345 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1346 | } |
| 1347 | |
| 1348 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1349 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1350 | * @phba: Pointer to HBA context object. |
| 1351 | * @iocbq: Pointer to driver iocb object. |
| 1352 | * |
| 1353 | * This function is called with hbalock held to release driver |
| 1354 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1355 | * does not change for each use of the iocb object. This function |
| 1356 | * clears all other fields of the iocb object when it is freed. |
| 1357 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1358 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1359 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1360 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1361 | lockdep_assert_held(&phba->hbalock); |
| 1362 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1363 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1364 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1365 | } |
| 1366 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1367 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1368 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1369 | * @phba: Pointer to HBA context object. |
| 1370 | * @iocbq: Pointer to driver iocb object. |
| 1371 | * |
| 1372 | * This function is called with no lock held to release the iocb to |
| 1373 | * iocb pool. |
| 1374 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1375 | void |
| 1376 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1377 | { |
| 1378 | unsigned long iflags; |
| 1379 | |
| 1380 | /* |
| 1381 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1382 | */ |
| 1383 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1384 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1385 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1386 | } |
| 1387 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1388 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1389 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1390 | * @phba: Pointer to HBA context object. |
| 1391 | * @iocblist: List of IOCBs. |
| 1392 | * @ulpstatus: ULP status in IOCB command field. |
| 1393 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1394 | * |
| 1395 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1396 | * on the list by invoking the complete callback function associated with the |
| 1397 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1398 | * fields. |
| 1399 | **/ |
| 1400 | void |
| 1401 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1402 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1403 | { |
| 1404 | struct lpfc_iocbq *piocb; |
| 1405 | |
| 1406 | while (!list_empty(iocblist)) { |
| 1407 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1408 | if (!piocb->iocb_cmpl) |
| 1409 | lpfc_sli_release_iocbq(phba, piocb); |
| 1410 | else { |
| 1411 | piocb->iocb.ulpStatus = ulpstatus; |
| 1412 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1413 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1414 | } |
| 1415 | } |
| 1416 | return; |
| 1417 | } |
| 1418 | |
| 1419 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1420 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1421 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1422 | * |
| 1423 | * This function is called by ring event handler function to get the iocb type. |
| 1424 | * This function translates the iocb command to an iocb command type used to |
| 1425 | * decide the final disposition of each completed IOCB. |
| 1426 | * The function returns |
| 1427 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1428 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1429 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1430 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1431 | * |
| 1432 | * The caller is not required to hold any lock. |
| 1433 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1434 | static lpfc_iocb_type |
| 1435 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1436 | { |
| 1437 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1438 | |
| 1439 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1440 | return 0; |
| 1441 | |
| 1442 | switch (iocb_cmnd) { |
| 1443 | case CMD_XMIT_SEQUENCE_CR: |
| 1444 | case CMD_XMIT_SEQUENCE_CX: |
| 1445 | case CMD_XMIT_BCAST_CN: |
| 1446 | case CMD_XMIT_BCAST_CX: |
| 1447 | case CMD_ELS_REQUEST_CR: |
| 1448 | case CMD_ELS_REQUEST_CX: |
| 1449 | case CMD_CREATE_XRI_CR: |
| 1450 | case CMD_CREATE_XRI_CX: |
| 1451 | case CMD_GET_RPI_CN: |
| 1452 | case CMD_XMIT_ELS_RSP_CX: |
| 1453 | case CMD_GET_RPI_CR: |
| 1454 | case CMD_FCP_IWRITE_CR: |
| 1455 | case CMD_FCP_IWRITE_CX: |
| 1456 | case CMD_FCP_IREAD_CR: |
| 1457 | case CMD_FCP_IREAD_CX: |
| 1458 | case CMD_FCP_ICMND_CR: |
| 1459 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1460 | case CMD_FCP_TSEND_CX: |
| 1461 | case CMD_FCP_TRSP_CX: |
| 1462 | case CMD_FCP_TRECEIVE_CX: |
| 1463 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1464 | case CMD_ADAPTER_MSG: |
| 1465 | case CMD_ADAPTER_DUMP: |
| 1466 | case CMD_XMIT_SEQUENCE64_CR: |
| 1467 | case CMD_XMIT_SEQUENCE64_CX: |
| 1468 | case CMD_XMIT_BCAST64_CN: |
| 1469 | case CMD_XMIT_BCAST64_CX: |
| 1470 | case CMD_ELS_REQUEST64_CR: |
| 1471 | case CMD_ELS_REQUEST64_CX: |
| 1472 | case CMD_FCP_IWRITE64_CR: |
| 1473 | case CMD_FCP_IWRITE64_CX: |
| 1474 | case CMD_FCP_IREAD64_CR: |
| 1475 | case CMD_FCP_IREAD64_CX: |
| 1476 | case CMD_FCP_ICMND64_CR: |
| 1477 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1478 | case CMD_FCP_TSEND64_CX: |
| 1479 | case CMD_FCP_TRSP64_CX: |
| 1480 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1481 | case CMD_GEN_REQUEST64_CR: |
| 1482 | case CMD_GEN_REQUEST64_CX: |
| 1483 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1484 | case DSSCMD_IWRITE64_CR: |
| 1485 | case DSSCMD_IWRITE64_CX: |
| 1486 | case DSSCMD_IREAD64_CR: |
| 1487 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1488 | type = LPFC_SOL_IOCB; |
| 1489 | break; |
| 1490 | case CMD_ABORT_XRI_CN: |
| 1491 | case CMD_ABORT_XRI_CX: |
| 1492 | case CMD_CLOSE_XRI_CN: |
| 1493 | case CMD_CLOSE_XRI_CX: |
| 1494 | case CMD_XRI_ABORTED_CX: |
| 1495 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1496 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | type = LPFC_ABORT_IOCB; |
| 1498 | break; |
| 1499 | case CMD_RCV_SEQUENCE_CX: |
| 1500 | case CMD_RCV_ELS_REQ_CX: |
| 1501 | case CMD_RCV_SEQUENCE64_CX: |
| 1502 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1503 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1504 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1505 | case CMD_IOCB_RCV_ELS64_CX: |
| 1506 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1507 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1508 | type = LPFC_UNSOL_IOCB; |
| 1509 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1510 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1511 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1512 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1513 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1514 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1515 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1516 | case CMD_IOCB_RET_HBQE64_CN: |
| 1517 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1518 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1519 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1520 | case CMD_IOCB_LOGENTRY_CN: |
| 1521 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1522 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1523 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1524 | type = LPFC_UNKNOWN_IOCB; |
| 1525 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1526 | default: |
| 1527 | type = LPFC_UNKNOWN_IOCB; |
| 1528 | break; |
| 1529 | } |
| 1530 | |
| 1531 | return type; |
| 1532 | } |
| 1533 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1534 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1535 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1536 | * @phba: Pointer to HBA context object. |
| 1537 | * |
| 1538 | * This function is called from SLI initialization code |
| 1539 | * to configure every ring of the HBA's SLI interface. The |
| 1540 | * caller is not required to hold any lock. This function issues |
| 1541 | * a config_ring mailbox command for each ring. |
| 1542 | * This function returns zero if successful else returns a negative |
| 1543 | * error code. |
| 1544 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1545 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1546 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1547 | { |
| 1548 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1549 | LPFC_MBOXQ_t *pmb; |
| 1550 | MAILBOX_t *pmbox; |
| 1551 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1552 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1553 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1554 | if (!pmb) |
| 1555 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1556 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1557 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1558 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1559 | lpfc_config_ring(phba, i, pmb); |
| 1560 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1561 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1562 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1563 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1564 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1565 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1566 | rc, pmbox->mbxCommand, |
| 1567 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1568 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1569 | ret = -ENXIO; |
| 1570 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1571 | } |
| 1572 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1573 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1574 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1575 | } |
| 1576 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1577 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1578 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1579 | * @phba: Pointer to HBA context object. |
| 1580 | * @pring: Pointer to driver SLI ring object. |
| 1581 | * @piocb: Pointer to the driver iocb object. |
| 1582 | * |
| 1583 | * This function is called with hbalock held. The function adds the |
| 1584 | * new iocb to txcmplq of the given ring. This function always returns |
| 1585 | * 0. If this function is called for ELS ring, this function checks if |
| 1586 | * there is a vport associated with the ELS command. This function also |
| 1587 | * starts els_tmofunc timer if this is an ELS command. |
| 1588 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1589 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1590 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1591 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1592 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1593 | lockdep_assert_held(&phba->hbalock); |
| 1594 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1595 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1596 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1597 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1598 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1599 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1600 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1601 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1602 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1603 | BUG_ON(!piocb->vport); |
| 1604 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1605 | mod_timer(&piocb->vport->els_tmofunc, |
| 1606 | jiffies + |
| 1607 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 1608 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1609 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1610 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1611 | } |
| 1612 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1613 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1614 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1615 | * @phba: Pointer to HBA context object. |
| 1616 | * @pring: Pointer to driver SLI ring object. |
| 1617 | * |
| 1618 | * This function is called with hbalock held to get next |
| 1619 | * iocb in txq of the given ring. If there is any iocb in |
| 1620 | * the txq, the function returns first iocb in the list after |
| 1621 | * removing the iocb from the list, else it returns NULL. |
| 1622 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1623 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1624 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1625 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | struct lpfc_iocbq *cmd_iocb; |
| 1627 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1628 | lockdep_assert_held(&phba->hbalock); |
| 1629 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1630 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1631 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1632 | } |
| 1633 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1634 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1635 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1636 | * @phba: Pointer to HBA context object. |
| 1637 | * @pring: Pointer to driver SLI ring object. |
| 1638 | * |
| 1639 | * This function is called with hbalock held and the caller must post the |
| 1640 | * iocb without releasing the lock. If the caller releases the lock, |
| 1641 | * iocb slot returned by the function is not guaranteed to be available. |
| 1642 | * The function returns pointer to the next available iocb slot if there |
| 1643 | * is available slot in the ring, else it returns NULL. |
| 1644 | * If the get index of the ring is ahead of the put index, the function |
| 1645 | * will post an error attention event to the worker thread to take the |
| 1646 | * HBA to offline state. |
| 1647 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1648 | static IOCB_t * |
| 1649 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1650 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1651 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1652 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1653 | |
| 1654 | lockdep_assert_held(&phba->hbalock); |
| 1655 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1656 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1657 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1658 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1659 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1660 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1661 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1662 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1663 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1664 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1665 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1666 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1667 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1668 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1669 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1670 | pring->sli.sli3.local_getidx, |
| 1671 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1672 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1673 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1674 | /* |
| 1675 | * All error attention handlers are posted to |
| 1676 | * worker thread |
| 1677 | */ |
| 1678 | phba->work_ha |= HA_ERATT; |
| 1679 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1680 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1681 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1682 | |
| 1683 | return NULL; |
| 1684 | } |
| 1685 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1686 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | return NULL; |
| 1688 | } |
| 1689 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1690 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | } |
| 1692 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1693 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1694 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1695 | * @phba: Pointer to HBA context object. |
| 1696 | * @iocbq: Pointer to driver iocb object. |
| 1697 | * |
| 1698 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1699 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1700 | * array and assigns a new iotag. |
| 1701 | * The function returns the allocated iotag if successful, else returns zero. |
| 1702 | * Zero is not a valid iotag. |
| 1703 | * The caller is not required to hold any lock. |
| 1704 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1705 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1706 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1707 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1708 | struct lpfc_iocbq **new_arr; |
| 1709 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1710 | size_t new_len; |
| 1711 | struct lpfc_sli *psli = &phba->sli; |
| 1712 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1713 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1714 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1715 | iotag = psli->last_iotag; |
| 1716 | if(++iotag < psli->iocbq_lookup_len) { |
| 1717 | psli->last_iotag = iotag; |
| 1718 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1719 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1720 | iocbq->iotag = iotag; |
| 1721 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1722 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1723 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1724 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1725 | spin_unlock_irq(&phba->hbalock); |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1726 | new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1727 | GFP_KERNEL); |
| 1728 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1729 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1730 | old_arr = psli->iocbq_lookup; |
| 1731 | if (new_len <= psli->iocbq_lookup_len) { |
| 1732 | /* highly unprobable case */ |
| 1733 | kfree(new_arr); |
| 1734 | iotag = psli->last_iotag; |
| 1735 | if(++iotag < psli->iocbq_lookup_len) { |
| 1736 | psli->last_iotag = iotag; |
| 1737 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1738 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1739 | iocbq->iotag = iotag; |
| 1740 | return iotag; |
| 1741 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1742 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1743 | return 0; |
| 1744 | } |
| 1745 | if (psli->iocbq_lookup) |
| 1746 | memcpy(new_arr, old_arr, |
| 1747 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1748 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1749 | psli->iocbq_lookup = new_arr; |
| 1750 | psli->iocbq_lookup_len = new_len; |
| 1751 | psli->last_iotag = iotag; |
| 1752 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1753 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1754 | iocbq->iotag = iotag; |
| 1755 | kfree(old_arr); |
| 1756 | return iotag; |
| 1757 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1758 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1759 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1760 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1761 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1762 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1763 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1764 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1765 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1766 | } |
| 1767 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1768 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1769 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1770 | * @phba: Pointer to HBA context object. |
| 1771 | * @pring: Pointer to driver SLI ring object. |
| 1772 | * @iocb: Pointer to iocb slot in the ring. |
| 1773 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1774 | * posted to firmware. |
| 1775 | * |
| 1776 | * This function is called with hbalock held to post a new iocb to |
| 1777 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1778 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1779 | * a completion call back for this iocb else the function will free the |
| 1780 | * iocb object. |
| 1781 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1782 | static void |
| 1783 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1784 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1785 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1786 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1787 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1788 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1789 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1790 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1791 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1792 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1793 | if (pring->ringno == LPFC_ELS_RING) { |
| 1794 | lpfc_debugfs_slow_ring_trc(phba, |
| 1795 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1796 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1797 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1798 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1799 | } |
| 1800 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1801 | /* |
| 1802 | * Issue iocb command to adapter |
| 1803 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1804 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1805 | wmb(); |
| 1806 | pring->stats.iocb_cmd++; |
| 1807 | |
| 1808 | /* |
| 1809 | * If there is no completion routine to call, we can release the |
| 1810 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1811 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1812 | */ |
| 1813 | if (nextiocb->iocb_cmpl) |
| 1814 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1815 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1816 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1817 | |
| 1818 | /* |
| 1819 | * Let the HBA know what IOCB slot will be the next one the |
| 1820 | * driver will put a command into. |
| 1821 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1822 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1823 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1824 | } |
| 1825 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1826 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1827 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1828 | * @phba: Pointer to HBA context object. |
| 1829 | * @pring: Pointer to driver SLI ring object. |
| 1830 | * |
| 1831 | * The caller is not required to hold any lock for calling this function. |
| 1832 | * This function updates the chip attention bits for the ring to inform firmware |
| 1833 | * that there are pending work to be done for this ring and requests an |
| 1834 | * interrupt when there is space available in the ring. This function is |
| 1835 | * called when the driver is unable to post more iocbs to the ring due |
| 1836 | * to unavailability of space in the ring. |
| 1837 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1838 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1839 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1840 | { |
| 1841 | int ringno = pring->ringno; |
| 1842 | |
| 1843 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1844 | |
| 1845 | wmb(); |
| 1846 | |
| 1847 | /* |
| 1848 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1849 | * The HBA will tell us when an IOCB entry is available. |
| 1850 | */ |
| 1851 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1852 | readl(phba->CAregaddr); /* flush */ |
| 1853 | |
| 1854 | pring->stats.iocb_cmd_full++; |
| 1855 | } |
| 1856 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1857 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1858 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1859 | * @phba: Pointer to HBA context object. |
| 1860 | * @pring: Pointer to driver SLI ring object. |
| 1861 | * |
| 1862 | * This function updates the chip attention register bit for the |
| 1863 | * given ring to inform HBA that there is more work to be done |
| 1864 | * in this ring. The caller is not required to hold any lock. |
| 1865 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1866 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1867 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1868 | { |
| 1869 | int ringno = pring->ringno; |
| 1870 | |
| 1871 | /* |
| 1872 | * Tell the HBA that there is work to do in this ring. |
| 1873 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1874 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1875 | wmb(); |
| 1876 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1877 | readl(phba->CAregaddr); /* flush */ |
| 1878 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1879 | } |
| 1880 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1881 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1882 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1883 | * @phba: Pointer to HBA context object. |
| 1884 | * @pring: Pointer to driver SLI ring object. |
| 1885 | * |
| 1886 | * This function is called with hbalock held to post pending iocbs |
| 1887 | * in the txq to the firmware. This function is called when driver |
| 1888 | * detects space available in the ring. |
| 1889 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1890 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1891 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1892 | { |
| 1893 | IOCB_t *iocb; |
| 1894 | struct lpfc_iocbq *nextiocb; |
| 1895 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1896 | lockdep_assert_held(&phba->hbalock); |
| 1897 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1898 | /* |
| 1899 | * Check to see if: |
| 1900 | * (a) there is anything on the txq to send |
| 1901 | * (b) link is up |
| 1902 | * (c) link attention events can be processed (fcp ring only) |
| 1903 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1904 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1905 | |
| 1906 | if (lpfc_is_link_up(phba) && |
| 1907 | (!list_empty(&pring->txq)) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1908 | (pring->ringno != LPFC_FCP_RING || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1909 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1910 | |
| 1911 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1912 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1913 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1914 | |
| 1915 | if (iocb) |
| 1916 | lpfc_sli_update_ring(phba, pring); |
| 1917 | else |
| 1918 | lpfc_sli_update_full_ring(phba, pring); |
| 1919 | } |
| 1920 | |
| 1921 | return; |
| 1922 | } |
| 1923 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1924 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1925 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1926 | * @phba: Pointer to HBA context object. |
| 1927 | * @hbqno: HBQ number. |
| 1928 | * |
| 1929 | * This function is called with hbalock held to get the next |
| 1930 | * available slot for the given HBQ. If there is free slot |
| 1931 | * available for the HBQ it will return pointer to the next available |
| 1932 | * HBQ entry else it will return NULL. |
| 1933 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1934 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1935 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1936 | { |
| 1937 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1938 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1939 | lockdep_assert_held(&phba->hbalock); |
| 1940 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1941 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1942 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1943 | hbqp->next_hbqPutIdx = 0; |
| 1944 | |
| 1945 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1946 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1947 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1948 | |
| 1949 | hbqp->local_hbqGetIdx = getidx; |
| 1950 | |
| 1951 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1952 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1953 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1954 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1955 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1956 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1957 | hbqp->entry_count); |
| 1958 | |
| 1959 | phba->link_state = LPFC_HBA_ERROR; |
| 1960 | return NULL; |
| 1961 | } |
| 1962 | |
| 1963 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1964 | return NULL; |
| 1965 | } |
| 1966 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1967 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1968 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1969 | } |
| 1970 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1971 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1972 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1973 | * @phba: Pointer to HBA context object. |
| 1974 | * |
| 1975 | * This function is called with no lock held to free all the |
| 1976 | * hbq buffers while uninitializing the SLI interface. It also |
| 1977 | * frees the HBQ buffers returned by the firmware but not yet |
| 1978 | * processed by the upper layers. |
| 1979 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1980 | void |
| 1981 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1982 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1983 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1984 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1985 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1986 | int i, hbq_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1987 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1988 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1989 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1990 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1991 | for (i = 0; i < hbq_count; ++i) { |
| 1992 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1993 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1994 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1995 | list_del(&hbq_buf->dbuf.list); |
| 1996 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1997 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1998 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1999 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2000 | |
| 2001 | /* Mark the HBQs not in use */ |
| 2002 | phba->hbq_in_use = 0; |
| 2003 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2004 | } |
| 2005 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2006 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2007 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2008 | * @phba: Pointer to HBA context object. |
| 2009 | * @hbqno: HBQ number. |
| 2010 | * @hbq_buf: Pointer to HBQ buffer. |
| 2011 | * |
| 2012 | * This function is called with the hbalock held to post a |
| 2013 | * hbq buffer to the firmware. If the function finds an empty |
| 2014 | * slot in the HBQ, it will post the buffer. The function will return |
| 2015 | * pointer to the hbq entry if it successfully post the buffer |
| 2016 | * else it will return NULL. |
| 2017 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2018 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2019 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2020 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2021 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2022 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2023 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 2024 | } |
| 2025 | |
| 2026 | /** |
| 2027 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 2028 | * @phba: Pointer to HBA context object. |
| 2029 | * @hbqno: HBQ number. |
| 2030 | * @hbq_buf: Pointer to HBQ buffer. |
| 2031 | * |
| 2032 | * This function is called with the hbalock held to post a hbq buffer to the |
| 2033 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 2034 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 2035 | * it successfully post the buffer else it will return an error. |
| 2036 | **/ |
| 2037 | static int |
| 2038 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 2039 | struct hbq_dmabuf *hbq_buf) |
| 2040 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2041 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2042 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2043 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2044 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2045 | /* Get next HBQ entry slot to use */ |
| 2046 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 2047 | if (hbqe) { |
| 2048 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 2049 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2050 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 2051 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2052 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2053 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2054 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 2055 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 2056 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2057 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 2058 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2059 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2060 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2061 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2062 | return 0; |
| 2063 | } else |
| 2064 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2065 | } |
| 2066 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2067 | /** |
| 2068 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 2069 | * @phba: Pointer to HBA context object. |
| 2070 | * @hbqno: HBQ number. |
| 2071 | * @hbq_buf: Pointer to HBQ buffer. |
| 2072 | * |
| 2073 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 2074 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 2075 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 2076 | **/ |
| 2077 | static int |
| 2078 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 2079 | struct hbq_dmabuf *hbq_buf) |
| 2080 | { |
| 2081 | int rc; |
| 2082 | struct lpfc_rqe hrqe; |
| 2083 | struct lpfc_rqe drqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2084 | struct lpfc_queue *hrq; |
| 2085 | struct lpfc_queue *drq; |
| 2086 | |
| 2087 | if (hbqno != LPFC_ELS_HBQ) |
| 2088 | return 1; |
| 2089 | hrq = phba->sli4_hba.hdr_rq; |
| 2090 | drq = phba->sli4_hba.dat_rq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2091 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2092 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2093 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 2094 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 2095 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 2096 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2097 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2098 | if (rc < 0) |
| 2099 | return rc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2100 | hbq_buf->tag = (rc | (hbqno << 16)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2101 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 2102 | return 0; |
| 2103 | } |
| 2104 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2105 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2106 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 2107 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2108 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2109 | .mask_count = 0, |
| 2110 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2111 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2112 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2113 | .init_count = 40, |
| 2114 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2115 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2116 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2117 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2118 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2119 | &lpfc_els_hbq, |
| 2120 | }; |
| 2121 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2122 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2123 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2124 | * @phba: Pointer to HBA context object. |
| 2125 | * @hbqno: HBQ number. |
| 2126 | * @count: Number of HBQ buffers to be posted. |
| 2127 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2128 | * This function is called with no lock held to post more hbq buffers to the |
| 2129 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 2130 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2131 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 2132 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2133 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 2134 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2135 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2136 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2137 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2138 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2139 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2140 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2141 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2142 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 2143 | lpfc_hbq_defs[hbqno]->entry_count) |
| 2144 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 2145 | phba->hbqs[hbqno].buffer_count; |
| 2146 | if (!count) |
| 2147 | return 0; |
| 2148 | /* Allocate HBQ entries */ |
| 2149 | for (i = 0; i < count; i++) { |
| 2150 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 2151 | if (!hbq_buffer) |
| 2152 | break; |
| 2153 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 2154 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2155 | /* Check whether HBQ is still in use */ |
| 2156 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2157 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2158 | goto err; |
| 2159 | while (!list_empty(&hbq_buf_list)) { |
| 2160 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2161 | dbuf.list); |
| 2162 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 2163 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2164 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2165 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2166 | posted++; |
| 2167 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2168 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2169 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2170 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2171 | return posted; |
| 2172 | err: |
| 2173 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 2174 | while (!list_empty(&hbq_buf_list)) { |
| 2175 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2176 | dbuf.list); |
| 2177 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 2178 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2179 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2180 | } |
| 2181 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2182 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2183 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2184 | * @phba: Pointer to HBA context object. |
| 2185 | * @qno: HBQ number. |
| 2186 | * |
| 2187 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2188 | * is called with no lock held. The function returns the number of HBQ entries |
| 2189 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2190 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2191 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2192 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2193 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2194 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2195 | return 0; |
| 2196 | else |
| 2197 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2198 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2199 | } |
| 2200 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2201 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2202 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2203 | * @phba: Pointer to HBA context object. |
| 2204 | * @qno: HBQ queue number. |
| 2205 | * |
| 2206 | * This function is called from SLI initialization code path with |
| 2207 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2208 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2209 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2210 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2211 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2212 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2213 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2214 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2215 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2216 | else |
| 2217 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2218 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2219 | } |
| 2220 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2221 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2222 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 2223 | * @phba: Pointer to HBA context object. |
| 2224 | * @hbqno: HBQ number. |
| 2225 | * |
| 2226 | * This function removes the first hbq buffer on an hbq list and returns a |
| 2227 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2228 | **/ |
| 2229 | static struct hbq_dmabuf * |
| 2230 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 2231 | { |
| 2232 | struct lpfc_dmabuf *d_buf; |
| 2233 | |
| 2234 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 2235 | if (!d_buf) |
| 2236 | return NULL; |
| 2237 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2238 | } |
| 2239 | |
| 2240 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2241 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list |
| 2242 | * @phba: Pointer to HBA context object. |
| 2243 | * @hbqno: HBQ number. |
| 2244 | * |
| 2245 | * This function removes the first RQ buffer on an RQ buffer list and returns a |
| 2246 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2247 | **/ |
| 2248 | static struct rqb_dmabuf * |
| 2249 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) |
| 2250 | { |
| 2251 | struct lpfc_dmabuf *h_buf; |
| 2252 | struct lpfc_rqb *rqbp; |
| 2253 | |
| 2254 | rqbp = hrq->rqbp; |
| 2255 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 2256 | struct lpfc_dmabuf, list); |
| 2257 | if (!h_buf) |
| 2258 | return NULL; |
| 2259 | rqbp->buffer_count--; |
| 2260 | return container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 2261 | } |
| 2262 | |
| 2263 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2264 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2265 | * @phba: Pointer to HBA context object. |
| 2266 | * @tag: Tag of the hbq buffer. |
| 2267 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2268 | * This function searches for the hbq buffer associated with the given tag in |
| 2269 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2270 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2271 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2272 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2273 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2274 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2275 | struct lpfc_dmabuf *d_buf; |
| 2276 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2277 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2278 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2279 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2280 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2281 | return NULL; |
| 2282 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2283 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2284 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2285 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2286 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2287 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2288 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2289 | } |
| 2290 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2291 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2292 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2293 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2294 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2295 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2296 | } |
| 2297 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2298 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2299 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2300 | * @phba: Pointer to HBA context object. |
| 2301 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2302 | * |
| 2303 | * This function is called with hbalock. This function gives back |
| 2304 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2305 | * post the buffer, it will free the buffer. |
| 2306 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2307 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2308 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2309 | { |
| 2310 | uint32_t hbqno; |
| 2311 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2312 | if (hbq_buffer) { |
| 2313 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2314 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2315 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2316 | } |
| 2317 | } |
| 2318 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2319 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2320 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2321 | * @mbxCommand: mailbox command code. |
| 2322 | * |
| 2323 | * This function is called by the mailbox event handler function to verify |
| 2324 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2325 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2326 | * and the mailbox event handler will take the HBA offline. |
| 2327 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2328 | static int |
| 2329 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2330 | { |
| 2331 | uint8_t ret; |
| 2332 | |
| 2333 | switch (mbxCommand) { |
| 2334 | case MBX_LOAD_SM: |
| 2335 | case MBX_READ_NV: |
| 2336 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2337 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2338 | case MBX_RUN_BIU_DIAG: |
| 2339 | case MBX_INIT_LINK: |
| 2340 | case MBX_DOWN_LINK: |
| 2341 | case MBX_CONFIG_LINK: |
| 2342 | case MBX_CONFIG_RING: |
| 2343 | case MBX_RESET_RING: |
| 2344 | case MBX_READ_CONFIG: |
| 2345 | case MBX_READ_RCONFIG: |
| 2346 | case MBX_READ_SPARM: |
| 2347 | case MBX_READ_STATUS: |
| 2348 | case MBX_READ_RPI: |
| 2349 | case MBX_READ_XRI: |
| 2350 | case MBX_READ_REV: |
| 2351 | case MBX_READ_LNK_STAT: |
| 2352 | case MBX_REG_LOGIN: |
| 2353 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2354 | case MBX_CLEAR_LA: |
| 2355 | case MBX_DUMP_MEMORY: |
| 2356 | case MBX_DUMP_CONTEXT: |
| 2357 | case MBX_RUN_DIAGS: |
| 2358 | case MBX_RESTART: |
| 2359 | case MBX_UPDATE_CFG: |
| 2360 | case MBX_DOWN_LOAD: |
| 2361 | case MBX_DEL_LD_ENTRY: |
| 2362 | case MBX_RUN_PROGRAM: |
| 2363 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2364 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2365 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2366 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2367 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2368 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | case MBX_LOAD_AREA: |
| 2370 | case MBX_RUN_BIU_DIAG64: |
| 2371 | case MBX_CONFIG_PORT: |
| 2372 | case MBX_READ_SPARM64: |
| 2373 | case MBX_READ_RPI64: |
| 2374 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2375 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2376 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2377 | case MBX_SET_DEBUG: |
| 2378 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2379 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2380 | case MBX_REG_VPI: |
| 2381 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2382 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2383 | case MBX_PORT_CAPABILITIES: |
| 2384 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2385 | case MBX_SLI4_CONFIG: |
| 2386 | case MBX_SLI4_REQ_FTRS: |
| 2387 | case MBX_REG_FCFI: |
| 2388 | case MBX_UNREG_FCFI: |
| 2389 | case MBX_REG_VFI: |
| 2390 | case MBX_UNREG_VFI: |
| 2391 | case MBX_INIT_VPI: |
| 2392 | case MBX_INIT_VFI: |
| 2393 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2394 | case MBX_READ_EVENT_LOG_STATUS: |
| 2395 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2396 | case MBX_SECURITY_MGMT: |
| 2397 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2398 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2399 | ret = mbxCommand; |
| 2400 | break; |
| 2401 | default: |
| 2402 | ret = MBX_SHUTDOWN; |
| 2403 | break; |
| 2404 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2405 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2407 | |
| 2408 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2409 | * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2410 | * @phba: Pointer to HBA context object. |
| 2411 | * @pmboxq: Pointer to mailbox command. |
| 2412 | * |
| 2413 | * This is completion handler function for mailbox commands issued from |
| 2414 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2415 | * mailbox event handler function with no lock held. This function |
| 2416 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2417 | * of the mailbox. |
| 2418 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2419 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2420 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2421 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2422 | unsigned long drvr_flag; |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2423 | struct completion *pmbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2424 | |
| 2425 | /* |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2426 | * If pmbox_done is empty, the driver thread gave up waiting and |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2427 | * continued running. |
| 2428 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2429 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2430 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2431 | pmbox_done = (struct completion *)pmboxq->context3; |
| 2432 | if (pmbox_done) |
| 2433 | complete(pmbox_done); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2434 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2435 | return; |
| 2436 | } |
| 2437 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2438 | |
| 2439 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2440 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2441 | * @phba: Pointer to HBA context object. |
| 2442 | * @pmb: Pointer to mailbox object. |
| 2443 | * |
| 2444 | * This function is the default mailbox completion handler. It |
| 2445 | * frees the memory resources associated with the completed mailbox |
| 2446 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2447 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2448 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2449 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2450 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2451 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2452 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2453 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2454 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2455 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2456 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2457 | int rc; |
| 2458 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2459 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2460 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2461 | if (mp) { |
| 2462 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2463 | kfree(mp); |
| 2464 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2465 | |
| 2466 | /* |
| 2467 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2468 | * is in re-discovery driver need to cleanup the RPI. |
| 2469 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2470 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2471 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2472 | !pmb->u.mb.mbxStatus) { |
| 2473 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2474 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2475 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2476 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2477 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2478 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2479 | if (rc != MBX_NOT_FINISHED) |
| 2480 | return; |
| 2481 | } |
| 2482 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2483 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2484 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2485 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2486 | shost = lpfc_shost_from_vport(vport); |
| 2487 | spin_lock_irq(shost->host_lock); |
| 2488 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2489 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2490 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2491 | } |
| 2492 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2493 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2494 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2495 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2496 | pmb->ctx_buf = NULL; |
| 2497 | pmb->ctx_ndlp = NULL; |
| 2498 | } |
| 2499 | |
| 2500 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2501 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 2502 | |
| 2503 | /* Check to see if there are any deferred events to process */ |
| 2504 | if (ndlp) { |
| 2505 | lpfc_printf_vlog( |
| 2506 | vport, |
| 2507 | KERN_INFO, LOG_MBOX | LOG_DISCOVERY, |
| 2508 | "1438 UNREG cmpl deferred mbox x%x " |
| 2509 | "on NPort x%x Data: x%x x%x %p\n", |
| 2510 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2511 | ndlp->nlp_flag, ndlp->nlp_defer_did, ndlp); |
| 2512 | |
| 2513 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2514 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2515 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2516 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
| 2517 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2518 | } else { |
| 2519 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2520 | } |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2521 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2522 | pmb->ctx_ndlp = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2523 | } |
| 2524 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2525 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2526 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2527 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2528 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2529 | "2860 SLI authentication is required " |
| 2530 | "for INIT_LINK but has not done yet\n"); |
| 2531 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2532 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2533 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2534 | else |
| 2535 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2536 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2537 | /** |
| 2538 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2539 | * @phba: Pointer to HBA context object. |
| 2540 | * @pmb: Pointer to mailbox object. |
| 2541 | * |
| 2542 | * This function is the unreg rpi mailbox completion handler. It |
| 2543 | * frees the memory resources associated with the completed mailbox |
| 2544 | * command. An additional refrenece is put on the ndlp to prevent |
| 2545 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2546 | * the unreg mailbox command completes, this routine puts the |
| 2547 | * reference back. |
| 2548 | * |
| 2549 | **/ |
| 2550 | void |
| 2551 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2552 | { |
| 2553 | struct lpfc_vport *vport = pmb->vport; |
| 2554 | struct lpfc_nodelist *ndlp; |
| 2555 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2556 | ndlp = pmb->ctx_ndlp; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2557 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2558 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2559 | (bf_get(lpfc_sli_intf_if_type, |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 2560 | &phba->sli4_hba.sli_intf) >= |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2561 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2562 | if (ndlp) { |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2563 | lpfc_printf_vlog( |
| 2564 | vport, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 2565 | "0010 UNREG_LOGIN vpi:%x " |
| 2566 | "rpi:%x DID:%x defer x%x flg x%x " |
| 2567 | "map:%x %p\n", |
| 2568 | vport->vpi, ndlp->nlp_rpi, |
| 2569 | ndlp->nlp_DID, ndlp->nlp_defer_did, |
| 2570 | ndlp->nlp_flag, |
| 2571 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2572 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2573 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2574 | |
| 2575 | /* Check to see if there are any deferred |
| 2576 | * events to process |
| 2577 | */ |
| 2578 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2579 | (ndlp->nlp_defer_did != |
| 2580 | NLP_EVT_NOTHING_PENDING)) { |
| 2581 | lpfc_printf_vlog( |
| 2582 | vport, KERN_INFO, LOG_DISCOVERY, |
| 2583 | "4111 UNREG cmpl deferred " |
| 2584 | "clr x%x on " |
| 2585 | "NPort x%x Data: x%x %p\n", |
| 2586 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2587 | ndlp->nlp_defer_did, ndlp); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2588 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2589 | ndlp->nlp_defer_did = |
| 2590 | NLP_EVT_NOTHING_PENDING; |
| 2591 | lpfc_issue_els_plogi( |
| 2592 | vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2593 | } else { |
| 2594 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2595 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2596 | } |
| 2597 | } |
| 2598 | } |
| 2599 | |
| 2600 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2601 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2602 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2603 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2604 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2605 | * @phba: Pointer to HBA context object. |
| 2606 | * |
| 2607 | * This function is called with no lock held. This function processes all |
| 2608 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2609 | * service routine processes mailbox completion interrupt and adds completed |
| 2610 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2611 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2612 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2613 | * function returns the mailbox commands to the upper layer by calling the |
| 2614 | * completion handler function of each mailbox. |
| 2615 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2616 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2617 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2618 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2619 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2620 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2621 | int rc; |
| 2622 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2623 | |
| 2624 | phba->sli.slistat.mbox_event++; |
| 2625 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2626 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2627 | spin_lock_irq(&phba->hbalock); |
| 2628 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2629 | spin_unlock_irq(&phba->hbalock); |
| 2630 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2631 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2632 | do { |
| 2633 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2634 | if (pmb == NULL) |
| 2635 | break; |
| 2636 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2637 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2638 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2639 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2640 | if (pmb->vport) { |
| 2641 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2642 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2643 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2644 | (uint32_t)pmbox->mbxCommand, |
| 2645 | pmbox->un.varWords[0], |
| 2646 | pmbox->un.varWords[1]); |
| 2647 | } |
| 2648 | else { |
| 2649 | lpfc_debugfs_disc_trc(phba->pport, |
| 2650 | LPFC_DISC_TRC_MBOX, |
| 2651 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2652 | (uint32_t)pmbox->mbxCommand, |
| 2653 | pmbox->un.varWords[0], |
| 2654 | pmbox->un.varWords[1]); |
| 2655 | } |
| 2656 | } |
| 2657 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | /* |
| 2659 | * It is a fatal error if unknown mbox command completion. |
| 2660 | */ |
| 2661 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2662 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2663 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2664 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2665 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2666 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2667 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2668 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2669 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2670 | pmb), |
| 2671 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2672 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2673 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2674 | phba->work_hs = HS_FFER3; |
| 2675 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2676 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | } |
| 2678 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2679 | if (pmbox->mbxStatus) { |
| 2680 | phba->sli.slistat.mbox_stat_err++; |
| 2681 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2682 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2683 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2684 | LOG_MBOX | LOG_SLI, |
| 2685 | "(%d):0305 Mbox cmd cmpl " |
| 2686 | "error - RETRYing Data: x%x " |
| 2687 | "(x%x/x%x) x%x x%x x%x\n", |
| 2688 | pmb->vport ? pmb->vport->vpi : 0, |
| 2689 | pmbox->mbxCommand, |
| 2690 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2691 | pmb), |
| 2692 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2693 | pmb), |
| 2694 | pmbox->mbxStatus, |
| 2695 | pmbox->un.varWords[0], |
| 2696 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2697 | pmbox->mbxStatus = 0; |
| 2698 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2699 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2700 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2701 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2706 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2707 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2708 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2709 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2710 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2711 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2712 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2713 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2714 | pmb->mbox_cmpl, |
| 2715 | *((uint32_t *) pmbox), |
| 2716 | pmbox->un.varWords[0], |
| 2717 | pmbox->un.varWords[1], |
| 2718 | pmbox->un.varWords[2], |
| 2719 | pmbox->un.varWords[3], |
| 2720 | pmbox->un.varWords[4], |
| 2721 | pmbox->un.varWords[5], |
| 2722 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2723 | pmbox->un.varWords[7], |
| 2724 | pmbox->un.varWords[8], |
| 2725 | pmbox->un.varWords[9], |
| 2726 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2727 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2728 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2729 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2730 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2731 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2732 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2733 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2734 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2735 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2736 | * @phba: Pointer to HBA context object. |
| 2737 | * @pring: Pointer to driver SLI ring object. |
| 2738 | * @tag: buffer tag. |
| 2739 | * |
| 2740 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2741 | * is set in the tag the buffer is posted for a particular exchange, |
| 2742 | * the function will return the buffer without replacing the buffer. |
| 2743 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2744 | * returns the buffer and also posts another buffer to the firmware. |
| 2745 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2746 | static struct lpfc_dmabuf * |
| 2747 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2748 | struct lpfc_sli_ring *pring, |
| 2749 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2750 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2751 | struct hbq_dmabuf *hbq_entry; |
| 2752 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2753 | if (tag & QUE_BUFTAG_BIT) |
| 2754 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2755 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2756 | if (!hbq_entry) |
| 2757 | return NULL; |
| 2758 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2759 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2760 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2761 | /** |
| 2762 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2763 | * @phba: Pointer to HBA context object. |
| 2764 | * @pring: Pointer to driver SLI ring object. |
| 2765 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2766 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2767 | * @fch_type: the type for the first frame of the sequence. |
| 2768 | * |
| 2769 | * This function is called with no lock held. This function uses the r_ctl and |
| 2770 | * type of the received sequence to find the correct callback function to call |
| 2771 | * to process the sequence. |
| 2772 | **/ |
| 2773 | static int |
| 2774 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2775 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2776 | uint32_t fch_type) |
| 2777 | { |
| 2778 | int i; |
| 2779 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2780 | switch (fch_type) { |
| 2781 | case FC_TYPE_NVME: |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2782 | lpfc_nvmet_unsol_ls_event(phba, pring, saveq); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2783 | return 1; |
| 2784 | default: |
| 2785 | break; |
| 2786 | } |
| 2787 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2788 | /* unSolicited Responses */ |
| 2789 | if (pring->prt[0].profile) { |
| 2790 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2791 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2792 | saveq); |
| 2793 | return 1; |
| 2794 | } |
| 2795 | /* We must search, based on rctl / type |
| 2796 | for the right routine */ |
| 2797 | for (i = 0; i < pring->num_mask; i++) { |
| 2798 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2799 | (pring->prt[i].type == fch_type)) { |
| 2800 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2801 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2802 | (phba, pring, saveq); |
| 2803 | return 1; |
| 2804 | } |
| 2805 | } |
| 2806 | return 0; |
| 2807 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2808 | |
| 2809 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2810 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2811 | * @phba: Pointer to HBA context object. |
| 2812 | * @pring: Pointer to driver SLI ring object. |
| 2813 | * @saveq: Pointer to the unsolicited iocb. |
| 2814 | * |
| 2815 | * This function is called with no lock held by the ring event handler |
| 2816 | * when there is an unsolicited iocb posted to the response ring by the |
| 2817 | * firmware. This function gets the buffer associated with the iocbs |
| 2818 | * and calls the event handler for the ring. This function handles both |
| 2819 | * qring buffers and hbq buffers. |
| 2820 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2821 | * upper layer functions will free the iocb objects. |
| 2822 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2823 | static int |
| 2824 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2825 | struct lpfc_iocbq *saveq) |
| 2826 | { |
| 2827 | IOCB_t * irsp; |
| 2828 | WORD5 * w5p; |
| 2829 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2830 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2831 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2832 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2833 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2834 | |
| 2835 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2836 | if (pring->lpfc_sli_rcv_async_status) |
| 2837 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2838 | else |
| 2839 | lpfc_printf_log(phba, |
| 2840 | KERN_WARNING, |
| 2841 | LOG_SLI, |
| 2842 | "0316 Ring %d handler: unexpected " |
| 2843 | "ASYNC_STATUS iocb received evt_code " |
| 2844 | "0x%x\n", |
| 2845 | pring->ringno, |
| 2846 | irsp->un.asyncstat.evt_code); |
| 2847 | return 1; |
| 2848 | } |
| 2849 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2850 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2851 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2852 | if (irsp->ulpBdeCount > 0) { |
| 2853 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2854 | irsp->un.ulpWord[3]); |
| 2855 | lpfc_in_buf_free(phba, dmzbuf); |
| 2856 | } |
| 2857 | |
| 2858 | if (irsp->ulpBdeCount > 1) { |
| 2859 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2860 | irsp->unsli3.sli3Words[3]); |
| 2861 | lpfc_in_buf_free(phba, dmzbuf); |
| 2862 | } |
| 2863 | |
| 2864 | if (irsp->ulpBdeCount > 2) { |
| 2865 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2866 | irsp->unsli3.sli3Words[7]); |
| 2867 | lpfc_in_buf_free(phba, dmzbuf); |
| 2868 | } |
| 2869 | |
| 2870 | return 1; |
| 2871 | } |
| 2872 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2873 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2874 | if (irsp->ulpBdeCount != 0) { |
| 2875 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2876 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2877 | if (!saveq->context2) |
| 2878 | lpfc_printf_log(phba, |
| 2879 | KERN_ERR, |
| 2880 | LOG_SLI, |
| 2881 | "0341 Ring %d Cannot find buffer for " |
| 2882 | "an unsolicited iocb. tag 0x%x\n", |
| 2883 | pring->ringno, |
| 2884 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2885 | } |
| 2886 | if (irsp->ulpBdeCount == 2) { |
| 2887 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2888 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2889 | if (!saveq->context3) |
| 2890 | lpfc_printf_log(phba, |
| 2891 | KERN_ERR, |
| 2892 | LOG_SLI, |
| 2893 | "0342 Ring %d Cannot find buffer for an" |
| 2894 | " unsolicited iocb. tag 0x%x\n", |
| 2895 | pring->ringno, |
| 2896 | irsp->unsli3.sli3Words[7]); |
| 2897 | } |
| 2898 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2899 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2900 | if (irsp->ulpBdeCount != 0) { |
| 2901 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2902 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2903 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2904 | lpfc_printf_log(phba, |
| 2905 | KERN_ERR, |
| 2906 | LOG_SLI, |
| 2907 | "0343 Ring %d Cannot find " |
| 2908 | "buffer for an unsolicited iocb" |
| 2909 | ". tag 0x%x\n", pring->ringno, |
| 2910 | irsp->un.ulpWord[3]); |
| 2911 | } |
| 2912 | if (irsp->ulpBdeCount == 2) { |
| 2913 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2914 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2915 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2916 | lpfc_printf_log(phba, |
| 2917 | KERN_ERR, |
| 2918 | LOG_SLI, |
| 2919 | "0344 Ring %d Cannot find " |
| 2920 | "buffer for an unsolicited " |
| 2921 | "iocb. tag 0x%x\n", |
| 2922 | pring->ringno, |
| 2923 | irsp->unsli3.sli3Words[7]); |
| 2924 | } |
| 2925 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2926 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2927 | if (irsp->ulpBdeCount != 0 && |
| 2928 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2929 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2930 | int found = 0; |
| 2931 | |
| 2932 | /* search continue save q for same XRI */ |
| 2933 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2934 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2935 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2936 | list_add_tail(&saveq->list, &iocbq->list); |
| 2937 | found = 1; |
| 2938 | break; |
| 2939 | } |
| 2940 | } |
| 2941 | if (!found) |
| 2942 | list_add_tail(&saveq->clist, |
| 2943 | &pring->iocb_continue_saveq); |
| 2944 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2945 | list_del_init(&iocbq->clist); |
| 2946 | saveq = iocbq; |
| 2947 | irsp = &(saveq->iocb); |
| 2948 | } else |
| 2949 | return 0; |
| 2950 | } |
| 2951 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2952 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2953 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2954 | Rctl = FC_RCTL_ELS_REQ; |
| 2955 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2956 | } else { |
| 2957 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2958 | Rctl = w5p->hcsw.Rctl; |
| 2959 | Type = w5p->hcsw.Type; |
| 2960 | |
| 2961 | /* Firmware Workaround */ |
| 2962 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2963 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2964 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2965 | Rctl = FC_RCTL_ELS_REQ; |
| 2966 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2967 | w5p->hcsw.Rctl = Rctl; |
| 2968 | w5p->hcsw.Type = Type; |
| 2969 | } |
| 2970 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2971 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2972 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2973 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2974 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2975 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2976 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2977 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2978 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2979 | } |
| 2980 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2981 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2982 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2983 | * @phba: Pointer to HBA context object. |
| 2984 | * @pring: Pointer to driver SLI ring object. |
| 2985 | * @prspiocb: Pointer to response iocb object. |
| 2986 | * |
| 2987 | * This function looks up the iocb_lookup table to get the command iocb |
| 2988 | * corresponding to the given response iocb using the iotag of the |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 2989 | * response iocb. This function is called with the hbalock held |
| 2990 | * for sli3 devices or the ring_lock for sli4 devices. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2991 | * This function returns the command iocb object if it finds the command |
| 2992 | * iocb else returns NULL. |
| 2993 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2994 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2995 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2996 | struct lpfc_sli_ring *pring, |
| 2997 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2998 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2999 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 3000 | uint16_t iotag; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 3001 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3002 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3003 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3004 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3005 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3006 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3007 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3008 | /* remove from txcmpl queue list */ |
| 3009 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3010 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3011 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3012 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3013 | } |
| 3014 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3015 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3016 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3017 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3018 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3019 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3020 | return NULL; |
| 3021 | } |
| 3022 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3023 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3024 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 3025 | * @phba: Pointer to HBA context object. |
| 3026 | * @pring: Pointer to driver SLI ring object. |
| 3027 | * @iotag: IOCB tag. |
| 3028 | * |
| 3029 | * This function looks up the iocb_lookup table to get the command iocb |
| 3030 | * corresponding to the given iotag. This function is called with the |
| 3031 | * hbalock held. |
| 3032 | * This function returns the command iocb object if it finds the command |
| 3033 | * iocb else returns NULL. |
| 3034 | **/ |
| 3035 | static struct lpfc_iocbq * |
| 3036 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 3037 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 3038 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3039 | struct lpfc_iocbq *cmd_iocb = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3040 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 3041 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3042 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3043 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3044 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 3045 | /* remove from txcmpl queue list */ |
| 3046 | list_del_init(&cmd_iocb->list); |
| 3047 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3048 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3049 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3050 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3051 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3052 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3053 | "0372 iotag x%x lookup error: max iotag (x%x) " |
| 3054 | "iocb_flag x%x\n", |
| 3055 | iotag, phba->sli.last_iotag, |
| 3056 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3057 | return NULL; |
| 3058 | } |
| 3059 | |
| 3060 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3061 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3062 | * @phba: Pointer to HBA context object. |
| 3063 | * @pring: Pointer to driver SLI ring object. |
| 3064 | * @saveq: Pointer to the response iocb to be processed. |
| 3065 | * |
| 3066 | * This function is called by the ring event handler for non-fcp |
| 3067 | * rings when there is a new response iocb in the response ring. |
| 3068 | * The caller is not required to hold any locks. This function |
| 3069 | * gets the command iocb associated with the response iocb and |
| 3070 | * calls the completion handler for the command iocb. If there |
| 3071 | * is no completion handler, the function will free the resources |
| 3072 | * associated with command iocb. If the response iocb is for |
| 3073 | * an already aborted command iocb, the status of the completion |
| 3074 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 3075 | * This function always returns 1. |
| 3076 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3077 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3078 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3079 | struct lpfc_iocbq *saveq) |
| 3080 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3081 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | int rc = 1; |
| 3083 | unsigned long iflag; |
| 3084 | |
| 3085 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 3086 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3087 | spin_lock_irqsave(&pring->ring_lock, iflag); |
| 3088 | else |
| 3089 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3090 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 3091 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3092 | spin_unlock_irqrestore(&pring->ring_lock, iflag); |
| 3093 | else |
| 3094 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3095 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3096 | if (cmdiocbp) { |
| 3097 | if (cmdiocbp->iocb_cmpl) { |
| 3098 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3099 | * If an ELS command failed send an event to mgmt |
| 3100 | * application. |
| 3101 | */ |
| 3102 | if (saveq->iocb.ulpStatus && |
| 3103 | (pring->ringno == LPFC_ELS_RING) && |
| 3104 | (cmdiocbp->iocb.ulpCommand == |
| 3105 | CMD_ELS_REQUEST64_CR)) |
| 3106 | lpfc_send_els_failure_event(phba, |
| 3107 | cmdiocbp, saveq); |
| 3108 | |
| 3109 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3110 | * Post all ELS completions to the worker thread. |
| 3111 | * All other are passed to the completion callback. |
| 3112 | */ |
| 3113 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3114 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3115 | (cmdiocbp->iocb_flag & |
| 3116 | LPFC_DRIVER_ABORTED)) { |
| 3117 | spin_lock_irqsave(&phba->hbalock, |
| 3118 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3119 | cmdiocbp->iocb_flag &= |
| 3120 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3121 | spin_unlock_irqrestore(&phba->hbalock, |
| 3122 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3123 | saveq->iocb.ulpStatus = |
| 3124 | IOSTAT_LOCAL_REJECT; |
| 3125 | saveq->iocb.un.ulpWord[4] = |
| 3126 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3127 | |
| 3128 | /* Firmware could still be in progress |
| 3129 | * of DMAing payload, so don't free data |
| 3130 | * buffer till after a hbeat. |
| 3131 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3132 | spin_lock_irqsave(&phba->hbalock, |
| 3133 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3134 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3135 | spin_unlock_irqrestore(&phba->hbalock, |
| 3136 | iflag); |
| 3137 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3138 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3139 | if (saveq->iocb_flag & |
| 3140 | LPFC_EXCHANGE_BUSY) { |
| 3141 | /* Set cmdiocb flag for the |
| 3142 | * exchange busy so sgl (xri) |
| 3143 | * will not be released until |
| 3144 | * the abort xri is received |
| 3145 | * from hba. |
| 3146 | */ |
| 3147 | spin_lock_irqsave( |
| 3148 | &phba->hbalock, iflag); |
| 3149 | cmdiocbp->iocb_flag |= |
| 3150 | LPFC_EXCHANGE_BUSY; |
| 3151 | spin_unlock_irqrestore( |
| 3152 | &phba->hbalock, iflag); |
| 3153 | } |
| 3154 | if (cmdiocbp->iocb_flag & |
| 3155 | LPFC_DRIVER_ABORTED) { |
| 3156 | /* |
| 3157 | * Clear LPFC_DRIVER_ABORTED |
| 3158 | * bit in case it was driver |
| 3159 | * initiated abort. |
| 3160 | */ |
| 3161 | spin_lock_irqsave( |
| 3162 | &phba->hbalock, iflag); |
| 3163 | cmdiocbp->iocb_flag &= |
| 3164 | ~LPFC_DRIVER_ABORTED; |
| 3165 | spin_unlock_irqrestore( |
| 3166 | &phba->hbalock, iflag); |
| 3167 | cmdiocbp->iocb.ulpStatus = |
| 3168 | IOSTAT_LOCAL_REJECT; |
| 3169 | cmdiocbp->iocb.un.ulpWord[4] = |
| 3170 | IOERR_ABORT_REQUESTED; |
| 3171 | /* |
| 3172 | * For SLI4, irsiocb contains |
| 3173 | * NO_XRI in sli_xritag, it |
| 3174 | * shall not affect releasing |
| 3175 | * sgl (xri) process. |
| 3176 | */ |
| 3177 | saveq->iocb.ulpStatus = |
| 3178 | IOSTAT_LOCAL_REJECT; |
| 3179 | saveq->iocb.un.ulpWord[4] = |
| 3180 | IOERR_SLI_ABORTED; |
| 3181 | spin_lock_irqsave( |
| 3182 | &phba->hbalock, iflag); |
| 3183 | saveq->iocb_flag |= |
| 3184 | LPFC_DELAY_MEM_FREE; |
| 3185 | spin_unlock_irqrestore( |
| 3186 | &phba->hbalock, iflag); |
| 3187 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3188 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3189 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3190 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3191 | } else |
| 3192 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3193 | } else { |
| 3194 | /* |
| 3195 | * Unknown initiating command based on the response iotag. |
| 3196 | * This could be the case on the ELS ring because of |
| 3197 | * lpfc_els_abort(). |
| 3198 | */ |
| 3199 | if (pring->ringno != LPFC_ELS_RING) { |
| 3200 | /* |
| 3201 | * Ring <ringno> handler: unexpected completion IoTag |
| 3202 | * <IoTag> |
| 3203 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3204 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3205 | "0322 Ring %d handler: " |
| 3206 | "unexpected completion IoTag x%x " |
| 3207 | "Data: x%x x%x x%x x%x\n", |
| 3208 | pring->ringno, |
| 3209 | saveq->iocb.ulpIoTag, |
| 3210 | saveq->iocb.ulpStatus, |
| 3211 | saveq->iocb.un.ulpWord[4], |
| 3212 | saveq->iocb.ulpCommand, |
| 3213 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3214 | } |
| 3215 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3216 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3217 | return rc; |
| 3218 | } |
| 3219 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3220 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3221 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3222 | * @phba: Pointer to HBA context object. |
| 3223 | * @pring: Pointer to driver SLI ring object. |
| 3224 | * |
| 3225 | * This function is called from the iocb ring event handlers when |
| 3226 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 3227 | * an error attention condition to the worker thread and the worker |
| 3228 | * thread will transition the HBA to offline state. |
| 3229 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3230 | static void |
| 3231 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3232 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3233 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3234 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3235 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3236 | * rsp ring <portRspMax> |
| 3237 | */ |
| 3238 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3239 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3240 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3241 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3242 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3243 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3244 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3245 | |
| 3246 | /* |
| 3247 | * All error attention handlers are posted to |
| 3248 | * worker thread |
| 3249 | */ |
| 3250 | phba->work_ha |= HA_ERATT; |
| 3251 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3252 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3253 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3254 | |
| 3255 | return; |
| 3256 | } |
| 3257 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3258 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3259 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3260 | * @ptr: Pointer to address of HBA context object. |
| 3261 | * |
| 3262 | * This function is invoked by the Error Attention polling timer when the |
| 3263 | * timer times out. It will check the SLI Error Attention register for |
| 3264 | * possible attention events. If so, it will post an Error Attention event |
| 3265 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 3266 | * Error Attention polling timer for the next poll. |
| 3267 | **/ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3268 | void lpfc_poll_eratt(struct timer_list *t) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3269 | { |
| 3270 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3271 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3272 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3273 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3274 | phba = from_timer(phba, t, eratt_poll); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3275 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3276 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 3277 | sli_intr = phba->sli.slistat.sli_intr; |
| 3278 | |
| 3279 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 3280 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 3281 | sli_intr); |
| 3282 | else |
| 3283 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 3284 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3285 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 3286 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3287 | phba->sli.slistat.sli_ips = cnt; |
| 3288 | |
| 3289 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 3290 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3291 | /* Check chip HA register for error event */ |
| 3292 | eratt = lpfc_sli_check_eratt(phba); |
| 3293 | |
| 3294 | if (eratt) |
| 3295 | /* Tell the worker thread there is work to do */ |
| 3296 | lpfc_worker_wake_up(phba); |
| 3297 | else |
| 3298 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3299 | mod_timer(&phba->eratt_poll, |
| 3300 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3301 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3302 | return; |
| 3303 | } |
| 3304 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3305 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3306 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3307 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3308 | * @phba: Pointer to HBA context object. |
| 3309 | * @pring: Pointer to driver SLI ring object. |
| 3310 | * @mask: Host attention register mask for this ring. |
| 3311 | * |
| 3312 | * This function is called from the interrupt context when there is a ring |
| 3313 | * event for the fcp ring. The caller does not hold any lock. |
| 3314 | * The function processes each response iocb in the response ring until it |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3315 | * finds an iocb with LE bit set and chains all the iocbs up to the iocb with |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3316 | * LE bit set. The function will call the completion handler of the command iocb |
| 3317 | * if the response iocb indicates a completion for a command iocb or it is |
| 3318 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 3319 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3320 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3321 | * to check it explicitly. |
| 3322 | */ |
| 3323 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3324 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 3325 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3326 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3327 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3328 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3329 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3330 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 3331 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3332 | uint32_t status; |
| 3333 | uint32_t portRspPut, portRspMax; |
| 3334 | int rc = 1; |
| 3335 | lpfc_iocb_type type; |
| 3336 | unsigned long iflag; |
| 3337 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3338 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3339 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3340 | pring->stats.iocb_event++; |
| 3341 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3342 | /* |
| 3343 | * The next available response entry should never exceed the maximum |
| 3344 | * entries. If it does, treat it as an adapter hardware error. |
| 3345 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3346 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3347 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3348 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3349 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3350 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3351 | return 1; |
| 3352 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3353 | if (phba->fcp_ring_in_use) { |
| 3354 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3355 | return 1; |
| 3356 | } else |
| 3357 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3358 | |
| 3359 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3360 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3361 | /* |
| 3362 | * Fetch an entry off the ring and copy it into a local data |
| 3363 | * structure. The copy involves a byte-swap since the |
| 3364 | * network byte order and pci byte orders are different. |
| 3365 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3366 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3367 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3368 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3369 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3370 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3371 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3372 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3373 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3374 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3375 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3376 | irsp = &rspiocbq.iocb; |
| 3377 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3378 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3379 | pring->stats.iocb_rsp++; |
| 3380 | rsp_cmpl++; |
| 3381 | |
| 3382 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3383 | /* |
| 3384 | * If resource errors reported from HBA, reduce |
| 3385 | * queuedepths of the SCSI device. |
| 3386 | */ |
| 3387 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3388 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3389 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3390 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3391 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3392 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3393 | } |
| 3394 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3395 | /* Rsp ring <ringno> error: IOCB */ |
| 3396 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3397 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3398 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3399 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3400 | irsp->un.ulpWord[0], |
| 3401 | irsp->un.ulpWord[1], |
| 3402 | irsp->un.ulpWord[2], |
| 3403 | irsp->un.ulpWord[3], |
| 3404 | irsp->un.ulpWord[4], |
| 3405 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3406 | *(uint32_t *)&irsp->un1, |
| 3407 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3408 | } |
| 3409 | |
| 3410 | switch (type) { |
| 3411 | case LPFC_ABORT_IOCB: |
| 3412 | case LPFC_SOL_IOCB: |
| 3413 | /* |
| 3414 | * Idle exchange closed via ABTS from port. No iocb |
| 3415 | * resources need to be recovered. |
| 3416 | */ |
| 3417 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3418 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3419 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3420 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3421 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3422 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3423 | break; |
| 3424 | } |
| 3425 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3426 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3427 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3428 | if (unlikely(!cmdiocbq)) |
| 3429 | break; |
| 3430 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3431 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3432 | if (cmdiocbq->iocb_cmpl) { |
| 3433 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3434 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3435 | &rspiocbq); |
| 3436 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3437 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3438 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3439 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3440 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3441 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3442 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3443 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3444 | default: |
| 3445 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3446 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3447 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3448 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3449 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3450 | dev_warn(&((phba->pcidev)->dev), |
| 3451 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3452 | phba->brd_no, adaptermsg); |
| 3453 | } else { |
| 3454 | /* Unknown IOCB command */ |
| 3455 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3456 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3457 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3458 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3459 | irsp->ulpStatus, |
| 3460 | irsp->ulpIoTag, |
| 3461 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | } |
| 3463 | break; |
| 3464 | } |
| 3465 | |
| 3466 | /* |
| 3467 | * The response IOCB has been processed. Update the ring |
| 3468 | * pointer in SLIM. If the port response put pointer has not |
| 3469 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3470 | * response put pointer. |
| 3471 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3472 | writel(pring->sli.sli3.rspidx, |
| 3473 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3474 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3475 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3476 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3477 | } |
| 3478 | |
| 3479 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3480 | pring->stats.iocb_rsp_full++; |
| 3481 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3482 | writel(status, phba->CAregaddr); |
| 3483 | readl(phba->CAregaddr); |
| 3484 | } |
| 3485 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3486 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3487 | pring->stats.iocb_cmd_empty++; |
| 3488 | |
| 3489 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3490 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3491 | lpfc_sli_resume_iocb(phba, pring); |
| 3492 | |
| 3493 | if ((pring->lpfc_sli_cmd_available)) |
| 3494 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3495 | |
| 3496 | } |
| 3497 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3498 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3499 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3500 | return rc; |
| 3501 | } |
| 3502 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3503 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3504 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3505 | * @phba: Pointer to HBA context object. |
| 3506 | * @pring: Pointer to driver SLI ring object. |
| 3507 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3508 | * |
| 3509 | * This function is called from the worker thread when there is a slow-path |
| 3510 | * response IOCB to process. This function chains all the response iocbs until |
| 3511 | * seeing the iocb with the LE bit set. The function will call |
| 3512 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3513 | * completion of a command iocb. The function will call the |
| 3514 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3515 | * The function frees the resources or calls the completion handler if this |
| 3516 | * iocb is an abort completion. The function returns NULL when the response |
| 3517 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3518 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3519 | * response iocb passed in. |
| 3520 | **/ |
| 3521 | static struct lpfc_iocbq * |
| 3522 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3523 | struct lpfc_iocbq *rspiocbp) |
| 3524 | { |
| 3525 | struct lpfc_iocbq *saveq; |
| 3526 | struct lpfc_iocbq *cmdiocbp; |
| 3527 | struct lpfc_iocbq *next_iocb; |
| 3528 | IOCB_t *irsp = NULL; |
| 3529 | uint32_t free_saveq; |
| 3530 | uint8_t iocb_cmd_type; |
| 3531 | lpfc_iocb_type type; |
| 3532 | unsigned long iflag; |
| 3533 | int rc; |
| 3534 | |
| 3535 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3536 | /* First add the response iocb to the countinueq list */ |
| 3537 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3538 | pring->iocb_continueq_cnt++; |
| 3539 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3540 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3541 | irsp = &rspiocbp->iocb; |
| 3542 | if (irsp->ulpLe) { |
| 3543 | /* |
| 3544 | * By default, the driver expects to free all resources |
| 3545 | * associated with this iocb completion. |
| 3546 | */ |
| 3547 | free_saveq = 1; |
| 3548 | saveq = list_get_first(&pring->iocb_continueq, |
| 3549 | struct lpfc_iocbq, list); |
| 3550 | irsp = &(saveq->iocb); |
| 3551 | list_del_init(&pring->iocb_continueq); |
| 3552 | pring->iocb_continueq_cnt = 0; |
| 3553 | |
| 3554 | pring->stats.iocb_rsp++; |
| 3555 | |
| 3556 | /* |
| 3557 | * If resource errors reported from HBA, reduce |
| 3558 | * queuedepths of the SCSI device. |
| 3559 | */ |
| 3560 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3561 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3562 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3563 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3564 | phba->lpfc_rampdown_queue_depth(phba); |
| 3565 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3566 | } |
| 3567 | |
| 3568 | if (irsp->ulpStatus) { |
| 3569 | /* Rsp ring <ringno> error: IOCB */ |
| 3570 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3571 | "0328 Rsp Ring %d error: " |
| 3572 | "IOCB Data: " |
| 3573 | "x%x x%x x%x x%x " |
| 3574 | "x%x x%x x%x x%x " |
| 3575 | "x%x x%x x%x x%x " |
| 3576 | "x%x x%x x%x x%x\n", |
| 3577 | pring->ringno, |
| 3578 | irsp->un.ulpWord[0], |
| 3579 | irsp->un.ulpWord[1], |
| 3580 | irsp->un.ulpWord[2], |
| 3581 | irsp->un.ulpWord[3], |
| 3582 | irsp->un.ulpWord[4], |
| 3583 | irsp->un.ulpWord[5], |
| 3584 | *(((uint32_t *) irsp) + 6), |
| 3585 | *(((uint32_t *) irsp) + 7), |
| 3586 | *(((uint32_t *) irsp) + 8), |
| 3587 | *(((uint32_t *) irsp) + 9), |
| 3588 | *(((uint32_t *) irsp) + 10), |
| 3589 | *(((uint32_t *) irsp) + 11), |
| 3590 | *(((uint32_t *) irsp) + 12), |
| 3591 | *(((uint32_t *) irsp) + 13), |
| 3592 | *(((uint32_t *) irsp) + 14), |
| 3593 | *(((uint32_t *) irsp) + 15)); |
| 3594 | } |
| 3595 | |
| 3596 | /* |
| 3597 | * Fetch the IOCB command type and call the correct completion |
| 3598 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3599 | * get freed back to the lpfc_iocb_list by the discovery |
| 3600 | * kernel thread. |
| 3601 | */ |
| 3602 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3603 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3604 | switch (type) { |
| 3605 | case LPFC_SOL_IOCB: |
| 3606 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3607 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3608 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3609 | break; |
| 3610 | |
| 3611 | case LPFC_UNSOL_IOCB: |
| 3612 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3613 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3614 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3615 | if (!rc) |
| 3616 | free_saveq = 0; |
| 3617 | break; |
| 3618 | |
| 3619 | case LPFC_ABORT_IOCB: |
| 3620 | cmdiocbp = NULL; |
| 3621 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3622 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3623 | saveq); |
| 3624 | if (cmdiocbp) { |
| 3625 | /* Call the specified completion routine */ |
| 3626 | if (cmdiocbp->iocb_cmpl) { |
| 3627 | spin_unlock_irqrestore(&phba->hbalock, |
| 3628 | iflag); |
| 3629 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3630 | saveq); |
| 3631 | spin_lock_irqsave(&phba->hbalock, |
| 3632 | iflag); |
| 3633 | } else |
| 3634 | __lpfc_sli_release_iocbq(phba, |
| 3635 | cmdiocbp); |
| 3636 | } |
| 3637 | break; |
| 3638 | |
| 3639 | case LPFC_UNKNOWN_IOCB: |
| 3640 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3641 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3642 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3643 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3644 | MAX_MSG_DATA); |
| 3645 | dev_warn(&((phba->pcidev)->dev), |
| 3646 | "lpfc%d: %s\n", |
| 3647 | phba->brd_no, adaptermsg); |
| 3648 | } else { |
| 3649 | /* Unknown IOCB command */ |
| 3650 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3651 | "0335 Unknown IOCB " |
| 3652 | "command Data: x%x " |
| 3653 | "x%x x%x x%x\n", |
| 3654 | irsp->ulpCommand, |
| 3655 | irsp->ulpStatus, |
| 3656 | irsp->ulpIoTag, |
| 3657 | irsp->ulpContext); |
| 3658 | } |
| 3659 | break; |
| 3660 | } |
| 3661 | |
| 3662 | if (free_saveq) { |
| 3663 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3664 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3665 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3666 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3667 | } |
| 3668 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3669 | } |
| 3670 | rspiocbp = NULL; |
| 3671 | } |
| 3672 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3673 | return rspiocbp; |
| 3674 | } |
| 3675 | |
| 3676 | /** |
| 3677 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3678 | * @phba: Pointer to HBA context object. |
| 3679 | * @pring: Pointer to driver SLI ring object. |
| 3680 | * @mask: Host attention register mask for this ring. |
| 3681 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3682 | * This routine wraps the actual slow_ring event process routine from the |
| 3683 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3684 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3685 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3686 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3687 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3688 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3689 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3690 | } |
| 3691 | |
| 3692 | /** |
| 3693 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3694 | * @phba: Pointer to HBA context object. |
| 3695 | * @pring: Pointer to driver SLI ring object. |
| 3696 | * @mask: Host attention register mask for this ring. |
| 3697 | * |
| 3698 | * This function is called from the worker thread when there is a ring event |
| 3699 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3700 | * remove each response iocb in the response ring and calls the handle |
| 3701 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3702 | **/ |
| 3703 | static void |
| 3704 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3705 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3706 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3707 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3708 | IOCB_t *entry; |
| 3709 | IOCB_t *irsp = NULL; |
| 3710 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3711 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3712 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3713 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3714 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3715 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3716 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3717 | pring->stats.iocb_event++; |
| 3718 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3719 | /* |
| 3720 | * The next available response entry should never exceed the maximum |
| 3721 | * entries. If it does, treat it as an adapter hardware error. |
| 3722 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3723 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3724 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3725 | if (portRspPut >= portRspMax) { |
| 3726 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3727 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3728 | * rsp ring <portRspMax> |
| 3729 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3730 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3731 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3732 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3733 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3734 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3735 | phba->link_state = LPFC_HBA_ERROR; |
| 3736 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3737 | |
| 3738 | phba->work_hs = HS_FFER3; |
| 3739 | lpfc_handle_eratt(phba); |
| 3740 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3741 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3745 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3746 | /* |
| 3747 | * Build a completion list and call the appropriate handler. |
| 3748 | * The process is to get the next available response iocb, get |
| 3749 | * a free iocb from the list, copy the response data into the |
| 3750 | * free iocb, insert to the continuation list, and update the |
| 3751 | * next response index to slim. This process makes response |
| 3752 | * iocb's in the ring available to DMA as fast as possible but |
| 3753 | * pays a penalty for a copy operation. Since the iocb is |
| 3754 | * only 32 bytes, this penalty is considered small relative to |
| 3755 | * the PCI reads for register values and a slim write. When |
| 3756 | * the ulpLe field is set, the entire Command has been |
| 3757 | * received. |
| 3758 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3759 | entry = lpfc_resp_iocb(phba, pring); |
| 3760 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3761 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3762 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3763 | if (rspiocbp == NULL) { |
| 3764 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3765 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | break; |
| 3767 | } |
| 3768 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3769 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3770 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3771 | irsp = &rspiocbp->iocb; |
| 3772 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3773 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3774 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3775 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3776 | if (pring->ringno == LPFC_ELS_RING) { |
| 3777 | lpfc_debugfs_slow_ring_trc(phba, |
| 3778 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3779 | *(((uint32_t *) irsp) + 4), |
| 3780 | *(((uint32_t *) irsp) + 6), |
| 3781 | *(((uint32_t *) irsp) + 7)); |
| 3782 | } |
| 3783 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3784 | writel(pring->sli.sli3.rspidx, |
| 3785 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3786 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3787 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3788 | /* Handle the response IOCB */ |
| 3789 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3790 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3791 | |
| 3792 | /* |
| 3793 | * If the port response put pointer has not been updated, sync |
| 3794 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3795 | * response put pointer. |
| 3796 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3797 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3798 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3799 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3800 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3802 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3803 | /* At least one response entry has been freed */ |
| 3804 | pring->stats.iocb_rsp_full++; |
| 3805 | /* SET RxRE_RSP in Chip Att register */ |
| 3806 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3807 | writel(status, phba->CAregaddr); |
| 3808 | readl(phba->CAregaddr); /* flush */ |
| 3809 | } |
| 3810 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3811 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3812 | pring->stats.iocb_cmd_empty++; |
| 3813 | |
| 3814 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3815 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3816 | lpfc_sli_resume_iocb(phba, pring); |
| 3817 | |
| 3818 | if ((pring->lpfc_sli_cmd_available)) |
| 3819 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3820 | |
| 3821 | } |
| 3822 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3823 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3824 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3825 | } |
| 3826 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3827 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3828 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3829 | * @phba: Pointer to HBA context object. |
| 3830 | * @pring: Pointer to driver SLI ring object. |
| 3831 | * @mask: Host attention register mask for this ring. |
| 3832 | * |
| 3833 | * This function is called from the worker thread when there is a pending |
| 3834 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3835 | * queue. The caller does not hold any lock. The function will remove each |
| 3836 | * response iocb from the response worker queue and calls the handle |
| 3837 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3838 | **/ |
| 3839 | static void |
| 3840 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3841 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3842 | { |
| 3843 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3844 | struct hbq_dmabuf *dmabuf; |
| 3845 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3846 | unsigned long iflag; |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3847 | int count = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3848 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3849 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3850 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3851 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3852 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3853 | /* Get the response iocb from the head of work queue */ |
| 3854 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3855 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3856 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3857 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3858 | |
| 3859 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3860 | case CQE_CODE_COMPL_WQE: |
| 3861 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3862 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3863 | /* Translate ELS WCQE to response IOCBQ */ |
| 3864 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3865 | irspiocbq); |
| 3866 | if (irspiocbq) |
| 3867 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3868 | irspiocbq); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3869 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3870 | break; |
| 3871 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3872 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3873 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3874 | cq_event); |
| 3875 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3876 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3877 | break; |
| 3878 | default: |
| 3879 | break; |
| 3880 | } |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3881 | |
| 3882 | /* Limit the number of events to 64 to avoid soft lockups */ |
| 3883 | if (count == 64) |
| 3884 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | |
| 3888 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3889 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3890 | * @phba: Pointer to HBA context object. |
| 3891 | * @pring: Pointer to driver SLI ring object. |
| 3892 | * |
| 3893 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3894 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3895 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3896 | * the return of this function. The caller is not required to hold any locks. |
| 3897 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3898 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3900 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3901 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3902 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3903 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3904 | if (pring->ringno == LPFC_ELS_RING) { |
| 3905 | lpfc_fabric_abort_hba(phba); |
| 3906 | } |
| 3907 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3908 | /* Error everything on txq and txcmplq |
| 3909 | * First do the txq. |
| 3910 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3911 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3912 | spin_lock_irq(&pring->ring_lock); |
| 3913 | list_splice_init(&pring->txq, &completions); |
| 3914 | pring->txq_cnt = 0; |
| 3915 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3916 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3917 | spin_lock_irq(&phba->hbalock); |
| 3918 | /* Next issue ABTS for everything on the txcmplq */ |
| 3919 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3920 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3921 | spin_unlock_irq(&phba->hbalock); |
| 3922 | } else { |
| 3923 | spin_lock_irq(&phba->hbalock); |
| 3924 | list_splice_init(&pring->txq, &completions); |
| 3925 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3926 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3927 | /* Next issue ABTS for everything on the txcmplq */ |
| 3928 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3929 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3930 | spin_unlock_irq(&phba->hbalock); |
| 3931 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3932 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3933 | /* Cancel all the IOCBs from the completions list */ |
| 3934 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3935 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3936 | } |
| 3937 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3938 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3939 | * lpfc_sli_abort_wqe_ring - Abort all iocbs in the ring |
| 3940 | * @phba: Pointer to HBA context object. |
| 3941 | * @pring: Pointer to driver SLI ring object. |
| 3942 | * |
| 3943 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3944 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3945 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3946 | * the return of this function. The caller is not required to hold any locks. |
| 3947 | **/ |
| 3948 | void |
| 3949 | lpfc_sli_abort_wqe_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3950 | { |
| 3951 | LIST_HEAD(completions); |
| 3952 | struct lpfc_iocbq *iocb, *next_iocb; |
| 3953 | |
| 3954 | if (pring->ringno == LPFC_ELS_RING) |
| 3955 | lpfc_fabric_abort_hba(phba); |
| 3956 | |
| 3957 | spin_lock_irq(&phba->hbalock); |
| 3958 | /* Next issue ABTS for everything on the txcmplq */ |
| 3959 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3960 | lpfc_sli4_abort_nvme_io(phba, pring, iocb); |
| 3961 | spin_unlock_irq(&phba->hbalock); |
| 3962 | } |
| 3963 | |
| 3964 | |
| 3965 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3966 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 3967 | * @phba: Pointer to HBA context object. |
| 3968 | * @pring: Pointer to driver SLI ring object. |
| 3969 | * |
| 3970 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 3971 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3972 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3973 | * the return of this function. The caller is not required to hold any locks. |
| 3974 | **/ |
| 3975 | void |
| 3976 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 3977 | { |
| 3978 | struct lpfc_sli *psli = &phba->sli; |
| 3979 | struct lpfc_sli_ring *pring; |
| 3980 | uint32_t i; |
| 3981 | |
| 3982 | /* Look on all the FCP Rings for the iotag */ |
| 3983 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3984 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3985 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3986 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3987 | } |
| 3988 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3989 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3990 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3991 | } |
| 3992 | } |
| 3993 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3994 | /** |
| 3995 | * lpfc_sli_abort_nvme_rings - Abort all wqes in all NVME rings |
| 3996 | * @phba: Pointer to HBA context object. |
| 3997 | * |
| 3998 | * This function aborts all wqes in NVME rings. This function issues an |
| 3999 | * abort wqe for all the outstanding IO commands in txcmplq. The iocbs in |
| 4000 | * the txcmplq is not guaranteed to complete before the return of this |
| 4001 | * function. The caller is not required to hold any locks. |
| 4002 | **/ |
| 4003 | void |
| 4004 | lpfc_sli_abort_nvme_rings(struct lpfc_hba *phba) |
| 4005 | { |
| 4006 | struct lpfc_sli_ring *pring; |
| 4007 | uint32_t i; |
| 4008 | |
| 4009 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 4010 | return; |
| 4011 | |
| 4012 | /* Abort all IO on each NVME ring. */ |
| 4013 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 4014 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 4015 | lpfc_sli_abort_wqe_ring(phba, pring); |
| 4016 | } |
| 4017 | } |
| 4018 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4019 | |
| 4020 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4021 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4022 | * @phba: Pointer to HBA context object. |
| 4023 | * |
| 4024 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 4025 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 4026 | * for all the iocb commands in txcmplq, they will just be returned with |
| 4027 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 4028 | * slot has been permanently disabled. |
| 4029 | **/ |
| 4030 | void |
| 4031 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 4032 | { |
| 4033 | LIST_HEAD(txq); |
| 4034 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4035 | struct lpfc_sli *psli = &phba->sli; |
| 4036 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4037 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4038 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4039 | |
| 4040 | spin_lock_irq(&phba->hbalock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4041 | /* Indicate the I/O queues are flushed */ |
| 4042 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4043 | spin_unlock_irq(&phba->hbalock); |
| 4044 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4045 | /* Look on all the FCP Rings for the iotag */ |
| 4046 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 4047 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4048 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4049 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4050 | spin_lock_irq(&pring->ring_lock); |
| 4051 | /* Retrieve everything on txq */ |
| 4052 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4053 | list_for_each_entry_safe(piocb, next_iocb, |
| 4054 | &pring->txcmplq, list) |
| 4055 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4056 | /* Retrieve everything on the txcmplq */ |
| 4057 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4058 | pring->txq_cnt = 0; |
| 4059 | pring->txcmplq_cnt = 0; |
| 4060 | spin_unlock_irq(&pring->ring_lock); |
| 4061 | |
| 4062 | /* Flush the txq */ |
| 4063 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 4064 | IOSTAT_LOCAL_REJECT, |
| 4065 | IOERR_SLI_DOWN); |
| 4066 | /* Flush the txcmpq */ |
| 4067 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4068 | IOSTAT_LOCAL_REJECT, |
| 4069 | IOERR_SLI_DOWN); |
| 4070 | } |
| 4071 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4072 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4073 | |
| 4074 | spin_lock_irq(&phba->hbalock); |
| 4075 | /* Retrieve everything on txq */ |
| 4076 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4077 | list_for_each_entry_safe(piocb, next_iocb, |
| 4078 | &pring->txcmplq, list) |
| 4079 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4080 | /* Retrieve everything on the txcmplq */ |
| 4081 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4082 | pring->txq_cnt = 0; |
| 4083 | pring->txcmplq_cnt = 0; |
| 4084 | spin_unlock_irq(&phba->hbalock); |
| 4085 | |
| 4086 | /* Flush the txq */ |
| 4087 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 4088 | IOERR_SLI_DOWN); |
| 4089 | /* Flush the txcmpq */ |
| 4090 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 4091 | IOERR_SLI_DOWN); |
| 4092 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4096 | * lpfc_sli_flush_nvme_rings - flush all wqes in the nvme rings |
| 4097 | * @phba: Pointer to HBA context object. |
| 4098 | * |
| 4099 | * This function flushes all wqes in the nvme rings and frees all resources |
| 4100 | * in the txcmplq. This function does not issue abort wqes for the IO |
| 4101 | * commands in txcmplq, they will just be returned with |
| 4102 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 4103 | * slot has been permanently disabled. |
| 4104 | **/ |
| 4105 | void |
| 4106 | lpfc_sli_flush_nvme_rings(struct lpfc_hba *phba) |
| 4107 | { |
| 4108 | LIST_HEAD(txcmplq); |
| 4109 | struct lpfc_sli_ring *pring; |
| 4110 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4111 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4112 | |
| 4113 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 4114 | return; |
| 4115 | |
| 4116 | /* Hint to other driver operations that a flush is in progress. */ |
| 4117 | spin_lock_irq(&phba->hbalock); |
| 4118 | phba->hba_flag |= HBA_NVME_IOQ_FLUSH; |
| 4119 | spin_unlock_irq(&phba->hbalock); |
| 4120 | |
| 4121 | /* Cycle through all NVME rings and complete each IO with |
| 4122 | * a local driver reason code. This is a flush so no |
| 4123 | * abort exchange to FW. |
| 4124 | */ |
| 4125 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 4126 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 4127 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4128 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4129 | list_for_each_entry_safe(piocb, next_iocb, |
| 4130 | &pring->txcmplq, list) |
| 4131 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
| 4132 | /* Retrieve everything on the txcmplq */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4133 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4134 | pring->txcmplq_cnt = 0; |
| 4135 | spin_unlock_irq(&pring->ring_lock); |
| 4136 | |
| 4137 | /* Flush the txcmpq &&&PAE */ |
| 4138 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4139 | IOSTAT_LOCAL_REJECT, |
| 4140 | IOERR_SLI_DOWN); |
| 4141 | } |
| 4142 | } |
| 4143 | |
| 4144 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4145 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4146 | * @phba: Pointer to HBA context object. |
| 4147 | * @mask: Bit mask to be checked. |
| 4148 | * |
| 4149 | * This function reads the host status register and compares |
| 4150 | * with the provided bit mask to check if HBA completed |
| 4151 | * the restart. This function will wait in a loop for the |
| 4152 | * HBA to complete restart. If the HBA does not restart within |
| 4153 | * 15 iterations, the function will reset the HBA again. The |
| 4154 | * function returns 1 when HBA fail to restart otherwise returns |
| 4155 | * zero. |
| 4156 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4157 | static int |
| 4158 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4159 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4160 | uint32_t status; |
| 4161 | int i = 0; |
| 4162 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4163 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4164 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4165 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4166 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4167 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4168 | /* |
| 4169 | * Check status register every 100ms for 5 retries, then every |
| 4170 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 4171 | * every 2.5 sec for 4. |
| 4172 | * Break our of the loop if errors occurred during init. |
| 4173 | */ |
| 4174 | while (((status & mask) != mask) && |
| 4175 | !(status & HS_FFERM) && |
| 4176 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4177 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4178 | if (i <= 5) |
| 4179 | msleep(10); |
| 4180 | else if (i <= 10) |
| 4181 | msleep(500); |
| 4182 | else |
| 4183 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4184 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4185 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4186 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4187 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4188 | lpfc_sli_brdrestart(phba); |
| 4189 | } |
| 4190 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4191 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 4192 | retval = 1; |
| 4193 | break; |
| 4194 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4195 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4196 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4197 | /* Check to see if any errors occurred during init */ |
| 4198 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4199 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4200 | "2751 Adapter failed to restart, " |
| 4201 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 4202 | status, |
| 4203 | readl(phba->MBslimaddr + 0xa8), |
| 4204 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4205 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4206 | retval = 1; |
| 4207 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4208 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4209 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4210 | } |
| 4211 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4212 | /** |
| 4213 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 4214 | * @phba: Pointer to HBA context object. |
| 4215 | * @mask: Bit mask to be checked. |
| 4216 | * |
| 4217 | * This function checks the host status register to check if HBA is |
| 4218 | * ready. This function will wait in a loop for the HBA to be ready |
| 4219 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 4220 | * function again. The function returns 1 when HBA fail to be ready |
| 4221 | * otherwise returns zero. |
| 4222 | **/ |
| 4223 | static int |
| 4224 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 4225 | { |
| 4226 | uint32_t status; |
| 4227 | int retval = 0; |
| 4228 | |
| 4229 | /* Read the HBA Host Status Register */ |
| 4230 | status = lpfc_sli4_post_status_check(phba); |
| 4231 | |
| 4232 | if (status) { |
| 4233 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 4234 | lpfc_sli_brdrestart(phba); |
| 4235 | status = lpfc_sli4_post_status_check(phba); |
| 4236 | } |
| 4237 | |
| 4238 | /* Check to see if any errors occurred during init */ |
| 4239 | if (status) { |
| 4240 | phba->link_state = LPFC_HBA_ERROR; |
| 4241 | retval = 1; |
| 4242 | } else |
| 4243 | phba->sli4_hba.intr_enable = 0; |
| 4244 | |
| 4245 | return retval; |
| 4246 | } |
| 4247 | |
| 4248 | /** |
| 4249 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 4250 | * @phba: Pointer to HBA context object. |
| 4251 | * @mask: Bit mask to be checked. |
| 4252 | * |
| 4253 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 4254 | * from the API jump table function pointer from the lpfc_hba struct. |
| 4255 | **/ |
| 4256 | int |
| 4257 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 4258 | { |
| 4259 | return phba->lpfc_sli_brdready(phba, mask); |
| 4260 | } |
| 4261 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4262 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 4263 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4264 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4265 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4266 | * @phba: Pointer to HBA context object. |
| 4267 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 4268 | * This function is called before resetting an HBA. This function is called |
| 4269 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4270 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4271 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4272 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4273 | uint32_t __iomem *resp_buf; |
| 4274 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4275 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4276 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4277 | int i; |
| 4278 | uint8_t hdrtype; |
| 4279 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 4280 | lockdep_assert_held(&phba->hbalock); |
| 4281 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4282 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 4283 | if (hdrtype != 0x80 || |
| 4284 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 4285 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 4286 | return; |
| 4287 | |
| 4288 | /* |
| 4289 | * Tell the other part of the chip to suspend temporarily all |
| 4290 | * its DMA activity. |
| 4291 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4292 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4293 | |
| 4294 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4295 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 4296 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4297 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 4298 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4299 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4300 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4301 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4302 | return; |
| 4303 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4304 | /* Clear Chip error bit */ |
| 4305 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4306 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4307 | } |
| 4308 | |
| 4309 | mbox = 0; |
| 4310 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 4311 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 4312 | |
| 4313 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4314 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4315 | writel(mbox, mbox_buf); |
| 4316 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4317 | for (i = 0; i < 50; i++) { |
| 4318 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4319 | return; |
| 4320 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 4321 | mdelay(1); |
| 4322 | else |
| 4323 | break; |
| 4324 | } |
| 4325 | resp_data = 0; |
| 4326 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4327 | return; |
| 4328 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4329 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4330 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4331 | goto restore_hc; |
| 4332 | else |
| 4333 | goto clear_errat; |
| 4334 | } |
| 4335 | |
| 4336 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4337 | resp_data = 0; |
| 4338 | for (i = 0; i < 500; i++) { |
| 4339 | if (lpfc_readl(resp_buf, &resp_data)) |
| 4340 | return; |
| 4341 | if (resp_data != mbox) |
| 4342 | mdelay(1); |
| 4343 | else |
| 4344 | break; |
| 4345 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4346 | |
| 4347 | clear_errat: |
| 4348 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4349 | while (++i < 500) { |
| 4350 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4351 | return; |
| 4352 | if (!(ha_copy & HA_ERATT)) |
| 4353 | mdelay(1); |
| 4354 | else |
| 4355 | break; |
| 4356 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4357 | |
| 4358 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 4359 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4360 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4364 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4365 | writel(hc_copy, phba->HCregaddr); |
| 4366 | readl(phba->HCregaddr); /* flush */ |
| 4367 | } |
| 4368 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4369 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4370 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4371 | * @phba: Pointer to HBA context object. |
| 4372 | * |
| 4373 | * This function issues a kill_board mailbox command and waits for |
| 4374 | * the error attention interrupt. This function is called for stopping |
| 4375 | * the firmware processing. The caller is not required to hold any |
| 4376 | * locks. This function calls lpfc_hba_down_post function to free |
| 4377 | * any pending commands after the kill. The function will return 1 when it |
| 4378 | * fails to kill the board else will return 0. |
| 4379 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4380 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4381 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4382 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4383 | struct lpfc_sli *psli; |
| 4384 | LPFC_MBOXQ_t *pmb; |
| 4385 | uint32_t status; |
| 4386 | uint32_t ha_copy; |
| 4387 | int retval; |
| 4388 | int i = 0; |
| 4389 | |
| 4390 | psli = &phba->sli; |
| 4391 | |
| 4392 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4393 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4394 | "0329 Kill HBA Data: x%x x%x\n", |
| 4395 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4396 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4397 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4398 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4399 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4400 | |
| 4401 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4402 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4403 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 4404 | spin_unlock_irq(&phba->hbalock); |
| 4405 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4406 | return 1; |
| 4407 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4408 | status &= ~HC_ERINT_ENA; |
| 4409 | writel(status, phba->HCregaddr); |
| 4410 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4411 | phba->link_flag |= LS_IGNORE_ERATT; |
| 4412 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4413 | |
| 4414 | lpfc_kill_board(phba, pmb); |
| 4415 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4416 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4417 | |
| 4418 | if (retval != MBX_SUCCESS) { |
| 4419 | if (retval != MBX_BUSY) |
| 4420 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4421 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4422 | "2752 KILL_BOARD command failed retval %d\n", |
| 4423 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4424 | spin_lock_irq(&phba->hbalock); |
| 4425 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4426 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4427 | return 1; |
| 4428 | } |
| 4429 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4430 | spin_lock_irq(&phba->hbalock); |
| 4431 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 4432 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4433 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4434 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4435 | |
| 4436 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 4437 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 4438 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 4439 | * board is now undefined. |
| 4440 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4441 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4442 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4443 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 4444 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4445 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4446 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4450 | if (ha_copy & HA_ERATT) { |
| 4451 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4452 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4453 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4454 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4455 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4456 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4457 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4458 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4459 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4460 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4461 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4462 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4463 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4464 | } |
| 4465 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4466 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4467 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4468 | * @phba: Pointer to HBA context object. |
| 4469 | * |
| 4470 | * This function resets the HBA by writing HC_INITFF to the control |
| 4471 | * register. After the HBA resets, this function resets all the iocb ring |
| 4472 | * indices. This function disables PCI layer parity checking during |
| 4473 | * the reset. |
| 4474 | * This function returns 0 always. |
| 4475 | * The caller is not required to hold any locks. |
| 4476 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4477 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4478 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4479 | { |
| 4480 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4481 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4482 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4483 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4484 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4485 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4486 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4487 | /* Reset HBA */ |
| 4488 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4489 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4490 | (phba->pport) ? phba->pport->port_state : 0, |
| 4491 | psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4492 | |
| 4493 | /* perform board reset */ |
| 4494 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4495 | phba->link_events = 0; |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4496 | if (phba->pport) { |
| 4497 | phba->pport->fc_myDID = 0; |
| 4498 | phba->pport->fc_prevDID = 0; |
| 4499 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4500 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4501 | /* Turn off parity checking and serr during the physical reset */ |
| 4502 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4503 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4504 | (cfg_value & |
| 4505 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4506 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4507 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4508 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4509 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4510 | writel(HC_INITFF, phba->HCregaddr); |
| 4511 | mdelay(1); |
| 4512 | readl(phba->HCregaddr); /* flush */ |
| 4513 | writel(0, phba->HCregaddr); |
| 4514 | readl(phba->HCregaddr); /* flush */ |
| 4515 | |
| 4516 | /* Restore PCI cmd register */ |
| 4517 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4518 | |
| 4519 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4520 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4521 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4523 | pring->sli.sli3.rspidx = 0; |
| 4524 | pring->sli.sli3.next_cmdidx = 0; |
| 4525 | pring->sli.sli3.local_getidx = 0; |
| 4526 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4527 | pring->missbufcnt = 0; |
| 4528 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4529 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4530 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4531 | return 0; |
| 4532 | } |
| 4533 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4534 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4535 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4536 | * @phba: Pointer to HBA context object. |
| 4537 | * |
| 4538 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4539 | * checking during resets the device. The caller is not required to hold |
| 4540 | * any locks. |
| 4541 | * |
| 4542 | * This function returns 0 always. |
| 4543 | **/ |
| 4544 | int |
| 4545 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4546 | { |
| 4547 | struct lpfc_sli *psli = &phba->sli; |
| 4548 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4549 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4550 | |
| 4551 | /* Reset HBA */ |
| 4552 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4553 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4554 | phba->pport->port_state, psli->sli_flag, |
| 4555 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4556 | |
| 4557 | /* perform board reset */ |
| 4558 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4559 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4560 | phba->pport->fc_myDID = 0; |
| 4561 | phba->pport->fc_prevDID = 0; |
| 4562 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4563 | spin_lock_irq(&phba->hbalock); |
| 4564 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4565 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4566 | spin_unlock_irq(&phba->hbalock); |
| 4567 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4568 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4569 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4570 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4571 | return rc; |
| 4572 | } |
| 4573 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4574 | /* Now physically reset the device */ |
| 4575 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4576 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4577 | |
| 4578 | /* Turn off parity checking and serr during the physical reset */ |
| 4579 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4580 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4581 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4582 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4583 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4584 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4585 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4586 | /* Restore PCI cmd register */ |
| 4587 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4588 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4589 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | /** |
| 4593 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4594 | * @phba: Pointer to HBA context object. |
| 4595 | * |
| 4596 | * This function is called in the SLI initialization code path to |
| 4597 | * restart the HBA. The caller is not required to hold any lock. |
| 4598 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4599 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4600 | * function to free any pending commands. The function enables |
| 4601 | * POST only during the first initialization. The function returns zero. |
| 4602 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4603 | * command before the return of this function. |
| 4604 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4605 | static int |
| 4606 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4607 | { |
| 4608 | MAILBOX_t *mb; |
| 4609 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4610 | volatile uint32_t word0; |
| 4611 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4612 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4613 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4614 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4615 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4616 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4617 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4618 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4619 | psli = &phba->sli; |
| 4620 | |
| 4621 | /* Restart HBA */ |
| 4622 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4623 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4624 | (phba->pport) ? phba->pport->port_state : 0, |
| 4625 | psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4626 | |
| 4627 | word0 = 0; |
| 4628 | mb = (MAILBOX_t *) &word0; |
| 4629 | mb->mbxCommand = MBX_RESTART; |
| 4630 | mb->mbxHc = 1; |
| 4631 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4632 | lpfc_reset_barrier(phba); |
| 4633 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4634 | to_slim = phba->MBslimaddr; |
| 4635 | writel(*(uint32_t *) mb, to_slim); |
| 4636 | readl(to_slim); /* flush */ |
| 4637 | |
| 4638 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4639 | if (phba->pport && phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4640 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4641 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4642 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4643 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4644 | writel(*(uint32_t *) mb, to_slim); |
| 4645 | readl(to_slim); /* flush */ |
| 4646 | |
| 4647 | lpfc_sli_brdreset(phba); |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4648 | if (phba->pport) |
| 4649 | phba->pport->stopped = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4650 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4651 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4652 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4653 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4654 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4655 | psli->stats_start = ktime_get_seconds(); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4656 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4657 | /* Give the INITFF and Post time to settle. */ |
| 4658 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4659 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4660 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4661 | if (hba_aer_enabled) |
| 4662 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4663 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4664 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4665 | |
| 4666 | return 0; |
| 4667 | } |
| 4668 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4669 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4670 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4671 | * @phba: Pointer to HBA context object. |
| 4672 | * |
| 4673 | * This function is called in the SLI initialization code path to restart |
| 4674 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4675 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4676 | * free any pending commands. |
| 4677 | **/ |
| 4678 | static int |
| 4679 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4680 | { |
| 4681 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4682 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4683 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4684 | |
| 4685 | /* Restart HBA */ |
| 4686 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4687 | "0296 Restart HBA Data: x%x x%x\n", |
| 4688 | phba->pport->port_state, psli->sli_flag); |
| 4689 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4690 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4691 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4692 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4693 | rc = lpfc_sli4_brdreset(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 4694 | if (rc) |
| 4695 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4696 | |
| 4697 | spin_lock_irq(&phba->hbalock); |
| 4698 | phba->pport->stopped = 0; |
| 4699 | phba->link_state = LPFC_INIT_START; |
| 4700 | phba->hba_flag = 0; |
| 4701 | spin_unlock_irq(&phba->hbalock); |
| 4702 | |
| 4703 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4704 | psli->stats_start = ktime_get_seconds(); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4705 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4706 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4707 | if (hba_aer_enabled) |
| 4708 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4709 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4710 | lpfc_hba_down_post(phba); |
James Smart | 569dbe8 | 2017-06-15 22:56:47 -0700 | [diff] [blame] | 4711 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4712 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4713 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | /** |
| 4717 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4718 | * @phba: Pointer to HBA context object. |
| 4719 | * |
| 4720 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4721 | * API jump table function pointer from the lpfc_hba struct. |
| 4722 | **/ |
| 4723 | int |
| 4724 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4725 | { |
| 4726 | return phba->lpfc_sli_brdrestart(phba); |
| 4727 | } |
| 4728 | |
| 4729 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4730 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4731 | * @phba: Pointer to HBA context object. |
| 4732 | * |
| 4733 | * This function is called after a HBA restart to wait for successful |
| 4734 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4735 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4736 | * iteration, the function will restart the HBA again. The function returns |
| 4737 | * zero if HBA successfully restarted else returns negative error code. |
| 4738 | **/ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4739 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4740 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4741 | { |
| 4742 | uint32_t status, i = 0; |
| 4743 | |
| 4744 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4745 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4746 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4747 | |
| 4748 | /* Check status register to see what current state is */ |
| 4749 | i = 0; |
| 4750 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4751 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4752 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4753 | * retries, then every 1 sec for 50 retires for a total of |
| 4754 | * ~60 seconds before reset the board again and check every |
| 4755 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4756 | * board ready is required by the Falcon FIPS zeroization |
| 4757 | * complete, and any reset the board in between shall cause |
| 4758 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4759 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4760 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4761 | /* Adapter failed to init, timeout, status reg |
| 4762 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4763 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4764 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4765 | "timeout, status reg x%x, " |
| 4766 | "FW Data: A8 x%x AC x%x\n", status, |
| 4767 | readl(phba->MBslimaddr + 0xa8), |
| 4768 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4769 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4770 | return -ETIMEDOUT; |
| 4771 | } |
| 4772 | |
| 4773 | /* Check to see if any errors occurred during init */ |
| 4774 | if (status & HS_FFERM) { |
| 4775 | /* ERROR: During chipset initialization */ |
| 4776 | /* Adapter failed to init, chipset, status reg |
| 4777 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4778 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4779 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4780 | "chipset, status reg x%x, " |
| 4781 | "FW Data: A8 x%x AC x%x\n", status, |
| 4782 | readl(phba->MBslimaddr + 0xa8), |
| 4783 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4784 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4785 | return -EIO; |
| 4786 | } |
| 4787 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4788 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4789 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4790 | else if (i <= 100) |
| 4791 | msleep(100); |
| 4792 | else |
| 4793 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4794 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4795 | if (i == 150) { |
| 4796 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4797 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4798 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4799 | } |
| 4800 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4801 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4802 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4803 | } |
| 4804 | |
| 4805 | /* Check to see if any errors occurred during init */ |
| 4806 | if (status & HS_FFERM) { |
| 4807 | /* ERROR: During chipset initialization */ |
| 4808 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4809 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4810 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4811 | "status reg x%x, " |
| 4812 | "FW Data: A8 x%x AC x%x\n", status, |
| 4813 | readl(phba->MBslimaddr + 0xa8), |
| 4814 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4815 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4816 | return -EIO; |
| 4817 | } |
| 4818 | |
| 4819 | /* Clear all interrupt enable conditions */ |
| 4820 | writel(0, phba->HCregaddr); |
| 4821 | readl(phba->HCregaddr); /* flush */ |
| 4822 | |
| 4823 | /* setup host attn register */ |
| 4824 | writel(0xffffffff, phba->HAregaddr); |
| 4825 | readl(phba->HAregaddr); /* flush */ |
| 4826 | return 0; |
| 4827 | } |
| 4828 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4829 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4830 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4831 | * |
| 4832 | * This function calculates and returns the number of HBQs required to be |
| 4833 | * configured. |
| 4834 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4835 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4836 | lpfc_sli_hbq_count(void) |
| 4837 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4838 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4839 | } |
| 4840 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4841 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4842 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4843 | * |
| 4844 | * This function adds the number of hbq entries in every HBQ to get |
| 4845 | * the total number of hbq entries required for the HBA and returns |
| 4846 | * the total count. |
| 4847 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4848 | static int |
| 4849 | lpfc_sli_hbq_entry_count(void) |
| 4850 | { |
| 4851 | int hbq_count = lpfc_sli_hbq_count(); |
| 4852 | int count = 0; |
| 4853 | int i; |
| 4854 | |
| 4855 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4856 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4857 | return count; |
| 4858 | } |
| 4859 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4860 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4861 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4862 | * |
| 4863 | * This function calculates amount of memory required for all hbq entries |
| 4864 | * to be configured and returns the total memory required. |
| 4865 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4866 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4867 | lpfc_sli_hbq_size(void) |
| 4868 | { |
| 4869 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4870 | } |
| 4871 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4872 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4873 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4874 | * @phba: Pointer to HBA context object. |
| 4875 | * |
| 4876 | * This function is called during the SLI initialization to configure |
| 4877 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4878 | * required to hold any locks. This function will return zero if successful |
| 4879 | * else it will return negative error code. |
| 4880 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4881 | static int |
| 4882 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4883 | { |
| 4884 | int hbq_count = lpfc_sli_hbq_count(); |
| 4885 | LPFC_MBOXQ_t *pmb; |
| 4886 | MAILBOX_t *pmbox; |
| 4887 | uint32_t hbqno; |
| 4888 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4889 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4890 | /* Get a Mailbox buffer to setup mailbox |
| 4891 | * commands for HBA initialization |
| 4892 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4893 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4894 | |
| 4895 | if (!pmb) |
| 4896 | return -ENOMEM; |
| 4897 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4898 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4899 | |
| 4900 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4901 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4902 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4903 | |
| 4904 | hbq_entry_index = 0; |
| 4905 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4906 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4907 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4908 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4909 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4910 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4911 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4912 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4913 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4914 | |
| 4915 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4916 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4917 | mbxStatus <status>, ring <num> */ |
| 4918 | |
| 4919 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4920 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4921 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4922 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4923 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4924 | pmbox->mbxStatus, hbqno); |
| 4925 | |
| 4926 | phba->link_state = LPFC_HBA_ERROR; |
| 4927 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4928 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4929 | } |
| 4930 | } |
| 4931 | phba->hbq_count = hbq_count; |
| 4932 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4933 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4934 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4935 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4936 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4937 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4938 | return 0; |
| 4939 | } |
| 4940 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4941 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4942 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4943 | * @phba: Pointer to HBA context object. |
| 4944 | * |
| 4945 | * This function is called during the SLI initialization to configure |
| 4946 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4947 | * required to hold any locks. This function will return zero if successful |
| 4948 | * else it will return negative error code. |
| 4949 | **/ |
| 4950 | static int |
| 4951 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4952 | { |
| 4953 | phba->hbq_in_use = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4954 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 4955 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4956 | phba->hbq_count = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4957 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4958 | /* Initially populate or replenish the HBQs */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4959 | return 0; |
| 4960 | } |
| 4961 | |
| 4962 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4963 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4964 | * @phba: Pointer to HBA context object. |
| 4965 | * @sli_mode: sli mode - 2/3 |
| 4966 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4967 | * This function is called by the sli initialization code path |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4968 | * to issue config_port mailbox command. This function restarts the |
| 4969 | * HBA firmware and issues a config_port mailbox command to configure |
| 4970 | * the SLI interface in the sli mode specified by sli_mode |
| 4971 | * variable. The caller is not required to hold any locks. |
| 4972 | * The function returns 0 if successful, else returns negative error |
| 4973 | * code. |
| 4974 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4975 | int |
| 4976 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4977 | { |
| 4978 | LPFC_MBOXQ_t *pmb; |
| 4979 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4980 | |
| 4981 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4982 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4983 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4984 | return -ENOMEM; |
| 4985 | } |
| 4986 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4987 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4988 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4989 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4990 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4991 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4992 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4993 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4994 | rc = lpfc_sli_chipset_init(phba); |
| 4995 | if (rc) |
| 4996 | break; |
| 4997 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4998 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4999 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5000 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5001 | resetcount++; |
| 5002 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5003 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 5004 | * value of 0 means the call was successful. Any other |
| 5005 | * nonzero value is a failure, but if ERESTART is returned, |
| 5006 | * the driver may reset the HBA and try again. |
| 5007 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5008 | rc = lpfc_config_port_prep(phba); |
| 5009 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5010 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5011 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5012 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5013 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5014 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5015 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5016 | lpfc_config_port(phba, pmb); |
| 5017 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5018 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 5019 | LPFC_SLI3_HBQ_ENABLED | |
| 5020 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5021 | LPFC_SLI3_BG_ENABLED | |
| 5022 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5023 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5024 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5025 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5026 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5027 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5028 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5029 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5030 | spin_unlock_irq(&phba->hbalock); |
| 5031 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5032 | } else { |
| 5033 | /* Allow asynchronous mailbox command to go through */ |
| 5034 | spin_lock_irq(&phba->hbalock); |
| 5035 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 5036 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5037 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5038 | |
| 5039 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 5040 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 5041 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5042 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5043 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5044 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5045 | if (!done) { |
| 5046 | rc = -EINVAL; |
| 5047 | goto do_prep_failed; |
| 5048 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5049 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 5050 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5051 | rc = -ENXIO; |
| 5052 | goto do_prep_failed; |
| 5053 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5054 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5055 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5056 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 5057 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 5058 | phba->max_vpi : phba->max_vports; |
| 5059 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5060 | } else |
| 5061 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5062 | phba->fips_level = 0; |
| 5063 | phba->fips_spec_rev = 0; |
| 5064 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5065 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5066 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 5067 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 5068 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5069 | "2850 Security Crypto Active. FIPS x%d " |
| 5070 | "(Spec Rev: x%d)", |
| 5071 | phba->fips_level, phba->fips_spec_rev); |
| 5072 | } |
| 5073 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 5074 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5075 | "2856 Config Port Security Crypto " |
| 5076 | "Error: x%x ", |
| 5077 | pmb->u.mb.un.varCfgPort.sec_err); |
| 5078 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5079 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5080 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5081 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5082 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 5083 | |
| 5084 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 5085 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5086 | |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5087 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 5088 | if (pmb->u.mb.un.varCfgPort.gbg == 0) { |
| 5089 | phba->cfg_enable_bg = 0; |
| 5090 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5091 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5092 | "0443 Adapter did not grant " |
| 5093 | "BlockGuard\n"); |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5094 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5095 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5096 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 5097 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5098 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5099 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5100 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5101 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5102 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5103 | return rc; |
| 5104 | } |
| 5105 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5106 | |
| 5107 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5108 | * lpfc_sli_hba_setup - SLI initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5109 | * @phba: Pointer to HBA context object. |
| 5110 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5111 | * This function is the main SLI initialization function. This function |
| 5112 | * is called by the HBA initialization code, HBA reset code and HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5113 | * error attention handler code. Caller is not required to hold any |
| 5114 | * locks. This function issues config_port mailbox command to configure |
| 5115 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 5116 | * calls the config_port_post function to issue init_link mailbox |
| 5117 | * command and to start the discovery. The function will return zero |
| 5118 | * if successful, else it will return negative error code. |
| 5119 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5120 | int |
| 5121 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 5122 | { |
| 5123 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5124 | int mode = 3, i; |
| 5125 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5126 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5127 | switch (phba->cfg_sli_mode) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5128 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 5129 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5130 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5131 | "1824 NPIV enabled: Override sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5132 | "parameter (%d) to auto (0).\n", |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5133 | phba->cfg_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5134 | break; |
| 5135 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5136 | mode = 2; |
| 5137 | break; |
| 5138 | case 0: |
| 5139 | case 3: |
| 5140 | break; |
| 5141 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5142 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5143 | "1819 Unrecognized sli_mode parameter: %d.\n", |
| 5144 | phba->cfg_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5145 | |
| 5146 | break; |
| 5147 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 5148 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5149 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5150 | rc = lpfc_sli_config_port(phba, mode); |
| 5151 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5152 | if (rc && phba->cfg_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5153 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5154 | "1820 Unable to select SLI-3. " |
| 5155 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5156 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5157 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | 4597663f | 2016-07-06 12:36:01 -0700 | [diff] [blame] | 5158 | else if (rc && mode == 2) |
| 5159 | rc = lpfc_sli_config_port(phba, 3); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5160 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5161 | goto lpfc_sli_hba_setup_error; |
| 5162 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5163 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 5164 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 5165 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 5166 | if (!rc) { |
| 5167 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5168 | "2709 This device supports " |
| 5169 | "Advanced Error Reporting (AER)\n"); |
| 5170 | spin_lock_irq(&phba->hbalock); |
| 5171 | phba->hba_flag |= HBA_AER_ENABLED; |
| 5172 | spin_unlock_irq(&phba->hbalock); |
| 5173 | } else { |
| 5174 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5175 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 5176 | "Advanced Error Reporting (AER): %d\n", |
| 5177 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5178 | phba->cfg_aer_support = 0; |
| 5179 | } |
| 5180 | } |
| 5181 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5182 | if (phba->sli_rev == 3) { |
| 5183 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 5184 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5185 | } else { |
| 5186 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 5187 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5188 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5189 | } |
| 5190 | |
| 5191 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5192 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 5193 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5194 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5195 | |
| 5196 | if (rc) |
| 5197 | goto lpfc_sli_hba_setup_error; |
| 5198 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5199 | /* Initialize VPIs. */ |
| 5200 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 5201 | /* |
| 5202 | * The VPI bitmask and physical ID array are allocated |
| 5203 | * and initialized once only - at driver load. A port |
| 5204 | * reset doesn't need to reinitialize this memory. |
| 5205 | */ |
| 5206 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 5207 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5208 | phba->vpi_bmask = kcalloc(longs, |
| 5209 | sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5210 | GFP_KERNEL); |
| 5211 | if (!phba->vpi_bmask) { |
| 5212 | rc = -ENOMEM; |
| 5213 | goto lpfc_sli_hba_setup_error; |
| 5214 | } |
| 5215 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5216 | phba->vpi_ids = kcalloc(phba->max_vpi + 1, |
| 5217 | sizeof(uint16_t), |
| 5218 | GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5219 | if (!phba->vpi_ids) { |
| 5220 | kfree(phba->vpi_bmask); |
| 5221 | rc = -ENOMEM; |
| 5222 | goto lpfc_sli_hba_setup_error; |
| 5223 | } |
| 5224 | for (i = 0; i < phba->max_vpi; i++) |
| 5225 | phba->vpi_ids[i] = i; |
| 5226 | } |
| 5227 | } |
| 5228 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5229 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5230 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 5231 | rc = lpfc_sli_hbq_setup(phba); |
| 5232 | if (rc) |
| 5233 | goto lpfc_sli_hba_setup_error; |
| 5234 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5235 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5236 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5237 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5238 | |
| 5239 | rc = lpfc_config_port_post(phba); |
| 5240 | if (rc) |
| 5241 | goto lpfc_sli_hba_setup_error; |
| 5242 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5243 | return rc; |
| 5244 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5245 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5246 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 5247 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5248 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5249 | return rc; |
| 5250 | } |
| 5251 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5252 | /** |
| 5253 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 5254 | * @phba: Pointer to HBA context object. |
| 5255 | * @mboxq: mailbox pointer. |
| 5256 | * This function issue a dump mailbox command to read config region |
| 5257 | * 23 and parse the records in the region and populate driver |
| 5258 | * data structure. |
| 5259 | **/ |
| 5260 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5261 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5262 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5263 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5264 | struct lpfc_dmabuf *mp; |
| 5265 | struct lpfc_mqe *mqe; |
| 5266 | uint32_t data_length; |
| 5267 | int rc; |
| 5268 | |
| 5269 | /* Program the default value of vlan_id and fc_map */ |
| 5270 | phba->valid_vlan = 0; |
| 5271 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5272 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5273 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5274 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5275 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5276 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5277 | return -ENOMEM; |
| 5278 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5279 | mqe = &mboxq->u.mqe; |
| 5280 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 5281 | rc = -ENOMEM; |
| 5282 | goto out_free_mboxq; |
| 5283 | } |
| 5284 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5285 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5286 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5287 | |
| 5288 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5289 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 5290 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5291 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5292 | "CQ: x%x x%x x%x x%x\n", |
| 5293 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5294 | bf_get(lpfc_mqe_command, mqe), |
| 5295 | bf_get(lpfc_mqe_status, mqe), |
| 5296 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 5297 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 5298 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 5299 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 5300 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 5301 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 5302 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 5303 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 5304 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 5305 | mboxq->mcqe.word0, |
| 5306 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 5307 | mboxq->mcqe.trailer); |
| 5308 | |
| 5309 | if (rc) { |
| 5310 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5311 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5312 | rc = -EIO; |
| 5313 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5314 | } |
| 5315 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 5316 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5317 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5318 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5319 | rc = -EIO; |
| 5320 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5321 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5322 | |
| 5323 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 5324 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5325 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5326 | rc = 0; |
| 5327 | |
| 5328 | out_free_mboxq: |
| 5329 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5330 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5331 | } |
| 5332 | |
| 5333 | /** |
| 5334 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 5335 | * @phba: pointer to lpfc hba data structure. |
| 5336 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 5337 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 5338 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 5339 | * On output, the number of data bytes in @vpd. |
| 5340 | * |
| 5341 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 5342 | * addition, this routine gets the port vpd data. |
| 5343 | * |
| 5344 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5345 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5346 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5347 | **/ |
| 5348 | static int |
| 5349 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 5350 | uint8_t *vpd, uint32_t *vpd_size) |
| 5351 | { |
| 5352 | int rc = 0; |
| 5353 | uint32_t dma_size; |
| 5354 | struct lpfc_dmabuf *dmabuf; |
| 5355 | struct lpfc_mqe *mqe; |
| 5356 | |
| 5357 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5358 | if (!dmabuf) |
| 5359 | return -ENOMEM; |
| 5360 | |
| 5361 | /* |
| 5362 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 5363 | * mailbox command. |
| 5364 | */ |
| 5365 | dma_size = *vpd_size; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 5366 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size, |
| 5367 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5368 | if (!dmabuf->virt) { |
| 5369 | kfree(dmabuf); |
| 5370 | return -ENOMEM; |
| 5371 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5372 | |
| 5373 | /* |
| 5374 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 5375 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 5376 | * in SLI3. This code corrects the conflicts. |
| 5377 | */ |
| 5378 | lpfc_read_rev(phba, mboxq); |
| 5379 | mqe = &mboxq->u.mqe; |
| 5380 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 5381 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 5382 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 5383 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 5384 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 5385 | |
| 5386 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5387 | if (rc) { |
| 5388 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5389 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 5390 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5391 | return -EIO; |
| 5392 | } |
| 5393 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5394 | /* |
| 5395 | * The available vpd length cannot be bigger than the |
| 5396 | * DMA buffer passed to the port. Catch the less than |
| 5397 | * case and update the caller's size. |
| 5398 | */ |
| 5399 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 5400 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 5401 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5402 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 5403 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5404 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5405 | dmabuf->virt, dmabuf->phys); |
| 5406 | kfree(dmabuf); |
| 5407 | return 0; |
| 5408 | } |
| 5409 | |
| 5410 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5411 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 5412 | * @phba: pointer to lpfc hba data structure. |
| 5413 | * |
| 5414 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5415 | * is attached to. |
| 5416 | * |
| 5417 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5418 | * 0 - successful |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5419 | * otherwise - failed to retrieve physical port name |
| 5420 | **/ |
| 5421 | static int |
| 5422 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 5423 | { |
| 5424 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5425 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 5426 | struct lpfc_controller_attribute *cntl_attr; |
| 5427 | struct lpfc_mbx_get_port_name *get_port_name; |
| 5428 | void *virtaddr = NULL; |
| 5429 | uint32_t alloclen, reqlen; |
| 5430 | uint32_t shdr_status, shdr_add_status; |
| 5431 | union lpfc_sli4_cfg_shdr *shdr; |
| 5432 | char cport_name = 0; |
| 5433 | int rc; |
| 5434 | |
| 5435 | /* We assume nothing at this point */ |
| 5436 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5437 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 5438 | |
| 5439 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5440 | if (!mboxq) |
| 5441 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5442 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5443 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5444 | lpfc_sli4_read_config(phba); |
| 5445 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 5446 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5447 | |
| 5448 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 5449 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 5450 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5451 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 5452 | LPFC_SLI4_MBX_NEMBED); |
| 5453 | if (alloclen < reqlen) { |
| 5454 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5455 | "3084 Allocated DMA memory size (%d) is " |
| 5456 | "less than the requested DMA memory size " |
| 5457 | "(%d)\n", alloclen, reqlen); |
| 5458 | rc = -ENOMEM; |
| 5459 | goto out_free_mboxq; |
| 5460 | } |
| 5461 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5462 | virtaddr = mboxq->sge_array->addr[0]; |
| 5463 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5464 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5465 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5466 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5467 | if (shdr_status || shdr_add_status || rc) { |
| 5468 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5469 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5470 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5471 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5472 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5473 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5474 | rc, shdr_status, shdr_add_status); |
| 5475 | rc = -ENXIO; |
| 5476 | goto out_free_mboxq; |
| 5477 | } |
| 5478 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5479 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5480 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5481 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5482 | phba->sli4_hba.lnk_info.lnk_no = |
| 5483 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 5484 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5485 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 5486 | phba->sli4_hba.lnk_info.lnk_tp, |
| 5487 | phba->sli4_hba.lnk_info.lnk_no); |
| 5488 | |
| 5489 | retrieve_ppname: |
| 5490 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5491 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5492 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5493 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5494 | LPFC_SLI4_MBX_EMBED); |
| 5495 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5496 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5497 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5498 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5499 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5500 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5501 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5502 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5503 | if (shdr_status || shdr_add_status || rc) { |
| 5504 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5505 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5506 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5507 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5508 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5509 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5510 | rc, shdr_status, shdr_add_status); |
| 5511 | rc = -ENXIO; |
| 5512 | goto out_free_mboxq; |
| 5513 | } |
| 5514 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5515 | case LPFC_LINK_NUMBER_0: |
| 5516 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5517 | &get_port_name->u.response); |
| 5518 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5519 | break; |
| 5520 | case LPFC_LINK_NUMBER_1: |
| 5521 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5522 | &get_port_name->u.response); |
| 5523 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5524 | break; |
| 5525 | case LPFC_LINK_NUMBER_2: |
| 5526 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5527 | &get_port_name->u.response); |
| 5528 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5529 | break; |
| 5530 | case LPFC_LINK_NUMBER_3: |
| 5531 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5532 | &get_port_name->u.response); |
| 5533 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5534 | break; |
| 5535 | default: |
| 5536 | break; |
| 5537 | } |
| 5538 | |
| 5539 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5540 | phba->Port[0] = cport_name; |
| 5541 | phba->Port[1] = '\0'; |
| 5542 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5543 | "3091 SLI get port name: %s\n", phba->Port); |
| 5544 | } |
| 5545 | |
| 5546 | out_free_mboxq: |
| 5547 | if (rc != MBX_TIMEOUT) { |
| 5548 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5549 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5550 | else |
| 5551 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5552 | } |
| 5553 | return rc; |
| 5554 | } |
| 5555 | |
| 5556 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5557 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5558 | * @phba: pointer to lpfc hba data structure. |
| 5559 | * |
| 5560 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5561 | * event queues |
| 5562 | **/ |
| 5563 | static void |
| 5564 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5565 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5566 | int qidx; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5567 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5568 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5569 | sli4_hba->sli4_cq_release(sli4_hba->mbx_cq, LPFC_QUEUE_REARM); |
| 5570 | sli4_hba->sli4_cq_release(sli4_hba->els_cq, LPFC_QUEUE_REARM); |
| 5571 | if (sli4_hba->nvmels_cq) |
| 5572 | sli4_hba->sli4_cq_release(sli4_hba->nvmels_cq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5573 | LPFC_QUEUE_REARM); |
| 5574 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5575 | if (sli4_hba->fcp_cq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5576 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5577 | sli4_hba->sli4_cq_release(sli4_hba->fcp_cq[qidx], |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5578 | LPFC_QUEUE_REARM); |
| 5579 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5580 | if (sli4_hba->nvme_cq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5581 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5582 | sli4_hba->sli4_cq_release(sli4_hba->nvme_cq[qidx], |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5583 | LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5584 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5585 | if (phba->cfg_fof) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5586 | sli4_hba->sli4_cq_release(sli4_hba->oas_cq, LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5587 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5588 | if (sli4_hba->hba_eq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5589 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5590 | sli4_hba->sli4_eq_release(sli4_hba->hba_eq[qidx], |
| 5591 | LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5592 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5593 | if (phba->nvmet_support) { |
| 5594 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5595 | sli4_hba->sli4_cq_release( |
| 5596 | sli4_hba->nvmet_cqset[qidx], |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5597 | LPFC_QUEUE_REARM); |
| 5598 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5599 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5600 | |
| 5601 | if (phba->cfg_fof) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5602 | sli4_hba->sli4_eq_release(sli4_hba->fof_eq, LPFC_QUEUE_REARM); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5606 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5607 | * @phba: Pointer to HBA context object. |
| 5608 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5609 | * @extnt_count: buffer to hold port available extent count. |
| 5610 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5611 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5612 | * This function calls the port and retrievs the number of available |
| 5613 | * extents and their size for a particular extent type. |
| 5614 | * |
| 5615 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5616 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5617 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5618 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5619 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5620 | { |
| 5621 | int rc = 0; |
| 5622 | uint32_t length; |
| 5623 | uint32_t mbox_tmo; |
| 5624 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5625 | LPFC_MBOXQ_t *mbox; |
| 5626 | |
| 5627 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5628 | if (!mbox) |
| 5629 | return -ENOMEM; |
| 5630 | |
| 5631 | /* Find out how many extents are available for this resource type */ |
| 5632 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5633 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5634 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5635 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5636 | length, LPFC_SLI4_MBX_EMBED); |
| 5637 | |
| 5638 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5639 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5640 | LPFC_SLI4_MBX_EMBED); |
| 5641 | if (unlikely(rc)) { |
| 5642 | rc = -EIO; |
| 5643 | goto err_exit; |
| 5644 | } |
| 5645 | |
| 5646 | if (!phba->sli4_hba.intr_enable) |
| 5647 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5648 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5649 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5650 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5651 | } |
| 5652 | if (unlikely(rc)) { |
| 5653 | rc = -EIO; |
| 5654 | goto err_exit; |
| 5655 | } |
| 5656 | |
| 5657 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5658 | if (bf_get(lpfc_mbox_hdr_status, |
| 5659 | &rsrc_info->header.cfg_shdr.response)) { |
| 5660 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5661 | "2930 Failed to get resource extents " |
| 5662 | "Status 0x%x Add'l Status 0x%x\n", |
| 5663 | bf_get(lpfc_mbox_hdr_status, |
| 5664 | &rsrc_info->header.cfg_shdr.response), |
| 5665 | bf_get(lpfc_mbox_hdr_add_status, |
| 5666 | &rsrc_info->header.cfg_shdr.response)); |
| 5667 | rc = -EIO; |
| 5668 | goto err_exit; |
| 5669 | } |
| 5670 | |
| 5671 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5672 | &rsrc_info->u.rsp); |
| 5673 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5674 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5675 | |
| 5676 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5677 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5678 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5679 | |
| 5680 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5681 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5682 | return rc; |
| 5683 | } |
| 5684 | |
| 5685 | /** |
| 5686 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5687 | * @phba: Pointer to HBA context object. |
| 5688 | * @type: The extent type to check. |
| 5689 | * |
| 5690 | * This function reads the current available extents from the port and checks |
| 5691 | * if the extent count or extent size has changed since the last access. |
| 5692 | * Callers use this routine post port reset to understand if there is a |
| 5693 | * extent reprovisioning requirement. |
| 5694 | * |
| 5695 | * Returns: |
| 5696 | * -Error: error indicates problem. |
| 5697 | * 1: Extent count or size has changed. |
| 5698 | * 0: No changes. |
| 5699 | **/ |
| 5700 | static int |
| 5701 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5702 | { |
| 5703 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5704 | uint16_t size_diff, rsrc_ext_size; |
| 5705 | int rc = 0; |
| 5706 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5707 | struct list_head *rsrc_blk_list = NULL; |
| 5708 | |
| 5709 | size_diff = 0; |
| 5710 | curr_ext_cnt = 0; |
| 5711 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5712 | &rsrc_ext_cnt, |
| 5713 | &rsrc_ext_size); |
| 5714 | if (unlikely(rc)) |
| 5715 | return -EIO; |
| 5716 | |
| 5717 | switch (type) { |
| 5718 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5719 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5720 | break; |
| 5721 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5722 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5723 | break; |
| 5724 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5725 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5726 | break; |
| 5727 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5728 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5729 | break; |
| 5730 | default: |
| 5731 | break; |
| 5732 | } |
| 5733 | |
| 5734 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5735 | curr_ext_cnt++; |
| 5736 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5737 | size_diff++; |
| 5738 | } |
| 5739 | |
| 5740 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5741 | rc = 1; |
| 5742 | |
| 5743 | return rc; |
| 5744 | } |
| 5745 | |
| 5746 | /** |
| 5747 | * lpfc_sli4_cfg_post_extnts - |
| 5748 | * @phba: Pointer to HBA context object. |
| 5749 | * @extnt_cnt - number of available extents. |
| 5750 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5751 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5752 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5753 | * |
| 5754 | * This function executes the extents allocation request. It also |
| 5755 | * takes care of the amount of memory needed to allocate or get the |
| 5756 | * allocated extents. It is the caller's responsibility to evaluate |
| 5757 | * the response. |
| 5758 | * |
| 5759 | * Returns: |
| 5760 | * -Error: Error value describes the condition found. |
| 5761 | * 0: if successful |
| 5762 | **/ |
| 5763 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5764 | lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5765 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5766 | { |
| 5767 | int rc = 0; |
| 5768 | uint32_t req_len; |
| 5769 | uint32_t emb_len; |
| 5770 | uint32_t alloc_len, mbox_tmo; |
| 5771 | |
| 5772 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5773 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5774 | |
| 5775 | /* |
| 5776 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5777 | * accounts for extents-specific word. |
| 5778 | */ |
| 5779 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5780 | sizeof(uint32_t); |
| 5781 | |
| 5782 | /* |
| 5783 | * Presume the allocation and response will fit into an embedded |
| 5784 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5785 | */ |
| 5786 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5787 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5788 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5789 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5790 | sizeof(uint32_t); |
| 5791 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5792 | } |
| 5793 | |
| 5794 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5795 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5796 | req_len, *emb); |
| 5797 | if (alloc_len < req_len) { |
| 5798 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5799 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5800 | "less than the requested DMA memory " |
| 5801 | "size (x%x)\n", alloc_len, req_len); |
| 5802 | return -ENOMEM; |
| 5803 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5804 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5805 | if (unlikely(rc)) |
| 5806 | return -EIO; |
| 5807 | |
| 5808 | if (!phba->sli4_hba.intr_enable) |
| 5809 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5810 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5811 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5812 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5813 | } |
| 5814 | |
| 5815 | if (unlikely(rc)) |
| 5816 | rc = -EIO; |
| 5817 | return rc; |
| 5818 | } |
| 5819 | |
| 5820 | /** |
| 5821 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5822 | * @phba: Pointer to HBA context object. |
| 5823 | * @type: The resource extent type to allocate. |
| 5824 | * |
| 5825 | * This function allocates the number of elements for the specified |
| 5826 | * resource type. |
| 5827 | **/ |
| 5828 | static int |
| 5829 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5830 | { |
| 5831 | bool emb = false; |
| 5832 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5833 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5834 | uint16_t *ids; |
| 5835 | int i, rc; |
| 5836 | unsigned long longs; |
| 5837 | unsigned long *bmask; |
| 5838 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5839 | LPFC_MBOXQ_t *mbox; |
| 5840 | uint32_t length; |
| 5841 | struct lpfc_id_range *id_array = NULL; |
| 5842 | void *virtaddr = NULL; |
| 5843 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5844 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5845 | struct list_head *ext_blk_list; |
| 5846 | |
| 5847 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5848 | &rsrc_cnt, |
| 5849 | &rsrc_size); |
| 5850 | if (unlikely(rc)) |
| 5851 | return -EIO; |
| 5852 | |
| 5853 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5854 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5855 | "3009 No available Resource Extents " |
| 5856 | "for resource type 0x%x: Count: 0x%x, " |
| 5857 | "Size 0x%x\n", type, rsrc_cnt, |
| 5858 | rsrc_size); |
| 5859 | return -ENOMEM; |
| 5860 | } |
| 5861 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5862 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5863 | "2903 Post resource extents type-0x%x: " |
| 5864 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5865 | |
| 5866 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5867 | if (!mbox) |
| 5868 | return -ENOMEM; |
| 5869 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5870 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5871 | if (unlikely(rc)) { |
| 5872 | rc = -EIO; |
| 5873 | goto err_exit; |
| 5874 | } |
| 5875 | |
| 5876 | /* |
| 5877 | * Figure out where the response is located. Then get local pointers |
| 5878 | * to the response data. The port does not guarantee to respond to |
| 5879 | * all extents counts request so update the local variable with the |
| 5880 | * allocated count from the port. |
| 5881 | */ |
| 5882 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5883 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5884 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5885 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5886 | } else { |
| 5887 | virtaddr = mbox->sge_array->addr[0]; |
| 5888 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5889 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5890 | id_array = &n_rsrc->id; |
| 5891 | } |
| 5892 | |
| 5893 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5894 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5895 | |
| 5896 | /* |
| 5897 | * Based on the resource size and count, correct the base and max |
| 5898 | * resource values. |
| 5899 | */ |
| 5900 | length = sizeof(struct lpfc_rsrc_blks); |
| 5901 | switch (type) { |
| 5902 | case LPFC_RSC_TYPE_FCOE_RPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5903 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5904 | sizeof(unsigned long), |
| 5905 | GFP_KERNEL); |
| 5906 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5907 | rc = -ENOMEM; |
| 5908 | goto err_exit; |
| 5909 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5910 | phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5911 | sizeof(uint16_t), |
| 5912 | GFP_KERNEL); |
| 5913 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5914 | kfree(phba->sli4_hba.rpi_bmask); |
| 5915 | rc = -ENOMEM; |
| 5916 | goto err_exit; |
| 5917 | } |
| 5918 | |
| 5919 | /* |
| 5920 | * The next_rpi was initialized with the maximum available |
| 5921 | * count but the port may allocate a smaller number. Catch |
| 5922 | * that case and update the next_rpi. |
| 5923 | */ |
| 5924 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5925 | |
| 5926 | /* Initialize local ptrs for common extent processing later. */ |
| 5927 | bmask = phba->sli4_hba.rpi_bmask; |
| 5928 | ids = phba->sli4_hba.rpi_ids; |
| 5929 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5930 | break; |
| 5931 | case LPFC_RSC_TYPE_FCOE_VPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5932 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5933 | GFP_KERNEL); |
| 5934 | if (unlikely(!phba->vpi_bmask)) { |
| 5935 | rc = -ENOMEM; |
| 5936 | goto err_exit; |
| 5937 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5938 | phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5939 | GFP_KERNEL); |
| 5940 | if (unlikely(!phba->vpi_ids)) { |
| 5941 | kfree(phba->vpi_bmask); |
| 5942 | rc = -ENOMEM; |
| 5943 | goto err_exit; |
| 5944 | } |
| 5945 | |
| 5946 | /* Initialize local ptrs for common extent processing later. */ |
| 5947 | bmask = phba->vpi_bmask; |
| 5948 | ids = phba->vpi_ids; |
| 5949 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5950 | break; |
| 5951 | case LPFC_RSC_TYPE_FCOE_XRI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5952 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5953 | sizeof(unsigned long), |
| 5954 | GFP_KERNEL); |
| 5955 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5956 | rc = -ENOMEM; |
| 5957 | goto err_exit; |
| 5958 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5959 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5960 | phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5961 | sizeof(uint16_t), |
| 5962 | GFP_KERNEL); |
| 5963 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5964 | kfree(phba->sli4_hba.xri_bmask); |
| 5965 | rc = -ENOMEM; |
| 5966 | goto err_exit; |
| 5967 | } |
| 5968 | |
| 5969 | /* Initialize local ptrs for common extent processing later. */ |
| 5970 | bmask = phba->sli4_hba.xri_bmask; |
| 5971 | ids = phba->sli4_hba.xri_ids; |
| 5972 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5973 | break; |
| 5974 | case LPFC_RSC_TYPE_FCOE_VFI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5975 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5976 | sizeof(unsigned long), |
| 5977 | GFP_KERNEL); |
| 5978 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5979 | rc = -ENOMEM; |
| 5980 | goto err_exit; |
| 5981 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5982 | phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5983 | sizeof(uint16_t), |
| 5984 | GFP_KERNEL); |
| 5985 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5986 | kfree(phba->sli4_hba.vfi_bmask); |
| 5987 | rc = -ENOMEM; |
| 5988 | goto err_exit; |
| 5989 | } |
| 5990 | |
| 5991 | /* Initialize local ptrs for common extent processing later. */ |
| 5992 | bmask = phba->sli4_hba.vfi_bmask; |
| 5993 | ids = phba->sli4_hba.vfi_ids; |
| 5994 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5995 | break; |
| 5996 | default: |
| 5997 | /* Unsupported Opcode. Fail call. */ |
| 5998 | id_array = NULL; |
| 5999 | bmask = NULL; |
| 6000 | ids = NULL; |
| 6001 | ext_blk_list = NULL; |
| 6002 | goto err_exit; |
| 6003 | } |
| 6004 | |
| 6005 | /* |
| 6006 | * Complete initializing the extent configuration with the |
| 6007 | * allocated ids assigned to this function. The bitmask serves |
| 6008 | * as an index into the array and manages the available ids. The |
| 6009 | * array just stores the ids communicated to the port via the wqes. |
| 6010 | */ |
| 6011 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 6012 | if ((i % 2) == 0) |
| 6013 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 6014 | &id_array[k]); |
| 6015 | else |
| 6016 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 6017 | &id_array[k]); |
| 6018 | |
| 6019 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 6020 | if (unlikely(!rsrc_blks)) { |
| 6021 | rc = -ENOMEM; |
| 6022 | kfree(bmask); |
| 6023 | kfree(ids); |
| 6024 | goto err_exit; |
| 6025 | } |
| 6026 | rsrc_blks->rsrc_start = rsrc_id; |
| 6027 | rsrc_blks->rsrc_size = rsrc_size; |
| 6028 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 6029 | rsrc_start = rsrc_id; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6030 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6031 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6032 | lpfc_sli4_get_iocb_cnt(phba); |
| 6033 | phba->sli4_hba.nvme_xri_start = |
| 6034 | phba->sli4_hba.scsi_xri_start + |
| 6035 | phba->sli4_hba.scsi_xri_max; |
| 6036 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6037 | |
| 6038 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 6039 | ids[j] = rsrc_id; |
| 6040 | rsrc_id++; |
| 6041 | j++; |
| 6042 | } |
| 6043 | /* Entire word processed. Get next word.*/ |
| 6044 | if ((i % 2) == 1) |
| 6045 | k++; |
| 6046 | } |
| 6047 | err_exit: |
| 6048 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6049 | return rc; |
| 6050 | } |
| 6051 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6052 | |
| 6053 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6054 | /** |
| 6055 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 6056 | * @phba: Pointer to HBA context object. |
| 6057 | * @type: the extent's type. |
| 6058 | * |
| 6059 | * This function deallocates all extents of a particular resource type. |
| 6060 | * SLI4 does not allow for deallocating a particular extent range. It |
| 6061 | * is the caller's responsibility to release all kernel memory resources. |
| 6062 | **/ |
| 6063 | static int |
| 6064 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 6065 | { |
| 6066 | int rc; |
| 6067 | uint32_t length, mbox_tmo = 0; |
| 6068 | LPFC_MBOXQ_t *mbox; |
| 6069 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 6070 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 6071 | |
| 6072 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6073 | if (!mbox) |
| 6074 | return -ENOMEM; |
| 6075 | |
| 6076 | /* |
| 6077 | * This function sends an embedded mailbox because it only sends the |
| 6078 | * the resource type. All extents of this type are released by the |
| 6079 | * port. |
| 6080 | */ |
| 6081 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 6082 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6083 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6084 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 6085 | length, LPFC_SLI4_MBX_EMBED); |
| 6086 | |
| 6087 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 6088 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 6089 | LPFC_SLI4_MBX_EMBED); |
| 6090 | if (unlikely(rc)) { |
| 6091 | rc = -EIO; |
| 6092 | goto out_free_mbox; |
| 6093 | } |
| 6094 | if (!phba->sli4_hba.intr_enable) |
| 6095 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6096 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6097 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6098 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6099 | } |
| 6100 | if (unlikely(rc)) { |
| 6101 | rc = -EIO; |
| 6102 | goto out_free_mbox; |
| 6103 | } |
| 6104 | |
| 6105 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 6106 | if (bf_get(lpfc_mbox_hdr_status, |
| 6107 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 6108 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6109 | "2919 Failed to release resource extents " |
| 6110 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 6111 | "Resource memory not released.\n", |
| 6112 | type, |
| 6113 | bf_get(lpfc_mbox_hdr_status, |
| 6114 | &dealloc_rsrc->header.cfg_shdr.response), |
| 6115 | bf_get(lpfc_mbox_hdr_add_status, |
| 6116 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 6117 | rc = -EIO; |
| 6118 | goto out_free_mbox; |
| 6119 | } |
| 6120 | |
| 6121 | /* Release kernel memory resources for the specific type. */ |
| 6122 | switch (type) { |
| 6123 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6124 | kfree(phba->vpi_bmask); |
| 6125 | kfree(phba->vpi_ids); |
| 6126 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6127 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6128 | &phba->lpfc_vpi_blk_list, list) { |
| 6129 | list_del_init(&rsrc_blk->list); |
| 6130 | kfree(rsrc_blk); |
| 6131 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6132 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6133 | break; |
| 6134 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6135 | kfree(phba->sli4_hba.xri_bmask); |
| 6136 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6137 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6138 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 6139 | list_del_init(&rsrc_blk->list); |
| 6140 | kfree(rsrc_blk); |
| 6141 | } |
| 6142 | break; |
| 6143 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6144 | kfree(phba->sli4_hba.vfi_bmask); |
| 6145 | kfree(phba->sli4_hba.vfi_ids); |
| 6146 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6147 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6148 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 6149 | list_del_init(&rsrc_blk->list); |
| 6150 | kfree(rsrc_blk); |
| 6151 | } |
| 6152 | break; |
| 6153 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6154 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 6155 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6156 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 6157 | list_del_init(&rsrc_blk->list); |
| 6158 | kfree(rsrc_blk); |
| 6159 | } |
| 6160 | break; |
| 6161 | default: |
| 6162 | break; |
| 6163 | } |
| 6164 | |
| 6165 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6166 | |
| 6167 | out_free_mbox: |
| 6168 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6169 | return rc; |
| 6170 | } |
| 6171 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 6172 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6173 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 6174 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6175 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6176 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6177 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6178 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 6179 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6180 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6181 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 6182 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6183 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6184 | switch (feature) { |
| 6185 | case LPFC_SET_UE_RECOVERY: |
| 6186 | bf_set(lpfc_mbx_set_feature_UER, |
| 6187 | &mbox->u.mqe.un.set_feature, 1); |
| 6188 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 6189 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6190 | break; |
| 6191 | case LPFC_SET_MDS_DIAGS: |
| 6192 | bf_set(lpfc_mbx_set_feature_mds, |
| 6193 | &mbox->u.mqe.un.set_feature, 1); |
| 6194 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 6195 | &mbox->u.mqe.un.set_feature, 1); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6196 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 6197 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6198 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6199 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6200 | |
| 6201 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6202 | } |
| 6203 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6204 | /** |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6205 | * lpfc_ras_stop_fwlog: Disable FW logging by the adapter |
| 6206 | * @phba: Pointer to HBA context object. |
| 6207 | * |
| 6208 | * Disable FW logging into host memory on the adapter. To |
| 6209 | * be done before reading logs from the host memory. |
| 6210 | **/ |
| 6211 | void |
| 6212 | lpfc_ras_stop_fwlog(struct lpfc_hba *phba) |
| 6213 | { |
| 6214 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6215 | |
| 6216 | ras_fwlog->ras_active = false; |
| 6217 | |
| 6218 | /* Disable FW logging to host memory */ |
| 6219 | writel(LPFC_CTL_PDEV_CTL_DDL_RAS, |
| 6220 | phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET); |
| 6221 | } |
| 6222 | |
| 6223 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6224 | * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging. |
| 6225 | * @phba: Pointer to HBA context object. |
| 6226 | * |
| 6227 | * This function is called to free memory allocated for RAS FW logging |
| 6228 | * support in the driver. |
| 6229 | **/ |
| 6230 | void |
| 6231 | lpfc_sli4_ras_dma_free(struct lpfc_hba *phba) |
| 6232 | { |
| 6233 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6234 | struct lpfc_dmabuf *dmabuf, *next; |
| 6235 | |
| 6236 | if (!list_empty(&ras_fwlog->fwlog_buff_list)) { |
| 6237 | list_for_each_entry_safe(dmabuf, next, |
| 6238 | &ras_fwlog->fwlog_buff_list, |
| 6239 | list) { |
| 6240 | list_del(&dmabuf->list); |
| 6241 | dma_free_coherent(&phba->pcidev->dev, |
| 6242 | LPFC_RAS_MAX_ENTRY_SIZE, |
| 6243 | dmabuf->virt, dmabuf->phys); |
| 6244 | kfree(dmabuf); |
| 6245 | } |
| 6246 | } |
| 6247 | |
| 6248 | if (ras_fwlog->lwpd.virt) { |
| 6249 | dma_free_coherent(&phba->pcidev->dev, |
| 6250 | sizeof(uint32_t) * 2, |
| 6251 | ras_fwlog->lwpd.virt, |
| 6252 | ras_fwlog->lwpd.phys); |
| 6253 | ras_fwlog->lwpd.virt = NULL; |
| 6254 | } |
| 6255 | |
| 6256 | ras_fwlog->ras_active = false; |
| 6257 | } |
| 6258 | |
| 6259 | /** |
| 6260 | * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support |
| 6261 | * @phba: Pointer to HBA context object. |
| 6262 | * @fwlog_buff_count: Count of buffers to be created. |
| 6263 | * |
| 6264 | * This routine DMA memory for Log Write Position Data[LPWD] and buffer |
| 6265 | * to update FW log is posted to the adapter. |
| 6266 | * Buffer count is calculated based on module param ras_fwlog_buffsize |
| 6267 | * Size of each buffer posted to FW is 64K. |
| 6268 | **/ |
| 6269 | |
| 6270 | static int |
| 6271 | lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba, |
| 6272 | uint32_t fwlog_buff_count) |
| 6273 | { |
| 6274 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6275 | struct lpfc_dmabuf *dmabuf; |
| 6276 | int rc = 0, i = 0; |
| 6277 | |
| 6278 | /* Initialize List */ |
| 6279 | INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list); |
| 6280 | |
| 6281 | /* Allocate memory for the LWPD */ |
| 6282 | ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6283 | sizeof(uint32_t) * 2, |
| 6284 | &ras_fwlog->lwpd.phys, |
| 6285 | GFP_KERNEL); |
| 6286 | if (!ras_fwlog->lwpd.virt) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6287 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6288 | "6185 LWPD Memory Alloc Failed\n"); |
| 6289 | |
| 6290 | return -ENOMEM; |
| 6291 | } |
| 6292 | |
| 6293 | ras_fwlog->fw_buffcount = fwlog_buff_count; |
| 6294 | for (i = 0; i < ras_fwlog->fw_buffcount; i++) { |
| 6295 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 6296 | GFP_KERNEL); |
| 6297 | if (!dmabuf) { |
| 6298 | rc = -ENOMEM; |
| 6299 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6300 | "6186 Memory Alloc failed FW logging"); |
| 6301 | goto free_mem; |
| 6302 | } |
| 6303 | |
Sabyasachi Gupta | 359d0ac | 2018-11-18 20:08:48 +0530 | [diff] [blame] | 6304 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6305 | LPFC_RAS_MAX_ENTRY_SIZE, |
| 6306 | &dmabuf->phys, |
| 6307 | GFP_KERNEL); |
| 6308 | if (!dmabuf->virt) { |
| 6309 | kfree(dmabuf); |
| 6310 | rc = -ENOMEM; |
| 6311 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6312 | "6187 DMA Alloc Failed FW logging"); |
| 6313 | goto free_mem; |
| 6314 | } |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6315 | dmabuf->buffer_tag = i; |
| 6316 | list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list); |
| 6317 | } |
| 6318 | |
| 6319 | free_mem: |
| 6320 | if (rc) |
| 6321 | lpfc_sli4_ras_dma_free(phba); |
| 6322 | |
| 6323 | return rc; |
| 6324 | } |
| 6325 | |
| 6326 | /** |
| 6327 | * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command |
| 6328 | * @phba: pointer to lpfc hba data structure. |
| 6329 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 6330 | * |
| 6331 | * Completion handler for driver's RAS MBX command to the device. |
| 6332 | **/ |
| 6333 | static void |
| 6334 | lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6335 | { |
| 6336 | MAILBOX_t *mb; |
| 6337 | union lpfc_sli4_cfg_shdr *shdr; |
| 6338 | uint32_t shdr_status, shdr_add_status; |
| 6339 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6340 | |
| 6341 | mb = &pmb->u.mb; |
| 6342 | |
| 6343 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6344 | &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr; |
| 6345 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6346 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6347 | |
| 6348 | if (mb->mbxStatus != MBX_SUCCESS || shdr_status) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6349 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6350 | "6188 FW LOG mailbox " |
| 6351 | "completed with status x%x add_status x%x," |
| 6352 | " mbx status x%x\n", |
| 6353 | shdr_status, shdr_add_status, mb->mbxStatus); |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6354 | |
| 6355 | ras_fwlog->ras_hwsupport = false; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6356 | goto disable_ras; |
| 6357 | } |
| 6358 | |
| 6359 | ras_fwlog->ras_active = true; |
| 6360 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6361 | |
| 6362 | return; |
| 6363 | |
| 6364 | disable_ras: |
| 6365 | /* Free RAS DMA memory */ |
| 6366 | lpfc_sli4_ras_dma_free(phba); |
| 6367 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6368 | } |
| 6369 | |
| 6370 | /** |
| 6371 | * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command |
| 6372 | * @phba: pointer to lpfc hba data structure. |
| 6373 | * @fwlog_level: Logging verbosity level. |
| 6374 | * @fwlog_enable: Enable/Disable logging. |
| 6375 | * |
| 6376 | * Initialize memory and post mailbox command to enable FW logging in host |
| 6377 | * memory. |
| 6378 | **/ |
| 6379 | int |
| 6380 | lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba, |
| 6381 | uint32_t fwlog_level, |
| 6382 | uint32_t fwlog_enable) |
| 6383 | { |
| 6384 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6385 | struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL; |
| 6386 | struct lpfc_dmabuf *dmabuf; |
| 6387 | LPFC_MBOXQ_t *mbox; |
| 6388 | uint32_t len = 0, fwlog_buffsize, fwlog_entry_count; |
| 6389 | int rc = 0; |
| 6390 | |
| 6391 | fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE * |
| 6392 | phba->cfg_ras_fwlog_buffsize); |
| 6393 | fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE); |
| 6394 | |
| 6395 | /* |
| 6396 | * If re-enabling FW logging support use earlier allocated |
| 6397 | * DMA buffers while posting MBX command. |
| 6398 | **/ |
| 6399 | if (!ras_fwlog->lwpd.virt) { |
| 6400 | rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count); |
| 6401 | if (rc) { |
| 6402 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6403 | "6189 FW Log Memory Allocation Failed"); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6404 | return rc; |
| 6405 | } |
| 6406 | } |
| 6407 | |
| 6408 | /* Setup Mailbox command */ |
| 6409 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6410 | if (!mbox) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6411 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6412 | "6190 RAS MBX Alloc Failed"); |
| 6413 | rc = -ENOMEM; |
| 6414 | goto mem_free; |
| 6415 | } |
| 6416 | |
| 6417 | ras_fwlog->fw_loglevel = fwlog_level; |
| 6418 | len = (sizeof(struct lpfc_mbx_set_ras_fwlog) - |
| 6419 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6420 | |
| 6421 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL, |
| 6422 | LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION, |
| 6423 | len, LPFC_SLI4_MBX_EMBED); |
| 6424 | |
| 6425 | mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog; |
| 6426 | bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request, |
| 6427 | fwlog_enable); |
| 6428 | bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request, |
| 6429 | ras_fwlog->fw_loglevel); |
| 6430 | bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request, |
| 6431 | ras_fwlog->fw_buffcount); |
| 6432 | bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request, |
| 6433 | LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE); |
| 6434 | |
| 6435 | /* Update DMA buffer address */ |
| 6436 | list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) { |
| 6437 | memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE); |
| 6438 | |
| 6439 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo = |
| 6440 | putPaddrLow(dmabuf->phys); |
| 6441 | |
| 6442 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi = |
| 6443 | putPaddrHigh(dmabuf->phys); |
| 6444 | } |
| 6445 | |
| 6446 | /* Update LPWD address */ |
| 6447 | mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys); |
| 6448 | mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys); |
| 6449 | |
| 6450 | mbox->vport = phba->pport; |
| 6451 | mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl; |
| 6452 | |
| 6453 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6454 | |
| 6455 | if (rc == MBX_NOT_FINISHED) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6456 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6457 | "6191 FW-Log Mailbox failed. " |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6458 | "status %d mbxStatus : x%x", rc, |
| 6459 | bf_get(lpfc_mqe_status, &mbox->u.mqe)); |
| 6460 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6461 | rc = -EIO; |
| 6462 | goto mem_free; |
| 6463 | } else |
| 6464 | rc = 0; |
| 6465 | mem_free: |
| 6466 | if (rc) |
| 6467 | lpfc_sli4_ras_dma_free(phba); |
| 6468 | |
| 6469 | return rc; |
| 6470 | } |
| 6471 | |
| 6472 | /** |
| 6473 | * lpfc_sli4_ras_setup - Check if RAS supported on the adapter |
| 6474 | * @phba: Pointer to HBA context object. |
| 6475 | * |
| 6476 | * Check if RAS is supported on the adapter and initialize it. |
| 6477 | **/ |
| 6478 | void |
| 6479 | lpfc_sli4_ras_setup(struct lpfc_hba *phba) |
| 6480 | { |
| 6481 | /* Check RAS FW Log needs to be enabled or not */ |
| 6482 | if (lpfc_check_fwlog_support(phba)) |
| 6483 | return; |
| 6484 | |
| 6485 | lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level, |
| 6486 | LPFC_RAS_ENABLE_LOGGING); |
| 6487 | } |
| 6488 | |
| 6489 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6490 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 6491 | * @phba: Pointer to HBA context object. |
| 6492 | * |
| 6493 | * This function allocates all SLI4 resource identifiers. |
| 6494 | **/ |
| 6495 | int |
| 6496 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 6497 | { |
| 6498 | int i, rc, error = 0; |
| 6499 | uint16_t count, base; |
| 6500 | unsigned long longs; |
| 6501 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6502 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6503 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6504 | if (phba->sli4_hba.extents_in_use) { |
| 6505 | /* |
| 6506 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 6507 | * resource extent count must be read and allocated before |
| 6508 | * provisioning the resource id arrays. |
| 6509 | */ |
| 6510 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 6511 | LPFC_IDX_RSRC_RDY) { |
| 6512 | /* |
| 6513 | * Extent-based resources are set - the driver could |
| 6514 | * be in a port reset. Figure out if any corrective |
| 6515 | * actions need to be taken. |
| 6516 | */ |
| 6517 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6518 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6519 | if (rc != 0) |
| 6520 | error++; |
| 6521 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6522 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6523 | if (rc != 0) |
| 6524 | error++; |
| 6525 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6526 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6527 | if (rc != 0) |
| 6528 | error++; |
| 6529 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6530 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6531 | if (rc != 0) |
| 6532 | error++; |
| 6533 | |
| 6534 | /* |
| 6535 | * It's possible that the number of resources |
| 6536 | * provided to this port instance changed between |
| 6537 | * resets. Detect this condition and reallocate |
| 6538 | * resources. Otherwise, there is no action. |
| 6539 | */ |
| 6540 | if (error) { |
| 6541 | lpfc_printf_log(phba, KERN_INFO, |
| 6542 | LOG_MBOX | LOG_INIT, |
| 6543 | "2931 Detected extent resource " |
| 6544 | "change. Reallocating all " |
| 6545 | "extents.\n"); |
| 6546 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6547 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6548 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6549 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6550 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6551 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6552 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6553 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6554 | } else |
| 6555 | return 0; |
| 6556 | } |
| 6557 | |
| 6558 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6559 | if (unlikely(rc)) |
| 6560 | goto err_exit; |
| 6561 | |
| 6562 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6563 | if (unlikely(rc)) |
| 6564 | goto err_exit; |
| 6565 | |
| 6566 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6567 | if (unlikely(rc)) |
| 6568 | goto err_exit; |
| 6569 | |
| 6570 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6571 | if (unlikely(rc)) |
| 6572 | goto err_exit; |
| 6573 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6574 | LPFC_IDX_RSRC_RDY); |
| 6575 | return rc; |
| 6576 | } else { |
| 6577 | /* |
| 6578 | * The port does not support resource extents. The XRI, VPI, |
| 6579 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 6580 | * Just allocate the bitmasks and provision the resource id |
| 6581 | * arrays. If a port reset is active, the resources don't |
| 6582 | * need any action - just exit. |
| 6583 | */ |
| 6584 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6585 | LPFC_IDX_RSRC_RDY) { |
| 6586 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6587 | lpfc_sli4_remove_rpis(phba); |
| 6588 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6589 | /* RPIs. */ |
| 6590 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6591 | if (count <= 0) { |
| 6592 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6593 | "3279 Invalid provisioning of " |
| 6594 | "rpi:%d\n", count); |
| 6595 | rc = -EINVAL; |
| 6596 | goto err_exit; |
| 6597 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6598 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 6599 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6600 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6601 | sizeof(unsigned long), |
| 6602 | GFP_KERNEL); |
| 6603 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6604 | rc = -ENOMEM; |
| 6605 | goto err_exit; |
| 6606 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6607 | phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6608 | GFP_KERNEL); |
| 6609 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6610 | rc = -ENOMEM; |
| 6611 | goto free_rpi_bmask; |
| 6612 | } |
| 6613 | |
| 6614 | for (i = 0; i < count; i++) |
| 6615 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 6616 | |
| 6617 | /* VPIs. */ |
| 6618 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6619 | if (count <= 0) { |
| 6620 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6621 | "3280 Invalid provisioning of " |
| 6622 | "vpi:%d\n", count); |
| 6623 | rc = -EINVAL; |
| 6624 | goto free_rpi_ids; |
| 6625 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6626 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6627 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6628 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6629 | GFP_KERNEL); |
| 6630 | if (unlikely(!phba->vpi_bmask)) { |
| 6631 | rc = -ENOMEM; |
| 6632 | goto free_rpi_ids; |
| 6633 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6634 | phba->vpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6635 | GFP_KERNEL); |
| 6636 | if (unlikely(!phba->vpi_ids)) { |
| 6637 | rc = -ENOMEM; |
| 6638 | goto free_vpi_bmask; |
| 6639 | } |
| 6640 | |
| 6641 | for (i = 0; i < count; i++) |
| 6642 | phba->vpi_ids[i] = base + i; |
| 6643 | |
| 6644 | /* XRIs. */ |
| 6645 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6646 | if (count <= 0) { |
| 6647 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6648 | "3281 Invalid provisioning of " |
| 6649 | "xri:%d\n", count); |
| 6650 | rc = -EINVAL; |
| 6651 | goto free_vpi_ids; |
| 6652 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6653 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 6654 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6655 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6656 | sizeof(unsigned long), |
| 6657 | GFP_KERNEL); |
| 6658 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6659 | rc = -ENOMEM; |
| 6660 | goto free_vpi_ids; |
| 6661 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 6662 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6663 | phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6664 | GFP_KERNEL); |
| 6665 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6666 | rc = -ENOMEM; |
| 6667 | goto free_xri_bmask; |
| 6668 | } |
| 6669 | |
| 6670 | for (i = 0; i < count; i++) |
| 6671 | phba->sli4_hba.xri_ids[i] = base + i; |
| 6672 | |
| 6673 | /* VFIs. */ |
| 6674 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6675 | if (count <= 0) { |
| 6676 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6677 | "3282 Invalid provisioning of " |
| 6678 | "vfi:%d\n", count); |
| 6679 | rc = -EINVAL; |
| 6680 | goto free_xri_ids; |
| 6681 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6682 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 6683 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6684 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6685 | sizeof(unsigned long), |
| 6686 | GFP_KERNEL); |
| 6687 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6688 | rc = -ENOMEM; |
| 6689 | goto free_xri_ids; |
| 6690 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6691 | phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6692 | GFP_KERNEL); |
| 6693 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6694 | rc = -ENOMEM; |
| 6695 | goto free_vfi_bmask; |
| 6696 | } |
| 6697 | |
| 6698 | for (i = 0; i < count; i++) |
| 6699 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 6700 | |
| 6701 | /* |
| 6702 | * Mark all resources ready. An HBA reset doesn't need |
| 6703 | * to reset the initialization. |
| 6704 | */ |
| 6705 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6706 | LPFC_IDX_RSRC_RDY); |
| 6707 | return 0; |
| 6708 | } |
| 6709 | |
| 6710 | free_vfi_bmask: |
| 6711 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6712 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6713 | free_xri_ids: |
| 6714 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6715 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6716 | free_xri_bmask: |
| 6717 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6718 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6719 | free_vpi_ids: |
| 6720 | kfree(phba->vpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6721 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6722 | free_vpi_bmask: |
| 6723 | kfree(phba->vpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6724 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6725 | free_rpi_ids: |
| 6726 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6727 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6728 | free_rpi_bmask: |
| 6729 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6730 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6731 | err_exit: |
| 6732 | return rc; |
| 6733 | } |
| 6734 | |
| 6735 | /** |
| 6736 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 6737 | * @phba: Pointer to HBA context object. |
| 6738 | * |
| 6739 | * This function allocates the number of elements for the specified |
| 6740 | * resource type. |
| 6741 | **/ |
| 6742 | int |
| 6743 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 6744 | { |
| 6745 | if (phba->sli4_hba.extents_in_use) { |
| 6746 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6747 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6748 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6749 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6750 | } else { |
| 6751 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6752 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6753 | kfree(phba->vpi_ids); |
| 6754 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6755 | kfree(phba->sli4_hba.xri_bmask); |
| 6756 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6757 | kfree(phba->sli4_hba.vfi_bmask); |
| 6758 | kfree(phba->sli4_hba.vfi_ids); |
| 6759 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6760 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6761 | } |
| 6762 | |
| 6763 | return 0; |
| 6764 | } |
| 6765 | |
| 6766 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6767 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 6768 | * @phba: Pointer to HBA context object. |
| 6769 | * @type: The resource extent type. |
| 6770 | * @extnt_count: buffer to hold port extent count response |
| 6771 | * @extnt_size: buffer to hold port extent size response. |
| 6772 | * |
| 6773 | * This function calls the port to read the host allocated extents |
| 6774 | * for a particular type. |
| 6775 | **/ |
| 6776 | int |
| 6777 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 6778 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 6779 | { |
| 6780 | bool emb; |
| 6781 | int rc = 0; |
| 6782 | uint16_t curr_blks = 0; |
| 6783 | uint32_t req_len, emb_len; |
| 6784 | uint32_t alloc_len, mbox_tmo; |
| 6785 | struct list_head *blk_list_head; |
| 6786 | struct lpfc_rsrc_blks *rsrc_blk; |
| 6787 | LPFC_MBOXQ_t *mbox; |
| 6788 | void *virtaddr = NULL; |
| 6789 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6790 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6791 | union lpfc_sli4_cfg_shdr *shdr; |
| 6792 | |
| 6793 | switch (type) { |
| 6794 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6795 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6796 | break; |
| 6797 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6798 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6799 | break; |
| 6800 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6801 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6802 | break; |
| 6803 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6804 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6805 | break; |
| 6806 | default: |
| 6807 | return -EIO; |
| 6808 | } |
| 6809 | |
| 6810 | /* Count the number of extents currently allocatd for this type. */ |
| 6811 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6812 | if (curr_blks == 0) { |
| 6813 | /* |
| 6814 | * The GET_ALLOCATED mailbox does not return the size, |
| 6815 | * just the count. The size should be just the size |
| 6816 | * stored in the current allocated block and all sizes |
| 6817 | * for an extent type are the same so set the return |
| 6818 | * value now. |
| 6819 | */ |
| 6820 | *extnt_size = rsrc_blk->rsrc_size; |
| 6821 | } |
| 6822 | curr_blks++; |
| 6823 | } |
| 6824 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6825 | /* |
| 6826 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6827 | * accounts for extents-specific word. |
| 6828 | */ |
| 6829 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6830 | sizeof(uint32_t); |
| 6831 | |
| 6832 | /* |
| 6833 | * Presume the allocation and response will fit into an embedded |
| 6834 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6835 | */ |
| 6836 | emb = LPFC_SLI4_MBX_EMBED; |
| 6837 | req_len = emb_len; |
| 6838 | if (req_len > emb_len) { |
| 6839 | req_len = curr_blks * sizeof(uint16_t) + |
| 6840 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6841 | sizeof(uint32_t); |
| 6842 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6843 | } |
| 6844 | |
| 6845 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6846 | if (!mbox) |
| 6847 | return -ENOMEM; |
| 6848 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6849 | |
| 6850 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6851 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6852 | req_len, emb); |
| 6853 | if (alloc_len < req_len) { |
| 6854 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6855 | "2983 Allocated DMA memory size (x%x) is " |
| 6856 | "less than the requested DMA memory " |
| 6857 | "size (x%x)\n", alloc_len, req_len); |
| 6858 | rc = -ENOMEM; |
| 6859 | goto err_exit; |
| 6860 | } |
| 6861 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6862 | if (unlikely(rc)) { |
| 6863 | rc = -EIO; |
| 6864 | goto err_exit; |
| 6865 | } |
| 6866 | |
| 6867 | if (!phba->sli4_hba.intr_enable) |
| 6868 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6869 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6870 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6871 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6872 | } |
| 6873 | |
| 6874 | if (unlikely(rc)) { |
| 6875 | rc = -EIO; |
| 6876 | goto err_exit; |
| 6877 | } |
| 6878 | |
| 6879 | /* |
| 6880 | * Figure out where the response is located. Then get local pointers |
| 6881 | * to the response data. The port does not guarantee to respond to |
| 6882 | * all extents counts request so update the local variable with the |
| 6883 | * allocated count from the port. |
| 6884 | */ |
| 6885 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6886 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6887 | shdr = &rsrc_ext->header.cfg_shdr; |
| 6888 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6889 | } else { |
| 6890 | virtaddr = mbox->sge_array->addr[0]; |
| 6891 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6892 | shdr = &n_rsrc->cfg_shdr; |
| 6893 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6894 | } |
| 6895 | |
| 6896 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 6897 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6898 | "2984 Failed to read allocated resources " |
| 6899 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 6900 | type, |
| 6901 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 6902 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 6903 | rc = -EIO; |
| 6904 | goto err_exit; |
| 6905 | } |
| 6906 | err_exit: |
| 6907 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6908 | return rc; |
| 6909 | } |
| 6910 | |
| 6911 | /** |
James Smart | 0ef6996 | 2017-04-21 16:04:50 -0700 | [diff] [blame] | 6912 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6913 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6914 | * @pring: Pointer to driver SLI ring object. |
| 6915 | * @sgl_list: linked link of sgl buffers to post |
| 6916 | * @cnt: number of linked list buffers |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6917 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6918 | * This routine walks the list of buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6919 | * repost them to the port by using SGL block post. This is needed after a |
| 6920 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6921 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
| 6922 | * SGL block post mailbox commands to post them to the port. For single |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6923 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 6924 | * mailbox command for posting. |
| 6925 | * |
| 6926 | * Returns: 0 = success, non-zero failure. |
| 6927 | **/ |
| 6928 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6929 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
| 6930 | struct list_head *sgl_list, int cnt) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6931 | { |
| 6932 | struct lpfc_sglq *sglq_entry = NULL; |
| 6933 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 6934 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6935 | int status, total_cnt; |
| 6936 | int post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6937 | int last_xritag = NO_XRI; |
| 6938 | LIST_HEAD(prep_sgl_list); |
| 6939 | LIST_HEAD(blck_sgl_list); |
| 6940 | LIST_HEAD(allc_sgl_list); |
| 6941 | LIST_HEAD(post_sgl_list); |
| 6942 | LIST_HEAD(free_sgl_list); |
| 6943 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6944 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6945 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6946 | list_splice_init(sgl_list, &allc_sgl_list); |
| 6947 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6948 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6949 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6950 | total_cnt = cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6951 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6952 | &allc_sgl_list, list) { |
| 6953 | list_del_init(&sglq_entry->list); |
| 6954 | block_cnt++; |
| 6955 | if ((last_xritag != NO_XRI) && |
| 6956 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6957 | /* a hole in xri block, form a sgl posting block */ |
| 6958 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6959 | post_cnt = block_cnt - 1; |
| 6960 | /* prepare list for next posting block */ |
| 6961 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6962 | block_cnt = 1; |
| 6963 | } else { |
| 6964 | /* prepare list for next posting block */ |
| 6965 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6966 | /* enough sgls for non-embed sgl mbox command */ |
| 6967 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6968 | list_splice_init(&prep_sgl_list, |
| 6969 | &blck_sgl_list); |
| 6970 | post_cnt = block_cnt; |
| 6971 | block_cnt = 0; |
| 6972 | } |
| 6973 | } |
| 6974 | num_posted++; |
| 6975 | |
| 6976 | /* keep track of last sgl's xritag */ |
| 6977 | last_xritag = sglq_entry->sli4_xritag; |
| 6978 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6979 | /* end of repost sgl list condition for buffers */ |
| 6980 | if (num_posted == total_cnt) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6981 | if (post_cnt == 0) { |
| 6982 | list_splice_init(&prep_sgl_list, |
| 6983 | &blck_sgl_list); |
| 6984 | post_cnt = block_cnt; |
| 6985 | } else if (block_cnt == 1) { |
| 6986 | status = lpfc_sli4_post_sgl(phba, |
| 6987 | sglq_entry->phys, 0, |
| 6988 | sglq_entry->sli4_xritag); |
| 6989 | if (!status) { |
| 6990 | /* successful, put sgl to posted list */ |
| 6991 | list_add_tail(&sglq_entry->list, |
| 6992 | &post_sgl_list); |
| 6993 | } else { |
| 6994 | /* Failure, put sgl to free list */ |
| 6995 | lpfc_printf_log(phba, KERN_WARNING, |
| 6996 | LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6997 | "3159 Failed to post " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6998 | "sgl, xritag:x%x\n", |
| 6999 | sglq_entry->sli4_xritag); |
| 7000 | list_add_tail(&sglq_entry->list, |
| 7001 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7002 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7003 | } |
| 7004 | } |
| 7005 | } |
| 7006 | |
| 7007 | /* continue until a nembed page worth of sgls */ |
| 7008 | if (post_cnt == 0) |
| 7009 | continue; |
| 7010 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7011 | /* post the buffer list sgls as a block */ |
| 7012 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, |
| 7013 | post_cnt); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7014 | |
| 7015 | if (!status) { |
| 7016 | /* success, put sgl list to posted sgl list */ |
| 7017 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 7018 | } else { |
| 7019 | /* Failure, put sgl list to free sgl list */ |
| 7020 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 7021 | struct lpfc_sglq, |
| 7022 | list); |
| 7023 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7024 | "3160 Failed to post sgl-list, " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7025 | "xritag:x%x-x%x\n", |
| 7026 | sglq_entry_first->sli4_xritag, |
| 7027 | (sglq_entry_first->sli4_xritag + |
| 7028 | post_cnt - 1)); |
| 7029 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7030 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7031 | } |
| 7032 | |
| 7033 | /* don't reset xirtag due to hole in xri block */ |
| 7034 | if (block_cnt == 0) |
| 7035 | last_xritag = NO_XRI; |
| 7036 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7037 | /* reset sgl post count for next round of posting */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7038 | post_cnt = 0; |
| 7039 | } |
| 7040 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7041 | /* free the sgls failed to post */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7042 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 7043 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7044 | /* push sgls posted to the available list */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7045 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7046 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7047 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7048 | list_splice_init(&post_sgl_list, sgl_list); |
| 7049 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7050 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7051 | } else { |
| 7052 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7053 | "3161 Failure to post sgl to port.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7054 | return -EIO; |
| 7055 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7056 | |
| 7057 | /* return the number of XRIs actually posted */ |
| 7058 | return total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7059 | } |
| 7060 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7061 | void |
| 7062 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 7063 | { |
| 7064 | uint32_t len; |
| 7065 | |
| 7066 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 7067 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 7068 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7069 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 7070 | LPFC_SLI4_MBX_EMBED); |
| 7071 | |
| 7072 | mbox->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_OS_DRIVER_VERSION; |
James Smart | b2fd103 | 2016-12-19 15:07:21 -0800 | [diff] [blame] | 7073 | mbox->u.mqe.un.set_host_data.param_len = |
| 7074 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7075 | snprintf(mbox->u.mqe.un.set_host_data.data, |
| 7076 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 7077 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 7078 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 7079 | } |
| 7080 | |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7081 | int |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7082 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7083 | struct lpfc_queue *drq, int count, int idx) |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7084 | { |
| 7085 | int rc, i; |
| 7086 | struct lpfc_rqe hrqe; |
| 7087 | struct lpfc_rqe drqe; |
| 7088 | struct lpfc_rqb *rqbp; |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7089 | unsigned long flags; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7090 | struct rqb_dmabuf *rqb_buffer; |
| 7091 | LIST_HEAD(rqb_buf_list); |
| 7092 | |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7093 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7094 | rqbp = hrq->rqbp; |
| 7095 | for (i = 0; i < count; i++) { |
| 7096 | /* IF RQ is already full, don't bother */ |
| 7097 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) |
| 7098 | break; |
| 7099 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); |
| 7100 | if (!rqb_buffer) |
| 7101 | break; |
| 7102 | rqb_buffer->hrq = hrq; |
| 7103 | rqb_buffer->drq = drq; |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7104 | rqb_buffer->idx = idx; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7105 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
| 7106 | } |
| 7107 | while (!list_empty(&rqb_buf_list)) { |
| 7108 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, |
| 7109 | hbuf.list); |
| 7110 | |
| 7111 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); |
| 7112 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); |
| 7113 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); |
| 7114 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); |
| 7115 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
| 7116 | if (rc < 0) { |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7117 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7118 | "6421 Cannot post to HRQ %d: %x %x %x " |
| 7119 | "DRQ %x %x\n", |
| 7120 | hrq->queue_id, |
| 7121 | hrq->host_index, |
| 7122 | hrq->hba_index, |
| 7123 | hrq->entry_count, |
| 7124 | drq->host_index, |
| 7125 | drq->hba_index); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7126 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
| 7127 | } else { |
| 7128 | list_add_tail(&rqb_buffer->hbuf.list, |
| 7129 | &rqbp->rqb_buffer_list); |
| 7130 | rqbp->buffer_count++; |
| 7131 | } |
| 7132 | } |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7133 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7134 | return 1; |
| 7135 | } |
| 7136 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7137 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7138 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7139 | * @phba: Pointer to HBA context object. |
| 7140 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7141 | * This function is the main SLI4 device initialization PCI function. This |
| 7142 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7143 | * HBA error attention handler code. Caller is not required to hold any |
| 7144 | * locks. |
| 7145 | **/ |
| 7146 | int |
| 7147 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 7148 | { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7149 | int rc, i, cnt; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7150 | LPFC_MBOXQ_t *mboxq; |
| 7151 | struct lpfc_mqe *mqe; |
| 7152 | uint8_t *vpd; |
| 7153 | uint32_t vpd_size; |
| 7154 | uint32_t ftr_rsp = 0; |
| 7155 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 7156 | struct lpfc_vport *vport = phba->pport; |
| 7157 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7158 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7159 | |
| 7160 | /* Perform a PCI function reset to start from clean */ |
| 7161 | rc = lpfc_pci_function_reset(phba); |
| 7162 | if (unlikely(rc)) |
| 7163 | return -ENODEV; |
| 7164 | |
| 7165 | /* Check the HBA Host Status Register for readyness */ |
| 7166 | rc = lpfc_sli4_post_status_check(phba); |
| 7167 | if (unlikely(rc)) |
| 7168 | return -ENODEV; |
| 7169 | else { |
| 7170 | spin_lock_irq(&phba->hbalock); |
| 7171 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 7172 | spin_unlock_irq(&phba->hbalock); |
| 7173 | } |
| 7174 | |
| 7175 | /* |
| 7176 | * Allocate a single mailbox container for initializing the |
| 7177 | * port. |
| 7178 | */ |
| 7179 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7180 | if (!mboxq) |
| 7181 | return -ENOMEM; |
| 7182 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7183 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7184 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7185 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 7186 | if (!vpd) { |
| 7187 | rc = -ENOMEM; |
| 7188 | goto out_free_mbox; |
| 7189 | } |
| 7190 | |
| 7191 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7192 | if (unlikely(rc)) { |
| 7193 | kfree(vpd); |
| 7194 | goto out_free_mbox; |
| 7195 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7196 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7197 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7198 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7199 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7200 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7201 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 7202 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7203 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7204 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7205 | |
| 7206 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 7207 | LPFC_DCBX_CEE_MODE) |
| 7208 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 7209 | else |
| 7210 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 7211 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 7212 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 7213 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7214 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7215 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7216 | "0376 READ_REV Error. SLI Level %d " |
| 7217 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7218 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7219 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7220 | kfree(vpd); |
| 7221 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7222 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7223 | |
| 7224 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7225 | * Continue initialization with default values even if driver failed |
| 7226 | * to read FCoE param config regions, only read parameters if the |
| 7227 | * board is FCoE |
| 7228 | */ |
| 7229 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 7230 | lpfc_sli4_read_fcoe_params(phba)) |
| 7231 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 7232 | "2570 Failed to read FCoE parameters\n"); |
| 7233 | |
| 7234 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7235 | * Retrieve sli4 device physical port name, failure of doing it |
| 7236 | * is considered as non-fatal. |
| 7237 | */ |
| 7238 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 7239 | if (!rc) |
| 7240 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7241 | "3080 Successful retrieving SLI4 device " |
| 7242 | "physical port name: %s.\n", phba->Port); |
| 7243 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7244 | /* |
| 7245 | * Evaluate the read rev and vpd data. Populate the driver |
| 7246 | * state with the results. If this routine fails, the failure |
| 7247 | * is not fatal as the driver will use generic values. |
| 7248 | */ |
| 7249 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 7250 | if (unlikely(!rc)) { |
| 7251 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7252 | "0377 Error %d parsing vpd. " |
| 7253 | "Using defaults.\n", rc); |
| 7254 | rc = 0; |
| 7255 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7256 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7257 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7258 | /* Save information as VPD data */ |
| 7259 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 7260 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 7261 | |
| 7262 | /* |
| 7263 | * This is because first G7 ASIC doesn't support the standard |
| 7264 | * 0x5a NVME cmd descriptor type/subtype |
| 7265 | */ |
| 7266 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 7267 | LPFC_SLI_INTF_IF_TYPE_6) && |
| 7268 | (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) && |
| 7269 | (phba->vpd.rev.smRev == 0) && |
| 7270 | (phba->cfg_nvme_embed_cmd == 1)) |
| 7271 | phba->cfg_nvme_embed_cmd = 0; |
| 7272 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7273 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 7274 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 7275 | &mqe->un.read_rev); |
| 7276 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 7277 | &mqe->un.read_rev); |
| 7278 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 7279 | &mqe->un.read_rev); |
| 7280 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 7281 | &mqe->un.read_rev); |
| 7282 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 7283 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 7284 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 7285 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 7286 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 7287 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 7288 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7289 | "(%d):0380 READ_REV Status x%x " |
| 7290 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 7291 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7292 | bf_get(lpfc_mqe_status, mqe), |
| 7293 | phba->vpd.rev.opFwName, |
| 7294 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 7295 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7296 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7297 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 7298 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 7299 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 7300 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7301 | "3362 LUN queue depth changed from %d to %d\n", |
| 7302 | phba->pport->cfg_lun_queue_depth, rc); |
| 7303 | phba->pport->cfg_lun_queue_depth = rc; |
| 7304 | } |
| 7305 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7306 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 7307 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 7308 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 7309 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7310 | if (rc == MBX_SUCCESS) { |
| 7311 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 7312 | /* Set 1Sec interval to detect UE */ |
| 7313 | phba->eratt_poll_interval = 1; |
| 7314 | phba->sli4_hba.ue_to_sr = bf_get( |
| 7315 | lpfc_mbx_set_feature_UESR, |
| 7316 | &mboxq->u.mqe.un.set_feature); |
| 7317 | phba->sli4_hba.ue_to_rp = bf_get( |
| 7318 | lpfc_mbx_set_feature_UERP, |
| 7319 | &mboxq->u.mqe.un.set_feature); |
| 7320 | } |
| 7321 | } |
| 7322 | |
| 7323 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 7324 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 7325 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 7326 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7327 | if (rc != MBX_SUCCESS) |
| 7328 | phba->mds_diags_support = 0; |
| 7329 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7330 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7331 | /* |
| 7332 | * Discover the port's supported feature set and match it against the |
| 7333 | * hosts requests. |
| 7334 | */ |
| 7335 | lpfc_request_features(phba, mboxq); |
| 7336 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7337 | if (unlikely(rc)) { |
| 7338 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7339 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7340 | } |
| 7341 | |
| 7342 | /* |
| 7343 | * The port must support FCP initiator mode as this is the |
| 7344 | * only mode running in the host. |
| 7345 | */ |
| 7346 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 7347 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7348 | "0378 No support for fcpi mode.\n"); |
| 7349 | ftr_rsp++; |
| 7350 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 7351 | |
| 7352 | /* Performance Hints are ONLY for FCoE */ |
| 7353 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 7354 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 7355 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 7356 | else |
| 7357 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
| 7358 | } |
| 7359 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7360 | /* |
| 7361 | * If the port cannot support the host's requested features |
| 7362 | * then turn off the global config parameters to disable the |
| 7363 | * feature in the driver. This is not a fatal error. |
| 7364 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7365 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 7366 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) { |
| 7367 | phba->cfg_enable_bg = 0; |
| 7368 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7369 | ftr_rsp++; |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7370 | } |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7371 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7372 | |
| 7373 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 7374 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7375 | ftr_rsp++; |
| 7376 | |
| 7377 | if (ftr_rsp) { |
| 7378 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7379 | "0379 Feature Mismatch Data: x%08x %08x " |
| 7380 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 7381 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 7382 | phba->cfg_enable_npiv, phba->max_vpi); |
| 7383 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 7384 | phba->cfg_enable_bg = 0; |
| 7385 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7386 | phba->cfg_enable_npiv = 0; |
| 7387 | } |
| 7388 | |
| 7389 | /* These SLI3 features are assumed in SLI4 */ |
| 7390 | spin_lock_irq(&phba->hbalock); |
| 7391 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 7392 | spin_unlock_irq(&phba->hbalock); |
| 7393 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7394 | /* |
| 7395 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 7396 | * calls depends on these resources to complete port setup. |
| 7397 | */ |
| 7398 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 7399 | if (rc) { |
| 7400 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7401 | "2920 Failed to alloc Resource IDs " |
| 7402 | "rc = x%x\n", rc); |
| 7403 | goto out_free_mbox; |
| 7404 | } |
| 7405 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7406 | lpfc_set_host_data(phba, mboxq); |
| 7407 | |
| 7408 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7409 | if (rc) { |
| 7410 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7411 | "2134 Failed to set host os driver version %x", |
| 7412 | rc); |
| 7413 | } |
| 7414 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7415 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7416 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 7417 | if (rc) { |
| 7418 | phba->link_state = LPFC_HBA_ERROR; |
| 7419 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7420 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7421 | } |
| 7422 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7423 | mboxq->vport = vport; |
| 7424 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7425 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7426 | if (rc == MBX_SUCCESS) { |
| 7427 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 7428 | rc = 0; |
| 7429 | } |
| 7430 | |
| 7431 | /* |
| 7432 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 7433 | * it to the mbuf pool. |
| 7434 | */ |
| 7435 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 7436 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7437 | mboxq->ctx_buf = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7438 | if (unlikely(rc)) { |
| 7439 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7440 | "0382 READ_SPARAM command failed " |
| 7441 | "status %d, mbxStatus x%x\n", |
| 7442 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 7443 | phba->link_state = LPFC_HBA_ERROR; |
| 7444 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7445 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7446 | } |
| 7447 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7448 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7449 | |
| 7450 | /* Update the fc_host data structures with new wwn. */ |
| 7451 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 7452 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 7453 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7454 | /* Create all the SLI4 queues */ |
| 7455 | rc = lpfc_sli4_queue_create(phba); |
| 7456 | if (rc) { |
| 7457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7458 | "3089 Failed to allocate queues\n"); |
| 7459 | rc = -ENODEV; |
| 7460 | goto out_free_mbox; |
| 7461 | } |
| 7462 | /* Set up all the queues to the device */ |
| 7463 | rc = lpfc_sli4_queue_setup(phba); |
| 7464 | if (unlikely(rc)) { |
| 7465 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7466 | "0381 Error %d during queue setup.\n ", rc); |
| 7467 | goto out_stop_timers; |
| 7468 | } |
| 7469 | /* Initialize the driver internal SLI layer lists. */ |
| 7470 | lpfc_sli4_setup(phba); |
| 7471 | lpfc_sli4_queue_init(phba); |
| 7472 | |
| 7473 | /* update host els xri-sgl sizes and mappings */ |
| 7474 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7475 | if (unlikely(rc)) { |
| 7476 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7477 | "1400 Failed to update xri-sgl size and " |
| 7478 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7479 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7480 | } |
| 7481 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7482 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7483 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 7484 | phba->sli4_hba.els_xri_cnt); |
| 7485 | if (unlikely(rc < 0)) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7486 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7487 | "0582 Error %d during els sgl post " |
| 7488 | "operation\n", rc); |
| 7489 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7490 | goto out_destroy_queue; |
| 7491 | } |
| 7492 | phba->sli4_hba.els_xri_cnt = rc; |
| 7493 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7494 | if (phba->nvmet_support) { |
| 7495 | /* update host nvmet xri-sgl sizes and mappings */ |
| 7496 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 7497 | if (unlikely(rc)) { |
| 7498 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7499 | "6308 Failed to update nvmet-sgl size " |
| 7500 | "and mapping: %d\n", rc); |
| 7501 | goto out_destroy_queue; |
| 7502 | } |
| 7503 | |
| 7504 | /* register the nvmet sgl pool to the port */ |
| 7505 | rc = lpfc_sli4_repost_sgl_list( |
| 7506 | phba, |
| 7507 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 7508 | phba->sli4_hba.nvmet_xri_cnt); |
| 7509 | if (unlikely(rc < 0)) { |
| 7510 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7511 | "3117 Error %d during nvmet " |
| 7512 | "sgl post\n", rc); |
| 7513 | rc = -ENODEV; |
| 7514 | goto out_destroy_queue; |
| 7515 | } |
| 7516 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7517 | |
| 7518 | cnt = phba->cfg_iocb_cnt * 1024; |
| 7519 | /* We need 1 iocbq for every SGL, for IO processing */ |
| 7520 | cnt += phba->sli4_hba.nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7521 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7522 | /* update host scsi xri-sgl sizes and mappings */ |
| 7523 | rc = lpfc_sli4_scsi_sgl_update(phba); |
| 7524 | if (unlikely(rc)) { |
| 7525 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7526 | "6309 Failed to update scsi-sgl size " |
| 7527 | "and mapping: %d\n", rc); |
| 7528 | goto out_destroy_queue; |
| 7529 | } |
| 7530 | |
| 7531 | /* update host nvme xri-sgl sizes and mappings */ |
| 7532 | rc = lpfc_sli4_nvme_sgl_update(phba); |
| 7533 | if (unlikely(rc)) { |
| 7534 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7535 | "6082 Failed to update nvme-sgl size " |
| 7536 | "and mapping: %d\n", rc); |
| 7537 | goto out_destroy_queue; |
| 7538 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7539 | |
| 7540 | cnt = phba->cfg_iocb_cnt * 1024; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7541 | } |
| 7542 | |
| 7543 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7544 | /* Initialize and populate the iocb list per host */ |
| 7545 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7546 | "2821 initialize iocb list %d total %d\n", |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7547 | phba->cfg_iocb_cnt, cnt); |
| 7548 | rc = lpfc_init_iocb_list(phba, cnt); |
| 7549 | if (rc) { |
| 7550 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7551 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7552 | goto out_destroy_queue; |
| 7553 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7554 | } |
| 7555 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7556 | if (phba->nvmet_support) |
| 7557 | lpfc_nvmet_create_targetport(phba); |
| 7558 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7559 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7560 | /* Post initial buffers to all RQs created */ |
| 7561 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 7562 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 7563 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 7564 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 7565 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 7566 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7567 | rqbp->buffer_count = 0; |
| 7568 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7569 | lpfc_post_rq_buffer( |
| 7570 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 7571 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | 2448e48 | 2018-04-09 14:24:24 -0700 | [diff] [blame] | 7572 | phba->cfg_nvmet_mrq_post, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7573 | } |
| 7574 | } |
| 7575 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7576 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 7577 | /* register the allocated scsi sgl pool to the port */ |
| 7578 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 7579 | if (unlikely(rc)) { |
| 7580 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7581 | "0383 Error %d during scsi sgl post " |
| 7582 | "operation\n", rc); |
| 7583 | /* Some Scsi buffers were moved to abort scsi list */ |
| 7584 | /* A pci function reset will repost them */ |
| 7585 | rc = -ENODEV; |
| 7586 | goto out_destroy_queue; |
| 7587 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7588 | } |
| 7589 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 7590 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 7591 | (phba->nvmet_support == 0)) { |
| 7592 | |
| 7593 | /* register the allocated nvme sgl pool to the port */ |
| 7594 | rc = lpfc_repost_nvme_sgl_list(phba); |
| 7595 | if (unlikely(rc)) { |
| 7596 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7597 | "6116 Error %d during nvme sgl post " |
| 7598 | "operation\n", rc); |
| 7599 | /* Some NVME buffers were moved to abort nvme list */ |
| 7600 | /* A pci function reset will repost them */ |
| 7601 | rc = -ENODEV; |
| 7602 | goto out_destroy_queue; |
| 7603 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7604 | } |
| 7605 | |
| 7606 | /* Post the rpi header region to the device. */ |
| 7607 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 7608 | if (unlikely(rc)) { |
| 7609 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7610 | "0393 Error %d during rpi post operation\n", |
| 7611 | rc); |
| 7612 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7613 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7614 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7615 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7616 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7617 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7618 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7619 | /* |
| 7620 | * The FC Port needs to register FCFI (index 0) |
| 7621 | */ |
| 7622 | lpfc_reg_fcfi(phba, mboxq); |
| 7623 | mboxq->vport = phba->pport; |
| 7624 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7625 | if (rc != MBX_SUCCESS) |
| 7626 | goto out_unset_queue; |
| 7627 | rc = 0; |
| 7628 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 7629 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7630 | } else { |
| 7631 | /* We are a NVME Target mode with MRQ > 1 */ |
| 7632 | |
| 7633 | /* First register the FCFI */ |
| 7634 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 7635 | mboxq->vport = phba->pport; |
| 7636 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7637 | if (rc != MBX_SUCCESS) |
| 7638 | goto out_unset_queue; |
| 7639 | rc = 0; |
| 7640 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 7641 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 7642 | |
| 7643 | /* Next register the MRQs */ |
| 7644 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 7645 | mboxq->vport = phba->pport; |
| 7646 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7647 | if (rc != MBX_SUCCESS) |
| 7648 | goto out_unset_queue; |
| 7649 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7650 | } |
| 7651 | /* Check if the port is configured to be disabled */ |
| 7652 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7653 | } |
| 7654 | |
| 7655 | /* Arm the CQs and then EQs on device */ |
| 7656 | lpfc_sli4_arm_cqeq_intr(phba); |
| 7657 | |
| 7658 | /* Indicate device interrupt mode */ |
| 7659 | phba->sli4_hba.intr_enable = 1; |
| 7660 | |
| 7661 | /* Allow asynchronous mailbox command to go through */ |
| 7662 | spin_lock_irq(&phba->hbalock); |
| 7663 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7664 | spin_unlock_irq(&phba->hbalock); |
| 7665 | |
| 7666 | /* Post receive buffers to the device */ |
| 7667 | lpfc_sli4_rb_setup(phba); |
| 7668 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7669 | /* Reset HBA FCF states after HBA reset */ |
| 7670 | phba->fcf.fcf_flag = 0; |
| 7671 | phba->fcf.current_rec.flag = 0; |
| 7672 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7673 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7674 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7675 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7676 | |
| 7677 | /* Start heart beat timer */ |
| 7678 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7679 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7680 | phba->hb_outstanding = 0; |
| 7681 | phba->last_completion_time = jiffies; |
| 7682 | |
| 7683 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7684 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7685 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7686 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7687 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 7688 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 7689 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 7690 | if (!rc) { |
| 7691 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7692 | "2829 This device supports " |
| 7693 | "Advanced Error Reporting (AER)\n"); |
| 7694 | spin_lock_irq(&phba->hbalock); |
| 7695 | phba->hba_flag |= HBA_AER_ENABLED; |
| 7696 | spin_unlock_irq(&phba->hbalock); |
| 7697 | } else { |
| 7698 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7699 | "2830 This device does not support " |
| 7700 | "Advanced Error Reporting (AER)\n"); |
| 7701 | phba->cfg_aer_support = 0; |
| 7702 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7703 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7704 | } |
| 7705 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7706 | /* |
| 7707 | * The port is ready, set the host's link state to LINK_DOWN |
| 7708 | * in preparation for link interrupts. |
| 7709 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7710 | spin_lock_irq(&phba->hbalock); |
| 7711 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7712 | |
| 7713 | /* Check if physical ports are trunked */ |
| 7714 | if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba)) |
| 7715 | phba->trunk_link.link0.state = LPFC_LINK_DOWN; |
| 7716 | if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba)) |
| 7717 | phba->trunk_link.link1.state = LPFC_LINK_DOWN; |
| 7718 | if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba)) |
| 7719 | phba->trunk_link.link2.state = LPFC_LINK_DOWN; |
| 7720 | if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba)) |
| 7721 | phba->trunk_link.link3.state = LPFC_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7722 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7723 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7724 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 7725 | (phba->hba_flag & LINK_DISABLED)) { |
| 7726 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7727 | "3103 Adapter Link is disabled.\n"); |
| 7728 | lpfc_down_link(phba, mboxq); |
| 7729 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7730 | if (rc != MBX_SUCCESS) { |
| 7731 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7732 | "3104 Adapter failed to issue " |
| 7733 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 7734 | goto out_unset_queue; |
| 7735 | } |
| 7736 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7737 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 7738 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 7739 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 7740 | if (rc) |
| 7741 | goto out_unset_queue; |
| 7742 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7743 | } |
| 7744 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7745 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7746 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7747 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7748 | lpfc_sli4_queue_unset(phba); |
| 7749 | out_destroy_queue: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7750 | lpfc_free_iocb_list(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7751 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7752 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7753 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7754 | out_free_mbox: |
| 7755 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7756 | return rc; |
| 7757 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7758 | |
| 7759 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7760 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7761 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7762 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7763 | * This is the callback function for mailbox timer. The mailbox |
| 7764 | * timer is armed when a new mailbox command is issued and the timer |
| 7765 | * is deleted when the mailbox complete. The function is called by |
| 7766 | * the kernel timer code when a mailbox does not complete within |
| 7767 | * expected time. This function wakes up the worker thread to |
| 7768 | * process the mailbox timeout and returns. All the processing is |
| 7769 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 7770 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7771 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7772 | lpfc_mbox_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7773 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7774 | struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7775 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7776 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7777 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7778 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7779 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7780 | if (!tmo_posted) |
| 7781 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 7782 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 7783 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7784 | if (!tmo_posted) |
| 7785 | lpfc_worker_wake_up(phba); |
| 7786 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7787 | } |
| 7788 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7789 | /** |
| 7790 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 7791 | * are pending |
| 7792 | * @phba: Pointer to HBA context object. |
| 7793 | * |
| 7794 | * This function checks if any mailbox completions are present on the mailbox |
| 7795 | * completion queue. |
| 7796 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 7797 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7798 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 7799 | { |
| 7800 | |
| 7801 | uint32_t idx; |
| 7802 | struct lpfc_queue *mcq; |
| 7803 | struct lpfc_mcqe *mcqe; |
| 7804 | bool pending_completions = false; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7805 | uint8_t qe_valid; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7806 | |
| 7807 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7808 | return false; |
| 7809 | |
| 7810 | /* Check for completions on mailbox completion queue */ |
| 7811 | |
| 7812 | mcq = phba->sli4_hba.mbx_cq; |
| 7813 | idx = mcq->hba_index; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7814 | qe_valid = mcq->qe_valid; |
| 7815 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe) == qe_valid) { |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7816 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; |
| 7817 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 7818 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 7819 | pending_completions = true; |
| 7820 | break; |
| 7821 | } |
| 7822 | idx = (idx + 1) % mcq->entry_count; |
| 7823 | if (mcq->hba_index == idx) |
| 7824 | break; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7825 | |
| 7826 | /* if the index wrapped around, toggle the valid bit */ |
| 7827 | if (phba->sli4_hba.pc_sli4_params.cqav && !idx) |
| 7828 | qe_valid = (qe_valid) ? 0 : 1; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7829 | } |
| 7830 | return pending_completions; |
| 7831 | |
| 7832 | } |
| 7833 | |
| 7834 | /** |
| 7835 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 7836 | * that were missed. |
| 7837 | * @phba: Pointer to HBA context object. |
| 7838 | * |
| 7839 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 7840 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 7841 | * checks to see if mbox completions are on the mailbox completion queue |
| 7842 | * and will process all the completions associated with the eq for the |
| 7843 | * mailbox completion queue. |
| 7844 | **/ |
| 7845 | bool |
| 7846 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 7847 | { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7848 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7849 | uint32_t eqidx; |
| 7850 | struct lpfc_queue *fpeq = NULL; |
| 7851 | struct lpfc_eqe *eqe; |
| 7852 | bool mbox_pending; |
| 7853 | |
| 7854 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7855 | return false; |
| 7856 | |
| 7857 | /* Find the eq associated with the mcq */ |
| 7858 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7859 | if (sli4_hba->hba_eq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7860 | for (eqidx = 0; eqidx < phba->io_channel_irqs; eqidx++) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7861 | if (sli4_hba->hba_eq[eqidx]->queue_id == |
| 7862 | sli4_hba->mbx_cq->assoc_qid) { |
| 7863 | fpeq = sli4_hba->hba_eq[eqidx]; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7864 | break; |
| 7865 | } |
| 7866 | if (!fpeq) |
| 7867 | return false; |
| 7868 | |
| 7869 | /* Turn off interrupts from this EQ */ |
| 7870 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7871 | sli4_hba->sli4_eq_clr_intr(fpeq); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7872 | |
| 7873 | /* Check to see if a mbox completion is pending */ |
| 7874 | |
| 7875 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 7876 | |
| 7877 | /* |
| 7878 | * If a mbox completion is pending, process all the events on EQ |
| 7879 | * associated with the mbox completion queue (this could include |
| 7880 | * mailbox commands, async events, els commands, receive queue data |
| 7881 | * and fcp commands) |
| 7882 | */ |
| 7883 | |
| 7884 | if (mbox_pending) |
| 7885 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 7886 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); |
| 7887 | fpeq->EQ_processed++; |
| 7888 | } |
| 7889 | |
| 7890 | /* Always clear and re-arm the EQ */ |
| 7891 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7892 | sli4_hba->sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7893 | |
| 7894 | return mbox_pending; |
| 7895 | |
| 7896 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7897 | |
| 7898 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7899 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7900 | * @phba: Pointer to HBA context object. |
| 7901 | * |
| 7902 | * This function is called from worker thread when a mailbox command times out. |
| 7903 | * The caller is not required to hold any locks. This function will reset the |
| 7904 | * HBA and recover all the pending commands. |
| 7905 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7906 | void |
| 7907 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 7908 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7909 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7910 | MAILBOX_t *mb = NULL; |
| 7911 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7912 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7913 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7914 | /* If the mailbox completed, process the completion and return */ |
| 7915 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 7916 | return; |
| 7917 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7918 | if (pmbox != NULL) |
| 7919 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7920 | /* Check the pmbox pointer first. There is a race condition |
| 7921 | * between the mbox timeout handler getting executed in the |
| 7922 | * worklist and the mailbox actually completing. When this |
| 7923 | * race condition occurs, the mbox_active will be NULL. |
| 7924 | */ |
| 7925 | spin_lock_irq(&phba->hbalock); |
| 7926 | if (pmbox == NULL) { |
| 7927 | lpfc_printf_log(phba, KERN_WARNING, |
| 7928 | LOG_MBOX | LOG_SLI, |
| 7929 | "0353 Active Mailbox cleared - mailbox timeout " |
| 7930 | "exiting\n"); |
| 7931 | spin_unlock_irq(&phba->hbalock); |
| 7932 | return; |
| 7933 | } |
| 7934 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7935 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7936 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7937 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7938 | mb->mbxCommand, |
| 7939 | phba->pport->port_state, |
| 7940 | phba->sli.sli_flag, |
| 7941 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7942 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7943 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7944 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 7945 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7946 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7947 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7948 | spin_lock_irq(&phba->pport->work_port_lock); |
| 7949 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 7950 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 7951 | spin_lock_irq(&phba->hbalock); |
| 7952 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 7953 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7954 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7955 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 7956 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7957 | |
| 7958 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 7959 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7960 | |
| 7961 | /* Reset the HBA device */ |
| 7962 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7963 | } |
| 7964 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7965 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7966 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7967 | * @phba: Pointer to HBA context object. |
| 7968 | * @pmbox: Pointer to mailbox object. |
| 7969 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7970 | * |
| 7971 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7972 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 7973 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7974 | * The mailbox command can be submitted in polling mode, in which case |
| 7975 | * this function will wait in a polling loop for the completion of the |
| 7976 | * mailbox. |
| 7977 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 7978 | * function will submit the command and returns immediately without waiting |
| 7979 | * for the mailbox completion. The no_wait is supported only when HBA |
| 7980 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 7981 | * The SLI interface allows only one mailbox pending at a time. If the |
| 7982 | * mailbox is issued in polling mode and there is already a mailbox |
| 7983 | * pending, then the function will return an error. If the mailbox is issued |
| 7984 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 7985 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 7986 | * The sli layer owns the mailbox object until the completion of mailbox |
| 7987 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 7988 | * return codes the caller owns the mailbox command after the return of |
| 7989 | * the function. |
| 7990 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7991 | static int |
| 7992 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 7993 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7994 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7995 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7996 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7997 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7998 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7999 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8000 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8001 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8002 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8003 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8004 | int processing_queue = 0; |
| 8005 | |
| 8006 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8007 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 8008 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8009 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8010 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8011 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8012 | return MBX_SUCCESS; |
| 8013 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8014 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8015 | pmbox = lpfc_mbox_get(phba); |
| 8016 | if (!pmbox) { |
| 8017 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8018 | return MBX_SUCCESS; |
| 8019 | } |
| 8020 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8021 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8022 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8023 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8024 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8025 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8026 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8027 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8028 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8029 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8030 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8031 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8032 | } |
| 8033 | } |
| 8034 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8035 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8036 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 8037 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8038 | goto out_not_finished; |
| 8039 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8040 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8041 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8042 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 8043 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8044 | goto out_not_finished; |
| 8045 | } |
| 8046 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8047 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8048 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8049 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8050 | status = MBX_SUCCESS; |
| 8051 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8052 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 8053 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8054 | |
| 8055 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8056 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8057 | "(%d):0311 Mailbox command x%x cannot " |
| 8058 | "issue Data: x%x x%x\n", |
| 8059 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8060 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8061 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8062 | } |
| 8063 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8064 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8065 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 8066 | !(hc_copy & HC_MBINT_ENA)) { |
| 8067 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8068 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8069 | "(%d):2528 Mailbox command x%x cannot " |
| 8070 | "issue Data: x%x x%x\n", |
| 8071 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8072 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8073 | goto out_not_finished; |
| 8074 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 8075 | } |
| 8076 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8077 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8078 | /* Polling for a mbox command when another one is already active |
| 8079 | * is not allowed in SLI. Also, the driver must have established |
| 8080 | * SLI2 mode to queue and process multiple mbox commands. |
| 8081 | */ |
| 8082 | |
| 8083 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8084 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8085 | |
| 8086 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8087 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8088 | "(%d):2529 Mailbox command x%x " |
| 8089 | "cannot issue Data: x%x x%x\n", |
| 8090 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8091 | pmbox->u.mb.mbxCommand, |
| 8092 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8093 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8094 | } |
| 8095 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8096 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8097 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8098 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8099 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8100 | "(%d):2530 Mailbox command x%x " |
| 8101 | "cannot issue Data: x%x x%x\n", |
| 8102 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8103 | pmbox->u.mb.mbxCommand, |
| 8104 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8105 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8106 | } |
| 8107 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8108 | /* Another mailbox command is still being processed, queue this |
| 8109 | * command to be processed later. |
| 8110 | */ |
| 8111 | lpfc_mbox_put(phba, pmbox); |
| 8112 | |
| 8113 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8114 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8115 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8116 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8117 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8118 | mbx->mbxCommand, |
| 8119 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8120 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8121 | |
| 8122 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8123 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8124 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8125 | if (pmbox->vport) { |
| 8126 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8127 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8128 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8129 | (uint32_t)mbx->mbxCommand, |
| 8130 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8131 | } |
| 8132 | else { |
| 8133 | lpfc_debugfs_disc_trc(phba->pport, |
| 8134 | LPFC_DISC_TRC_MBOX, |
| 8135 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8136 | (uint32_t)mbx->mbxCommand, |
| 8137 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8138 | } |
| 8139 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8140 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8141 | } |
| 8142 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8143 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8144 | |
| 8145 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 8146 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8147 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8148 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8149 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8150 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8151 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8152 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8153 | "(%d):2531 Mailbox command x%x " |
| 8154 | "cannot issue Data: x%x x%x\n", |
| 8155 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8156 | pmbox->u.mb.mbxCommand, |
| 8157 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8158 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8159 | } |
| 8160 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8161 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8162 | 1000); |
| 8163 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8164 | } |
| 8165 | |
| 8166 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8167 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8168 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8169 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8170 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8171 | mbx->mbxCommand, |
| 8172 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8173 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8174 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8175 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8176 | if (pmbox->vport) { |
| 8177 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8178 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8179 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8180 | (uint32_t)mbx->mbxCommand, |
| 8181 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8182 | } |
| 8183 | else { |
| 8184 | lpfc_debugfs_disc_trc(phba->pport, |
| 8185 | LPFC_DISC_TRC_MBOX, |
| 8186 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8187 | (uint32_t)mbx->mbxCommand, |
| 8188 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8189 | } |
| 8190 | } |
| 8191 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8192 | psli->slistat.mbox_cmd++; |
| 8193 | evtctr = psli->slistat.mbox_event; |
| 8194 | |
| 8195 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8196 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8197 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8198 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8199 | /* Populate mbox extension offset word. */ |
| 8200 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8201 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8202 | = (uint8_t *)phba->mbox_ext |
| 8203 | - (uint8_t *)phba->mbox; |
| 8204 | } |
| 8205 | |
| 8206 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8207 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) { |
| 8208 | lpfc_sli_pcimem_bcopy(pmbox->ctx_buf, |
| 8209 | (uint8_t *)phba->mbox_ext, |
| 8210 | pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8211 | } |
| 8212 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8213 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8214 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8215 | /* Populate mbox extension offset word. */ |
| 8216 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8217 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8218 | = MAILBOX_HBA_EXT_OFFSET; |
| 8219 | |
| 8220 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8221 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8222 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 8223 | MAILBOX_HBA_EXT_OFFSET, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8224 | pmbox->ctx_buf, pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8225 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8226 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8227 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8228 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 8229 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8230 | |
| 8231 | /* First copy mbox command data to HBA SLIM, skip past first |
| 8232 | word */ |
| 8233 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8234 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8235 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 8236 | |
| 8237 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8238 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8239 | to_slim = phba->MBslimaddr; |
| 8240 | writel(ldata, to_slim); |
| 8241 | readl(to_slim); /* flush */ |
| 8242 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8243 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8244 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8245 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8246 | } |
| 8247 | |
| 8248 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8249 | |
| 8250 | switch (flag) { |
| 8251 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8252 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8253 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8254 | /* Interrupt board to do it */ |
| 8255 | writel(CA_MBATT, phba->CAregaddr); |
| 8256 | readl(phba->CAregaddr); /* flush */ |
| 8257 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8258 | break; |
| 8259 | |
| 8260 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8261 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8262 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8263 | /* Interrupt board to do it */ |
| 8264 | writel(CA_MBATT, phba->CAregaddr); |
| 8265 | readl(phba->CAregaddr); /* flush */ |
| 8266 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8267 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8268 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8269 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8270 | word0 = le32_to_cpu(word0); |
| 8271 | } else { |
| 8272 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8273 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 8274 | spin_unlock_irqrestore(&phba->hbalock, |
| 8275 | drvr_flag); |
| 8276 | goto out_not_finished; |
| 8277 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8278 | } |
| 8279 | |
| 8280 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8281 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8282 | spin_unlock_irqrestore(&phba->hbalock, |
| 8283 | drvr_flag); |
| 8284 | goto out_not_finished; |
| 8285 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8286 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8287 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8288 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8289 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8290 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 8291 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8292 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8293 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8294 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8295 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8296 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8297 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8298 | } |
| 8299 | |
| 8300 | /* Check if we took a mbox interrupt while we were |
| 8301 | polling */ |
| 8302 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 8303 | && (evtctr != psli->slistat.mbox_event)) |
| 8304 | break; |
| 8305 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8306 | if (i++ > 10) { |
| 8307 | spin_unlock_irqrestore(&phba->hbalock, |
| 8308 | drvr_flag); |
| 8309 | msleep(1); |
| 8310 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8311 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8312 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8313 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8314 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8315 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8316 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8317 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8318 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8319 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8320 | /* Check real SLIM for any errors */ |
| 8321 | slimword0 = readl(phba->MBslimaddr); |
| 8322 | slimmb = (MAILBOX_t *) & slimword0; |
| 8323 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 8324 | && slimmb->mbxStatus) { |
| 8325 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8326 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8327 | word0 = slimword0; |
| 8328 | } |
| 8329 | } |
| 8330 | } else { |
| 8331 | /* First copy command data */ |
| 8332 | word0 = readl(phba->MBslimaddr); |
| 8333 | } |
| 8334 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8335 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8336 | spin_unlock_irqrestore(&phba->hbalock, |
| 8337 | drvr_flag); |
| 8338 | goto out_not_finished; |
| 8339 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8340 | } |
| 8341 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8342 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8343 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8344 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 8345 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8346 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8347 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8348 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8349 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8350 | pmbox->out_ext_byte_len); |
| 8351 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8352 | } else { |
| 8353 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8354 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8355 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8356 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8357 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
| 8358 | lpfc_memcpy_from_slim( |
| 8359 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8360 | phba->MBslimaddr + |
| 8361 | MAILBOX_HBA_EXT_OFFSET, |
| 8362 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8363 | } |
| 8364 | } |
| 8365 | |
| 8366 | writel(HA_MBATT, phba->HAregaddr); |
| 8367 | readl(phba->HAregaddr); /* flush */ |
| 8368 | |
| 8369 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8370 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8371 | } |
| 8372 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8373 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8374 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8375 | |
| 8376 | out_not_finished: |
| 8377 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8378 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8379 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 8380 | } |
| 8381 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8382 | } |
| 8383 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8384 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8385 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 8386 | * @phba: Pointer to HBA context object. |
| 8387 | * |
| 8388 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 8389 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 8390 | * possible outstanding mailbox command before return. |
| 8391 | * |
| 8392 | * Returns: |
| 8393 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 8394 | * the outstanding mailbox command timed out. |
| 8395 | **/ |
| 8396 | static int |
| 8397 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 8398 | { |
| 8399 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8400 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8401 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8402 | |
| 8403 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 8404 | spin_lock_irq(&phba->hbalock); |
| 8405 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8406 | /* Determine how long we might wait for the active mailbox |
| 8407 | * command to be gracefully completed by firmware. |
| 8408 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8409 | if (phba->sli.mbox_active) |
| 8410 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 8411 | phba->sli.mbox_active) * |
| 8412 | 1000) + jiffies; |
| 8413 | spin_unlock_irq(&phba->hbalock); |
| 8414 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8415 | /* Make sure the mailbox is really active */ |
| 8416 | if (timeout) |
| 8417 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 8418 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8419 | /* Wait for the outstnading mailbox command to complete */ |
| 8420 | while (phba->sli.mbox_active) { |
| 8421 | /* Check active mailbox complete status every 2ms */ |
| 8422 | msleep(2); |
| 8423 | if (time_after(jiffies, timeout)) { |
| 8424 | /* Timeout, marked the outstanding cmd not complete */ |
| 8425 | rc = 1; |
| 8426 | break; |
| 8427 | } |
| 8428 | } |
| 8429 | |
| 8430 | /* Can not cleanly block async mailbox command, fails it */ |
| 8431 | if (rc) { |
| 8432 | spin_lock_irq(&phba->hbalock); |
| 8433 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8434 | spin_unlock_irq(&phba->hbalock); |
| 8435 | } |
| 8436 | return rc; |
| 8437 | } |
| 8438 | |
| 8439 | /** |
| 8440 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 8441 | * @phba: Pointer to HBA context object. |
| 8442 | * |
| 8443 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 8444 | * commands from the driver internal pending mailbox queue. It makes sure |
| 8445 | * that there is no outstanding mailbox command before resuming posting |
| 8446 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 8447 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 8448 | * mailbox command posting. |
| 8449 | **/ |
| 8450 | static void |
| 8451 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 8452 | { |
| 8453 | struct lpfc_sli *psli = &phba->sli; |
| 8454 | |
| 8455 | spin_lock_irq(&phba->hbalock); |
| 8456 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8457 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 8458 | spin_unlock_irq(&phba->hbalock); |
| 8459 | return; |
| 8460 | } |
| 8461 | |
| 8462 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 8463 | * successful or timeout, after timing-out the outstanding mailbox |
| 8464 | * command shall always be removed, so just unblock posting async |
| 8465 | * mailbox command and resume |
| 8466 | */ |
| 8467 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8468 | spin_unlock_irq(&phba->hbalock); |
| 8469 | |
| 8470 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 8471 | lpfc_worker_wake_up(phba); |
| 8472 | } |
| 8473 | |
| 8474 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8475 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 8476 | * @phba: Pointer to HBA context object. |
| 8477 | * @mboxq: Pointer to mailbox object. |
| 8478 | * |
| 8479 | * The function waits for the bootstrap mailbox register ready bit from |
| 8480 | * port for twice the regular mailbox command timeout value. |
| 8481 | * |
| 8482 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 8483 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 8484 | **/ |
| 8485 | static int |
| 8486 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8487 | { |
| 8488 | uint32_t db_ready; |
| 8489 | unsigned long timeout; |
| 8490 | struct lpfc_register bmbx_reg; |
| 8491 | |
| 8492 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 8493 | * 1000) + jiffies; |
| 8494 | |
| 8495 | do { |
| 8496 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 8497 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 8498 | if (!db_ready) |
| 8499 | msleep(2); |
| 8500 | |
| 8501 | if (time_after(jiffies, timeout)) |
| 8502 | return MBXERR_ERROR; |
| 8503 | } while (!db_ready); |
| 8504 | |
| 8505 | return 0; |
| 8506 | } |
| 8507 | |
| 8508 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8509 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 8510 | * @phba: Pointer to HBA context object. |
| 8511 | * @mboxq: Pointer to mailbox object. |
| 8512 | * |
| 8513 | * The function posts a mailbox to the port. The mailbox is expected |
| 8514 | * to be comletely filled in and ready for the port to operate on it. |
| 8515 | * This routine executes a synchronous completion operation on the |
| 8516 | * mailbox by polling for its completion. |
| 8517 | * |
| 8518 | * The caller must not be holding any locks when calling this routine. |
| 8519 | * |
| 8520 | * Returns: |
| 8521 | * MBX_SUCCESS - mailbox posted successfully |
| 8522 | * Any of the MBX error values. |
| 8523 | **/ |
| 8524 | static int |
| 8525 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8526 | { |
| 8527 | int rc = MBX_SUCCESS; |
| 8528 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8529 | uint32_t mcqe_status; |
| 8530 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8531 | struct lpfc_sli *psli = &phba->sli; |
| 8532 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 8533 | struct lpfc_bmbx_create *mbox_rgn; |
| 8534 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8535 | |
| 8536 | /* |
| 8537 | * Only one mailbox can be active to the bootstrap mailbox region |
| 8538 | * at a time and there is no queueing provided. |
| 8539 | */ |
| 8540 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8541 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8542 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8543 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8544 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8545 | "cannot issue Data: x%x x%x\n", |
| 8546 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8547 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8548 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8549 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8550 | psli->sli_flag, MBX_POLL); |
| 8551 | return MBXERR_ERROR; |
| 8552 | } |
| 8553 | /* The server grabs the token and owns it until release */ |
| 8554 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8555 | phba->sli.mbox_active = mboxq; |
| 8556 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8557 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8558 | /* wait for bootstrap mbox register for readyness */ |
| 8559 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8560 | if (rc) |
| 8561 | goto exit; |
| 8562 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8563 | /* |
| 8564 | * Initialize the bootstrap memory region to avoid stale data areas |
| 8565 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 8566 | * the bmbx mailbox region. |
| 8567 | */ |
| 8568 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 8569 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8570 | lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 8571 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8572 | |
| 8573 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 8574 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8575 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 8576 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8577 | /* wait for bootstrap mbox register for hi-address write done */ |
| 8578 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8579 | if (rc) |
| 8580 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8581 | |
| 8582 | /* Post the low mailbox dma address to the port. */ |
| 8583 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8584 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8585 | /* wait for bootstrap mbox register for low address write done */ |
| 8586 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8587 | if (rc) |
| 8588 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8589 | |
| 8590 | /* |
| 8591 | * Read the CQ to ensure the mailbox has completed. |
| 8592 | * If so, update the mailbox status so that the upper layers |
| 8593 | * can complete the request normally. |
| 8594 | */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8595 | lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 8596 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8597 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8598 | lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 8599 | sizeof(struct lpfc_mcqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8600 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8601 | /* |
| 8602 | * When the CQE status indicates a failure and the mailbox status |
| 8603 | * indicates success then copy the CQE status into the mailbox status |
| 8604 | * (and prefix it with x4000). |
| 8605 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8606 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8607 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 8608 | bf_set(lpfc_mqe_status, mb, |
| 8609 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8610 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8611 | } else |
| 8612 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8613 | |
| 8614 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8615 | "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8616 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 8617 | " x%x x%x CQ: x%x x%x x%x x%x\n", |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8618 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 8619 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8620 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8621 | bf_get(lpfc_mqe_status, mb), |
| 8622 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 8623 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 8624 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 8625 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 8626 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 8627 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 8628 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 8629 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 8630 | mboxq->mcqe.trailer); |
| 8631 | exit: |
| 8632 | /* We are holding the token, no needed for lock when release */ |
| 8633 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8634 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8635 | phba->sli.mbox_active = NULL; |
| 8636 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8637 | return rc; |
| 8638 | } |
| 8639 | |
| 8640 | /** |
| 8641 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 8642 | * @phba: Pointer to HBA context object. |
| 8643 | * @pmbox: Pointer to mailbox object. |
| 8644 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8645 | * |
| 8646 | * This function is called by discovery code and HBA management code to submit |
| 8647 | * a mailbox command to firmware with SLI-4 interface spec. |
| 8648 | * |
| 8649 | * Return codes the caller owns the mailbox command after the return of the |
| 8650 | * function. |
| 8651 | **/ |
| 8652 | static int |
| 8653 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 8654 | uint32_t flag) |
| 8655 | { |
| 8656 | struct lpfc_sli *psli = &phba->sli; |
| 8657 | unsigned long iflags; |
| 8658 | int rc; |
| 8659 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 8660 | /* dump from issue mailbox command if setup */ |
| 8661 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 8662 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8663 | rc = lpfc_mbox_dev_check(phba); |
| 8664 | if (unlikely(rc)) { |
| 8665 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8666 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8667 | "cannot issue Data: x%x x%x\n", |
| 8668 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8669 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8670 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8671 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8672 | psli->sli_flag, flag); |
| 8673 | goto out_not_finished; |
| 8674 | } |
| 8675 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8676 | /* Detect polling mode and jump to a handler */ |
| 8677 | if (!phba->sli4_hba.intr_enable) { |
| 8678 | if (flag == MBX_POLL) |
| 8679 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8680 | else |
| 8681 | rc = -EIO; |
| 8682 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8683 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8684 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8685 | "(x%x/x%x) failure: " |
| 8686 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8687 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8688 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8689 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8690 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8691 | mboxq), |
| 8692 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8693 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8694 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8695 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8696 | bf_get(lpfc_mcqe_ext_status, |
| 8697 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8698 | psli->sli_flag, flag); |
| 8699 | return rc; |
| 8700 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8701 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8702 | "(%d):2542 Try to issue mailbox command " |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8703 | "x%x (x%x/x%x) synchronously ahead of async " |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8704 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8705 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8706 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8707 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8708 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8709 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8710 | /* Try to block the asynchronous mailbox posting */ |
| 8711 | rc = lpfc_sli4_async_mbox_block(phba); |
| 8712 | if (!rc) { |
| 8713 | /* Successfully blocked, now issue sync mbox cmd */ |
| 8714 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8715 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8716 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8717 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8718 | "(%d):2597 Sync Mailbox command " |
| 8719 | "x%x (x%x/x%x) failure: " |
| 8720 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8721 | "Data: x%x x%x\n,", |
| 8722 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8723 | mboxq->u.mb.mbxCommand, |
| 8724 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8725 | mboxq), |
| 8726 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8727 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8728 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8729 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8730 | bf_get(lpfc_mcqe_ext_status, |
| 8731 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8732 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8733 | /* Unblock the async mailbox posting afterward */ |
| 8734 | lpfc_sli4_async_mbox_unblock(phba); |
| 8735 | } |
| 8736 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8737 | } |
| 8738 | |
| 8739 | /* Now, interrupt mode asynchrous mailbox command */ |
| 8740 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 8741 | if (rc) { |
| 8742 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8743 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8744 | "cannot issue Data: x%x x%x\n", |
| 8745 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8746 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8747 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8748 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8749 | psli->sli_flag, flag); |
| 8750 | goto out_not_finished; |
| 8751 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8752 | |
| 8753 | /* Put the mailbox command to the driver internal FIFO */ |
| 8754 | psli->slistat.mbox_busy++; |
| 8755 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8756 | lpfc_mbox_put(phba, mboxq); |
| 8757 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8758 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8759 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8760 | "x%x (x%x/x%x) x%x x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8761 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 8762 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8763 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8764 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8765 | phba->pport->port_state, |
| 8766 | psli->sli_flag, MBX_NOWAIT); |
| 8767 | /* Wake up worker thread to transport mailbox command from head */ |
| 8768 | lpfc_worker_wake_up(phba); |
| 8769 | |
| 8770 | return MBX_BUSY; |
| 8771 | |
| 8772 | out_not_finished: |
| 8773 | return MBX_NOT_FINISHED; |
| 8774 | } |
| 8775 | |
| 8776 | /** |
| 8777 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 8778 | * @phba: Pointer to HBA context object. |
| 8779 | * |
| 8780 | * This function is called by worker thread to send a mailbox command to |
| 8781 | * SLI4 HBA firmware. |
| 8782 | * |
| 8783 | **/ |
| 8784 | int |
| 8785 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 8786 | { |
| 8787 | struct lpfc_sli *psli = &phba->sli; |
| 8788 | LPFC_MBOXQ_t *mboxq; |
| 8789 | int rc = MBX_SUCCESS; |
| 8790 | unsigned long iflags; |
| 8791 | struct lpfc_mqe *mqe; |
| 8792 | uint32_t mbx_cmnd; |
| 8793 | |
| 8794 | /* Check interrupt mode before post async mailbox command */ |
| 8795 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 8796 | return MBX_NOT_FINISHED; |
| 8797 | |
| 8798 | /* Check for mailbox command service token */ |
| 8799 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8800 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8801 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8802 | return MBX_NOT_FINISHED; |
| 8803 | } |
| 8804 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8805 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8806 | return MBX_NOT_FINISHED; |
| 8807 | } |
| 8808 | if (unlikely(phba->sli.mbox_active)) { |
| 8809 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8810 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8811 | "0384 There is pending active mailbox cmd\n"); |
| 8812 | return MBX_NOT_FINISHED; |
| 8813 | } |
| 8814 | /* Take the mailbox command service token */ |
| 8815 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8816 | |
| 8817 | /* Get the next mailbox command from head of queue */ |
| 8818 | mboxq = lpfc_mbox_get(phba); |
| 8819 | |
| 8820 | /* If no more mailbox command waiting for post, we're done */ |
| 8821 | if (!mboxq) { |
| 8822 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8823 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8824 | return MBX_SUCCESS; |
| 8825 | } |
| 8826 | phba->sli.mbox_active = mboxq; |
| 8827 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8828 | |
| 8829 | /* Check device readiness for posting mailbox command */ |
| 8830 | rc = lpfc_mbox_dev_check(phba); |
| 8831 | if (unlikely(rc)) |
| 8832 | /* Driver clean routine will clean up pending mailbox */ |
| 8833 | goto out_not_finished; |
| 8834 | |
| 8835 | /* Prepare the mbox command to be posted */ |
| 8836 | mqe = &mboxq->u.mqe; |
| 8837 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 8838 | |
| 8839 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 8840 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8841 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8842 | |
| 8843 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8844 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8845 | "x%x x%x\n", |
| 8846 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8847 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8848 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8849 | phba->pport->port_state, psli->sli_flag); |
| 8850 | |
| 8851 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 8852 | if (mboxq->vport) { |
| 8853 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 8854 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8855 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 8856 | mbx_cmnd, mqe->un.mb_words[0], |
| 8857 | mqe->un.mb_words[1]); |
| 8858 | } else { |
| 8859 | lpfc_debugfs_disc_trc(phba->pport, |
| 8860 | LPFC_DISC_TRC_MBOX, |
| 8861 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 8862 | mbx_cmnd, mqe->un.mb_words[0], |
| 8863 | mqe->un.mb_words[1]); |
| 8864 | } |
| 8865 | } |
| 8866 | psli->slistat.mbox_cmd++; |
| 8867 | |
| 8868 | /* Post the mailbox command to the port */ |
| 8869 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 8870 | if (rc != MBX_SUCCESS) { |
| 8871 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8872 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8873 | "cannot issue Data: x%x x%x\n", |
| 8874 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8875 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8876 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8877 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8878 | psli->sli_flag, MBX_NOWAIT); |
| 8879 | goto out_not_finished; |
| 8880 | } |
| 8881 | |
| 8882 | return rc; |
| 8883 | |
| 8884 | out_not_finished: |
| 8885 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 8886 | if (phba->sli.mbox_active) { |
| 8887 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8888 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8889 | /* Release the token */ |
| 8890 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8891 | phba->sli.mbox_active = NULL; |
| 8892 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8893 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8894 | |
| 8895 | return MBX_NOT_FINISHED; |
| 8896 | } |
| 8897 | |
| 8898 | /** |
| 8899 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 8900 | * @phba: Pointer to HBA context object. |
| 8901 | * @pmbox: Pointer to mailbox object. |
| 8902 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8903 | * |
| 8904 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 8905 | * the API jump table function pointer from the lpfc_hba struct. |
| 8906 | * |
| 8907 | * Return codes the caller owns the mailbox command after the return of the |
| 8908 | * function. |
| 8909 | **/ |
| 8910 | int |
| 8911 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 8912 | { |
| 8913 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 8914 | } |
| 8915 | |
| 8916 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8917 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8918 | * @phba: The hba struct for which this call is being executed. |
| 8919 | * @dev_grp: The HBA PCI-Device group number. |
| 8920 | * |
| 8921 | * This routine sets up the mbox interface API function jump table in @phba |
| 8922 | * struct. |
| 8923 | * Returns: 0 - success, -ENODEV - failure. |
| 8924 | **/ |
| 8925 | int |
| 8926 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8927 | { |
| 8928 | |
| 8929 | switch (dev_grp) { |
| 8930 | case LPFC_PCI_DEV_LP: |
| 8931 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 8932 | phba->lpfc_sli_handle_slow_ring_event = |
| 8933 | lpfc_sli_handle_slow_ring_event_s3; |
| 8934 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 8935 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 8936 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 8937 | break; |
| 8938 | case LPFC_PCI_DEV_OC: |
| 8939 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 8940 | phba->lpfc_sli_handle_slow_ring_event = |
| 8941 | lpfc_sli_handle_slow_ring_event_s4; |
| 8942 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 8943 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 8944 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 8945 | break; |
| 8946 | default: |
| 8947 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8948 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 8949 | dev_grp); |
| 8950 | return -ENODEV; |
| 8951 | break; |
| 8952 | } |
| 8953 | return 0; |
| 8954 | } |
| 8955 | |
| 8956 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8957 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8958 | * @phba: Pointer to HBA context object. |
| 8959 | * @pring: Pointer to driver SLI ring object. |
| 8960 | * @piocb: Pointer to address of newly added command iocb. |
| 8961 | * |
| 8962 | * This function is called with hbalock held to add a command |
| 8963 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 8964 | * to the ring. |
| 8965 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8966 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8967 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8968 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8969 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8970 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8971 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 8972 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8973 | } |
| 8974 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8975 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8976 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8977 | * @phba: Pointer to HBA context object. |
| 8978 | * @pring: Pointer to driver SLI ring object. |
| 8979 | * @piocb: Pointer to address of newly added command iocb. |
| 8980 | * |
| 8981 | * This function is called with hbalock held before a new |
| 8982 | * iocb is submitted to the firmware. This function checks |
| 8983 | * txq to flush the iocbs in txq to Firmware before |
| 8984 | * submitting new iocbs to the Firmware. |
| 8985 | * If there are iocbs in the txq which need to be submitted |
| 8986 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 8987 | * of the txq after dequeuing it from txq. |
| 8988 | * If there is no iocb in the txq then the function will return |
| 8989 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 8990 | * *piocb to find if there are more commands in the txq. |
| 8991 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8992 | static struct lpfc_iocbq * |
| 8993 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8994 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8995 | { |
| 8996 | struct lpfc_iocbq * nextiocb; |
| 8997 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8998 | lockdep_assert_held(&phba->hbalock); |
| 8999 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9000 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 9001 | if (!nextiocb) { |
| 9002 | nextiocb = *piocb; |
| 9003 | *piocb = NULL; |
| 9004 | } |
| 9005 | |
| 9006 | return nextiocb; |
| 9007 | } |
| 9008 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9009 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9010 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9011 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9012 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9013 | * @piocb: Pointer to command iocb. |
| 9014 | * @flag: Flag indicating if this command can be put into txq. |
| 9015 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9016 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 9017 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 9018 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 9019 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 9020 | * this function allows only iocbs for posting buffers. This function finds |
| 9021 | * next available slot in the command ring and posts the command to the |
| 9022 | * available slot and writes the port attention register to request HBA start |
| 9023 | * processing new iocb. If there is no slot available in the ring and |
| 9024 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 9025 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9026 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9027 | * This function is called with hbalock held. The function will return success |
| 9028 | * after it successfully submit the iocb to firmware or after adding to the |
| 9029 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9030 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9031 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9032 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9033 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9034 | { |
| 9035 | struct lpfc_iocbq *nextiocb; |
| 9036 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9037 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9038 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9039 | lockdep_assert_held(&phba->hbalock); |
| 9040 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9041 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 9042 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 9043 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 9044 | lpfc_printf_log(phba, KERN_ERR, |
| 9045 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9046 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9047 | piocb->iocb.ulpCommand); |
| 9048 | dump_stack(); |
| 9049 | return IOCB_ERROR; |
| 9050 | } |
| 9051 | |
| 9052 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9053 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 9054 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 9055 | return IOCB_ERROR; |
| 9056 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9057 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 9058 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 9059 | return IOCB_ERROR; |
| 9060 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9061 | /* |
| 9062 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 9063 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9064 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9065 | return IOCB_ERROR; |
| 9066 | |
| 9067 | /* |
| 9068 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9069 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9070 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9071 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9072 | goto iocb_busy; |
| 9073 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9074 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9075 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9076 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9077 | * can be issued if the link is not up. |
| 9078 | */ |
| 9079 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9080 | case CMD_GEN_REQUEST64_CR: |
| 9081 | case CMD_GEN_REQUEST64_CX: |
| 9082 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 9083 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9084 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9085 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 9086 | MENLO_TRANSPORT_TYPE)) |
| 9087 | |
| 9088 | goto iocb_busy; |
| 9089 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9090 | case CMD_QUE_RING_BUF_CN: |
| 9091 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9092 | /* |
| 9093 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 9094 | * completion, iocb_cmpl MUST be 0. |
| 9095 | */ |
| 9096 | if (piocb->iocb_cmpl) |
| 9097 | piocb->iocb_cmpl = NULL; |
| 9098 | /*FALLTHROUGH*/ |
| 9099 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9100 | case CMD_CLOSE_XRI_CN: |
| 9101 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9102 | break; |
| 9103 | default: |
| 9104 | goto iocb_busy; |
| 9105 | } |
| 9106 | |
| 9107 | /* |
| 9108 | * For FCP commands, we must be in a state where we can process link |
| 9109 | * attention events. |
| 9110 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9111 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9112 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9113 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9114 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9115 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9116 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 9117 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 9118 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 9119 | |
| 9120 | if (iocb) |
| 9121 | lpfc_sli_update_ring(phba, pring); |
| 9122 | else |
| 9123 | lpfc_sli_update_full_ring(phba, pring); |
| 9124 | |
| 9125 | if (!piocb) |
| 9126 | return IOCB_SUCCESS; |
| 9127 | |
| 9128 | goto out_busy; |
| 9129 | |
| 9130 | iocb_busy: |
| 9131 | pring->stats.iocb_cmd_delay++; |
| 9132 | |
| 9133 | out_busy: |
| 9134 | |
| 9135 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9136 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9137 | return IOCB_SUCCESS; |
| 9138 | } |
| 9139 | |
| 9140 | return IOCB_BUSY; |
| 9141 | } |
| 9142 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9143 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9144 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 9145 | * @phba: Pointer to HBA context object. |
| 9146 | * @piocb: Pointer to command iocb. |
| 9147 | * @sglq: Pointer to the scatter gather queue object. |
| 9148 | * |
| 9149 | * This routine converts the bpl or bde that is in the IOCB |
| 9150 | * to a sgl list for the sli4 hardware. The physical address |
| 9151 | * of the bpl/bde is converted back to a virtual address. |
| 9152 | * If the IOCB contains a BPL then the list of BDE's is |
| 9153 | * converted to sli4_sge's. If the IOCB contains a single |
| 9154 | * BDE then it is converted to a single sli_sge. |
| 9155 | * The IOCB is still in cpu endianess so the contents of |
| 9156 | * the bpl can be used without byte swapping. |
| 9157 | * |
| 9158 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 9159 | **/ |
| 9160 | static uint16_t |
| 9161 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 9162 | struct lpfc_sglq *sglq) |
| 9163 | { |
| 9164 | uint16_t xritag = NO_XRI; |
| 9165 | struct ulp_bde64 *bpl = NULL; |
| 9166 | struct ulp_bde64 bde; |
| 9167 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9168 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9169 | IOCB_t *icmd; |
| 9170 | int numBdes = 0; |
| 9171 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9172 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 9173 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9174 | |
| 9175 | if (!piocbq || !sglq) |
| 9176 | return xritag; |
| 9177 | |
| 9178 | sgl = (struct sli4_sge *)sglq->sgl; |
| 9179 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9180 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 9181 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9182 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 9183 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 9184 | sizeof(struct ulp_bde64); |
| 9185 | /* The addrHigh and addrLow fields within the IOCB |
| 9186 | * have not been byteswapped yet so there is no |
| 9187 | * need to swap them back. |
| 9188 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9189 | if (piocbq->context3) |
| 9190 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 9191 | else |
| 9192 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9193 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9194 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9195 | if (!bpl) |
| 9196 | return xritag; |
| 9197 | |
| 9198 | for (i = 0; i < numBdes; i++) { |
| 9199 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9200 | sgl->addr_hi = bpl->addrHigh; |
| 9201 | sgl->addr_lo = bpl->addrLow; |
| 9202 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9203 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9204 | if ((i+1) == numBdes) |
| 9205 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9206 | else |
| 9207 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9208 | /* swap the size field back to the cpu so we |
| 9209 | * can assign it to the sgl. |
| 9210 | */ |
| 9211 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 9212 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9213 | /* The offsets in the sgl need to be accumulated |
| 9214 | * separately for the request and reply lists. |
| 9215 | * The request is always first, the reply follows. |
| 9216 | */ |
| 9217 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 9218 | /* add up the reply sg entries */ |
| 9219 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 9220 | inbound++; |
| 9221 | /* first inbound? reset the offset */ |
| 9222 | if (inbound == 1) |
| 9223 | offset = 0; |
| 9224 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 9225 | bf_set(lpfc_sli4_sge_type, sgl, |
| 9226 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9227 | offset += bde.tus.f.bdeSize; |
| 9228 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9229 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9230 | bpl++; |
| 9231 | sgl++; |
| 9232 | } |
| 9233 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 9234 | /* The addrHigh and addrLow fields of the BDE have not |
| 9235 | * been byteswapped yet so they need to be swapped |
| 9236 | * before putting them in the sgl. |
| 9237 | */ |
| 9238 | sgl->addr_hi = |
| 9239 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 9240 | sgl->addr_lo = |
| 9241 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9242 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9243 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9244 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9245 | sgl->sge_len = |
| 9246 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9247 | } |
| 9248 | return sglq->sli4_xritag; |
| 9249 | } |
| 9250 | |
| 9251 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9252 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 9253 | * @phba: Pointer to HBA context object. |
| 9254 | * @piocb: Pointer to command iocb. |
| 9255 | * @wqe: Pointer to the work queue entry. |
| 9256 | * |
| 9257 | * This routine converts the iocb command to its Work Queue Entry |
| 9258 | * equivalent. The wqe pointer should not have any fields set when |
| 9259 | * this routine is called because it will memcpy over them. |
| 9260 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 9261 | * wqe. |
| 9262 | * |
| 9263 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 9264 | **/ |
| 9265 | static int |
| 9266 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9267 | union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9268 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9269 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9270 | uint8_t ct = 0; |
| 9271 | uint32_t fip; |
| 9272 | uint32_t abort_tag; |
| 9273 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 9274 | uint8_t cmnd; |
| 9275 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9276 | uint16_t abrt_iotag; |
| 9277 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9278 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9279 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9280 | int numBdes, i; |
| 9281 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9282 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9283 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9284 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9285 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9286 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9287 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9288 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9289 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9290 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9291 | command_type = ELS_COMMAND_FIP; |
| 9292 | else |
| 9293 | command_type = ELS_COMMAND_NON_FIP; |
| 9294 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9295 | if (phba->fcp_embed_io) |
| 9296 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9297 | /* Some of the fields are in the right position already */ |
| 9298 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9299 | if (iocbq->iocb.ulpCommand != CMD_SEND_FRAME) { |
| 9300 | /* The ct field has moved so reset */ |
| 9301 | wqe->generic.wqe_com.word7 = 0; |
| 9302 | wqe->generic.wqe_com.word10 = 0; |
| 9303 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9304 | |
| 9305 | abort_tag = (uint32_t) iocbq->iotag; |
| 9306 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9307 | /* words0-2 bpl convert bde */ |
| 9308 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9309 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9310 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9311 | bpl = (struct ulp_bde64 *) |
| 9312 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 9313 | if (!bpl) |
| 9314 | return IOCB_ERROR; |
| 9315 | |
| 9316 | /* Should already be byte swapped. */ |
| 9317 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 9318 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 9319 | /* swap the size field back to the cpu so we |
| 9320 | * can assign it to the sgl. |
| 9321 | */ |
| 9322 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9323 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 9324 | total_len = 0; |
| 9325 | for (i = 0; i < numBdes; i++) { |
| 9326 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 9327 | total_len += bde.tus.f.bdeSize; |
| 9328 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9329 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9330 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9331 | |
| 9332 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 9333 | cmnd = iocbq->iocb.ulpCommand; |
| 9334 | |
| 9335 | switch (iocbq->iocb.ulpCommand) { |
| 9336 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 9337 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 9338 | ndlp = iocbq->context_un.ndlp; |
| 9339 | else |
| 9340 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9341 | if (!iocbq->iocb.ulpLe) { |
| 9342 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9343 | "2007 Only Limited Edition cmd Format" |
| 9344 | " supported 0x%x\n", |
| 9345 | iocbq->iocb.ulpCommand); |
| 9346 | return IOCB_ERROR; |
| 9347 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9348 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9349 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9350 | /* Els_reguest64 has a TMO */ |
| 9351 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 9352 | iocbq->iocb.ulpTimeout); |
| 9353 | /* Need a VF for word 4 set the vf bit*/ |
| 9354 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 9355 | /* And a VFID for word 12 */ |
| 9356 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9357 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9358 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9359 | iocbq->iocb.ulpContext); |
| 9360 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 9361 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9362 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9363 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9364 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 9365 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9366 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9367 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9368 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9369 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9370 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9371 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9372 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9373 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 9374 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9375 | *pcmd == ELS_CMD_PLOGI)) { |
| 9376 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 9377 | bf_set(els_req64_sid, &wqe->els_req, |
| 9378 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9379 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 9380 | !(phba->fc_topology == |
| 9381 | LPFC_TOPOLOGY_LOOP)) |
| 9382 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9383 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 9384 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 9385 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 9386 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9387 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 9388 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9389 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 9390 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9391 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9392 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 9393 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9394 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 9395 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 9396 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9397 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 9398 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9399 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9400 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9401 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9402 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9403 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 9404 | iocbq->iocb.un.ulpWord[3]); |
| 9405 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9406 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9407 | /* The entire sequence is transmitted for this IOCB */ |
| 9408 | xmit_len = total_len; |
| 9409 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9410 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 9411 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9412 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9413 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 9414 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9415 | /* word4 relative_offset memcpy */ |
| 9416 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9417 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 9418 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 9419 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 9420 | LPFC_WQE_IOD_WRITE); |
| 9421 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 9422 | LPFC_WQE_LENLOC_WORD12); |
| 9423 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9424 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 9425 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9426 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9427 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9428 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 9429 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9430 | /* word4 iocb=rsvd wqe=rsvd */ |
| 9431 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 9432 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9433 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9434 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9435 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 9436 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9437 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 9438 | LPFC_WQE_LENLOC_WORD3); |
| 9439 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9440 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9441 | case CMD_FCP_IWRITE64_CR: |
| 9442 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9443 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9444 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9445 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 9446 | xmit_len + sizeof(struct fcp_rsp)); |
| 9447 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 9448 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9449 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9450 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9451 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 9452 | iocbq->iocb.ulpFCP2Rcvy); |
| 9453 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 9454 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9455 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9456 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 9457 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9458 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9459 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9460 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9461 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9462 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 9463 | if (iocbq->priority) { |
| 9464 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9465 | (iocbq->priority << 1)); |
| 9466 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9467 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9468 | (phba->cfg_XLanePriority << 1)); |
| 9469 | } |
| 9470 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9471 | /* Note, word 10 is already initialized to 0 */ |
| 9472 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9473 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9474 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9475 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); |
| 9476 | else |
| 9477 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 9478 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9479 | if (phba->fcp_embed_io) { |
| 9480 | struct lpfc_scsi_buf *lpfc_cmd; |
| 9481 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9482 | struct fcp_cmnd *fcp_cmnd; |
| 9483 | uint32_t *ptr; |
| 9484 | |
| 9485 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9486 | |
| 9487 | lpfc_cmd = iocbq->context1; |
| 9488 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 9489 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9490 | |
| 9491 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9492 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9493 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9494 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9495 | wqe->generic.bde.addrHigh = 0; |
| 9496 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9497 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9498 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 9499 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9500 | |
| 9501 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9502 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9503 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9504 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9505 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9506 | case CMD_FCP_IREAD64_CR: |
| 9507 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9508 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9509 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 9510 | xmit_len + sizeof(struct fcp_rsp)); |
| 9511 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 9512 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9513 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9514 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9515 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 9516 | iocbq->iocb.ulpFCP2Rcvy); |
| 9517 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9518 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9519 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 9520 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 9521 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9522 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9523 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9524 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9525 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9526 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 9527 | if (iocbq->priority) { |
| 9528 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9529 | (iocbq->priority << 1)); |
| 9530 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9531 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9532 | (phba->cfg_XLanePriority << 1)); |
| 9533 | } |
| 9534 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9535 | /* Note, word 10 is already initialized to 0 */ |
| 9536 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9537 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9538 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9539 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); |
| 9540 | else |
| 9541 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0); |
| 9542 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9543 | if (phba->fcp_embed_io) { |
| 9544 | struct lpfc_scsi_buf *lpfc_cmd; |
| 9545 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9546 | struct fcp_cmnd *fcp_cmnd; |
| 9547 | uint32_t *ptr; |
| 9548 | |
| 9549 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9550 | |
| 9551 | lpfc_cmd = iocbq->context1; |
| 9552 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 9553 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9554 | |
| 9555 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9556 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9557 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9558 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9559 | wqe->generic.bde.addrHigh = 0; |
| 9560 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9561 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9562 | bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); |
| 9563 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9564 | |
| 9565 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9566 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9567 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9568 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9569 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9570 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9571 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9572 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 9573 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 9574 | xmit_len + sizeof(struct fcp_rsp)); |
| 9575 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 9576 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9577 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9578 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9579 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9580 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 9581 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9582 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 9583 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 9584 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 9585 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 9586 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9587 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9588 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9589 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 9590 | if (iocbq->priority) { |
| 9591 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9592 | (iocbq->priority << 1)); |
| 9593 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9594 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9595 | (phba->cfg_XLanePriority << 1)); |
| 9596 | } |
| 9597 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9598 | /* Note, word 10 is already initialized to 0 */ |
| 9599 | |
| 9600 | if (phba->fcp_embed_io) { |
| 9601 | struct lpfc_scsi_buf *lpfc_cmd; |
| 9602 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9603 | struct fcp_cmnd *fcp_cmnd; |
| 9604 | uint32_t *ptr; |
| 9605 | |
| 9606 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9607 | |
| 9608 | lpfc_cmd = iocbq->context1; |
| 9609 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 9610 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9611 | |
| 9612 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9613 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9614 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9615 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9616 | wqe->generic.bde.addrHigh = 0; |
| 9617 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9618 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9619 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); |
| 9620 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9621 | |
| 9622 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9623 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9624 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9625 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9626 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9627 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9628 | /* For this command calculate the xmit length of the |
| 9629 | * request bde. |
| 9630 | */ |
| 9631 | xmit_len = 0; |
| 9632 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9633 | sizeof(struct ulp_bde64); |
| 9634 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9635 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9636 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 9637 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9638 | xmit_len += bde.tus.f.bdeSize; |
| 9639 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9640 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 9641 | wqe->gen_req.request_payload_len = xmit_len; |
| 9642 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 9643 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9644 | /* word6 context tag copied in memcpy */ |
| 9645 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 9646 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 9647 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9648 | "2015 Invalid CT %x command 0x%x\n", |
| 9649 | ct, iocbq->iocb.ulpCommand); |
| 9650 | return IOCB_ERROR; |
| 9651 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9652 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 9653 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 9654 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 9655 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 9656 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9657 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 9658 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9659 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9660 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9661 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9662 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9663 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9664 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9665 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9666 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 9667 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9668 | /* word4 */ |
| 9669 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9670 | /* word5 iocb=rsvd wge=did */ |
| 9671 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9672 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 9673 | |
| 9674 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9675 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9676 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9677 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 9678 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9679 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 9680 | iocbq->vport->fc_myDID); |
| 9681 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 9682 | bf_set(wqe_els_did, |
| 9683 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 9684 | } |
| 9685 | } |
| 9686 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9687 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 9688 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9689 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 9690 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9691 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9692 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9693 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9694 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9695 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9696 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9697 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9698 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 9699 | LPFC_WQE_LENLOC_WORD3); |
| 9700 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9701 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 9702 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9703 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9704 | iocbq->context2)->virt); |
| 9705 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9706 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9707 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9708 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9709 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9710 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9711 | phba->vpi_ids[phba->pport->vpi]); |
| 9712 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9713 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9714 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9715 | case CMD_CLOSE_XRI_CN: |
| 9716 | case CMD_ABORT_XRI_CN: |
| 9717 | case CMD_ABORT_XRI_CX: |
| 9718 | /* words 0-2 memcpy should be 0 rserved */ |
| 9719 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9720 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 9721 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 9722 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 9723 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 9724 | } else |
| 9725 | fip = 0; |
| 9726 | |
| 9727 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9728 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9729 | * The link is down, or the command was ELS_FIP |
| 9730 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9731 | * on the wire. |
| 9732 | */ |
| 9733 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 9734 | else |
| 9735 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 9736 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9737 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 9738 | wqe->abort_cmd.rsrvd5 = 0; |
| 9739 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9740 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9741 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9742 | /* |
| 9743 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 9744 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 9745 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9746 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 9747 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 9748 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 9749 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9750 | cmnd = CMD_ABORT_XRI_CX; |
| 9751 | command_type = OTHER_COMMAND; |
| 9752 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9753 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9754 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9755 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9756 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9757 | * we re-construct this WQE here based on information in |
| 9758 | * iocbq from scratch. |
| 9759 | */ |
| 9760 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9761 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9762 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9763 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 9764 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9765 | LPFC_ABTS_UNSOL_INT) { |
| 9766 | /* ABTS sent by initiator to CT exchange, the |
| 9767 | * RX_ID field will be filled with the newly |
| 9768 | * allocated responder XRI. |
| 9769 | */ |
| 9770 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 9771 | iocbq->sli4_xritag); |
| 9772 | } else { |
| 9773 | /* ABTS sent by responder to CT exchange, the |
| 9774 | * RX_ID field will be filled with the responder |
| 9775 | * RX_ID from ABTS. |
| 9776 | */ |
| 9777 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9778 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9779 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9780 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 9781 | bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9782 | |
| 9783 | /* Use CT=VPI */ |
| 9784 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 9785 | ndlp->nlp_DID); |
| 9786 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 9787 | iocbq->iocb.ulpContext); |
| 9788 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9789 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9790 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9791 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 9792 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 9793 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9794 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 9795 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9796 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 9797 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 9798 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 9799 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 9800 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 9801 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 9802 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 9803 | } |
| 9804 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9805 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9806 | case CMD_SEND_FRAME: |
| 9807 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9808 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9809 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9810 | case CMD_XRI_ABORTED_CX: |
| 9811 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9812 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 9813 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 9814 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 9815 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 9816 | default: |
| 9817 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9818 | "2014 Invalid command 0x%x\n", |
| 9819 | iocbq->iocb.ulpCommand); |
| 9820 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9821 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9822 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9823 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 9824 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 9825 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 9826 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 9827 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 9828 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 9829 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 9830 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 9831 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9832 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9833 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9834 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 9835 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 9836 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 9837 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 9838 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9839 | return 0; |
| 9840 | } |
| 9841 | |
| 9842 | /** |
| 9843 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 9844 | * @phba: Pointer to HBA context object. |
| 9845 | * @ring_number: SLI ring number to issue iocb on. |
| 9846 | * @piocb: Pointer to command iocb. |
| 9847 | * @flag: Flag indicating if this command can be put into txq. |
| 9848 | * |
| 9849 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 9850 | * an iocb command to an HBA with SLI-4 interface spec. |
| 9851 | * |
| 9852 | * This function is called with hbalock held. The function will return success |
| 9853 | * after it successfully submit the iocb to firmware or after adding to the |
| 9854 | * txq. |
| 9855 | **/ |
| 9856 | static int |
| 9857 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 9858 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9859 | { |
| 9860 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9861 | union lpfc_wqe128 wqe; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9862 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9863 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9864 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9865 | /* Get the WQ */ |
| 9866 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 9867 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
| 9868 | if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) |
| 9869 | wq = phba->sli4_hba.fcp_wq[piocb->hba_wqidx]; |
| 9870 | else |
| 9871 | wq = phba->sli4_hba.oas_wq; |
| 9872 | } else { |
| 9873 | wq = phba->sli4_hba.els_wq; |
| 9874 | } |
| 9875 | |
| 9876 | /* Get corresponding ring */ |
| 9877 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9878 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9879 | /* |
| 9880 | * The WQE can be either 64 or 128 bytes, |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9881 | */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9882 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9883 | lockdep_assert_held(&phba->hbalock); |
| 9884 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9885 | if (piocb->sli4_xritag == NO_XRI) { |
| 9886 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9887 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9888 | sglq = NULL; |
| 9889 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9890 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9891 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9892 | __lpfc_sli_ringtx_put(phba, |
| 9893 | pring, piocb); |
| 9894 | return IOCB_SUCCESS; |
| 9895 | } else { |
| 9896 | return IOCB_BUSY; |
| 9897 | } |
| 9898 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9899 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9900 | if (!sglq) { |
| 9901 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9902 | __lpfc_sli_ringtx_put(phba, |
| 9903 | pring, |
| 9904 | piocb); |
| 9905 | return IOCB_SUCCESS; |
| 9906 | } else |
| 9907 | return IOCB_BUSY; |
| 9908 | } |
| 9909 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9910 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9911 | } else if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9912 | /* These IO's already have an XRI and a mapped sgl. */ |
| 9913 | sglq = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9914 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9915 | /* |
| 9916 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9917 | * sglq is on the active list |
| 9918 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 9919 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9920 | if (!sglq) |
| 9921 | return IOCB_ERROR; |
| 9922 | } |
| 9923 | |
| 9924 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9925 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9926 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9927 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9928 | return IOCB_ERROR; |
| 9929 | } |
| 9930 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9931 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9932 | return IOCB_ERROR; |
| 9933 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9934 | if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9935 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9936 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 9937 | |
| 9938 | return 0; |
| 9939 | } |
| 9940 | |
| 9941 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9942 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 9943 | * |
| 9944 | * This routine wraps the actual lockless version for issusing IOCB function |
| 9945 | * pointer from the lpfc_hba struct. |
| 9946 | * |
| 9947 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9948 | * IOCB_ERROR - Error |
| 9949 | * IOCB_SUCCESS - Success |
| 9950 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9951 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9952 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9953 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 9954 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9955 | { |
| 9956 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9957 | } |
| 9958 | |
| 9959 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9960 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9961 | * @phba: The hba struct for which this call is being executed. |
| 9962 | * @dev_grp: The HBA PCI-Device group number. |
| 9963 | * |
| 9964 | * This routine sets up the SLI interface API function jump table in @phba |
| 9965 | * struct. |
| 9966 | * Returns: 0 - success, -ENODEV - failure. |
| 9967 | **/ |
| 9968 | int |
| 9969 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 9970 | { |
| 9971 | |
| 9972 | switch (dev_grp) { |
| 9973 | case LPFC_PCI_DEV_LP: |
| 9974 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 9975 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 9976 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9977 | case LPFC_PCI_DEV_OC: |
| 9978 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 9979 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 9980 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9981 | default: |
| 9982 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9983 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 9984 | dev_grp); |
| 9985 | return -ENODEV; |
| 9986 | break; |
| 9987 | } |
| 9988 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 9989 | return 0; |
| 9990 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9991 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9992 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9993 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9994 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9995 | * @piocb: Pointer to command iocb. |
| 9996 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9997 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 9998 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9999 | * Since ABORTS must go on the same WQ of the command they are |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10000 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10001 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10002 | struct lpfc_sli_ring * |
| 10003 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10004 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10005 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 10006 | if (!(phba->cfg_fof) || |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10007 | (!(piocb->iocb_flag & LPFC_IO_FOF))) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 10008 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10009 | return NULL; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 10010 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10011 | * for abort iocb hba_wqidx should already |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 10012 | * be setup based on what work queue we used. |
| 10013 | */ |
Dick Kennedy | 8e036a9 | 2017-09-29 17:34:35 -0700 | [diff] [blame] | 10014 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10015 | piocb->hba_wqidx = |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 10016 | lpfc_sli4_scmd_to_wqidx_distr(phba, |
| 10017 | piocb->context1); |
Dick Kennedy | 8e036a9 | 2017-09-29 17:34:35 -0700 | [diff] [blame] | 10018 | piocb->hba_wqidx = piocb->hba_wqidx % |
| 10019 | phba->cfg_fcp_io_channel; |
| 10020 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10021 | return phba->sli4_hba.fcp_wq[piocb->hba_wqidx]->pring; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 10022 | } else { |
| 10023 | if (unlikely(!phba->sli4_hba.oas_wq)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10024 | return NULL; |
| 10025 | piocb->hba_wqidx = 0; |
| 10026 | return phba->sli4_hba.oas_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10027 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10028 | } else { |
| 10029 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 10030 | return NULL; |
| 10031 | piocb->hba_wqidx = 0; |
| 10032 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10033 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10034 | } |
| 10035 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10036 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10037 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10038 | * @phba: Pointer to HBA context object. |
| 10039 | * @pring: Pointer to driver SLI ring object. |
| 10040 | * @piocb: Pointer to command iocb. |
| 10041 | * @flag: Flag indicating if this command can be put into txq. |
| 10042 | * |
| 10043 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 10044 | * function. This function gets the hbalock and calls |
| 10045 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 10046 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 10047 | * functions which do not hold hbalock. |
| 10048 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10049 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10050 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10051 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10052 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10053 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10054 | struct lpfc_sli_ring *pring; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10055 | struct lpfc_queue *fpeq; |
| 10056 | struct lpfc_eqe *eqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10057 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10058 | int rc, idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10059 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10060 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10061 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 10062 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10063 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10064 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10065 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10066 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10067 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10068 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10069 | if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10070 | idx = piocb->hba_wqidx; |
| 10071 | hba_eq_hdl = &phba->sli4_hba.hba_eq_hdl[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10072 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10073 | if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use)) { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10074 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10075 | /* Get associated EQ with this index */ |
| 10076 | fpeq = phba->sli4_hba.hba_eq[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10077 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10078 | /* Turn off interrupts from this EQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10079 | phba->sli4_hba.sli4_eq_clr_intr(fpeq); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10080 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10081 | /* |
| 10082 | * Process all the events on FCP EQ |
| 10083 | */ |
| 10084 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 10085 | lpfc_sli4_hba_handle_eqe(phba, |
| 10086 | eqe, idx); |
| 10087 | fpeq->EQ_processed++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10088 | } |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10089 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10090 | /* Always clear and re-arm the EQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10091 | phba->sli4_hba.sli4_eq_release(fpeq, |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10092 | LPFC_QUEUE_REARM); |
| 10093 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10094 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10095 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10096 | } else { |
| 10097 | /* For now, SLI2/3 will still use hbalock */ |
| 10098 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10099 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10100 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10101 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10102 | return rc; |
| 10103 | } |
| 10104 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10105 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10106 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10107 | * @phba: Pointer to HBA context object. |
| 10108 | * |
| 10109 | * This function is called while driver attaches with the |
| 10110 | * HBA to setup the extra ring. The extra ring is used |
| 10111 | * only when driver needs to support target mode functionality |
| 10112 | * or IP over FC functionalities. |
| 10113 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10114 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10115 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10116 | static int |
| 10117 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 10118 | { |
| 10119 | struct lpfc_sli *psli; |
| 10120 | struct lpfc_sli_ring *pring; |
| 10121 | |
| 10122 | psli = &phba->sli; |
| 10123 | |
| 10124 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10125 | |
| 10126 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10127 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10128 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10129 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10130 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10131 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10132 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10133 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10134 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10135 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10136 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10137 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10138 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10139 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10140 | |
| 10141 | /* Setup default profile for this ring */ |
| 10142 | pring->iotag_max = 4096; |
| 10143 | pring->num_mask = 1; |
| 10144 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10145 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 10146 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10147 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 10148 | return 0; |
| 10149 | } |
| 10150 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10151 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 10152 | * @phba: Pointer to HBA context object. |
| 10153 | * @iocbq: Pointer to iocb object. |
| 10154 | * |
| 10155 | * The async_event handler calls this routine when it receives |
| 10156 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 10157 | * this event when an Abort Sequence request to an rport fails |
| 10158 | * twice in succession. The abort could be originated by the |
| 10159 | * driver or by the port. The ABTS could have been for an ELS |
| 10160 | * or FCP IO. The port only generates this event when an ABTS |
| 10161 | * fails to complete after one retry. |
| 10162 | */ |
| 10163 | static void |
| 10164 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 10165 | struct lpfc_iocbq *iocbq) |
| 10166 | { |
| 10167 | struct lpfc_nodelist *ndlp = NULL; |
| 10168 | uint16_t rpi = 0, vpi = 0; |
| 10169 | struct lpfc_vport *vport = NULL; |
| 10170 | |
| 10171 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 10172 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 10173 | rpi = iocbq->iocb.ulpContext; |
| 10174 | |
| 10175 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10176 | "3092 Port generated ABTS async event " |
| 10177 | "on vpi %d rpi %d status 0x%x\n", |
| 10178 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 10179 | |
| 10180 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 10181 | if (!vport) |
| 10182 | goto err_exit; |
| 10183 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 10184 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 10185 | goto err_exit; |
| 10186 | |
| 10187 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 10188 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10189 | return; |
| 10190 | |
| 10191 | err_exit: |
| 10192 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10193 | "3095 Event Context not found, no " |
| 10194 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 10195 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 10196 | vpi, rpi); |
| 10197 | } |
| 10198 | |
| 10199 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 10200 | * @phba: pointer to HBA context object. |
| 10201 | * @ndlp: nodelist pointer for the impacted rport. |
| 10202 | * @axri: pointer to the wcqe containing the failed exchange. |
| 10203 | * |
| 10204 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 10205 | * port. The port generates this event when an abort exchange request to an |
| 10206 | * rport fails twice in succession with no reply. The abort could be originated |
| 10207 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 10208 | */ |
| 10209 | void |
| 10210 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 10211 | struct lpfc_nodelist *ndlp, |
| 10212 | struct sli4_wcqe_xri_aborted *axri) |
| 10213 | { |
| 10214 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10215 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10216 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10217 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10218 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10219 | "3115 Node Context not found, driver " |
| 10220 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10221 | return; |
| 10222 | } |
| 10223 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10224 | vport = ndlp->vport; |
| 10225 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10226 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10227 | "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n", |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 10228 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10229 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10230 | bf_get(lpfc_wcqe_xa_status, axri), |
| 10231 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10232 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10233 | /* |
| 10234 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 10235 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 10236 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 10237 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 10238 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10239 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 10240 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10241 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10242 | } |
| 10243 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10244 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10245 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10246 | * @phba: Pointer to HBA context object. |
| 10247 | * @pring: Pointer to driver SLI ring object. |
| 10248 | * @iocbq: Pointer to iocb object. |
| 10249 | * |
| 10250 | * This function is called by the slow ring event handler |
| 10251 | * function when there is an ASYNC event iocb in the ring. |
| 10252 | * This function is called with no lock held. |
| 10253 | * Currently this function handles only temperature related |
| 10254 | * ASYNC events. The function decodes the temperature sensor |
| 10255 | * event message and posts events for the management applications. |
| 10256 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10257 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10258 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 10259 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 10260 | { |
| 10261 | IOCB_t *icmd; |
| 10262 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10263 | struct temp_event temp_event_data; |
| 10264 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10265 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10266 | |
| 10267 | icmd = &iocbq->iocb; |
| 10268 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10269 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10270 | switch (evt_code) { |
| 10271 | case ASYNC_TEMP_WARN: |
| 10272 | case ASYNC_TEMP_SAFE: |
| 10273 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 10274 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 10275 | if (evt_code == ASYNC_TEMP_WARN) { |
| 10276 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 10277 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10278 | "0347 Adapter is very hot, please take " |
| 10279 | "corrective action. temperature : %d Celsius\n", |
| 10280 | (uint32_t) icmd->ulpContext); |
| 10281 | } else { |
| 10282 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 10283 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10284 | "0340 Adapter temperature is OK now. " |
| 10285 | "temperature : %d Celsius\n", |
| 10286 | (uint32_t) icmd->ulpContext); |
| 10287 | } |
| 10288 | |
| 10289 | /* Send temperature change event to applications */ |
| 10290 | shost = lpfc_shost_from_vport(phba->pport); |
| 10291 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 10292 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 10293 | LPFC_NL_VENDOR_ID); |
| 10294 | break; |
| 10295 | case ASYNC_STATUS_CN: |
| 10296 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 10297 | break; |
| 10298 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10299 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10300 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10301 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 10302 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10303 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 10304 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 10305 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 10306 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10307 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10308 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 10309 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 10310 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 10311 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 10312 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10313 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10314 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10315 | } |
| 10316 | |
| 10317 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10318 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10319 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10320 | * @phba: Pointer to HBA context object. |
| 10321 | * |
| 10322 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10323 | * number of iocbs per ring and iotags. This function is |
| 10324 | * called while driver attach to the HBA and before the |
| 10325 | * interrupts are enabled. So there is no need for locking. |
| 10326 | * |
| 10327 | * This function always returns 0. |
| 10328 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10329 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10330 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 10331 | { |
| 10332 | struct lpfc_sli_ring *pring; |
| 10333 | |
| 10334 | pring = phba->sli4_hba.els_wq->pring; |
| 10335 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 10336 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 10337 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10338 | pring->prt[0].type = FC_TYPE_ELS; |
| 10339 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 10340 | lpfc_els_unsol_event; |
| 10341 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 10342 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10343 | pring->prt[1].type = FC_TYPE_ELS; |
| 10344 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 10345 | lpfc_els_unsol_event; |
| 10346 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10347 | /* NameServer Inquiry */ |
| 10348 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 10349 | /* NameServer */ |
| 10350 | pring->prt[2].type = FC_TYPE_CT; |
| 10351 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 10352 | lpfc_ct_unsol_event; |
| 10353 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10354 | /* NameServer response */ |
| 10355 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 10356 | /* NameServer */ |
| 10357 | pring->prt[3].type = FC_TYPE_CT; |
| 10358 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 10359 | lpfc_ct_unsol_event; |
| 10360 | return 0; |
| 10361 | } |
| 10362 | |
| 10363 | /** |
| 10364 | * lpfc_sli_setup - SLI ring setup function |
| 10365 | * @phba: Pointer to HBA context object. |
| 10366 | * |
| 10367 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10368 | * number of iocbs per ring and iotags. This function is |
| 10369 | * called while driver attach to the HBA and before the |
| 10370 | * interrupts are enabled. So there is no need for locking. |
| 10371 | * |
| 10372 | * This function always returns 0. SLI3 only. |
| 10373 | **/ |
| 10374 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10375 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 10376 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10377 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10378 | struct lpfc_sli *psli = &phba->sli; |
| 10379 | struct lpfc_sli_ring *pring; |
| 10380 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10381 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10382 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10383 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10384 | psli->iocbq_lookup = NULL; |
| 10385 | psli->iocbq_lookup_len = 0; |
| 10386 | psli->last_iotag = 0; |
| 10387 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10388 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10389 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10390 | switch (i) { |
| 10391 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 10392 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10393 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 10394 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 10395 | pring->sli.sli3.numCiocb += |
| 10396 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10397 | pring->sli.sli3.numRiocb += |
| 10398 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10399 | pring->sli.sli3.numCiocb += |
| 10400 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10401 | pring->sli.sli3.numRiocb += |
| 10402 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 10403 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10404 | SLI3_IOCB_CMD_SIZE : |
| 10405 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10406 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10407 | SLI3_IOCB_RSP_SIZE : |
| 10408 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10409 | pring->iotag_ctr = 0; |
| 10410 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10411 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10412 | pring->fast_iotag = pring->iotag_max; |
| 10413 | pring->num_mask = 0; |
| 10414 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10415 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10416 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10417 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 10418 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 10419 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10420 | SLI3_IOCB_CMD_SIZE : |
| 10421 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10422 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10423 | SLI3_IOCB_RSP_SIZE : |
| 10424 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10425 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10426 | pring->num_mask = 0; |
| 10427 | break; |
| 10428 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 10429 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10430 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 10431 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 10432 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10433 | SLI3_IOCB_CMD_SIZE : |
| 10434 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10435 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10436 | SLI3_IOCB_RSP_SIZE : |
| 10437 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10438 | pring->fast_iotag = 0; |
| 10439 | pring->iotag_ctr = 0; |
| 10440 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10441 | pring->lpfc_sli_rcv_async_status = |
| 10442 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10443 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10444 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10445 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10446 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10447 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10448 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10449 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10450 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10451 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10452 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10453 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10454 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10455 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10456 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10457 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10458 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10459 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10460 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10461 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10462 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10463 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10464 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10465 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10466 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10467 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10468 | break; |
| 10469 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10470 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 10471 | pring->sli.sli3.sizeCiocb) + |
| 10472 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10473 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10474 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10475 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10476 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 10477 | "SLI2 SLIM Data: x%x x%lx\n", |
| 10478 | phba->brd_no, totiocbsize, |
| 10479 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10480 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10481 | if (phba->cfg_multi_ring_support == 2) |
| 10482 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10483 | |
| 10484 | return 0; |
| 10485 | } |
| 10486 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10487 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10488 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10489 | * @phba: Pointer to HBA context object. |
| 10490 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10491 | * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10492 | * ring. This function also initializes ring indices of each ring. |
| 10493 | * This function is called during the initialization of the SLI |
| 10494 | * interface of an HBA. |
| 10495 | * This function is called with no lock held and always returns |
| 10496 | * 1. |
| 10497 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10498 | void |
| 10499 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 10500 | { |
| 10501 | struct lpfc_sli *psli; |
| 10502 | struct lpfc_sli_ring *pring; |
| 10503 | int i; |
| 10504 | |
| 10505 | psli = &phba->sli; |
| 10506 | spin_lock_irq(&phba->hbalock); |
| 10507 | INIT_LIST_HEAD(&psli->mboxq); |
| 10508 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 10509 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 10510 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
| 10511 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
| 10512 | pring->flag = 0; |
| 10513 | pring->ringno = LPFC_FCP_RING; |
| 10514 | INIT_LIST_HEAD(&pring->txq); |
| 10515 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10516 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10517 | spin_lock_init(&pring->ring_lock); |
| 10518 | } |
| 10519 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 10520 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 10521 | pring->flag = 0; |
| 10522 | pring->ringno = LPFC_FCP_RING; |
| 10523 | INIT_LIST_HEAD(&pring->txq); |
| 10524 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10525 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10526 | spin_lock_init(&pring->ring_lock); |
| 10527 | } |
| 10528 | pring = phba->sli4_hba.els_wq->pring; |
| 10529 | pring->flag = 0; |
| 10530 | pring->ringno = LPFC_ELS_RING; |
| 10531 | INIT_LIST_HEAD(&pring->txq); |
| 10532 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10533 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10534 | spin_lock_init(&pring->ring_lock); |
| 10535 | |
| 10536 | if (phba->cfg_nvme_io_channel) { |
| 10537 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 10538 | pring->flag = 0; |
| 10539 | pring->ringno = LPFC_ELS_RING; |
| 10540 | INIT_LIST_HEAD(&pring->txq); |
| 10541 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10542 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10543 | spin_lock_init(&pring->ring_lock); |
| 10544 | } |
| 10545 | |
| 10546 | if (phba->cfg_fof) { |
| 10547 | pring = phba->sli4_hba.oas_wq->pring; |
| 10548 | pring->flag = 0; |
| 10549 | pring->ringno = LPFC_FCP_RING; |
| 10550 | INIT_LIST_HEAD(&pring->txq); |
| 10551 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10552 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10553 | spin_lock_init(&pring->ring_lock); |
| 10554 | } |
| 10555 | |
| 10556 | spin_unlock_irq(&phba->hbalock); |
| 10557 | } |
| 10558 | |
| 10559 | /** |
| 10560 | * lpfc_sli_queue_init - Queue initialization function |
| 10561 | * @phba: Pointer to HBA context object. |
| 10562 | * |
| 10563 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 10564 | * ring. This function also initializes ring indices of each ring. |
| 10565 | * This function is called during the initialization of the SLI |
| 10566 | * interface of an HBA. |
| 10567 | * This function is called with no lock held and always returns |
| 10568 | * 1. |
| 10569 | **/ |
| 10570 | void |
| 10571 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10572 | { |
| 10573 | struct lpfc_sli *psli; |
| 10574 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10575 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10576 | |
| 10577 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10578 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10579 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10580 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10581 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 10582 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10583 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10584 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10585 | pring->sli.sli3.next_cmdidx = 0; |
| 10586 | pring->sli.sli3.local_getidx = 0; |
| 10587 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10588 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 10589 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10590 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10591 | pring->flag = 0; |
| 10592 | INIT_LIST_HEAD(&pring->txq); |
| 10593 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10594 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10595 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10596 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10597 | } |
| 10598 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10599 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10600 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 10601 | * @phba: Pointer to HBA context object. |
| 10602 | * |
| 10603 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 10604 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 10605 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 10606 | * command; and completed mailbox command queue. It is caller's responsibility |
| 10607 | * to make sure that the driver is in the proper state to flush the mailbox |
| 10608 | * command sub-system. Namely, the posting of mailbox commands into the |
| 10609 | * pending mailbox command queue from the various clients must be stopped; |
| 10610 | * either the HBA is in a state that it will never works on the outstanding |
| 10611 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 10612 | * mailbox command has been completed. |
| 10613 | **/ |
| 10614 | static void |
| 10615 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 10616 | { |
| 10617 | LIST_HEAD(completions); |
| 10618 | struct lpfc_sli *psli = &phba->sli; |
| 10619 | LPFC_MBOXQ_t *pmb; |
| 10620 | unsigned long iflag; |
| 10621 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10622 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10623 | local_bh_disable(); |
| 10624 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10625 | /* Flush all the mailbox commands in the mbox system */ |
| 10626 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10627 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10628 | /* The pending mailbox command queue */ |
| 10629 | list_splice_init(&phba->sli.mboxq, &completions); |
| 10630 | /* The outstanding active mailbox command */ |
| 10631 | if (psli->mbox_active) { |
| 10632 | list_add_tail(&psli->mbox_active->list, &completions); |
| 10633 | psli->mbox_active = NULL; |
| 10634 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10635 | } |
| 10636 | /* The completed mailbox command queue */ |
| 10637 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 10638 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10639 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10640 | /* Enable softirqs again, done with phba->hbalock */ |
| 10641 | local_bh_enable(); |
| 10642 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10643 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 10644 | while (!list_empty(&completions)) { |
| 10645 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 10646 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10647 | if (pmb->mbox_cmpl) |
| 10648 | pmb->mbox_cmpl(phba, pmb); |
| 10649 | } |
| 10650 | } |
| 10651 | |
| 10652 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10653 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10654 | * @vport: Pointer to virtual port object. |
| 10655 | * |
| 10656 | * lpfc_sli_host_down is called to clean up the resources |
| 10657 | * associated with a vport before destroying virtual |
| 10658 | * port data structures. |
| 10659 | * This function does following operations: |
| 10660 | * - Free discovery resources associated with this virtual |
| 10661 | * port. |
| 10662 | * - Free iocbs associated with this virtual port in |
| 10663 | * the txq. |
| 10664 | * - Send abort for all iocb commands associated with this |
| 10665 | * vport in txcmplq. |
| 10666 | * |
| 10667 | * This function is called with no lock held and always returns 1. |
| 10668 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10669 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10670 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 10671 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10672 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10673 | struct lpfc_hba *phba = vport->phba; |
| 10674 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10675 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10676 | struct lpfc_sli_ring *pring; |
| 10677 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10678 | int i; |
| 10679 | unsigned long flags = 0; |
| 10680 | uint16_t prev_pring_flag; |
| 10681 | |
| 10682 | lpfc_cleanup_discovery_resources(vport); |
| 10683 | |
| 10684 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10685 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10686 | /* |
| 10687 | * Error everything on the txq since these iocbs |
| 10688 | * have not been given to the FW yet. |
| 10689 | * Also issue ABTS for everything on the txcmplq |
| 10690 | */ |
| 10691 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10692 | for (i = 0; i < psli->num_rings; i++) { |
| 10693 | pring = &psli->sli3_ring[i]; |
| 10694 | prev_pring_flag = pring->flag; |
| 10695 | /* Only slow rings */ |
| 10696 | if (pring->ringno == LPFC_ELS_RING) { |
| 10697 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10698 | /* Set the lpfc data pending flag */ |
| 10699 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10700 | } |
| 10701 | list_for_each_entry_safe(iocb, next_iocb, |
| 10702 | &pring->txq, list) { |
| 10703 | if (iocb->vport != vport) |
| 10704 | continue; |
| 10705 | list_move_tail(&iocb->list, &completions); |
| 10706 | } |
| 10707 | list_for_each_entry_safe(iocb, next_iocb, |
| 10708 | &pring->txcmplq, list) { |
| 10709 | if (iocb->vport != vport) |
| 10710 | continue; |
| 10711 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10712 | } |
| 10713 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10714 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10715 | } else { |
| 10716 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10717 | pring = qp->pring; |
| 10718 | if (!pring) |
| 10719 | continue; |
| 10720 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10721 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10722 | /* Set the lpfc data pending flag */ |
| 10723 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10724 | } |
| 10725 | prev_pring_flag = pring->flag; |
| 10726 | spin_lock_irq(&pring->ring_lock); |
| 10727 | list_for_each_entry_safe(iocb, next_iocb, |
| 10728 | &pring->txq, list) { |
| 10729 | if (iocb->vport != vport) |
| 10730 | continue; |
| 10731 | list_move_tail(&iocb->list, &completions); |
| 10732 | } |
| 10733 | spin_unlock_irq(&pring->ring_lock); |
| 10734 | list_for_each_entry_safe(iocb, next_iocb, |
| 10735 | &pring->txcmplq, list) { |
| 10736 | if (iocb->vport != vport) |
| 10737 | continue; |
| 10738 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10739 | } |
| 10740 | pring->flag = prev_pring_flag; |
| 10741 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10742 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10743 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10744 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10745 | /* Cancel all the IOCBs from the completions list */ |
| 10746 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10747 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10748 | return 1; |
| 10749 | } |
| 10750 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10751 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10752 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10753 | * @phba: Pointer to HBA context object. |
| 10754 | * |
| 10755 | * This function cleans up all iocb, buffers, mailbox commands |
| 10756 | * while shutting down the HBA. This function is called with no |
| 10757 | * lock held and always returns 1. |
| 10758 | * This function does the following to cleanup driver resources: |
| 10759 | * - Free discovery resources for each virtual port |
| 10760 | * - Cleanup any pending fabric iocbs |
| 10761 | * - Iterate through the iocb txq and free each entry |
| 10762 | * in the list. |
| 10763 | * - Free up any buffer posted to the HBA |
| 10764 | * - Free mailbox commands in the mailbox queue. |
| 10765 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10766 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10767 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10768 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10769 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10770 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10771 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10772 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10773 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10774 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10775 | int i; |
| 10776 | |
| 10777 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10778 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10779 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10780 | lpfc_hba_down_prep(phba); |
| 10781 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10782 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10783 | local_bh_disable(); |
| 10784 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10785 | lpfc_fabric_abort_hba(phba); |
| 10786 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10787 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10788 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10789 | /* |
| 10790 | * Error everything on the txq since these iocbs |
| 10791 | * have not been given to the FW yet. |
| 10792 | */ |
| 10793 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10794 | for (i = 0; i < psli->num_rings; i++) { |
| 10795 | pring = &psli->sli3_ring[i]; |
| 10796 | /* Only slow rings */ |
| 10797 | if (pring->ringno == LPFC_ELS_RING) { |
| 10798 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10799 | /* Set the lpfc data pending flag */ |
| 10800 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10801 | } |
| 10802 | list_splice_init(&pring->txq, &completions); |
| 10803 | } |
| 10804 | } else { |
| 10805 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10806 | pring = qp->pring; |
| 10807 | if (!pring) |
| 10808 | continue; |
| 10809 | spin_lock_irq(&pring->ring_lock); |
| 10810 | list_splice_init(&pring->txq, &completions); |
| 10811 | spin_unlock_irq(&pring->ring_lock); |
| 10812 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10813 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10814 | /* Set the lpfc data pending flag */ |
| 10815 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10816 | } |
| 10817 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10818 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10819 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10820 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10821 | /* Cancel all the IOCBs from the completions list */ |
| 10822 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10823 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10824 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10825 | spin_lock_irqsave(&phba->hbalock, flags); |
| 10826 | list_splice_init(&phba->elsbuf, &completions); |
| 10827 | phba->elsbuf_cnt = 0; |
| 10828 | phba->elsbuf_prev_cnt = 0; |
| 10829 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10830 | |
| 10831 | while (!list_empty(&completions)) { |
| 10832 | list_remove_head(&completions, buf_ptr, |
| 10833 | struct lpfc_dmabuf, list); |
| 10834 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 10835 | kfree(buf_ptr); |
| 10836 | } |
| 10837 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10838 | /* Enable softirqs again, done with phba->hbalock */ |
| 10839 | local_bh_enable(); |
| 10840 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10841 | /* Return any active mbox cmds */ |
| 10842 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10843 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10844 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10845 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10846 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10847 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10848 | return 1; |
| 10849 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10850 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10851 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10852 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10853 | * @srcp: Source memory pointer. |
| 10854 | * @destp: Destination memory pointer. |
| 10855 | * @cnt: Number of words required to be copied. |
| 10856 | * |
| 10857 | * This function is used for copying data between driver memory |
| 10858 | * and the SLI memory. This function also changes the endianness |
| 10859 | * of each word if native endianness is different from SLI |
| 10860 | * endianness. This function can be called with or without |
| 10861 | * lock. |
| 10862 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10863 | void |
| 10864 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10865 | { |
| 10866 | uint32_t *src = srcp; |
| 10867 | uint32_t *dest = destp; |
| 10868 | uint32_t ldata; |
| 10869 | int i; |
| 10870 | |
| 10871 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 10872 | ldata = *src; |
| 10873 | ldata = le32_to_cpu(ldata); |
| 10874 | *dest = ldata; |
| 10875 | src++; |
| 10876 | dest++; |
| 10877 | } |
| 10878 | } |
| 10879 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10880 | |
| 10881 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 10882 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 10883 | * @srcp: Source memory pointer. |
| 10884 | * @destp: Destination memory pointer. |
| 10885 | * @cnt: Number of words required to be copied. |
| 10886 | * |
| 10887 | * This function is used for copying data between a data structure |
| 10888 | * with big endian representation to local endianness. |
| 10889 | * This function can be called with or without lock. |
| 10890 | **/ |
| 10891 | void |
| 10892 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10893 | { |
| 10894 | uint32_t *src = srcp; |
| 10895 | uint32_t *dest = destp; |
| 10896 | uint32_t ldata; |
| 10897 | int i; |
| 10898 | |
| 10899 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 10900 | ldata = *src; |
| 10901 | ldata = be32_to_cpu(ldata); |
| 10902 | *dest = ldata; |
| 10903 | src++; |
| 10904 | dest++; |
| 10905 | } |
| 10906 | } |
| 10907 | |
| 10908 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10909 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10910 | * @phba: Pointer to HBA context object. |
| 10911 | * @pring: Pointer to driver SLI ring object. |
| 10912 | * @mp: Pointer to driver buffer object. |
| 10913 | * |
| 10914 | * This function is called with no lock held. |
| 10915 | * It always return zero after adding the buffer to the postbufq |
| 10916 | * buffer list. |
| 10917 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10918 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10919 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10920 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10921 | { |
| 10922 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 10923 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10924 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10925 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10926 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10927 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10928 | return 0; |
| 10929 | } |
| 10930 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10931 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10932 | * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10933 | * @phba: Pointer to HBA context object. |
| 10934 | * |
| 10935 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 10936 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 10937 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 10938 | * does not conflict with tags of buffer posted for unsolicited events. |
| 10939 | * The function returns the allocated tag. The function is called with |
| 10940 | * no locks held. |
| 10941 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10942 | uint32_t |
| 10943 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 10944 | { |
| 10945 | spin_lock_irq(&phba->hbalock); |
| 10946 | phba->buffer_tag_count++; |
| 10947 | /* |
| 10948 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 10949 | * a tag assigned by HBQ. |
| 10950 | */ |
| 10951 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 10952 | spin_unlock_irq(&phba->hbalock); |
| 10953 | return phba->buffer_tag_count; |
| 10954 | } |
| 10955 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10956 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10957 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10958 | * @phba: Pointer to HBA context object. |
| 10959 | * @pring: Pointer to driver SLI ring object. |
| 10960 | * @tag: Buffer tag. |
| 10961 | * |
| 10962 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 10963 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 10964 | * iocb is posted to the response ring with the tag of the buffer. |
| 10965 | * This function searches the pring->postbufq list using the tag |
| 10966 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 10967 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 10968 | * buffer is returned to the caller else NULL is returned. |
| 10969 | * This function is called with no lock held. |
| 10970 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10971 | struct lpfc_dmabuf * |
| 10972 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10973 | uint32_t tag) |
| 10974 | { |
| 10975 | struct lpfc_dmabuf *mp, *next_mp; |
| 10976 | struct list_head *slp = &pring->postbufq; |
| 10977 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10978 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10979 | spin_lock_irq(&phba->hbalock); |
| 10980 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10981 | if (mp->buffer_tag == tag) { |
| 10982 | list_del_init(&mp->list); |
| 10983 | pring->postbufq_cnt--; |
| 10984 | spin_unlock_irq(&phba->hbalock); |
| 10985 | return mp; |
| 10986 | } |
| 10987 | } |
| 10988 | |
| 10989 | spin_unlock_irq(&phba->hbalock); |
| 10990 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10991 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10992 | "ring %d Data x%lx x%p x%p x%x\n", |
| 10993 | pring->ringno, (unsigned long) tag, |
| 10994 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10995 | |
| 10996 | return NULL; |
| 10997 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10998 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10999 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11000 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11001 | * @phba: Pointer to HBA context object. |
| 11002 | * @pring: Pointer to driver SLI ring object. |
| 11003 | * @phys: DMA address of the buffer. |
| 11004 | * |
| 11005 | * This function searches the buffer list using the dma_address |
| 11006 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 11007 | * corresponding to the dma_address. The function returns the |
| 11008 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 11009 | * This function is called by the ct and els unsolicited event |
| 11010 | * handlers to get the buffer associated with the unsolicited |
| 11011 | * event. |
| 11012 | * |
| 11013 | * This function is called with no lock held. |
| 11014 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11015 | struct lpfc_dmabuf * |
| 11016 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11017 | dma_addr_t phys) |
| 11018 | { |
| 11019 | struct lpfc_dmabuf *mp, *next_mp; |
| 11020 | struct list_head *slp = &pring->postbufq; |
| 11021 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11022 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11023 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11024 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 11025 | if (mp->phys == phys) { |
| 11026 | list_del_init(&mp->list); |
| 11027 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11028 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11029 | return mp; |
| 11030 | } |
| 11031 | } |
| 11032 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11033 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11034 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11035 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11036 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11037 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11038 | slp->next, slp->prev, pring->postbufq_cnt); |
| 11039 | return NULL; |
| 11040 | } |
| 11041 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11042 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11043 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11044 | * @phba: Pointer to HBA context object. |
| 11045 | * @cmdiocb: Pointer to driver command iocb object. |
| 11046 | * @rspiocb: Pointer to driver response iocb object. |
| 11047 | * |
| 11048 | * This function is the completion handler for the abort iocbs for |
| 11049 | * ELS commands. This function is called from the ELS ring event |
| 11050 | * handler with no lock held. This function frees memory resources |
| 11051 | * associated with the abort iocb. |
| 11052 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11053 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11054 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11055 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11056 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11057 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11058 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11059 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11060 | |
| 11061 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11062 | |
| 11063 | /* |
| 11064 | * Assume that the port already completed and returned, or |
| 11065 | * will return the iocb. Just Log the message. |
| 11066 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11067 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 11068 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 11069 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11070 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11071 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11072 | if (irsp->ulpCommand == CMD_ABORT_XRI_CX && |
| 11073 | irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 11074 | irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) { |
| 11075 | spin_unlock_irq(&phba->hbalock); |
| 11076 | goto release_iocb; |
| 11077 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11078 | if (abort_iotag != 0 && |
| 11079 | abort_iotag <= phba->sli.last_iotag) |
| 11080 | abort_iocb = |
| 11081 | phba->sli.iocbq_lookup[abort_iotag]; |
| 11082 | } else |
| 11083 | /* For sli4 the abort_tag is the XRI, |
| 11084 | * so the abort routine puts the iotag of the iocb |
| 11085 | * being aborted in the context field of the abort |
| 11086 | * IOCB. |
| 11087 | */ |
| 11088 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11089 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11090 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 11091 | "0327 Cannot abort els iocb %p " |
| 11092 | "with tag %x context %x, abort status %x, " |
| 11093 | "abort code %x\n", |
| 11094 | abort_iocb, abort_iotag, abort_context, |
| 11095 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11096 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11097 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11098 | } |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11099 | release_iocb: |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11100 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11101 | return; |
| 11102 | } |
| 11103 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11104 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11105 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11106 | * @phba: Pointer to HBA context object. |
| 11107 | * @cmdiocb: Pointer to driver command iocb object. |
| 11108 | * @rspiocb: Pointer to driver response iocb object. |
| 11109 | * |
| 11110 | * The function is called from SLI ring event handler with no |
| 11111 | * lock held. This function is the completion handler for ELS commands |
| 11112 | * which are aborted. The function frees memory resources used for |
| 11113 | * the aborted ELS commands. |
| 11114 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11115 | static void |
| 11116 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11117 | struct lpfc_iocbq *rspiocb) |
| 11118 | { |
| 11119 | IOCB_t *irsp = &rspiocb->iocb; |
| 11120 | |
| 11121 | /* ELS cmd tag <ulpIoTag> completes */ |
| 11122 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11123 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11124 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11125 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11126 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11127 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 11128 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 11129 | else |
| 11130 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11131 | return; |
| 11132 | } |
| 11133 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11134 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11135 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11136 | * @phba: Pointer to HBA context object. |
| 11137 | * @pring: Pointer to driver SLI ring object. |
| 11138 | * @cmdiocb: Pointer to driver command iocb object. |
| 11139 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11140 | * This function issues an abort iocb for the provided command iocb down to |
| 11141 | * the port. Other than the case the outstanding command iocb is an abort |
| 11142 | * request, this function issues abort out unconditionally. This function is |
| 11143 | * called with hbalock held. The function returns 0 when it fails due to |
| 11144 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11145 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11146 | static int |
| 11147 | lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11148 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11149 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11150 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11151 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11152 | IOCB_t *icmd = NULL; |
| 11153 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11154 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11155 | unsigned long iflags; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11156 | struct lpfc_nodelist *ndlp; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11157 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11158 | lockdep_assert_held(&phba->hbalock); |
| 11159 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11160 | /* |
| 11161 | * There are certain command types we don't want to abort. And we |
| 11162 | * don't want to abort commands that are already in the process of |
| 11163 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11164 | */ |
| 11165 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11166 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11167 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11168 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11169 | return 0; |
| 11170 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11171 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11172 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11173 | if (abtsiocbp == NULL) |
| 11174 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11175 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11176 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11177 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11178 | */ |
| 11179 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11180 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11181 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11182 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11183 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11184 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11185 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11186 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11187 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11188 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11189 | if (pring->ringno == LPFC_ELS_RING) { |
| 11190 | ndlp = (struct lpfc_nodelist *)(cmdiocb->context1); |
| 11191 | iabt->un.acxri.abortContextTag = ndlp->nlp_rpi; |
| 11192 | } |
| 11193 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11194 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11195 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11196 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11197 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11198 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11199 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 11200 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11201 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 11202 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11203 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11204 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11205 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 11206 | else |
| 11207 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 11208 | |
| 11209 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 11210 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 11211 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11212 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 11213 | "0339 Abort xri x%x, original iotag x%x, " |
| 11214 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11215 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11216 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11217 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11218 | |
| 11219 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11220 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 11221 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11222 | return 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11223 | /* Note: both hbalock and ring_lock need to be set here */ |
| 11224 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11225 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11226 | abtsiocbp, 0); |
| 11227 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 11228 | } else { |
| 11229 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11230 | abtsiocbp, 0); |
| 11231 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11232 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11233 | if (retval) |
| 11234 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11235 | |
| 11236 | /* |
| 11237 | * Caller to this routine should check for IOCB_ERROR |
| 11238 | * and handle it properly. This routine no longer removes |
| 11239 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 11240 | */ |
| 11241 | return retval; |
| 11242 | } |
| 11243 | |
| 11244 | /** |
| 11245 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 11246 | * @phba: Pointer to HBA context object. |
| 11247 | * @pring: Pointer to driver SLI ring object. |
| 11248 | * @cmdiocb: Pointer to driver command iocb object. |
| 11249 | * |
| 11250 | * This function issues an abort iocb for the provided command iocb. In case |
| 11251 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 11252 | * ring. Instead, the callback function shall be changed to those commands |
| 11253 | * so that nothing happens when them finishes. This function is called with |
| 11254 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 11255 | * request. |
| 11256 | **/ |
| 11257 | int |
| 11258 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11259 | struct lpfc_iocbq *cmdiocb) |
| 11260 | { |
| 11261 | struct lpfc_vport *vport = cmdiocb->vport; |
| 11262 | int retval = IOCB_ERROR; |
| 11263 | IOCB_t *icmd = NULL; |
| 11264 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11265 | lockdep_assert_held(&phba->hbalock); |
| 11266 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11267 | /* |
| 11268 | * There are certain command types we don't want to abort. And we |
| 11269 | * don't want to abort commands that are already in the process of |
| 11270 | * being aborted. |
| 11271 | */ |
| 11272 | icmd = &cmdiocb->iocb; |
| 11273 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 11274 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11275 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 11276 | return 0; |
| 11277 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 11278 | if (!pring) { |
| 11279 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11280 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11281 | else |
| 11282 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11283 | goto abort_iotag_exit; |
| 11284 | } |
| 11285 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11286 | /* |
| 11287 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 11288 | * the callback so that nothing happens when it finishes. |
| 11289 | */ |
| 11290 | if ((vport->load_flag & FC_UNLOADING) && |
| 11291 | (pring->ringno == LPFC_ELS_RING)) { |
| 11292 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11293 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11294 | else |
| 11295 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11296 | goto abort_iotag_exit; |
| 11297 | } |
| 11298 | |
| 11299 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 11300 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 11301 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11302 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11303 | /* |
| 11304 | * Caller to this routine should check for IOCB_ERROR |
| 11305 | * and handle it properly. This routine no longer removes |
| 11306 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11307 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11308 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11309 | } |
| 11310 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11311 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11312 | * lpfc_sli4_abort_nvme_io - Issue abort for a command iocb |
| 11313 | * @phba: Pointer to HBA context object. |
| 11314 | * @pring: Pointer to driver SLI ring object. |
| 11315 | * @cmdiocb: Pointer to driver command iocb object. |
| 11316 | * |
| 11317 | * This function issues an abort iocb for the provided command iocb down to |
| 11318 | * the port. Other than the case the outstanding command iocb is an abort |
| 11319 | * request, this function issues abort out unconditionally. This function is |
| 11320 | * called with hbalock held. The function returns 0 when it fails due to |
| 11321 | * memory allocation failure or when the command iocb is an abort request. |
| 11322 | **/ |
| 11323 | static int |
| 11324 | lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11325 | struct lpfc_iocbq *cmdiocb) |
| 11326 | { |
| 11327 | struct lpfc_vport *vport = cmdiocb->vport; |
| 11328 | struct lpfc_iocbq *abtsiocbp; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 11329 | union lpfc_wqe128 *abts_wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11330 | int retval; |
| 11331 | |
| 11332 | /* |
| 11333 | * There are certain command types we don't want to abort. And we |
| 11334 | * don't want to abort commands that are already in the process of |
| 11335 | * being aborted. |
| 11336 | */ |
| 11337 | if (cmdiocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 11338 | cmdiocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN || |
| 11339 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 11340 | return 0; |
| 11341 | |
| 11342 | /* issue ABTS for this io based on iotag */ |
| 11343 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| 11344 | if (abtsiocbp == NULL) |
| 11345 | return 0; |
| 11346 | |
| 11347 | /* This signals the response to set the correct status |
| 11348 | * before calling the completion handler |
| 11349 | */ |
| 11350 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11351 | |
| 11352 | /* Complete prepping the abort wqe and issue to the FW. */ |
| 11353 | abts_wqe = &abtsiocbp->wqe; |
James Smart | 1c36833 | 2018-11-29 16:09:37 -0800 | [diff] [blame] | 11354 | |
| 11355 | /* Clear any stale WQE contents */ |
| 11356 | memset(abts_wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11357 | bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG); |
| 11358 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11359 | /* word 7 */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11360 | bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 11361 | bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com, |
| 11362 | cmdiocb->iocb.ulpClass); |
| 11363 | |
| 11364 | /* word 8 - tell the FW to abort the IO associated with this |
| 11365 | * outstanding exchange ID. |
| 11366 | */ |
| 11367 | abts_wqe->abort_cmd.wqe_com.abort_tag = cmdiocb->sli4_xritag; |
| 11368 | |
| 11369 | /* word 9 - this is the iotag for the abts_wqe completion. */ |
| 11370 | bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com, |
| 11371 | abtsiocbp->iotag); |
| 11372 | |
| 11373 | /* word 10 */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11374 | bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1); |
| 11375 | bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 11376 | |
| 11377 | /* word 11 */ |
| 11378 | bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND); |
| 11379 | bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1); |
| 11380 | bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
| 11381 | |
| 11382 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 11383 | abtsiocbp->iocb_flag |= LPFC_IO_NVME; |
| 11384 | abtsiocbp->vport = vport; |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 11385 | abtsiocbp->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11386 | retval = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abtsiocbp); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 11387 | if (retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11388 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 11389 | "6147 Failed abts issue_wqe with status x%x " |
| 11390 | "for oxid x%x\n", |
| 11391 | retval, cmdiocb->sli4_xritag); |
| 11392 | lpfc_sli_release_iocbq(phba, abtsiocbp); |
| 11393 | return retval; |
| 11394 | } |
| 11395 | |
| 11396 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 11397 | "6148 Drv Abort NVME Request Issued for " |
| 11398 | "ox_id x%x on reqtag x%x\n", |
| 11399 | cmdiocb->sli4_xritag, |
| 11400 | abtsiocbp->iotag); |
| 11401 | |
| 11402 | return retval; |
| 11403 | } |
| 11404 | |
| 11405 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11406 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 11407 | * @phba: pointer to lpfc HBA data structure. |
| 11408 | * |
| 11409 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 11410 | **/ |
| 11411 | void |
| 11412 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 11413 | { |
| 11414 | struct lpfc_sli *psli = &phba->sli; |
| 11415 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11416 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11417 | int i; |
| 11418 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11419 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11420 | for (i = 0; i < psli->num_rings; i++) { |
| 11421 | pring = &psli->sli3_ring[i]; |
| 11422 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 11423 | } |
| 11424 | return; |
| 11425 | } |
| 11426 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11427 | pring = qp->pring; |
| 11428 | if (!pring) |
| 11429 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 11430 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11431 | } |
| 11432 | } |
| 11433 | |
| 11434 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11435 | * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11436 | * @iocbq: Pointer to driver iocb object. |
| 11437 | * @vport: Pointer to driver virtual port object. |
| 11438 | * @tgt_id: SCSI ID of the target. |
| 11439 | * @lun_id: LUN ID of the scsi device. |
| 11440 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 11441 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11442 | * This function acts as an iocb filter for functions which abort or count |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11443 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 11444 | * 0 if the filtering criteria is met for the given iocb and will return |
| 11445 | * 1 if the filtering criteria is not met. |
| 11446 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 11447 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 11448 | * lun_id parameter. |
| 11449 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 11450 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 11451 | * parameters. |
| 11452 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 11453 | * given iocb is for the SCSI host associated with the given vport. |
| 11454 | * This function is called with no locks held. |
| 11455 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11456 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11457 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 11458 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11459 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11460 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11461 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11462 | int rc = 1; |
| 11463 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11464 | if (iocbq->vport != vport) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11465 | return rc; |
| 11466 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11467 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 11468 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11469 | return rc; |
| 11470 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11471 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11472 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11473 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11474 | return rc; |
| 11475 | |
| 11476 | switch (ctx_cmd) { |
| 11477 | case LPFC_CTX_LUN: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11478 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11479 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 11480 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11481 | rc = 0; |
| 11482 | break; |
| 11483 | case LPFC_CTX_TGT: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11484 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11485 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11486 | rc = 0; |
| 11487 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11488 | case LPFC_CTX_HOST: |
| 11489 | rc = 0; |
| 11490 | break; |
| 11491 | default: |
| 11492 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 11493 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11494 | break; |
| 11495 | } |
| 11496 | |
| 11497 | return rc; |
| 11498 | } |
| 11499 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11500 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11501 | * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11502 | * @vport: Pointer to virtual port. |
| 11503 | * @tgt_id: SCSI ID of the target. |
| 11504 | * @lun_id: LUN ID of the scsi device. |
| 11505 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11506 | * |
| 11507 | * This function returns number of FCP commands pending for the vport. |
| 11508 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 11509 | * commands pending on the vport associated with SCSI device specified |
| 11510 | * by tgt_id and lun_id parameters. |
| 11511 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 11512 | * commands pending on the vport associated with SCSI target specified |
| 11513 | * by tgt_id parameter. |
| 11514 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 11515 | * commands pending on the vport. |
| 11516 | * This function returns the number of iocbs which satisfy the filter. |
| 11517 | * This function is called without any lock held. |
| 11518 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11519 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11520 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 11521 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11522 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11523 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11524 | struct lpfc_iocbq *iocbq; |
| 11525 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11526 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11527 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11528 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 11529 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11530 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11531 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 11532 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11533 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11534 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11535 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11536 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11537 | return sum; |
| 11538 | } |
| 11539 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11540 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11541 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11542 | * @phba: Pointer to HBA context object |
| 11543 | * @cmdiocb: Pointer to command iocb object. |
| 11544 | * @rspiocb: Pointer to response iocb object. |
| 11545 | * |
| 11546 | * This function is called when an aborted FCP iocb completes. This |
| 11547 | * function is called by the ring event handler with no lock held. |
| 11548 | * This function frees the iocb. |
| 11549 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11550 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11551 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11552 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11553 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11554 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 11555 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11556 | "original iotag x%x, abort cmd iotag x%x " |
| 11557 | "status 0x%x, reason 0x%x\n", |
| 11558 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 11559 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 11560 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 11561 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11562 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11563 | return; |
| 11564 | } |
| 11565 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11566 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11567 | * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11568 | * @vport: Pointer to virtual port. |
| 11569 | * @pring: Pointer to driver SLI ring object. |
| 11570 | * @tgt_id: SCSI ID of the target. |
| 11571 | * @lun_id: LUN ID of the scsi device. |
| 11572 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11573 | * |
| 11574 | * This function sends an abort command for every SCSI command |
| 11575 | * associated with the given virtual port pending on the ring |
| 11576 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11577 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11578 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11579 | * parameters |
| 11580 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11581 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11582 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11583 | * FCP iocbs associated with virtual port. |
| 11584 | * This function returns number of iocbs it failed to abort. |
| 11585 | * This function is called with no locks held. |
| 11586 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11587 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11588 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11589 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11590 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11591 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11592 | struct lpfc_iocbq *iocbq; |
| 11593 | struct lpfc_iocbq *abtsiocb; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11594 | struct lpfc_sli_ring *pring_s4; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11595 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11596 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11597 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11598 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11599 | /* all I/Os are in process of being flushed */ |
| 11600 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) |
| 11601 | return errcnt; |
| 11602 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11603 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11604 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11605 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11606 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11607 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11608 | continue; |
| 11609 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11610 | /* |
| 11611 | * If the iocbq is already being aborted, don't take a second |
| 11612 | * action, but do count it. |
| 11613 | */ |
| 11614 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11615 | continue; |
| 11616 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11617 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11618 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11619 | if (abtsiocb == NULL) { |
| 11620 | errcnt++; |
| 11621 | continue; |
| 11622 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11623 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11624 | /* indicate the IO is being aborted by the driver. */ |
| 11625 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11626 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11627 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11628 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11629 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11630 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11631 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 11632 | else |
| 11633 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11634 | abtsiocb->iocb.ulpLe = 1; |
| 11635 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11636 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11637 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11638 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11639 | abtsiocb->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11640 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11641 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11642 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11643 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11644 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11645 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11646 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11647 | else |
| 11648 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11649 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11650 | /* Setup callback routine and issue the command. */ |
| 11651 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11652 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11653 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11654 | if (!pring_s4) |
| 11655 | continue; |
| 11656 | ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11657 | abtsiocb, 0); |
| 11658 | } else |
| 11659 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11660 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11661 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11662 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11663 | errcnt++; |
| 11664 | continue; |
| 11665 | } |
| 11666 | } |
| 11667 | |
| 11668 | return errcnt; |
| 11669 | } |
| 11670 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11671 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11672 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 11673 | * @vport: Pointer to virtual port. |
| 11674 | * @pring: Pointer to driver SLI ring object. |
| 11675 | * @tgt_id: SCSI ID of the target. |
| 11676 | * @lun_id: LUN ID of the scsi device. |
| 11677 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11678 | * |
| 11679 | * This function sends an abort command for every SCSI command |
| 11680 | * associated with the given virtual port pending on the ring |
| 11681 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11682 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11683 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11684 | * parameters |
| 11685 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11686 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11687 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11688 | * FCP iocbs associated with virtual port. |
| 11689 | * This function returns number of iocbs it aborted . |
| 11690 | * This function is called with no locks held right after a taskmgmt |
| 11691 | * command is sent. |
| 11692 | **/ |
| 11693 | int |
| 11694 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11695 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 11696 | { |
| 11697 | struct lpfc_hba *phba = vport->phba; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11698 | struct lpfc_scsi_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11699 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11700 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11701 | struct lpfc_iocbq *iocbq; |
| 11702 | IOCB_t *icmd; |
| 11703 | int sum, i, ret_val; |
| 11704 | unsigned long iflags; |
| 11705 | struct lpfc_sli_ring *pring_s4; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11706 | |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11707 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11708 | |
| 11709 | /* all I/Os are in process of being flushed */ |
| 11710 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11711 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11712 | return 0; |
| 11713 | } |
| 11714 | sum = 0; |
| 11715 | |
| 11716 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11717 | iocbq = phba->sli.iocbq_lookup[i]; |
| 11718 | |
| 11719 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 11720 | cmd) != 0) |
| 11721 | continue; |
| 11722 | |
| 11723 | /* |
| 11724 | * If the iocbq is already being aborted, don't take a second |
| 11725 | * action, but do count it. |
| 11726 | */ |
| 11727 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11728 | continue; |
| 11729 | |
| 11730 | /* issue ABTS for this IOCB based on iotag */ |
| 11731 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
| 11732 | if (abtsiocbq == NULL) |
| 11733 | continue; |
| 11734 | |
| 11735 | icmd = &iocbq->iocb; |
| 11736 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11737 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 11738 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11739 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 11740 | iocbq->sli4_xritag; |
| 11741 | else |
| 11742 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 11743 | abtsiocbq->iocb.ulpLe = 1; |
| 11744 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 11745 | abtsiocbq->vport = vport; |
| 11746 | |
| 11747 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11748 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11749 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11750 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11751 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11752 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11753 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11754 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 11755 | ndlp = lpfc_cmd->rdata->pnode; |
| 11756 | |
| 11757 | if (lpfc_is_link_up(phba) && |
| 11758 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11759 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11760 | else |
| 11761 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11762 | |
| 11763 | /* Setup callback routine and issue the command. */ |
| 11764 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 11765 | |
| 11766 | /* |
| 11767 | * Indicate the IO is being aborted by the driver and set |
| 11768 | * the caller's flag into the aborted IO. |
| 11769 | */ |
| 11770 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11771 | |
| 11772 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11773 | pring_s4 = lpfc_sli4_calc_ring(phba, abtsiocbq); |
| 11774 | if (!pring_s4) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11775 | continue; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11776 | /* Note: both hbalock and ring_lock must be set here */ |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11777 | spin_lock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11778 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11779 | abtsiocbq, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11780 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11781 | } else { |
| 11782 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11783 | abtsiocbq, 0); |
| 11784 | } |
| 11785 | |
| 11786 | |
| 11787 | if (ret_val == IOCB_ERROR) |
| 11788 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 11789 | else |
| 11790 | sum++; |
| 11791 | } |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11792 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11793 | return sum; |
| 11794 | } |
| 11795 | |
| 11796 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11797 | * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11798 | * @phba: Pointer to HBA context object. |
| 11799 | * @cmdiocbq: Pointer to command iocb. |
| 11800 | * @rspiocbq: Pointer to response iocb. |
| 11801 | * |
| 11802 | * This function is the completion handler for iocbs issued using |
| 11803 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 11804 | * ring event handler function without any lock held. This function |
| 11805 | * can be called from both worker thread context and interrupt |
| 11806 | * context. This function also can be called from other thread which |
| 11807 | * cleans up the SLI layer objects. |
| 11808 | * This function copy the contents of the response iocb to the |
| 11809 | * response iocb memory object provided by the caller of |
| 11810 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 11811 | * sleeps for the iocb completion. |
| 11812 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11813 | static void |
| 11814 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 11815 | struct lpfc_iocbq *cmdiocbq, |
| 11816 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11817 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11818 | wait_queue_head_t *pdone_q; |
| 11819 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11820 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11821 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11822 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11823 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 11824 | |
| 11825 | /* |
| 11826 | * A time out has occurred for the iocb. If a time out |
| 11827 | * completion handler has been supplied, call it. Otherwise, |
| 11828 | * just free the iocbq. |
| 11829 | */ |
| 11830 | |
| 11831 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11832 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 11833 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 11834 | if (cmdiocbq->iocb_cmpl) |
| 11835 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 11836 | else |
| 11837 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 11838 | return; |
| 11839 | } |
| 11840 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11841 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 11842 | if (cmdiocbq->context2 && rspiocbq) |
| 11843 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 11844 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 11845 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11846 | /* Set the exchange busy flag for task management commands */ |
| 11847 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 11848 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 11849 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 11850 | cur_iocbq); |
| 11851 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 11852 | } |
| 11853 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11854 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11855 | if (pdone_q) |
| 11856 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11857 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11858 | return; |
| 11859 | } |
| 11860 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11861 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11862 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 11863 | * @phba: Pointer to HBA context object.. |
| 11864 | * @piocbq: Pointer to command iocb. |
| 11865 | * @flag: Flag to test. |
| 11866 | * |
| 11867 | * This routine grabs the hbalock and then test the iocb_flag to |
| 11868 | * see if the passed in flag is set. |
| 11869 | * Returns: |
| 11870 | * 1 if flag is set. |
| 11871 | * 0 if flag is not set. |
| 11872 | **/ |
| 11873 | static int |
| 11874 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 11875 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 11876 | { |
| 11877 | unsigned long iflags; |
| 11878 | int ret; |
| 11879 | |
| 11880 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11881 | ret = piocbq->iocb_flag & flag; |
| 11882 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11883 | return ret; |
| 11884 | |
| 11885 | } |
| 11886 | |
| 11887 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11888 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11889 | * @phba: Pointer to HBA context object.. |
| 11890 | * @pring: Pointer to sli ring. |
| 11891 | * @piocb: Pointer to command iocb. |
| 11892 | * @prspiocbq: Pointer to response iocb. |
| 11893 | * @timeout: Timeout in number of seconds. |
| 11894 | * |
| 11895 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11896 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 11897 | * to handle iocbs which time out. If the field is NULL, the |
| 11898 | * function shall free the iocbq structure. If more clean up is |
| 11899 | * needed, the caller is expected to provide a completion function |
| 11900 | * that will provide the needed clean up. If the iocb command is |
| 11901 | * not completed within timeout seconds, the function will either |
| 11902 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 11903 | * completion function set in the iocb_cmpl field and then return |
| 11904 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 11905 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11906 | * The function waits for the iocb completion using an |
| 11907 | * non-interruptible wait. |
| 11908 | * This function will sleep while waiting for iocb completion. |
| 11909 | * So, this function should not be called from any context which |
| 11910 | * does not allow sleeping. Due to the same reason, this function |
| 11911 | * cannot be called with interrupt disabled. |
| 11912 | * This function assumes that the iocb completions occur while |
| 11913 | * this function sleep. So, this function cannot be called from |
| 11914 | * the thread which process iocb completion for this ring. |
| 11915 | * This function clears the iocb_flag of the iocb object before |
| 11916 | * issuing the iocb and the iocb completion handler sets this |
| 11917 | * flag and wakes this thread when the iocb completes. |
| 11918 | * The contents of the response iocb will be copied to prspiocbq |
| 11919 | * by the completion handler when the command completes. |
| 11920 | * This function returns IOCB_SUCCESS when success. |
| 11921 | * This function is called with no lock held. |
| 11922 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11923 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11924 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11925 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11926 | struct lpfc_iocbq *piocb, |
| 11927 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11928 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11929 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 11930 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11931 | long timeleft, timeout_req = 0; |
| 11932 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11933 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11934 | struct lpfc_iocbq *iocb; |
| 11935 | int txq_cnt = 0; |
| 11936 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11937 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11938 | unsigned long iflags; |
| 11939 | bool iocb_completed = true; |
| 11940 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11941 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 11942 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 11943 | else |
| 11944 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11945 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11946 | * If the caller has provided a response iocbq buffer, then context2 |
| 11947 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11948 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11949 | if (prspiocbq) { |
| 11950 | if (piocb->context2) |
| 11951 | return IOCB_ERROR; |
| 11952 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11953 | } |
| 11954 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11955 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11956 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 11957 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11958 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11959 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11960 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11961 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11962 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11963 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 11964 | writel(creg_val, phba->HCregaddr); |
| 11965 | readl(phba->HCregaddr); /* flush */ |
| 11966 | } |
| 11967 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11968 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 11969 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11970 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 11971 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11972 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11973 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11974 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11975 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11976 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11977 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11978 | /* |
| 11979 | * IOCB timed out. Inform the wake iocb wait |
| 11980 | * completion function and set local status |
| 11981 | */ |
| 11982 | |
| 11983 | iocb_completed = false; |
| 11984 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 11985 | } |
| 11986 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11987 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11988 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11989 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 11990 | /* Note: we are not indicating if the IOCB has a success |
| 11991 | * status or not - that's for the caller to check. |
| 11992 | * IOCB_SUCCESS means just that the command was sent and |
| 11993 | * completed. Not that it completed successfully. |
| 11994 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11995 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11996 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11997 | "0338 IOCB wait timeout error - no " |
| 11998 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11999 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12000 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12001 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12002 | "0330 IOCB wake NOT set, " |
| 12003 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12004 | timeout, (timeleft / jiffies)); |
| 12005 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12006 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12007 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12008 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 12009 | list_for_each_entry(iocb, &pring->txq, list) { |
| 12010 | txq_cnt++; |
| 12011 | } |
| 12012 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 12013 | txcmplq_cnt++; |
| 12014 | } |
| 12015 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 12016 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 12017 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 12018 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12019 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12020 | } else { |
| 12021 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12022 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12023 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12024 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12025 | } |
| 12026 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12027 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12028 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 12029 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12030 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 12031 | writel(creg_val, phba->HCregaddr); |
| 12032 | readl(phba->HCregaddr); /* flush */ |
| 12033 | } |
| 12034 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12035 | if (prspiocbq) |
| 12036 | piocb->context2 = NULL; |
| 12037 | |
| 12038 | piocb->context_un.wait_queue = NULL; |
| 12039 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12040 | return retval; |
| 12041 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12042 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12043 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12044 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12045 | * @phba: Pointer to HBA context object. |
| 12046 | * @pmboxq: Pointer to driver mailbox object. |
| 12047 | * @timeout: Timeout in number of seconds. |
| 12048 | * |
| 12049 | * This function issues the mailbox to firmware and waits for the |
| 12050 | * mailbox command to complete. If the mailbox command is not |
| 12051 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 12052 | * The function waits for the mailbox completion using an |
| 12053 | * interruptible wait. If the thread is woken up due to a |
| 12054 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 12055 | * should not free the mailbox resources, if this function returns |
| 12056 | * MBX_TIMEOUT. |
| 12057 | * This function will sleep while waiting for mailbox completion. |
| 12058 | * So, this function should not be called from any context which |
| 12059 | * does not allow sleeping. Due to the same reason, this function |
| 12060 | * cannot be called with interrupt disabled. |
| 12061 | * This function assumes that the mailbox completion occurs while |
| 12062 | * this function sleep. So, this function cannot be called from |
| 12063 | * the worker thread which processes mailbox completion. |
| 12064 | * This function is called in the context of HBA management |
| 12065 | * applications. |
| 12066 | * This function returns MBX_SUCCESS when successful. |
| 12067 | * This function is called with no lock held. |
| 12068 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12069 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12070 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12071 | uint32_t timeout) |
| 12072 | { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12073 | struct completion mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12074 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12075 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12076 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 12077 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12078 | /* setup wake call as IOCB callback */ |
| 12079 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12080 | |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12081 | /* setup context3 field to pass wait_queue pointer to wake function */ |
| 12082 | init_completion(&mbox_done); |
| 12083 | pmboxq->context3 = &mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12084 | /* now issue the command */ |
| 12085 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12086 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12087 | wait_for_completion_timeout(&mbox_done, |
| 12088 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12089 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12090 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12091 | pmboxq->context3 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12092 | /* |
| 12093 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 12094 | * else do not free the resources. |
| 12095 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12096 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12097 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12098 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12099 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12100 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12101 | } |
| 12102 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12103 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12104 | return retval; |
| 12105 | } |
| 12106 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12107 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12108 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12109 | * @phba: Pointer to HBA context. |
| 12110 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12111 | * This function is called to shutdown the driver's mailbox sub-system. |
| 12112 | * It first marks the mailbox sub-system is in a block state to prevent |
| 12113 | * the asynchronous mailbox command from issued off the pending mailbox |
| 12114 | * command queue. If the mailbox command sub-system shutdown is due to |
| 12115 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 12116 | * the mailbox sub-system flush routine to forcefully bring down the |
| 12117 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 12118 | * as with offline or HBA function reset), this routine will wait for the |
| 12119 | * outstanding mailbox command to complete before invoking the mailbox |
| 12120 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12121 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12122 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12123 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12124 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12125 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12126 | unsigned long timeout; |
| 12127 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12128 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 12129 | /* delay 100ms for port state */ |
| 12130 | msleep(100); |
| 12131 | lpfc_sli_mbox_sys_flush(phba); |
| 12132 | return; |
| 12133 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12134 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12135 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12136 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 12137 | local_bh_disable(); |
| 12138 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12139 | spin_lock_irq(&phba->hbalock); |
| 12140 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12141 | |
| 12142 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12143 | /* Determine how long we might wait for the active mailbox |
| 12144 | * command to be gracefully completed by firmware. |
| 12145 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12146 | if (phba->sli.mbox_active) |
| 12147 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 12148 | phba->sli.mbox_active) * |
| 12149 | 1000) + jiffies; |
| 12150 | spin_unlock_irq(&phba->hbalock); |
| 12151 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12152 | /* Enable softirqs again, done with phba->hbalock */ |
| 12153 | local_bh_enable(); |
| 12154 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12155 | while (phba->sli.mbox_active) { |
| 12156 | /* Check active mailbox complete status every 2ms */ |
| 12157 | msleep(2); |
| 12158 | if (time_after(jiffies, timeout)) |
| 12159 | /* Timeout, let the mailbox flush routine to |
| 12160 | * forcefully release active mailbox command |
| 12161 | */ |
| 12162 | break; |
| 12163 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12164 | } else { |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12165 | spin_unlock_irq(&phba->hbalock); |
| 12166 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12167 | /* Enable softirqs again, done with phba->hbalock */ |
| 12168 | local_bh_enable(); |
| 12169 | } |
| 12170 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12171 | lpfc_sli_mbox_sys_flush(phba); |
| 12172 | } |
| 12173 | |
| 12174 | /** |
| 12175 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 12176 | * @phba: Pointer to HBA context. |
| 12177 | * |
| 12178 | * This function is called to read the SLI3 device error attention registers |
| 12179 | * for possible error attention events. The caller must hold the hostlock |
| 12180 | * with spin_lock_irq(). |
| 12181 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12182 | * This function returns 1 when there is Error Attention in the Host Attention |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12183 | * Register and returns 0 otherwise. |
| 12184 | **/ |
| 12185 | static int |
| 12186 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 12187 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 12188 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12189 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12190 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12191 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12192 | goto unplug_err; |
| 12193 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12194 | if (ha_copy & HA_ERATT) { |
| 12195 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12196 | if (lpfc_sli_read_hs(phba)) |
| 12197 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12198 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12199 | /* Check if there is a deferred error condition is active */ |
| 12200 | if ((HS_FFER1 & phba->work_hs) && |
| 12201 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12202 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12203 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12204 | /* Clear all interrupt enable conditions */ |
| 12205 | writel(0, phba->HCregaddr); |
| 12206 | readl(phba->HCregaddr); |
| 12207 | } |
| 12208 | |
| 12209 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12210 | phba->work_ha |= HA_ERATT; |
| 12211 | /* Indicate polling handles this ERATT */ |
| 12212 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12213 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12214 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12215 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12216 | |
| 12217 | unplug_err: |
| 12218 | /* Set the driver HS work bitmap */ |
| 12219 | phba->work_hs |= UNPLUG_ERR; |
| 12220 | /* Set the driver HA work bitmap */ |
| 12221 | phba->work_ha |= HA_ERATT; |
| 12222 | /* Indicate polling handles this ERATT */ |
| 12223 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12224 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12225 | } |
| 12226 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12227 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12228 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 12229 | * @phba: Pointer to HBA context. |
| 12230 | * |
| 12231 | * This function is called to read the SLI4 device error attention registers |
| 12232 | * for possible error attention events. The caller must hold the hostlock |
| 12233 | * with spin_lock_irq(). |
| 12234 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12235 | * This function returns 1 when there is Error Attention in the Host Attention |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12236 | * Register and returns 0 otherwise. |
| 12237 | **/ |
| 12238 | static int |
| 12239 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 12240 | { |
| 12241 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12242 | uint32_t if_type, portsmphr; |
| 12243 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12244 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12245 | /* |
| 12246 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12247 | * registers for error attention. This can be changed later. |
| 12248 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12249 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 12250 | switch (if_type) { |
| 12251 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12252 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 12253 | &uerr_sta_lo) || |
| 12254 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 12255 | &uerr_sta_hi)) { |
| 12256 | phba->work_hs |= UNPLUG_ERR; |
| 12257 | phba->work_ha |= HA_ERATT; |
| 12258 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12259 | return 1; |
| 12260 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12261 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 12262 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 12263 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12264 | "1423 HBA Unrecoverable error: " |
| 12265 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 12266 | "ue_mask_lo_reg=0x%x, " |
| 12267 | "ue_mask_hi_reg=0x%x\n", |
| 12268 | uerr_sta_lo, uerr_sta_hi, |
| 12269 | phba->sli4_hba.ue_mask_lo, |
| 12270 | phba->sli4_hba.ue_mask_hi); |
| 12271 | phba->work_status[0] = uerr_sta_lo; |
| 12272 | phba->work_status[1] = uerr_sta_hi; |
| 12273 | phba->work_ha |= HA_ERATT; |
| 12274 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12275 | return 1; |
| 12276 | } |
| 12277 | break; |
| 12278 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 12279 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12280 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 12281 | &portstat_reg.word0) || |
| 12282 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 12283 | &portsmphr)){ |
| 12284 | phba->work_hs |= UNPLUG_ERR; |
| 12285 | phba->work_ha |= HA_ERATT; |
| 12286 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12287 | return 1; |
| 12288 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12289 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 12290 | phba->work_status[0] = |
| 12291 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 12292 | phba->work_status[1] = |
| 12293 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 12294 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12295 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12296 | "port status reg 0x%x, " |
| 12297 | "port smphr reg 0x%x, " |
| 12298 | "error 1=0x%x, error 2=0x%x\n", |
| 12299 | portstat_reg.word0, |
| 12300 | portsmphr, |
| 12301 | phba->work_status[0], |
| 12302 | phba->work_status[1]); |
| 12303 | phba->work_ha |= HA_ERATT; |
| 12304 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12305 | return 1; |
| 12306 | } |
| 12307 | break; |
| 12308 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 12309 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12310 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12311 | "2886 HBA Error Attention on unsupported " |
| 12312 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12313 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12314 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12315 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12316 | return 0; |
| 12317 | } |
| 12318 | |
| 12319 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12320 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12321 | * @phba: Pointer to HBA context. |
| 12322 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12323 | * This function is called from timer soft interrupt context to check HBA's |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12324 | * error attention register bit for error attention events. |
| 12325 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12326 | * This function returns 1 when there is Error Attention in the Host Attention |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12327 | * Register and returns 0 otherwise. |
| 12328 | **/ |
| 12329 | int |
| 12330 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 12331 | { |
| 12332 | uint32_t ha_copy; |
| 12333 | |
| 12334 | /* If somebody is waiting to handle an eratt, don't process it |
| 12335 | * here. The brdkill function will do this. |
| 12336 | */ |
| 12337 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12338 | return 0; |
| 12339 | |
| 12340 | /* Check if interrupt handler handles this ERATT */ |
| 12341 | spin_lock_irq(&phba->hbalock); |
| 12342 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 12343 | /* Interrupt handler has handled ERATT */ |
| 12344 | spin_unlock_irq(&phba->hbalock); |
| 12345 | return 0; |
| 12346 | } |
| 12347 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12348 | /* |
| 12349 | * If there is deferred error attention, do not check for error |
| 12350 | * attention |
| 12351 | */ |
| 12352 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 12353 | spin_unlock_irq(&phba->hbalock); |
| 12354 | return 0; |
| 12355 | } |
| 12356 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12357 | /* If PCI channel is offline, don't process it */ |
| 12358 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12359 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12360 | return 0; |
| 12361 | } |
| 12362 | |
| 12363 | switch (phba->sli_rev) { |
| 12364 | case LPFC_SLI_REV2: |
| 12365 | case LPFC_SLI_REV3: |
| 12366 | /* Read chip Host Attention (HA) register */ |
| 12367 | ha_copy = lpfc_sli_eratt_read(phba); |
| 12368 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12369 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12370 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12371 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 12372 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12373 | default: |
| 12374 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12375 | "0299 Invalid SLI revision (%d)\n", |
| 12376 | phba->sli_rev); |
| 12377 | ha_copy = 0; |
| 12378 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12379 | } |
| 12380 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12381 | |
| 12382 | return ha_copy; |
| 12383 | } |
| 12384 | |
| 12385 | /** |
| 12386 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 12387 | * @phba: Pointer to HBA context. |
| 12388 | * |
| 12389 | * This inline routine checks whether a device or its PCI slot is in a state |
| 12390 | * that the interrupt should be handled. |
| 12391 | * |
| 12392 | * This function returns 0 if the device or the PCI slot is in a state that |
| 12393 | * interrupt should be handled, otherwise -EIO. |
| 12394 | */ |
| 12395 | static inline int |
| 12396 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 12397 | { |
| 12398 | /* If the pci channel is offline, ignore all the interrupts */ |
| 12399 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 12400 | return -EIO; |
| 12401 | |
| 12402 | /* Update device level interrupt statistics */ |
| 12403 | phba->sli.slistat.sli_intr++; |
| 12404 | |
| 12405 | /* Ignore all interrupts during initialization. */ |
| 12406 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 12407 | return -EIO; |
| 12408 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12409 | return 0; |
| 12410 | } |
| 12411 | |
| 12412 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12413 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12414 | * @irq: Interrupt number. |
| 12415 | * @dev_id: The device context pointer. |
| 12416 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12417 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12418 | * service routine when device with SLI-3 interface spec is enabled with |
| 12419 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 12420 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 12421 | * interrupt mode, this function is called as part of the device-level |
| 12422 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 12423 | * is undergoing initialization, the interrupt handler will not process |
| 12424 | * the interrupt. The link attention and ELS ring attention events are |
| 12425 | * handled by the worker thread. The interrupt handler signals the worker |
| 12426 | * thread and returns for these events. This function is called without |
| 12427 | * any lock held. It gets the hbalock to access and update SLI data |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12428 | * structures. |
| 12429 | * |
| 12430 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12431 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12432 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12433 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12434 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12435 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12436 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12437 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12438 | uint32_t work_ha_copy; |
| 12439 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12440 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12441 | uint32_t control; |
| 12442 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12443 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12444 | struct lpfc_vport *vport; |
| 12445 | struct lpfc_nodelist *ndlp; |
| 12446 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12447 | LPFC_MBOXQ_t *pmb; |
| 12448 | int rc; |
| 12449 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12450 | /* |
| 12451 | * Get the driver's phba structure from the dev_id and |
| 12452 | * assume the HBA is not interrupting. |
| 12453 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12454 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12455 | |
| 12456 | if (unlikely(!phba)) |
| 12457 | return IRQ_NONE; |
| 12458 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12459 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12460 | * Stuff needs to be attented to when this function is invoked as an |
| 12461 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12462 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12463 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12464 | /* Check device state for handling interrupt */ |
| 12465 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12466 | return IRQ_NONE; |
| 12467 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12468 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12469 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12470 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12471 | /* If somebody is waiting to handle an eratt don't process it |
| 12472 | * here. The brdkill function will do this. |
| 12473 | */ |
| 12474 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12475 | ha_copy &= ~HA_ERATT; |
| 12476 | /* Check the need for handling ERATT in interrupt handler */ |
| 12477 | if (ha_copy & HA_ERATT) { |
| 12478 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12479 | /* ERATT polling has handled ERATT */ |
| 12480 | ha_copy &= ~HA_ERATT; |
| 12481 | else |
| 12482 | /* Indicate interrupt handler handles ERATT */ |
| 12483 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12484 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12485 | |
| 12486 | /* |
| 12487 | * If there is deferred error attention, do not check for any |
| 12488 | * interrupt. |
| 12489 | */ |
| 12490 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12491 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12492 | return IRQ_NONE; |
| 12493 | } |
| 12494 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12495 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12496 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 12497 | goto unplug_error; |
| 12498 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12499 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 12500 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12501 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12502 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 12503 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12504 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12505 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12506 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12507 | } else |
| 12508 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12509 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12510 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 12511 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12512 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12513 | if (work_ha_copy & HA_LATT) { |
| 12514 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 12515 | /* |
| 12516 | * Turn off Link Attention interrupts |
| 12517 | * until CLEAR_LA done |
| 12518 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12519 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12520 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12521 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12522 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12523 | control &= ~HC_LAINT_ENA; |
| 12524 | writel(control, phba->HCregaddr); |
| 12525 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12526 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12527 | } |
| 12528 | else |
| 12529 | work_ha_copy &= ~HA_LATT; |
| 12530 | } |
| 12531 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12532 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12533 | /* |
| 12534 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 12535 | * the only slow ring. |
| 12536 | */ |
| 12537 | status = (work_ha_copy & |
| 12538 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12539 | status >>= (4*LPFC_ELS_RING); |
| 12540 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12541 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12542 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12543 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12544 | |
| 12545 | lpfc_debugfs_slow_ring_trc(phba, |
| 12546 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 12547 | control, status, |
| 12548 | (uint32_t)phba->sli.slistat.sli_intr); |
| 12549 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12550 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12551 | lpfc_debugfs_slow_ring_trc(phba, |
| 12552 | "ISR Disable ring:" |
| 12553 | "pwork:x%x hawork:x%x wait:x%x", |
| 12554 | phba->work_ha, work_ha_copy, |
| 12555 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12556 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12557 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12558 | control &= |
| 12559 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12560 | writel(control, phba->HCregaddr); |
| 12561 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12562 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12563 | else { |
| 12564 | lpfc_debugfs_slow_ring_trc(phba, |
| 12565 | "ISR slow ring: pwork:" |
| 12566 | "x%x hawork:x%x wait:x%x", |
| 12567 | phba->work_ha, work_ha_copy, |
| 12568 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12569 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12570 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12571 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12572 | } |
| 12573 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12574 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12575 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12576 | if (lpfc_sli_read_hs(phba)) |
| 12577 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12578 | /* |
| 12579 | * Check if there is a deferred error condition |
| 12580 | * is active |
| 12581 | */ |
| 12582 | if ((HS_FFER1 & phba->work_hs) && |
| 12583 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12584 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 12585 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12586 | phba->hba_flag |= DEFER_ERATT; |
| 12587 | /* Clear all interrupt enable conditions */ |
| 12588 | writel(0, phba->HCregaddr); |
| 12589 | readl(phba->HCregaddr); |
| 12590 | } |
| 12591 | } |
| 12592 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12593 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12594 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12595 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12596 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12597 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12598 | |
| 12599 | /* First check out the status word */ |
| 12600 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 12601 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12602 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12603 | /* |
| 12604 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 12605 | * mbxStatus <status> |
| 12606 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12607 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12608 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12609 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12610 | "Interrupt mbxCommand x%x " |
| 12611 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12612 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12613 | pmbox->mbxCommand, |
| 12614 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12615 | /* clear mailbox attention bit */ |
| 12616 | work_ha_copy &= ~HA_MBATT; |
| 12617 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12618 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12619 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12620 | phba->last_completion_time = jiffies; |
| 12621 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12622 | if (pmb->mbox_cmpl) { |
| 12623 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 12624 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12625 | if (pmb->out_ext_byte_len && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12626 | pmb->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12627 | lpfc_sli_pcimem_bcopy( |
| 12628 | phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12629 | pmb->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12630 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12631 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12632 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12633 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12634 | |
| 12635 | lpfc_debugfs_disc_trc(vport, |
| 12636 | LPFC_DISC_TRC_MBOX_VPORT, |
| 12637 | "MBOX dflt rpi: : " |
| 12638 | "status:x%x rpi:x%x", |
| 12639 | (uint32_t)pmbox->mbxStatus, |
| 12640 | pmbox->un.varWords[0], 0); |
| 12641 | |
| 12642 | if (!pmbox->mbxStatus) { |
| 12643 | mp = (struct lpfc_dmabuf *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12644 | (pmb->ctx_buf); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12645 | ndlp = (struct lpfc_nodelist *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12646 | pmb->ctx_ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12647 | |
| 12648 | /* Reg_LOGIN of dflt RPI was |
| 12649 | * successful. new lets get |
| 12650 | * rid of the RPI using the |
| 12651 | * same mbox buffer. |
| 12652 | */ |
| 12653 | lpfc_unreg_login(phba, |
| 12654 | vport->vpi, |
| 12655 | pmbox->un.varWords[0], |
| 12656 | pmb); |
| 12657 | pmb->mbox_cmpl = |
| 12658 | lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12659 | pmb->ctx_buf = mp; |
| 12660 | pmb->ctx_ndlp = ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12661 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12662 | rc = lpfc_sli_issue_mbox(phba, |
| 12663 | pmb, |
| 12664 | MBX_NOWAIT); |
| 12665 | if (rc != MBX_BUSY) |
| 12666 | lpfc_printf_log(phba, |
| 12667 | KERN_ERR, |
| 12668 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12669 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12670 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12671 | if (rc != MBX_NOT_FINISHED) |
| 12672 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12673 | } |
| 12674 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12675 | spin_lock_irqsave( |
| 12676 | &phba->pport->work_port_lock, |
| 12677 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12678 | phba->pport->work_port_events &= |
| 12679 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12680 | spin_unlock_irqrestore( |
| 12681 | &phba->pport->work_port_lock, |
| 12682 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12683 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12684 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12685 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12686 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12687 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12688 | if ((work_ha_copy & HA_MBATT) && |
| 12689 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12690 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12691 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12692 | do { |
| 12693 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 12694 | MBX_NOWAIT); |
| 12695 | } while (rc == MBX_NOT_FINISHED); |
| 12696 | if (rc != MBX_SUCCESS) |
| 12697 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12698 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12699 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12700 | } |
| 12701 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12702 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12703 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12704 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12705 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12706 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12707 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12708 | unplug_error: |
| 12709 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12710 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12711 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12712 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12713 | |
| 12714 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12715 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12716 | * @irq: Interrupt number. |
| 12717 | * @dev_id: The device context pointer. |
| 12718 | * |
| 12719 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12720 | * service routine when device with SLI-3 interface spec is enabled with |
| 12721 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12722 | * ring event in the HBA. However, when the device is enabled with either |
| 12723 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12724 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12725 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12726 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12727 | * the intrrupt context. This function is called without any lock held. |
| 12728 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12729 | * |
| 12730 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12731 | * returns IRQ_NONE. |
| 12732 | **/ |
| 12733 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12734 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12735 | { |
| 12736 | struct lpfc_hba *phba; |
| 12737 | uint32_t ha_copy; |
| 12738 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12739 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12740 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12741 | |
| 12742 | /* Get the driver's phba structure from the dev_id and |
| 12743 | * assume the HBA is not interrupting. |
| 12744 | */ |
| 12745 | phba = (struct lpfc_hba *) dev_id; |
| 12746 | |
| 12747 | if (unlikely(!phba)) |
| 12748 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12749 | |
| 12750 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12751 | * Stuff needs to be attented to when this function is invoked as an |
| 12752 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12753 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12754 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12755 | /* Check device state for handling interrupt */ |
| 12756 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12757 | return IRQ_NONE; |
| 12758 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12759 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12760 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12761 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12762 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12763 | /* |
| 12764 | * If there is deferred error attention, do not check for |
| 12765 | * any interrupt. |
| 12766 | */ |
| 12767 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12768 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12769 | return IRQ_NONE; |
| 12770 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12771 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 12772 | phba->HAregaddr); |
| 12773 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12774 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12775 | } else |
| 12776 | ha_copy = phba->ha_copy; |
| 12777 | |
| 12778 | /* |
| 12779 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 12780 | */ |
| 12781 | ha_copy &= ~(phba->work_ha_mask); |
| 12782 | |
| 12783 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12784 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12785 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12786 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12787 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12788 | |
| 12789 | if (phba->cfg_multi_ring_support == 2) { |
| 12790 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12791 | * Process all events on extra ring. Take the optimized path |
| 12792 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12793 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12794 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12795 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12796 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12797 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12798 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12799 | status); |
| 12800 | } |
| 12801 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12802 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12803 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12804 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12805 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12806 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12807 | * @irq: Interrupt number. |
| 12808 | * @dev_id: The device context pointer. |
| 12809 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12810 | * This function is the HBA device-level interrupt handler to device with |
| 12811 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 12812 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 12813 | * requires driver attention. This function invokes the slow-path interrupt |
| 12814 | * attention handling function and fast-path interrupt attention handling |
| 12815 | * function in turn to process the relevant HBA attention events. This |
| 12816 | * function is called without any lock held. It gets the hbalock to access |
| 12817 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12818 | * |
| 12819 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12820 | * returns IRQ_NONE. |
| 12821 | **/ |
| 12822 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12823 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12824 | { |
| 12825 | struct lpfc_hba *phba; |
| 12826 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 12827 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12828 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12829 | |
| 12830 | /* |
| 12831 | * Get the driver's phba structure from the dev_id and |
| 12832 | * assume the HBA is not interrupting. |
| 12833 | */ |
| 12834 | phba = (struct lpfc_hba *) dev_id; |
| 12835 | |
| 12836 | if (unlikely(!phba)) |
| 12837 | return IRQ_NONE; |
| 12838 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12839 | /* Check device state for handling interrupt */ |
| 12840 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12841 | return IRQ_NONE; |
| 12842 | |
| 12843 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12844 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 12845 | spin_unlock(&phba->hbalock); |
| 12846 | return IRQ_HANDLED; |
| 12847 | } |
| 12848 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12849 | if (unlikely(!phba->ha_copy)) { |
| 12850 | spin_unlock(&phba->hbalock); |
| 12851 | return IRQ_NONE; |
| 12852 | } else if (phba->ha_copy & HA_ERATT) { |
| 12853 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12854 | /* ERATT polling has handled ERATT */ |
| 12855 | phba->ha_copy &= ~HA_ERATT; |
| 12856 | else |
| 12857 | /* Indicate interrupt handler handles ERATT */ |
| 12858 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12859 | } |
| 12860 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12861 | /* |
| 12862 | * If there is deferred error attention, do not check for any interrupt. |
| 12863 | */ |
| 12864 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 12865 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12866 | return IRQ_NONE; |
| 12867 | } |
| 12868 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12869 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12870 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 12871 | spin_unlock(&phba->hbalock); |
| 12872 | return IRQ_HANDLED; |
| 12873 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12874 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 12875 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12876 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12877 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12878 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12879 | readl(phba->HAregaddr); /* flush */ |
| 12880 | spin_unlock(&phba->hbalock); |
| 12881 | |
| 12882 | /* |
| 12883 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 12884 | */ |
| 12885 | |
| 12886 | /* status of events with mailbox and link attention */ |
| 12887 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 12888 | |
| 12889 | /* status of events with ELS ring */ |
| 12890 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12891 | status2 >>= (4*LPFC_ELS_RING); |
| 12892 | |
| 12893 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12894 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12895 | else |
| 12896 | sp_irq_rc = IRQ_NONE; |
| 12897 | |
| 12898 | /* |
| 12899 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12900 | */ |
| 12901 | |
| 12902 | /* status of events with FCP ring */ |
| 12903 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 12904 | status1 >>= (4*LPFC_FCP_RING); |
| 12905 | |
| 12906 | /* status of events with extra ring */ |
| 12907 | if (phba->cfg_multi_ring_support == 2) { |
| 12908 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 12909 | status2 >>= (4*LPFC_EXTRA_RING); |
| 12910 | } else |
| 12911 | status2 = 0; |
| 12912 | |
| 12913 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12914 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12915 | else |
| 12916 | fp_irq_rc = IRQ_NONE; |
| 12917 | |
| 12918 | /* Return device-level interrupt handling status */ |
| 12919 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12920 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12921 | |
| 12922 | /** |
| 12923 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 12924 | * @phba: pointer to lpfc hba data structure. |
| 12925 | * |
| 12926 | * This routine is invoked by the worker thread to process all the pending |
| 12927 | * SLI4 FCP abort XRI events. |
| 12928 | **/ |
| 12929 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12930 | { |
| 12931 | struct lpfc_cq_event *cq_event; |
| 12932 | |
| 12933 | /* First, declare the fcp xri abort event has been handled */ |
| 12934 | spin_lock_irq(&phba->hbalock); |
| 12935 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 12936 | spin_unlock_irq(&phba->hbalock); |
| 12937 | /* Now, handle all the fcp xri abort events */ |
| 12938 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 12939 | /* Get the first event from the head of the event queue */ |
| 12940 | spin_lock_irq(&phba->hbalock); |
| 12941 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 12942 | cq_event, struct lpfc_cq_event, list); |
| 12943 | spin_unlock_irq(&phba->hbalock); |
| 12944 | /* Notify aborted XRI for FCP work queue */ |
| 12945 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12946 | /* Free the event processed back to the free pool */ |
| 12947 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12948 | } |
| 12949 | } |
| 12950 | |
| 12951 | /** |
| 12952 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 12953 | * @phba: pointer to lpfc hba data structure. |
| 12954 | * |
| 12955 | * This routine is invoked by the worker thread to process all the pending |
| 12956 | * SLI4 els abort xri events. |
| 12957 | **/ |
| 12958 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12959 | { |
| 12960 | struct lpfc_cq_event *cq_event; |
| 12961 | |
| 12962 | /* First, declare the els xri abort event has been handled */ |
| 12963 | spin_lock_irq(&phba->hbalock); |
| 12964 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 12965 | spin_unlock_irq(&phba->hbalock); |
| 12966 | /* Now, handle all the els xri abort events */ |
| 12967 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 12968 | /* Get the first event from the head of the event queue */ |
| 12969 | spin_lock_irq(&phba->hbalock); |
| 12970 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 12971 | cq_event, struct lpfc_cq_event, list); |
| 12972 | spin_unlock_irq(&phba->hbalock); |
| 12973 | /* Notify aborted XRI for ELS work queue */ |
| 12974 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12975 | /* Free the event processed back to the free pool */ |
| 12976 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12977 | } |
| 12978 | } |
| 12979 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12980 | /** |
| 12981 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 12982 | * @phba: pointer to lpfc hba data structure |
| 12983 | * @pIocbIn: pointer to the rspiocbq |
| 12984 | * @pIocbOut: pointer to the cmdiocbq |
| 12985 | * @wcqe: pointer to the complete wcqe |
| 12986 | * |
| 12987 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 12988 | * by copying all the IOCB fields from command iocbq and transferring the |
| 12989 | * completion status information from the complete wcqe. |
| 12990 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12991 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12992 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 12993 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12994 | struct lpfc_iocbq *pIocbOut, |
| 12995 | struct lpfc_wcqe_complete *wcqe) |
| 12996 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12997 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12998 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12999 | uint32_t status, max_response; |
| 13000 | struct lpfc_dmabuf *dmabuf; |
| 13001 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13002 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 13003 | |
| 13004 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 13005 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13006 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 13007 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 13008 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13009 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 13010 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 13011 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 13012 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 13013 | wcqe->total_data_placed; |
| 13014 | else |
| 13015 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 13016 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13017 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 13018 | switch (pIocbOut->iocb.ulpCommand) { |
| 13019 | case CMD_ELS_REQUEST64_CR: |
| 13020 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 13021 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 13022 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 13023 | max_response = bde.tus.f.bdeSize; |
| 13024 | break; |
| 13025 | case CMD_GEN_REQUEST64_CR: |
| 13026 | max_response = 0; |
| 13027 | if (!pIocbOut->context3) |
| 13028 | break; |
| 13029 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 13030 | sizeof(struct ulp_bde64); |
| 13031 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 13032 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 13033 | for (i = 0; i < numBdes; i++) { |
| 13034 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 13035 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 13036 | max_response += bde.tus.f.bdeSize; |
| 13037 | } |
| 13038 | break; |
| 13039 | default: |
| 13040 | max_response = wcqe->total_data_placed; |
| 13041 | break; |
| 13042 | } |
| 13043 | if (max_response < wcqe->total_data_placed) |
| 13044 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 13045 | else |
| 13046 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 13047 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 13048 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13049 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 13050 | /* Convert BG errors for completion status */ |
| 13051 | if (status == CQE_STATUS_DI_ERROR) { |
| 13052 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 13053 | |
| 13054 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 13055 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 13056 | else |
| 13057 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 13058 | |
| 13059 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 13060 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 13061 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13062 | BGS_GUARD_ERR_MASK; |
| 13063 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 13064 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13065 | BGS_APPTAG_ERR_MASK; |
| 13066 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 13067 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13068 | BGS_REFTAG_ERR_MASK; |
| 13069 | |
| 13070 | /* Check to see if there was any good data before the error */ |
| 13071 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 13072 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13073 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 13074 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 13075 | wcqe->total_data_placed; |
| 13076 | } |
| 13077 | |
| 13078 | /* |
| 13079 | * Set ALL the error bits to indicate we don't know what |
| 13080 | * type of error it is. |
| 13081 | */ |
| 13082 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 13083 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13084 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 13085 | BGS_GUARD_ERR_MASK); |
| 13086 | } |
| 13087 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13088 | /* Pick up HBA exchange busy condition */ |
| 13089 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 13090 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13091 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 13092 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13093 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13094 | } |
| 13095 | |
| 13096 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13097 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 13098 | * @phba: Pointer to HBA context object. |
| 13099 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13100 | * |
| 13101 | * This routine handles an ELS work-queue completion event and construct |
| 13102 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 13103 | * discovery engine to handle. |
| 13104 | * |
| 13105 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 13106 | **/ |
| 13107 | static struct lpfc_iocbq * |
| 13108 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 13109 | struct lpfc_iocbq *irspiocbq) |
| 13110 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13111 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13112 | struct lpfc_iocbq *cmdiocbq; |
| 13113 | struct lpfc_wcqe_complete *wcqe; |
| 13114 | unsigned long iflags; |
| 13115 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13116 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 13117 | if (unlikely(!pring)) |
| 13118 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13119 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13120 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13121 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13122 | pring->stats.iocb_event++; |
| 13123 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 13124 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13125 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13126 | if (unlikely(!cmdiocbq)) { |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13127 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13128 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13129 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13130 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 13131 | wcqe->word0, wcqe->total_data_placed, |
| 13132 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13133 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 13134 | return NULL; |
| 13135 | } |
| 13136 | |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13137 | /* Put the iocb back on the txcmplq */ |
| 13138 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 13139 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 13140 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13141 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13142 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13143 | |
| 13144 | return irspiocbq; |
| 13145 | } |
| 13146 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13147 | inline struct lpfc_cq_event * |
| 13148 | lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size) |
| 13149 | { |
| 13150 | struct lpfc_cq_event *cq_event; |
| 13151 | |
| 13152 | /* Allocate a new internal CQ_EVENT entry */ |
| 13153 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 13154 | if (!cq_event) { |
| 13155 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13156 | "0602 Failed to alloc CQ_EVENT entry\n"); |
| 13157 | return NULL; |
| 13158 | } |
| 13159 | |
| 13160 | /* Move the CQE into the event */ |
| 13161 | memcpy(&cq_event->cqe, entry, size); |
| 13162 | return cq_event; |
| 13163 | } |
| 13164 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13165 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13166 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 13167 | * @phba: Pointer to HBA context object. |
| 13168 | * @cqe: Pointer to mailbox completion queue entry. |
| 13169 | * |
| 13170 | * This routine process a mailbox completion queue entry with asynchrous |
| 13171 | * event. |
| 13172 | * |
| 13173 | * Return: true if work posted to worker thread, otherwise false. |
| 13174 | **/ |
| 13175 | static bool |
| 13176 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13177 | { |
| 13178 | struct lpfc_cq_event *cq_event; |
| 13179 | unsigned long iflags; |
| 13180 | |
| 13181 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13182 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 13183 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 13184 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 13185 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13186 | cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe)); |
| 13187 | if (!cq_event) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13188 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13189 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13190 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 13191 | /* Set the async event flag */ |
| 13192 | phba->hba_flag |= ASYNC_EVENT; |
| 13193 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13194 | |
| 13195 | return true; |
| 13196 | } |
| 13197 | |
| 13198 | /** |
| 13199 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 13200 | * @phba: Pointer to HBA context object. |
| 13201 | * @cqe: Pointer to mailbox completion queue entry. |
| 13202 | * |
| 13203 | * This routine process a mailbox completion queue entry with mailbox |
| 13204 | * completion event. |
| 13205 | * |
| 13206 | * Return: true if work posted to worker thread, otherwise false. |
| 13207 | **/ |
| 13208 | static bool |
| 13209 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13210 | { |
| 13211 | uint32_t mcqe_status; |
| 13212 | MAILBOX_t *mbox, *pmbox; |
| 13213 | struct lpfc_mqe *mqe; |
| 13214 | struct lpfc_vport *vport; |
| 13215 | struct lpfc_nodelist *ndlp; |
| 13216 | struct lpfc_dmabuf *mp; |
| 13217 | unsigned long iflags; |
| 13218 | LPFC_MBOXQ_t *pmb; |
| 13219 | bool workposted = false; |
| 13220 | int rc; |
| 13221 | |
| 13222 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 13223 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 13224 | goto out_no_mqe_complete; |
| 13225 | |
| 13226 | /* Get the reference to the active mbox command */ |
| 13227 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13228 | pmb = phba->sli.mbox_active; |
| 13229 | if (unlikely(!pmb)) { |
| 13230 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 13231 | "1832 No pending MBOX command to handle\n"); |
| 13232 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13233 | goto out_no_mqe_complete; |
| 13234 | } |
| 13235 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13236 | mqe = &pmb->u.mqe; |
| 13237 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 13238 | mbox = phba->mbox; |
| 13239 | vport = pmb->vport; |
| 13240 | |
| 13241 | /* Reset heartbeat timer */ |
| 13242 | phba->last_completion_time = jiffies; |
| 13243 | del_timer(&phba->sli.mbox_tmo); |
| 13244 | |
| 13245 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 13246 | if (pmb->mbox_cmpl && mbox) |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13247 | lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13248 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13249 | /* |
| 13250 | * For mcqe errors, conditionally move a modified error code to |
| 13251 | * the mbox so that the error will not be missed. |
| 13252 | */ |
| 13253 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 13254 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 13255 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 13256 | bf_set(lpfc_mqe_status, mqe, |
| 13257 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 13258 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13259 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 13260 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 13261 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 13262 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 13263 | mcqe_status, |
| 13264 | pmbox->un.varWords[0], 0); |
| 13265 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13266 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 13267 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13268 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 13269 | * RID of the PPI using the same mbox buffer. |
| 13270 | */ |
| 13271 | lpfc_unreg_login(phba, vport->vpi, |
| 13272 | pmbox->un.varWords[0], pmb); |
| 13273 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13274 | pmb->ctx_buf = mp; |
| 13275 | pmb->ctx_ndlp = ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13276 | pmb->vport = vport; |
| 13277 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 13278 | if (rc != MBX_BUSY) |
| 13279 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 13280 | LOG_SLI, "0385 rc should " |
| 13281 | "have been MBX_BUSY\n"); |
| 13282 | if (rc != MBX_NOT_FINISHED) |
| 13283 | goto send_current_mbox; |
| 13284 | } |
| 13285 | } |
| 13286 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 13287 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 13288 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 13289 | |
| 13290 | /* There is mailbox completion work to do */ |
| 13291 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13292 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 13293 | phba->work_ha |= HA_MBATT; |
| 13294 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13295 | workposted = true; |
| 13296 | |
| 13297 | send_current_mbox: |
| 13298 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13299 | /* Release the mailbox command posting token */ |
| 13300 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 13301 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 13302 | phba->sli.mbox_active = NULL; |
| 13303 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13304 | /* Wake up worker thread to post the next pending mailbox command */ |
| 13305 | lpfc_worker_wake_up(phba); |
| 13306 | out_no_mqe_complete: |
| 13307 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13308 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 13309 | return workposted; |
| 13310 | } |
| 13311 | |
| 13312 | /** |
| 13313 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 13314 | * @phba: Pointer to HBA context object. |
| 13315 | * @cqe: Pointer to mailbox completion queue entry. |
| 13316 | * |
| 13317 | * This routine process a mailbox completion queue entry, it invokes the |
| 13318 | * proper mailbox complete handling or asynchrous event handling routine |
| 13319 | * according to the MCQE's async bit. |
| 13320 | * |
| 13321 | * Return: true if work posted to worker thread, otherwise false. |
| 13322 | **/ |
| 13323 | static bool |
| 13324 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 13325 | { |
| 13326 | struct lpfc_mcqe mcqe; |
| 13327 | bool workposted; |
| 13328 | |
| 13329 | /* Copy the mailbox MCQE and convert endian order as needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13330 | lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13331 | |
| 13332 | /* Invoke the proper event handling routine */ |
| 13333 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 13334 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 13335 | else |
| 13336 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 13337 | return workposted; |
| 13338 | } |
| 13339 | |
| 13340 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13341 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 13342 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13343 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13344 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13345 | * |
| 13346 | * This routine handles an ELS work-queue completion event. |
| 13347 | * |
| 13348 | * Return: true if work posted to worker thread, otherwise false. |
| 13349 | **/ |
| 13350 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13351 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13352 | struct lpfc_wcqe_complete *wcqe) |
| 13353 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13354 | struct lpfc_iocbq *irspiocbq; |
| 13355 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13356 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13357 | int txq_cnt = 0; |
| 13358 | int txcmplq_cnt = 0; |
| 13359 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13360 | |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13361 | /* Check for response status */ |
| 13362 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13363 | /* Log the error status */ |
| 13364 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13365 | "0357 ELS CQE error: status=x%x: " |
| 13366 | "CQE: %08x %08x %08x %08x\n", |
| 13367 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 13368 | wcqe->word0, wcqe->total_data_placed, |
| 13369 | wcqe->parameter, wcqe->word3); |
| 13370 | } |
| 13371 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13372 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13373 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 13374 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13375 | if (!list_empty(&pring->txq)) |
| 13376 | txq_cnt++; |
| 13377 | if (!list_empty(&pring->txcmplq)) |
| 13378 | txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13379 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 13380 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 13381 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13382 | txq_cnt, phba->iocb_cnt, |
| 13383 | fcp_txcmplq_cnt, |
| 13384 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13385 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13386 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13387 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13388 | /* Save off the slow-path queue event for work thread to process */ |
| 13389 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13390 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13391 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13392 | &phba->sli4_hba.sp_queue_event); |
| 13393 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13394 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13395 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13396 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13397 | } |
| 13398 | |
| 13399 | /** |
| 13400 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 13401 | * @phba: Pointer to HBA context object. |
| 13402 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13403 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13404 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13405 | * proper WQ release routine to the slow-path WQ. |
| 13406 | **/ |
| 13407 | static void |
| 13408 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 13409 | struct lpfc_wcqe_release *wcqe) |
| 13410 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13411 | /* sanity check on queue memory */ |
| 13412 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 13413 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13414 | /* Check for the slow-path ELS work queue */ |
| 13415 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 13416 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 13417 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 13418 | else |
| 13419 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13420 | "2579 Slow-path wqe consume event carries " |
| 13421 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 13422 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 13423 | phba->sli4_hba.els_wq->queue_id); |
| 13424 | } |
| 13425 | |
| 13426 | /** |
| 13427 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 13428 | * @phba: Pointer to HBA context object. |
| 13429 | * @cq: Pointer to a WQ completion queue. |
| 13430 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13431 | * |
| 13432 | * This routine handles an XRI abort event. |
| 13433 | * |
| 13434 | * Return: true if work posted to worker thread, otherwise false. |
| 13435 | **/ |
| 13436 | static bool |
| 13437 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 13438 | struct lpfc_queue *cq, |
| 13439 | struct sli4_wcqe_xri_aborted *wcqe) |
| 13440 | { |
| 13441 | bool workposted = false; |
| 13442 | struct lpfc_cq_event *cq_event; |
| 13443 | unsigned long iflags; |
| 13444 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13445 | switch (cq->subtype) { |
| 13446 | case LPFC_FCP: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13447 | cq_event = lpfc_cq_event_setup( |
| 13448 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 13449 | if (!cq_event) |
| 13450 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13451 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13452 | list_add_tail(&cq_event->list, |
| 13453 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 13454 | /* Set the fcp xri abort event flag */ |
| 13455 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 13456 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13457 | workposted = true; |
| 13458 | break; |
James Smart | 422c4cb | 2017-11-20 16:00:32 -0800 | [diff] [blame] | 13459 | case LPFC_NVME_LS: /* NVME LS uses ELS resources */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13460 | case LPFC_ELS: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13461 | cq_event = lpfc_cq_event_setup( |
| 13462 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 13463 | if (!cq_event) |
| 13464 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13465 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13466 | list_add_tail(&cq_event->list, |
| 13467 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 13468 | /* Set the els xri abort event flag */ |
| 13469 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 13470 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13471 | workposted = true; |
| 13472 | break; |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13473 | case LPFC_NVME: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13474 | /* Notify aborted XRI for NVME work queue */ |
| 13475 | if (phba->nvmet_support) |
| 13476 | lpfc_sli4_nvmet_xri_aborted(phba, wcqe); |
| 13477 | else |
| 13478 | lpfc_sli4_nvme_xri_aborted(phba, wcqe); |
| 13479 | |
| 13480 | workposted = false; |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13481 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13482 | default: |
| 13483 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13484 | "0603 Invalid CQ subtype %d: " |
| 13485 | "%08x %08x %08x %08x\n", |
| 13486 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 13487 | wcqe->word2, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13488 | workposted = false; |
| 13489 | break; |
| 13490 | } |
| 13491 | return workposted; |
| 13492 | } |
| 13493 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13494 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 13495 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13496 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13497 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13498 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13499 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13500 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13501 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13502 | * |
| 13503 | * Return: true if work posted to worker thread, otherwise false. |
| 13504 | **/ |
| 13505 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13506 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 13507 | { |
| 13508 | bool workposted = false; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13509 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13510 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 13511 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13512 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13513 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13514 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13515 | unsigned long iflags; |
| 13516 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13517 | /* sanity check on queue memory */ |
| 13518 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13519 | return workposted; |
| 13520 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13521 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13522 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13523 | else |
| 13524 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13525 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13526 | goto out; |
| 13527 | |
| 13528 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13529 | switch (status) { |
| 13530 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13531 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13532 | "2537 Receive Frame Truncated!!\n"); |
| 13533 | case FC_STATUS_RQ_SUCCESS: |
| 13534 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13535 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13536 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 13537 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13538 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13539 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13540 | goto out; |
| 13541 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13542 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13543 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13544 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13545 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13546 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13547 | |
| 13548 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 13549 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 13550 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13551 | /* Handle MDS Loopback frames */ |
| 13552 | lpfc_sli4_handle_mds_loopback(phba->pport, dma_buf); |
| 13553 | break; |
| 13554 | } |
| 13555 | |
| 13556 | /* save off the frame for the work thread to process */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13557 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13558 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13559 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13560 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13561 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13562 | workposted = true; |
| 13563 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13564 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13565 | if (phba->nvmet_support) { |
| 13566 | tgtp = phba->targetport->private; |
| 13567 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13568 | "6402 RQE Error x%x, posted %d err_cnt " |
| 13569 | "%d: %x %x %x\n", |
| 13570 | status, hrq->RQ_buf_posted, |
| 13571 | hrq->RQ_no_posted_buf, |
| 13572 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13573 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13574 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13575 | } |
| 13576 | /* fallthrough */ |
| 13577 | |
| 13578 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13579 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13580 | /* Post more buffers if possible */ |
| 13581 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13582 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 13583 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13584 | workposted = true; |
| 13585 | break; |
| 13586 | } |
| 13587 | out: |
| 13588 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13589 | } |
| 13590 | |
| 13591 | /** |
| 13592 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 13593 | * @phba: Pointer to HBA context object. |
| 13594 | * @cq: Pointer to the completion queue. |
| 13595 | * @wcqe: Pointer to a completion queue entry. |
| 13596 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13597 | * This routine process a slow-path work-queue or receive queue completion queue |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13598 | * entry. |
| 13599 | * |
| 13600 | * Return: true if work posted to worker thread, otherwise false. |
| 13601 | **/ |
| 13602 | static bool |
| 13603 | lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13604 | struct lpfc_cqe *cqe) |
| 13605 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13606 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13607 | bool workposted = false; |
| 13608 | |
| 13609 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13610 | lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13611 | |
| 13612 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13613 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13614 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13615 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13616 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13617 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13618 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13619 | break; |
| 13620 | case CQE_CODE_RELEASE_WQE: |
| 13621 | /* Process the WQ release event */ |
| 13622 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13623 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13624 | break; |
| 13625 | case CQE_CODE_XRI_ABORTED: |
| 13626 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13627 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13628 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13629 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13630 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13631 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13632 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13633 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13634 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13635 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13636 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13637 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13638 | default: |
| 13639 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13640 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13641 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13642 | break; |
| 13643 | } |
| 13644 | return workposted; |
| 13645 | } |
| 13646 | |
| 13647 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13648 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 13649 | * @phba: Pointer to HBA context object. |
| 13650 | * @eqe: Pointer to fast-path event queue entry. |
| 13651 | * |
| 13652 | * This routine process a event queue entry from the slow-path event queue. |
| 13653 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13654 | * completion event on a completion queue, if not, an error shall be logged |
| 13655 | * and just return. Otherwise, it will get to the corresponding completion |
| 13656 | * queue and process all the entries on that completion queue, rearm the |
| 13657 | * completion queue, and then return. |
| 13658 | * |
| 13659 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13660 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13661 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13662 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13663 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13664 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13665 | uint16_t cqid; |
| 13666 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13667 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13668 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13669 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13670 | list_for_each_entry(childq, &speq->child_list, list) { |
| 13671 | if (childq->queue_id == cqid) { |
| 13672 | cq = childq; |
| 13673 | break; |
| 13674 | } |
| 13675 | } |
| 13676 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13677 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13678 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13679 | "0365 Slow-path CQ identifier " |
| 13680 | "(%d) does not exist\n", cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13681 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13682 | } |
| 13683 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13684 | /* Save EQ associated with this CQ */ |
| 13685 | cq->assoc_qp = speq; |
| 13686 | |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13687 | if (!queue_work(phba->wq, &cq->spwork)) |
| 13688 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13689 | "0390 Cannot schedule soft IRQ " |
| 13690 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 13691 | cqid, cq->queue_id, smp_processor_id()); |
| 13692 | } |
| 13693 | |
| 13694 | /** |
| 13695 | * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry |
| 13696 | * @phba: Pointer to HBA context object. |
| 13697 | * |
| 13698 | * This routine process a event queue entry from the slow-path event queue. |
| 13699 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13700 | * completion event on a completion queue, if not, an error shall be logged |
| 13701 | * and just return. Otherwise, it will get to the corresponding completion |
| 13702 | * queue and process all the entries on that completion queue, rearm the |
| 13703 | * completion queue, and then return. |
| 13704 | * |
| 13705 | **/ |
| 13706 | static void |
| 13707 | lpfc_sli4_sp_process_cq(struct work_struct *work) |
| 13708 | { |
| 13709 | struct lpfc_queue *cq = |
| 13710 | container_of(work, struct lpfc_queue, spwork); |
| 13711 | struct lpfc_hba *phba = cq->phba; |
| 13712 | struct lpfc_cqe *cqe; |
| 13713 | bool workposted = false; |
| 13714 | int ccount = 0; |
| 13715 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13716 | /* Process all the entries to the CQ */ |
| 13717 | switch (cq->type) { |
| 13718 | case LPFC_MCQ: |
| 13719 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 13720 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13721 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13722 | break; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13723 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13724 | } |
| 13725 | break; |
| 13726 | case LPFC_WCQ: |
| 13727 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13728 | if (cq->subtype == LPFC_FCP || |
| 13729 | cq->subtype == LPFC_NVME) { |
| 13730 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13731 | if (phba->ktime_on) |
| 13732 | cq->isr_timestamp = ktime_get_ns(); |
| 13733 | else |
| 13734 | cq->isr_timestamp = 0; |
| 13735 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13736 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 13737 | cqe); |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13738 | } else { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 13739 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 13740 | cqe); |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13741 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13742 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13743 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13744 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13745 | |
| 13746 | /* Track the max number of CQEs processed in 1 EQ */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13747 | if (ccount > cq->CQ_max_cqe) |
| 13748 | cq->CQ_max_cqe = ccount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13749 | break; |
| 13750 | default: |
| 13751 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13752 | "0370 Invalid completion queue type (%d)\n", |
| 13753 | cq->type); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13754 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13755 | } |
| 13756 | |
| 13757 | /* Catch the no cq entry condition, log an error */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13758 | if (unlikely(ccount == 0)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13759 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13760 | "0371 No entry from the CQ: identifier " |
| 13761 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 13762 | |
| 13763 | /* In any case, flash and re-arm the RCQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 13764 | phba->sli4_hba.sli4_cq_release(cq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13765 | |
| 13766 | /* wake up worker thread if there are works to be done */ |
| 13767 | if (workposted) |
| 13768 | lpfc_worker_wake_up(phba); |
| 13769 | } |
| 13770 | |
| 13771 | /** |
| 13772 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13773 | * @phba: Pointer to HBA context object. |
| 13774 | * @cq: Pointer to associated CQ |
| 13775 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13776 | * |
| 13777 | * This routine process a fast-path work queue completion entry from fast-path |
| 13778 | * event queue for FCP command response completion. |
| 13779 | **/ |
| 13780 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13781 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13782 | struct lpfc_wcqe_complete *wcqe) |
| 13783 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13784 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13785 | struct lpfc_iocbq *cmdiocbq; |
| 13786 | struct lpfc_iocbq irspiocbq; |
| 13787 | unsigned long iflags; |
| 13788 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13789 | /* Check for response status */ |
| 13790 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13791 | /* If resource errors reported from HBA, reduce queue |
| 13792 | * depth of the SCSI device. |
| 13793 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13794 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 13795 | IOSTAT_LOCAL_REJECT)) && |
| 13796 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 13797 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13798 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13799 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13800 | /* Log the error status */ |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13801 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13802 | "0373 FCP CQE error: status=x%x: " |
| 13803 | "CQE: %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13804 | bf_get(lpfc_wcqe_c_status, wcqe), |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13805 | wcqe->word0, wcqe->total_data_placed, |
| 13806 | wcqe->parameter, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13807 | } |
| 13808 | |
| 13809 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13810 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 13811 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13812 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13813 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13814 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13815 | if (unlikely(!cmdiocbq)) { |
| 13816 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13817 | "0374 FCP complete with no corresponding " |
| 13818 | "cmdiocb: iotag (%d)\n", |
| 13819 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13820 | return; |
| 13821 | } |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13822 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13823 | cmdiocbq->isr_timestamp = cq->isr_timestamp; |
| 13824 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13825 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 13826 | if (cmdiocbq->wqe_cmpl) { |
| 13827 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13828 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13829 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13830 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13831 | } |
| 13832 | |
| 13833 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 13834 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 13835 | return; |
| 13836 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13837 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13838 | "0375 FCP cmdiocb not callback function " |
| 13839 | "iotag: (%d)\n", |
| 13840 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13841 | return; |
| 13842 | } |
| 13843 | |
| 13844 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13845 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13846 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 13847 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13848 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13849 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13850 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13851 | } |
| 13852 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13853 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 13854 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 13855 | } |
| 13856 | |
| 13857 | /** |
| 13858 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 13859 | * @phba: Pointer to HBA context object. |
| 13860 | * @cq: Pointer to completion queue. |
| 13861 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13862 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13863 | * This routine handles an fast-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13864 | * proper WQ release routine to the slow-path WQ. |
| 13865 | **/ |
| 13866 | static void |
| 13867 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13868 | struct lpfc_wcqe_release *wcqe) |
| 13869 | { |
| 13870 | struct lpfc_queue *childwq; |
| 13871 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13872 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13873 | |
| 13874 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13875 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13876 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13877 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13878 | lpfc_sli4_wq_release(childwq, |
| 13879 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 13880 | if (childwq->q_flag & HBA_NVMET_WQFULL) |
| 13881 | lpfc_nvmet_wqfull_process(phba, childwq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13882 | wqid_matched = true; |
| 13883 | break; |
| 13884 | } |
| 13885 | } |
| 13886 | /* Report warning log message if no match found */ |
| 13887 | if (wqid_matched != true) |
| 13888 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13889 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13890 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13891 | } |
| 13892 | |
| 13893 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13894 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 13895 | * @phba: Pointer to HBA context object. |
| 13896 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 13897 | * |
| 13898 | * This routine process a receive-queue completion queue entry. |
| 13899 | * |
| 13900 | * Return: true if work posted to worker thread, otherwise false. |
| 13901 | **/ |
| 13902 | static bool |
| 13903 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13904 | struct lpfc_rcqe *rcqe) |
| 13905 | { |
| 13906 | bool workposted = false; |
| 13907 | struct lpfc_queue *hrq; |
| 13908 | struct lpfc_queue *drq; |
| 13909 | struct rqb_dmabuf *dma_buf; |
| 13910 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13911 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13912 | uint32_t status, rq_id; |
| 13913 | unsigned long iflags; |
| 13914 | uint32_t fctl, idx; |
| 13915 | |
| 13916 | if ((phba->nvmet_support == 0) || |
| 13917 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 13918 | return workposted; |
| 13919 | |
| 13920 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13921 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 13922 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 13923 | |
| 13924 | /* sanity check on queue memory */ |
| 13925 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13926 | return workposted; |
| 13927 | |
| 13928 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13929 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13930 | else |
| 13931 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13932 | |
| 13933 | if ((phba->nvmet_support == 0) || |
| 13934 | (rq_id != hrq->queue_id)) |
| 13935 | return workposted; |
| 13936 | |
| 13937 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13938 | switch (status) { |
| 13939 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13940 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13941 | "6126 Receive Frame Truncated!!\n"); |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 13942 | /* Drop thru */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13943 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13944 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13945 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13946 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 13947 | if (!dma_buf) { |
| 13948 | hrq->RQ_no_buf_found++; |
| 13949 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13950 | goto out; |
| 13951 | } |
| 13952 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13953 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13954 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13955 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13956 | |
| 13957 | /* Just some basic sanity checks on FCP Command frame */ |
| 13958 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
| 13959 | fc_hdr->fh_f_ctl[1] << 8 | |
| 13960 | fc_hdr->fh_f_ctl[2]); |
| 13961 | if (((fctl & |
| 13962 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 13963 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 13964 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 13965 | goto drop; |
| 13966 | |
| 13967 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
| 13968 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 13969 | lpfc_nvmet_unsol_fcp_event( |
Dick Kennedy | 66d7ce9 | 2017-08-23 16:55:42 -0700 | [diff] [blame] | 13970 | phba, idx, dma_buf, |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13971 | cq->isr_timestamp); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13972 | return false; |
| 13973 | } |
| 13974 | drop: |
| 13975 | lpfc_in_buf_free(phba, &dma_buf->dbuf); |
| 13976 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13977 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13978 | if (phba->nvmet_support) { |
| 13979 | tgtp = phba->targetport->private; |
| 13980 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13981 | "6401 RQE Error x%x, posted %d err_cnt " |
| 13982 | "%d: %x %x %x\n", |
| 13983 | status, hrq->RQ_buf_posted, |
| 13984 | hrq->RQ_no_posted_buf, |
| 13985 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13986 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13987 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13988 | } |
| 13989 | /* fallthrough */ |
| 13990 | |
| 13991 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13992 | hrq->RQ_no_posted_buf++; |
| 13993 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13994 | break; |
| 13995 | } |
| 13996 | out: |
| 13997 | return workposted; |
| 13998 | } |
| 13999 | |
| 14000 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14001 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14002 | * @cq: Pointer to the completion queue. |
| 14003 | * @eqe: Pointer to fast-path completion queue entry. |
| 14004 | * |
| 14005 | * This routine process a fast-path work queue completion entry from fast-path |
| 14006 | * event queue for FCP command response completion. |
| 14007 | **/ |
| 14008 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14009 | lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14010 | struct lpfc_cqe *cqe) |
| 14011 | { |
| 14012 | struct lpfc_wcqe_release wcqe; |
| 14013 | bool workposted = false; |
| 14014 | |
| 14015 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 14016 | lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14017 | |
| 14018 | /* Check and process for different type of WCQE and dispatch */ |
| 14019 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 14020 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14021 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14022 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14023 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 14024 | phba->last_completion_time = jiffies; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14025 | if ((cq->subtype == LPFC_FCP) || (cq->subtype == LPFC_NVME)) |
| 14026 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
| 14027 | (struct lpfc_wcqe_complete *)&wcqe); |
| 14028 | if (cq->subtype == LPFC_NVME_LS) |
| 14029 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14030 | (struct lpfc_wcqe_complete *)&wcqe); |
| 14031 | break; |
| 14032 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14033 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14034 | /* Process the WQ release event */ |
| 14035 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 14036 | (struct lpfc_wcqe_release *)&wcqe); |
| 14037 | break; |
| 14038 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14039 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14040 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14041 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14042 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 14043 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 14044 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14045 | case CQE_CODE_RECEIVE_V1: |
| 14046 | case CQE_CODE_RECEIVE: |
| 14047 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14048 | if (cq->subtype == LPFC_NVMET) { |
| 14049 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 14050 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 14051 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14052 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14053 | default: |
| 14054 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14055 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14056 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 14057 | break; |
| 14058 | } |
| 14059 | return workposted; |
| 14060 | } |
| 14061 | |
| 14062 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14063 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14064 | * @phba: Pointer to HBA context object. |
| 14065 | * @eqe: Pointer to fast-path event queue entry. |
| 14066 | * |
| 14067 | * This routine process a event queue entry from the fast-path event queue. |
| 14068 | * It will check the MajorCode and MinorCode to determine this is for a |
| 14069 | * completion event on a completion queue, if not, an error shall be logged |
| 14070 | * and just return. Otherwise, it will get to the corresponding completion |
| 14071 | * queue and process all the entries on the completion queue, rearm the |
| 14072 | * completion queue, and then return. |
| 14073 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14074 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14075 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 14076 | uint32_t qidx) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14077 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14078 | struct lpfc_queue *cq = NULL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14079 | uint16_t cqid, id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14080 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14081 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14082 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14083 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14084 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14085 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 14086 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14087 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14088 | } |
| 14089 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14090 | /* Get the reference to the corresponding CQ */ |
| 14091 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 14092 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14093 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 14094 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 14095 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 14096 | /* Process NVMET unsol rcv */ |
| 14097 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 14098 | goto process_cq; |
| 14099 | } |
| 14100 | } |
| 14101 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14102 | if (phba->sli4_hba.nvme_cq_map && |
| 14103 | (cqid == phba->sli4_hba.nvme_cq_map[qidx])) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 14104 | /* Process NVME / NVMET command completion */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14105 | cq = phba->sli4_hba.nvme_cq[qidx]; |
| 14106 | goto process_cq; |
| 14107 | } |
| 14108 | |
| 14109 | if (phba->sli4_hba.fcp_cq_map && |
| 14110 | (cqid == phba->sli4_hba.fcp_cq_map[qidx])) { |
| 14111 | /* Process FCP command completion */ |
| 14112 | cq = phba->sli4_hba.fcp_cq[qidx]; |
| 14113 | goto process_cq; |
| 14114 | } |
| 14115 | |
| 14116 | if (phba->sli4_hba.nvmels_cq && |
| 14117 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 14118 | /* Process NVME unsol rcv */ |
| 14119 | cq = phba->sli4_hba.nvmels_cq; |
| 14120 | } |
| 14121 | |
| 14122 | /* Otherwise this is a Slow path event */ |
| 14123 | if (cq == NULL) { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14124 | lpfc_sli4_sp_handle_eqe(phba, eqe, phba->sli4_hba.hba_eq[qidx]); |
| 14125 | return; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14126 | } |
| 14127 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14128 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14129 | if (unlikely(cqid != cq->queue_id)) { |
| 14130 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14131 | "0368 Miss-matched fast-path completion " |
| 14132 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 14133 | cqid, cq->queue_id); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14134 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14135 | } |
| 14136 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14137 | /* Save EQ associated with this CQ */ |
| 14138 | cq->assoc_qp = phba->sli4_hba.hba_eq[qidx]; |
| 14139 | |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14140 | if (!queue_work(phba->wq, &cq->irqwork)) |
| 14141 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14142 | "0363 Cannot schedule soft IRQ " |
| 14143 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 14144 | cqid, cq->queue_id, smp_processor_id()); |
| 14145 | } |
| 14146 | |
| 14147 | /** |
| 14148 | * lpfc_sli4_hba_process_cq - Process a fast-path event queue entry |
| 14149 | * @phba: Pointer to HBA context object. |
| 14150 | * @eqe: Pointer to fast-path event queue entry. |
| 14151 | * |
| 14152 | * This routine process a event queue entry from the fast-path event queue. |
| 14153 | * It will check the MajorCode and MinorCode to determine this is for a |
| 14154 | * completion event on a completion queue, if not, an error shall be logged |
| 14155 | * and just return. Otherwise, it will get to the corresponding completion |
| 14156 | * queue and process all the entries on the completion queue, rearm the |
| 14157 | * completion queue, and then return. |
| 14158 | **/ |
| 14159 | static void |
| 14160 | lpfc_sli4_hba_process_cq(struct work_struct *work) |
| 14161 | { |
| 14162 | struct lpfc_queue *cq = |
| 14163 | container_of(work, struct lpfc_queue, irqwork); |
| 14164 | struct lpfc_hba *phba = cq->phba; |
| 14165 | struct lpfc_cqe *cqe; |
| 14166 | bool workposted = false; |
| 14167 | int ccount = 0; |
| 14168 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14169 | /* Process all the entries to the CQ */ |
| 14170 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 14171 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 14172 | if (phba->ktime_on) |
| 14173 | cq->isr_timestamp = ktime_get_ns(); |
| 14174 | else |
| 14175 | cq->isr_timestamp = 0; |
| 14176 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14177 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, cqe); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14178 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 14179 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14180 | } |
| 14181 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14182 | /* Track the max number of CQEs processed in 1 EQ */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14183 | if (ccount > cq->CQ_max_cqe) |
| 14184 | cq->CQ_max_cqe = ccount; |
| 14185 | cq->assoc_qp->EQ_cqe_cnt += ccount; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14186 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14187 | /* Catch the no cq entry condition */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14188 | if (unlikely(ccount == 0)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14189 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14190 | "0369 No entry from fast-path completion " |
| 14191 | "queue fcpcqid=%d\n", cq->queue_id); |
| 14192 | |
| 14193 | /* In any case, flash and re-arm the CQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 14194 | phba->sli4_hba.sli4_cq_release(cq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14195 | |
| 14196 | /* wake up worker thread if there are works to be done */ |
| 14197 | if (workposted) |
| 14198 | lpfc_worker_wake_up(phba); |
| 14199 | } |
| 14200 | |
| 14201 | static void |
| 14202 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 14203 | { |
| 14204 | struct lpfc_eqe *eqe; |
| 14205 | |
| 14206 | /* walk all the EQ entries and drop on the floor */ |
| 14207 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 14208 | ; |
| 14209 | |
| 14210 | /* Clear and re-arm the EQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 14211 | phba->sli4_hba.sli4_eq_release(eq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14212 | } |
| 14213 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14214 | |
| 14215 | /** |
| 14216 | * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue |
| 14217 | * entry |
| 14218 | * @phba: Pointer to HBA context object. |
| 14219 | * @eqe: Pointer to fast-path event queue entry. |
| 14220 | * |
| 14221 | * This routine process a event queue entry from the Flash Optimized Fabric |
| 14222 | * event queue. It will check the MajorCode and MinorCode to determine this |
| 14223 | * is for a completion event on a completion queue, if not, an error shall be |
| 14224 | * logged and just return. Otherwise, it will get to the corresponding |
| 14225 | * completion queue and process all the entries on the completion queue, rearm |
| 14226 | * the completion queue, and then return. |
| 14227 | **/ |
| 14228 | static void |
| 14229 | lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) |
| 14230 | { |
| 14231 | struct lpfc_queue *cq; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14232 | uint16_t cqid; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14233 | |
| 14234 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
| 14235 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14236 | "9147 Not a valid completion " |
| 14237 | "event: majorcode=x%x, minorcode=x%x\n", |
| 14238 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 14239 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
| 14240 | return; |
| 14241 | } |
| 14242 | |
| 14243 | /* Get the reference to the corresponding CQ */ |
| 14244 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 14245 | |
| 14246 | /* Next check for OAS */ |
| 14247 | cq = phba->sli4_hba.oas_cq; |
| 14248 | if (unlikely(!cq)) { |
| 14249 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 14250 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14251 | "9148 OAS completion queue " |
| 14252 | "does not exist\n"); |
| 14253 | return; |
| 14254 | } |
| 14255 | |
| 14256 | if (unlikely(cqid != cq->queue_id)) { |
| 14257 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14258 | "9149 Miss-matched fast-path compl " |
| 14259 | "queue id: eqcqid=%d, fcpcqid=%d\n", |
| 14260 | cqid, cq->queue_id); |
| 14261 | return; |
| 14262 | } |
| 14263 | |
James Smart | d41b65b | 2017-06-15 22:56:41 -0700 | [diff] [blame] | 14264 | /* Save EQ associated with this CQ */ |
| 14265 | cq->assoc_qp = phba->sli4_hba.fof_eq; |
| 14266 | |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14267 | /* CQ work will be processed on CPU affinitized to this IRQ */ |
| 14268 | if (!queue_work(phba->wq, &cq->irqwork)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14269 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14270 | "0367 Cannot schedule soft IRQ " |
| 14271 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 14272 | cqid, cq->queue_id, smp_processor_id()); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14273 | } |
| 14274 | |
| 14275 | /** |
| 14276 | * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device |
| 14277 | * @irq: Interrupt number. |
| 14278 | * @dev_id: The device context pointer. |
| 14279 | * |
| 14280 | * This function is directly called from the PCI layer as an interrupt |
| 14281 | * service routine when device with SLI-4 interface spec is enabled with |
| 14282 | * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric |
| 14283 | * IOCB ring event in the HBA. However, when the device is enabled with either |
| 14284 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 14285 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 14286 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 14287 | * process the interrupt. The Flash Optimized Fabric ring event are handled in |
| 14288 | * the intrrupt context. This function is called without any lock held. |
| 14289 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 14290 | * the EQ to CQ are one-to-one map such that the EQ index is |
| 14291 | * equal to that of CQ index. |
| 14292 | * |
| 14293 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 14294 | * returns IRQ_NONE. |
| 14295 | **/ |
| 14296 | irqreturn_t |
| 14297 | lpfc_sli4_fof_intr_handler(int irq, void *dev_id) |
| 14298 | { |
| 14299 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14300 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14301 | struct lpfc_queue *eq; |
| 14302 | struct lpfc_eqe *eqe; |
| 14303 | unsigned long iflag; |
| 14304 | int ecount = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14305 | |
| 14306 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14307 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 14308 | phba = hba_eq_hdl->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14309 | |
| 14310 | if (unlikely(!phba)) |
| 14311 | return IRQ_NONE; |
| 14312 | |
| 14313 | /* Get to the EQ struct associated with this vector */ |
| 14314 | eq = phba->sli4_hba.fof_eq; |
| 14315 | if (unlikely(!eq)) |
| 14316 | return IRQ_NONE; |
| 14317 | |
| 14318 | /* Check device state for handling interrupt */ |
| 14319 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14320 | /* Check again for link_state with lock held */ |
| 14321 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 14322 | if (phba->link_state < LPFC_LINK_DOWN) |
| 14323 | /* Flush, clear interrupt, and rearm the EQ */ |
| 14324 | lpfc_sli4_eq_flush(phba, eq); |
| 14325 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 14326 | return IRQ_NONE; |
| 14327 | } |
| 14328 | |
| 14329 | /* |
| 14330 | * Process all the event on FCP fast-path EQ |
| 14331 | */ |
| 14332 | while ((eqe = lpfc_sli4_eq_get(eq))) { |
| 14333 | lpfc_sli4_fof_handle_eqe(phba, eqe); |
| 14334 | if (!(++ecount % eq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 14335 | break; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14336 | eq->EQ_processed++; |
| 14337 | } |
| 14338 | |
| 14339 | /* Track the max number of EQEs processed in 1 intr */ |
| 14340 | if (ecount > eq->EQ_max_eqe) |
| 14341 | eq->EQ_max_eqe = ecount; |
| 14342 | |
| 14343 | |
| 14344 | if (unlikely(ecount == 0)) { |
| 14345 | eq->EQ_no_entry++; |
| 14346 | |
| 14347 | if (phba->intr_type == MSIX) |
| 14348 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 14349 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14350 | "9145 MSI-X interrupt with no EQE\n"); |
| 14351 | else { |
| 14352 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14353 | "9146 ISR interrupt with no EQE\n"); |
| 14354 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 14355 | return IRQ_NONE; |
| 14356 | } |
| 14357 | } |
| 14358 | /* Always clear and re-arm the fast-path EQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 14359 | phba->sli4_hba.sli4_eq_release(eq, LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14360 | return IRQ_HANDLED; |
| 14361 | } |
| 14362 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14363 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14364 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14365 | * @irq: Interrupt number. |
| 14366 | * @dev_id: The device context pointer. |
| 14367 | * |
| 14368 | * This function is directly called from the PCI layer as an interrupt |
| 14369 | * service routine when device with SLI-4 interface spec is enabled with |
| 14370 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 14371 | * ring event in the HBA. However, when the device is enabled with either |
| 14372 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 14373 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 14374 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 14375 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 14376 | * the intrrupt context. This function is called without any lock held. |
| 14377 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 14378 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 14379 | * equal to that of FCP CQ index. |
| 14380 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14381 | * The link attention and ELS ring attention events are handled |
| 14382 | * by the worker thread. The interrupt handler signals the worker thread |
| 14383 | * and returns for these events. This function is called without any lock |
| 14384 | * held. It gets the hbalock to access and update SLI data structures. |
| 14385 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14386 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 14387 | * returns IRQ_NONE. |
| 14388 | **/ |
| 14389 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14390 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14391 | { |
| 14392 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14393 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14394 | struct lpfc_queue *fpeq; |
| 14395 | struct lpfc_eqe *eqe; |
| 14396 | unsigned long iflag; |
| 14397 | int ecount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14398 | int hba_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14399 | |
| 14400 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14401 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 14402 | phba = hba_eq_hdl->phba; |
| 14403 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14404 | |
| 14405 | if (unlikely(!phba)) |
| 14406 | return IRQ_NONE; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14407 | if (unlikely(!phba->sli4_hba.hba_eq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 14408 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14409 | |
| 14410 | /* Get to the EQ struct associated with this vector */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14411 | fpeq = phba->sli4_hba.hba_eq[hba_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14412 | if (unlikely(!fpeq)) |
| 14413 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14414 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14415 | if (lpfc_fcp_look_ahead) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14416 | if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use)) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 14417 | phba->sli4_hba.sli4_eq_clr_intr(fpeq); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14418 | else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14419 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14420 | return IRQ_NONE; |
| 14421 | } |
| 14422 | } |
| 14423 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14424 | /* Check device state for handling interrupt */ |
| 14425 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 14426 | /* Check again for link_state with lock held */ |
| 14427 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 14428 | if (phba->link_state < LPFC_LINK_DOWN) |
| 14429 | /* Flush, clear interrupt, and rearm the EQ */ |
| 14430 | lpfc_sli4_eq_flush(phba, fpeq); |
| 14431 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14432 | if (lpfc_fcp_look_ahead) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14433 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14434 | return IRQ_NONE; |
| 14435 | } |
| 14436 | |
| 14437 | /* |
| 14438 | * Process all the event on FCP fast-path EQ |
| 14439 | */ |
| 14440 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14441 | lpfc_sli4_hba_handle_eqe(phba, eqe, hba_eqidx); |
| 14442 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 14443 | break; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14444 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14445 | } |
| 14446 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14447 | /* Track the max number of EQEs processed in 1 intr */ |
| 14448 | if (ecount > fpeq->EQ_max_eqe) |
| 14449 | fpeq->EQ_max_eqe = ecount; |
| 14450 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14451 | /* Always clear and re-arm the fast-path EQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 14452 | phba->sli4_hba.sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14453 | |
| 14454 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14455 | fpeq->EQ_no_entry++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14456 | |
| 14457 | if (lpfc_fcp_look_ahead) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14458 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14459 | return IRQ_NONE; |
| 14460 | } |
| 14461 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14462 | if (phba->intr_type == MSIX) |
| 14463 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 14464 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14465 | "0358 MSI-X interrupt with no EQE\n"); |
| 14466 | else |
| 14467 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 14468 | return IRQ_NONE; |
| 14469 | } |
| 14470 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14471 | if (lpfc_fcp_look_ahead) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14472 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
| 14473 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14474 | return IRQ_HANDLED; |
| 14475 | } /* lpfc_sli4_fp_intr_handler */ |
| 14476 | |
| 14477 | /** |
| 14478 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 14479 | * @irq: Interrupt number. |
| 14480 | * @dev_id: The device context pointer. |
| 14481 | * |
| 14482 | * This function is the device-level interrupt handler to device with SLI-4 |
| 14483 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 14484 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 14485 | * driver attention. This function invokes the slow-path interrupt attention |
| 14486 | * handling function and fast-path interrupt attention handling function in |
| 14487 | * turn to process the relevant HBA attention events. This function is called |
| 14488 | * without any lock held. It gets the hbalock to access and update SLI data |
| 14489 | * structures. |
| 14490 | * |
| 14491 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 14492 | * returns IRQ_NONE. |
| 14493 | **/ |
| 14494 | irqreturn_t |
| 14495 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 14496 | { |
| 14497 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14498 | irqreturn_t hba_irq_rc; |
| 14499 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14500 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14501 | |
| 14502 | /* Get the driver's phba structure from the dev_id */ |
| 14503 | phba = (struct lpfc_hba *)dev_id; |
| 14504 | |
| 14505 | if (unlikely(!phba)) |
| 14506 | return IRQ_NONE; |
| 14507 | |
| 14508 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14509 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 14510 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14511 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14512 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14513 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14514 | if (hba_irq_rc == IRQ_HANDLED) |
| 14515 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14516 | } |
| 14517 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14518 | if (phba->cfg_fof) { |
| 14519 | hba_irq_rc = lpfc_sli4_fof_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14520 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14521 | if (hba_irq_rc == IRQ_HANDLED) |
| 14522 | hba_handled |= true; |
| 14523 | } |
| 14524 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14525 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14526 | } /* lpfc_sli4_intr_handler */ |
| 14527 | |
| 14528 | /** |
| 14529 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 14530 | * @queue: The queue structure to free. |
| 14531 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 14532 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14533 | * the host resident queue. This function must be called after destroying the |
| 14534 | * queue on the HBA. |
| 14535 | **/ |
| 14536 | void |
| 14537 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 14538 | { |
| 14539 | struct lpfc_dmabuf *dmabuf; |
| 14540 | |
| 14541 | if (!queue) |
| 14542 | return; |
| 14543 | |
| 14544 | while (!list_empty(&queue->page_list)) { |
| 14545 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 14546 | list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14547 | dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14548 | dmabuf->virt, dmabuf->phys); |
| 14549 | kfree(dmabuf); |
| 14550 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14551 | if (queue->rqbp) { |
| 14552 | lpfc_free_rq_buffer(queue->phba, queue); |
| 14553 | kfree(queue->rqbp); |
| 14554 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 14555 | |
| 14556 | if (!list_empty(&queue->wq_list)) |
| 14557 | list_del(&queue->wq_list); |
| 14558 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14559 | kfree(queue); |
| 14560 | return; |
| 14561 | } |
| 14562 | |
| 14563 | /** |
| 14564 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 14565 | * @phba: The HBA that this queue is being created on. |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14566 | * @page_size: The size of a queue page |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14567 | * @entry_size: The size of each queue entry for this queue. |
| 14568 | * @entry count: The number of entries that this queue will handle. |
| 14569 | * |
| 14570 | * This function allocates a queue structure and the DMAable memory used for |
| 14571 | * the host resident queue. This function must be called before creating the |
| 14572 | * queue on the HBA. |
| 14573 | **/ |
| 14574 | struct lpfc_queue * |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14575 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size, |
| 14576 | uint32_t entry_size, uint32_t entry_count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14577 | { |
| 14578 | struct lpfc_queue *queue; |
| 14579 | struct lpfc_dmabuf *dmabuf; |
| 14580 | int x, total_qe_count; |
| 14581 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14582 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14583 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14584 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14585 | hw_page_size = page_size; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14586 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14587 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 14588 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 14589 | if (!queue) |
| 14590 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14591 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 14592 | hw_page_size))/hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14593 | |
| 14594 | /* If needed, Adjust page count to match the max the adapter supports */ |
Ewan D. Milne | 4e87eb2 | 2018-12-13 15:25:16 -0500 | [diff] [blame] | 14595 | if (phba->sli4_hba.pc_sli4_params.wqpcnt && |
| 14596 | (queue->page_count > phba->sli4_hba.pc_sli4_params.wqpcnt)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14597 | queue->page_count = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 14598 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14599 | INIT_LIST_HEAD(&queue->list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14600 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 14601 | INIT_LIST_HEAD(&queue->wqfull_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14602 | INIT_LIST_HEAD(&queue->page_list); |
| 14603 | INIT_LIST_HEAD(&queue->child_list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14604 | |
| 14605 | /* Set queue parameters now. If the system cannot provide memory |
| 14606 | * resources, the free routine needs to know what was allocated. |
| 14607 | */ |
| 14608 | queue->entry_size = entry_size; |
| 14609 | queue->entry_count = entry_count; |
| 14610 | queue->page_size = hw_page_size; |
| 14611 | queue->phba = phba; |
| 14612 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14613 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 14614 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 14615 | if (!dmabuf) |
| 14616 | goto out_fail; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 14617 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 14618 | hw_page_size, &dmabuf->phys, |
| 14619 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14620 | if (!dmabuf->virt) { |
| 14621 | kfree(dmabuf); |
| 14622 | goto out_fail; |
| 14623 | } |
| 14624 | dmabuf->buffer_tag = x; |
| 14625 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 14626 | /* initialize queue's entry array */ |
| 14627 | dma_pointer = dmabuf->virt; |
| 14628 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14629 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14630 | total_qe_count++, dma_pointer += entry_size) { |
| 14631 | queue->qe[total_qe_count].address = dma_pointer; |
| 14632 | } |
| 14633 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14634 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
| 14635 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14636 | |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14637 | /* entry_repost will be set during q creation */ |
| 14638 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14639 | return queue; |
| 14640 | out_fail: |
| 14641 | lpfc_sli4_queue_free(queue); |
| 14642 | return NULL; |
| 14643 | } |
| 14644 | |
| 14645 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14646 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 14647 | * @phba: HBA structure that indicates port to create a queue on. |
| 14648 | * @pci_barset: PCI BAR set flag. |
| 14649 | * |
| 14650 | * This function shall perform iomap of the specified PCI BAR address to host |
| 14651 | * memory address if not already done so and return it. The returned host |
| 14652 | * memory address can be NULL. |
| 14653 | */ |
| 14654 | static void __iomem * |
| 14655 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 14656 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14657 | if (!phba->pcidev) |
| 14658 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14659 | |
| 14660 | switch (pci_barset) { |
| 14661 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14662 | return phba->pci_bar0_memmap_p; |
| 14663 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14664 | return phba->pci_bar2_memmap_p; |
| 14665 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14666 | return phba->pci_bar4_memmap_p; |
| 14667 | default: |
| 14668 | break; |
| 14669 | } |
| 14670 | return NULL; |
| 14671 | } |
| 14672 | |
| 14673 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14674 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on FCP EQs |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14675 | * @phba: HBA structure that indicates port to create a queue on. |
| 14676 | * @startq: The starting FCP EQ to modify |
| 14677 | * |
| 14678 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 14679 | * The command allows up to LPFC_MAX_EQ_DELAY_EQID_CNT EQ ID's to be |
| 14680 | * updated in one mailbox command. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14681 | * |
| 14682 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 14683 | * is used to get the starting FCP EQ to change. |
| 14684 | * This function is asynchronous and will wait for the mailbox |
| 14685 | * command to finish before continuing. |
| 14686 | * |
| 14687 | * On success this function will return a zero. If unable to allocate enough |
| 14688 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14689 | * fails this function will return -ENXIO. |
| 14690 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14691 | int |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14692 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
| 14693 | uint32_t numq, uint32_t imax) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14694 | { |
| 14695 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 14696 | LPFC_MBOXQ_t *mbox; |
| 14697 | struct lpfc_queue *eq; |
| 14698 | int cnt, rc, length, status = 0; |
| 14699 | uint32_t shdr_status, shdr_add_status; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14700 | uint32_t result, val; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14701 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14702 | union lpfc_sli4_cfg_shdr *shdr; |
| 14703 | uint16_t dmult; |
| 14704 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14705 | if (startq >= phba->io_channel_irqs) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14706 | return 0; |
| 14707 | |
| 14708 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14709 | if (!mbox) |
| 14710 | return -ENOMEM; |
| 14711 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 14712 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14713 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14714 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 14715 | length, LPFC_SLI4_MBX_EMBED); |
| 14716 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 14717 | |
| 14718 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14719 | result = imax / phba->io_channel_irqs; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14720 | if (result > LPFC_DMULT_CONST || result == 0) |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14721 | dmult = 0; |
| 14722 | else |
| 14723 | dmult = LPFC_DMULT_CONST/result - 1; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14724 | if (dmult > LPFC_DMULT_MAX) |
| 14725 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14726 | |
| 14727 | cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14728 | for (qidx = startq; qidx < phba->io_channel_irqs; qidx++) { |
| 14729 | eq = phba->sli4_hba.hba_eq[qidx]; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14730 | if (!eq) |
| 14731 | continue; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14732 | eq->q_mode = imax; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14733 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 14734 | eq_delay->u.request.eq[cnt].phase = 0; |
| 14735 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 14736 | cnt++; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14737 | |
| 14738 | /* q_mode is only used for auto_imax */ |
| 14739 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 14740 | /* Use EQ Delay Register method for q_mode */ |
| 14741 | |
| 14742 | /* Convert for EQ Delay register */ |
| 14743 | val = phba->cfg_fcp_imax; |
| 14744 | if (val) { |
| 14745 | /* First, interrupts per sec per EQ */ |
| 14746 | val = phba->cfg_fcp_imax / |
| 14747 | phba->io_channel_irqs; |
| 14748 | |
| 14749 | /* us delay between each interrupt */ |
| 14750 | val = LPFC_SEC_TO_USEC / val; |
| 14751 | } |
| 14752 | eq->q_mode = val; |
| 14753 | } else { |
| 14754 | eq->q_mode = imax; |
| 14755 | } |
| 14756 | |
| 14757 | if (cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14758 | break; |
| 14759 | } |
| 14760 | eq_delay->u.request.num_eq = cnt; |
| 14761 | |
| 14762 | mbox->vport = phba->pport; |
| 14763 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14764 | mbox->ctx_buf = NULL; |
| 14765 | mbox->ctx_ndlp = NULL; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14766 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14767 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 14768 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14769 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14770 | if (shdr_status || shdr_add_status || rc) { |
| 14771 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14772 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 14773 | "status x%x add_status x%x, mbx status x%x\n", |
| 14774 | shdr_status, shdr_add_status, rc); |
| 14775 | status = -ENXIO; |
| 14776 | } |
| 14777 | mempool_free(mbox, phba->mbox_mem_pool); |
| 14778 | return status; |
| 14779 | } |
| 14780 | |
| 14781 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14782 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 14783 | * @phba: HBA structure that indicates port to create a queue on. |
| 14784 | * @eq: The queue structure to use to create the event queue. |
| 14785 | * @imax: The maximum interrupt per second limit. |
| 14786 | * |
| 14787 | * This function creates an event queue, as detailed in @eq, on a port, |
| 14788 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 14789 | * |
| 14790 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 14791 | * is used to get the entry count and entry size that are necessary to |
| 14792 | * determine the number of pages to allocate and use for this queue. This |
| 14793 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 14794 | * event queue. This function is asynchronous and will wait for the mailbox |
| 14795 | * command to finish before continuing. |
| 14796 | * |
| 14797 | * On success this function will return a zero. If unable to allocate enough |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14798 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14799 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14800 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14801 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14802 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14803 | { |
| 14804 | struct lpfc_mbx_eq_create *eq_create; |
| 14805 | LPFC_MBOXQ_t *mbox; |
| 14806 | int rc, length, status = 0; |
| 14807 | struct lpfc_dmabuf *dmabuf; |
| 14808 | uint32_t shdr_status, shdr_add_status; |
| 14809 | union lpfc_sli4_cfg_shdr *shdr; |
| 14810 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14811 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14812 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14813 | /* sanity check on queue memory */ |
| 14814 | if (!eq) |
| 14815 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14816 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14817 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14818 | |
| 14819 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14820 | if (!mbox) |
| 14821 | return -ENOMEM; |
| 14822 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 14823 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14824 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14825 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 14826 | length, LPFC_SLI4_MBX_EMBED); |
| 14827 | eq_create = &mbox->u.mqe.un.eq_create; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14828 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14829 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 14830 | eq->page_count); |
| 14831 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 14832 | LPFC_EQE_SIZE); |
| 14833 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14834 | |
| 14835 | /* Use version 2 of CREATE_EQ if eqav is set */ |
| 14836 | if (phba->sli4_hba.pc_sli4_params.eqav) { |
| 14837 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14838 | LPFC_Q_CREATE_VERSION_2); |
| 14839 | bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context, |
| 14840 | phba->sli4_hba.pc_sli4_params.eqav); |
| 14841 | } |
| 14842 | |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 14843 | /* don't setup delay multiplier using EQ_CREATE */ |
| 14844 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14845 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 14846 | dmult); |
| 14847 | switch (eq->entry_count) { |
| 14848 | default: |
| 14849 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14850 | "0360 Unsupported EQ count. (%d)\n", |
| 14851 | eq->entry_count); |
| 14852 | if (eq->entry_count < 256) |
| 14853 | return -EINVAL; |
| 14854 | /* otherwise default to smallest count (drop through) */ |
| 14855 | case 256: |
| 14856 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14857 | LPFC_EQ_CNT_256); |
| 14858 | break; |
| 14859 | case 512: |
| 14860 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14861 | LPFC_EQ_CNT_512); |
| 14862 | break; |
| 14863 | case 1024: |
| 14864 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14865 | LPFC_EQ_CNT_1024); |
| 14866 | break; |
| 14867 | case 2048: |
| 14868 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14869 | LPFC_EQ_CNT_2048); |
| 14870 | break; |
| 14871 | case 4096: |
| 14872 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14873 | LPFC_EQ_CNT_4096); |
| 14874 | break; |
| 14875 | } |
| 14876 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14877 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14878 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14879 | putPaddrLow(dmabuf->phys); |
| 14880 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14881 | putPaddrHigh(dmabuf->phys); |
| 14882 | } |
| 14883 | mbox->vport = phba->pport; |
| 14884 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14885 | mbox->ctx_buf = NULL; |
| 14886 | mbox->ctx_ndlp = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14887 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14888 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14889 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14890 | if (shdr_status || shdr_add_status || rc) { |
| 14891 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14892 | "2500 EQ_CREATE mailbox failed with " |
| 14893 | "status x%x add_status x%x, mbx status x%x\n", |
| 14894 | shdr_status, shdr_add_status, rc); |
| 14895 | status = -ENXIO; |
| 14896 | } |
| 14897 | eq->type = LPFC_EQ; |
| 14898 | eq->subtype = LPFC_NONE; |
| 14899 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 14900 | if (eq->queue_id == 0xFFFF) |
| 14901 | status = -ENXIO; |
| 14902 | eq->host_index = 0; |
| 14903 | eq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14904 | eq->entry_repost = LPFC_EQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14905 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14906 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14907 | return status; |
| 14908 | } |
| 14909 | |
| 14910 | /** |
| 14911 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 14912 | * @phba: HBA structure that indicates port to create a queue on. |
| 14913 | * @cq: The queue structure to use to create the completion queue. |
| 14914 | * @eq: The event queue to bind this completion queue to. |
| 14915 | * |
| 14916 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 14917 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 14918 | * |
| 14919 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14920 | * is used to get the entry count and entry size that are necessary to |
| 14921 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14922 | * is used to indicate which event queue to bind this completion queue to. This |
| 14923 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 14924 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14925 | * command to finish before continuing. |
| 14926 | * |
| 14927 | * On success this function will return a zero. If unable to allocate enough |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14928 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14929 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14930 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14931 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14932 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14933 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 14934 | { |
| 14935 | struct lpfc_mbx_cq_create *cq_create; |
| 14936 | struct lpfc_dmabuf *dmabuf; |
| 14937 | LPFC_MBOXQ_t *mbox; |
| 14938 | int rc, length, status = 0; |
| 14939 | uint32_t shdr_status, shdr_add_status; |
| 14940 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14941 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14942 | /* sanity check on queue memory */ |
| 14943 | if (!cq || !eq) |
| 14944 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14945 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14946 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14947 | if (!mbox) |
| 14948 | return -ENOMEM; |
| 14949 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 14950 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14951 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14952 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 14953 | length, LPFC_SLI4_MBX_EMBED); |
| 14954 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14955 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14956 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 14957 | cq->page_count); |
| 14958 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 14959 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14960 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14961 | phba->sli4_hba.pc_sli4_params.cqv); |
| 14962 | if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14963 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, |
| 14964 | (cq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14965 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 14966 | eq->queue_id); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14967 | bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context, |
| 14968 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14969 | } else { |
| 14970 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 14971 | eq->queue_id); |
| 14972 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14973 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14974 | case 2048: |
| 14975 | case 4096: |
| 14976 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 14977 | LPFC_Q_CREATE_VERSION_2) { |
| 14978 | cq_create->u.request.context.lpfc_cq_context_count = |
| 14979 | cq->entry_count; |
| 14980 | bf_set(lpfc_cq_context_count, |
| 14981 | &cq_create->u.request.context, |
| 14982 | LPFC_CQ_CNT_WORD7); |
| 14983 | break; |
| 14984 | } |
| 14985 | /* Fall Thru */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14986 | default: |
| 14987 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14988 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14989 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14990 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14991 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14992 | if (cq->entry_count < 256) { |
| 14993 | status = -EINVAL; |
| 14994 | goto out; |
| 14995 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14996 | /* otherwise default to smallest count (drop through) */ |
| 14997 | case 256: |
| 14998 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14999 | LPFC_CQ_CNT_256); |
| 15000 | break; |
| 15001 | case 512: |
| 15002 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15003 | LPFC_CQ_CNT_512); |
| 15004 | break; |
| 15005 | case 1024: |
| 15006 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15007 | LPFC_CQ_CNT_1024); |
| 15008 | break; |
| 15009 | } |
| 15010 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15011 | memset(dmabuf->virt, 0, cq->page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15012 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15013 | putPaddrLow(dmabuf->phys); |
| 15014 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15015 | putPaddrHigh(dmabuf->phys); |
| 15016 | } |
| 15017 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15018 | |
| 15019 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15020 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15021 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15022 | if (shdr_status || shdr_add_status || rc) { |
| 15023 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15024 | "2501 CQ_CREATE mailbox failed with " |
| 15025 | "status x%x add_status x%x, mbx status x%x\n", |
| 15026 | shdr_status, shdr_add_status, rc); |
| 15027 | status = -ENXIO; |
| 15028 | goto out; |
| 15029 | } |
| 15030 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 15031 | if (cq->queue_id == 0xFFFF) { |
| 15032 | status = -ENXIO; |
| 15033 | goto out; |
| 15034 | } |
| 15035 | /* link the cq onto the parent eq child list */ |
| 15036 | list_add_tail(&cq->list, &eq->child_list); |
| 15037 | /* Set up completion queue's type and subtype */ |
| 15038 | cq->type = type; |
| 15039 | cq->subtype = subtype; |
| 15040 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15041 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15042 | cq->host_index = 0; |
| 15043 | cq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15044 | cq->entry_repost = LPFC_CQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15045 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15046 | out: |
| 15047 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15048 | return status; |
| 15049 | } |
| 15050 | |
| 15051 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15052 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 15053 | * @phba: HBA structure that indicates port to create a queue on. |
| 15054 | * @cqp: The queue structure array to use to create the completion queues. |
| 15055 | * @eqp: The event queue array to bind these completion queues to. |
| 15056 | * |
| 15057 | * This function creates a set of completion queue, s to support MRQ |
| 15058 | * as detailed in @cqp, on a port, |
| 15059 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 15060 | * |
| 15061 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15062 | * is used to get the entry count and entry size that are necessary to |
| 15063 | * determine the number of pages to allocate and use for this queue. The @eq |
| 15064 | * is used to indicate which event queue to bind this completion queue to. This |
| 15065 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 15066 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 15067 | * command to finish before continuing. |
| 15068 | * |
| 15069 | * On success this function will return a zero. If unable to allocate enough |
| 15070 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15071 | * fails this function will return -ENXIO. |
| 15072 | **/ |
| 15073 | int |
| 15074 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
| 15075 | struct lpfc_queue **eqp, uint32_t type, uint32_t subtype) |
| 15076 | { |
| 15077 | struct lpfc_queue *cq; |
| 15078 | struct lpfc_queue *eq; |
| 15079 | struct lpfc_mbx_cq_create_set *cq_set; |
| 15080 | struct lpfc_dmabuf *dmabuf; |
| 15081 | LPFC_MBOXQ_t *mbox; |
| 15082 | int rc, length, alloclen, status = 0; |
| 15083 | int cnt, idx, numcq, page_idx = 0; |
| 15084 | uint32_t shdr_status, shdr_add_status; |
| 15085 | union lpfc_sli4_cfg_shdr *shdr; |
| 15086 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15087 | |
| 15088 | /* sanity check on queue memory */ |
| 15089 | numcq = phba->cfg_nvmet_mrq; |
| 15090 | if (!cqp || !eqp || !numcq) |
| 15091 | return -ENODEV; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15092 | |
| 15093 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15094 | if (!mbox) |
| 15095 | return -ENOMEM; |
| 15096 | |
| 15097 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 15098 | length += ((numcq * cqp[0]->page_count) * |
| 15099 | sizeof(struct dma_address)); |
| 15100 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15101 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 15102 | LPFC_SLI4_MBX_NEMBED); |
| 15103 | if (alloclen < length) { |
| 15104 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15105 | "3098 Allocated DMA memory size (%d) is " |
| 15106 | "less than the requested DMA memory size " |
| 15107 | "(%d)\n", alloclen, length); |
| 15108 | status = -ENOMEM; |
| 15109 | goto out; |
| 15110 | } |
| 15111 | cq_set = mbox->sge_array->addr[0]; |
| 15112 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 15113 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 15114 | |
| 15115 | for (idx = 0; idx < numcq; idx++) { |
| 15116 | cq = cqp[idx]; |
| 15117 | eq = eqp[idx]; |
| 15118 | if (!cq || !eq) { |
| 15119 | status = -ENOMEM; |
| 15120 | goto out; |
| 15121 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15122 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15123 | hw_page_size = cq->page_size; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15124 | |
| 15125 | switch (idx) { |
| 15126 | case 0: |
| 15127 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 15128 | &cq_set->u.request, |
| 15129 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 15130 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 15131 | &cq_set->u.request, cq->page_count); |
| 15132 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 15133 | &cq_set->u.request, 1); |
| 15134 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 15135 | &cq_set->u.request, 1); |
| 15136 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 15137 | &cq_set->u.request, 0); |
| 15138 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 15139 | &cq_set->u.request, numcq); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 15140 | bf_set(lpfc_mbx_cq_create_set_autovalid, |
| 15141 | &cq_set->u.request, |
| 15142 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15143 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15144 | case 2048: |
| 15145 | case 4096: |
| 15146 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 15147 | LPFC_Q_CREATE_VERSION_2) { |
| 15148 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15149 | &cq_set->u.request, |
| 15150 | cq->entry_count); |
| 15151 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15152 | &cq_set->u.request, |
| 15153 | LPFC_CQ_CNT_WORD7); |
| 15154 | break; |
| 15155 | } |
| 15156 | /* Fall Thru */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15157 | default: |
| 15158 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15159 | "3118 Bad CQ count. (%d)\n", |
| 15160 | cq->entry_count); |
| 15161 | if (cq->entry_count < 256) { |
| 15162 | status = -EINVAL; |
| 15163 | goto out; |
| 15164 | } |
| 15165 | /* otherwise default to smallest (drop thru) */ |
| 15166 | case 256: |
| 15167 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15168 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 15169 | break; |
| 15170 | case 512: |
| 15171 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15172 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 15173 | break; |
| 15174 | case 1024: |
| 15175 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15176 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 15177 | break; |
| 15178 | } |
| 15179 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 15180 | &cq_set->u.request, eq->queue_id); |
| 15181 | break; |
| 15182 | case 1: |
| 15183 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 15184 | &cq_set->u.request, eq->queue_id); |
| 15185 | break; |
| 15186 | case 2: |
| 15187 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 15188 | &cq_set->u.request, eq->queue_id); |
| 15189 | break; |
| 15190 | case 3: |
| 15191 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 15192 | &cq_set->u.request, eq->queue_id); |
| 15193 | break; |
| 15194 | case 4: |
| 15195 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 15196 | &cq_set->u.request, eq->queue_id); |
| 15197 | break; |
| 15198 | case 5: |
| 15199 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 15200 | &cq_set->u.request, eq->queue_id); |
| 15201 | break; |
| 15202 | case 6: |
| 15203 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 15204 | &cq_set->u.request, eq->queue_id); |
| 15205 | break; |
| 15206 | case 7: |
| 15207 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 15208 | &cq_set->u.request, eq->queue_id); |
| 15209 | break; |
| 15210 | case 8: |
| 15211 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 15212 | &cq_set->u.request, eq->queue_id); |
| 15213 | break; |
| 15214 | case 9: |
| 15215 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 15216 | &cq_set->u.request, eq->queue_id); |
| 15217 | break; |
| 15218 | case 10: |
| 15219 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 15220 | &cq_set->u.request, eq->queue_id); |
| 15221 | break; |
| 15222 | case 11: |
| 15223 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 15224 | &cq_set->u.request, eq->queue_id); |
| 15225 | break; |
| 15226 | case 12: |
| 15227 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 15228 | &cq_set->u.request, eq->queue_id); |
| 15229 | break; |
| 15230 | case 13: |
| 15231 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 15232 | &cq_set->u.request, eq->queue_id); |
| 15233 | break; |
| 15234 | case 14: |
| 15235 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 15236 | &cq_set->u.request, eq->queue_id); |
| 15237 | break; |
| 15238 | case 15: |
| 15239 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 15240 | &cq_set->u.request, eq->queue_id); |
| 15241 | break; |
| 15242 | } |
| 15243 | |
| 15244 | /* link the cq onto the parent eq child list */ |
| 15245 | list_add_tail(&cq->list, &eq->child_list); |
| 15246 | /* Set up completion queue's type and subtype */ |
| 15247 | cq->type = type; |
| 15248 | cq->subtype = subtype; |
| 15249 | cq->assoc_qid = eq->queue_id; |
| 15250 | cq->host_index = 0; |
| 15251 | cq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15252 | cq->entry_repost = LPFC_CQ_REPOST; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15253 | cq->chann = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15254 | |
| 15255 | rc = 0; |
| 15256 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 15257 | memset(dmabuf->virt, 0, hw_page_size); |
| 15258 | cnt = page_idx + dmabuf->buffer_tag; |
| 15259 | cq_set->u.request.page[cnt].addr_lo = |
| 15260 | putPaddrLow(dmabuf->phys); |
| 15261 | cq_set->u.request.page[cnt].addr_hi = |
| 15262 | putPaddrHigh(dmabuf->phys); |
| 15263 | rc++; |
| 15264 | } |
| 15265 | page_idx += rc; |
| 15266 | } |
| 15267 | |
| 15268 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15269 | |
| 15270 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15271 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15272 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15273 | if (shdr_status || shdr_add_status || rc) { |
| 15274 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15275 | "3119 CQ_CREATE_SET mailbox failed with " |
| 15276 | "status x%x add_status x%x, mbx status x%x\n", |
| 15277 | shdr_status, shdr_add_status, rc); |
| 15278 | status = -ENXIO; |
| 15279 | goto out; |
| 15280 | } |
| 15281 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 15282 | if (rc == 0xFFFF) { |
| 15283 | status = -ENXIO; |
| 15284 | goto out; |
| 15285 | } |
| 15286 | |
| 15287 | for (idx = 0; idx < numcq; idx++) { |
| 15288 | cq = cqp[idx]; |
| 15289 | cq->queue_id = rc + idx; |
| 15290 | } |
| 15291 | |
| 15292 | out: |
| 15293 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 15294 | return status; |
| 15295 | } |
| 15296 | |
| 15297 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15298 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15299 | * @phba: HBA structure that indicates port to create a queue on. |
| 15300 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15301 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 15302 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15303 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15304 | * This function provides failback (fb) functionality when the |
| 15305 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 15306 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15307 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15308 | * This routine cannot fail as all attributes were previously accessed and |
| 15309 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15310 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15311 | static void |
| 15312 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15313 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15314 | { |
| 15315 | struct lpfc_mbx_mq_create *mq_create; |
| 15316 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15317 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15318 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15319 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 15320 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15321 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15322 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 15323 | length, LPFC_SLI4_MBX_EMBED); |
| 15324 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15325 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15326 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15327 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15328 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15329 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 15330 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15331 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15332 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15333 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15334 | break; |
| 15335 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15336 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15337 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15338 | break; |
| 15339 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15340 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15341 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15342 | break; |
| 15343 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15344 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15345 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15346 | break; |
| 15347 | } |
| 15348 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 15349 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15350 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15351 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15352 | putPaddrHigh(dmabuf->phys); |
| 15353 | } |
| 15354 | } |
| 15355 | |
| 15356 | /** |
| 15357 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 15358 | * @phba: HBA structure that indicates port to create a queue on. |
| 15359 | * @mq: The queue structure to use to create the mailbox queue. |
| 15360 | * @cq: The completion queue to associate with this cq. |
| 15361 | * @subtype: The queue's subtype. |
| 15362 | * |
| 15363 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 15364 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 15365 | * |
| 15366 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15367 | * is used to get the entry count and entry size that are necessary to |
| 15368 | * determine the number of pages to allocate and use for this queue. This |
| 15369 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 15370 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 15371 | * command to finish before continuing. |
| 15372 | * |
| 15373 | * On success this function will return a zero. If unable to allocate enough |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15374 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15375 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15376 | **/ |
| 15377 | int32_t |
| 15378 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15379 | struct lpfc_queue *cq, uint32_t subtype) |
| 15380 | { |
| 15381 | struct lpfc_mbx_mq_create *mq_create; |
| 15382 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 15383 | struct lpfc_dmabuf *dmabuf; |
| 15384 | LPFC_MBOXQ_t *mbox; |
| 15385 | int rc, length, status = 0; |
| 15386 | uint32_t shdr_status, shdr_add_status; |
| 15387 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15388 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15389 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15390 | /* sanity check on queue memory */ |
| 15391 | if (!mq || !cq) |
| 15392 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15393 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15394 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15395 | |
| 15396 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15397 | if (!mbox) |
| 15398 | return -ENOMEM; |
| 15399 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 15400 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15401 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15402 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 15403 | length, LPFC_SLI4_MBX_EMBED); |
| 15404 | |
| 15405 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15406 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15407 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 15408 | &mq_create_ext->u.request, mq->page_count); |
| 15409 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 15410 | &mq_create_ext->u.request, 1); |
| 15411 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15412 | &mq_create_ext->u.request, 1); |
| 15413 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 15414 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15415 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 15416 | &mq_create_ext->u.request, 1); |
| 15417 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 15418 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15419 | bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15420 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15421 | phba->sli4_hba.pc_sli4_params.mqv); |
| 15422 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 15423 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 15424 | cq->queue_id); |
| 15425 | else |
| 15426 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 15427 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15428 | switch (mq->entry_count) { |
| 15429 | default: |
| 15430 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15431 | "0362 Unsupported MQ count. (%d)\n", |
| 15432 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15433 | if (mq->entry_count < 16) { |
| 15434 | status = -EINVAL; |
| 15435 | goto out; |
| 15436 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15437 | /* otherwise default to smallest count (drop through) */ |
| 15438 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15439 | bf_set(lpfc_mq_context_ring_size, |
| 15440 | &mq_create_ext->u.request.context, |
| 15441 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15442 | break; |
| 15443 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15444 | bf_set(lpfc_mq_context_ring_size, |
| 15445 | &mq_create_ext->u.request.context, |
| 15446 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15447 | break; |
| 15448 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15449 | bf_set(lpfc_mq_context_ring_size, |
| 15450 | &mq_create_ext->u.request.context, |
| 15451 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15452 | break; |
| 15453 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15454 | bf_set(lpfc_mq_context_ring_size, |
| 15455 | &mq_create_ext->u.request.context, |
| 15456 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15457 | break; |
| 15458 | } |
| 15459 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15460 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15461 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15462 | putPaddrLow(dmabuf->phys); |
| 15463 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15464 | putPaddrHigh(dmabuf->phys); |
| 15465 | } |
| 15466 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15467 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15468 | &mq_create_ext->u.response); |
| 15469 | if (rc != MBX_SUCCESS) { |
| 15470 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15471 | "2795 MQ_CREATE_EXT failed with " |
| 15472 | "status x%x. Failback to MQ_CREATE.\n", |
| 15473 | rc); |
| 15474 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 15475 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15476 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15477 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 15478 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15479 | &mq_create->u.response); |
| 15480 | } |
| 15481 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15482 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15483 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15484 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15485 | if (shdr_status || shdr_add_status || rc) { |
| 15486 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15487 | "2502 MQ_CREATE mailbox failed with " |
| 15488 | "status x%x add_status x%x, mbx status x%x\n", |
| 15489 | shdr_status, shdr_add_status, rc); |
| 15490 | status = -ENXIO; |
| 15491 | goto out; |
| 15492 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15493 | if (mq->queue_id == 0xFFFF) { |
| 15494 | status = -ENXIO; |
| 15495 | goto out; |
| 15496 | } |
| 15497 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15498 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15499 | mq->subtype = subtype; |
| 15500 | mq->host_index = 0; |
| 15501 | mq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15502 | mq->entry_repost = LPFC_MQ_REPOST; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15503 | |
| 15504 | /* link the mq onto the parent cq child list */ |
| 15505 | list_add_tail(&mq->list, &cq->child_list); |
| 15506 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15507 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15508 | return status; |
| 15509 | } |
| 15510 | |
| 15511 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15512 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 15513 | * @phba: HBA structure that indicates port to create a queue on. |
| 15514 | * @wq: The queue structure to use to create the work queue. |
| 15515 | * @cq: The completion queue to bind this work queue to. |
| 15516 | * @subtype: The subtype of the work queue indicating its functionality. |
| 15517 | * |
| 15518 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 15519 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 15520 | * |
| 15521 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 15522 | * is used to get the entry count and entry size that are necessary to |
| 15523 | * determine the number of pages to allocate and use for this queue. The @cq |
| 15524 | * is used to indicate which completion queue to bind this work queue to. This |
| 15525 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 15526 | * work queue. This function is asynchronous and will wait for the mailbox |
| 15527 | * command to finish before continuing. |
| 15528 | * |
| 15529 | * On success this function will return a zero. If unable to allocate enough |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15530 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15531 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15532 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15533 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15534 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 15535 | struct lpfc_queue *cq, uint32_t subtype) |
| 15536 | { |
| 15537 | struct lpfc_mbx_wq_create *wq_create; |
| 15538 | struct lpfc_dmabuf *dmabuf; |
| 15539 | LPFC_MBOXQ_t *mbox; |
| 15540 | int rc, length, status = 0; |
| 15541 | uint32_t shdr_status, shdr_add_status; |
| 15542 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15543 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15544 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15545 | void __iomem *bar_memmap_p; |
| 15546 | uint32_t db_offset; |
| 15547 | uint16_t pci_barset; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15548 | uint8_t dpp_barset; |
| 15549 | uint32_t dpp_offset; |
| 15550 | unsigned long pg_addr; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15551 | uint8_t wq_create_version; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15552 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15553 | /* sanity check on queue memory */ |
| 15554 | if (!wq || !cq) |
| 15555 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15556 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15557 | hw_page_size = wq->page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15558 | |
| 15559 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15560 | if (!mbox) |
| 15561 | return -ENOMEM; |
| 15562 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 15563 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15564 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15565 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 15566 | length, LPFC_SLI4_MBX_EMBED); |
| 15567 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15568 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15569 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 15570 | wq->page_count); |
| 15571 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 15572 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15573 | |
| 15574 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15575 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15576 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15577 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 15578 | if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) || |
| 15579 | (wq->page_size > SLI4_PAGE_SIZE)) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15580 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15581 | else |
| 15582 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15583 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15584 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15585 | if (phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) |
| 15586 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15587 | else |
| 15588 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15589 | |
| 15590 | switch (wq_create_version) { |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15591 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15592 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 15593 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 15594 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15595 | LPFC_Q_CREATE_VERSION_1); |
| 15596 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15597 | switch (wq->entry_size) { |
| 15598 | default: |
| 15599 | case 64: |
| 15600 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15601 | &wq_create->u.request_1, |
| 15602 | LPFC_WQ_WQE_SIZE_64); |
| 15603 | break; |
| 15604 | case 128: |
| 15605 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15606 | &wq_create->u.request_1, |
| 15607 | LPFC_WQ_WQE_SIZE_128); |
| 15608 | break; |
| 15609 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15610 | /* Request DPP by default */ |
| 15611 | bf_set(lpfc_mbx_wq_create_dpp_req, &wq_create->u.request_1, 1); |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 15612 | bf_set(lpfc_mbx_wq_create_page_size, |
| 15613 | &wq_create->u.request_1, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15614 | (wq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15615 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15616 | break; |
| 15617 | default: |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15618 | page = wq_create->u.request.page; |
| 15619 | break; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15620 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15621 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15622 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15623 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15624 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 15625 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15626 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15627 | |
| 15628 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15629 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 15630 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15631 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15632 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15633 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15634 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15635 | if (shdr_status || shdr_add_status || rc) { |
| 15636 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15637 | "2503 WQ_CREATE mailbox failed with " |
| 15638 | "status x%x add_status x%x, mbx status x%x\n", |
| 15639 | shdr_status, shdr_add_status, rc); |
| 15640 | status = -ENXIO; |
| 15641 | goto out; |
| 15642 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15643 | |
| 15644 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) |
| 15645 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, |
| 15646 | &wq_create->u.response); |
| 15647 | else |
| 15648 | wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id, |
| 15649 | &wq_create->u.response_1); |
| 15650 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15651 | if (wq->queue_id == 0xFFFF) { |
| 15652 | status = -ENXIO; |
| 15653 | goto out; |
| 15654 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15655 | |
| 15656 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 15657 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) { |
| 15658 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15659 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 15660 | &wq_create->u.response); |
| 15661 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15662 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15663 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15664 | "3265 WQ[%d] doorbell format " |
| 15665 | "not supported: x%x\n", |
| 15666 | wq->queue_id, wq->db_format); |
| 15667 | status = -EINVAL; |
| 15668 | goto out; |
| 15669 | } |
| 15670 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 15671 | &wq_create->u.response); |
| 15672 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15673 | pci_barset); |
| 15674 | if (!bar_memmap_p) { |
| 15675 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15676 | "3263 WQ[%d] failed to memmap " |
| 15677 | "pci barset:x%x\n", |
| 15678 | wq->queue_id, pci_barset); |
| 15679 | status = -ENOMEM; |
| 15680 | goto out; |
| 15681 | } |
| 15682 | db_offset = wq_create->u.response.doorbell_offset; |
| 15683 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 15684 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 15685 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15686 | "3252 WQ[%d] doorbell offset " |
| 15687 | "not supported: x%x\n", |
| 15688 | wq->queue_id, db_offset); |
| 15689 | status = -EINVAL; |
| 15690 | goto out; |
| 15691 | } |
| 15692 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15693 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15694 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 15695 | "format:x%x\n", wq->queue_id, |
| 15696 | pci_barset, db_offset, wq->db_format); |
| 15697 | } else |
| 15698 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15699 | } else { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15700 | /* Check if DPP was honored by the firmware */ |
| 15701 | wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp, |
| 15702 | &wq_create->u.response_1); |
| 15703 | if (wq->dpp_enable) { |
| 15704 | pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set, |
| 15705 | &wq_create->u.response_1); |
| 15706 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15707 | pci_barset); |
| 15708 | if (!bar_memmap_p) { |
| 15709 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15710 | "3267 WQ[%d] failed to memmap " |
| 15711 | "pci barset:x%x\n", |
| 15712 | wq->queue_id, pci_barset); |
| 15713 | status = -ENOMEM; |
| 15714 | goto out; |
| 15715 | } |
| 15716 | db_offset = wq_create->u.response_1.doorbell_offset; |
| 15717 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15718 | wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id, |
| 15719 | &wq_create->u.response_1); |
| 15720 | dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar, |
| 15721 | &wq_create->u.response_1); |
| 15722 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15723 | dpp_barset); |
| 15724 | if (!bar_memmap_p) { |
| 15725 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15726 | "3268 WQ[%d] failed to memmap " |
| 15727 | "pci barset:x%x\n", |
| 15728 | wq->queue_id, dpp_barset); |
| 15729 | status = -ENOMEM; |
| 15730 | goto out; |
| 15731 | } |
| 15732 | dpp_offset = wq_create->u.response_1.dpp_offset; |
| 15733 | wq->dpp_regaddr = bar_memmap_p + dpp_offset; |
| 15734 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15735 | "3271 WQ[%d]: barset:x%x, offset:x%x, " |
| 15736 | "dpp_id:x%x dpp_barset:x%x " |
| 15737 | "dpp_offset:x%x\n", |
| 15738 | wq->queue_id, pci_barset, db_offset, |
| 15739 | wq->dpp_id, dpp_barset, dpp_offset); |
| 15740 | |
| 15741 | /* Enable combined writes for DPP aperture */ |
| 15742 | pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK; |
| 15743 | #ifdef CONFIG_X86 |
| 15744 | rc = set_memory_wc(pg_addr, 1); |
| 15745 | if (rc) { |
| 15746 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15747 | "3272 Cannot setup Combined " |
| 15748 | "Write on WQ[%d] - disable DPP\n", |
| 15749 | wq->queue_id); |
| 15750 | phba->cfg_enable_dpp = 0; |
| 15751 | } |
| 15752 | #else |
| 15753 | phba->cfg_enable_dpp = 0; |
| 15754 | #endif |
| 15755 | } else |
| 15756 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15757 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15758 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 15759 | if (wq->pring == NULL) { |
| 15760 | status = -ENOMEM; |
| 15761 | goto out; |
| 15762 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15763 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15764 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15765 | wq->subtype = subtype; |
| 15766 | wq->host_index = 0; |
| 15767 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 15768 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15769 | |
| 15770 | /* link the wq onto the parent cq child list */ |
| 15771 | list_add_tail(&wq->list, &cq->child_list); |
| 15772 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15773 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15774 | return status; |
| 15775 | } |
| 15776 | |
| 15777 | /** |
| 15778 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 15779 | * @phba: HBA structure that indicates port to create a queue on. |
| 15780 | * @hrq: The queue structure to use to create the header receive queue. |
| 15781 | * @drq: The queue structure to use to create the data receive queue. |
| 15782 | * @cq: The completion queue to bind this work queue to. |
| 15783 | * |
| 15784 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15785 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15786 | * to the HBA. |
| 15787 | * |
| 15788 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15789 | * struct is used to get the entry count that is necessary to determine the |
| 15790 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15791 | * completion queue to bind received buffers that are posted to these queues to. |
| 15792 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15793 | * receive queue pair. This function is asynchronous and will wait for the |
| 15794 | * mailbox command to finish before continuing. |
| 15795 | * |
| 15796 | * On success this function will return a zero. If unable to allocate enough |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 15797 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15798 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15799 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15800 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15801 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15802 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 15803 | { |
| 15804 | struct lpfc_mbx_rq_create *rq_create; |
| 15805 | struct lpfc_dmabuf *dmabuf; |
| 15806 | LPFC_MBOXQ_t *mbox; |
| 15807 | int rc, length, status = 0; |
| 15808 | uint32_t shdr_status, shdr_add_status; |
| 15809 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15810 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15811 | void __iomem *bar_memmap_p; |
| 15812 | uint32_t db_offset; |
| 15813 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15814 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15815 | /* sanity check on queue memory */ |
| 15816 | if (!hrq || !drq || !cq) |
| 15817 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15818 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15819 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15820 | |
| 15821 | if (hrq->entry_count != drq->entry_count) |
| 15822 | return -EINVAL; |
| 15823 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15824 | if (!mbox) |
| 15825 | return -ENOMEM; |
| 15826 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 15827 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15828 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15829 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15830 | length, LPFC_SLI4_MBX_EMBED); |
| 15831 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15832 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15833 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15834 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15835 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15836 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15837 | &rq_create->u.request.context, |
| 15838 | hrq->entry_count); |
| 15839 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15840 | bf_set(lpfc_rq_context_rqe_size, |
| 15841 | &rq_create->u.request.context, |
| 15842 | LPFC_RQE_SIZE_8); |
| 15843 | bf_set(lpfc_rq_context_page_size, |
| 15844 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 15845 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15846 | } else { |
| 15847 | switch (hrq->entry_count) { |
| 15848 | default: |
| 15849 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15850 | "2535 Unsupported RQ count. (%d)\n", |
| 15851 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15852 | if (hrq->entry_count < 512) { |
| 15853 | status = -EINVAL; |
| 15854 | goto out; |
| 15855 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15856 | /* otherwise default to smallest count (drop through) */ |
| 15857 | case 512: |
| 15858 | bf_set(lpfc_rq_context_rqe_count, |
| 15859 | &rq_create->u.request.context, |
| 15860 | LPFC_RQ_RING_SIZE_512); |
| 15861 | break; |
| 15862 | case 1024: |
| 15863 | bf_set(lpfc_rq_context_rqe_count, |
| 15864 | &rq_create->u.request.context, |
| 15865 | LPFC_RQ_RING_SIZE_1024); |
| 15866 | break; |
| 15867 | case 2048: |
| 15868 | bf_set(lpfc_rq_context_rqe_count, |
| 15869 | &rq_create->u.request.context, |
| 15870 | LPFC_RQ_RING_SIZE_2048); |
| 15871 | break; |
| 15872 | case 4096: |
| 15873 | bf_set(lpfc_rq_context_rqe_count, |
| 15874 | &rq_create->u.request.context, |
| 15875 | LPFC_RQ_RING_SIZE_4096); |
| 15876 | break; |
| 15877 | } |
| 15878 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 15879 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15880 | } |
| 15881 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15882 | cq->queue_id); |
| 15883 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15884 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15885 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15886 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15887 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15888 | putPaddrLow(dmabuf->phys); |
| 15889 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15890 | putPaddrHigh(dmabuf->phys); |
| 15891 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15892 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15893 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 15894 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15895 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15896 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15897 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15898 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15899 | if (shdr_status || shdr_add_status || rc) { |
| 15900 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15901 | "2504 RQ_CREATE mailbox failed with " |
| 15902 | "status x%x add_status x%x, mbx status x%x\n", |
| 15903 | shdr_status, shdr_add_status, rc); |
| 15904 | status = -ENXIO; |
| 15905 | goto out; |
| 15906 | } |
| 15907 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15908 | if (hrq->queue_id == 0xFFFF) { |
| 15909 | status = -ENXIO; |
| 15910 | goto out; |
| 15911 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15912 | |
| 15913 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15914 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 15915 | &rq_create->u.response); |
| 15916 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15917 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15918 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15919 | "3262 RQ [%d] doorbell format not " |
| 15920 | "supported: x%x\n", hrq->queue_id, |
| 15921 | hrq->db_format); |
| 15922 | status = -EINVAL; |
| 15923 | goto out; |
| 15924 | } |
| 15925 | |
| 15926 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 15927 | &rq_create->u.response); |
| 15928 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 15929 | if (!bar_memmap_p) { |
| 15930 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15931 | "3269 RQ[%d] failed to memmap pci " |
| 15932 | "barset:x%x\n", hrq->queue_id, |
| 15933 | pci_barset); |
| 15934 | status = -ENOMEM; |
| 15935 | goto out; |
| 15936 | } |
| 15937 | |
| 15938 | db_offset = rq_create->u.response.doorbell_offset; |
| 15939 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 15940 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 15941 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15942 | "3270 RQ[%d] doorbell offset not " |
| 15943 | "supported: x%x\n", hrq->queue_id, |
| 15944 | db_offset); |
| 15945 | status = -EINVAL; |
| 15946 | goto out; |
| 15947 | } |
| 15948 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 15949 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 15950 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 15951 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 15952 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15953 | } else { |
| 15954 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15955 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15956 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15957 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15958 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15959 | hrq->subtype = subtype; |
| 15960 | hrq->host_index = 0; |
| 15961 | hrq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15962 | hrq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15963 | |
| 15964 | /* now create the data queue */ |
| 15965 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15966 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15967 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15968 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15969 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15970 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15971 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15972 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15973 | if (subtype == LPFC_NVMET) |
| 15974 | rq_create->u.request.context.buffer_size = |
| 15975 | LPFC_NVMET_DATA_BUF_SIZE; |
| 15976 | else |
| 15977 | rq_create->u.request.context.buffer_size = |
| 15978 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15979 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 15980 | LPFC_RQE_SIZE_8); |
| 15981 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 15982 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15983 | } else { |
| 15984 | switch (drq->entry_count) { |
| 15985 | default: |
| 15986 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15987 | "2536 Unsupported RQ count. (%d)\n", |
| 15988 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15989 | if (drq->entry_count < 512) { |
| 15990 | status = -EINVAL; |
| 15991 | goto out; |
| 15992 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15993 | /* otherwise default to smallest count (drop through) */ |
| 15994 | case 512: |
| 15995 | bf_set(lpfc_rq_context_rqe_count, |
| 15996 | &rq_create->u.request.context, |
| 15997 | LPFC_RQ_RING_SIZE_512); |
| 15998 | break; |
| 15999 | case 1024: |
| 16000 | bf_set(lpfc_rq_context_rqe_count, |
| 16001 | &rq_create->u.request.context, |
| 16002 | LPFC_RQ_RING_SIZE_1024); |
| 16003 | break; |
| 16004 | case 2048: |
| 16005 | bf_set(lpfc_rq_context_rqe_count, |
| 16006 | &rq_create->u.request.context, |
| 16007 | LPFC_RQ_RING_SIZE_2048); |
| 16008 | break; |
| 16009 | case 4096: |
| 16010 | bf_set(lpfc_rq_context_rqe_count, |
| 16011 | &rq_create->u.request.context, |
| 16012 | LPFC_RQ_RING_SIZE_4096); |
| 16013 | break; |
| 16014 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16015 | if (subtype == LPFC_NVMET) |
| 16016 | bf_set(lpfc_rq_context_buf_size, |
| 16017 | &rq_create->u.request.context, |
| 16018 | LPFC_NVMET_DATA_BUF_SIZE); |
| 16019 | else |
| 16020 | bf_set(lpfc_rq_context_buf_size, |
| 16021 | &rq_create->u.request.context, |
| 16022 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16023 | } |
| 16024 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 16025 | cq->queue_id); |
| 16026 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 16027 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16028 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 16029 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 16030 | putPaddrLow(dmabuf->phys); |
| 16031 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 16032 | putPaddrHigh(dmabuf->phys); |
| 16033 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16034 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 16035 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16036 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16037 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16038 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 16039 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16040 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16041 | if (shdr_status || shdr_add_status || rc) { |
| 16042 | status = -ENXIO; |
| 16043 | goto out; |
| 16044 | } |
| 16045 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16046 | if (drq->queue_id == 0xFFFF) { |
| 16047 | status = -ENXIO; |
| 16048 | goto out; |
| 16049 | } |
| 16050 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 16051 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16052 | drq->subtype = subtype; |
| 16053 | drq->host_index = 0; |
| 16054 | drq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 16055 | drq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16056 | |
| 16057 | /* link the header and data RQs onto the parent cq child list */ |
| 16058 | list_add_tail(&hrq->list, &cq->child_list); |
| 16059 | list_add_tail(&drq->list, &cq->child_list); |
| 16060 | |
| 16061 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16062 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16063 | return status; |
| 16064 | } |
| 16065 | |
| 16066 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16067 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 16068 | * @phba: HBA structure that indicates port to create a queue on. |
| 16069 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 16070 | * @drqp: The queue structure array to use to create the data receive queues. |
| 16071 | * @cqp: The completion queue array to bind these receive queues to. |
| 16072 | * |
| 16073 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 16074 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 16075 | * to the HBA. |
| 16076 | * |
| 16077 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 16078 | * struct is used to get the entry count that is necessary to determine the |
| 16079 | * number of pages to use for this queue. The @cq is used to indicate which |
| 16080 | * completion queue to bind received buffers that are posted to these queues to. |
| 16081 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 16082 | * receive queue pair. This function is asynchronous and will wait for the |
| 16083 | * mailbox command to finish before continuing. |
| 16084 | * |
| 16085 | * On success this function will return a zero. If unable to allocate enough |
| 16086 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 16087 | * fails this function will return -ENXIO. |
| 16088 | **/ |
| 16089 | int |
| 16090 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 16091 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 16092 | uint32_t subtype) |
| 16093 | { |
| 16094 | struct lpfc_queue *hrq, *drq, *cq; |
| 16095 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 16096 | struct lpfc_dmabuf *dmabuf; |
| 16097 | LPFC_MBOXQ_t *mbox; |
| 16098 | int rc, length, alloclen, status = 0; |
| 16099 | int cnt, idx, numrq, page_idx = 0; |
| 16100 | uint32_t shdr_status, shdr_add_status; |
| 16101 | union lpfc_sli4_cfg_shdr *shdr; |
| 16102 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 16103 | |
| 16104 | numrq = phba->cfg_nvmet_mrq; |
| 16105 | /* sanity check on array memory */ |
| 16106 | if (!hrqp || !drqp || !cqp || !numrq) |
| 16107 | return -ENODEV; |
| 16108 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 16109 | hw_page_size = SLI4_PAGE_SIZE; |
| 16110 | |
| 16111 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16112 | if (!mbox) |
| 16113 | return -ENOMEM; |
| 16114 | |
| 16115 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 16116 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 16117 | sizeof(struct dma_address)); |
| 16118 | |
| 16119 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16120 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 16121 | LPFC_SLI4_MBX_NEMBED); |
| 16122 | if (alloclen < length) { |
| 16123 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16124 | "3099 Allocated DMA memory size (%d) is " |
| 16125 | "less than the requested DMA memory size " |
| 16126 | "(%d)\n", alloclen, length); |
| 16127 | status = -ENOMEM; |
| 16128 | goto out; |
| 16129 | } |
| 16130 | |
| 16131 | |
| 16132 | |
| 16133 | rq_create = mbox->sge_array->addr[0]; |
| 16134 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 16135 | |
| 16136 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 16137 | cnt = 0; |
| 16138 | |
| 16139 | for (idx = 0; idx < numrq; idx++) { |
| 16140 | hrq = hrqp[idx]; |
| 16141 | drq = drqp[idx]; |
| 16142 | cq = cqp[idx]; |
| 16143 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16144 | /* sanity check on queue memory */ |
| 16145 | if (!hrq || !drq || !cq) { |
| 16146 | status = -ENODEV; |
| 16147 | goto out; |
| 16148 | } |
| 16149 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 16150 | if (hrq->entry_count != drq->entry_count) { |
| 16151 | status = -EINVAL; |
| 16152 | goto out; |
| 16153 | } |
| 16154 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16155 | if (idx == 0) { |
| 16156 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 16157 | &rq_create->u.request, |
| 16158 | hrq->page_count); |
| 16159 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 16160 | &rq_create->u.request, (numrq * 2)); |
| 16161 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 16162 | 1); |
| 16163 | bf_set(lpfc_rq_context_base_cq, |
| 16164 | &rq_create->u.request.context, |
| 16165 | cq->queue_id); |
| 16166 | bf_set(lpfc_rq_context_data_size, |
| 16167 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16168 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16169 | bf_set(lpfc_rq_context_hdr_size, |
| 16170 | &rq_create->u.request.context, |
| 16171 | LPFC_HDR_BUF_SIZE); |
| 16172 | bf_set(lpfc_rq_context_rqe_count_1, |
| 16173 | &rq_create->u.request.context, |
| 16174 | hrq->entry_count); |
| 16175 | bf_set(lpfc_rq_context_rqe_size, |
| 16176 | &rq_create->u.request.context, |
| 16177 | LPFC_RQE_SIZE_8); |
| 16178 | bf_set(lpfc_rq_context_page_size, |
| 16179 | &rq_create->u.request.context, |
| 16180 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 16181 | } |
| 16182 | rc = 0; |
| 16183 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 16184 | memset(dmabuf->virt, 0, hw_page_size); |
| 16185 | cnt = page_idx + dmabuf->buffer_tag; |
| 16186 | rq_create->u.request.page[cnt].addr_lo = |
| 16187 | putPaddrLow(dmabuf->phys); |
| 16188 | rq_create->u.request.page[cnt].addr_hi = |
| 16189 | putPaddrHigh(dmabuf->phys); |
| 16190 | rc++; |
| 16191 | } |
| 16192 | page_idx += rc; |
| 16193 | |
| 16194 | rc = 0; |
| 16195 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 16196 | memset(dmabuf->virt, 0, hw_page_size); |
| 16197 | cnt = page_idx + dmabuf->buffer_tag; |
| 16198 | rq_create->u.request.page[cnt].addr_lo = |
| 16199 | putPaddrLow(dmabuf->phys); |
| 16200 | rq_create->u.request.page[cnt].addr_hi = |
| 16201 | putPaddrHigh(dmabuf->phys); |
| 16202 | rc++; |
| 16203 | } |
| 16204 | page_idx += rc; |
| 16205 | |
| 16206 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 16207 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16208 | hrq->type = LPFC_HRQ; |
| 16209 | hrq->assoc_qid = cq->queue_id; |
| 16210 | hrq->subtype = subtype; |
| 16211 | hrq->host_index = 0; |
| 16212 | hrq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 16213 | hrq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16214 | |
| 16215 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 16216 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16217 | drq->type = LPFC_DRQ; |
| 16218 | drq->assoc_qid = cq->queue_id; |
| 16219 | drq->subtype = subtype; |
| 16220 | drq->host_index = 0; |
| 16221 | drq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 16222 | drq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16223 | |
| 16224 | list_add_tail(&hrq->list, &cq->child_list); |
| 16225 | list_add_tail(&drq->list, &cq->child_list); |
| 16226 | } |
| 16227 | |
| 16228 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16229 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16230 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16231 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16232 | if (shdr_status || shdr_add_status || rc) { |
| 16233 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16234 | "3120 RQ_CREATE mailbox failed with " |
| 16235 | "status x%x add_status x%x, mbx status x%x\n", |
| 16236 | shdr_status, shdr_add_status, rc); |
| 16237 | status = -ENXIO; |
| 16238 | goto out; |
| 16239 | } |
| 16240 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16241 | if (rc == 0xFFFF) { |
| 16242 | status = -ENXIO; |
| 16243 | goto out; |
| 16244 | } |
| 16245 | |
| 16246 | /* Initialize all RQs with associated queue id */ |
| 16247 | for (idx = 0; idx < numrq; idx++) { |
| 16248 | hrq = hrqp[idx]; |
| 16249 | hrq->queue_id = rc + (2 * idx); |
| 16250 | drq = drqp[idx]; |
| 16251 | drq->queue_id = rc + (2 * idx) + 1; |
| 16252 | } |
| 16253 | |
| 16254 | out: |
| 16255 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16256 | return status; |
| 16257 | } |
| 16258 | |
| 16259 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16260 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 16261 | * @eq: The queue structure associated with the queue to destroy. |
| 16262 | * |
| 16263 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 16264 | * command, specific to the type of queue, to the HBA. |
| 16265 | * |
| 16266 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 16267 | * |
| 16268 | * On success this function will return a zero. If the queue destroy mailbox |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16269 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16270 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16271 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16272 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 16273 | { |
| 16274 | LPFC_MBOXQ_t *mbox; |
| 16275 | int rc, length, status = 0; |
| 16276 | uint32_t shdr_status, shdr_add_status; |
| 16277 | union lpfc_sli4_cfg_shdr *shdr; |
| 16278 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16279 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16280 | if (!eq) |
| 16281 | return -ENODEV; |
| 16282 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16283 | if (!mbox) |
| 16284 | return -ENOMEM; |
| 16285 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 16286 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16287 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16288 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 16289 | length, LPFC_SLI4_MBX_EMBED); |
| 16290 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 16291 | eq->queue_id); |
| 16292 | mbox->vport = eq->phba->pport; |
| 16293 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16294 | |
| 16295 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 16296 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16297 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16298 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 16299 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16300 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16301 | if (shdr_status || shdr_add_status || rc) { |
| 16302 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16303 | "2505 EQ_DESTROY mailbox failed with " |
| 16304 | "status x%x add_status x%x, mbx status x%x\n", |
| 16305 | shdr_status, shdr_add_status, rc); |
| 16306 | status = -ENXIO; |
| 16307 | } |
| 16308 | |
| 16309 | /* Remove eq from any list */ |
| 16310 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16311 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16312 | return status; |
| 16313 | } |
| 16314 | |
| 16315 | /** |
| 16316 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 16317 | * @cq: The queue structure associated with the queue to destroy. |
| 16318 | * |
| 16319 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 16320 | * command, specific to the type of queue, to the HBA. |
| 16321 | * |
| 16322 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 16323 | * |
| 16324 | * On success this function will return a zero. If the queue destroy mailbox |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16325 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16326 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16327 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16328 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 16329 | { |
| 16330 | LPFC_MBOXQ_t *mbox; |
| 16331 | int rc, length, status = 0; |
| 16332 | uint32_t shdr_status, shdr_add_status; |
| 16333 | union lpfc_sli4_cfg_shdr *shdr; |
| 16334 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16335 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16336 | if (!cq) |
| 16337 | return -ENODEV; |
| 16338 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16339 | if (!mbox) |
| 16340 | return -ENOMEM; |
| 16341 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 16342 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16343 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16344 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 16345 | length, LPFC_SLI4_MBX_EMBED); |
| 16346 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 16347 | cq->queue_id); |
| 16348 | mbox->vport = cq->phba->pport; |
| 16349 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16350 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 16351 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16352 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16353 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 16354 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16355 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16356 | if (shdr_status || shdr_add_status || rc) { |
| 16357 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16358 | "2506 CQ_DESTROY mailbox failed with " |
| 16359 | "status x%x add_status x%x, mbx status x%x\n", |
| 16360 | shdr_status, shdr_add_status, rc); |
| 16361 | status = -ENXIO; |
| 16362 | } |
| 16363 | /* Remove cq from any list */ |
| 16364 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16365 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16366 | return status; |
| 16367 | } |
| 16368 | |
| 16369 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16370 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 16371 | * @qm: The queue structure associated with the queue to destroy. |
| 16372 | * |
| 16373 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 16374 | * command, specific to the type of queue, to the HBA. |
| 16375 | * |
| 16376 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 16377 | * |
| 16378 | * On success this function will return a zero. If the queue destroy mailbox |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16379 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16380 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16381 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16382 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 16383 | { |
| 16384 | LPFC_MBOXQ_t *mbox; |
| 16385 | int rc, length, status = 0; |
| 16386 | uint32_t shdr_status, shdr_add_status; |
| 16387 | union lpfc_sli4_cfg_shdr *shdr; |
| 16388 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16389 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16390 | if (!mq) |
| 16391 | return -ENODEV; |
| 16392 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16393 | if (!mbox) |
| 16394 | return -ENOMEM; |
| 16395 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 16396 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16397 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16398 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 16399 | length, LPFC_SLI4_MBX_EMBED); |
| 16400 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 16401 | mq->queue_id); |
| 16402 | mbox->vport = mq->phba->pport; |
| 16403 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16404 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 16405 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16406 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16407 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 16408 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16409 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16410 | if (shdr_status || shdr_add_status || rc) { |
| 16411 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16412 | "2507 MQ_DESTROY mailbox failed with " |
| 16413 | "status x%x add_status x%x, mbx status x%x\n", |
| 16414 | shdr_status, shdr_add_status, rc); |
| 16415 | status = -ENXIO; |
| 16416 | } |
| 16417 | /* Remove mq from any list */ |
| 16418 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16419 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16420 | return status; |
| 16421 | } |
| 16422 | |
| 16423 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16424 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 16425 | * @wq: The queue structure associated with the queue to destroy. |
| 16426 | * |
| 16427 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 16428 | * command, specific to the type of queue, to the HBA. |
| 16429 | * |
| 16430 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 16431 | * |
| 16432 | * On success this function will return a zero. If the queue destroy mailbox |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16433 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16434 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16435 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16436 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 16437 | { |
| 16438 | LPFC_MBOXQ_t *mbox; |
| 16439 | int rc, length, status = 0; |
| 16440 | uint32_t shdr_status, shdr_add_status; |
| 16441 | union lpfc_sli4_cfg_shdr *shdr; |
| 16442 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16443 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16444 | if (!wq) |
| 16445 | return -ENODEV; |
| 16446 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16447 | if (!mbox) |
| 16448 | return -ENOMEM; |
| 16449 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 16450 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16451 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16452 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 16453 | length, LPFC_SLI4_MBX_EMBED); |
| 16454 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 16455 | wq->queue_id); |
| 16456 | mbox->vport = wq->phba->pport; |
| 16457 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16458 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 16459 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16460 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 16461 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16462 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16463 | if (shdr_status || shdr_add_status || rc) { |
| 16464 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16465 | "2508 WQ_DESTROY mailbox failed with " |
| 16466 | "status x%x add_status x%x, mbx status x%x\n", |
| 16467 | shdr_status, shdr_add_status, rc); |
| 16468 | status = -ENXIO; |
| 16469 | } |
| 16470 | /* Remove wq from any list */ |
| 16471 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 16472 | kfree(wq->pring); |
| 16473 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16474 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16475 | return status; |
| 16476 | } |
| 16477 | |
| 16478 | /** |
| 16479 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 16480 | * @rq: The queue structure associated with the queue to destroy. |
| 16481 | * |
| 16482 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 16483 | * command, specific to the type of queue, to the HBA. |
| 16484 | * |
| 16485 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 16486 | * |
| 16487 | * On success this function will return a zero. If the queue destroy mailbox |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16488 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16489 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16490 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16491 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 16492 | struct lpfc_queue *drq) |
| 16493 | { |
| 16494 | LPFC_MBOXQ_t *mbox; |
| 16495 | int rc, length, status = 0; |
| 16496 | uint32_t shdr_status, shdr_add_status; |
| 16497 | union lpfc_sli4_cfg_shdr *shdr; |
| 16498 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16499 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16500 | if (!hrq || !drq) |
| 16501 | return -ENODEV; |
| 16502 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16503 | if (!mbox) |
| 16504 | return -ENOMEM; |
| 16505 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16506 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16507 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16508 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 16509 | length, LPFC_SLI4_MBX_EMBED); |
| 16510 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16511 | hrq->queue_id); |
| 16512 | mbox->vport = hrq->phba->pport; |
| 16513 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16514 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 16515 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16516 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16517 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16518 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16519 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16520 | if (shdr_status || shdr_add_status || rc) { |
| 16521 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16522 | "2509 RQ_DESTROY mailbox failed with " |
| 16523 | "status x%x add_status x%x, mbx status x%x\n", |
| 16524 | shdr_status, shdr_add_status, rc); |
| 16525 | if (rc != MBX_TIMEOUT) |
| 16526 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 16527 | return -ENXIO; |
| 16528 | } |
| 16529 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16530 | drq->queue_id); |
| 16531 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 16532 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16533 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16534 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16535 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16536 | if (shdr_status || shdr_add_status || rc) { |
| 16537 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16538 | "2510 RQ_DESTROY mailbox failed with " |
| 16539 | "status x%x add_status x%x, mbx status x%x\n", |
| 16540 | shdr_status, shdr_add_status, rc); |
| 16541 | status = -ENXIO; |
| 16542 | } |
| 16543 | list_del_init(&hrq->list); |
| 16544 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16545 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16546 | return status; |
| 16547 | } |
| 16548 | |
| 16549 | /** |
| 16550 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 16551 | * @phba: The virtual port for which this call being executed. |
| 16552 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 16553 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 16554 | * @xritag: the xritag that ties this io to the SGL pages. |
| 16555 | * |
| 16556 | * This routine will post the sgl pages for the IO that has the xritag |
| 16557 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 16558 | * creation and persists for as long as the driver is loaded. |
| 16559 | * if the caller has fewer than 256 scatter gather segments to map then |
| 16560 | * pdma_phys_addr1 should be 0. |
| 16561 | * If the caller needs to map more than 256 scatter gather segment then |
| 16562 | * pdma_phys_addr1 should be a valid physical address. |
| 16563 | * physical address for SGLs must be 64 byte aligned. |
| 16564 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 16565 | * the second sgl can have between 1 and 256 entries. |
| 16566 | * |
| 16567 | * Return codes: |
| 16568 | * 0 - Success |
| 16569 | * -ENXIO, -ENOMEM - Failure |
| 16570 | **/ |
| 16571 | int |
| 16572 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 16573 | dma_addr_t pdma_phys_addr0, |
| 16574 | dma_addr_t pdma_phys_addr1, |
| 16575 | uint16_t xritag) |
| 16576 | { |
| 16577 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 16578 | LPFC_MBOXQ_t *mbox; |
| 16579 | int rc; |
| 16580 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16581 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16582 | union lpfc_sli4_cfg_shdr *shdr; |
| 16583 | |
| 16584 | if (xritag == NO_XRI) { |
| 16585 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16586 | "0364 Invalid param:\n"); |
| 16587 | return -EINVAL; |
| 16588 | } |
| 16589 | |
| 16590 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16591 | if (!mbox) |
| 16592 | return -ENOMEM; |
| 16593 | |
| 16594 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16595 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16596 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16597 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16598 | |
| 16599 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 16600 | &mbox->u.mqe.un.post_sgl_pages; |
| 16601 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 16602 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 16603 | |
| 16604 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 16605 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 16606 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 16607 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 16608 | |
| 16609 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 16610 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 16611 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 16612 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 16613 | if (!phba->sli4_hba.intr_enable) |
| 16614 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16615 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16616 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16617 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16618 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16619 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16620 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 16621 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16622 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16623 | if (rc != MBX_TIMEOUT) |
| 16624 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16625 | if (shdr_status || shdr_add_status || rc) { |
| 16626 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16627 | "2511 POST_SGL mailbox failed with " |
| 16628 | "status x%x add_status x%x, mbx status x%x\n", |
| 16629 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16630 | } |
| 16631 | return 0; |
| 16632 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16633 | |
| 16634 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16635 | * lpfc_sli4_alloc_xri - Get an available rpi in the device's range |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16636 | * @phba: pointer to lpfc hba data structure. |
| 16637 | * |
| 16638 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16639 | * HBA consistent with the SLI-4 interface spec. This routine |
| 16640 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 16641 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16642 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16643 | * Returns |
| 16644 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 16645 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 16646 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16647 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16648 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 16649 | { |
| 16650 | unsigned long xri; |
| 16651 | |
| 16652 | /* |
| 16653 | * Fetch the next logical xri. Because this index is logical, |
| 16654 | * the driver starts at 0 each time. |
| 16655 | */ |
| 16656 | spin_lock_irq(&phba->hbalock); |
| 16657 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 16658 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 16659 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 16660 | spin_unlock_irq(&phba->hbalock); |
| 16661 | return NO_XRI; |
| 16662 | } else { |
| 16663 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 16664 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16665 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16666 | spin_unlock_irq(&phba->hbalock); |
| 16667 | return xri; |
| 16668 | } |
| 16669 | |
| 16670 | /** |
| 16671 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16672 | * @phba: pointer to lpfc hba data structure. |
| 16673 | * |
| 16674 | * This routine is invoked to release an xri to the pool of |
| 16675 | * available rpis maintained by the driver. |
| 16676 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16677 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16678 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16679 | { |
| 16680 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16681 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 16682 | } |
| 16683 | } |
| 16684 | |
| 16685 | /** |
| 16686 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16687 | * @phba: pointer to lpfc hba data structure. |
| 16688 | * |
| 16689 | * This routine is invoked to release an xri to the pool of |
| 16690 | * available rpis maintained by the driver. |
| 16691 | **/ |
| 16692 | void |
| 16693 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16694 | { |
| 16695 | spin_lock_irq(&phba->hbalock); |
| 16696 | __lpfc_sli4_free_xri(phba, xri); |
| 16697 | spin_unlock_irq(&phba->hbalock); |
| 16698 | } |
| 16699 | |
| 16700 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16701 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 16702 | * @phba: Pointer to HBA context object. |
| 16703 | * |
| 16704 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 16705 | * it will return 0xffff. |
| 16706 | * The function returns the allocated xritag if successful, else returns zero. |
| 16707 | * Zero is not a valid xritag. |
| 16708 | * The caller is not required to hold any lock. |
| 16709 | **/ |
| 16710 | uint16_t |
| 16711 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 16712 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16713 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16714 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16715 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 16716 | if (xri_index == NO_XRI) |
| 16717 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 16718 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 16719 | " Max XRI is %d, Used XRI is %d\n", |
| 16720 | xri_index, |
| 16721 | phba->sli4_hba.max_cfg_param.max_xri, |
| 16722 | phba->sli4_hba.max_cfg_param.xri_used); |
| 16723 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16724 | } |
| 16725 | |
| 16726 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16727 | * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16728 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16729 | * @post_sgl_list: pointer to els sgl entry list. |
| 16730 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16731 | * |
| 16732 | * This routine is invoked to post a block of driver's sgl pages to the |
| 16733 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 16734 | * is only called when the driver is loading and after all IO has been |
| 16735 | * stopped. |
| 16736 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16737 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16738 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16739 | struct list_head *post_sgl_list, |
| 16740 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16741 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16742 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16743 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16744 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16745 | void *viraddr; |
| 16746 | LPFC_MBOXQ_t *mbox; |
| 16747 | uint32_t reqlen, alloclen, pg_pairs; |
| 16748 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16749 | uint16_t xritag_start = 0; |
| 16750 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16751 | uint32_t shdr_status, shdr_add_status; |
| 16752 | union lpfc_sli4_cfg_shdr *shdr; |
| 16753 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16754 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16755 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16756 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16757 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16758 | "2559 Block sgl registration required DMA " |
| 16759 | "size (%d) great than a page\n", reqlen); |
| 16760 | return -ENOMEM; |
| 16761 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16762 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16763 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16764 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16765 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16766 | |
| 16767 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16768 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16769 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16770 | LPFC_SLI4_MBX_NEMBED); |
| 16771 | |
| 16772 | if (alloclen < reqlen) { |
| 16773 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16774 | "0285 Allocated DMA memory size (%d) is " |
| 16775 | "less than the requested DMA memory " |
| 16776 | "size (%d)\n", alloclen, reqlen); |
| 16777 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16778 | return -ENOMEM; |
| 16779 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16780 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16781 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16782 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16783 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16784 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16785 | pg_pairs = 0; |
| 16786 | list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16787 | /* Set up the sge entry */ |
| 16788 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16789 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 16790 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16791 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 16792 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16793 | cpu_to_le32(putPaddrLow(0)); |
| 16794 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16795 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16796 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16797 | /* Keep the first xritag on the list */ |
| 16798 | if (pg_pairs == 0) |
| 16799 | xritag_start = sglq_entry->sli4_xritag; |
| 16800 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16801 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16802 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16803 | |
| 16804 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16805 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16806 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16807 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16808 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16809 | if (!phba->sli4_hba.intr_enable) |
| 16810 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16811 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16812 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16813 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16814 | } |
| 16815 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16816 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16817 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16818 | if (rc != MBX_TIMEOUT) |
| 16819 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16820 | if (shdr_status || shdr_add_status || rc) { |
| 16821 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16822 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 16823 | "status x%x add_status x%x mbx status x%x\n", |
| 16824 | shdr_status, shdr_add_status, rc); |
| 16825 | rc = -ENXIO; |
| 16826 | } |
| 16827 | return rc; |
| 16828 | } |
| 16829 | |
| 16830 | /** |
| 16831 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 16832 | * @phba: pointer to lpfc hba data structure. |
| 16833 | * @sblist: pointer to scsi buffer list. |
| 16834 | * @count: number of scsi buffers on the list. |
| 16835 | * |
| 16836 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 16837 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 16838 | * No Lock is held. |
| 16839 | * |
| 16840 | **/ |
| 16841 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16842 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 16843 | struct list_head *sblist, |
| 16844 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16845 | { |
| 16846 | struct lpfc_scsi_buf *psb; |
| 16847 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16848 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16849 | void *viraddr; |
| 16850 | LPFC_MBOXQ_t *mbox; |
| 16851 | uint32_t reqlen, alloclen, pg_pairs; |
| 16852 | uint32_t mbox_tmo; |
| 16853 | uint16_t xritag_start = 0; |
| 16854 | int rc = 0; |
| 16855 | uint32_t shdr_status, shdr_add_status; |
| 16856 | dma_addr_t pdma_phys_bpl1; |
| 16857 | union lpfc_sli4_cfg_shdr *shdr; |
| 16858 | |
| 16859 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16860 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16861 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16862 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16863 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 16864 | "0217 Block sgl registration required DMA " |
| 16865 | "size (%d) great than a page\n", reqlen); |
| 16866 | return -ENOMEM; |
| 16867 | } |
| 16868 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16869 | if (!mbox) { |
| 16870 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16871 | "0283 Failed to allocate mbox cmd memory\n"); |
| 16872 | return -ENOMEM; |
| 16873 | } |
| 16874 | |
| 16875 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16876 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16877 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16878 | LPFC_SLI4_MBX_NEMBED); |
| 16879 | |
| 16880 | if (alloclen < reqlen) { |
| 16881 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16882 | "2561 Allocated DMA memory size (%d) is " |
| 16883 | "less than the requested DMA memory " |
| 16884 | "size (%d)\n", alloclen, reqlen); |
| 16885 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16886 | return -ENOMEM; |
| 16887 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16888 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16889 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16890 | viraddr = mbox->sge_array->addr[0]; |
| 16891 | |
| 16892 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 16893 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16894 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16895 | |
| 16896 | pg_pairs = 0; |
| 16897 | list_for_each_entry(psb, sblist, list) { |
| 16898 | /* Set up the sge entry */ |
| 16899 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16900 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 16901 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16902 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 16903 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 16904 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 16905 | else |
| 16906 | pdma_phys_bpl1 = 0; |
| 16907 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16908 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 16909 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16910 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 16911 | /* Keep the first xritag on the list */ |
| 16912 | if (pg_pairs == 0) |
| 16913 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 16914 | sgl_pg_pairs++; |
| 16915 | pg_pairs++; |
| 16916 | } |
| 16917 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 16918 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 16919 | /* Perform endian conversion if necessary */ |
| 16920 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 16921 | |
| 16922 | if (!phba->sli4_hba.intr_enable) |
| 16923 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16924 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16925 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16926 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16927 | } |
| 16928 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16929 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16930 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16931 | if (rc != MBX_TIMEOUT) |
| 16932 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16933 | if (shdr_status || shdr_add_status || rc) { |
| 16934 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16935 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 16936 | "status x%x add_status x%x mbx status x%x\n", |
| 16937 | shdr_status, shdr_add_status, rc); |
| 16938 | rc = -ENXIO; |
| 16939 | } |
| 16940 | return rc; |
| 16941 | } |
| 16942 | |
| 16943 | /** |
| 16944 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 16945 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 16946 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16947 | * |
| 16948 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 16949 | * valid type of frame that the LPFC driver will handle. This function will |
| 16950 | * return a zero if the frame is a valid frame or a non zero value when the |
| 16951 | * frame does not pass the check. |
| 16952 | **/ |
| 16953 | static int |
| 16954 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 16955 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 16956 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16957 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16958 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16959 | |
| 16960 | switch (fc_hdr->fh_r_ctl) { |
| 16961 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 16962 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 16963 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 16964 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 16965 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 16966 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 16967 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 16968 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 16969 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 16970 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 16971 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 16972 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 16973 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 16974 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 16975 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 16976 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 16977 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 16978 | case FC_RCTL_BA_PRMT: |
| 16979 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 16980 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 16981 | case FC_RCTL_P_RJT: /* port reject */ |
| 16982 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 16983 | case FC_RCTL_P_BSY: /* port busy */ |
| 16984 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 16985 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 16986 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16987 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16988 | case FC_RCTL_END: /* end */ |
| 16989 | break; |
| 16990 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 16991 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16992 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 16993 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 16994 | default: |
| 16995 | goto drop; |
| 16996 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16997 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16998 | switch (fc_hdr->fh_type) { |
| 16999 | case FC_TYPE_BLS: |
| 17000 | case FC_TYPE_ELS: |
| 17001 | case FC_TYPE_FCP: |
| 17002 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17003 | case FC_TYPE_NVME: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17004 | break; |
| 17005 | case FC_TYPE_IP: |
| 17006 | case FC_TYPE_ILS: |
| 17007 | default: |
| 17008 | goto drop; |
| 17009 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17010 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17011 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17012 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 17013 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17014 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 17015 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 17016 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 17017 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 17018 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17019 | return 0; |
| 17020 | drop: |
| 17021 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17022 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 17023 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17024 | return 1; |
| 17025 | } |
| 17026 | |
| 17027 | /** |
| 17028 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 17029 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17030 | * |
| 17031 | * This function processes the FC header to retrieve the VFI from the VF |
| 17032 | * header, if one exists. This function will return the VFI if one exists |
| 17033 | * or 0 if no VSAN Header exists. |
| 17034 | **/ |
| 17035 | static uint32_t |
| 17036 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 17037 | { |
| 17038 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 17039 | |
| 17040 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 17041 | return 0; |
| 17042 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 17043 | } |
| 17044 | |
| 17045 | /** |
| 17046 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 17047 | * @phba: Pointer to the HBA structure to search for the vport on |
| 17048 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17049 | * @fcfi: The FC Fabric ID that the frame came from |
| 17050 | * |
| 17051 | * This function searches the @phba for a vport that matches the content of the |
| 17052 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 17053 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 17054 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 17055 | * vport. |
| 17056 | **/ |
| 17057 | static struct lpfc_vport * |
| 17058 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17059 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17060 | { |
| 17061 | struct lpfc_vport **vports; |
| 17062 | struct lpfc_vport *vport = NULL; |
| 17063 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17064 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 17065 | if (did == Fabric_DID) |
| 17066 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17067 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 17068 | !(phba->link_state == LPFC_HBA_READY)) |
| 17069 | return phba->pport; |
| 17070 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17071 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17072 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17073 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 17074 | if (phba->fcf.fcfi == fcfi && |
| 17075 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 17076 | vports[i]->fc_myDID == did) { |
| 17077 | vport = vports[i]; |
| 17078 | break; |
| 17079 | } |
| 17080 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17081 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17082 | lpfc_destroy_vport_work_array(phba, vports); |
| 17083 | return vport; |
| 17084 | } |
| 17085 | |
| 17086 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17087 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 17088 | * @vport: The vport to work on. |
| 17089 | * |
| 17090 | * This function updates the receive sequence time stamp for this vport. The |
| 17091 | * receive sequence time stamp indicates the time that the last frame of the |
| 17092 | * the sequence that has been idle for the longest amount of time was received. |
| 17093 | * the driver uses this time stamp to indicate if any received sequences have |
| 17094 | * timed out. |
| 17095 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17096 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17097 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 17098 | { |
| 17099 | struct lpfc_dmabuf *h_buf; |
| 17100 | struct hbq_dmabuf *dmabuf = NULL; |
| 17101 | |
| 17102 | /* get the oldest sequence on the rcv list */ |
| 17103 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 17104 | struct lpfc_dmabuf, list); |
| 17105 | if (!h_buf) |
| 17106 | return; |
| 17107 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17108 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 17109 | } |
| 17110 | |
| 17111 | /** |
| 17112 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 17113 | * @vport: The vport that the received sequences were sent to. |
| 17114 | * |
| 17115 | * This function cleans up all outstanding received sequences. This is called |
| 17116 | * by the driver when a link event or user action invalidates all the received |
| 17117 | * sequences. |
| 17118 | **/ |
| 17119 | void |
| 17120 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 17121 | { |
| 17122 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17123 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17124 | struct hbq_dmabuf *dmabuf = NULL; |
| 17125 | |
| 17126 | /* start with the oldest sequence on the rcv list */ |
| 17127 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17128 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17129 | list_del_init(&dmabuf->hbuf.list); |
| 17130 | list_for_each_entry_safe(d_buf, dnext, |
| 17131 | &dmabuf->dbuf.list, list) { |
| 17132 | list_del_init(&d_buf->list); |
| 17133 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17134 | } |
| 17135 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17136 | } |
| 17137 | } |
| 17138 | |
| 17139 | /** |
| 17140 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 17141 | * @vport: The vport that the received sequences were sent to. |
| 17142 | * |
| 17143 | * This function determines whether any received sequences have timed out by |
| 17144 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 17145 | * indicates that there is at least one timed out sequence this routine will |
| 17146 | * go through the received sequences one at a time from most inactive to most |
| 17147 | * active to determine which ones need to be cleaned up. Once it has determined |
| 17148 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 17149 | * without sending an abort. |
| 17150 | **/ |
| 17151 | void |
| 17152 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 17153 | { |
| 17154 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17155 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17156 | struct hbq_dmabuf *dmabuf = NULL; |
| 17157 | unsigned long timeout; |
| 17158 | int abort_count = 0; |
| 17159 | |
| 17160 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17161 | vport->rcv_buffer_time_stamp); |
| 17162 | if (list_empty(&vport->rcv_buffer_list) || |
| 17163 | time_before(jiffies, timeout)) |
| 17164 | return; |
| 17165 | /* start with the oldest sequence on the rcv list */ |
| 17166 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17167 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17168 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17169 | dmabuf->time_stamp); |
| 17170 | if (time_before(jiffies, timeout)) |
| 17171 | break; |
| 17172 | abort_count++; |
| 17173 | list_del_init(&dmabuf->hbuf.list); |
| 17174 | list_for_each_entry_safe(d_buf, dnext, |
| 17175 | &dmabuf->dbuf.list, list) { |
| 17176 | list_del_init(&d_buf->list); |
| 17177 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17178 | } |
| 17179 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17180 | } |
| 17181 | if (abort_count) |
| 17182 | lpfc_update_rcv_time_stamp(vport); |
| 17183 | } |
| 17184 | |
| 17185 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17186 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 17187 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 17188 | * |
| 17189 | * This function searches through the existing incomplete sequences that have |
| 17190 | * been sent to this @vport. If the frame matches one of the incomplete |
| 17191 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 17192 | * make up that sequence. If no sequence is found that matches this frame then |
| 17193 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 17194 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 17195 | * the frame was linked to. |
| 17196 | **/ |
| 17197 | static struct hbq_dmabuf * |
| 17198 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17199 | { |
| 17200 | struct fc_frame_header *new_hdr; |
| 17201 | struct fc_frame_header *temp_hdr; |
| 17202 | struct lpfc_dmabuf *d_buf; |
| 17203 | struct lpfc_dmabuf *h_buf; |
| 17204 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17205 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17206 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17207 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17208 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17209 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17210 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17211 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17212 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 17213 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17214 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17215 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17216 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17217 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17218 | continue; |
| 17219 | /* found a pending sequence that matches this frame */ |
| 17220 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17221 | break; |
| 17222 | } |
| 17223 | if (!seq_dmabuf) { |
| 17224 | /* |
| 17225 | * This indicates first frame received for this sequence. |
| 17226 | * Queue the buffer on the vport's rcv_buffer_list. |
| 17227 | */ |
| 17228 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17229 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17230 | return dmabuf; |
| 17231 | } |
| 17232 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17233 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 17234 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17235 | list_del_init(&seq_dmabuf->hbuf.list); |
| 17236 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17237 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17238 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17239 | return dmabuf; |
| 17240 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17241 | /* move this sequence to the tail to indicate a young sequence */ |
| 17242 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17243 | seq_dmabuf->time_stamp = jiffies; |
| 17244 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17245 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 17246 | temp_hdr = dmabuf->hbuf.virt; |
| 17247 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 17248 | return seq_dmabuf; |
| 17249 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17250 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17251 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 17252 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17253 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17254 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 17255 | /* |
| 17256 | * If the frame's sequence count is greater than the frame on |
| 17257 | * the list then insert the frame right after this frame |
| 17258 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17259 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 17260 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17261 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17262 | found = 1; |
| 17263 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17264 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17265 | |
| 17266 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 17267 | break; |
| 17268 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17269 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17270 | |
| 17271 | if (found) |
| 17272 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17273 | return NULL; |
| 17274 | } |
| 17275 | |
| 17276 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17277 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 17278 | * @vport: pointer to a vitural port |
| 17279 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17280 | * |
| 17281 | * This function tries to abort from the partially assembed sequence, described |
| 17282 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 17283 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 17284 | * the frames from the partially assembled sequence. |
| 17285 | * |
| 17286 | * Return |
| 17287 | * true -- if there is matching partially assembled sequence present and all |
| 17288 | * the frames freed with the sequence; |
| 17289 | * false -- if there is no matching partially assembled sequence present so |
| 17290 | * nothing got aborted in the lower layer driver |
| 17291 | **/ |
| 17292 | static bool |
| 17293 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 17294 | struct hbq_dmabuf *dmabuf) |
| 17295 | { |
| 17296 | struct fc_frame_header *new_hdr; |
| 17297 | struct fc_frame_header *temp_hdr; |
| 17298 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 17299 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17300 | |
| 17301 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 17302 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 17303 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 17304 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17305 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17306 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17307 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17308 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17309 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17310 | continue; |
| 17311 | /* found a pending sequence that matches this frame */ |
| 17312 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17313 | break; |
| 17314 | } |
| 17315 | |
| 17316 | /* Free up all the frames from the partially assembled sequence */ |
| 17317 | if (seq_dmabuf) { |
| 17318 | list_for_each_entry_safe(d_buf, n_buf, |
| 17319 | &seq_dmabuf->dbuf.list, list) { |
| 17320 | list_del_init(&d_buf->list); |
| 17321 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17322 | } |
| 17323 | return true; |
| 17324 | } |
| 17325 | return false; |
| 17326 | } |
| 17327 | |
| 17328 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17329 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 17330 | * @vport: pointer to a vitural port |
| 17331 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17332 | * |
| 17333 | * This function tries to abort from the assembed sequence from upper level |
| 17334 | * protocol, described by the information from basic abbort @dmabuf. It |
| 17335 | * checks to see whether such pending context exists at upper level protocol. |
| 17336 | * If so, it shall clean up the pending context. |
| 17337 | * |
| 17338 | * Return |
| 17339 | * true -- if there is matching pending context of the sequence cleaned |
| 17340 | * at ulp; |
| 17341 | * false -- if there is no matching pending context of the sequence present |
| 17342 | * at ulp. |
| 17343 | **/ |
| 17344 | static bool |
| 17345 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17346 | { |
| 17347 | struct lpfc_hba *phba = vport->phba; |
| 17348 | int handled; |
| 17349 | |
| 17350 | /* Accepting abort at ulp with SLI4 only */ |
| 17351 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 17352 | return false; |
| 17353 | |
| 17354 | /* Register all caring upper level protocols to attend abort */ |
| 17355 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 17356 | if (handled) |
| 17357 | return true; |
| 17358 | |
| 17359 | return false; |
| 17360 | } |
| 17361 | |
| 17362 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17363 | * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17364 | * @phba: Pointer to HBA context object. |
| 17365 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 17366 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 17367 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17368 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17369 | * event. It properly releases the memory allocated to the sequence abort |
| 17370 | * accept iocb. |
| 17371 | **/ |
| 17372 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17373 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17374 | struct lpfc_iocbq *cmd_iocbq, |
| 17375 | struct lpfc_iocbq *rsp_iocbq) |
| 17376 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17377 | struct lpfc_nodelist *ndlp; |
| 17378 | |
| 17379 | if (cmd_iocbq) { |
| 17380 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 17381 | lpfc_nlp_put(ndlp); |
| 17382 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17383 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17384 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17385 | |
| 17386 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 17387 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 17388 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17389 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 17390 | rsp_iocbq->iocb.ulpStatus, |
| 17391 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17392 | } |
| 17393 | |
| 17394 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17395 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 17396 | * @phba: Pointer to HBA context object. |
| 17397 | * @xri: xri id in transaction. |
| 17398 | * |
| 17399 | * This function validates the xri maps to the known range of XRIs allocated an |
| 17400 | * used by the driver. |
| 17401 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17402 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17403 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 17404 | uint16_t xri) |
| 17405 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17406 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17407 | |
| 17408 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 17409 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 17410 | return i; |
| 17411 | } |
| 17412 | return NO_XRI; |
| 17413 | } |
| 17414 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17415 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17416 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17417 | * @phba: Pointer to HBA context object. |
| 17418 | * @fc_hdr: pointer to a FC frame header. |
| 17419 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17420 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17421 | * event after aborting the sequence handling. |
| 17422 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17423 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17424 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 17425 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17426 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17427 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17428 | struct lpfc_iocbq *ctiocb = NULL; |
| 17429 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17430 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17431 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17432 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17433 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17434 | |
| 17435 | if (!lpfc_is_link_up(phba)) |
| 17436 | return; |
| 17437 | |
| 17438 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 17439 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17440 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17441 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17442 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17443 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 17444 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17445 | if (!ndlp) { |
| 17446 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17447 | "1268 Failed to allocate ndlp for " |
| 17448 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 17449 | return; |
| 17450 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17451 | /* Put ndlp onto pport node list */ |
| 17452 | lpfc_enqueue_node(vport, ndlp); |
| 17453 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 17454 | /* re-setup ndlp without removing from node list */ |
| 17455 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 17456 | if (!ndlp) { |
| 17457 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17458 | "3275 Failed to active ndlp found " |
| 17459 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 17460 | return; |
| 17461 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17462 | } |
| 17463 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17464 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17465 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 17466 | if (!ctiocb) |
| 17467 | return; |
| 17468 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17469 | /* Extract the F_CTL field from FC_HDR */ |
| 17470 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 17471 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17472 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17473 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17474 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17475 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 17476 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 17477 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 17478 | |
| 17479 | /* Fill in the rest of iocb fields */ |
| 17480 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 17481 | icmd->ulpBdeCount = 0; |
| 17482 | icmd->ulpLe = 1; |
| 17483 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17484 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17485 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17486 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17487 | ctiocb->iocb_cmpl = NULL; |
| 17488 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17489 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17490 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17491 | ctiocb->sli4_xritag = NO_XRI; |
| 17492 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17493 | if (fctl & FC_FC_EX_CTX) |
| 17494 | /* Exchange responder sent the abort so we |
| 17495 | * own the oxid. |
| 17496 | */ |
| 17497 | xri = oxid; |
| 17498 | else |
| 17499 | xri = rxid; |
| 17500 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 17501 | if (lxri != NO_XRI) |
| 17502 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 17503 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17504 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 17505 | * the oxid maps to the FCP XRI range, the port no longer has |
| 17506 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 17507 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17508 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17509 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17510 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17511 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17512 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17513 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17514 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17515 | } |
| 17516 | |
| 17517 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 17518 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 17519 | * the IOCB for a BA_RJT. |
| 17520 | */ |
| 17521 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17522 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17523 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17524 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17525 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17526 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17527 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17528 | if (fctl & FC_FC_EX_CTX) { |
| 17529 | /* ABTS sent by responder to CT exchange, construction |
| 17530 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 17531 | * field and RX_ID from ABTS for RX_ID field. |
| 17532 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17533 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17534 | } else { |
| 17535 | /* ABTS sent by initiator to CT exchange, construction |
| 17536 | * of BA_ACC will need to allocate a new XRI as for the |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 17537 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17538 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17539 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17540 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 17541 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17542 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17543 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17544 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17545 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 17546 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 17547 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17548 | |
| 17549 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 17550 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17551 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 17552 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 17553 | "xri x%x, Data x%x\n", |
| 17554 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 17555 | phba->link_state); |
| 17556 | lpfc_nlp_put(ndlp); |
| 17557 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17558 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 17559 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17560 | } |
| 17561 | |
| 17562 | /** |
| 17563 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 17564 | * @vport: Pointer to the vport on which this sequence was received |
| 17565 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17566 | * |
| 17567 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 17568 | * receive sequence is only partially assembed by the driver, it shall abort |
| 17569 | * the partially assembled frames for the sequence. Otherwise, if the |
| 17570 | * unsolicited receive sequence has been completely assembled and passed to |
| 17571 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 17572 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 17573 | * accept to accept the abort. |
| 17574 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17575 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17576 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 17577 | struct hbq_dmabuf *dmabuf) |
| 17578 | { |
| 17579 | struct lpfc_hba *phba = vport->phba; |
| 17580 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17581 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17582 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17583 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17584 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 17585 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17586 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17587 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17588 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17589 | /* ABTS by responder to exchange, no cleanup needed */ |
| 17590 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17591 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17592 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 17593 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 17594 | if (aborted == false) |
| 17595 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17596 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17597 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17598 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17599 | if (phba->nvmet_support) { |
| 17600 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 17601 | return; |
| 17602 | } |
| 17603 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17604 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 17605 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17606 | } |
| 17607 | |
| 17608 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17609 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 17610 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17611 | * |
| 17612 | * This function checks the sequence, starting with the frame described by |
| 17613 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 17614 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 17615 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 17616 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 17617 | * set. 3) That there are no holes in the sequence count. The function will |
| 17618 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 17619 | **/ |
| 17620 | static int |
| 17621 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 17622 | { |
| 17623 | struct fc_frame_header *hdr; |
| 17624 | struct lpfc_dmabuf *d_buf; |
| 17625 | struct hbq_dmabuf *seq_dmabuf; |
| 17626 | uint32_t fctl; |
| 17627 | int seq_count = 0; |
| 17628 | |
| 17629 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17630 | /* make sure first fame of sequence has a sequence count of zero */ |
| 17631 | if (hdr->fh_seq_cnt != seq_count) |
| 17632 | return 0; |
| 17633 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17634 | hdr->fh_f_ctl[1] << 8 | |
| 17635 | hdr->fh_f_ctl[2]); |
| 17636 | /* If last frame of sequence we can return success. */ |
| 17637 | if (fctl & FC_FC_END_SEQ) |
| 17638 | return 1; |
| 17639 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 17640 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17641 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17642 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17643 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17644 | return 0; |
| 17645 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17646 | hdr->fh_f_ctl[1] << 8 | |
| 17647 | hdr->fh_f_ctl[2]); |
| 17648 | /* If last frame of sequence we can return success. */ |
| 17649 | if (fctl & FC_FC_END_SEQ) |
| 17650 | return 1; |
| 17651 | } |
| 17652 | return 0; |
| 17653 | } |
| 17654 | |
| 17655 | /** |
| 17656 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 17657 | * @vport: Pointer to the vport on which this sequence was received |
| 17658 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17659 | * |
| 17660 | * This function takes a sequence, described by a list of frames, and creates |
| 17661 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 17662 | * used to issue to the generic unsolicited sequence handler. This routine |
| 17663 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 17664 | * to allocate an iocbq then it throw out the received frames that were not |
| 17665 | * able to be described and return a pointer to the first iocbq. If unable to |
| 17666 | * allocate any iocbqs (including the first) this function will return NULL. |
| 17667 | **/ |
| 17668 | static struct lpfc_iocbq * |
| 17669 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 17670 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17671 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17672 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 17673 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 17674 | struct fc_frame_header *fc_hdr; |
| 17675 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17676 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17677 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17678 | |
| 17679 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17680 | /* remove from receive buffer list */ |
| 17681 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17682 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17683 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17684 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17685 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17686 | /* Get an iocbq struct to fill in. */ |
| 17687 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17688 | if (first_iocbq) { |
| 17689 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17690 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17691 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17692 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17693 | |
| 17694 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 17695 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 17696 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 17697 | first_iocbq->iocb.un.rcvels.parmRo = |
| 17698 | sli4_did_from_fc_hdr(fc_hdr); |
| 17699 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 17700 | } else |
| 17701 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17702 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 17703 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 17704 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 17705 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 17706 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 17707 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17708 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17709 | tot_len = bf_get(lpfc_rcqe_length, |
| 17710 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17711 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17712 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 17713 | first_iocbq->context3 = NULL; |
| 17714 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17715 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 17716 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17717 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17718 | else |
| 17719 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 17720 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17721 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17722 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17723 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17724 | } |
| 17725 | iocbq = first_iocbq; |
| 17726 | /* |
| 17727 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 17728 | * of buffers for this sequence and save two buffers in each IOCBq |
| 17729 | */ |
| 17730 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 17731 | if (!iocbq) { |
| 17732 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17733 | continue; |
| 17734 | } |
| 17735 | if (!iocbq->context3) { |
| 17736 | iocbq->context3 = d_buf; |
| 17737 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17738 | /* We need to get the size out of the right CQE */ |
| 17739 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17740 | len = bf_get(lpfc_rcqe_length, |
| 17741 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17742 | pbde = (struct ulp_bde64 *) |
| 17743 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 17744 | if (len > LPFC_DATA_BUF_SIZE) |
| 17745 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 17746 | else |
| 17747 | pbde->tus.f.bdeSize = len; |
| 17748 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17749 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 17750 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17751 | } else { |
| 17752 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17753 | if (!iocbq) { |
| 17754 | if (first_iocbq) { |
| 17755 | first_iocbq->iocb.ulpStatus = |
| 17756 | IOSTAT_FCP_RSP_ERROR; |
| 17757 | first_iocbq->iocb.un.ulpWord[4] = |
| 17758 | IOERR_NO_RESOURCES; |
| 17759 | } |
| 17760 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17761 | continue; |
| 17762 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17763 | /* We need to get the size out of the right CQE */ |
| 17764 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17765 | len = bf_get(lpfc_rcqe_length, |
| 17766 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17767 | iocbq->context2 = d_buf; |
| 17768 | iocbq->context3 = NULL; |
| 17769 | iocbq->iocb.ulpBdeCount = 1; |
| 17770 | if (len > LPFC_DATA_BUF_SIZE) |
| 17771 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 17772 | LPFC_DATA_BUF_SIZE; |
| 17773 | else |
| 17774 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 17775 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17776 | tot_len += len; |
| 17777 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 17778 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17779 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 17780 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 17781 | } |
| 17782 | } |
| 17783 | return first_iocbq; |
| 17784 | } |
| 17785 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17786 | static void |
| 17787 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 17788 | struct hbq_dmabuf *seq_dmabuf) |
| 17789 | { |
| 17790 | struct fc_frame_header *fc_hdr; |
| 17791 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 17792 | struct lpfc_hba *phba = vport->phba; |
| 17793 | |
| 17794 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17795 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 17796 | if (!iocbq) { |
| 17797 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17798 | "2707 Ring %d handler: Failed to allocate " |
| 17799 | "iocb Rctl x%x Type x%x received\n", |
| 17800 | LPFC_ELS_RING, |
| 17801 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17802 | return; |
| 17803 | } |
| 17804 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17805 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17806 | iocbq, fc_hdr->fh_r_ctl, |
| 17807 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17808 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17809 | "2540 Ring %d handler: unexpected Rctl " |
| 17810 | "x%x Type x%x received\n", |
| 17811 | LPFC_ELS_RING, |
| 17812 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17813 | |
| 17814 | /* Free iocb created in lpfc_prep_seq */ |
| 17815 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 17816 | &iocbq->list, list) { |
| 17817 | list_del_init(&curr_iocb->list); |
| 17818 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 17819 | } |
| 17820 | lpfc_sli_release_iocbq(phba, iocbq); |
| 17821 | } |
| 17822 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17823 | static void |
| 17824 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 17825 | struct lpfc_iocbq *rspiocb) |
| 17826 | { |
| 17827 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 17828 | |
| 17829 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17830 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17831 | kfree(pcmd); |
| 17832 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17833 | lpfc_drain_txq(phba); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17834 | } |
| 17835 | |
| 17836 | static void |
| 17837 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 17838 | struct hbq_dmabuf *dmabuf) |
| 17839 | { |
| 17840 | struct fc_frame_header *fc_hdr; |
| 17841 | struct lpfc_hba *phba = vport->phba; |
| 17842 | struct lpfc_iocbq *iocbq = NULL; |
| 17843 | union lpfc_wqe *wqe; |
| 17844 | struct lpfc_dmabuf *pcmd = NULL; |
| 17845 | uint32_t frame_len; |
| 17846 | int rc; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17847 | unsigned long iflags; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17848 | |
| 17849 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17850 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17851 | |
| 17852 | /* Send the received frame back */ |
| 17853 | iocbq = lpfc_sli_get_iocbq(phba); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17854 | if (!iocbq) { |
| 17855 | /* Queue cq event and wakeup worker thread to process it */ |
| 17856 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 17857 | list_add_tail(&dmabuf->cq_event.list, |
| 17858 | &phba->sli4_hba.sp_queue_event); |
| 17859 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
| 17860 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 17861 | lpfc_worker_wake_up(phba); |
| 17862 | return; |
| 17863 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17864 | |
| 17865 | /* Allocate buffer for command payload */ |
| 17866 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 17867 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17868 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17869 | &pcmd->phys); |
| 17870 | if (!pcmd || !pcmd->virt) |
| 17871 | goto exit; |
| 17872 | |
| 17873 | INIT_LIST_HEAD(&pcmd->list); |
| 17874 | |
| 17875 | /* copyin the payload */ |
| 17876 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 17877 | |
| 17878 | /* fill in BDE's for command */ |
| 17879 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 17880 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 17881 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 17882 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 17883 | |
| 17884 | iocbq->context2 = pcmd; |
| 17885 | iocbq->vport = vport; |
| 17886 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 17887 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 17888 | |
| 17889 | /* |
| 17890 | * Setup rest of the iocb as though it were a WQE |
| 17891 | * Build the SEND_FRAME WQE |
| 17892 | */ |
| 17893 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 17894 | |
| 17895 | wqe->send_frame.frame_len = frame_len; |
| 17896 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 17897 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 17898 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 17899 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 17900 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 17901 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 17902 | |
| 17903 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 17904 | iocbq->iocb.ulpLe = 1; |
| 17905 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 17906 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 17907 | if (rc == IOCB_ERROR) |
| 17908 | goto exit; |
| 17909 | |
| 17910 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17911 | return; |
| 17912 | |
| 17913 | exit: |
| 17914 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 17915 | "2023 Unable to process MDS loopback frame\n"); |
| 17916 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17917 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17918 | kfree(pcmd); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 17919 | if (iocbq) |
| 17920 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17921 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17922 | } |
| 17923 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17924 | /** |
| 17925 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 17926 | * @phba: Pointer to HBA context object. |
| 17927 | * |
| 17928 | * This function is called with no lock held. This function processes all |
| 17929 | * the received buffers and gives it to upper layers when a received buffer |
| 17930 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17931 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17932 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 17933 | * appropriate receive function when the final frame in a sequence is received. |
| 17934 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17935 | void |
| 17936 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 17937 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17938 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17939 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17940 | struct fc_frame_header *fc_hdr; |
| 17941 | struct lpfc_vport *vport; |
| 17942 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17943 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17944 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17945 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17946 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17947 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17948 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 17949 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 17950 | vport = phba->pport; |
| 17951 | /* Handle MDS Loopback frames */ |
| 17952 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 17953 | return; |
| 17954 | } |
| 17955 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17956 | /* check to see if this a valid type of frame */ |
| 17957 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 17958 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17959 | return; |
| 17960 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17961 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17962 | if ((bf_get(lpfc_cqe_code, |
| 17963 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 17964 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 17965 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17966 | else |
| 17967 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 17968 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17969 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17970 | /* d_id this frame is directed to */ |
| 17971 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 17972 | |
| 17973 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17974 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17975 | /* throw out the frame */ |
| 17976 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17977 | return; |
| 17978 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17979 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17980 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 17981 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 17982 | (did != Fabric_DID)) { |
| 17983 | /* |
| 17984 | * Throw out the frame if we are not pt2pt. |
| 17985 | * The pt2pt protocol allows for discovery frames |
| 17986 | * to be received without a registered VPI. |
| 17987 | */ |
| 17988 | if (!(vport->fc_flag & FC_PT2PT) || |
| 17989 | (phba->link_state == LPFC_HBA_READY)) { |
| 17990 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17991 | return; |
| 17992 | } |
| 17993 | } |
| 17994 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17995 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 17996 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 17997 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 17998 | return; |
| 17999 | } |
| 18000 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18001 | /* Link this frame */ |
| 18002 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 18003 | if (!seq_dmabuf) { |
| 18004 | /* unable to add frame to vport - throw it out */ |
| 18005 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18006 | return; |
| 18007 | } |
| 18008 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 18009 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18010 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 18011 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18012 | /* Send the complete sequence to the upper layer protocol */ |
| 18013 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18014 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18015 | |
| 18016 | /** |
| 18017 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 18018 | * @phba: pointer to lpfc hba data structure. |
| 18019 | * |
| 18020 | * This routine is invoked to post rpi header templates to the |
| 18021 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18022 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18023 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18024 | * |
| 18025 | * This routine does not require any locks. It's usage is expected |
| 18026 | * to be driver load or reset recovery when the driver is |
| 18027 | * sequential. |
| 18028 | * |
| 18029 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18030 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18031 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18032 | * When this error occurs, the driver is not guaranteed |
| 18033 | * to have any rpi regions posted to the device and |
| 18034 | * must either attempt to repost the regions or take a |
| 18035 | * fatal error. |
| 18036 | **/ |
| 18037 | int |
| 18038 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 18039 | { |
| 18040 | struct lpfc_rpi_hdr *rpi_page; |
| 18041 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18042 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18043 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18044 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18045 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18046 | goto exit; |
| 18047 | if (phba->sli4_hba.extents_in_use) |
| 18048 | return -EIO; |
| 18049 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18050 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18051 | /* |
| 18052 | * Assign the rpi headers a physical rpi only if the driver |
| 18053 | * has not initialized those resources. A port reset only |
| 18054 | * needs the headers posted. |
| 18055 | */ |
| 18056 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 18057 | LPFC_RPI_RSRC_RDY) |
| 18058 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 18059 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18060 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 18061 | if (rc != MBX_SUCCESS) { |
| 18062 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18063 | "2008 Error %d posting all rpi " |
| 18064 | "headers\n", rc); |
| 18065 | rc = -EIO; |
| 18066 | break; |
| 18067 | } |
| 18068 | } |
| 18069 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18070 | exit: |
| 18071 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 18072 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18073 | return rc; |
| 18074 | } |
| 18075 | |
| 18076 | /** |
| 18077 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 18078 | * @phba: pointer to lpfc hba data structure. |
| 18079 | * @rpi_page: pointer to the rpi memory region. |
| 18080 | * |
| 18081 | * This routine is invoked to post a single rpi header to the |
| 18082 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 18083 | * maps up to 64 rpi context regions. |
| 18084 | * |
| 18085 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18086 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18087 | * -ENOMEM - No available memory |
| 18088 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18089 | **/ |
| 18090 | int |
| 18091 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 18092 | { |
| 18093 | LPFC_MBOXQ_t *mboxq; |
| 18094 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 18095 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18096 | uint32_t shdr_status, shdr_add_status; |
| 18097 | union lpfc_sli4_cfg_shdr *shdr; |
| 18098 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18099 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18100 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18101 | return rc; |
| 18102 | if (phba->sli4_hba.extents_in_use) |
| 18103 | return -EIO; |
| 18104 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18105 | /* The port is notified of the header region via a mailbox command. */ |
| 18106 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18107 | if (!mboxq) { |
| 18108 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18109 | "2001 Unable to allocate memory for issuing " |
| 18110 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 18111 | return -ENOMEM; |
| 18112 | } |
| 18113 | |
| 18114 | /* Post all rpi memory regions to the port. */ |
| 18115 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18116 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18117 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 18118 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 18119 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 18120 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18121 | |
| 18122 | |
| 18123 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18124 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 18125 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18126 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 18127 | hdr_tmpl, rpi_page->page_count); |
| 18128 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18129 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 18130 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 18131 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18132 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 18133 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18134 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18135 | if (rc != MBX_TIMEOUT) |
| 18136 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18137 | if (shdr_status || shdr_add_status || rc) { |
| 18138 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18139 | "2514 POST_RPI_HDR mailbox failed with " |
| 18140 | "status x%x add_status x%x, mbx status x%x\n", |
| 18141 | shdr_status, shdr_add_status, rc); |
| 18142 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 18143 | } else { |
| 18144 | /* |
| 18145 | * The next_rpi stores the next logical module-64 rpi value used |
| 18146 | * to post physical rpis in subsequent rpi postings. |
| 18147 | */ |
| 18148 | spin_lock_irq(&phba->hbalock); |
| 18149 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 18150 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18151 | } |
| 18152 | return rc; |
| 18153 | } |
| 18154 | |
| 18155 | /** |
| 18156 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 18157 | * @phba: pointer to lpfc hba data structure. |
| 18158 | * |
| 18159 | * This routine is invoked to post rpi header templates to the |
| 18160 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18161 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18162 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18163 | * |
| 18164 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18165 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18166 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 18167 | **/ |
| 18168 | int |
| 18169 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 18170 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18171 | unsigned long rpi; |
| 18172 | uint16_t max_rpi, rpi_limit; |
| 18173 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18174 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18175 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18176 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18177 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18178 | * Fetch the next logical rpi. Because this index is logical, |
| 18179 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18180 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18181 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18182 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 18183 | rpi_limit = phba->sli4_hba.next_rpi; |
| 18184 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18185 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 18186 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18187 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 18188 | else { |
| 18189 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 18190 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 18191 | phba->sli4_hba.rpi_count++; |
| 18192 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18193 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 18194 | "0001 rpi:%x max:%x lim:%x\n", |
| 18195 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18196 | |
| 18197 | /* |
| 18198 | * Don't try to allocate more rpi header regions if the device limit |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18199 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18200 | */ |
| 18201 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 18202 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18203 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18204 | return rpi; |
| 18205 | } |
| 18206 | |
| 18207 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18208 | * RPI header postings are not required for SLI4 ports capable of |
| 18209 | * extents. |
| 18210 | */ |
| 18211 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18212 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18213 | return rpi; |
| 18214 | } |
| 18215 | |
| 18216 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18217 | * If the driver is running low on rpi resources, allocate another |
| 18218 | * page now. Note that the next_rpi value is used because |
| 18219 | * it represents how many are actually in use whereas max_rpi notes |
| 18220 | * how many are supported max by the device. |
| 18221 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18222 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18223 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18224 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 18225 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 18226 | if (!rpi_hdr) { |
| 18227 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18228 | "2002 Error Could not grow rpi " |
| 18229 | "count\n"); |
| 18230 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18231 | lrpi = rpi_hdr->start_rpi; |
| 18232 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18233 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 18234 | } |
| 18235 | } |
| 18236 | |
| 18237 | return rpi; |
| 18238 | } |
| 18239 | |
| 18240 | /** |
| 18241 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18242 | * @phba: pointer to lpfc hba data structure. |
| 18243 | * |
| 18244 | * This routine is invoked to release an rpi to the pool of |
| 18245 | * available rpis maintained by the driver. |
| 18246 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18247 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18248 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18249 | { |
| 18250 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 18251 | phba->sli4_hba.rpi_count--; |
| 18252 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 18253 | } |
| 18254 | } |
| 18255 | |
| 18256 | /** |
| 18257 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18258 | * @phba: pointer to lpfc hba data structure. |
| 18259 | * |
| 18260 | * This routine is invoked to release an rpi to the pool of |
| 18261 | * available rpis maintained by the driver. |
| 18262 | **/ |
| 18263 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18264 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18265 | { |
| 18266 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18267 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18268 | spin_unlock_irq(&phba->hbalock); |
| 18269 | } |
| 18270 | |
| 18271 | /** |
| 18272 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 18273 | * @phba: pointer to lpfc hba data structure. |
| 18274 | * |
| 18275 | * This routine is invoked to remove the memory region that |
| 18276 | * provided rpi via a bitmask. |
| 18277 | **/ |
| 18278 | void |
| 18279 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 18280 | { |
| 18281 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18282 | kfree(phba->sli4_hba.rpi_ids); |
| 18283 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18284 | } |
| 18285 | |
| 18286 | /** |
| 18287 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 18288 | * @phba: pointer to lpfc hba data structure. |
| 18289 | * |
| 18290 | * This routine is invoked to remove the memory region that |
| 18291 | * provided rpi via a bitmask. |
| 18292 | **/ |
| 18293 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18294 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 18295 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18296 | { |
| 18297 | LPFC_MBOXQ_t *mboxq; |
| 18298 | struct lpfc_hba *phba = ndlp->phba; |
| 18299 | int rc; |
| 18300 | |
| 18301 | /* The port is notified of the header region via a mailbox command. */ |
| 18302 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18303 | if (!mboxq) |
| 18304 | return -ENOMEM; |
| 18305 | |
| 18306 | /* Post all rpi memory regions to the port. */ |
| 18307 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18308 | if (cmpl) { |
| 18309 | mboxq->mbox_cmpl = cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 18310 | mboxq->ctx_buf = arg; |
| 18311 | mboxq->ctx_ndlp = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 18312 | } else |
| 18313 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18314 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18315 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18316 | if (rc == MBX_NOT_FINISHED) { |
| 18317 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18318 | "2010 Resume RPI Mailbox failed " |
| 18319 | "status %d, mbxStatus x%x\n", rc, |
| 18320 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 18321 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18322 | return -EIO; |
| 18323 | } |
| 18324 | return 0; |
| 18325 | } |
| 18326 | |
| 18327 | /** |
| 18328 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18329 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18330 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18331 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18332 | * |
| 18333 | * Returns: |
| 18334 | * 0 success |
| 18335 | * -Evalue otherwise |
| 18336 | **/ |
| 18337 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18338 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18339 | { |
| 18340 | LPFC_MBOXQ_t *mboxq; |
| 18341 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18342 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18343 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18344 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18345 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18346 | if (!mboxq) |
| 18347 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18348 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18349 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18350 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18351 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18352 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18353 | "2022 INIT VPI Mailbox failed " |
| 18354 | "status %d, mbxStatus x%x\n", rc, |
| 18355 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18356 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18357 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18358 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18359 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18360 | |
| 18361 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18362 | } |
| 18363 | |
| 18364 | /** |
| 18365 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 18366 | * @phba: pointer to lpfc hba data structure. |
| 18367 | * @mboxq: Pointer to mailbox object. |
| 18368 | * |
| 18369 | * This routine is invoked to manually add a single FCF record. The caller |
| 18370 | * must pass a completely initialized FCF_Record. This routine takes |
| 18371 | * care of the nonembedded mailbox operations. |
| 18372 | **/ |
| 18373 | static void |
| 18374 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 18375 | { |
| 18376 | void *virt_addr; |
| 18377 | union lpfc_sli4_cfg_shdr *shdr; |
| 18378 | uint32_t shdr_status, shdr_add_status; |
| 18379 | |
| 18380 | virt_addr = mboxq->sge_array->addr[0]; |
| 18381 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 18382 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 18383 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18384 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18385 | |
| 18386 | if ((shdr_status || shdr_add_status) && |
| 18387 | (shdr_status != STATUS_FCF_IN_USE)) |
| 18388 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18389 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 18390 | "status x%x add_status x%x\n", |
| 18391 | shdr_status, shdr_add_status); |
| 18392 | |
| 18393 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18394 | } |
| 18395 | |
| 18396 | /** |
| 18397 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 18398 | * @phba: pointer to lpfc hba data structure. |
| 18399 | * @fcf_record: pointer to the initialized fcf record to add. |
| 18400 | * |
| 18401 | * This routine is invoked to manually add a single FCF record. The caller |
| 18402 | * must pass a completely initialized FCF_Record. This routine takes |
| 18403 | * care of the nonembedded mailbox operations. |
| 18404 | **/ |
| 18405 | int |
| 18406 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 18407 | { |
| 18408 | int rc = 0; |
| 18409 | LPFC_MBOXQ_t *mboxq; |
| 18410 | uint8_t *bytep; |
| 18411 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18412 | struct lpfc_mbx_sge sge; |
| 18413 | uint32_t alloc_len, req_len; |
| 18414 | uint32_t fcfindex; |
| 18415 | |
| 18416 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18417 | if (!mboxq) { |
| 18418 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18419 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 18420 | return -ENOMEM; |
| 18421 | } |
| 18422 | |
| 18423 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 18424 | sizeof(uint32_t); |
| 18425 | |
| 18426 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 18427 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18428 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 18429 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 18430 | if (alloc_len < req_len) { |
| 18431 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18432 | "2523 Allocated DMA memory size (x%x) is " |
| 18433 | "less than the requested DMA memory " |
| 18434 | "size (x%x)\n", alloc_len, req_len); |
| 18435 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18436 | return -ENOMEM; |
| 18437 | } |
| 18438 | |
| 18439 | /* |
| 18440 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 18441 | * routine only uses a single SGE. |
| 18442 | */ |
| 18443 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18444 | virt_addr = mboxq->sge_array->addr[0]; |
| 18445 | /* |
| 18446 | * Configure the FCF record for FCFI 0. This is the driver's |
| 18447 | * hardcoded default and gets used in nonFIP mode. |
| 18448 | */ |
| 18449 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 18450 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 18451 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 18452 | |
| 18453 | /* |
| 18454 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 18455 | * the FCoE header plus word10. The data copy needs to be endian |
| 18456 | * correct. |
| 18457 | */ |
| 18458 | bytep += sizeof(uint32_t); |
| 18459 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 18460 | mboxq->vport = phba->pport; |
| 18461 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 18462 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18463 | if (rc == MBX_NOT_FINISHED) { |
| 18464 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18465 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 18466 | "status 0x%x\n", rc); |
| 18467 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18468 | rc = -EIO; |
| 18469 | } else |
| 18470 | rc = 0; |
| 18471 | |
| 18472 | return rc; |
| 18473 | } |
| 18474 | |
| 18475 | /** |
| 18476 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 18477 | * @phba: pointer to lpfc hba data structure. |
| 18478 | * @fcf_record: pointer to the fcf record to write the default data. |
| 18479 | * @fcf_index: FCF table entry index. |
| 18480 | * |
| 18481 | * This routine is invoked to build the driver's default FCF record. The |
| 18482 | * values used are hardcoded. This routine handles memory initialization. |
| 18483 | * |
| 18484 | **/ |
| 18485 | void |
| 18486 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 18487 | struct fcf_record *fcf_record, |
| 18488 | uint16_t fcf_index) |
| 18489 | { |
| 18490 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 18491 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 18492 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 18493 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 18494 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 18495 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 18496 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 18497 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 18498 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 18499 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 18500 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 18501 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 18502 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 18503 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 18504 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18505 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 18506 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 18507 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 18508 | /* Set the VLAN bit map */ |
| 18509 | if (phba->valid_vlan) { |
| 18510 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 18511 | = 1 << (phba->vlan_id % 8); |
| 18512 | } |
| 18513 | } |
| 18514 | |
| 18515 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18516 | * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18517 | * @phba: pointer to lpfc hba data structure. |
| 18518 | * @fcf_index: FCF table entry offset. |
| 18519 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18520 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 18521 | * record and processing it one at a time starting from the @fcf_index |
| 18522 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 18523 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18524 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18525 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18526 | **/ |
| 18527 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18528 | lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18529 | { |
| 18530 | int rc = 0, error; |
| 18531 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18532 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18533 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 18534 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18535 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18536 | if (!mboxq) { |
| 18537 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18538 | "2000 Failed to allocate mbox for " |
| 18539 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18540 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18541 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18542 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18543 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18544 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18545 | if (rc) { |
| 18546 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18547 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18548 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18549 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18550 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18551 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18552 | |
| 18553 | spin_lock_irq(&phba->hbalock); |
| 18554 | phba->hba_flag |= FCF_TS_INPROG; |
| 18555 | spin_unlock_irq(&phba->hbalock); |
| 18556 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18557 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18558 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18559 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18560 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 18561 | /* Reset eligible FCF count for new scan */ |
| 18562 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 18563 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18564 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18565 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18566 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18567 | if (error) { |
| 18568 | if (mboxq) |
| 18569 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18570 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18571 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18572 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18573 | spin_unlock_irq(&phba->hbalock); |
| 18574 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18575 | return error; |
| 18576 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18577 | |
| 18578 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18579 | * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18580 | * @phba: pointer to lpfc hba data structure. |
| 18581 | * @fcf_index: FCF table entry offset. |
| 18582 | * |
| 18583 | * This routine is invoked to read an FCF record indicated by @fcf_index |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18584 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18585 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18586 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18587 | * otherwise. |
| 18588 | **/ |
| 18589 | int |
| 18590 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18591 | { |
| 18592 | int rc = 0, error; |
| 18593 | LPFC_MBOXQ_t *mboxq; |
| 18594 | |
| 18595 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18596 | if (!mboxq) { |
| 18597 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18598 | "2763 Failed to allocate mbox for " |
| 18599 | "READ_FCF cmd\n"); |
| 18600 | error = -ENOMEM; |
| 18601 | goto fail_fcf_read; |
| 18602 | } |
| 18603 | /* Construct the read FCF record mailbox command */ |
| 18604 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18605 | if (rc) { |
| 18606 | error = -EINVAL; |
| 18607 | goto fail_fcf_read; |
| 18608 | } |
| 18609 | /* Issue the mailbox command asynchronously */ |
| 18610 | mboxq->vport = phba->pport; |
| 18611 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 18612 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18613 | if (rc == MBX_NOT_FINISHED) |
| 18614 | error = -EIO; |
| 18615 | else |
| 18616 | error = 0; |
| 18617 | |
| 18618 | fail_fcf_read: |
| 18619 | if (error && mboxq) |
| 18620 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18621 | return error; |
| 18622 | } |
| 18623 | |
| 18624 | /** |
| 18625 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 18626 | * @phba: pointer to lpfc hba data structure. |
| 18627 | * @fcf_index: FCF table entry offset. |
| 18628 | * |
| 18629 | * This routine is invoked to read an FCF record indicated by @fcf_index to |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18630 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18631 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18632 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18633 | * otherwise. |
| 18634 | **/ |
| 18635 | int |
| 18636 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18637 | { |
| 18638 | int rc = 0, error; |
| 18639 | LPFC_MBOXQ_t *mboxq; |
| 18640 | |
| 18641 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18642 | if (!mboxq) { |
| 18643 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18644 | "2758 Failed to allocate mbox for " |
| 18645 | "READ_FCF cmd\n"); |
| 18646 | error = -ENOMEM; |
| 18647 | goto fail_fcf_read; |
| 18648 | } |
| 18649 | /* Construct the read FCF record mailbox command */ |
| 18650 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18651 | if (rc) { |
| 18652 | error = -EINVAL; |
| 18653 | goto fail_fcf_read; |
| 18654 | } |
| 18655 | /* Issue the mailbox command asynchronously */ |
| 18656 | mboxq->vport = phba->pport; |
| 18657 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 18658 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18659 | if (rc == MBX_NOT_FINISHED) |
| 18660 | error = -EIO; |
| 18661 | else |
| 18662 | error = 0; |
| 18663 | |
| 18664 | fail_fcf_read: |
| 18665 | if (error && mboxq) |
| 18666 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18667 | return error; |
| 18668 | } |
| 18669 | |
| 18670 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18671 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18672 | * phba pointer to the lpfc_hba struct for this port. |
| 18673 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 18674 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 18675 | * rr_bmask based on their priority level. Starting from the highest priority |
| 18676 | * to the lowest. The most likely FCF candidate will be in the highest |
| 18677 | * priority group. When this routine is called it searches the fcf_pri list for |
| 18678 | * next lowest priority group and repopulates the rr_bmask with only those |
| 18679 | * fcf_indexes. |
| 18680 | * returns: |
| 18681 | * 1=success 0=failure |
| 18682 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18683 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18684 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 18685 | { |
| 18686 | uint16_t next_fcf_pri; |
| 18687 | uint16_t last_index; |
| 18688 | struct lpfc_fcf_pri *fcf_pri; |
| 18689 | int rc; |
| 18690 | int ret = 0; |
| 18691 | |
| 18692 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 18693 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18694 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 18695 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18696 | |
| 18697 | /* Verify the priority list has 2 or more entries */ |
| 18698 | spin_lock_irq(&phba->hbalock); |
| 18699 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 18700 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 18701 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18702 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 18703 | "3061 Last IDX %d\n", last_index); |
| 18704 | return 0; /* Empty rr list */ |
| 18705 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18706 | spin_unlock_irq(&phba->hbalock); |
| 18707 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18708 | next_fcf_pri = 0; |
| 18709 | /* |
| 18710 | * Clear the rr_bmask and set all of the bits that are at this |
| 18711 | * priority. |
| 18712 | */ |
| 18713 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 18714 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 18715 | spin_lock_irq(&phba->hbalock); |
| 18716 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18717 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 18718 | continue; |
| 18719 | /* |
| 18720 | * the 1st priority that has not FLOGI failed |
| 18721 | * will be the highest. |
| 18722 | */ |
| 18723 | if (!next_fcf_pri) |
| 18724 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18725 | spin_unlock_irq(&phba->hbalock); |
| 18726 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18727 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18728 | fcf_pri->fcf_rec.fcf_index); |
| 18729 | if (rc) |
| 18730 | return 0; |
| 18731 | } |
| 18732 | spin_lock_irq(&phba->hbalock); |
| 18733 | } |
| 18734 | /* |
| 18735 | * if next_fcf_pri was not set above and the list is not empty then |
| 18736 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 18737 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18738 | */ |
| 18739 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 18740 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18741 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 18742 | /* |
| 18743 | * the 1st priority that has not FLOGI failed |
| 18744 | * will be the highest. |
| 18745 | */ |
| 18746 | if (!next_fcf_pri) |
| 18747 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18748 | spin_unlock_irq(&phba->hbalock); |
| 18749 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18750 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18751 | fcf_pri->fcf_rec.fcf_index); |
| 18752 | if (rc) |
| 18753 | return 0; |
| 18754 | } |
| 18755 | spin_lock_irq(&phba->hbalock); |
| 18756 | } |
| 18757 | } else |
| 18758 | ret = 1; |
| 18759 | spin_unlock_irq(&phba->hbalock); |
| 18760 | |
| 18761 | return ret; |
| 18762 | } |
| 18763 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18764 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 18765 | * @phba: pointer to lpfc hba data structure. |
| 18766 | * |
| 18767 | * This routine is to get the next eligible FCF record index in a round |
| 18768 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18769 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18770 | * shall be returned, otherwise, the next eligible FCF record's index |
| 18771 | * shall be returned. |
| 18772 | **/ |
| 18773 | uint16_t |
| 18774 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 18775 | { |
| 18776 | uint16_t next_fcf_index; |
| 18777 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18778 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18779 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18780 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 18781 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18782 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18783 | /* Determine the next fcf index to check */ |
| 18784 | next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18785 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18786 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18787 | next_fcf_index); |
| 18788 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18789 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18790 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18791 | /* |
| 18792 | * If we have wrapped then we need to clear the bits that |
| 18793 | * have been tested so that we can detect when we should |
| 18794 | * change the priority level. |
| 18795 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18796 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18797 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18798 | } |
| 18799 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18800 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18801 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18802 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 18803 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 18804 | /* |
| 18805 | * If next fcf index is not found check if there are lower |
| 18806 | * Priority level fcf's in the fcf_priority list. |
| 18807 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 18808 | * at that level and continue the selection process. |
| 18809 | */ |
| 18810 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18811 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18812 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 18813 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 18814 | |
| 18815 | return LPFC_FCOE_FCF_NEXT_NONE; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18816 | } |
| 18817 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18818 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 18819 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18820 | LPFC_FCF_FLOGI_FAILED) { |
| 18821 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 18822 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 18823 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18824 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18825 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18826 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18827 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18828 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 18829 | next_fcf_index); |
| 18830 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18831 | return next_fcf_index; |
| 18832 | } |
| 18833 | |
| 18834 | /** |
| 18835 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 18836 | * @phba: pointer to lpfc hba data structure. |
| 18837 | * |
| 18838 | * This routine sets the FCF record index in to the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18839 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18840 | * does not go beyond the range of the driver allocated bmask dimension |
| 18841 | * before setting the bit. |
| 18842 | * |
| 18843 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 18844 | * -EINVAL. |
| 18845 | **/ |
| 18846 | int |
| 18847 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18848 | { |
| 18849 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18850 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18851 | "2610 FCF (x%x) reached driver's book " |
| 18852 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18853 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18854 | return -EINVAL; |
| 18855 | } |
| 18856 | /* Set the eligible FCF record index bmask */ |
| 18857 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 18858 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18859 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18860 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18861 | "bmask\n", fcf_index); |
| 18862 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18863 | return 0; |
| 18864 | } |
| 18865 | |
| 18866 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18867 | * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18868 | * @phba: pointer to lpfc hba data structure. |
| 18869 | * |
| 18870 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18871 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18872 | * does not go beyond the range of the driver allocated bmask dimension |
| 18873 | * before clearing the bit. |
| 18874 | **/ |
| 18875 | void |
| 18876 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18877 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18878 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18879 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18880 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18881 | "2762 FCF (x%x) reached driver's book " |
| 18882 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18883 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18884 | return; |
| 18885 | } |
| 18886 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18887 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18888 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 18889 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18890 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 18891 | list_del_init(&fcf_pri->list); |
| 18892 | break; |
| 18893 | } |
| 18894 | } |
| 18895 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18896 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18897 | |
| 18898 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18899 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18900 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18901 | } |
| 18902 | |
| 18903 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18904 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 18905 | * @phba: pointer to lpfc hba data structure. |
| 18906 | * |
| 18907 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 18908 | * command. If the mailbox command returned failure, it will try to stop the |
| 18909 | * FCF rediscover wait timer. |
| 18910 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18911 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18912 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 18913 | { |
| 18914 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18915 | uint32_t shdr_status, shdr_add_status; |
| 18916 | |
| 18917 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18918 | |
| 18919 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 18920 | &redisc_fcf->header.cfg_shdr.response); |
| 18921 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 18922 | &redisc_fcf->header.cfg_shdr.response); |
| 18923 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18924 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18925 | "2746 Requesting for FCF rediscovery failed " |
| 18926 | "status x%x add_status x%x\n", |
| 18927 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18928 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18929 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18930 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18931 | spin_unlock_irq(&phba->hbalock); |
| 18932 | /* |
| 18933 | * CVL event triggered FCF rediscover request failed, |
| 18934 | * last resort to re-try current registered FCF entry. |
| 18935 | */ |
| 18936 | lpfc_retry_pport_discovery(phba); |
| 18937 | } else { |
| 18938 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18939 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18940 | spin_unlock_irq(&phba->hbalock); |
| 18941 | /* |
| 18942 | * DEAD FCF event triggered FCF rediscover request |
| 18943 | * failed, last resort to fail over as a link down |
| 18944 | * to FCF registration. |
| 18945 | */ |
| 18946 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 18947 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18948 | } else { |
| 18949 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18950 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18951 | /* |
| 18952 | * Start FCF rediscovery wait timer for pending FCF |
| 18953 | * before rescan FCF record table. |
| 18954 | */ |
| 18955 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18956 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18957 | |
| 18958 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18959 | } |
| 18960 | |
| 18961 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18962 | * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18963 | * @phba: pointer to lpfc hba data structure. |
| 18964 | * |
| 18965 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 18966 | * by the port. |
| 18967 | **/ |
| 18968 | int |
| 18969 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 18970 | { |
| 18971 | LPFC_MBOXQ_t *mbox; |
| 18972 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18973 | int rc, length; |
| 18974 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18975 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 18976 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 18977 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18978 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18979 | if (!mbox) { |
| 18980 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18981 | "2745 Failed to allocate mbox for " |
| 18982 | "requesting FCF rediscover.\n"); |
| 18983 | return -ENOMEM; |
| 18984 | } |
| 18985 | |
| 18986 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 18987 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 18988 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18989 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 18990 | length, LPFC_SLI4_MBX_EMBED); |
| 18991 | |
| 18992 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18993 | /* Set count to 0 for invalidating the entire FCF database */ |
| 18994 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 18995 | |
| 18996 | /* Issue the mailbox command asynchronously */ |
| 18997 | mbox->vport = phba->pport; |
| 18998 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 18999 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 19000 | |
| 19001 | if (rc == MBX_NOT_FINISHED) { |
| 19002 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19003 | return -EIO; |
| 19004 | } |
| 19005 | return 0; |
| 19006 | } |
| 19007 | |
| 19008 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19009 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 19010 | * @phba: pointer to lpfc hba data structure. |
| 19011 | * |
| 19012 | * This function is the failover routine as a last resort to the FCF DEAD |
| 19013 | * event when driver failed to perform fast FCF failover. |
| 19014 | **/ |
| 19015 | void |
| 19016 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 19017 | { |
| 19018 | uint32_t link_state; |
| 19019 | |
| 19020 | /* |
| 19021 | * Last resort as FCF DEAD event failover will treat this as |
| 19022 | * a link down, but save the link state because we don't want |
| 19023 | * it to be changed to Link Down unless it is already down. |
| 19024 | */ |
| 19025 | link_state = phba->link_state; |
| 19026 | lpfc_linkdown(phba); |
| 19027 | phba->link_state = link_state; |
| 19028 | |
| 19029 | /* Unregister FCF if no devices connected to it */ |
| 19030 | lpfc_unregister_unused_fcf(phba); |
| 19031 | } |
| 19032 | |
| 19033 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19034 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19035 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19036 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19037 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19038 | * This function gets SLI3 port configure region 23 data through memory dump |
| 19039 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19040 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19041 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19042 | static uint32_t |
| 19043 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19044 | { |
| 19045 | LPFC_MBOXQ_t *pmb = NULL; |
| 19046 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19047 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19048 | int rc; |
| 19049 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19050 | if (!rgn23_data) |
| 19051 | return 0; |
| 19052 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19053 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19054 | if (!pmb) { |
| 19055 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19056 | "2600 failed to allocate mailbox memory\n"); |
| 19057 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19058 | } |
| 19059 | mb = &pmb->u.mb; |
| 19060 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19061 | do { |
| 19062 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 19063 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 19064 | |
| 19065 | if (rc != MBX_SUCCESS) { |
| 19066 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19067 | "2601 failed to read config " |
| 19068 | "region 23, rc 0x%x Status 0x%x\n", |
| 19069 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19070 | mb->un.varDmp.word_cnt = 0; |
| 19071 | } |
| 19072 | /* |
| 19073 | * dump mem may return a zero when finished or we got a |
| 19074 | * mailbox error, either way we are done. |
| 19075 | */ |
| 19076 | if (mb->un.varDmp.word_cnt == 0) |
| 19077 | break; |
| 19078 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 19079 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 19080 | |
| 19081 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19082 | rgn23_data + offset, |
| 19083 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19084 | offset += mb->un.varDmp.word_cnt; |
| 19085 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 19086 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19087 | mempool_free(pmb, phba->mbox_mem_pool); |
| 19088 | return offset; |
| 19089 | } |
| 19090 | |
| 19091 | /** |
| 19092 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 19093 | * @phba: pointer to lpfc hba data structure. |
| 19094 | * @rgn23_data: pointer to configure region 23 data. |
| 19095 | * |
| 19096 | * This function gets SLI4 port configure region 23 data through memory dump |
| 19097 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19098 | * will be returned, otherwise, 0 will be returned. |
| 19099 | **/ |
| 19100 | static uint32_t |
| 19101 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 19102 | { |
| 19103 | LPFC_MBOXQ_t *mboxq = NULL; |
| 19104 | struct lpfc_dmabuf *mp = NULL; |
| 19105 | struct lpfc_mqe *mqe; |
| 19106 | uint32_t data_length = 0; |
| 19107 | int rc; |
| 19108 | |
| 19109 | if (!rgn23_data) |
| 19110 | return 0; |
| 19111 | |
| 19112 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19113 | if (!mboxq) { |
| 19114 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19115 | "3105 failed to allocate mailbox memory\n"); |
| 19116 | return 0; |
| 19117 | } |
| 19118 | |
| 19119 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 19120 | goto out; |
| 19121 | mqe = &mboxq->u.mqe; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19122 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19123 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 19124 | if (rc) |
| 19125 | goto out; |
| 19126 | data_length = mqe->un.mb_words[5]; |
| 19127 | if (data_length == 0) |
| 19128 | goto out; |
| 19129 | if (data_length > DMP_RGN23_SIZE) { |
| 19130 | data_length = 0; |
| 19131 | goto out; |
| 19132 | } |
| 19133 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 19134 | out: |
| 19135 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 19136 | if (mp) { |
| 19137 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19138 | kfree(mp); |
| 19139 | } |
| 19140 | return data_length; |
| 19141 | } |
| 19142 | |
| 19143 | /** |
| 19144 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 19145 | * @phba: pointer to lpfc hba data structure. |
| 19146 | * |
| 19147 | * This function read region 23 and parse TLV for port status to |
| 19148 | * decide if the user disaled the port. If the TLV indicates the |
| 19149 | * port is disabled, the hba_flag is set accordingly. |
| 19150 | **/ |
| 19151 | void |
| 19152 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 19153 | { |
| 19154 | uint8_t *rgn23_data = NULL; |
| 19155 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 19156 | uint32_t offset = 0; |
| 19157 | |
| 19158 | /* Get adapter Region 23 data */ |
| 19159 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 19160 | if (!rgn23_data) |
| 19161 | goto out; |
| 19162 | |
| 19163 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 19164 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 19165 | else { |
| 19166 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 19167 | &phba->sli4_hba.sli_intf); |
| 19168 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 19169 | goto out; |
| 19170 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 19171 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19172 | |
| 19173 | if (!data_size) |
| 19174 | goto out; |
| 19175 | |
| 19176 | /* Check the region signature first */ |
| 19177 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 19178 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19179 | "2619 Config region 23 has bad signature\n"); |
| 19180 | goto out; |
| 19181 | } |
| 19182 | offset += 4; |
| 19183 | |
| 19184 | /* Check the data structure version */ |
| 19185 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 19186 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19187 | "2620 Config region 23 has bad version\n"); |
| 19188 | goto out; |
| 19189 | } |
| 19190 | offset += 4; |
| 19191 | |
| 19192 | /* Parse TLV entries in the region */ |
| 19193 | while (offset < data_size) { |
| 19194 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 19195 | break; |
| 19196 | /* |
| 19197 | * If the TLV is not driver specific TLV or driver id is |
| 19198 | * not linux driver id, skip the record. |
| 19199 | */ |
| 19200 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 19201 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 19202 | (rgn23_data[offset + 3] != 0)) { |
| 19203 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19204 | continue; |
| 19205 | } |
| 19206 | |
| 19207 | /* Driver found a driver specific TLV in the config region */ |
| 19208 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 19209 | offset += 4; |
| 19210 | tlv_offset = 0; |
| 19211 | |
| 19212 | /* |
| 19213 | * Search for configured port state sub-TLV. |
| 19214 | */ |
| 19215 | while ((offset < data_size) && |
| 19216 | (tlv_offset < sub_tlv_len)) { |
| 19217 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 19218 | offset += 4; |
| 19219 | tlv_offset += 4; |
| 19220 | break; |
| 19221 | } |
| 19222 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 19223 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19224 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 19225 | continue; |
| 19226 | } |
| 19227 | |
| 19228 | /* This HBA contains PORT_STE configured */ |
| 19229 | if (!rgn23_data[offset + 2]) |
| 19230 | phba->hba_flag |= LINK_DISABLED; |
| 19231 | |
| 19232 | goto out; |
| 19233 | } |
| 19234 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19235 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19236 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19237 | kfree(rgn23_data); |
| 19238 | return; |
| 19239 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19240 | |
| 19241 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19242 | * lpfc_wr_object - write an object to the firmware |
| 19243 | * @phba: HBA structure that indicates port to create a queue on. |
| 19244 | * @dmabuf_list: list of dmabufs to write to the port. |
| 19245 | * @size: the total byte value of the objects to write to the port. |
| 19246 | * @offset: the current offset to be used to start the transfer. |
| 19247 | * |
| 19248 | * This routine will create a wr_object mailbox command to send to the port. |
| 19249 | * the mailbox command will be constructed using the dma buffers described in |
| 19250 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 19251 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 19252 | * used to indicate the starting offset of the transfer and will also return |
| 19253 | * the offset after the write object mailbox has completed. @size is used to |
| 19254 | * determine the end of the object and whether the eof bit should be set. |
| 19255 | * |
| 19256 | * Return 0 is successful and offset will contain the the new offset to use |
| 19257 | * for the next write. |
| 19258 | * Return negative value for error cases. |
| 19259 | **/ |
| 19260 | int |
| 19261 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 19262 | uint32_t size, uint32_t *offset) |
| 19263 | { |
| 19264 | struct lpfc_mbx_wr_object *wr_object; |
| 19265 | LPFC_MBOXQ_t *mbox; |
| 19266 | int rc = 0, i = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame^] | 19267 | uint32_t shdr_status, shdr_add_status, shdr_change_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19268 | uint32_t mbox_tmo; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19269 | struct lpfc_dmabuf *dmabuf; |
| 19270 | uint32_t written = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame^] | 19271 | bool check_change_status = false; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19272 | |
| 19273 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19274 | if (!mbox) |
| 19275 | return -ENOMEM; |
| 19276 | |
| 19277 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 19278 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 19279 | sizeof(struct lpfc_mbx_wr_object) - |
| 19280 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 19281 | |
| 19282 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 19283 | wr_object->u.request.write_offset = *offset; |
| 19284 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 19285 | wr_object->u.request.object_name[0] = |
| 19286 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 19287 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 19288 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 19289 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 19290 | break; |
| 19291 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 19292 | wr_object->u.request.bde[i].addrHigh = |
| 19293 | putPaddrHigh(dmabuf->phys); |
| 19294 | if (written + SLI4_PAGE_SIZE >= size) { |
| 19295 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19296 | (size - written); |
| 19297 | written += (size - written); |
| 19298 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame^] | 19299 | bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1); |
| 19300 | check_change_status = true; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19301 | } else { |
| 19302 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19303 | SLI4_PAGE_SIZE; |
| 19304 | written += SLI4_PAGE_SIZE; |
| 19305 | } |
| 19306 | i++; |
| 19307 | } |
| 19308 | wr_object->u.request.bde_count = i; |
| 19309 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 19310 | if (!phba->sli4_hba.intr_enable) |
| 19311 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 19312 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 19313 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19314 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 19315 | } |
| 19316 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame^] | 19317 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 19318 | &wr_object->header.cfg_shdr.response); |
| 19319 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 19320 | &wr_object->header.cfg_shdr.response); |
| 19321 | if (check_change_status) { |
| 19322 | shdr_change_status = bf_get(lpfc_wr_object_change_status, |
| 19323 | &wr_object->u.response); |
| 19324 | switch (shdr_change_status) { |
| 19325 | case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET): |
| 19326 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19327 | "3198 Firmware write complete: System " |
| 19328 | "reboot required to instantiate\n"); |
| 19329 | break; |
| 19330 | case (LPFC_CHANGE_STATUS_FW_RESET): |
| 19331 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19332 | "3199 Firmware write complete: Firmware" |
| 19333 | " reset required to instantiate\n"); |
| 19334 | break; |
| 19335 | case (LPFC_CHANGE_STATUS_PORT_MIGRATION): |
| 19336 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19337 | "3200 Firmware write complete: Port " |
| 19338 | "Migration or PCI Reset required to " |
| 19339 | "instantiate\n"); |
| 19340 | break; |
| 19341 | case (LPFC_CHANGE_STATUS_PCI_RESET): |
| 19342 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19343 | "3201 Firmware write complete: PCI " |
| 19344 | "Reset required to instantiate\n"); |
| 19345 | break; |
| 19346 | default: |
| 19347 | break; |
| 19348 | } |
| 19349 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19350 | if (rc != MBX_TIMEOUT) |
| 19351 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19352 | if (shdr_status || shdr_add_status || rc) { |
| 19353 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19354 | "3025 Write Object mailbox failed with " |
| 19355 | "status x%x add_status x%x, mbx status x%x\n", |
| 19356 | shdr_status, shdr_add_status, rc); |
| 19357 | rc = -ENXIO; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 19358 | *offset = shdr_add_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19359 | } else |
| 19360 | *offset += wr_object->u.response.actual_write_length; |
| 19361 | return rc; |
| 19362 | } |
| 19363 | |
| 19364 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19365 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 19366 | * @vport: pointer to vport data structure. |
| 19367 | * |
| 19368 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 19369 | * and REG_VPI mailbox commands associated with the vport. This function |
| 19370 | * is called when driver want to restart discovery of the vport due to |
| 19371 | * a Clear Virtual Link event. |
| 19372 | **/ |
| 19373 | void |
| 19374 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 19375 | { |
| 19376 | struct lpfc_hba *phba = vport->phba; |
| 19377 | LPFC_MBOXQ_t *mb, *nextmb; |
| 19378 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19379 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19380 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19381 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19382 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19383 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19384 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19385 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19386 | spin_lock_irq(&phba->hbalock); |
| 19387 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 19388 | if (mb->vport != vport) |
| 19389 | continue; |
| 19390 | |
| 19391 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19392 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19393 | continue; |
| 19394 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19395 | list_del(&mb->list); |
| 19396 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 19397 | } |
| 19398 | /* Clean up active mailbox command with the vport */ |
| 19399 | mb = phba->sli.mbox_active; |
| 19400 | if (mb && (mb->vport == vport)) { |
| 19401 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 19402 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 19403 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19404 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19405 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19406 | /* Put reference count for delayed processing */ |
| 19407 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 19408 | /* Unregister the RPI when mailbox complete */ |
| 19409 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19410 | } |
| 19411 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19412 | /* Cleanup any mailbox completions which are not yet processed */ |
| 19413 | do { |
| 19414 | restart_loop = 0; |
| 19415 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 19416 | /* |
| 19417 | * If this mailox is already processed or it is |
| 19418 | * for another vport ignore it. |
| 19419 | */ |
| 19420 | if ((mb->vport != vport) || |
| 19421 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 19422 | continue; |
| 19423 | |
| 19424 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19425 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19426 | continue; |
| 19427 | |
| 19428 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19429 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19430 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19431 | /* Unregister the RPI when mailbox complete */ |
| 19432 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19433 | restart_loop = 1; |
| 19434 | spin_unlock_irq(&phba->hbalock); |
| 19435 | spin_lock(shost->host_lock); |
| 19436 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19437 | spin_unlock(shost->host_lock); |
| 19438 | spin_lock_irq(&phba->hbalock); |
| 19439 | break; |
| 19440 | } |
| 19441 | } |
| 19442 | } while (restart_loop); |
| 19443 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19444 | spin_unlock_irq(&phba->hbalock); |
| 19445 | |
| 19446 | /* Release the cleaned-up mailbox commands */ |
| 19447 | while (!list_empty(&mbox_cmd_list)) { |
| 19448 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19449 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19450 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19451 | if (mp) { |
| 19452 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19453 | kfree(mp); |
| 19454 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19455 | mb->ctx_buf = NULL; |
| 19456 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
| 19457 | mb->ctx_ndlp = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19458 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19459 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19460 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19461 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19462 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19463 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19464 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19465 | mempool_free(mb, phba->mbox_mem_pool); |
| 19466 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19467 | |
| 19468 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 19469 | if (act_mbx_ndlp) { |
| 19470 | spin_lock(shost->host_lock); |
| 19471 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19472 | spin_unlock(shost->host_lock); |
| 19473 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19474 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19475 | } |
| 19476 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19477 | /** |
| 19478 | * lpfc_drain_txq - Drain the txq |
| 19479 | * @phba: Pointer to HBA context object. |
| 19480 | * |
| 19481 | * This function attempt to submit IOCBs on the txq |
| 19482 | * to the adapter. For SLI4 adapters, the txq contains |
| 19483 | * ELS IOCBs that have been deferred because the there |
| 19484 | * are no SGLs. This congestion can occur with large |
| 19485 | * vport counts during node discovery. |
| 19486 | **/ |
| 19487 | |
| 19488 | uint32_t |
| 19489 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 19490 | { |
| 19491 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19492 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 19493 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19494 | unsigned long iflags = 0; |
| 19495 | char *fail_msg = NULL; |
| 19496 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19497 | union lpfc_wqe128 wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 19498 | uint32_t txq_cnt = 0; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19499 | struct lpfc_queue *wq; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19500 | |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19501 | if (phba->link_flag & LS_MDS_LOOPBACK) { |
| 19502 | /* MDS WQE are posted only to first WQ*/ |
| 19503 | wq = phba->sli4_hba.fcp_wq[0]; |
| 19504 | if (unlikely(!wq)) |
| 19505 | return 0; |
| 19506 | pring = wq->pring; |
| 19507 | } else { |
| 19508 | wq = phba->sli4_hba.els_wq; |
| 19509 | if (unlikely(!wq)) |
| 19510 | return 0; |
| 19511 | pring = lpfc_phba_elsring(phba); |
| 19512 | } |
| 19513 | |
| 19514 | if (unlikely(!pring) || list_empty(&pring->txq)) |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 19515 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19516 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19517 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19518 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 19519 | txq_cnt++; |
| 19520 | } |
| 19521 | |
| 19522 | if (txq_cnt > pring->txq_max) |
| 19523 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19524 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19525 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19526 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19527 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19528 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19529 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19530 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19531 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19532 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19533 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19534 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19535 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19536 | break; |
| 19537 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19538 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19539 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19540 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19541 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19542 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19543 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19544 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19545 | |
| 19546 | /* The xri and iocb resources secured, |
| 19547 | * attempt to issue request |
| 19548 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19549 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19550 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 19551 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 19552 | fail_msg = "to convert bpl to sgl"; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19553 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19554 | fail_msg = "to convert iocb to wqe"; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19555 | else if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19556 | fail_msg = " - Wq is full"; |
| 19557 | else |
| 19558 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 19559 | |
| 19560 | if (fail_msg) { |
| 19561 | /* Failed means we can't issue and need to cancel */ |
| 19562 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19563 | "2822 IOCB failed %s iotag 0x%x " |
| 19564 | "xri 0x%x\n", |
| 19565 | fail_msg, |
| 19566 | piocbq->iotag, piocbq->sli4_xritag); |
| 19567 | list_add_tail(&piocbq->list, &completions); |
| 19568 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19569 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19570 | } |
| 19571 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19572 | /* Cancel all the IOCBs that cannot be issued */ |
| 19573 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 19574 | IOERR_SLI_ABORTED); |
| 19575 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19576 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19577 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19578 | |
| 19579 | /** |
| 19580 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 19581 | * @phba: Pointer to HBA context object. |
| 19582 | * @pwqe: Pointer to command WQE. |
| 19583 | * @sglq: Pointer to the scatter gather queue object. |
| 19584 | * |
| 19585 | * This routine converts the bpl or bde that is in the WQE |
| 19586 | * to a sgl list for the sli4 hardware. The physical address |
| 19587 | * of the bpl/bde is converted back to a virtual address. |
| 19588 | * If the WQE contains a BPL then the list of BDE's is |
| 19589 | * converted to sli4_sge's. If the WQE contains a single |
| 19590 | * BDE then it is converted to a single sli_sge. |
| 19591 | * The WQE is still in cpu endianness so the contents of |
| 19592 | * the bpl can be used without byte swapping. |
| 19593 | * |
| 19594 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 19595 | */ |
| 19596 | static uint16_t |
| 19597 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 19598 | struct lpfc_sglq *sglq) |
| 19599 | { |
| 19600 | uint16_t xritag = NO_XRI; |
| 19601 | struct ulp_bde64 *bpl = NULL; |
| 19602 | struct ulp_bde64 bde; |
| 19603 | struct sli4_sge *sgl = NULL; |
| 19604 | struct lpfc_dmabuf *dmabuf; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19605 | union lpfc_wqe128 *wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19606 | int numBdes = 0; |
| 19607 | int i = 0; |
| 19608 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 19609 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 19610 | uint32_t cmd; |
| 19611 | |
| 19612 | if (!pwqeq || !sglq) |
| 19613 | return xritag; |
| 19614 | |
| 19615 | sgl = (struct sli4_sge *)sglq->sgl; |
| 19616 | wqe = &pwqeq->wqe; |
| 19617 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 19618 | |
| 19619 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 19620 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 19621 | return sglq->sli4_xritag; |
| 19622 | numBdes = pwqeq->rsvd2; |
| 19623 | if (numBdes) { |
| 19624 | /* The addrHigh and addrLow fields within the WQE |
| 19625 | * have not been byteswapped yet so there is no |
| 19626 | * need to swap them back. |
| 19627 | */ |
| 19628 | if (pwqeq->context3) |
| 19629 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 19630 | else |
| 19631 | return xritag; |
| 19632 | |
| 19633 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 19634 | if (!bpl) |
| 19635 | return xritag; |
| 19636 | |
| 19637 | for (i = 0; i < numBdes; i++) { |
| 19638 | /* Should already be byte swapped. */ |
| 19639 | sgl->addr_hi = bpl->addrHigh; |
| 19640 | sgl->addr_lo = bpl->addrLow; |
| 19641 | |
| 19642 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19643 | if ((i+1) == numBdes) |
| 19644 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19645 | else |
| 19646 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 19647 | /* swap the size field back to the cpu so we |
| 19648 | * can assign it to the sgl. |
| 19649 | */ |
| 19650 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 19651 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 19652 | /* The offsets in the sgl need to be accumulated |
| 19653 | * separately for the request and reply lists. |
| 19654 | * The request is always first, the reply follows. |
| 19655 | */ |
| 19656 | switch (cmd) { |
| 19657 | case CMD_GEN_REQUEST64_WQE: |
| 19658 | /* add up the reply sg entries */ |
| 19659 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 19660 | inbound++; |
| 19661 | /* first inbound? reset the offset */ |
| 19662 | if (inbound == 1) |
| 19663 | offset = 0; |
| 19664 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19665 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19666 | LPFC_SGE_TYPE_DATA); |
| 19667 | offset += bde.tus.f.bdeSize; |
| 19668 | break; |
| 19669 | case CMD_FCP_TRSP64_WQE: |
| 19670 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 19671 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19672 | LPFC_SGE_TYPE_DATA); |
| 19673 | break; |
| 19674 | case CMD_FCP_TSEND64_WQE: |
| 19675 | case CMD_FCP_TRECEIVE64_WQE: |
| 19676 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19677 | bpl->tus.f.bdeFlags); |
| 19678 | if (i < 3) |
| 19679 | offset = 0; |
| 19680 | else |
| 19681 | offset += bde.tus.f.bdeSize; |
| 19682 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19683 | break; |
| 19684 | } |
| 19685 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19686 | bpl++; |
| 19687 | sgl++; |
| 19688 | } |
| 19689 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 19690 | /* The addrHigh and addrLow fields of the BDE have not |
| 19691 | * been byteswapped yet so they need to be swapped |
| 19692 | * before putting them in the sgl. |
| 19693 | */ |
| 19694 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 19695 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 19696 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19697 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19698 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19699 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 19700 | } |
| 19701 | return sglq->sli4_xritag; |
| 19702 | } |
| 19703 | |
| 19704 | /** |
| 19705 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 19706 | * @phba: Pointer to HBA context object. |
| 19707 | * @ring_number: Base sli ring number |
| 19708 | * @pwqe: Pointer to command WQE. |
| 19709 | **/ |
| 19710 | int |
| 19711 | lpfc_sli4_issue_wqe(struct lpfc_hba *phba, uint32_t ring_number, |
| 19712 | struct lpfc_iocbq *pwqe) |
| 19713 | { |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19714 | union lpfc_wqe128 *wqe = &pwqe->wqe; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19715 | struct lpfc_nvmet_rcv_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19716 | struct lpfc_queue *wq; |
| 19717 | struct lpfc_sglq *sglq; |
| 19718 | struct lpfc_sli_ring *pring; |
| 19719 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19720 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19721 | |
| 19722 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 19723 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 19724 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 19725 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 19726 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 19727 | if (!sglq) { |
| 19728 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19729 | return WQE_BUSY; |
| 19730 | } |
| 19731 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19732 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19733 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 19734 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19735 | return WQE_ERROR; |
| 19736 | } |
| 19737 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19738 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19739 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 19740 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19741 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19742 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19743 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19744 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19745 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19746 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19747 | return 0; |
| 19748 | } |
| 19749 | |
| 19750 | /* NVME_FCREQ and NVME_ABTS requests */ |
| 19751 | if (pwqe->iocb_flag & LPFC_IO_NVME) { |
| 19752 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
| 19753 | pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring; |
| 19754 | |
| 19755 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 19756 | wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]; |
| 19757 | bf_set(wqe_cqid, &wqe->generic.wqe_com, |
| 19758 | phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19759 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19760 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19761 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19762 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19763 | } |
| 19764 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19765 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19766 | return 0; |
| 19767 | } |
| 19768 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19769 | /* NVMET requests */ |
| 19770 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 19771 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
| 19772 | pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring; |
| 19773 | |
| 19774 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 19775 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 19776 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19777 | if (pwqe->sli4_xritag == NO_XRI) { |
| 19778 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19779 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19780 | } |
| 19781 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19782 | pwqe->sli4_xritag); |
| 19783 | wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]; |
| 19784 | bf_set(wqe_cqid, &wqe->generic.wqe_com, |
| 19785 | phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19786 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19787 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19788 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19789 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19790 | } |
| 19791 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19792 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19793 | return 0; |
| 19794 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19795 | return WQE_ERROR; |
| 19796 | } |