| 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 | 0d04121 | 2019-01-28 11:14:41 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2019 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 | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 81 | static bool lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, |
| 82 | struct lpfc_queue *cq, struct lpfc_cqe *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, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 86 | struct lpfc_queue *eq, |
| 87 | struct lpfc_eqe *eqe); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 88 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
| 89 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 90 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 91 | static IOCB_t * |
| 92 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 93 | { |
| 94 | return &iocbq->iocb; |
| 95 | } |
| 96 | |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 97 | #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN) |
| 98 | /** |
| 99 | * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function |
| 100 | * @srcp: Source memory pointer. |
| 101 | * @destp: Destination memory pointer. |
| 102 | * @cnt: Number of words required to be copied. |
| 103 | * Must be a multiple of sizeof(uint64_t) |
| 104 | * |
| 105 | * This function is used for copying data between driver memory |
| 106 | * and the SLI WQ. This function also changes the endianness |
| 107 | * of each word if native endianness is different from SLI |
| 108 | * endianness. This function can be called with or without |
| 109 | * lock. |
| 110 | **/ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 111 | static void |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 112 | lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 113 | { |
| 114 | uint64_t *src = srcp; |
| 115 | uint64_t *dest = destp; |
| 116 | int i; |
| 117 | |
| 118 | for (i = 0; i < (int)cnt; i += sizeof(uint64_t)) |
| 119 | *dest++ = *src++; |
| 120 | } |
| 121 | #else |
| 122 | #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c) |
| 123 | #endif |
| 124 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 125 | /** |
| 126 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 127 | * @q: The Work Queue to operate on. |
| 128 | * @wqe: The work Queue Entry to put on the Work queue. |
| 129 | * |
| 130 | * This routine will copy the contents of @wqe to the next available entry on |
| 131 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 132 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 133 | * successful. If no entries are available on @q then this function will return |
| 134 | * -ENOMEM. |
| 135 | * The caller is expected to hold the hbalock when calling this routine. |
| 136 | **/ |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 137 | static int |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 138 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 139 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 140 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 141 | struct lpfc_register doorbell; |
| 142 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 143 | uint32_t idx; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 144 | uint32_t i = 0; |
| 145 | uint8_t *tmp; |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame] | 146 | u32 if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 147 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 148 | /* sanity check on queue memory */ |
| 149 | if (unlikely(!q)) |
| 150 | return -ENOMEM; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 151 | temp_wqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 152 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 153 | /* 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] | 154 | idx = ((q->host_index + 1) % q->entry_count); |
| 155 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 156 | q->WQ_overflow++; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 157 | return -EBUSY; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 158 | } |
| 159 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 160 | /* set consumption flag every once in a while */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 161 | if (!((q->host_index + 1) % q->notify_interval)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 162 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | 04673e3 | 2018-01-30 15:58:45 -0800 | [diff] [blame] | 163 | else |
| 164 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 0); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 165 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 166 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 167 | lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 168 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 169 | /* write to DPP aperture taking advatage of Combined Writes */ |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 170 | tmp = (uint8_t *)temp_wqe; |
| 171 | #ifdef __raw_writeq |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 172 | for (i = 0; i < q->entry_size; i += sizeof(uint64_t)) |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 173 | __raw_writeq(*((uint64_t *)(tmp + i)), |
| 174 | q->dpp_regaddr + i); |
| 175 | #else |
| 176 | for (i = 0; i < q->entry_size; i += sizeof(uint32_t)) |
| 177 | __raw_writel(*((uint32_t *)(tmp + i)), |
| 178 | q->dpp_regaddr + i); |
| 179 | #endif |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 180 | } |
| 181 | /* ensure WQE bcopy and DPP flushed before doorbell write */ |
James Smart | 6b3b3bd | 2016-12-19 15:07:30 -0800 | [diff] [blame] | 182 | wmb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 183 | |
| 184 | /* Update the host index before invoking device */ |
| 185 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 186 | |
| 187 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 188 | |
| 189 | /* Ring Doorbell */ |
| 190 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 191 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 192 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 193 | bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1); |
| 194 | bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1); |
| 195 | bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell, |
| 196 | q->dpp_id); |
| 197 | bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell, |
| 198 | q->queue_id); |
| 199 | } else { |
| 200 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 201 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame] | 202 | |
| 203 | /* Leave bits <23:16> clear for if_type 6 dpp */ |
| 204 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 205 | &q->phba->sli4_hba.sli_intf); |
| 206 | if (if_type != LPFC_SLI_INTF_IF_TYPE_6) |
| 207 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, |
| 208 | host_index); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 209 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 210 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 211 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 212 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 213 | } else { |
| 214 | return -EINVAL; |
| 215 | } |
| 216 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 223 | * @q: The Work Queue to operate on. |
| 224 | * @index: The index to advance the hba index to. |
| 225 | * |
| 226 | * This routine will update the HBA index of a queue to reflect consumption of |
| 227 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 228 | * an entry the host calls this function to update the queue's internal |
| 229 | * pointers. This routine returns the number of entries that were consumed by |
| 230 | * the HBA. |
| 231 | **/ |
| 232 | static uint32_t |
| 233 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 234 | { |
| 235 | uint32_t released = 0; |
| 236 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 237 | /* sanity check on queue memory */ |
| 238 | if (unlikely(!q)) |
| 239 | return 0; |
| 240 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 241 | if (q->hba_index == index) |
| 242 | return 0; |
| 243 | do { |
| 244 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 245 | released++; |
| 246 | } while (q->hba_index != index); |
| 247 | return released; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 252 | * @q: The Mailbox Queue to operate on. |
| 253 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 254 | * |
| 255 | * This routine will copy the contents of @mqe to the next available entry on |
| 256 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 257 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 258 | * successful. If no entries are available on @q then this function will return |
| 259 | * -ENOMEM. |
| 260 | * The caller is expected to hold the hbalock when calling this routine. |
| 261 | **/ |
| 262 | static uint32_t |
| 263 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 264 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 265 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 266 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 267 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 268 | /* sanity check on queue memory */ |
| 269 | if (unlikely(!q)) |
| 270 | return -ENOMEM; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 271 | temp_mqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 272 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 273 | /* If the host has not yet processed the next entry then we are done */ |
| 274 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 275 | return -ENOMEM; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 276 | lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 277 | /* Save off the mailbox pointer for completion */ |
| 278 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 279 | |
| 280 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 281 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 282 | |
| 283 | /* Ring Doorbell */ |
| 284 | doorbell.word0 = 0; |
| 285 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 286 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 287 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 293 | * @q: The Mailbox Queue to operate on. |
| 294 | * |
| 295 | * This routine will update the HBA index of a queue to reflect consumption of |
| 296 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 297 | * an entry the host calls this function to update the queue's internal |
| 298 | * pointers. This routine returns the number of entries that were consumed by |
| 299 | * the HBA. |
| 300 | **/ |
| 301 | static uint32_t |
| 302 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 303 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 304 | /* sanity check on queue memory */ |
| 305 | if (unlikely(!q)) |
| 306 | return 0; |
| 307 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 308 | /* Clear the mailbox pointer for completion */ |
| 309 | q->phba->mbox = NULL; |
| 310 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 311 | return 1; |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 316 | * @q: The Event Queue to get the first valid EQE from |
| 317 | * |
| 318 | * This routine will get the first valid Event Queue Entry from @q, update |
| 319 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 320 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 321 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 322 | **/ |
| 323 | static struct lpfc_eqe * |
| 324 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 325 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 326 | struct lpfc_eqe *eqe; |
| 327 | |
| 328 | /* sanity check on queue memory */ |
| 329 | if (unlikely(!q)) |
| 330 | return NULL; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 331 | eqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 332 | |
| 333 | /* If the next EQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 334 | if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 335 | return NULL; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 336 | |
| 337 | /* |
| 338 | * insert barrier for instruction interlock : data from the hardware |
| 339 | * 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] | 340 | * upon. Speculative instructions were allowing a bcopy at the start |
| 341 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 342 | * after our return, to copy data before the valid bit check above |
| 343 | * was done. As such, some of the copied data was stale. The barrier |
| 344 | * ensures the check is before any data is copied. |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 345 | */ |
| 346 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 347 | return eqe; |
| 348 | } |
| 349 | |
| 350 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 351 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 352 | * @q: The Event Queue to disable interrupts |
| 353 | * |
| 354 | **/ |
James Smart | 92f3b32 | 2019-03-20 10:44:22 -0700 | [diff] [blame] | 355 | void |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 356 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 357 | { |
| 358 | struct lpfc_register doorbell; |
| 359 | |
| 360 | doorbell.word0 = 0; |
| 361 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 362 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 363 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 364 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 365 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 366 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 370 | * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ |
| 371 | * @q: The Event Queue to disable interrupts |
| 372 | * |
| 373 | **/ |
James Smart | 92f3b32 | 2019-03-20 10:44:22 -0700 | [diff] [blame] | 374 | void |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 375 | lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q) |
| 376 | { |
| 377 | struct lpfc_register doorbell; |
| 378 | |
| 379 | doorbell.word0 = 0; |
James Smart | aad59d5 | 2018-09-10 10:30:47 -0700 | [diff] [blame] | 380 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 381 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 382 | } |
| 383 | |
| 384 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 385 | * lpfc_sli4_write_eq_db - write EQ DB for eqe's consumed or arm state |
| 386 | * @phba: adapter with EQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 387 | * @q: The Event Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 388 | * @count: Number of elements that have been consumed |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 389 | * @arm: Indicates whether the host wants to arms this CQ. |
| 390 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 391 | * This routine will notify the HBA, by ringing the doorbell, that count |
| 392 | * number of EQEs have been processed. The @arm parameter indicates whether |
| 393 | * the queue should be rearmed when ringing the doorbell. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 394 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 395 | void |
| 396 | lpfc_sli4_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 397 | uint32_t count, bool arm) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 398 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 399 | struct lpfc_register doorbell; |
| 400 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 401 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 402 | if (unlikely(!q || (count == 0 && !arm))) |
| 403 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 404 | |
| 405 | /* ring doorbell for number popped */ |
| 406 | doorbell.word0 = 0; |
| 407 | if (arm) { |
| 408 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 409 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 410 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 411 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 412 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 413 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 414 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 415 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 416 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 417 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 418 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 419 | readl(q->phba->sli4_hba.EQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 423 | * lpfc_sli4_if6_write_eq_db - write EQ DB for eqe's consumed or arm state |
| 424 | * @phba: adapter with EQ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 425 | * @q: The Event Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 426 | * @count: Number of elements that have been consumed |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 427 | * @arm: Indicates whether the host wants to arms this CQ. |
| 428 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 429 | * This routine will notify the HBA, by ringing the doorbell, that count |
| 430 | * number of EQEs have been processed. The @arm parameter indicates whether |
| 431 | * the queue should be rearmed when ringing the doorbell. |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 432 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 433 | void |
| 434 | lpfc_sli4_if6_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 435 | uint32_t count, bool arm) |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 436 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 437 | struct lpfc_register doorbell; |
| 438 | |
| 439 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 440 | if (unlikely(!q || (count == 0 && !arm))) |
| 441 | return; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 442 | |
| 443 | /* ring doorbell for number popped */ |
| 444 | doorbell.word0 = 0; |
| 445 | if (arm) |
| 446 | bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 447 | bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, count); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 448 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
| 449 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 450 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 451 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 452 | readl(q->phba->sli4_hba.EQDBregaddr); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | static void |
| 456 | __lpfc_sli4_consume_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 457 | struct lpfc_eqe *eqe) |
| 458 | { |
| 459 | if (!phba->sli4_hba.pc_sli4_params.eqav) |
| 460 | bf_set_le32(lpfc_eqe_valid, eqe, 0); |
| 461 | |
| 462 | eq->host_index = ((eq->host_index + 1) % eq->entry_count); |
| 463 | |
| 464 | /* if the index wrapped around, toggle the valid bit */ |
| 465 | if (phba->sli4_hba.pc_sli4_params.eqav && !eq->host_index) |
| 466 | eq->qe_valid = (eq->qe_valid) ? 0 : 1; |
| 467 | } |
| 468 | |
| 469 | static void |
| 470 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 471 | { |
| 472 | struct lpfc_eqe *eqe; |
| 473 | uint32_t count = 0; |
| 474 | |
| 475 | /* walk all the EQ entries and drop on the floor */ |
| 476 | eqe = lpfc_sli4_eq_get(eq); |
| 477 | while (eqe) { |
| 478 | __lpfc_sli4_consume_eqe(phba, eq, eqe); |
| 479 | count++; |
| 480 | eqe = lpfc_sli4_eq_get(eq); |
| 481 | } |
| 482 | |
| 483 | /* Clear and re-arm the EQ */ |
| 484 | phba->sli4_hba.sli4_write_eq_db(phba, eq, count, LPFC_QUEUE_REARM); |
| 485 | } |
| 486 | |
| 487 | static int |
| 488 | lpfc_sli4_process_eq(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 489 | { |
| 490 | struct lpfc_eqe *eqe; |
| 491 | int count = 0, consumed = 0; |
| 492 | |
| 493 | if (cmpxchg(&eq->queue_claimed, 0, 1) != 0) |
| 494 | goto rearm_and_exit; |
| 495 | |
| 496 | eqe = lpfc_sli4_eq_get(eq); |
| 497 | while (eqe) { |
| 498 | lpfc_sli4_hba_handle_eqe(phba, eq, eqe); |
| 499 | __lpfc_sli4_consume_eqe(phba, eq, eqe); |
| 500 | |
| 501 | consumed++; |
| 502 | if (!(++count % eq->max_proc_limit)) |
| 503 | break; |
| 504 | |
| 505 | if (!(count % eq->notify_interval)) { |
| 506 | phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, |
| 507 | LPFC_QUEUE_NOARM); |
| 508 | consumed = 0; |
| 509 | } |
| 510 | |
| 511 | eqe = lpfc_sli4_eq_get(eq); |
| 512 | } |
| 513 | eq->EQ_processed += count; |
| 514 | |
| 515 | /* Track the max number of EQEs processed in 1 intr */ |
| 516 | if (count > eq->EQ_max_eqe) |
| 517 | eq->EQ_max_eqe = count; |
| 518 | |
| 519 | eq->queue_claimed = 0; |
| 520 | |
| 521 | rearm_and_exit: |
| 522 | /* Always clear and re-arm the EQ */ |
| 523 | phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, LPFC_QUEUE_REARM); |
| 524 | |
| 525 | return count; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 529 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 530 | * @q: The Completion Queue to get the first valid CQE from |
| 531 | * |
| 532 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 533 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 534 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 535 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 536 | **/ |
| 537 | static struct lpfc_cqe * |
| 538 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 539 | { |
| 540 | struct lpfc_cqe *cqe; |
| 541 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 542 | /* sanity check on queue memory */ |
| 543 | if (unlikely(!q)) |
| 544 | return NULL; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 545 | cqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 546 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 547 | /* If the next CQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 548 | if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 549 | return NULL; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 550 | |
| 551 | /* |
| 552 | * insert barrier for instruction interlock : data from the hardware |
| 553 | * 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] | 554 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 555 | * instructions allowing action on content before valid bit checked, |
| 556 | * add barrier here as well. May not be needed as "content" is a |
| 557 | * single 32-bit entity here (vs multi word structure for cq's). |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 558 | */ |
| 559 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 560 | return cqe; |
| 561 | } |
| 562 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 563 | static void |
| 564 | __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 565 | struct lpfc_cqe *cqe) |
| 566 | { |
| 567 | if (!phba->sli4_hba.pc_sli4_params.cqav) |
| 568 | bf_set_le32(lpfc_cqe_valid, cqe, 0); |
| 569 | |
| 570 | cq->host_index = ((cq->host_index + 1) % cq->entry_count); |
| 571 | |
| 572 | /* if the index wrapped around, toggle the valid bit */ |
| 573 | if (phba->sli4_hba.pc_sli4_params.cqav && !cq->host_index) |
| 574 | cq->qe_valid = (cq->qe_valid) ? 0 : 1; |
| 575 | } |
| 576 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 577 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 578 | * lpfc_sli4_write_cq_db - write cq DB for entries consumed or arm state. |
| 579 | * @phba: the adapter with the CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 580 | * @q: The Completion Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 581 | * @count: the number of elements that were consumed |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 582 | * @arm: Indicates whether the host wants to arms this CQ. |
| 583 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 584 | * This routine will notify the HBA, by ringing the doorbell, that the |
| 585 | * CQEs have been processed. The @arm parameter specifies whether the |
| 586 | * queue should be rearmed when ringing the doorbell. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 587 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 588 | void |
| 589 | lpfc_sli4_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 590 | uint32_t count, bool arm) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 591 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 592 | struct lpfc_register doorbell; |
| 593 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 594 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 595 | if (unlikely(!q || (count == 0 && !arm))) |
| 596 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 597 | |
| 598 | /* ring doorbell for number popped */ |
| 599 | doorbell.word0 = 0; |
| 600 | if (arm) |
| 601 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 602 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 603 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 604 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 605 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 606 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 607 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 611 | * lpfc_sli4_if6_write_cq_db - write cq DB for entries consumed or arm state. |
| 612 | * @phba: the adapter with the CQ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 613 | * @q: The Completion Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 614 | * @count: the number of elements that were consumed |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 615 | * @arm: Indicates whether the host wants to arms this CQ. |
| 616 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 617 | * This routine will notify the HBA, by ringing the doorbell, that the |
| 618 | * CQEs have been processed. The @arm parameter specifies whether the |
| 619 | * queue should be rearmed when ringing the doorbell. |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 620 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 621 | void |
| 622 | lpfc_sli4_if6_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 623 | uint32_t count, bool arm) |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 624 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 625 | struct lpfc_register doorbell; |
| 626 | |
| 627 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 628 | if (unlikely(!q || (count == 0 && !arm))) |
| 629 | return; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 630 | |
| 631 | /* ring doorbell for number popped */ |
| 632 | doorbell.word0 = 0; |
| 633 | if (arm) |
| 634 | bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 635 | bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, count); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 636 | bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id); |
| 637 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 641 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 642 | * @q: The Header Receive Queue to operate on. |
| 643 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 644 | * |
| 645 | * This routine will copy the contents of @wqe to the next available entry on |
| 646 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 647 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 648 | * index that the rqe was copied to if successful. If no entries are available |
| 649 | * on @q then this function will return -ENOMEM. |
| 650 | * The caller is expected to hold the hbalock when calling this routine. |
| 651 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 652 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 653 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 654 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 655 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 656 | struct lpfc_rqe *temp_hrqe; |
| 657 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 658 | struct lpfc_register doorbell; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 659 | int hq_put_index; |
| 660 | int dq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 661 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 662 | /* sanity check on queue memory */ |
| 663 | if (unlikely(!hq) || unlikely(!dq)) |
| 664 | return -ENOMEM; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 665 | hq_put_index = hq->host_index; |
| 666 | dq_put_index = dq->host_index; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 667 | temp_hrqe = lpfc_sli4_qe(hq, hq_put_index); |
| 668 | temp_drqe = lpfc_sli4_qe(dq, dq_put_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 669 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 670 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 671 | return -EINVAL; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 672 | if (hq_put_index != dq_put_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 673 | return -EINVAL; |
| 674 | /* 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] | 675 | if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 676 | return -EBUSY; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 677 | lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 678 | lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 679 | |
| 680 | /* Update the host index to point to the next slot */ |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 681 | hq->host_index = ((hq_put_index + 1) % hq->entry_count); |
| 682 | dq->host_index = ((dq_put_index + 1) % dq->entry_count); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 683 | hq->RQ_buf_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 684 | |
| 685 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 686 | if (!(hq->host_index % hq->notify_interval)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 687 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 688 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 689 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 690 | hq->notify_interval); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 691 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 692 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 693 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 694 | hq->notify_interval); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 695 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 696 | hq->host_index); |
| 697 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 698 | } else { |
| 699 | return -EINVAL; |
| 700 | } |
| 701 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 702 | } |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 703 | return hq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | /** |
| 707 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 708 | * @q: The Header Receive Queue to operate on. |
| 709 | * |
| 710 | * This routine will update the HBA index of a queue to reflect consumption of |
| 711 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 712 | * consumed an entry the host calls this function to update the queue's |
| 713 | * internal pointers. This routine returns the number of entries that were |
| 714 | * consumed by the HBA. |
| 715 | **/ |
| 716 | static uint32_t |
| 717 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 718 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 719 | /* sanity check on queue memory */ |
| 720 | if (unlikely(!hq) || unlikely(!dq)) |
| 721 | return 0; |
| 722 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 723 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 724 | return 0; |
| 725 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 726 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 727 | return 1; |
| 728 | } |
| 729 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 730 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 731 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 732 | * @phba: Pointer to HBA context object. |
| 733 | * @pring: Pointer to driver SLI ring object. |
| 734 | * |
| 735 | * This function returns pointer to next command iocb entry |
| 736 | * in the command ring. The caller must hold hbalock to prevent |
| 737 | * other threads consume the next command iocb. |
| 738 | * SLI-2/SLI-3 provide different sized iocbs. |
| 739 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 740 | static inline IOCB_t * |
| 741 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 742 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 743 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 744 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 745 | } |
| 746 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 747 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 748 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 749 | * @phba: Pointer to HBA context object. |
| 750 | * @pring: Pointer to driver SLI ring object. |
| 751 | * |
| 752 | * This function returns pointer to next response iocb entry |
| 753 | * in the response ring. The caller must hold hbalock to make sure |
| 754 | * that no other thread consume the next response iocb. |
| 755 | * SLI-2/SLI-3 provide different sized iocbs. |
| 756 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 757 | static inline IOCB_t * |
| 758 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 759 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 760 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 761 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 762 | } |
| 763 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 764 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 765 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 766 | * @phba: Pointer to HBA context object. |
| 767 | * |
| 768 | * This function is called with hbalock held. This function |
| 769 | * allocates a new driver iocb object from the iocb pool. If the |
| 770 | * allocation is successful, it returns pointer to the newly |
| 771 | * allocated iocb object else it returns NULL. |
| 772 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 773 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 774 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 775 | { |
| 776 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 777 | struct lpfc_iocbq * iocbq = NULL; |
| 778 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 779 | lockdep_assert_held(&phba->hbalock); |
| 780 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 781 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 782 | if (iocbq) |
| 783 | phba->iocb_cnt++; |
| 784 | if (phba->iocb_cnt > phba->iocb_max) |
| 785 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 786 | return iocbq; |
| 787 | } |
| 788 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 789 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 790 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 791 | * @phba: Pointer to HBA context object. |
| 792 | * @xritag: XRI value. |
| 793 | * |
| 794 | * This function clears the sglq pointer from the array of acive |
| 795 | * sglq's. The xritag that is passed in is used to index into the |
| 796 | * array. Before the xritag can be used it needs to be adjusted |
| 797 | * by subtracting the xribase. |
| 798 | * |
| 799 | * Returns sglq ponter = success, NULL = Failure. |
| 800 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 801 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 802 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 803 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 804 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 805 | |
| 806 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 807 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 808 | return sglq; |
| 809 | } |
| 810 | |
| 811 | /** |
| 812 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 813 | * @phba: Pointer to HBA context object. |
| 814 | * @xritag: XRI value. |
| 815 | * |
| 816 | * This function returns the sglq pointer from the array of acive |
| 817 | * sglq's. The xritag that is passed in is used to index into the |
| 818 | * array. Before the xritag can be used it needs to be adjusted |
| 819 | * by subtracting the xribase. |
| 820 | * |
| 821 | * Returns sglq ponter = success, NULL = Failure. |
| 822 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 823 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 824 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 825 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 826 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 827 | |
| 828 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 829 | return sglq; |
| 830 | } |
| 831 | |
| 832 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 833 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 834 | * @phba: Pointer to HBA context object. |
| 835 | * @xritag: xri used in this exchange. |
| 836 | * @rrq: The RRQ to be cleared. |
| 837 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 838 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 839 | void |
| 840 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 841 | uint16_t xritag, |
| 842 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 843 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 844 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 845 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 846 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 847 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 848 | |
| 849 | /* The target DID could have been swapped (cable swap) |
| 850 | * we should use the ndlp from the findnode if it is |
| 851 | * available. |
| 852 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 853 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 854 | ndlp = rrq->ndlp; |
| 855 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 856 | if (!ndlp) |
| 857 | goto out; |
| 858 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 859 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 860 | rrq->send_rrq = 0; |
| 861 | rrq->xritag = 0; |
| 862 | rrq->rrq_stop_time = 0; |
| 863 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 864 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 865 | mempool_free(rrq, phba->rrq_pool); |
| 866 | } |
| 867 | |
| 868 | /** |
| 869 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 870 | * @phba: Pointer to HBA context object. |
| 871 | * |
| 872 | * This function is called with hbalock held. This function |
| 873 | * Checks if stop_time (ratov from setting rrq active) has |
| 874 | * been reached, if it has and the send_rrq flag is set then |
| 875 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 876 | * then it will just call the routine to clear the rrq and |
| 877 | * free the rrq resource. |
| 878 | * The timer is set to the next rrq that is going to expire before |
| 879 | * leaving the routine. |
| 880 | * |
| 881 | **/ |
| 882 | void |
| 883 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 884 | { |
| 885 | struct lpfc_node_rrq *rrq; |
| 886 | struct lpfc_node_rrq *nextrrq; |
| 887 | unsigned long next_time; |
| 888 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 889 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 890 | |
| 891 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 892 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 893 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 894 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 895 | &phba->active_rrq_list, list) { |
| 896 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 897 | list_move(&rrq->list, &send_rrq); |
| 898 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 899 | next_time = rrq->rrq_stop_time; |
| 900 | } |
| 901 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 902 | if ((!list_empty(&phba->active_rrq_list)) && |
| 903 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 904 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 905 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 906 | list_del(&rrq->list); |
Bart Van Assche | ffd4381 | 2019-03-28 11:06:17 -0700 | [diff] [blame] | 907 | if (!rrq->send_rrq) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 908 | /* this call will free the rrq */ |
Bart Van Assche | ffd4381 | 2019-03-28 11:06:17 -0700 | [diff] [blame] | 909 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 910 | } else if (lpfc_send_rrq(phba, rrq)) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 911 | /* if we send the rrq then the completion handler |
| 912 | * will clear the bit in the xribitmap. |
| 913 | */ |
| 914 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 915 | rrq); |
| 916 | } |
| 917 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | /** |
| 921 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 922 | * @vport: Pointer to vport context object. |
| 923 | * @xri: The xri used in the exchange. |
| 924 | * @did: The targets DID for this exchange. |
| 925 | * |
| 926 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 927 | * rrq = rrq for this xri and target. |
| 928 | **/ |
| 929 | struct lpfc_node_rrq * |
| 930 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 931 | { |
| 932 | struct lpfc_hba *phba = vport->phba; |
| 933 | struct lpfc_node_rrq *rrq; |
| 934 | struct lpfc_node_rrq *nextrrq; |
| 935 | unsigned long iflags; |
| 936 | |
| 937 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 938 | return NULL; |
| 939 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 940 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 941 | if (rrq->vport == vport && rrq->xritag == xri && |
| 942 | rrq->nlp_DID == did){ |
| 943 | list_del(&rrq->list); |
| 944 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 945 | return rrq; |
| 946 | } |
| 947 | } |
| 948 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 949 | return NULL; |
| 950 | } |
| 951 | |
| 952 | /** |
| 953 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 954 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 955 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 956 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 957 | * phba->active_rrq_list and clear the rrq. |
| 958 | * 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] | 959 | **/ |
| 960 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 961 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 962 | |
| 963 | { |
| 964 | struct lpfc_hba *phba = vport->phba; |
| 965 | struct lpfc_node_rrq *rrq; |
| 966 | struct lpfc_node_rrq *nextrrq; |
| 967 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 968 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 969 | |
| 970 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 971 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 972 | if (!ndlp) { |
| 973 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 974 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 975 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 976 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 977 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 978 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 979 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 980 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 981 | |
| 982 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 983 | list_del(&rrq->list); |
| 984 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 985 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 989 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 990 | * @phba: Pointer to HBA context object. |
| 991 | * @ndlp: Targets nodelist pointer for this exchange. |
| 992 | * @xritag the xri in the bitmap to test. |
| 993 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 994 | * This function returns: |
| 995 | * 0 = rrq not active for this xri |
| 996 | * 1 = rrq is valid for this xri. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 997 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 998 | int |
| 999 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1000 | uint16_t xritag) |
| 1001 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1002 | if (!ndlp) |
| 1003 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1004 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1005 | return 0; |
| 1006 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
Colin Ian King | 258f84f | 2019-02-12 15:29:45 +0000 | [diff] [blame] | 1007 | return 1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1008 | else |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
| 1012 | /** |
| 1013 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 1014 | * @phba: Pointer to HBA context object. |
| 1015 | * @ndlp: nodelist pointer for this target. |
| 1016 | * @xritag: xri used in this exchange. |
| 1017 | * @rxid: Remote Exchange ID. |
| 1018 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 1019 | * |
| 1020 | * This function takes the hbalock. |
| 1021 | * The active bit is always set in the active rrq xri_bitmap even |
| 1022 | * if there is no slot avaiable for the other rrq information. |
| 1023 | * |
| 1024 | * returns 0 rrq actived for this xri |
| 1025 | * < 0 No memory or invalid ndlp. |
| 1026 | **/ |
| 1027 | int |
| 1028 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1029 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1030 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1031 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1032 | struct lpfc_node_rrq *rrq; |
| 1033 | int empty; |
| 1034 | |
| 1035 | if (!ndlp) |
| 1036 | return -EINVAL; |
| 1037 | |
| 1038 | if (!phba->cfg_enable_rrq) |
| 1039 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1040 | |
| 1041 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1042 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1043 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 1044 | goto out; |
| 1045 | } |
| 1046 | |
| 1047 | /* |
| 1048 | * set the active bit even if there is no mem available. |
| 1049 | */ |
| 1050 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 1051 | goto out; |
| 1052 | |
| 1053 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 1054 | goto out; |
| 1055 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1056 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1057 | goto out; |
| 1058 | |
| 1059 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1060 | goto out; |
| 1061 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1062 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1063 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 1064 | if (!rrq) { |
| 1065 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1066 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 1067 | " DID:0x%x Send:%d\n", |
| 1068 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1069 | return -EINVAL; |
| 1070 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 1071 | if (phba->cfg_enable_rrq == 1) |
| 1072 | rrq->send_rrq = send_rrq; |
| 1073 | else |
| 1074 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1075 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1076 | rrq->rrq_stop_time = jiffies + |
| 1077 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1078 | rrq->ndlp = ndlp; |
| 1079 | rrq->nlp_DID = ndlp->nlp_DID; |
| 1080 | rrq->vport = ndlp->vport; |
| 1081 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1082 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1083 | empty = list_empty(&phba->active_rrq_list); |
| 1084 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 1085 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1086 | if (empty) |
| 1087 | lpfc_worker_wake_up(phba); |
| 1088 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1089 | return 0; |
| 1090 | out: |
| 1091 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1092 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1093 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 1094 | " DID:0x%x Send:%d\n", |
| 1095 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1096 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1100 | * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1101 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1102 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1103 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1104 | * The driver calls this function with either the nvme ls ring lock |
| 1105 | * or the fc els ring lock held depending on the iocb usage. This function |
| 1106 | * gets a new driver sglq object from the sglq list. If the list is not empty |
| 1107 | * then it is successful, it returns pointer to the newly allocated sglq |
| 1108 | * object else it returns NULL. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1109 | **/ |
| 1110 | static struct lpfc_sglq * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1111 | __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] | 1112 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1113 | 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] | 1114 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1115 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1116 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1117 | struct lpfc_nodelist *ndlp; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1118 | struct lpfc_sli_ring *pring = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1119 | int found = 0; |
| 1120 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1121 | if (piocbq->iocb_flag & LPFC_IO_NVME_LS) |
| 1122 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 1123 | else |
| 1124 | pring = lpfc_phba_elsring(phba); |
| 1125 | |
| 1126 | lockdep_assert_held(&pring->ring_lock); |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1127 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1128 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1129 | lpfc_cmd = (struct lpfc_io_buf *) piocbq->context1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1130 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 1131 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1132 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1133 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1134 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 1135 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 1136 | ndlp = NULL; |
| 1137 | else |
| 1138 | ndlp = piocbq->context_un.ndlp; |
| 1139 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1140 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1141 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1142 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1143 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 1144 | list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1145 | start_sglq = sglq; |
| 1146 | while (!found) { |
| 1147 | if (!sglq) |
James Smart | d11f54b | 2017-03-04 09:30:24 -0800 | [diff] [blame] | 1148 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1149 | if (ndlp && ndlp->active_rrqs_xri_bitmap && |
| 1150 | test_bit(sglq->sli4_lxritag, |
| 1151 | ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1152 | /* This xri has an rrq outstanding for this DID. |
| 1153 | * put it back in the list and get another xri. |
| 1154 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1155 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1156 | sglq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1157 | list_remove_head(lpfc_els_sgl_list, sglq, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1158 | struct lpfc_sglq, list); |
| 1159 | if (sglq == start_sglq) { |
James Smart | 14041bd | 2017-06-01 21:07:01 -0700 | [diff] [blame] | 1160 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1161 | sglq = NULL; |
| 1162 | break; |
| 1163 | } else |
| 1164 | continue; |
| 1165 | } |
| 1166 | sglq->ndlp = ndlp; |
| 1167 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1168 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1169 | sglq->state = SGL_ALLOCATED; |
| 1170 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1171 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1172 | return sglq; |
| 1173 | } |
| 1174 | |
| 1175 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1176 | * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool |
| 1177 | * @phba: Pointer to HBA context object. |
| 1178 | * @piocb: Pointer to the iocbq. |
| 1179 | * |
| 1180 | * This function is called with the sgl_list lock held. This function |
| 1181 | * gets a new driver sglq object from the sglq list. If the |
| 1182 | * list is not empty then it is successful, it returns pointer to the newly |
| 1183 | * allocated sglq object else it returns NULL. |
| 1184 | **/ |
| 1185 | struct lpfc_sglq * |
| 1186 | __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
| 1187 | { |
| 1188 | struct list_head *lpfc_nvmet_sgl_list; |
| 1189 | struct lpfc_sglq *sglq = NULL; |
| 1190 | |
| 1191 | lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list; |
| 1192 | |
| 1193 | lockdep_assert_held(&phba->sli4_hba.sgl_list_lock); |
| 1194 | |
| 1195 | list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list); |
| 1196 | if (!sglq) |
| 1197 | return NULL; |
| 1198 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
| 1199 | sglq->state = SGL_ALLOCATED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1200 | return sglq; |
| 1201 | } |
| 1202 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1203 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1204 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1205 | * @phba: Pointer to HBA context object. |
| 1206 | * |
| 1207 | * This function is called with no lock held. This function |
| 1208 | * allocates a new driver iocb object from the iocb pool. If the |
| 1209 | * allocation is successful, it returns pointer to the newly |
| 1210 | * allocated iocb object else it returns NULL. |
| 1211 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1212 | struct lpfc_iocbq * |
| 1213 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1214 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1215 | struct lpfc_iocbq * iocbq = NULL; |
| 1216 | unsigned long iflags; |
| 1217 | |
| 1218 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1219 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 1220 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1221 | return iocbq; |
| 1222 | } |
| 1223 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1224 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1225 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 1226 | * @phba: Pointer to HBA context object. |
| 1227 | * @iocbq: Pointer to driver iocb object. |
| 1228 | * |
| 1229 | * This function is called with hbalock held to release driver |
| 1230 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1231 | * does not change for each use of the iocb object. This function |
| 1232 | * clears all other fields of the iocb object when it is freed. |
| 1233 | * The sqlq structure that holds the xritag and phys and virtual |
| 1234 | * mappings for the scatter gather list is retrieved from the |
| 1235 | * active array of sglq. The get of the sglq pointer also clears |
| 1236 | * the entry in the array. If the status of the IO indiactes that |
| 1237 | * this IO was aborted then the sglq entry it put on the |
| 1238 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1239 | * 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] | 1240 | * entry is added to the free list (lpfc_els_sgl_list). |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1241 | **/ |
| 1242 | static void |
| 1243 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1244 | { |
| 1245 | struct lpfc_sglq *sglq; |
| 1246 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1247 | unsigned long iflag = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1248 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1249 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1250 | lockdep_assert_held(&phba->hbalock); |
| 1251 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1252 | if (iocbq->sli4_xritag == NO_XRI) |
| 1253 | sglq = NULL; |
| 1254 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1255 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1256 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1257 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1258 | if (sglq) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1259 | if (iocbq->iocb_flag & LPFC_IO_NVMET) { |
| 1260 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1261 | iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1262 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1263 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1264 | list_add_tail(&sglq->list, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1265 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 1266 | spin_unlock_irqrestore( |
| 1267 | &phba->sli4_hba.sgl_list_lock, iflag); |
| 1268 | goto out; |
| 1269 | } |
| 1270 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1271 | pring = phba->sli4_hba.els_wq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1272 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1273 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1274 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1275 | iflag); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1276 | list_add(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1277 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1278 | spin_unlock_irqrestore( |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1279 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1280 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1281 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1282 | iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1283 | sglq->state = SGL_FREED; |
| 1284 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1285 | list_add_tail(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1286 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1287 | spin_unlock_irqrestore( |
| 1288 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1289 | |
| 1290 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1291 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1292 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1293 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1294 | } |
| 1295 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1296 | out: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1297 | /* |
| 1298 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1299 | */ |
| 1300 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1301 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1302 | iocbq->sli4_xritag = NO_XRI; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1303 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | |
| 1304 | LPFC_IO_NVME_LS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1305 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1306 | } |
| 1307 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1308 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1309 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1310 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1311 | * @phba: Pointer to HBA context object. |
| 1312 | * @iocbq: Pointer to driver iocb object. |
| 1313 | * |
| 1314 | * This function is called with hbalock held to release driver |
| 1315 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1316 | * does not change for each use of the iocb object. This function |
| 1317 | * clears all other fields of the iocb object when it is freed. |
| 1318 | **/ |
| 1319 | static void |
| 1320 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1321 | { |
| 1322 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1323 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1324 | lockdep_assert_held(&phba->hbalock); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1325 | |
| 1326 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1327 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1328 | */ |
| 1329 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1330 | iocbq->sli4_xritag = NO_XRI; |
| 1331 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1332 | } |
| 1333 | |
| 1334 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1335 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1336 | * @phba: Pointer to HBA context object. |
| 1337 | * @iocbq: Pointer to driver iocb object. |
| 1338 | * |
| 1339 | * This function is called with hbalock held to release driver |
| 1340 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1341 | * does not change for each use of the iocb object. This function |
| 1342 | * clears all other fields of the iocb object when it is freed. |
| 1343 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1344 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1345 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1346 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1347 | lockdep_assert_held(&phba->hbalock); |
| 1348 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1349 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1350 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1351 | } |
| 1352 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1353 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1354 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1355 | * @phba: Pointer to HBA context object. |
| 1356 | * @iocbq: Pointer to driver iocb object. |
| 1357 | * |
| 1358 | * This function is called with no lock held to release the iocb to |
| 1359 | * iocb pool. |
| 1360 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1361 | void |
| 1362 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1363 | { |
| 1364 | unsigned long iflags; |
| 1365 | |
| 1366 | /* |
| 1367 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1368 | */ |
| 1369 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1370 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1371 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1372 | } |
| 1373 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1374 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1375 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1376 | * @phba: Pointer to HBA context object. |
| 1377 | * @iocblist: List of IOCBs. |
| 1378 | * @ulpstatus: ULP status in IOCB command field. |
| 1379 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1380 | * |
| 1381 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1382 | * on the list by invoking the complete callback function associated with the |
| 1383 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1384 | * fields. |
| 1385 | **/ |
| 1386 | void |
| 1387 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1388 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1389 | { |
| 1390 | struct lpfc_iocbq *piocb; |
| 1391 | |
| 1392 | while (!list_empty(iocblist)) { |
| 1393 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | 84f2ddf | 2019-08-14 16:56:55 -0700 | [diff] [blame] | 1394 | if (!piocb->iocb_cmpl) { |
| 1395 | if (piocb->iocb_flag & LPFC_IO_NVME) |
| 1396 | lpfc_nvme_cancel_iocb(phba, piocb); |
| 1397 | else |
| 1398 | lpfc_sli_release_iocbq(phba, piocb); |
| 1399 | } else { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1400 | piocb->iocb.ulpStatus = ulpstatus; |
| 1401 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1402 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1403 | } |
| 1404 | } |
| 1405 | return; |
| 1406 | } |
| 1407 | |
| 1408 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1409 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1410 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1411 | * |
| 1412 | * This function is called by ring event handler function to get the iocb type. |
| 1413 | * This function translates the iocb command to an iocb command type used to |
| 1414 | * decide the final disposition of each completed IOCB. |
| 1415 | * The function returns |
| 1416 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1417 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1418 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1419 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1420 | * |
| 1421 | * The caller is not required to hold any lock. |
| 1422 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1423 | static lpfc_iocb_type |
| 1424 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1425 | { |
| 1426 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1427 | |
| 1428 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1429 | return 0; |
| 1430 | |
| 1431 | switch (iocb_cmnd) { |
| 1432 | case CMD_XMIT_SEQUENCE_CR: |
| 1433 | case CMD_XMIT_SEQUENCE_CX: |
| 1434 | case CMD_XMIT_BCAST_CN: |
| 1435 | case CMD_XMIT_BCAST_CX: |
| 1436 | case CMD_ELS_REQUEST_CR: |
| 1437 | case CMD_ELS_REQUEST_CX: |
| 1438 | case CMD_CREATE_XRI_CR: |
| 1439 | case CMD_CREATE_XRI_CX: |
| 1440 | case CMD_GET_RPI_CN: |
| 1441 | case CMD_XMIT_ELS_RSP_CX: |
| 1442 | case CMD_GET_RPI_CR: |
| 1443 | case CMD_FCP_IWRITE_CR: |
| 1444 | case CMD_FCP_IWRITE_CX: |
| 1445 | case CMD_FCP_IREAD_CR: |
| 1446 | case CMD_FCP_IREAD_CX: |
| 1447 | case CMD_FCP_ICMND_CR: |
| 1448 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1449 | case CMD_FCP_TSEND_CX: |
| 1450 | case CMD_FCP_TRSP_CX: |
| 1451 | case CMD_FCP_TRECEIVE_CX: |
| 1452 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1453 | case CMD_ADAPTER_MSG: |
| 1454 | case CMD_ADAPTER_DUMP: |
| 1455 | case CMD_XMIT_SEQUENCE64_CR: |
| 1456 | case CMD_XMIT_SEQUENCE64_CX: |
| 1457 | case CMD_XMIT_BCAST64_CN: |
| 1458 | case CMD_XMIT_BCAST64_CX: |
| 1459 | case CMD_ELS_REQUEST64_CR: |
| 1460 | case CMD_ELS_REQUEST64_CX: |
| 1461 | case CMD_FCP_IWRITE64_CR: |
| 1462 | case CMD_FCP_IWRITE64_CX: |
| 1463 | case CMD_FCP_IREAD64_CR: |
| 1464 | case CMD_FCP_IREAD64_CX: |
| 1465 | case CMD_FCP_ICMND64_CR: |
| 1466 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1467 | case CMD_FCP_TSEND64_CX: |
| 1468 | case CMD_FCP_TRSP64_CX: |
| 1469 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1470 | case CMD_GEN_REQUEST64_CR: |
| 1471 | case CMD_GEN_REQUEST64_CX: |
| 1472 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1473 | case DSSCMD_IWRITE64_CR: |
| 1474 | case DSSCMD_IWRITE64_CX: |
| 1475 | case DSSCMD_IREAD64_CR: |
| 1476 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1477 | type = LPFC_SOL_IOCB; |
| 1478 | break; |
| 1479 | case CMD_ABORT_XRI_CN: |
| 1480 | case CMD_ABORT_XRI_CX: |
| 1481 | case CMD_CLOSE_XRI_CN: |
| 1482 | case CMD_CLOSE_XRI_CX: |
| 1483 | case CMD_XRI_ABORTED_CX: |
| 1484 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1485 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1486 | type = LPFC_ABORT_IOCB; |
| 1487 | break; |
| 1488 | case CMD_RCV_SEQUENCE_CX: |
| 1489 | case CMD_RCV_ELS_REQ_CX: |
| 1490 | case CMD_RCV_SEQUENCE64_CX: |
| 1491 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1492 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1493 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1494 | case CMD_IOCB_RCV_ELS64_CX: |
| 1495 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1496 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | type = LPFC_UNSOL_IOCB; |
| 1498 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1499 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1500 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1501 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1502 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1503 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1504 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1505 | case CMD_IOCB_RET_HBQE64_CN: |
| 1506 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1507 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1508 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1509 | case CMD_IOCB_LOGENTRY_CN: |
| 1510 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1511 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1512 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1513 | type = LPFC_UNKNOWN_IOCB; |
| 1514 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1515 | default: |
| 1516 | type = LPFC_UNKNOWN_IOCB; |
| 1517 | break; |
| 1518 | } |
| 1519 | |
| 1520 | return type; |
| 1521 | } |
| 1522 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1523 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1524 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1525 | * @phba: Pointer to HBA context object. |
| 1526 | * |
| 1527 | * This function is called from SLI initialization code |
| 1528 | * to configure every ring of the HBA's SLI interface. The |
| 1529 | * caller is not required to hold any lock. This function issues |
| 1530 | * a config_ring mailbox command for each ring. |
| 1531 | * This function returns zero if successful else returns a negative |
| 1532 | * error code. |
| 1533 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1534 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1535 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1536 | { |
| 1537 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1538 | LPFC_MBOXQ_t *pmb; |
| 1539 | MAILBOX_t *pmbox; |
| 1540 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1541 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1542 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1543 | if (!pmb) |
| 1544 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1545 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1546 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1547 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1548 | lpfc_config_ring(phba, i, pmb); |
| 1549 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1550 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1551 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1552 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1553 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1554 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1555 | rc, pmbox->mbxCommand, |
| 1556 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1557 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1558 | ret = -ENXIO; |
| 1559 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1560 | } |
| 1561 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1562 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1563 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1564 | } |
| 1565 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1566 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1567 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1568 | * @phba: Pointer to HBA context object. |
| 1569 | * @pring: Pointer to driver SLI ring object. |
| 1570 | * @piocb: Pointer to the driver iocb object. |
| 1571 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1572 | * The driver calls this function with the hbalock held for SLI3 ports or |
| 1573 | * the ring lock held for SLI4 ports. The function adds the |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1574 | * new iocb to txcmplq of the given ring. This function always returns |
| 1575 | * 0. If this function is called for ELS ring, this function checks if |
| 1576 | * there is a vport associated with the ELS command. This function also |
| 1577 | * starts els_tmofunc timer if this is an ELS command. |
| 1578 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1579 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1580 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1581 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1582 | { |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1583 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1584 | lockdep_assert_held(&pring->ring_lock); |
| 1585 | else |
| 1586 | lockdep_assert_held(&phba->hbalock); |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1587 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1588 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1589 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1590 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1591 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1592 | pring->txcmplq_cnt++; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1593 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1594 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1595 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1596 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1597 | BUG_ON(!piocb->vport); |
| 1598 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1599 | mod_timer(&piocb->vport->els_tmofunc, |
| 1600 | jiffies + |
| 1601 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 1602 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1603 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1604 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1605 | } |
| 1606 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1607 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1608 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1609 | * @phba: Pointer to HBA context object. |
| 1610 | * @pring: Pointer to driver SLI ring object. |
| 1611 | * |
| 1612 | * This function is called with hbalock held to get next |
| 1613 | * iocb in txq of the given ring. If there is any iocb in |
| 1614 | * the txq, the function returns first iocb in the list after |
| 1615 | * removing the iocb from the list, else it returns NULL. |
| 1616 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1617 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1618 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1619 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1620 | struct lpfc_iocbq *cmd_iocb; |
| 1621 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1622 | lockdep_assert_held(&phba->hbalock); |
| 1623 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1624 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1625 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1626 | } |
| 1627 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1628 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1629 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1630 | * @phba: Pointer to HBA context object. |
| 1631 | * @pring: Pointer to driver SLI ring object. |
| 1632 | * |
| 1633 | * This function is called with hbalock held and the caller must post the |
| 1634 | * iocb without releasing the lock. If the caller releases the lock, |
| 1635 | * iocb slot returned by the function is not guaranteed to be available. |
| 1636 | * The function returns pointer to the next available iocb slot if there |
| 1637 | * is available slot in the ring, else it returns NULL. |
| 1638 | * If the get index of the ring is ahead of the put index, the function |
| 1639 | * will post an error attention event to the worker thread to take the |
| 1640 | * HBA to offline state. |
| 1641 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1642 | static IOCB_t * |
| 1643 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1644 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1645 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1646 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1647 | |
| 1648 | lockdep_assert_held(&phba->hbalock); |
| 1649 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1650 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1651 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1652 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1653 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1654 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1655 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1656 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1657 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1658 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1659 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1660 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1661 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1662 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1663 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1664 | pring->sli.sli3.local_getidx, |
| 1665 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1666 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1667 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1668 | /* |
| 1669 | * All error attention handlers are posted to |
| 1670 | * worker thread |
| 1671 | */ |
| 1672 | phba->work_ha |= HA_ERATT; |
| 1673 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1674 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1675 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1676 | |
| 1677 | return NULL; |
| 1678 | } |
| 1679 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1680 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1681 | return NULL; |
| 1682 | } |
| 1683 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1684 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1685 | } |
| 1686 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1687 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1688 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1689 | * @phba: Pointer to HBA context object. |
| 1690 | * @iocbq: Pointer to driver iocb object. |
| 1691 | * |
| 1692 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1693 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1694 | * array and assigns a new iotag. |
| 1695 | * The function returns the allocated iotag if successful, else returns zero. |
| 1696 | * Zero is not a valid iotag. |
| 1697 | * The caller is not required to hold any lock. |
| 1698 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1699 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1700 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1701 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1702 | struct lpfc_iocbq **new_arr; |
| 1703 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1704 | size_t new_len; |
| 1705 | struct lpfc_sli *psli = &phba->sli; |
| 1706 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1707 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1708 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1709 | iotag = psli->last_iotag; |
| 1710 | if(++iotag < psli->iocbq_lookup_len) { |
| 1711 | psli->last_iotag = iotag; |
| 1712 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1713 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1714 | iocbq->iotag = iotag; |
| 1715 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1716 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1717 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1718 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1719 | spin_unlock_irq(&phba->hbalock); |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1720 | new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1721 | GFP_KERNEL); |
| 1722 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1723 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1724 | old_arr = psli->iocbq_lookup; |
| 1725 | if (new_len <= psli->iocbq_lookup_len) { |
| 1726 | /* highly unprobable case */ |
| 1727 | kfree(new_arr); |
| 1728 | iotag = psli->last_iotag; |
| 1729 | if(++iotag < psli->iocbq_lookup_len) { |
| 1730 | psli->last_iotag = iotag; |
| 1731 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1732 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1733 | iocbq->iotag = iotag; |
| 1734 | return iotag; |
| 1735 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1736 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1737 | return 0; |
| 1738 | } |
| 1739 | if (psli->iocbq_lookup) |
| 1740 | memcpy(new_arr, old_arr, |
| 1741 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1742 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1743 | psli->iocbq_lookup = new_arr; |
| 1744 | psli->iocbq_lookup_len = new_len; |
| 1745 | psli->last_iotag = iotag; |
| 1746 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1747 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1748 | iocbq->iotag = iotag; |
| 1749 | kfree(old_arr); |
| 1750 | return iotag; |
| 1751 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1752 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1753 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1754 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1755 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1756 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1757 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1758 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1759 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1760 | } |
| 1761 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1762 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1763 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1764 | * @phba: Pointer to HBA context object. |
| 1765 | * @pring: Pointer to driver SLI ring object. |
| 1766 | * @iocb: Pointer to iocb slot in the ring. |
| 1767 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1768 | * posted to firmware. |
| 1769 | * |
| 1770 | * This function is called with hbalock held to post a new iocb to |
| 1771 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1772 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1773 | * a completion call back for this iocb else the function will free the |
| 1774 | * iocb object. |
| 1775 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1776 | static void |
| 1777 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1778 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1779 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1780 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1781 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1782 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1783 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1784 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1785 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1786 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1787 | if (pring->ringno == LPFC_ELS_RING) { |
| 1788 | lpfc_debugfs_slow_ring_trc(phba, |
| 1789 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1790 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1791 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1792 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1793 | } |
| 1794 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1795 | /* |
| 1796 | * Issue iocb command to adapter |
| 1797 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1798 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1799 | wmb(); |
| 1800 | pring->stats.iocb_cmd++; |
| 1801 | |
| 1802 | /* |
| 1803 | * If there is no completion routine to call, we can release the |
| 1804 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1805 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1806 | */ |
| 1807 | if (nextiocb->iocb_cmpl) |
| 1808 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1809 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1810 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1811 | |
| 1812 | /* |
| 1813 | * Let the HBA know what IOCB slot will be the next one the |
| 1814 | * driver will put a command into. |
| 1815 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1816 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1817 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1818 | } |
| 1819 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1820 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1821 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1822 | * @phba: Pointer to HBA context object. |
| 1823 | * @pring: Pointer to driver SLI ring object. |
| 1824 | * |
| 1825 | * The caller is not required to hold any lock for calling this function. |
| 1826 | * This function updates the chip attention bits for the ring to inform firmware |
| 1827 | * that there are pending work to be done for this ring and requests an |
| 1828 | * interrupt when there is space available in the ring. This function is |
| 1829 | * called when the driver is unable to post more iocbs to the ring due |
| 1830 | * to unavailability of space in the ring. |
| 1831 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1832 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1833 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1834 | { |
| 1835 | int ringno = pring->ringno; |
| 1836 | |
| 1837 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1838 | |
| 1839 | wmb(); |
| 1840 | |
| 1841 | /* |
| 1842 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1843 | * The HBA will tell us when an IOCB entry is available. |
| 1844 | */ |
| 1845 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1846 | readl(phba->CAregaddr); /* flush */ |
| 1847 | |
| 1848 | pring->stats.iocb_cmd_full++; |
| 1849 | } |
| 1850 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1851 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1852 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1853 | * @phba: Pointer to HBA context object. |
| 1854 | * @pring: Pointer to driver SLI ring object. |
| 1855 | * |
| 1856 | * This function updates the chip attention register bit for the |
| 1857 | * given ring to inform HBA that there is more work to be done |
| 1858 | * in this ring. The caller is not required to hold any lock. |
| 1859 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1860 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1861 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1862 | { |
| 1863 | int ringno = pring->ringno; |
| 1864 | |
| 1865 | /* |
| 1866 | * Tell the HBA that there is work to do in this ring. |
| 1867 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1868 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1869 | wmb(); |
| 1870 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1871 | readl(phba->CAregaddr); /* flush */ |
| 1872 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1873 | } |
| 1874 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1875 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1876 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1877 | * @phba: Pointer to HBA context object. |
| 1878 | * @pring: Pointer to driver SLI ring object. |
| 1879 | * |
| 1880 | * This function is called with hbalock held to post pending iocbs |
| 1881 | * in the txq to the firmware. This function is called when driver |
| 1882 | * detects space available in the ring. |
| 1883 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1884 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1885 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1886 | { |
| 1887 | IOCB_t *iocb; |
| 1888 | struct lpfc_iocbq *nextiocb; |
| 1889 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1890 | lockdep_assert_held(&phba->hbalock); |
| 1891 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1892 | /* |
| 1893 | * Check to see if: |
| 1894 | * (a) there is anything on the txq to send |
| 1895 | * (b) link is up |
| 1896 | * (c) link attention events can be processed (fcp ring only) |
| 1897 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1898 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1899 | |
| 1900 | if (lpfc_is_link_up(phba) && |
| 1901 | (!list_empty(&pring->txq)) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1902 | (pring->ringno != LPFC_FCP_RING || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1903 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1904 | |
| 1905 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1906 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1907 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1908 | |
| 1909 | if (iocb) |
| 1910 | lpfc_sli_update_ring(phba, pring); |
| 1911 | else |
| 1912 | lpfc_sli_update_full_ring(phba, pring); |
| 1913 | } |
| 1914 | |
| 1915 | return; |
| 1916 | } |
| 1917 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1918 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1919 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1920 | * @phba: Pointer to HBA context object. |
| 1921 | * @hbqno: HBQ number. |
| 1922 | * |
| 1923 | * This function is called with hbalock held to get the next |
| 1924 | * available slot for the given HBQ. If there is free slot |
| 1925 | * available for the HBQ it will return pointer to the next available |
| 1926 | * HBQ entry else it will return NULL. |
| 1927 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1928 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1929 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1930 | { |
| 1931 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1932 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1933 | lockdep_assert_held(&phba->hbalock); |
| 1934 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1935 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1936 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1937 | hbqp->next_hbqPutIdx = 0; |
| 1938 | |
| 1939 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1940 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1941 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1942 | |
| 1943 | hbqp->local_hbqGetIdx = getidx; |
| 1944 | |
| 1945 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1946 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1947 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1948 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1949 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1950 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1951 | hbqp->entry_count); |
| 1952 | |
| 1953 | phba->link_state = LPFC_HBA_ERROR; |
| 1954 | return NULL; |
| 1955 | } |
| 1956 | |
| 1957 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1958 | return NULL; |
| 1959 | } |
| 1960 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1961 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1962 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1963 | } |
| 1964 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1965 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1966 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1967 | * @phba: Pointer to HBA context object. |
| 1968 | * |
| 1969 | * This function is called with no lock held to free all the |
| 1970 | * hbq buffers while uninitializing the SLI interface. It also |
| 1971 | * frees the HBQ buffers returned by the firmware but not yet |
| 1972 | * processed by the upper layers. |
| 1973 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1974 | void |
| 1975 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1976 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1977 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1978 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1979 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1980 | int i, hbq_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1981 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1982 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1983 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1984 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1985 | for (i = 0; i < hbq_count; ++i) { |
| 1986 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1987 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1988 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1989 | list_del(&hbq_buf->dbuf.list); |
| 1990 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1991 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1992 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1993 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1994 | |
| 1995 | /* Mark the HBQs not in use */ |
| 1996 | phba->hbq_in_use = 0; |
| 1997 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1998 | } |
| 1999 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2000 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2001 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2002 | * @phba: Pointer to HBA context object. |
| 2003 | * @hbqno: HBQ number. |
| 2004 | * @hbq_buf: Pointer to HBQ buffer. |
| 2005 | * |
| 2006 | * This function is called with the hbalock held to post a |
| 2007 | * hbq buffer to the firmware. If the function finds an empty |
| 2008 | * slot in the HBQ, it will post the buffer. The function will return |
| 2009 | * pointer to the hbq entry if it successfully post the buffer |
| 2010 | * else it will return NULL. |
| 2011 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2012 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2013 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2014 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2015 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2016 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2017 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 2018 | } |
| 2019 | |
| 2020 | /** |
| 2021 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 2022 | * @phba: Pointer to HBA context object. |
| 2023 | * @hbqno: HBQ number. |
| 2024 | * @hbq_buf: Pointer to HBQ buffer. |
| 2025 | * |
| 2026 | * This function is called with the hbalock held to post a hbq buffer to the |
| 2027 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 2028 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 2029 | * it successfully post the buffer else it will return an error. |
| 2030 | **/ |
| 2031 | static int |
| 2032 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 2033 | struct hbq_dmabuf *hbq_buf) |
| 2034 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2035 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2036 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2037 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2038 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2039 | /* Get next HBQ entry slot to use */ |
| 2040 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 2041 | if (hbqe) { |
| 2042 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 2043 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2044 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 2045 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2046 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2047 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2048 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 2049 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 2050 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2051 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 2052 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2053 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2054 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2055 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2056 | return 0; |
| 2057 | } else |
| 2058 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2059 | } |
| 2060 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2061 | /** |
| 2062 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 2063 | * @phba: Pointer to HBA context object. |
| 2064 | * @hbqno: HBQ number. |
| 2065 | * @hbq_buf: Pointer to HBQ buffer. |
| 2066 | * |
| 2067 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 2068 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 2069 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 2070 | **/ |
| 2071 | static int |
| 2072 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 2073 | struct hbq_dmabuf *hbq_buf) |
| 2074 | { |
| 2075 | int rc; |
| 2076 | struct lpfc_rqe hrqe; |
| 2077 | struct lpfc_rqe drqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2078 | struct lpfc_queue *hrq; |
| 2079 | struct lpfc_queue *drq; |
| 2080 | |
| 2081 | if (hbqno != LPFC_ELS_HBQ) |
| 2082 | return 1; |
| 2083 | hrq = phba->sli4_hba.hdr_rq; |
| 2084 | drq = phba->sli4_hba.dat_rq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2085 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2086 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2087 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 2088 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 2089 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 2090 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2091 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2092 | if (rc < 0) |
| 2093 | return rc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2094 | hbq_buf->tag = (rc | (hbqno << 16)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2095 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 2096 | return 0; |
| 2097 | } |
| 2098 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2099 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2100 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 2101 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2102 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2103 | .mask_count = 0, |
| 2104 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2105 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2106 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2107 | .init_count = 40, |
| 2108 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2109 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2110 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2111 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2112 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2113 | &lpfc_els_hbq, |
| 2114 | }; |
| 2115 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2116 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2117 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2118 | * @phba: Pointer to HBA context object. |
| 2119 | * @hbqno: HBQ number. |
| 2120 | * @count: Number of HBQ buffers to be posted. |
| 2121 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2122 | * This function is called with no lock held to post more hbq buffers to the |
| 2123 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 2124 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2125 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 2126 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2127 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 2128 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2129 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2130 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2131 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2132 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2133 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2134 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2135 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2136 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 2137 | lpfc_hbq_defs[hbqno]->entry_count) |
| 2138 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 2139 | phba->hbqs[hbqno].buffer_count; |
| 2140 | if (!count) |
| 2141 | return 0; |
| 2142 | /* Allocate HBQ entries */ |
| 2143 | for (i = 0; i < count; i++) { |
| 2144 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 2145 | if (!hbq_buffer) |
| 2146 | break; |
| 2147 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 2148 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2149 | /* Check whether HBQ is still in use */ |
| 2150 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2151 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2152 | goto err; |
| 2153 | while (!list_empty(&hbq_buf_list)) { |
| 2154 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2155 | dbuf.list); |
| 2156 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 2157 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2158 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2159 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2160 | posted++; |
| 2161 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2162 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2163 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2164 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2165 | return posted; |
| 2166 | err: |
| 2167 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 2168 | while (!list_empty(&hbq_buf_list)) { |
| 2169 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2170 | dbuf.list); |
| 2171 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 2172 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2173 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2174 | } |
| 2175 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2176 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2177 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2178 | * @phba: Pointer to HBA context object. |
| 2179 | * @qno: HBQ number. |
| 2180 | * |
| 2181 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2182 | * is called with no lock held. The function returns the number of HBQ entries |
| 2183 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2184 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2185 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2186 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2187 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2188 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2189 | return 0; |
| 2190 | else |
| 2191 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2192 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2193 | } |
| 2194 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2195 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2196 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2197 | * @phba: Pointer to HBA context object. |
| 2198 | * @qno: HBQ queue number. |
| 2199 | * |
| 2200 | * This function is called from SLI initialization code path with |
| 2201 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2202 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2203 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2204 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2205 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2206 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2207 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2208 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2209 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2210 | else |
| 2211 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2212 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2213 | } |
| 2214 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2215 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2216 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 2217 | * @phba: Pointer to HBA context object. |
| 2218 | * @hbqno: HBQ number. |
| 2219 | * |
| 2220 | * This function removes the first hbq buffer on an hbq list and returns a |
| 2221 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2222 | **/ |
| 2223 | static struct hbq_dmabuf * |
| 2224 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 2225 | { |
| 2226 | struct lpfc_dmabuf *d_buf; |
| 2227 | |
| 2228 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 2229 | if (!d_buf) |
| 2230 | return NULL; |
| 2231 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2232 | } |
| 2233 | |
| 2234 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2235 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list |
| 2236 | * @phba: Pointer to HBA context object. |
| 2237 | * @hbqno: HBQ number. |
| 2238 | * |
| 2239 | * This function removes the first RQ buffer on an RQ buffer list and returns a |
| 2240 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2241 | **/ |
| 2242 | static struct rqb_dmabuf * |
| 2243 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) |
| 2244 | { |
| 2245 | struct lpfc_dmabuf *h_buf; |
| 2246 | struct lpfc_rqb *rqbp; |
| 2247 | |
| 2248 | rqbp = hrq->rqbp; |
| 2249 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 2250 | struct lpfc_dmabuf, list); |
| 2251 | if (!h_buf) |
| 2252 | return NULL; |
| 2253 | rqbp->buffer_count--; |
| 2254 | return container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 2255 | } |
| 2256 | |
| 2257 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2258 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2259 | * @phba: Pointer to HBA context object. |
| 2260 | * @tag: Tag of the hbq buffer. |
| 2261 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2262 | * This function searches for the hbq buffer associated with the given tag in |
| 2263 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2264 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2265 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2266 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2267 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2268 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2269 | struct lpfc_dmabuf *d_buf; |
| 2270 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2271 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2272 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2273 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2274 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2275 | return NULL; |
| 2276 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2277 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2278 | 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] | 2279 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2280 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2281 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2282 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2283 | } |
| 2284 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2285 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2286 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2287 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2288 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2289 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2290 | } |
| 2291 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2292 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2293 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2294 | * @phba: Pointer to HBA context object. |
| 2295 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2296 | * |
| 2297 | * This function is called with hbalock. This function gives back |
| 2298 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2299 | * post the buffer, it will free the buffer. |
| 2300 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2301 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2302 | 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] | 2303 | { |
| 2304 | uint32_t hbqno; |
| 2305 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2306 | if (hbq_buffer) { |
| 2307 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2308 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2309 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2310 | } |
| 2311 | } |
| 2312 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2313 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2314 | * 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] | 2315 | * @mbxCommand: mailbox command code. |
| 2316 | * |
| 2317 | * This function is called by the mailbox event handler function to verify |
| 2318 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2319 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2320 | * and the mailbox event handler will take the HBA offline. |
| 2321 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2322 | static int |
| 2323 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2324 | { |
| 2325 | uint8_t ret; |
| 2326 | |
| 2327 | switch (mbxCommand) { |
| 2328 | case MBX_LOAD_SM: |
| 2329 | case MBX_READ_NV: |
| 2330 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2331 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2332 | case MBX_RUN_BIU_DIAG: |
| 2333 | case MBX_INIT_LINK: |
| 2334 | case MBX_DOWN_LINK: |
| 2335 | case MBX_CONFIG_LINK: |
| 2336 | case MBX_CONFIG_RING: |
| 2337 | case MBX_RESET_RING: |
| 2338 | case MBX_READ_CONFIG: |
| 2339 | case MBX_READ_RCONFIG: |
| 2340 | case MBX_READ_SPARM: |
| 2341 | case MBX_READ_STATUS: |
| 2342 | case MBX_READ_RPI: |
| 2343 | case MBX_READ_XRI: |
| 2344 | case MBX_READ_REV: |
| 2345 | case MBX_READ_LNK_STAT: |
| 2346 | case MBX_REG_LOGIN: |
| 2347 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | case MBX_CLEAR_LA: |
| 2349 | case MBX_DUMP_MEMORY: |
| 2350 | case MBX_DUMP_CONTEXT: |
| 2351 | case MBX_RUN_DIAGS: |
| 2352 | case MBX_RESTART: |
| 2353 | case MBX_UPDATE_CFG: |
| 2354 | case MBX_DOWN_LOAD: |
| 2355 | case MBX_DEL_LD_ENTRY: |
| 2356 | case MBX_RUN_PROGRAM: |
| 2357 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2358 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2359 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2360 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2362 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | case MBX_LOAD_AREA: |
| 2364 | case MBX_RUN_BIU_DIAG64: |
| 2365 | case MBX_CONFIG_PORT: |
| 2366 | case MBX_READ_SPARM64: |
| 2367 | case MBX_READ_RPI64: |
| 2368 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2369 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2370 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2371 | case MBX_SET_DEBUG: |
| 2372 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2373 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2374 | case MBX_REG_VPI: |
| 2375 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2376 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2377 | case MBX_PORT_CAPABILITIES: |
| 2378 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2379 | case MBX_SLI4_CONFIG: |
| 2380 | case MBX_SLI4_REQ_FTRS: |
| 2381 | case MBX_REG_FCFI: |
| 2382 | case MBX_UNREG_FCFI: |
| 2383 | case MBX_REG_VFI: |
| 2384 | case MBX_UNREG_VFI: |
| 2385 | case MBX_INIT_VPI: |
| 2386 | case MBX_INIT_VFI: |
| 2387 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2388 | case MBX_READ_EVENT_LOG_STATUS: |
| 2389 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2390 | case MBX_SECURITY_MGMT: |
| 2391 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2392 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2393 | ret = mbxCommand; |
| 2394 | break; |
| 2395 | default: |
| 2396 | ret = MBX_SHUTDOWN; |
| 2397 | break; |
| 2398 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2399 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2400 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2401 | |
| 2402 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2403 | * 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] | 2404 | * @phba: Pointer to HBA context object. |
| 2405 | * @pmboxq: Pointer to mailbox command. |
| 2406 | * |
| 2407 | * This is completion handler function for mailbox commands issued from |
| 2408 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2409 | * mailbox event handler function with no lock held. This function |
| 2410 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2411 | * of the mailbox. |
| 2412 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2413 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2414 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2415 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2416 | unsigned long drvr_flag; |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2417 | struct completion *pmbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2418 | |
| 2419 | /* |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2420 | * If pmbox_done is empty, the driver thread gave up waiting and |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2421 | * continued running. |
| 2422 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2423 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2424 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2425 | pmbox_done = (struct completion *)pmboxq->context3; |
| 2426 | if (pmbox_done) |
| 2427 | complete(pmbox_done); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2428 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2429 | return; |
| 2430 | } |
| 2431 | |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2432 | static void |
| 2433 | __lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 2434 | { |
| 2435 | unsigned long iflags; |
| 2436 | |
| 2437 | if (ndlp->nlp_flag & NLP_RELEASE_RPI) { |
| 2438 | lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi); |
| 2439 | spin_lock_irqsave(&vport->phba->ndlp_lock, iflags); |
| 2440 | ndlp->nlp_flag &= ~NLP_RELEASE_RPI; |
| 2441 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
| 2442 | spin_unlock_irqrestore(&vport->phba->ndlp_lock, iflags); |
| 2443 | } |
| 2444 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 2445 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2446 | |
| 2447 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2448 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2449 | * @phba: Pointer to HBA context object. |
| 2450 | * @pmb: Pointer to mailbox object. |
| 2451 | * |
| 2452 | * This function is the default mailbox completion handler. It |
| 2453 | * frees the memory resources associated with the completed mailbox |
| 2454 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2455 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2456 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2457 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2458 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2459 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2460 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2461 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2462 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2463 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2464 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2465 | int rc; |
| 2466 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2467 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2468 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2469 | if (mp) { |
| 2470 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2471 | kfree(mp); |
| 2472 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2473 | |
| 2474 | /* |
| 2475 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2476 | * is in re-discovery driver need to cleanup the RPI. |
| 2477 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2478 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2479 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2480 | !pmb->u.mb.mbxStatus) { |
| 2481 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2482 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2483 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2484 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2485 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2486 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2487 | if (rc != MBX_NOT_FINISHED) |
| 2488 | return; |
| 2489 | } |
| 2490 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2491 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2492 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2493 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2494 | shost = lpfc_shost_from_vport(vport); |
| 2495 | spin_lock_irq(shost->host_lock); |
| 2496 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2497 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2498 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2499 | } |
| 2500 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2501 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2502 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2503 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2504 | pmb->ctx_buf = NULL; |
| 2505 | pmb->ctx_ndlp = NULL; |
| 2506 | } |
| 2507 | |
| 2508 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2509 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 2510 | |
| 2511 | /* Check to see if there are any deferred events to process */ |
| 2512 | if (ndlp) { |
| 2513 | lpfc_printf_vlog( |
| 2514 | vport, |
| 2515 | KERN_INFO, LOG_MBOX | LOG_DISCOVERY, |
| 2516 | "1438 UNREG cmpl deferred mbox x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2517 | "on NPort x%x Data: x%x x%x %px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2518 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2519 | ndlp->nlp_flag, ndlp->nlp_defer_did, ndlp); |
| 2520 | |
| 2521 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2522 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2523 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2524 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
| 2525 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2526 | } else { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2527 | __lpfc_sli_rpi_release(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2528 | } |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 2529 | if (vport->load_flag & FC_UNLOADING) |
| 2530 | lpfc_nlp_put(ndlp); |
James Smart | 9b16406 | 2019-03-12 16:30:06 -0700 | [diff] [blame] | 2531 | pmb->ctx_ndlp = NULL; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2532 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2533 | } |
| 2534 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2535 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2536 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2537 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2538 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2539 | "2860 SLI authentication is required " |
| 2540 | "for INIT_LINK but has not done yet\n"); |
| 2541 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2542 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2543 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2544 | else |
| 2545 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2546 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2547 | /** |
| 2548 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2549 | * @phba: Pointer to HBA context object. |
| 2550 | * @pmb: Pointer to mailbox object. |
| 2551 | * |
| 2552 | * This function is the unreg rpi mailbox completion handler. It |
| 2553 | * frees the memory resources associated with the completed mailbox |
| 2554 | * command. An additional refrenece is put on the ndlp to prevent |
| 2555 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2556 | * the unreg mailbox command completes, this routine puts the |
| 2557 | * reference back. |
| 2558 | * |
| 2559 | **/ |
| 2560 | void |
| 2561 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2562 | { |
| 2563 | struct lpfc_vport *vport = pmb->vport; |
| 2564 | struct lpfc_nodelist *ndlp; |
| 2565 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2566 | ndlp = pmb->ctx_ndlp; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2567 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2568 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2569 | (bf_get(lpfc_sli_intf_if_type, |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 2570 | &phba->sli4_hba.sli_intf) >= |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2571 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2572 | if (ndlp) { |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2573 | lpfc_printf_vlog( |
| 2574 | vport, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 2575 | "0010 UNREG_LOGIN vpi:%x " |
| 2576 | "rpi:%x DID:%x defer x%x flg x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2577 | "map:%x %px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2578 | vport->vpi, ndlp->nlp_rpi, |
| 2579 | ndlp->nlp_DID, ndlp->nlp_defer_did, |
| 2580 | ndlp->nlp_flag, |
| 2581 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2582 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2583 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2584 | |
| 2585 | /* Check to see if there are any deferred |
| 2586 | * events to process |
| 2587 | */ |
| 2588 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2589 | (ndlp->nlp_defer_did != |
| 2590 | NLP_EVT_NOTHING_PENDING)) { |
| 2591 | lpfc_printf_vlog( |
| 2592 | vport, KERN_INFO, LOG_DISCOVERY, |
| 2593 | "4111 UNREG cmpl deferred " |
| 2594 | "clr x%x on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2595 | "NPort x%x Data: x%x x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2596 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2597 | ndlp->nlp_defer_did, ndlp); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2598 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2599 | ndlp->nlp_defer_did = |
| 2600 | NLP_EVT_NOTHING_PENDING; |
| 2601 | lpfc_issue_els_plogi( |
| 2602 | vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2603 | } else { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2604 | __lpfc_sli_rpi_release(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2605 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2606 | } |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2611 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2612 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2613 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2614 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2615 | * @phba: Pointer to HBA context object. |
| 2616 | * |
| 2617 | * This function is called with no lock held. This function processes all |
| 2618 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2619 | * service routine processes mailbox completion interrupt and adds completed |
| 2620 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2621 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2622 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2623 | * function returns the mailbox commands to the upper layer by calling the |
| 2624 | * completion handler function of each mailbox. |
| 2625 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2626 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2627 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2628 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2629 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2630 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2631 | int rc; |
| 2632 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2633 | |
| 2634 | phba->sli.slistat.mbox_event++; |
| 2635 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2636 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2637 | spin_lock_irq(&phba->hbalock); |
| 2638 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2639 | spin_unlock_irq(&phba->hbalock); |
| 2640 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2642 | do { |
| 2643 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2644 | if (pmb == NULL) |
| 2645 | break; |
| 2646 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2647 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2648 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2649 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2650 | if (pmb->vport) { |
| 2651 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2652 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2653 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2654 | (uint32_t)pmbox->mbxCommand, |
| 2655 | pmbox->un.varWords[0], |
| 2656 | pmbox->un.varWords[1]); |
| 2657 | } |
| 2658 | else { |
| 2659 | lpfc_debugfs_disc_trc(phba->pport, |
| 2660 | LPFC_DISC_TRC_MBOX, |
| 2661 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2662 | (uint32_t)pmbox->mbxCommand, |
| 2663 | pmbox->un.varWords[0], |
| 2664 | pmbox->un.varWords[1]); |
| 2665 | } |
| 2666 | } |
| 2667 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2668 | /* |
| 2669 | * It is a fatal error if unknown mbox command completion. |
| 2670 | */ |
| 2671 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2672 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2673 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2674 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2675 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2676 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2677 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2678 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2679 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2680 | pmb), |
| 2681 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2682 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2683 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2684 | phba->work_hs = HS_FFER3; |
| 2685 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2686 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2687 | } |
| 2688 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2689 | if (pmbox->mbxStatus) { |
| 2690 | phba->sli.slistat.mbox_stat_err++; |
| 2691 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2692 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2693 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2694 | LOG_MBOX | LOG_SLI, |
| 2695 | "(%d):0305 Mbox cmd cmpl " |
| 2696 | "error - RETRYing Data: x%x " |
| 2697 | "(x%x/x%x) x%x x%x x%x\n", |
| 2698 | pmb->vport ? pmb->vport->vpi : 0, |
| 2699 | pmbox->mbxCommand, |
| 2700 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2701 | pmb), |
| 2702 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2703 | pmb), |
| 2704 | pmbox->mbxStatus, |
| 2705 | pmbox->un.varWords[0], |
| 2706 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2707 | pmbox->mbxStatus = 0; |
| 2708 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2709 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2710 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2711 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2712 | } |
| 2713 | } |
| 2714 | |
| 2715 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2716 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
Sakari Ailus | 2d44d16 | 2019-09-04 19:04:23 +0300 | [diff] [blame] | 2717 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl %ps " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2718 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2719 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2720 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2721 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2722 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2723 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2724 | pmb->mbox_cmpl, |
| 2725 | *((uint32_t *) pmbox), |
| 2726 | pmbox->un.varWords[0], |
| 2727 | pmbox->un.varWords[1], |
| 2728 | pmbox->un.varWords[2], |
| 2729 | pmbox->un.varWords[3], |
| 2730 | pmbox->un.varWords[4], |
| 2731 | pmbox->un.varWords[5], |
| 2732 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2733 | pmbox->un.varWords[7], |
| 2734 | pmbox->un.varWords[8], |
| 2735 | pmbox->un.varWords[9], |
| 2736 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2737 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2738 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2739 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2740 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2741 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2743 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2744 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2745 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2746 | * @phba: Pointer to HBA context object. |
| 2747 | * @pring: Pointer to driver SLI ring object. |
| 2748 | * @tag: buffer tag. |
| 2749 | * |
| 2750 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2751 | * is set in the tag the buffer is posted for a particular exchange, |
| 2752 | * the function will return the buffer without replacing the buffer. |
| 2753 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2754 | * returns the buffer and also posts another buffer to the firmware. |
| 2755 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2756 | static struct lpfc_dmabuf * |
| 2757 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2758 | struct lpfc_sli_ring *pring, |
| 2759 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2760 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2761 | struct hbq_dmabuf *hbq_entry; |
| 2762 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2763 | if (tag & QUE_BUFTAG_BIT) |
| 2764 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2765 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2766 | if (!hbq_entry) |
| 2767 | return NULL; |
| 2768 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2769 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2770 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2771 | /** |
| 2772 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2773 | * @phba: Pointer to HBA context object. |
| 2774 | * @pring: Pointer to driver SLI ring object. |
| 2775 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2776 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2777 | * @fch_type: the type for the first frame of the sequence. |
| 2778 | * |
| 2779 | * This function is called with no lock held. This function uses the r_ctl and |
| 2780 | * type of the received sequence to find the correct callback function to call |
| 2781 | * to process the sequence. |
| 2782 | **/ |
| 2783 | static int |
| 2784 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2785 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2786 | uint32_t fch_type) |
| 2787 | { |
| 2788 | int i; |
| 2789 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2790 | switch (fch_type) { |
| 2791 | case FC_TYPE_NVME: |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2792 | lpfc_nvmet_unsol_ls_event(phba, pring, saveq); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2793 | return 1; |
| 2794 | default: |
| 2795 | break; |
| 2796 | } |
| 2797 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2798 | /* unSolicited Responses */ |
| 2799 | if (pring->prt[0].profile) { |
| 2800 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2801 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2802 | saveq); |
| 2803 | return 1; |
| 2804 | } |
| 2805 | /* We must search, based on rctl / type |
| 2806 | for the right routine */ |
| 2807 | for (i = 0; i < pring->num_mask; i++) { |
| 2808 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2809 | (pring->prt[i].type == fch_type)) { |
| 2810 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2811 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2812 | (phba, pring, saveq); |
| 2813 | return 1; |
| 2814 | } |
| 2815 | } |
| 2816 | return 0; |
| 2817 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2818 | |
| 2819 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2820 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2821 | * @phba: Pointer to HBA context object. |
| 2822 | * @pring: Pointer to driver SLI ring object. |
| 2823 | * @saveq: Pointer to the unsolicited iocb. |
| 2824 | * |
| 2825 | * This function is called with no lock held by the ring event handler |
| 2826 | * when there is an unsolicited iocb posted to the response ring by the |
| 2827 | * firmware. This function gets the buffer associated with the iocbs |
| 2828 | * and calls the event handler for the ring. This function handles both |
| 2829 | * qring buffers and hbq buffers. |
| 2830 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2831 | * upper layer functions will free the iocb objects. |
| 2832 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2833 | static int |
| 2834 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2835 | struct lpfc_iocbq *saveq) |
| 2836 | { |
| 2837 | IOCB_t * irsp; |
| 2838 | WORD5 * w5p; |
| 2839 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2840 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2841 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2842 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2843 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2844 | |
| 2845 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2846 | if (pring->lpfc_sli_rcv_async_status) |
| 2847 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2848 | else |
| 2849 | lpfc_printf_log(phba, |
| 2850 | KERN_WARNING, |
| 2851 | LOG_SLI, |
| 2852 | "0316 Ring %d handler: unexpected " |
| 2853 | "ASYNC_STATUS iocb received evt_code " |
| 2854 | "0x%x\n", |
| 2855 | pring->ringno, |
| 2856 | irsp->un.asyncstat.evt_code); |
| 2857 | return 1; |
| 2858 | } |
| 2859 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2860 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2861 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2862 | if (irsp->ulpBdeCount > 0) { |
| 2863 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2864 | irsp->un.ulpWord[3]); |
| 2865 | lpfc_in_buf_free(phba, dmzbuf); |
| 2866 | } |
| 2867 | |
| 2868 | if (irsp->ulpBdeCount > 1) { |
| 2869 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2870 | irsp->unsli3.sli3Words[3]); |
| 2871 | lpfc_in_buf_free(phba, dmzbuf); |
| 2872 | } |
| 2873 | |
| 2874 | if (irsp->ulpBdeCount > 2) { |
| 2875 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2876 | irsp->unsli3.sli3Words[7]); |
| 2877 | lpfc_in_buf_free(phba, dmzbuf); |
| 2878 | } |
| 2879 | |
| 2880 | return 1; |
| 2881 | } |
| 2882 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2883 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2884 | if (irsp->ulpBdeCount != 0) { |
| 2885 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2886 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2887 | if (!saveq->context2) |
| 2888 | lpfc_printf_log(phba, |
| 2889 | KERN_ERR, |
| 2890 | LOG_SLI, |
| 2891 | "0341 Ring %d Cannot find buffer for " |
| 2892 | "an unsolicited iocb. tag 0x%x\n", |
| 2893 | pring->ringno, |
| 2894 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2895 | } |
| 2896 | if (irsp->ulpBdeCount == 2) { |
| 2897 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2898 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2899 | if (!saveq->context3) |
| 2900 | lpfc_printf_log(phba, |
| 2901 | KERN_ERR, |
| 2902 | LOG_SLI, |
| 2903 | "0342 Ring %d Cannot find buffer for an" |
| 2904 | " unsolicited iocb. tag 0x%x\n", |
| 2905 | pring->ringno, |
| 2906 | irsp->unsli3.sli3Words[7]); |
| 2907 | } |
| 2908 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2909 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2910 | if (irsp->ulpBdeCount != 0) { |
| 2911 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2912 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2913 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2914 | lpfc_printf_log(phba, |
| 2915 | KERN_ERR, |
| 2916 | LOG_SLI, |
| 2917 | "0343 Ring %d Cannot find " |
| 2918 | "buffer for an unsolicited iocb" |
| 2919 | ". tag 0x%x\n", pring->ringno, |
| 2920 | irsp->un.ulpWord[3]); |
| 2921 | } |
| 2922 | if (irsp->ulpBdeCount == 2) { |
| 2923 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2924 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2925 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2926 | lpfc_printf_log(phba, |
| 2927 | KERN_ERR, |
| 2928 | LOG_SLI, |
| 2929 | "0344 Ring %d Cannot find " |
| 2930 | "buffer for an unsolicited " |
| 2931 | "iocb. tag 0x%x\n", |
| 2932 | pring->ringno, |
| 2933 | irsp->unsli3.sli3Words[7]); |
| 2934 | } |
| 2935 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2936 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2937 | if (irsp->ulpBdeCount != 0 && |
| 2938 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2939 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2940 | int found = 0; |
| 2941 | |
| 2942 | /* search continue save q for same XRI */ |
| 2943 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2944 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2945 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2946 | list_add_tail(&saveq->list, &iocbq->list); |
| 2947 | found = 1; |
| 2948 | break; |
| 2949 | } |
| 2950 | } |
| 2951 | if (!found) |
| 2952 | list_add_tail(&saveq->clist, |
| 2953 | &pring->iocb_continue_saveq); |
| 2954 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2955 | list_del_init(&iocbq->clist); |
| 2956 | saveq = iocbq; |
| 2957 | irsp = &(saveq->iocb); |
| 2958 | } else |
| 2959 | return 0; |
| 2960 | } |
| 2961 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2962 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2963 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2964 | Rctl = FC_RCTL_ELS_REQ; |
| 2965 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2966 | } else { |
| 2967 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2968 | Rctl = w5p->hcsw.Rctl; |
| 2969 | Type = w5p->hcsw.Type; |
| 2970 | |
| 2971 | /* Firmware Workaround */ |
| 2972 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2973 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2974 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2975 | Rctl = FC_RCTL_ELS_REQ; |
| 2976 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2977 | w5p->hcsw.Rctl = Rctl; |
| 2978 | w5p->hcsw.Type = Type; |
| 2979 | } |
| 2980 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2981 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2982 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2983 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2984 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2985 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2986 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2987 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2988 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2989 | } |
| 2990 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2991 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2992 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2993 | * @phba: Pointer to HBA context object. |
| 2994 | * @pring: Pointer to driver SLI ring object. |
| 2995 | * @prspiocb: Pointer to response iocb object. |
| 2996 | * |
| 2997 | * This function looks up the iocb_lookup table to get the command iocb |
| 2998 | * corresponding to the given response iocb using the iotag of the |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 2999 | * response iocb. The driver calls this function with the hbalock held |
| 3000 | * for SLI3 ports or the ring lock held for SLI4 ports. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3001 | * This function returns the command iocb object if it finds the command |
| 3002 | * iocb else returns NULL. |
| 3003 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3004 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3005 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 3006 | struct lpfc_sli_ring *pring, |
| 3007 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3008 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3009 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 3010 | uint16_t iotag; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3011 | spinlock_t *temp_lock = NULL; |
| 3012 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3013 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3014 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3015 | temp_lock = &pring->ring_lock; |
| 3016 | else |
| 3017 | temp_lock = &phba->hbalock; |
| 3018 | |
| 3019 | spin_lock_irqsave(temp_lock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3020 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3021 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3022 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3023 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3024 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3025 | /* remove from txcmpl queue list */ |
| 3026 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3027 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3028 | pring->txcmplq_cnt--; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3029 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3030 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3031 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3032 | } |
| 3033 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3034 | spin_unlock_irqrestore(temp_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3035 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3036 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3037 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3038 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3039 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3040 | return NULL; |
| 3041 | } |
| 3042 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3043 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3044 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 3045 | * @phba: Pointer to HBA context object. |
| 3046 | * @pring: Pointer to driver SLI ring object. |
| 3047 | * @iotag: IOCB tag. |
| 3048 | * |
| 3049 | * This function looks up the iocb_lookup table to get the command iocb |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3050 | * corresponding to the given iotag. The driver calls this function with |
| 3051 | * the ring lock held because this function is an SLI4 port only helper. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3052 | * This function returns the command iocb object if it finds the command |
| 3053 | * iocb else returns NULL. |
| 3054 | **/ |
| 3055 | static struct lpfc_iocbq * |
| 3056 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 3057 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 3058 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3059 | struct lpfc_iocbq *cmd_iocb = NULL; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3060 | spinlock_t *temp_lock = NULL; |
| 3061 | unsigned long iflag = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3062 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3063 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3064 | temp_lock = &pring->ring_lock; |
| 3065 | else |
| 3066 | temp_lock = &phba->hbalock; |
| 3067 | |
| 3068 | spin_lock_irqsave(temp_lock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3069 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3070 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3071 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 3072 | /* remove from txcmpl queue list */ |
| 3073 | list_del_init(&cmd_iocb->list); |
| 3074 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3075 | pring->txcmplq_cnt--; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3076 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3077 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3078 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3079 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3080 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3081 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3082 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3083 | "0372 iotag x%x lookup error: max iotag (x%x) " |
| 3084 | "iocb_flag x%x\n", |
| 3085 | iotag, phba->sli.last_iotag, |
| 3086 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3087 | return NULL; |
| 3088 | } |
| 3089 | |
| 3090 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3091 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3092 | * @phba: Pointer to HBA context object. |
| 3093 | * @pring: Pointer to driver SLI ring object. |
| 3094 | * @saveq: Pointer to the response iocb to be processed. |
| 3095 | * |
| 3096 | * This function is called by the ring event handler for non-fcp |
| 3097 | * rings when there is a new response iocb in the response ring. |
| 3098 | * The caller is not required to hold any locks. This function |
| 3099 | * gets the command iocb associated with the response iocb and |
| 3100 | * calls the completion handler for the command iocb. If there |
| 3101 | * is no completion handler, the function will free the resources |
| 3102 | * associated with command iocb. If the response iocb is for |
| 3103 | * an already aborted command iocb, the status of the completion |
| 3104 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 3105 | * This function always returns 1. |
| 3106 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3107 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3108 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3109 | struct lpfc_iocbq *saveq) |
| 3110 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3111 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3112 | int rc = 1; |
| 3113 | unsigned long iflag; |
| 3114 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3115 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3116 | if (cmdiocbp) { |
| 3117 | if (cmdiocbp->iocb_cmpl) { |
| 3118 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3119 | * If an ELS command failed send an event to mgmt |
| 3120 | * application. |
| 3121 | */ |
| 3122 | if (saveq->iocb.ulpStatus && |
| 3123 | (pring->ringno == LPFC_ELS_RING) && |
| 3124 | (cmdiocbp->iocb.ulpCommand == |
| 3125 | CMD_ELS_REQUEST64_CR)) |
| 3126 | lpfc_send_els_failure_event(phba, |
| 3127 | cmdiocbp, saveq); |
| 3128 | |
| 3129 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3130 | * Post all ELS completions to the worker thread. |
| 3131 | * All other are passed to the completion callback. |
| 3132 | */ |
| 3133 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3134 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3135 | (cmdiocbp->iocb_flag & |
| 3136 | LPFC_DRIVER_ABORTED)) { |
| 3137 | spin_lock_irqsave(&phba->hbalock, |
| 3138 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3139 | cmdiocbp->iocb_flag &= |
| 3140 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3141 | spin_unlock_irqrestore(&phba->hbalock, |
| 3142 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3143 | saveq->iocb.ulpStatus = |
| 3144 | IOSTAT_LOCAL_REJECT; |
| 3145 | saveq->iocb.un.ulpWord[4] = |
| 3146 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3147 | |
| 3148 | /* Firmware could still be in progress |
| 3149 | * of DMAing payload, so don't free data |
| 3150 | * buffer till after a hbeat. |
| 3151 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3152 | spin_lock_irqsave(&phba->hbalock, |
| 3153 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3154 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3155 | spin_unlock_irqrestore(&phba->hbalock, |
| 3156 | iflag); |
| 3157 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3158 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3159 | if (saveq->iocb_flag & |
| 3160 | LPFC_EXCHANGE_BUSY) { |
| 3161 | /* Set cmdiocb flag for the |
| 3162 | * exchange busy so sgl (xri) |
| 3163 | * will not be released until |
| 3164 | * the abort xri is received |
| 3165 | * from hba. |
| 3166 | */ |
| 3167 | spin_lock_irqsave( |
| 3168 | &phba->hbalock, iflag); |
| 3169 | cmdiocbp->iocb_flag |= |
| 3170 | LPFC_EXCHANGE_BUSY; |
| 3171 | spin_unlock_irqrestore( |
| 3172 | &phba->hbalock, iflag); |
| 3173 | } |
| 3174 | if (cmdiocbp->iocb_flag & |
| 3175 | LPFC_DRIVER_ABORTED) { |
| 3176 | /* |
| 3177 | * Clear LPFC_DRIVER_ABORTED |
| 3178 | * bit in case it was driver |
| 3179 | * initiated abort. |
| 3180 | */ |
| 3181 | spin_lock_irqsave( |
| 3182 | &phba->hbalock, iflag); |
| 3183 | cmdiocbp->iocb_flag &= |
| 3184 | ~LPFC_DRIVER_ABORTED; |
| 3185 | spin_unlock_irqrestore( |
| 3186 | &phba->hbalock, iflag); |
| 3187 | cmdiocbp->iocb.ulpStatus = |
| 3188 | IOSTAT_LOCAL_REJECT; |
| 3189 | cmdiocbp->iocb.un.ulpWord[4] = |
| 3190 | IOERR_ABORT_REQUESTED; |
| 3191 | /* |
| 3192 | * For SLI4, irsiocb contains |
| 3193 | * NO_XRI in sli_xritag, it |
| 3194 | * shall not affect releasing |
| 3195 | * sgl (xri) process. |
| 3196 | */ |
| 3197 | saveq->iocb.ulpStatus = |
| 3198 | IOSTAT_LOCAL_REJECT; |
| 3199 | saveq->iocb.un.ulpWord[4] = |
| 3200 | IOERR_SLI_ABORTED; |
| 3201 | spin_lock_irqsave( |
| 3202 | &phba->hbalock, iflag); |
| 3203 | saveq->iocb_flag |= |
| 3204 | LPFC_DELAY_MEM_FREE; |
| 3205 | spin_unlock_irqrestore( |
| 3206 | &phba->hbalock, iflag); |
| 3207 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3208 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3209 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3210 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3211 | } else |
| 3212 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3213 | } else { |
| 3214 | /* |
| 3215 | * Unknown initiating command based on the response iotag. |
| 3216 | * This could be the case on the ELS ring because of |
| 3217 | * lpfc_els_abort(). |
| 3218 | */ |
| 3219 | if (pring->ringno != LPFC_ELS_RING) { |
| 3220 | /* |
| 3221 | * Ring <ringno> handler: unexpected completion IoTag |
| 3222 | * <IoTag> |
| 3223 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3224 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3225 | "0322 Ring %d handler: " |
| 3226 | "unexpected completion IoTag x%x " |
| 3227 | "Data: x%x x%x x%x x%x\n", |
| 3228 | pring->ringno, |
| 3229 | saveq->iocb.ulpIoTag, |
| 3230 | saveq->iocb.ulpStatus, |
| 3231 | saveq->iocb.un.ulpWord[4], |
| 3232 | saveq->iocb.ulpCommand, |
| 3233 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3234 | } |
| 3235 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3236 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3237 | return rc; |
| 3238 | } |
| 3239 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3240 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3241 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3242 | * @phba: Pointer to HBA context object. |
| 3243 | * @pring: Pointer to driver SLI ring object. |
| 3244 | * |
| 3245 | * This function is called from the iocb ring event handlers when |
| 3246 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 3247 | * an error attention condition to the worker thread and the worker |
| 3248 | * thread will transition the HBA to offline state. |
| 3249 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3250 | static void |
| 3251 | 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] | 3252 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3253 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3254 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3255 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3256 | * rsp ring <portRspMax> |
| 3257 | */ |
| 3258 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3259 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3260 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3261 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3262 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3263 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3264 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3265 | |
| 3266 | /* |
| 3267 | * All error attention handlers are posted to |
| 3268 | * worker thread |
| 3269 | */ |
| 3270 | phba->work_ha |= HA_ERATT; |
| 3271 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3272 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3273 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3274 | |
| 3275 | return; |
| 3276 | } |
| 3277 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3278 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3279 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3280 | * @ptr: Pointer to address of HBA context object. |
| 3281 | * |
| 3282 | * This function is invoked by the Error Attention polling timer when the |
| 3283 | * timer times out. It will check the SLI Error Attention register for |
| 3284 | * possible attention events. If so, it will post an Error Attention event |
| 3285 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 3286 | * Error Attention polling timer for the next poll. |
| 3287 | **/ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3288 | void lpfc_poll_eratt(struct timer_list *t) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3289 | { |
| 3290 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3291 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3292 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3293 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3294 | phba = from_timer(phba, t, eratt_poll); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3295 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3296 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 3297 | sli_intr = phba->sli.slistat.sli_intr; |
| 3298 | |
| 3299 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 3300 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 3301 | sli_intr); |
| 3302 | else |
| 3303 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 3304 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3305 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 3306 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3307 | phba->sli.slistat.sli_ips = cnt; |
| 3308 | |
| 3309 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 3310 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3311 | /* Check chip HA register for error event */ |
| 3312 | eratt = lpfc_sli_check_eratt(phba); |
| 3313 | |
| 3314 | if (eratt) |
| 3315 | /* Tell the worker thread there is work to do */ |
| 3316 | lpfc_worker_wake_up(phba); |
| 3317 | else |
| 3318 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3319 | mod_timer(&phba->eratt_poll, |
| 3320 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3321 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3322 | return; |
| 3323 | } |
| 3324 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3325 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3326 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3327 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3328 | * @phba: Pointer to HBA context object. |
| 3329 | * @pring: Pointer to driver SLI ring object. |
| 3330 | * @mask: Host attention register mask for this ring. |
| 3331 | * |
| 3332 | * This function is called from the interrupt context when there is a ring |
| 3333 | * event for the fcp ring. The caller does not hold any lock. |
| 3334 | * 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] | 3335 | * 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] | 3336 | * LE bit set. The function will call the completion handler of the command iocb |
| 3337 | * if the response iocb indicates a completion for a command iocb or it is |
| 3338 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 3339 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3340 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3341 | * to check it explicitly. |
| 3342 | */ |
| 3343 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3344 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 3345 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3346 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3347 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3348 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3349 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3350 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 3351 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3352 | uint32_t status; |
| 3353 | uint32_t portRspPut, portRspMax; |
| 3354 | int rc = 1; |
| 3355 | lpfc_iocb_type type; |
| 3356 | unsigned long iflag; |
| 3357 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3358 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3359 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3360 | pring->stats.iocb_event++; |
| 3361 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3362 | /* |
| 3363 | * The next available response entry should never exceed the maximum |
| 3364 | * entries. If it does, treat it as an adapter hardware error. |
| 3365 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3366 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3367 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3368 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3369 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3370 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3371 | return 1; |
| 3372 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3373 | if (phba->fcp_ring_in_use) { |
| 3374 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3375 | return 1; |
| 3376 | } else |
| 3377 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3378 | |
| 3379 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3380 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3381 | /* |
| 3382 | * Fetch an entry off the ring and copy it into a local data |
| 3383 | * structure. The copy involves a byte-swap since the |
| 3384 | * network byte order and pci byte orders are different. |
| 3385 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3386 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3387 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3388 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3389 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3390 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3391 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3392 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3393 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3394 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3395 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3396 | irsp = &rspiocbq.iocb; |
| 3397 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3398 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3399 | pring->stats.iocb_rsp++; |
| 3400 | rsp_cmpl++; |
| 3401 | |
| 3402 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3403 | /* |
| 3404 | * If resource errors reported from HBA, reduce |
| 3405 | * queuedepths of the SCSI device. |
| 3406 | */ |
| 3407 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3408 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3409 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3410 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3411 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3412 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3413 | } |
| 3414 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3415 | /* Rsp ring <ringno> error: IOCB */ |
| 3416 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3417 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3418 | "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] | 3419 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3420 | irsp->un.ulpWord[0], |
| 3421 | irsp->un.ulpWord[1], |
| 3422 | irsp->un.ulpWord[2], |
| 3423 | irsp->un.ulpWord[3], |
| 3424 | irsp->un.ulpWord[4], |
| 3425 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3426 | *(uint32_t *)&irsp->un1, |
| 3427 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | switch (type) { |
| 3431 | case LPFC_ABORT_IOCB: |
| 3432 | case LPFC_SOL_IOCB: |
| 3433 | /* |
| 3434 | * Idle exchange closed via ABTS from port. No iocb |
| 3435 | * resources need to be recovered. |
| 3436 | */ |
| 3437 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3438 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3439 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3440 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3441 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3442 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3443 | break; |
| 3444 | } |
| 3445 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3446 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3447 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3448 | &rspiocbq); |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3449 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3450 | if (unlikely(!cmdiocbq)) |
| 3451 | break; |
| 3452 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3453 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3454 | if (cmdiocbq->iocb_cmpl) { |
| 3455 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3456 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3457 | &rspiocbq); |
| 3458 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3459 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3461 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3462 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3463 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3464 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3465 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | default: |
| 3467 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3468 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3469 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3470 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3471 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3472 | dev_warn(&((phba->pcidev)->dev), |
| 3473 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3474 | phba->brd_no, adaptermsg); |
| 3475 | } else { |
| 3476 | /* Unknown IOCB command */ |
| 3477 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3478 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3479 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3480 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3481 | irsp->ulpStatus, |
| 3482 | irsp->ulpIoTag, |
| 3483 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3484 | } |
| 3485 | break; |
| 3486 | } |
| 3487 | |
| 3488 | /* |
| 3489 | * The response IOCB has been processed. Update the ring |
| 3490 | * pointer in SLIM. If the port response put pointer has not |
| 3491 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3492 | * response put pointer. |
| 3493 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3494 | writel(pring->sli.sli3.rspidx, |
| 3495 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3496 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3497 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3498 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3499 | } |
| 3500 | |
| 3501 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3502 | pring->stats.iocb_rsp_full++; |
| 3503 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3504 | writel(status, phba->CAregaddr); |
| 3505 | readl(phba->CAregaddr); |
| 3506 | } |
| 3507 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3508 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3509 | pring->stats.iocb_cmd_empty++; |
| 3510 | |
| 3511 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3512 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3513 | lpfc_sli_resume_iocb(phba, pring); |
| 3514 | |
| 3515 | if ((pring->lpfc_sli_cmd_available)) |
| 3516 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3517 | |
| 3518 | } |
| 3519 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3520 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3521 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3522 | return rc; |
| 3523 | } |
| 3524 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3525 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3526 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3527 | * @phba: Pointer to HBA context object. |
| 3528 | * @pring: Pointer to driver SLI ring object. |
| 3529 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3530 | * |
| 3531 | * This function is called from the worker thread when there is a slow-path |
| 3532 | * response IOCB to process. This function chains all the response iocbs until |
| 3533 | * seeing the iocb with the LE bit set. The function will call |
| 3534 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3535 | * completion of a command iocb. The function will call the |
| 3536 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3537 | * The function frees the resources or calls the completion handler if this |
| 3538 | * iocb is an abort completion. The function returns NULL when the response |
| 3539 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3540 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3541 | * response iocb passed in. |
| 3542 | **/ |
| 3543 | static struct lpfc_iocbq * |
| 3544 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3545 | struct lpfc_iocbq *rspiocbp) |
| 3546 | { |
| 3547 | struct lpfc_iocbq *saveq; |
| 3548 | struct lpfc_iocbq *cmdiocbp; |
| 3549 | struct lpfc_iocbq *next_iocb; |
| 3550 | IOCB_t *irsp = NULL; |
| 3551 | uint32_t free_saveq; |
| 3552 | uint8_t iocb_cmd_type; |
| 3553 | lpfc_iocb_type type; |
| 3554 | unsigned long iflag; |
| 3555 | int rc; |
| 3556 | |
| 3557 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3558 | /* First add the response iocb to the countinueq list */ |
| 3559 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3560 | pring->iocb_continueq_cnt++; |
| 3561 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3562 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3563 | irsp = &rspiocbp->iocb; |
| 3564 | if (irsp->ulpLe) { |
| 3565 | /* |
| 3566 | * By default, the driver expects to free all resources |
| 3567 | * associated with this iocb completion. |
| 3568 | */ |
| 3569 | free_saveq = 1; |
| 3570 | saveq = list_get_first(&pring->iocb_continueq, |
| 3571 | struct lpfc_iocbq, list); |
| 3572 | irsp = &(saveq->iocb); |
| 3573 | list_del_init(&pring->iocb_continueq); |
| 3574 | pring->iocb_continueq_cnt = 0; |
| 3575 | |
| 3576 | pring->stats.iocb_rsp++; |
| 3577 | |
| 3578 | /* |
| 3579 | * If resource errors reported from HBA, reduce |
| 3580 | * queuedepths of the SCSI device. |
| 3581 | */ |
| 3582 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3583 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3584 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3585 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3586 | phba->lpfc_rampdown_queue_depth(phba); |
| 3587 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3588 | } |
| 3589 | |
| 3590 | if (irsp->ulpStatus) { |
| 3591 | /* Rsp ring <ringno> error: IOCB */ |
| 3592 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3593 | "0328 Rsp Ring %d error: " |
| 3594 | "IOCB Data: " |
| 3595 | "x%x x%x x%x x%x " |
| 3596 | "x%x x%x x%x x%x " |
| 3597 | "x%x x%x x%x x%x " |
| 3598 | "x%x x%x x%x x%x\n", |
| 3599 | pring->ringno, |
| 3600 | irsp->un.ulpWord[0], |
| 3601 | irsp->un.ulpWord[1], |
| 3602 | irsp->un.ulpWord[2], |
| 3603 | irsp->un.ulpWord[3], |
| 3604 | irsp->un.ulpWord[4], |
| 3605 | irsp->un.ulpWord[5], |
| 3606 | *(((uint32_t *) irsp) + 6), |
| 3607 | *(((uint32_t *) irsp) + 7), |
| 3608 | *(((uint32_t *) irsp) + 8), |
| 3609 | *(((uint32_t *) irsp) + 9), |
| 3610 | *(((uint32_t *) irsp) + 10), |
| 3611 | *(((uint32_t *) irsp) + 11), |
| 3612 | *(((uint32_t *) irsp) + 12), |
| 3613 | *(((uint32_t *) irsp) + 13), |
| 3614 | *(((uint32_t *) irsp) + 14), |
| 3615 | *(((uint32_t *) irsp) + 15)); |
| 3616 | } |
| 3617 | |
| 3618 | /* |
| 3619 | * Fetch the IOCB command type and call the correct completion |
| 3620 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3621 | * get freed back to the lpfc_iocb_list by the discovery |
| 3622 | * kernel thread. |
| 3623 | */ |
| 3624 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3625 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3626 | switch (type) { |
| 3627 | case LPFC_SOL_IOCB: |
| 3628 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3629 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3630 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3631 | break; |
| 3632 | |
| 3633 | case LPFC_UNSOL_IOCB: |
| 3634 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3635 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3636 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3637 | if (!rc) |
| 3638 | free_saveq = 0; |
| 3639 | break; |
| 3640 | |
| 3641 | case LPFC_ABORT_IOCB: |
| 3642 | cmdiocbp = NULL; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3643 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) { |
| 3644 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3645 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3646 | saveq); |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3647 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3648 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3649 | if (cmdiocbp) { |
| 3650 | /* Call the specified completion routine */ |
| 3651 | if (cmdiocbp->iocb_cmpl) { |
| 3652 | spin_unlock_irqrestore(&phba->hbalock, |
| 3653 | iflag); |
| 3654 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3655 | saveq); |
| 3656 | spin_lock_irqsave(&phba->hbalock, |
| 3657 | iflag); |
| 3658 | } else |
| 3659 | __lpfc_sli_release_iocbq(phba, |
| 3660 | cmdiocbp); |
| 3661 | } |
| 3662 | break; |
| 3663 | |
| 3664 | case LPFC_UNKNOWN_IOCB: |
| 3665 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3666 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3667 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3668 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3669 | MAX_MSG_DATA); |
| 3670 | dev_warn(&((phba->pcidev)->dev), |
| 3671 | "lpfc%d: %s\n", |
| 3672 | phba->brd_no, adaptermsg); |
| 3673 | } else { |
| 3674 | /* Unknown IOCB command */ |
| 3675 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3676 | "0335 Unknown IOCB " |
| 3677 | "command Data: x%x " |
| 3678 | "x%x x%x x%x\n", |
| 3679 | irsp->ulpCommand, |
| 3680 | irsp->ulpStatus, |
| 3681 | irsp->ulpIoTag, |
| 3682 | irsp->ulpContext); |
| 3683 | } |
| 3684 | break; |
| 3685 | } |
| 3686 | |
| 3687 | if (free_saveq) { |
| 3688 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3689 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3690 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3691 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3692 | } |
| 3693 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3694 | } |
| 3695 | rspiocbp = NULL; |
| 3696 | } |
| 3697 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3698 | return rspiocbp; |
| 3699 | } |
| 3700 | |
| 3701 | /** |
| 3702 | * 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] | 3703 | * @phba: Pointer to HBA context object. |
| 3704 | * @pring: Pointer to driver SLI ring object. |
| 3705 | * @mask: Host attention register mask for this ring. |
| 3706 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3707 | * This routine wraps the actual slow_ring event process routine from the |
| 3708 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3709 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3710 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3711 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3712 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3713 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3714 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3715 | } |
| 3716 | |
| 3717 | /** |
| 3718 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3719 | * @phba: Pointer to HBA context object. |
| 3720 | * @pring: Pointer to driver SLI ring object. |
| 3721 | * @mask: Host attention register mask for this ring. |
| 3722 | * |
| 3723 | * This function is called from the worker thread when there is a ring event |
| 3724 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3725 | * remove each response iocb in the response ring and calls the handle |
| 3726 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3727 | **/ |
| 3728 | static void |
| 3729 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3730 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3731 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3732 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3733 | IOCB_t *entry; |
| 3734 | IOCB_t *irsp = NULL; |
| 3735 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3736 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3737 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3738 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3739 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3740 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3741 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3742 | pring->stats.iocb_event++; |
| 3743 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3744 | /* |
| 3745 | * The next available response entry should never exceed the maximum |
| 3746 | * entries. If it does, treat it as an adapter hardware error. |
| 3747 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3748 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3749 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3750 | if (portRspPut >= portRspMax) { |
| 3751 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3752 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3753 | * rsp ring <portRspMax> |
| 3754 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3755 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3756 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3757 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3758 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3759 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3760 | phba->link_state = LPFC_HBA_ERROR; |
| 3761 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3762 | |
| 3763 | phba->work_hs = HS_FFER3; |
| 3764 | lpfc_handle_eratt(phba); |
| 3765 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3766 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3770 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3771 | /* |
| 3772 | * Build a completion list and call the appropriate handler. |
| 3773 | * The process is to get the next available response iocb, get |
| 3774 | * a free iocb from the list, copy the response data into the |
| 3775 | * free iocb, insert to the continuation list, and update the |
| 3776 | * next response index to slim. This process makes response |
| 3777 | * iocb's in the ring available to DMA as fast as possible but |
| 3778 | * pays a penalty for a copy operation. Since the iocb is |
| 3779 | * only 32 bytes, this penalty is considered small relative to |
| 3780 | * the PCI reads for register values and a slim write. When |
| 3781 | * the ulpLe field is set, the entire Command has been |
| 3782 | * received. |
| 3783 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3784 | entry = lpfc_resp_iocb(phba, pring); |
| 3785 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3786 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3787 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3788 | if (rspiocbp == NULL) { |
| 3789 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3790 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3791 | break; |
| 3792 | } |
| 3793 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3794 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3795 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | irsp = &rspiocbp->iocb; |
| 3797 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3798 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3799 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3801 | if (pring->ringno == LPFC_ELS_RING) { |
| 3802 | lpfc_debugfs_slow_ring_trc(phba, |
| 3803 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3804 | *(((uint32_t *) irsp) + 4), |
| 3805 | *(((uint32_t *) irsp) + 6), |
| 3806 | *(((uint32_t *) irsp) + 7)); |
| 3807 | } |
| 3808 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3809 | writel(pring->sli.sli3.rspidx, |
| 3810 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3811 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3812 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3813 | /* Handle the response IOCB */ |
| 3814 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3815 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3816 | |
| 3817 | /* |
| 3818 | * If the port response put pointer has not been updated, sync |
| 3819 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3820 | * response put pointer. |
| 3821 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3822 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3823 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3824 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3825 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3826 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3827 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3828 | /* At least one response entry has been freed */ |
| 3829 | pring->stats.iocb_rsp_full++; |
| 3830 | /* SET RxRE_RSP in Chip Att register */ |
| 3831 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3832 | writel(status, phba->CAregaddr); |
| 3833 | readl(phba->CAregaddr); /* flush */ |
| 3834 | } |
| 3835 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3836 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3837 | pring->stats.iocb_cmd_empty++; |
| 3838 | |
| 3839 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3840 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3841 | lpfc_sli_resume_iocb(phba, pring); |
| 3842 | |
| 3843 | if ((pring->lpfc_sli_cmd_available)) |
| 3844 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3845 | |
| 3846 | } |
| 3847 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3848 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3849 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3850 | } |
| 3851 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3852 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3853 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3854 | * @phba: Pointer to HBA context object. |
| 3855 | * @pring: Pointer to driver SLI ring object. |
| 3856 | * @mask: Host attention register mask for this ring. |
| 3857 | * |
| 3858 | * This function is called from the worker thread when there is a pending |
| 3859 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3860 | * queue. The caller does not hold any lock. The function will remove each |
| 3861 | * response iocb from the response worker queue and calls the handle |
| 3862 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3863 | **/ |
| 3864 | static void |
| 3865 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3866 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3867 | { |
| 3868 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3869 | struct hbq_dmabuf *dmabuf; |
| 3870 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3871 | unsigned long iflag; |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3872 | int count = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3873 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3874 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3875 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3876 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3877 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3878 | /* Get the response iocb from the head of work queue */ |
| 3879 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3880 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3881 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3882 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3883 | |
| 3884 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3885 | case CQE_CODE_COMPL_WQE: |
| 3886 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3887 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3888 | /* Translate ELS WCQE to response IOCBQ */ |
| 3889 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3890 | irspiocbq); |
| 3891 | if (irspiocbq) |
| 3892 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3893 | irspiocbq); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3894 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3895 | break; |
| 3896 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3897 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3898 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3899 | cq_event); |
| 3900 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3901 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3902 | break; |
| 3903 | default: |
| 3904 | break; |
| 3905 | } |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3906 | |
| 3907 | /* Limit the number of events to 64 to avoid soft lockups */ |
| 3908 | if (count == 64) |
| 3909 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3910 | } |
| 3911 | } |
| 3912 | |
| 3913 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3914 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3915 | * @phba: Pointer to HBA context object. |
| 3916 | * @pring: Pointer to driver SLI ring object. |
| 3917 | * |
| 3918 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3919 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3920 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3921 | * the return of this function. The caller is not required to hold any locks. |
| 3922 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3923 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3924 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3925 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3926 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3927 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3928 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3929 | if (pring->ringno == LPFC_ELS_RING) { |
| 3930 | lpfc_fabric_abort_hba(phba); |
| 3931 | } |
| 3932 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3933 | /* Error everything on txq and txcmplq |
| 3934 | * First do the txq. |
| 3935 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3936 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3937 | spin_lock_irq(&pring->ring_lock); |
| 3938 | list_splice_init(&pring->txq, &completions); |
| 3939 | pring->txq_cnt = 0; |
| 3940 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3941 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3942 | spin_lock_irq(&phba->hbalock); |
| 3943 | /* Next issue ABTS for everything on the txcmplq */ |
| 3944 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3945 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3946 | spin_unlock_irq(&phba->hbalock); |
| 3947 | } else { |
| 3948 | spin_lock_irq(&phba->hbalock); |
| 3949 | list_splice_init(&pring->txq, &completions); |
| 3950 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3951 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3952 | /* Next issue ABTS for everything on the txcmplq */ |
| 3953 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3954 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3955 | spin_unlock_irq(&phba->hbalock); |
| 3956 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3957 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3958 | /* Cancel all the IOCBs from the completions list */ |
| 3959 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3960 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3961 | } |
| 3962 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3963 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3964 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 3965 | * @phba: Pointer to HBA context object. |
| 3966 | * @pring: Pointer to driver SLI ring object. |
| 3967 | * |
| 3968 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 3969 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3970 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3971 | * the return of this function. The caller is not required to hold any locks. |
| 3972 | **/ |
| 3973 | void |
| 3974 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 3975 | { |
| 3976 | struct lpfc_sli *psli = &phba->sli; |
| 3977 | struct lpfc_sli_ring *pring; |
| 3978 | uint32_t i; |
| 3979 | |
| 3980 | /* Look on all the FCP Rings for the iotag */ |
| 3981 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 3982 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 3983 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3984 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3985 | } |
| 3986 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3987 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3988 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3989 | } |
| 3990 | } |
| 3991 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3992 | /** |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 3993 | * lpfc_sli_flush_io_rings - flush all iocbs in the IO ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3994 | * @phba: Pointer to HBA context object. |
| 3995 | * |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 3996 | * This function flushes all iocbs in the IO ring and frees all the iocb |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3997 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3998 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3999 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 4000 | * slot has been permanently disabled. |
| 4001 | **/ |
| 4002 | void |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4003 | lpfc_sli_flush_io_rings(struct lpfc_hba *phba) |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4004 | { |
| 4005 | LIST_HEAD(txq); |
| 4006 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4007 | struct lpfc_sli *psli = &phba->sli; |
| 4008 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4009 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4010 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4011 | |
| 4012 | spin_lock_irq(&phba->hbalock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4013 | /* Indicate the I/O queues are flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4014 | phba->hba_flag |= HBA_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4015 | spin_unlock_irq(&phba->hbalock); |
| 4016 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4017 | /* Look on all the FCP Rings for the iotag */ |
| 4018 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4019 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4020 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4021 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4022 | spin_lock_irq(&pring->ring_lock); |
| 4023 | /* Retrieve everything on txq */ |
| 4024 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4025 | list_for_each_entry_safe(piocb, next_iocb, |
| 4026 | &pring->txcmplq, list) |
| 4027 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4028 | /* Retrieve everything on the txcmplq */ |
| 4029 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4030 | pring->txq_cnt = 0; |
| 4031 | pring->txcmplq_cnt = 0; |
| 4032 | spin_unlock_irq(&pring->ring_lock); |
| 4033 | |
| 4034 | /* Flush the txq */ |
| 4035 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 4036 | IOSTAT_LOCAL_REJECT, |
| 4037 | IOERR_SLI_DOWN); |
| 4038 | /* Flush the txcmpq */ |
| 4039 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4040 | IOSTAT_LOCAL_REJECT, |
| 4041 | IOERR_SLI_DOWN); |
| 4042 | } |
| 4043 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4044 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4045 | |
| 4046 | spin_lock_irq(&phba->hbalock); |
| 4047 | /* Retrieve everything on txq */ |
| 4048 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4049 | list_for_each_entry_safe(piocb, next_iocb, |
| 4050 | &pring->txcmplq, list) |
| 4051 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4052 | /* Retrieve everything on the txcmplq */ |
| 4053 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4054 | pring->txq_cnt = 0; |
| 4055 | pring->txcmplq_cnt = 0; |
| 4056 | spin_unlock_irq(&phba->hbalock); |
| 4057 | |
| 4058 | /* Flush the txq */ |
| 4059 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 4060 | IOERR_SLI_DOWN); |
| 4061 | /* Flush the txcmpq */ |
| 4062 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 4063 | IOERR_SLI_DOWN); |
| 4064 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4068 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4069 | * @phba: Pointer to HBA context object. |
| 4070 | * @mask: Bit mask to be checked. |
| 4071 | * |
| 4072 | * This function reads the host status register and compares |
| 4073 | * with the provided bit mask to check if HBA completed |
| 4074 | * the restart. This function will wait in a loop for the |
| 4075 | * HBA to complete restart. If the HBA does not restart within |
| 4076 | * 15 iterations, the function will reset the HBA again. The |
| 4077 | * function returns 1 when HBA fail to restart otherwise returns |
| 4078 | * zero. |
| 4079 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4080 | static int |
| 4081 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4082 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4083 | uint32_t status; |
| 4084 | int i = 0; |
| 4085 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4086 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4087 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4088 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4089 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4090 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4091 | /* |
| 4092 | * Check status register every 100ms for 5 retries, then every |
| 4093 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 4094 | * every 2.5 sec for 4. |
| 4095 | * Break our of the loop if errors occurred during init. |
| 4096 | */ |
| 4097 | while (((status & mask) != mask) && |
| 4098 | !(status & HS_FFERM) && |
| 4099 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4100 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4101 | if (i <= 5) |
| 4102 | msleep(10); |
| 4103 | else if (i <= 10) |
| 4104 | msleep(500); |
| 4105 | else |
| 4106 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4107 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4108 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4109 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4110 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4111 | lpfc_sli_brdrestart(phba); |
| 4112 | } |
| 4113 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4114 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 4115 | retval = 1; |
| 4116 | break; |
| 4117 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4118 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4119 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4120 | /* Check to see if any errors occurred during init */ |
| 4121 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4122 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4123 | "2751 Adapter failed to restart, " |
| 4124 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 4125 | status, |
| 4126 | readl(phba->MBslimaddr + 0xa8), |
| 4127 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4128 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4129 | retval = 1; |
| 4130 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4131 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4132 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4133 | } |
| 4134 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4135 | /** |
| 4136 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 4137 | * @phba: Pointer to HBA context object. |
| 4138 | * @mask: Bit mask to be checked. |
| 4139 | * |
| 4140 | * This function checks the host status register to check if HBA is |
| 4141 | * ready. This function will wait in a loop for the HBA to be ready |
| 4142 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 4143 | * function again. The function returns 1 when HBA fail to be ready |
| 4144 | * otherwise returns zero. |
| 4145 | **/ |
| 4146 | static int |
| 4147 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 4148 | { |
| 4149 | uint32_t status; |
| 4150 | int retval = 0; |
| 4151 | |
| 4152 | /* Read the HBA Host Status Register */ |
| 4153 | status = lpfc_sli4_post_status_check(phba); |
| 4154 | |
| 4155 | if (status) { |
| 4156 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 4157 | lpfc_sli_brdrestart(phba); |
| 4158 | status = lpfc_sli4_post_status_check(phba); |
| 4159 | } |
| 4160 | |
| 4161 | /* Check to see if any errors occurred during init */ |
| 4162 | if (status) { |
| 4163 | phba->link_state = LPFC_HBA_ERROR; |
| 4164 | retval = 1; |
| 4165 | } else |
| 4166 | phba->sli4_hba.intr_enable = 0; |
| 4167 | |
| 4168 | return retval; |
| 4169 | } |
| 4170 | |
| 4171 | /** |
| 4172 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 4173 | * @phba: Pointer to HBA context object. |
| 4174 | * @mask: Bit mask to be checked. |
| 4175 | * |
| 4176 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 4177 | * from the API jump table function pointer from the lpfc_hba struct. |
| 4178 | **/ |
| 4179 | int |
| 4180 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 4181 | { |
| 4182 | return phba->lpfc_sli_brdready(phba, mask); |
| 4183 | } |
| 4184 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4185 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 4186 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4187 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4188 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4189 | * @phba: Pointer to HBA context object. |
| 4190 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 4191 | * This function is called before resetting an HBA. This function is called |
| 4192 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4193 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4194 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4195 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4196 | uint32_t __iomem *resp_buf; |
| 4197 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4198 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4199 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4200 | int i; |
| 4201 | uint8_t hdrtype; |
| 4202 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 4203 | lockdep_assert_held(&phba->hbalock); |
| 4204 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4205 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 4206 | if (hdrtype != 0x80 || |
| 4207 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 4208 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 4209 | return; |
| 4210 | |
| 4211 | /* |
| 4212 | * Tell the other part of the chip to suspend temporarily all |
| 4213 | * its DMA activity. |
| 4214 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4215 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4216 | |
| 4217 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4218 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 4219 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4220 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 4221 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4222 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4223 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4224 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4225 | return; |
| 4226 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4227 | /* Clear Chip error bit */ |
| 4228 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4229 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | mbox = 0; |
| 4233 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 4234 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 4235 | |
| 4236 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4237 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4238 | writel(mbox, mbox_buf); |
| 4239 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4240 | for (i = 0; i < 50; i++) { |
| 4241 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4242 | return; |
| 4243 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 4244 | mdelay(1); |
| 4245 | else |
| 4246 | break; |
| 4247 | } |
| 4248 | resp_data = 0; |
| 4249 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4250 | return; |
| 4251 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4252 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4253 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4254 | goto restore_hc; |
| 4255 | else |
| 4256 | goto clear_errat; |
| 4257 | } |
| 4258 | |
| 4259 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4260 | resp_data = 0; |
| 4261 | for (i = 0; i < 500; i++) { |
| 4262 | if (lpfc_readl(resp_buf, &resp_data)) |
| 4263 | return; |
| 4264 | if (resp_data != mbox) |
| 4265 | mdelay(1); |
| 4266 | else |
| 4267 | break; |
| 4268 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4269 | |
| 4270 | clear_errat: |
| 4271 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4272 | while (++i < 500) { |
| 4273 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4274 | return; |
| 4275 | if (!(ha_copy & HA_ERATT)) |
| 4276 | mdelay(1); |
| 4277 | else |
| 4278 | break; |
| 4279 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4280 | |
| 4281 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 4282 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4283 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4287 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4288 | writel(hc_copy, phba->HCregaddr); |
| 4289 | readl(phba->HCregaddr); /* flush */ |
| 4290 | } |
| 4291 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4292 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4293 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4294 | * @phba: Pointer to HBA context object. |
| 4295 | * |
| 4296 | * This function issues a kill_board mailbox command and waits for |
| 4297 | * the error attention interrupt. This function is called for stopping |
| 4298 | * the firmware processing. The caller is not required to hold any |
| 4299 | * locks. This function calls lpfc_hba_down_post function to free |
| 4300 | * any pending commands after the kill. The function will return 1 when it |
| 4301 | * fails to kill the board else will return 0. |
| 4302 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4303 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4304 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4305 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4306 | struct lpfc_sli *psli; |
| 4307 | LPFC_MBOXQ_t *pmb; |
| 4308 | uint32_t status; |
| 4309 | uint32_t ha_copy; |
| 4310 | int retval; |
| 4311 | int i = 0; |
| 4312 | |
| 4313 | psli = &phba->sli; |
| 4314 | |
| 4315 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4316 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4317 | "0329 Kill HBA Data: x%x x%x\n", |
| 4318 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4319 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4320 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4321 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4322 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4323 | |
| 4324 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4325 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4326 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 4327 | spin_unlock_irq(&phba->hbalock); |
| 4328 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4329 | return 1; |
| 4330 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4331 | status &= ~HC_ERINT_ENA; |
| 4332 | writel(status, phba->HCregaddr); |
| 4333 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4334 | phba->link_flag |= LS_IGNORE_ERATT; |
| 4335 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4336 | |
| 4337 | lpfc_kill_board(phba, pmb); |
| 4338 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4339 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4340 | |
| 4341 | if (retval != MBX_SUCCESS) { |
| 4342 | if (retval != MBX_BUSY) |
| 4343 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4344 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4345 | "2752 KILL_BOARD command failed retval %d\n", |
| 4346 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4347 | spin_lock_irq(&phba->hbalock); |
| 4348 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4349 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4350 | return 1; |
| 4351 | } |
| 4352 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4353 | spin_lock_irq(&phba->hbalock); |
| 4354 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 4355 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4356 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4357 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4358 | |
| 4359 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 4360 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 4361 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 4362 | * board is now undefined. |
| 4363 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4364 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4365 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4366 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 4367 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4368 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4369 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4373 | if (ha_copy & HA_ERATT) { |
| 4374 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4375 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4376 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4377 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4378 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4379 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4380 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4381 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4382 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4383 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4384 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4385 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4386 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4387 | } |
| 4388 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4389 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4390 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4391 | * @phba: Pointer to HBA context object. |
| 4392 | * |
| 4393 | * This function resets the HBA by writing HC_INITFF to the control |
| 4394 | * register. After the HBA resets, this function resets all the iocb ring |
| 4395 | * indices. This function disables PCI layer parity checking during |
| 4396 | * the reset. |
| 4397 | * This function returns 0 always. |
| 4398 | * The caller is not required to hold any locks. |
| 4399 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4400 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4401 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4402 | { |
| 4403 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4404 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4405 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4406 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4407 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4408 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4409 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4410 | /* Reset HBA */ |
| 4411 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4412 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4413 | (phba->pport) ? phba->pport->port_state : 0, |
| 4414 | psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4415 | |
| 4416 | /* perform board reset */ |
| 4417 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4418 | phba->link_events = 0; |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4419 | if (phba->pport) { |
| 4420 | phba->pport->fc_myDID = 0; |
| 4421 | phba->pport->fc_prevDID = 0; |
| 4422 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4423 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4424 | /* Turn off parity checking and serr during the physical reset */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 4425 | if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) |
| 4426 | return -EIO; |
| 4427 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4428 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4429 | (cfg_value & |
| 4430 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4431 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4432 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4433 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4434 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4435 | writel(HC_INITFF, phba->HCregaddr); |
| 4436 | mdelay(1); |
| 4437 | readl(phba->HCregaddr); /* flush */ |
| 4438 | writel(0, phba->HCregaddr); |
| 4439 | readl(phba->HCregaddr); /* flush */ |
| 4440 | |
| 4441 | /* Restore PCI cmd register */ |
| 4442 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4443 | |
| 4444 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4445 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4446 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4447 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4448 | pring->sli.sli3.rspidx = 0; |
| 4449 | pring->sli.sli3.next_cmdidx = 0; |
| 4450 | pring->sli.sli3.local_getidx = 0; |
| 4451 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4452 | pring->missbufcnt = 0; |
| 4453 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4454 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4455 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4456 | return 0; |
| 4457 | } |
| 4458 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4459 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4460 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4461 | * @phba: Pointer to HBA context object. |
| 4462 | * |
| 4463 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4464 | * checking during resets the device. The caller is not required to hold |
| 4465 | * any locks. |
| 4466 | * |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 4467 | * This function returns 0 on success else returns negative error code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4468 | **/ |
| 4469 | int |
| 4470 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4471 | { |
| 4472 | struct lpfc_sli *psli = &phba->sli; |
| 4473 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4474 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4475 | |
| 4476 | /* Reset HBA */ |
| 4477 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4478 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4479 | phba->pport->port_state, psli->sli_flag, |
| 4480 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4481 | |
| 4482 | /* perform board reset */ |
| 4483 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4484 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4485 | phba->pport->fc_myDID = 0; |
| 4486 | phba->pport->fc_prevDID = 0; |
| 4487 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4488 | spin_lock_irq(&phba->hbalock); |
| 4489 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4490 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4491 | spin_unlock_irq(&phba->hbalock); |
| 4492 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4493 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4494 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4495 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4496 | return rc; |
| 4497 | } |
| 4498 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4499 | /* Now physically reset the device */ |
| 4500 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4501 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4502 | |
| 4503 | /* Turn off parity checking and serr during the physical reset */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 4504 | if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) { |
| 4505 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4506 | "3205 PCI read Config failed\n"); |
| 4507 | return -EIO; |
| 4508 | } |
| 4509 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4510 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4511 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4512 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4513 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4514 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4515 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4516 | /* Restore PCI cmd register */ |
| 4517 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4518 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4519 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4520 | } |
| 4521 | |
| 4522 | /** |
| 4523 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4524 | * @phba: Pointer to HBA context object. |
| 4525 | * |
| 4526 | * This function is called in the SLI initialization code path to |
| 4527 | * restart the HBA. The caller is not required to hold any lock. |
| 4528 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4529 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4530 | * function to free any pending commands. The function enables |
| 4531 | * POST only during the first initialization. The function returns zero. |
| 4532 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4533 | * command before the return of this function. |
| 4534 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4535 | static int |
| 4536 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4537 | { |
| 4538 | MAILBOX_t *mb; |
| 4539 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4540 | volatile uint32_t word0; |
| 4541 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4542 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4543 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4544 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4545 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4546 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4547 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4548 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4549 | psli = &phba->sli; |
| 4550 | |
| 4551 | /* Restart HBA */ |
| 4552 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4553 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4554 | (phba->pport) ? phba->pport->port_state : 0, |
| 4555 | psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4556 | |
| 4557 | word0 = 0; |
| 4558 | mb = (MAILBOX_t *) &word0; |
| 4559 | mb->mbxCommand = MBX_RESTART; |
| 4560 | mb->mbxHc = 1; |
| 4561 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4562 | lpfc_reset_barrier(phba); |
| 4563 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4564 | to_slim = phba->MBslimaddr; |
| 4565 | writel(*(uint32_t *) mb, to_slim); |
| 4566 | readl(to_slim); /* flush */ |
| 4567 | |
| 4568 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4569 | if (phba->pport && phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4570 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4571 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4572 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4573 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4574 | writel(*(uint32_t *) mb, to_slim); |
| 4575 | readl(to_slim); /* flush */ |
| 4576 | |
| 4577 | lpfc_sli_brdreset(phba); |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4578 | if (phba->pport) |
| 4579 | phba->pport->stopped = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4580 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4581 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4582 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4583 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4584 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4585 | psli->stats_start = ktime_get_seconds(); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4586 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4587 | /* Give the INITFF and Post time to settle. */ |
| 4588 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4589 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4590 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4591 | if (hba_aer_enabled) |
| 4592 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4593 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4594 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4595 | |
| 4596 | return 0; |
| 4597 | } |
| 4598 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4599 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4600 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4601 | * @phba: Pointer to HBA context object. |
| 4602 | * |
| 4603 | * This function is called in the SLI initialization code path to restart |
| 4604 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4605 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4606 | * free any pending commands. |
| 4607 | **/ |
| 4608 | static int |
| 4609 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4610 | { |
| 4611 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4612 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4613 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4614 | |
| 4615 | /* Restart HBA */ |
| 4616 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4617 | "0296 Restart HBA Data: x%x x%x\n", |
| 4618 | phba->pport->port_state, psli->sli_flag); |
| 4619 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4620 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4621 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4622 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4623 | rc = lpfc_sli4_brdreset(phba); |
James Smart | 4fb86a6 | 2019-09-03 14:54:41 -0700 | [diff] [blame] | 4624 | if (rc) { |
| 4625 | phba->link_state = LPFC_HBA_ERROR; |
| 4626 | goto hba_down_queue; |
| 4627 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4628 | |
| 4629 | spin_lock_irq(&phba->hbalock); |
| 4630 | phba->pport->stopped = 0; |
| 4631 | phba->link_state = LPFC_INIT_START; |
| 4632 | phba->hba_flag = 0; |
| 4633 | spin_unlock_irq(&phba->hbalock); |
| 4634 | |
| 4635 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4636 | psli->stats_start = ktime_get_seconds(); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4637 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4638 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4639 | if (hba_aer_enabled) |
| 4640 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4641 | |
James Smart | 4fb86a6 | 2019-09-03 14:54:41 -0700 | [diff] [blame] | 4642 | hba_down_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4643 | lpfc_hba_down_post(phba); |
James Smart | 569dbe8 | 2017-06-15 22:56:47 -0700 | [diff] [blame] | 4644 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4645 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4646 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | /** |
| 4650 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4651 | * @phba: Pointer to HBA context object. |
| 4652 | * |
| 4653 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4654 | * API jump table function pointer from the lpfc_hba struct. |
| 4655 | **/ |
| 4656 | int |
| 4657 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4658 | { |
| 4659 | return phba->lpfc_sli_brdrestart(phba); |
| 4660 | } |
| 4661 | |
| 4662 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4663 | * 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] | 4664 | * @phba: Pointer to HBA context object. |
| 4665 | * |
| 4666 | * This function is called after a HBA restart to wait for successful |
| 4667 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4668 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4669 | * iteration, the function will restart the HBA again. The function returns |
| 4670 | * zero if HBA successfully restarted else returns negative error code. |
| 4671 | **/ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4672 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4673 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4674 | { |
| 4675 | uint32_t status, i = 0; |
| 4676 | |
| 4677 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4678 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4679 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4680 | |
| 4681 | /* Check status register to see what current state is */ |
| 4682 | i = 0; |
| 4683 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4684 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4685 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4686 | * retries, then every 1 sec for 50 retires for a total of |
| 4687 | * ~60 seconds before reset the board again and check every |
| 4688 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4689 | * board ready is required by the Falcon FIPS zeroization |
| 4690 | * complete, and any reset the board in between shall cause |
| 4691 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4692 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4693 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4694 | /* Adapter failed to init, timeout, status reg |
| 4695 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4696 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4697 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4698 | "timeout, status reg x%x, " |
| 4699 | "FW Data: A8 x%x AC x%x\n", status, |
| 4700 | readl(phba->MBslimaddr + 0xa8), |
| 4701 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4702 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4703 | return -ETIMEDOUT; |
| 4704 | } |
| 4705 | |
| 4706 | /* Check to see if any errors occurred during init */ |
| 4707 | if (status & HS_FFERM) { |
| 4708 | /* ERROR: During chipset initialization */ |
| 4709 | /* Adapter failed to init, chipset, status reg |
| 4710 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4711 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4712 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4713 | "chipset, status reg x%x, " |
| 4714 | "FW Data: A8 x%x AC x%x\n", status, |
| 4715 | readl(phba->MBslimaddr + 0xa8), |
| 4716 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4717 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4718 | return -EIO; |
| 4719 | } |
| 4720 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4721 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4722 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4723 | else if (i <= 100) |
| 4724 | msleep(100); |
| 4725 | else |
| 4726 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4727 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4728 | if (i == 150) { |
| 4729 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4730 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4731 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4732 | } |
| 4733 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4734 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4735 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | /* Check to see if any errors occurred during init */ |
| 4739 | if (status & HS_FFERM) { |
| 4740 | /* ERROR: During chipset initialization */ |
| 4741 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4742 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4743 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4744 | "status reg x%x, " |
| 4745 | "FW Data: A8 x%x AC x%x\n", status, |
| 4746 | readl(phba->MBslimaddr + 0xa8), |
| 4747 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4748 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4749 | return -EIO; |
| 4750 | } |
| 4751 | |
| 4752 | /* Clear all interrupt enable conditions */ |
| 4753 | writel(0, phba->HCregaddr); |
| 4754 | readl(phba->HCregaddr); /* flush */ |
| 4755 | |
| 4756 | /* setup host attn register */ |
| 4757 | writel(0xffffffff, phba->HAregaddr); |
| 4758 | readl(phba->HAregaddr); /* flush */ |
| 4759 | return 0; |
| 4760 | } |
| 4761 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4762 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4763 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4764 | * |
| 4765 | * This function calculates and returns the number of HBQs required to be |
| 4766 | * configured. |
| 4767 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4768 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4769 | lpfc_sli_hbq_count(void) |
| 4770 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4771 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4772 | } |
| 4773 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4774 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4775 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4776 | * |
| 4777 | * This function adds the number of hbq entries in every HBQ to get |
| 4778 | * the total number of hbq entries required for the HBA and returns |
| 4779 | * the total count. |
| 4780 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4781 | static int |
| 4782 | lpfc_sli_hbq_entry_count(void) |
| 4783 | { |
| 4784 | int hbq_count = lpfc_sli_hbq_count(); |
| 4785 | int count = 0; |
| 4786 | int i; |
| 4787 | |
| 4788 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4789 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4790 | return count; |
| 4791 | } |
| 4792 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4793 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4794 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4795 | * |
| 4796 | * This function calculates amount of memory required for all hbq entries |
| 4797 | * to be configured and returns the total memory required. |
| 4798 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4799 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4800 | lpfc_sli_hbq_size(void) |
| 4801 | { |
| 4802 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4803 | } |
| 4804 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4805 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4806 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4807 | * @phba: Pointer to HBA context object. |
| 4808 | * |
| 4809 | * This function is called during the SLI initialization to configure |
| 4810 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4811 | * required to hold any locks. This function will return zero if successful |
| 4812 | * else it will return negative error code. |
| 4813 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4814 | static int |
| 4815 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4816 | { |
| 4817 | int hbq_count = lpfc_sli_hbq_count(); |
| 4818 | LPFC_MBOXQ_t *pmb; |
| 4819 | MAILBOX_t *pmbox; |
| 4820 | uint32_t hbqno; |
| 4821 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4822 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4823 | /* Get a Mailbox buffer to setup mailbox |
| 4824 | * commands for HBA initialization |
| 4825 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4826 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4827 | |
| 4828 | if (!pmb) |
| 4829 | return -ENOMEM; |
| 4830 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4831 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4832 | |
| 4833 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4834 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4835 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4836 | |
| 4837 | hbq_entry_index = 0; |
| 4838 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4839 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4840 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4841 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4842 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4843 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4844 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4845 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4846 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4847 | |
| 4848 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4849 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4850 | mbxStatus <status>, ring <num> */ |
| 4851 | |
| 4852 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4853 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4854 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4855 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4856 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4857 | pmbox->mbxStatus, hbqno); |
| 4858 | |
| 4859 | phba->link_state = LPFC_HBA_ERROR; |
| 4860 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4861 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4862 | } |
| 4863 | } |
| 4864 | phba->hbq_count = hbq_count; |
| 4865 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4866 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4867 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4868 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4869 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4870 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4871 | return 0; |
| 4872 | } |
| 4873 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4874 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4875 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4876 | * @phba: Pointer to HBA context object. |
| 4877 | * |
| 4878 | * This function is called during the SLI initialization to configure |
| 4879 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4880 | * required to hold any locks. This function will return zero if successful |
| 4881 | * else it will return negative error code. |
| 4882 | **/ |
| 4883 | static int |
| 4884 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4885 | { |
| 4886 | phba->hbq_in_use = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4887 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 4888 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4889 | phba->hbq_count = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4890 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4891 | /* Initially populate or replenish the HBQs */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4892 | return 0; |
| 4893 | } |
| 4894 | |
| 4895 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4896 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4897 | * @phba: Pointer to HBA context object. |
| 4898 | * @sli_mode: sli mode - 2/3 |
| 4899 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4900 | * This function is called by the sli initialization code path |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4901 | * to issue config_port mailbox command. This function restarts the |
| 4902 | * HBA firmware and issues a config_port mailbox command to configure |
| 4903 | * the SLI interface in the sli mode specified by sli_mode |
| 4904 | * variable. The caller is not required to hold any locks. |
| 4905 | * The function returns 0 if successful, else returns negative error |
| 4906 | * code. |
| 4907 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4908 | int |
| 4909 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4910 | { |
| 4911 | LPFC_MBOXQ_t *pmb; |
| 4912 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4913 | |
| 4914 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4915 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4916 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4917 | return -ENOMEM; |
| 4918 | } |
| 4919 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4920 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4921 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4922 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4923 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4924 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4925 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4926 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4927 | rc = lpfc_sli_chipset_init(phba); |
| 4928 | if (rc) |
| 4929 | break; |
| 4930 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4931 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4932 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4933 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4934 | resetcount++; |
| 4935 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4936 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4937 | * value of 0 means the call was successful. Any other |
| 4938 | * nonzero value is a failure, but if ERESTART is returned, |
| 4939 | * the driver may reset the HBA and try again. |
| 4940 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4941 | rc = lpfc_config_port_prep(phba); |
| 4942 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4943 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4944 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4945 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4946 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4947 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4948 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4949 | lpfc_config_port(phba, pmb); |
| 4950 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4951 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4952 | LPFC_SLI3_HBQ_ENABLED | |
| 4953 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4954 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4955 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4956 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4957 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4958 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4959 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4960 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4961 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4962 | spin_unlock_irq(&phba->hbalock); |
| 4963 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4964 | } else { |
| 4965 | /* Allow asynchronous mailbox command to go through */ |
| 4966 | spin_lock_irq(&phba->hbalock); |
| 4967 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4968 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4969 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4970 | |
| 4971 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4972 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4973 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4974 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4975 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4976 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4977 | if (!done) { |
| 4978 | rc = -EINVAL; |
| 4979 | goto do_prep_failed; |
| 4980 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4981 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4982 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4983 | rc = -ENXIO; |
| 4984 | goto do_prep_failed; |
| 4985 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4986 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4987 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4988 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4989 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4990 | phba->max_vpi : phba->max_vports; |
| 4991 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4992 | } else |
| 4993 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4994 | phba->fips_level = 0; |
| 4995 | phba->fips_spec_rev = 0; |
| 4996 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4997 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4998 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4999 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 5000 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5001 | "2850 Security Crypto Active. FIPS x%d " |
| 5002 | "(Spec Rev: x%d)", |
| 5003 | phba->fips_level, phba->fips_spec_rev); |
| 5004 | } |
| 5005 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 5006 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5007 | "2856 Config Port Security Crypto " |
| 5008 | "Error: x%x ", |
| 5009 | pmb->u.mb.un.varCfgPort.sec_err); |
| 5010 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5011 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5012 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5013 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5014 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 5015 | |
| 5016 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 5017 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5018 | |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5019 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 5020 | if (pmb->u.mb.un.varCfgPort.gbg == 0) { |
| 5021 | phba->cfg_enable_bg = 0; |
| 5022 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5023 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5024 | "0443 Adapter did not grant " |
| 5025 | "BlockGuard\n"); |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5026 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5027 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5028 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 5029 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5030 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5031 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5032 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5033 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5034 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5035 | return rc; |
| 5036 | } |
| 5037 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5038 | |
| 5039 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5040 | * lpfc_sli_hba_setup - SLI initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5041 | * @phba: Pointer to HBA context object. |
| 5042 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5043 | * This function is the main SLI initialization function. This function |
| 5044 | * is called by the HBA initialization code, HBA reset code and HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5045 | * error attention handler code. Caller is not required to hold any |
| 5046 | * locks. This function issues config_port mailbox command to configure |
| 5047 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 5048 | * calls the config_port_post function to issue init_link mailbox |
| 5049 | * command and to start the discovery. The function will return zero |
| 5050 | * if successful, else it will return negative error code. |
| 5051 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5052 | int |
| 5053 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 5054 | { |
| 5055 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5056 | int mode = 3, i; |
| 5057 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5058 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5059 | switch (phba->cfg_sli_mode) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5060 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 5061 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5062 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5063 | "1824 NPIV enabled: Override sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5064 | "parameter (%d) to auto (0).\n", |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5065 | phba->cfg_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5066 | break; |
| 5067 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5068 | mode = 2; |
| 5069 | break; |
| 5070 | case 0: |
| 5071 | case 3: |
| 5072 | break; |
| 5073 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5074 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5075 | "1819 Unrecognized sli_mode parameter: %d.\n", |
| 5076 | phba->cfg_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5077 | |
| 5078 | break; |
| 5079 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 5080 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5081 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5082 | rc = lpfc_sli_config_port(phba, mode); |
| 5083 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5084 | if (rc && phba->cfg_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5085 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5086 | "1820 Unable to select SLI-3. " |
| 5087 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5088 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5089 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | 4597663f | 2016-07-06 12:36:01 -0700 | [diff] [blame] | 5090 | else if (rc && mode == 2) |
| 5091 | rc = lpfc_sli_config_port(phba, 3); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5092 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5093 | goto lpfc_sli_hba_setup_error; |
| 5094 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5095 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 5096 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 5097 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 5098 | if (!rc) { |
| 5099 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5100 | "2709 This device supports " |
| 5101 | "Advanced Error Reporting (AER)\n"); |
| 5102 | spin_lock_irq(&phba->hbalock); |
| 5103 | phba->hba_flag |= HBA_AER_ENABLED; |
| 5104 | spin_unlock_irq(&phba->hbalock); |
| 5105 | } else { |
| 5106 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5107 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 5108 | "Advanced Error Reporting (AER): %d\n", |
| 5109 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5110 | phba->cfg_aer_support = 0; |
| 5111 | } |
| 5112 | } |
| 5113 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5114 | if (phba->sli_rev == 3) { |
| 5115 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 5116 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5117 | } else { |
| 5118 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 5119 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5120 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5124 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 5125 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5126 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5127 | |
| 5128 | if (rc) |
| 5129 | goto lpfc_sli_hba_setup_error; |
| 5130 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5131 | /* Initialize VPIs. */ |
| 5132 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 5133 | /* |
| 5134 | * The VPI bitmask and physical ID array are allocated |
| 5135 | * and initialized once only - at driver load. A port |
| 5136 | * reset doesn't need to reinitialize this memory. |
| 5137 | */ |
| 5138 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 5139 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5140 | phba->vpi_bmask = kcalloc(longs, |
| 5141 | sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5142 | GFP_KERNEL); |
| 5143 | if (!phba->vpi_bmask) { |
| 5144 | rc = -ENOMEM; |
| 5145 | goto lpfc_sli_hba_setup_error; |
| 5146 | } |
| 5147 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5148 | phba->vpi_ids = kcalloc(phba->max_vpi + 1, |
| 5149 | sizeof(uint16_t), |
| 5150 | GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5151 | if (!phba->vpi_ids) { |
| 5152 | kfree(phba->vpi_bmask); |
| 5153 | rc = -ENOMEM; |
| 5154 | goto lpfc_sli_hba_setup_error; |
| 5155 | } |
| 5156 | for (i = 0; i < phba->max_vpi; i++) |
| 5157 | phba->vpi_ids[i] = i; |
| 5158 | } |
| 5159 | } |
| 5160 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5161 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5162 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 5163 | rc = lpfc_sli_hbq_setup(phba); |
| 5164 | if (rc) |
| 5165 | goto lpfc_sli_hba_setup_error; |
| 5166 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5167 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5168 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5169 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5170 | |
| 5171 | rc = lpfc_config_port_post(phba); |
| 5172 | if (rc) |
| 5173 | goto lpfc_sli_hba_setup_error; |
| 5174 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5175 | return rc; |
| 5176 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5177 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5178 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 5179 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5180 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5181 | return rc; |
| 5182 | } |
| 5183 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5184 | /** |
| 5185 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 5186 | * @phba: Pointer to HBA context object. |
| 5187 | * @mboxq: mailbox pointer. |
| 5188 | * This function issue a dump mailbox command to read config region |
| 5189 | * 23 and parse the records in the region and populate driver |
| 5190 | * data structure. |
| 5191 | **/ |
| 5192 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5193 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5194 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5195 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5196 | struct lpfc_dmabuf *mp; |
| 5197 | struct lpfc_mqe *mqe; |
| 5198 | uint32_t data_length; |
| 5199 | int rc; |
| 5200 | |
| 5201 | /* Program the default value of vlan_id and fc_map */ |
| 5202 | phba->valid_vlan = 0; |
| 5203 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5204 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5205 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5206 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5207 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5208 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5209 | return -ENOMEM; |
| 5210 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5211 | mqe = &mboxq->u.mqe; |
| 5212 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 5213 | rc = -ENOMEM; |
| 5214 | goto out_free_mboxq; |
| 5215 | } |
| 5216 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5217 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5218 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5219 | |
| 5220 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5221 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 5222 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5223 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5224 | "CQ: x%x x%x x%x x%x\n", |
| 5225 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5226 | bf_get(lpfc_mqe_command, mqe), |
| 5227 | bf_get(lpfc_mqe_status, mqe), |
| 5228 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 5229 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 5230 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 5231 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 5232 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 5233 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 5234 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 5235 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 5236 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 5237 | mboxq->mcqe.word0, |
| 5238 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 5239 | mboxq->mcqe.trailer); |
| 5240 | |
| 5241 | if (rc) { |
| 5242 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5243 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5244 | rc = -EIO; |
| 5245 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5246 | } |
| 5247 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 5248 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5249 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5250 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5251 | rc = -EIO; |
| 5252 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5253 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5254 | |
| 5255 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 5256 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5257 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5258 | rc = 0; |
| 5259 | |
| 5260 | out_free_mboxq: |
| 5261 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5262 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5263 | } |
| 5264 | |
| 5265 | /** |
| 5266 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 5267 | * @phba: pointer to lpfc hba data structure. |
| 5268 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 5269 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 5270 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 5271 | * On output, the number of data bytes in @vpd. |
| 5272 | * |
| 5273 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 5274 | * addition, this routine gets the port vpd data. |
| 5275 | * |
| 5276 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5277 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5278 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5279 | **/ |
| 5280 | static int |
| 5281 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 5282 | uint8_t *vpd, uint32_t *vpd_size) |
| 5283 | { |
| 5284 | int rc = 0; |
| 5285 | uint32_t dma_size; |
| 5286 | struct lpfc_dmabuf *dmabuf; |
| 5287 | struct lpfc_mqe *mqe; |
| 5288 | |
| 5289 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5290 | if (!dmabuf) |
| 5291 | return -ENOMEM; |
| 5292 | |
| 5293 | /* |
| 5294 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 5295 | * mailbox command. |
| 5296 | */ |
| 5297 | dma_size = *vpd_size; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 5298 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, dma_size, |
| 5299 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5300 | if (!dmabuf->virt) { |
| 5301 | kfree(dmabuf); |
| 5302 | return -ENOMEM; |
| 5303 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5304 | |
| 5305 | /* |
| 5306 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 5307 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 5308 | * in SLI3. This code corrects the conflicts. |
| 5309 | */ |
| 5310 | lpfc_read_rev(phba, mboxq); |
| 5311 | mqe = &mboxq->u.mqe; |
| 5312 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 5313 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 5314 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 5315 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 5316 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 5317 | |
| 5318 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5319 | if (rc) { |
| 5320 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5321 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 5322 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5323 | return -EIO; |
| 5324 | } |
| 5325 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5326 | /* |
| 5327 | * The available vpd length cannot be bigger than the |
| 5328 | * DMA buffer passed to the port. Catch the less than |
| 5329 | * case and update the caller's size. |
| 5330 | */ |
| 5331 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 5332 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 5333 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5334 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 5335 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5336 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5337 | dmabuf->virt, dmabuf->phys); |
| 5338 | kfree(dmabuf); |
| 5339 | return 0; |
| 5340 | } |
| 5341 | |
| 5342 | /** |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5343 | * lpfc_sli4_get_ctl_attr - Retrieve SLI4 device controller attributes |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5344 | * @phba: pointer to lpfc hba data structure. |
| 5345 | * |
| 5346 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5347 | * is attached to. |
| 5348 | * |
| 5349 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5350 | * 0 - successful |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5351 | * otherwise - failed to retrieve controller attributes |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5352 | **/ |
| 5353 | static int |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5354 | lpfc_sli4_get_ctl_attr(struct lpfc_hba *phba) |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5355 | { |
| 5356 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5357 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 5358 | struct lpfc_controller_attribute *cntl_attr; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5359 | void *virtaddr = NULL; |
| 5360 | uint32_t alloclen, reqlen; |
| 5361 | uint32_t shdr_status, shdr_add_status; |
| 5362 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5363 | int rc; |
| 5364 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5365 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5366 | if (!mboxq) |
| 5367 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5368 | |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5369 | /* Send COMMON_GET_CNTL_ATTRIBUTES mbox cmd */ |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5370 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 5371 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5372 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 5373 | LPFC_SLI4_MBX_NEMBED); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5374 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5375 | if (alloclen < reqlen) { |
| 5376 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5377 | "3084 Allocated DMA memory size (%d) is " |
| 5378 | "less than the requested DMA memory size " |
| 5379 | "(%d)\n", alloclen, reqlen); |
| 5380 | rc = -ENOMEM; |
| 5381 | goto out_free_mboxq; |
| 5382 | } |
| 5383 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5384 | virtaddr = mboxq->sge_array->addr[0]; |
| 5385 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5386 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5387 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5388 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5389 | if (shdr_status || shdr_add_status || rc) { |
| 5390 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5391 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5392 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5393 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5394 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5395 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5396 | rc, shdr_status, shdr_add_status); |
| 5397 | rc = -ENXIO; |
| 5398 | goto out_free_mboxq; |
| 5399 | } |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5400 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5401 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5402 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5403 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5404 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5405 | phba->sli4_hba.lnk_info.lnk_no = |
| 5406 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5407 | |
| 5408 | memset(phba->BIOSVersion, 0, sizeof(phba->BIOSVersion)); |
| 5409 | strlcat(phba->BIOSVersion, (char *)cntl_attr->bios_ver_str, |
| 5410 | sizeof(phba->BIOSVersion)); |
| 5411 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5412 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5413 | "3086 lnk_type:%d, lnk_numb:%d, bios_ver:%s\n", |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5414 | phba->sli4_hba.lnk_info.lnk_tp, |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5415 | phba->sli4_hba.lnk_info.lnk_no, |
| 5416 | phba->BIOSVersion); |
| 5417 | out_free_mboxq: |
| 5418 | if (rc != MBX_TIMEOUT) { |
| 5419 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5420 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5421 | else |
| 5422 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5423 | } |
| 5424 | return rc; |
| 5425 | } |
| 5426 | |
| 5427 | /** |
| 5428 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 5429 | * @phba: pointer to lpfc hba data structure. |
| 5430 | * |
| 5431 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5432 | * is attached to. |
| 5433 | * |
| 5434 | * Return codes |
| 5435 | * 0 - successful |
| 5436 | * otherwise - failed to retrieve physical port name |
| 5437 | **/ |
| 5438 | static int |
| 5439 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 5440 | { |
| 5441 | LPFC_MBOXQ_t *mboxq; |
| 5442 | struct lpfc_mbx_get_port_name *get_port_name; |
| 5443 | uint32_t shdr_status, shdr_add_status; |
| 5444 | union lpfc_sli4_cfg_shdr *shdr; |
| 5445 | char cport_name = 0; |
| 5446 | int rc; |
| 5447 | |
| 5448 | /* We assume nothing at this point */ |
| 5449 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5450 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 5451 | |
| 5452 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5453 | if (!mboxq) |
| 5454 | return -ENOMEM; |
| 5455 | /* obtain link type and link number via READ_CONFIG */ |
| 5456 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5457 | lpfc_sli4_read_config(phba); |
| 5458 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 5459 | goto retrieve_ppname; |
| 5460 | |
| 5461 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 5462 | rc = lpfc_sli4_get_ctl_attr(phba); |
| 5463 | if (rc) |
| 5464 | goto out_free_mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5465 | |
| 5466 | retrieve_ppname: |
| 5467 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5468 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5469 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5470 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5471 | LPFC_SLI4_MBX_EMBED); |
| 5472 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5473 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5474 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5475 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5476 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5477 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5478 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5479 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5480 | if (shdr_status || shdr_add_status || rc) { |
| 5481 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5482 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5483 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5484 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5485 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5486 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5487 | rc, shdr_status, shdr_add_status); |
| 5488 | rc = -ENXIO; |
| 5489 | goto out_free_mboxq; |
| 5490 | } |
| 5491 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5492 | case LPFC_LINK_NUMBER_0: |
| 5493 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5494 | &get_port_name->u.response); |
| 5495 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5496 | break; |
| 5497 | case LPFC_LINK_NUMBER_1: |
| 5498 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5499 | &get_port_name->u.response); |
| 5500 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5501 | break; |
| 5502 | case LPFC_LINK_NUMBER_2: |
| 5503 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5504 | &get_port_name->u.response); |
| 5505 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5506 | break; |
| 5507 | case LPFC_LINK_NUMBER_3: |
| 5508 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5509 | &get_port_name->u.response); |
| 5510 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5511 | break; |
| 5512 | default: |
| 5513 | break; |
| 5514 | } |
| 5515 | |
| 5516 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5517 | phba->Port[0] = cport_name; |
| 5518 | phba->Port[1] = '\0'; |
| 5519 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5520 | "3091 SLI get port name: %s\n", phba->Port); |
| 5521 | } |
| 5522 | |
| 5523 | out_free_mboxq: |
| 5524 | if (rc != MBX_TIMEOUT) { |
| 5525 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5526 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5527 | else |
| 5528 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5529 | } |
| 5530 | return rc; |
| 5531 | } |
| 5532 | |
| 5533 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5534 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5535 | * @phba: pointer to lpfc hba data structure. |
| 5536 | * |
| 5537 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5538 | * event queues |
| 5539 | **/ |
| 5540 | static void |
| 5541 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5542 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5543 | int qidx; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5544 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5545 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5546 | struct lpfc_queue *eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5547 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5548 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM); |
| 5549 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->els_cq, 0, LPFC_QUEUE_REARM); |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5550 | if (sli4_hba->nvmels_cq) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5551 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0, |
| 5552 | LPFC_QUEUE_REARM); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5553 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5554 | if (sli4_hba->hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5555 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5556 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5557 | qp = &sli4_hba->hdwq[qidx]; |
| 5558 | /* ARM the corresponding CQ */ |
James Smart | 01f2ef6 | 2019-08-28 16:19:11 -0700 | [diff] [blame] | 5559 | sli4_hba->sli4_write_cq_db(phba, qp->io_cq, 0, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 5560 | LPFC_QUEUE_REARM); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5561 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5562 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5563 | /* Loop thru all IRQ vectors */ |
| 5564 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 5565 | eq = sli4_hba->hba_eq_hdl[qidx].eq; |
| 5566 | /* ARM the corresponding EQ */ |
| 5567 | sli4_hba->sli4_write_eq_db(phba, eq, |
| 5568 | 0, LPFC_QUEUE_REARM); |
| 5569 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5570 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5571 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5572 | if (phba->nvmet_support) { |
| 5573 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5574 | sli4_hba->sli4_write_cq_db(phba, |
| 5575 | sli4_hba->nvmet_cqset[qidx], 0, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5576 | LPFC_QUEUE_REARM); |
| 5577 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5578 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5579 | } |
| 5580 | |
| 5581 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5582 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5583 | * @phba: Pointer to HBA context object. |
| 5584 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5585 | * @extnt_count: buffer to hold port available extent count. |
| 5586 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5587 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5588 | * This function calls the port and retrievs the number of available |
| 5589 | * extents and their size for a particular extent type. |
| 5590 | * |
| 5591 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5592 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5593 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5594 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5595 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5596 | { |
| 5597 | int rc = 0; |
| 5598 | uint32_t length; |
| 5599 | uint32_t mbox_tmo; |
| 5600 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5601 | LPFC_MBOXQ_t *mbox; |
| 5602 | |
| 5603 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5604 | if (!mbox) |
| 5605 | return -ENOMEM; |
| 5606 | |
| 5607 | /* Find out how many extents are available for this resource type */ |
| 5608 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5609 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5610 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5611 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5612 | length, LPFC_SLI4_MBX_EMBED); |
| 5613 | |
| 5614 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5615 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5616 | LPFC_SLI4_MBX_EMBED); |
| 5617 | if (unlikely(rc)) { |
| 5618 | rc = -EIO; |
| 5619 | goto err_exit; |
| 5620 | } |
| 5621 | |
| 5622 | if (!phba->sli4_hba.intr_enable) |
| 5623 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5624 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5625 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5626 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5627 | } |
| 5628 | if (unlikely(rc)) { |
| 5629 | rc = -EIO; |
| 5630 | goto err_exit; |
| 5631 | } |
| 5632 | |
| 5633 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5634 | if (bf_get(lpfc_mbox_hdr_status, |
| 5635 | &rsrc_info->header.cfg_shdr.response)) { |
| 5636 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5637 | "2930 Failed to get resource extents " |
| 5638 | "Status 0x%x Add'l Status 0x%x\n", |
| 5639 | bf_get(lpfc_mbox_hdr_status, |
| 5640 | &rsrc_info->header.cfg_shdr.response), |
| 5641 | bf_get(lpfc_mbox_hdr_add_status, |
| 5642 | &rsrc_info->header.cfg_shdr.response)); |
| 5643 | rc = -EIO; |
| 5644 | goto err_exit; |
| 5645 | } |
| 5646 | |
| 5647 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5648 | &rsrc_info->u.rsp); |
| 5649 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5650 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5651 | |
| 5652 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5653 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5654 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5655 | |
| 5656 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5657 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5658 | return rc; |
| 5659 | } |
| 5660 | |
| 5661 | /** |
| 5662 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5663 | * @phba: Pointer to HBA context object. |
| 5664 | * @type: The extent type to check. |
| 5665 | * |
| 5666 | * This function reads the current available extents from the port and checks |
| 5667 | * if the extent count or extent size has changed since the last access. |
| 5668 | * Callers use this routine post port reset to understand if there is a |
| 5669 | * extent reprovisioning requirement. |
| 5670 | * |
| 5671 | * Returns: |
| 5672 | * -Error: error indicates problem. |
| 5673 | * 1: Extent count or size has changed. |
| 5674 | * 0: No changes. |
| 5675 | **/ |
| 5676 | static int |
| 5677 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5678 | { |
| 5679 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5680 | uint16_t size_diff, rsrc_ext_size; |
| 5681 | int rc = 0; |
| 5682 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5683 | struct list_head *rsrc_blk_list = NULL; |
| 5684 | |
| 5685 | size_diff = 0; |
| 5686 | curr_ext_cnt = 0; |
| 5687 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5688 | &rsrc_ext_cnt, |
| 5689 | &rsrc_ext_size); |
| 5690 | if (unlikely(rc)) |
| 5691 | return -EIO; |
| 5692 | |
| 5693 | switch (type) { |
| 5694 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5695 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5696 | break; |
| 5697 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5698 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5699 | break; |
| 5700 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5701 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5702 | break; |
| 5703 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5704 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5705 | break; |
| 5706 | default: |
| 5707 | break; |
| 5708 | } |
| 5709 | |
| 5710 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5711 | curr_ext_cnt++; |
| 5712 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5713 | size_diff++; |
| 5714 | } |
| 5715 | |
| 5716 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5717 | rc = 1; |
| 5718 | |
| 5719 | return rc; |
| 5720 | } |
| 5721 | |
| 5722 | /** |
| 5723 | * lpfc_sli4_cfg_post_extnts - |
| 5724 | * @phba: Pointer to HBA context object. |
| 5725 | * @extnt_cnt - number of available extents. |
| 5726 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5727 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5728 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5729 | * |
| 5730 | * This function executes the extents allocation request. It also |
| 5731 | * takes care of the amount of memory needed to allocate or get the |
| 5732 | * allocated extents. It is the caller's responsibility to evaluate |
| 5733 | * the response. |
| 5734 | * |
| 5735 | * Returns: |
| 5736 | * -Error: Error value describes the condition found. |
| 5737 | * 0: if successful |
| 5738 | **/ |
| 5739 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5740 | 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] | 5741 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5742 | { |
| 5743 | int rc = 0; |
| 5744 | uint32_t req_len; |
| 5745 | uint32_t emb_len; |
| 5746 | uint32_t alloc_len, mbox_tmo; |
| 5747 | |
| 5748 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5749 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5750 | |
| 5751 | /* |
| 5752 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5753 | * accounts for extents-specific word. |
| 5754 | */ |
| 5755 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5756 | sizeof(uint32_t); |
| 5757 | |
| 5758 | /* |
| 5759 | * Presume the allocation and response will fit into an embedded |
| 5760 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5761 | */ |
| 5762 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5763 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5764 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5765 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5766 | sizeof(uint32_t); |
| 5767 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5768 | } |
| 5769 | |
| 5770 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5771 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5772 | req_len, *emb); |
| 5773 | if (alloc_len < req_len) { |
| 5774 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5775 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5776 | "less than the requested DMA memory " |
| 5777 | "size (x%x)\n", alloc_len, req_len); |
| 5778 | return -ENOMEM; |
| 5779 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5780 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5781 | if (unlikely(rc)) |
| 5782 | return -EIO; |
| 5783 | |
| 5784 | if (!phba->sli4_hba.intr_enable) |
| 5785 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5786 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5787 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5788 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5789 | } |
| 5790 | |
| 5791 | if (unlikely(rc)) |
| 5792 | rc = -EIO; |
| 5793 | return rc; |
| 5794 | } |
| 5795 | |
| 5796 | /** |
| 5797 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5798 | * @phba: Pointer to HBA context object. |
| 5799 | * @type: The resource extent type to allocate. |
| 5800 | * |
| 5801 | * This function allocates the number of elements for the specified |
| 5802 | * resource type. |
| 5803 | **/ |
| 5804 | static int |
| 5805 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5806 | { |
| 5807 | bool emb = false; |
| 5808 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5809 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5810 | uint16_t *ids; |
| 5811 | int i, rc; |
| 5812 | unsigned long longs; |
| 5813 | unsigned long *bmask; |
| 5814 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5815 | LPFC_MBOXQ_t *mbox; |
| 5816 | uint32_t length; |
| 5817 | struct lpfc_id_range *id_array = NULL; |
| 5818 | void *virtaddr = NULL; |
| 5819 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5820 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5821 | struct list_head *ext_blk_list; |
| 5822 | |
| 5823 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5824 | &rsrc_cnt, |
| 5825 | &rsrc_size); |
| 5826 | if (unlikely(rc)) |
| 5827 | return -EIO; |
| 5828 | |
| 5829 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5830 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5831 | "3009 No available Resource Extents " |
| 5832 | "for resource type 0x%x: Count: 0x%x, " |
| 5833 | "Size 0x%x\n", type, rsrc_cnt, |
| 5834 | rsrc_size); |
| 5835 | return -ENOMEM; |
| 5836 | } |
| 5837 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5838 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5839 | "2903 Post resource extents type-0x%x: " |
| 5840 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5841 | |
| 5842 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5843 | if (!mbox) |
| 5844 | return -ENOMEM; |
| 5845 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5846 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5847 | if (unlikely(rc)) { |
| 5848 | rc = -EIO; |
| 5849 | goto err_exit; |
| 5850 | } |
| 5851 | |
| 5852 | /* |
| 5853 | * Figure out where the response is located. Then get local pointers |
| 5854 | * to the response data. The port does not guarantee to respond to |
| 5855 | * all extents counts request so update the local variable with the |
| 5856 | * allocated count from the port. |
| 5857 | */ |
| 5858 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5859 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5860 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5861 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5862 | } else { |
| 5863 | virtaddr = mbox->sge_array->addr[0]; |
| 5864 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5865 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5866 | id_array = &n_rsrc->id; |
| 5867 | } |
| 5868 | |
| 5869 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5870 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5871 | |
| 5872 | /* |
| 5873 | * Based on the resource size and count, correct the base and max |
| 5874 | * resource values. |
| 5875 | */ |
| 5876 | length = sizeof(struct lpfc_rsrc_blks); |
| 5877 | switch (type) { |
| 5878 | case LPFC_RSC_TYPE_FCOE_RPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5879 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5880 | sizeof(unsigned long), |
| 5881 | GFP_KERNEL); |
| 5882 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5883 | rc = -ENOMEM; |
| 5884 | goto err_exit; |
| 5885 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5886 | phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5887 | sizeof(uint16_t), |
| 5888 | GFP_KERNEL); |
| 5889 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5890 | kfree(phba->sli4_hba.rpi_bmask); |
| 5891 | rc = -ENOMEM; |
| 5892 | goto err_exit; |
| 5893 | } |
| 5894 | |
| 5895 | /* |
| 5896 | * The next_rpi was initialized with the maximum available |
| 5897 | * count but the port may allocate a smaller number. Catch |
| 5898 | * that case and update the next_rpi. |
| 5899 | */ |
| 5900 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5901 | |
| 5902 | /* Initialize local ptrs for common extent processing later. */ |
| 5903 | bmask = phba->sli4_hba.rpi_bmask; |
| 5904 | ids = phba->sli4_hba.rpi_ids; |
| 5905 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5906 | break; |
| 5907 | case LPFC_RSC_TYPE_FCOE_VPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5908 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5909 | GFP_KERNEL); |
| 5910 | if (unlikely(!phba->vpi_bmask)) { |
| 5911 | rc = -ENOMEM; |
| 5912 | goto err_exit; |
| 5913 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5914 | phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5915 | GFP_KERNEL); |
| 5916 | if (unlikely(!phba->vpi_ids)) { |
| 5917 | kfree(phba->vpi_bmask); |
| 5918 | rc = -ENOMEM; |
| 5919 | goto err_exit; |
| 5920 | } |
| 5921 | |
| 5922 | /* Initialize local ptrs for common extent processing later. */ |
| 5923 | bmask = phba->vpi_bmask; |
| 5924 | ids = phba->vpi_ids; |
| 5925 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5926 | break; |
| 5927 | case LPFC_RSC_TYPE_FCOE_XRI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5928 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5929 | sizeof(unsigned long), |
| 5930 | GFP_KERNEL); |
| 5931 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5932 | rc = -ENOMEM; |
| 5933 | goto err_exit; |
| 5934 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5935 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5936 | phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5937 | sizeof(uint16_t), |
| 5938 | GFP_KERNEL); |
| 5939 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5940 | kfree(phba->sli4_hba.xri_bmask); |
| 5941 | rc = -ENOMEM; |
| 5942 | goto err_exit; |
| 5943 | } |
| 5944 | |
| 5945 | /* Initialize local ptrs for common extent processing later. */ |
| 5946 | bmask = phba->sli4_hba.xri_bmask; |
| 5947 | ids = phba->sli4_hba.xri_ids; |
| 5948 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5949 | break; |
| 5950 | case LPFC_RSC_TYPE_FCOE_VFI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5951 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5952 | sizeof(unsigned long), |
| 5953 | GFP_KERNEL); |
| 5954 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5955 | rc = -ENOMEM; |
| 5956 | goto err_exit; |
| 5957 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5958 | phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5959 | sizeof(uint16_t), |
| 5960 | GFP_KERNEL); |
| 5961 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5962 | kfree(phba->sli4_hba.vfi_bmask); |
| 5963 | rc = -ENOMEM; |
| 5964 | goto err_exit; |
| 5965 | } |
| 5966 | |
| 5967 | /* Initialize local ptrs for common extent processing later. */ |
| 5968 | bmask = phba->sli4_hba.vfi_bmask; |
| 5969 | ids = phba->sli4_hba.vfi_ids; |
| 5970 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5971 | break; |
| 5972 | default: |
| 5973 | /* Unsupported Opcode. Fail call. */ |
| 5974 | id_array = NULL; |
| 5975 | bmask = NULL; |
| 5976 | ids = NULL; |
| 5977 | ext_blk_list = NULL; |
| 5978 | goto err_exit; |
| 5979 | } |
| 5980 | |
| 5981 | /* |
| 5982 | * Complete initializing the extent configuration with the |
| 5983 | * allocated ids assigned to this function. The bitmask serves |
| 5984 | * as an index into the array and manages the available ids. The |
| 5985 | * array just stores the ids communicated to the port via the wqes. |
| 5986 | */ |
| 5987 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5988 | if ((i % 2) == 0) |
| 5989 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5990 | &id_array[k]); |
| 5991 | else |
| 5992 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5993 | &id_array[k]); |
| 5994 | |
| 5995 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5996 | if (unlikely(!rsrc_blks)) { |
| 5997 | rc = -ENOMEM; |
| 5998 | kfree(bmask); |
| 5999 | kfree(ids); |
| 6000 | goto err_exit; |
| 6001 | } |
| 6002 | rsrc_blks->rsrc_start = rsrc_id; |
| 6003 | rsrc_blks->rsrc_size = rsrc_size; |
| 6004 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 6005 | rsrc_start = rsrc_id; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6006 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6007 | phba->sli4_hba.io_xri_start = rsrc_start + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6008 | lpfc_sli4_get_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6009 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6010 | |
| 6011 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 6012 | ids[j] = rsrc_id; |
| 6013 | rsrc_id++; |
| 6014 | j++; |
| 6015 | } |
| 6016 | /* Entire word processed. Get next word.*/ |
| 6017 | if ((i % 2) == 1) |
| 6018 | k++; |
| 6019 | } |
| 6020 | err_exit: |
| 6021 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6022 | return rc; |
| 6023 | } |
| 6024 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6025 | |
| 6026 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6027 | /** |
| 6028 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 6029 | * @phba: Pointer to HBA context object. |
| 6030 | * @type: the extent's type. |
| 6031 | * |
| 6032 | * This function deallocates all extents of a particular resource type. |
| 6033 | * SLI4 does not allow for deallocating a particular extent range. It |
| 6034 | * is the caller's responsibility to release all kernel memory resources. |
| 6035 | **/ |
| 6036 | static int |
| 6037 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 6038 | { |
| 6039 | int rc; |
| 6040 | uint32_t length, mbox_tmo = 0; |
| 6041 | LPFC_MBOXQ_t *mbox; |
| 6042 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 6043 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 6044 | |
| 6045 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6046 | if (!mbox) |
| 6047 | return -ENOMEM; |
| 6048 | |
| 6049 | /* |
| 6050 | * This function sends an embedded mailbox because it only sends the |
| 6051 | * the resource type. All extents of this type are released by the |
| 6052 | * port. |
| 6053 | */ |
| 6054 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 6055 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6056 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6057 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 6058 | length, LPFC_SLI4_MBX_EMBED); |
| 6059 | |
| 6060 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 6061 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 6062 | LPFC_SLI4_MBX_EMBED); |
| 6063 | if (unlikely(rc)) { |
| 6064 | rc = -EIO; |
| 6065 | goto out_free_mbox; |
| 6066 | } |
| 6067 | if (!phba->sli4_hba.intr_enable) |
| 6068 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6069 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6070 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6071 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6072 | } |
| 6073 | if (unlikely(rc)) { |
| 6074 | rc = -EIO; |
| 6075 | goto out_free_mbox; |
| 6076 | } |
| 6077 | |
| 6078 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 6079 | if (bf_get(lpfc_mbox_hdr_status, |
| 6080 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 6081 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6082 | "2919 Failed to release resource extents " |
| 6083 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 6084 | "Resource memory not released.\n", |
| 6085 | type, |
| 6086 | bf_get(lpfc_mbox_hdr_status, |
| 6087 | &dealloc_rsrc->header.cfg_shdr.response), |
| 6088 | bf_get(lpfc_mbox_hdr_add_status, |
| 6089 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 6090 | rc = -EIO; |
| 6091 | goto out_free_mbox; |
| 6092 | } |
| 6093 | |
| 6094 | /* Release kernel memory resources for the specific type. */ |
| 6095 | switch (type) { |
| 6096 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6097 | kfree(phba->vpi_bmask); |
| 6098 | kfree(phba->vpi_ids); |
| 6099 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6100 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6101 | &phba->lpfc_vpi_blk_list, list) { |
| 6102 | list_del_init(&rsrc_blk->list); |
| 6103 | kfree(rsrc_blk); |
| 6104 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6105 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6106 | break; |
| 6107 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6108 | kfree(phba->sli4_hba.xri_bmask); |
| 6109 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6110 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6111 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 6112 | list_del_init(&rsrc_blk->list); |
| 6113 | kfree(rsrc_blk); |
| 6114 | } |
| 6115 | break; |
| 6116 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6117 | kfree(phba->sli4_hba.vfi_bmask); |
| 6118 | kfree(phba->sli4_hba.vfi_ids); |
| 6119 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6120 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6121 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 6122 | list_del_init(&rsrc_blk->list); |
| 6123 | kfree(rsrc_blk); |
| 6124 | } |
| 6125 | break; |
| 6126 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6127 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 6128 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6129 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 6130 | list_del_init(&rsrc_blk->list); |
| 6131 | kfree(rsrc_blk); |
| 6132 | } |
| 6133 | break; |
| 6134 | default: |
| 6135 | break; |
| 6136 | } |
| 6137 | |
| 6138 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6139 | |
| 6140 | out_free_mbox: |
| 6141 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6142 | return rc; |
| 6143 | } |
| 6144 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 6145 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6146 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 6147 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6148 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6149 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6150 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6151 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 6152 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6153 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6154 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 6155 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6156 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6157 | switch (feature) { |
| 6158 | case LPFC_SET_UE_RECOVERY: |
| 6159 | bf_set(lpfc_mbx_set_feature_UER, |
| 6160 | &mbox->u.mqe.un.set_feature, 1); |
| 6161 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 6162 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6163 | break; |
| 6164 | case LPFC_SET_MDS_DIAGS: |
| 6165 | bf_set(lpfc_mbx_set_feature_mds, |
| 6166 | &mbox->u.mqe.un.set_feature, 1); |
| 6167 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 6168 | &mbox->u.mqe.un.set_feature, 1); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6169 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 6170 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6171 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6172 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6173 | |
| 6174 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6175 | } |
| 6176 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6177 | /** |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6178 | * lpfc_ras_stop_fwlog: Disable FW logging by the adapter |
| 6179 | * @phba: Pointer to HBA context object. |
| 6180 | * |
| 6181 | * Disable FW logging into host memory on the adapter. To |
| 6182 | * be done before reading logs from the host memory. |
| 6183 | **/ |
| 6184 | void |
| 6185 | lpfc_ras_stop_fwlog(struct lpfc_hba *phba) |
| 6186 | { |
| 6187 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6188 | |
| 6189 | ras_fwlog->ras_active = false; |
| 6190 | |
| 6191 | /* Disable FW logging to host memory */ |
| 6192 | writel(LPFC_CTL_PDEV_CTL_DDL_RAS, |
| 6193 | phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET); |
| 6194 | } |
| 6195 | |
| 6196 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6197 | * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging. |
| 6198 | * @phba: Pointer to HBA context object. |
| 6199 | * |
| 6200 | * This function is called to free memory allocated for RAS FW logging |
| 6201 | * support in the driver. |
| 6202 | **/ |
| 6203 | void |
| 6204 | lpfc_sli4_ras_dma_free(struct lpfc_hba *phba) |
| 6205 | { |
| 6206 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6207 | struct lpfc_dmabuf *dmabuf, *next; |
| 6208 | |
| 6209 | if (!list_empty(&ras_fwlog->fwlog_buff_list)) { |
| 6210 | list_for_each_entry_safe(dmabuf, next, |
| 6211 | &ras_fwlog->fwlog_buff_list, |
| 6212 | list) { |
| 6213 | list_del(&dmabuf->list); |
| 6214 | dma_free_coherent(&phba->pcidev->dev, |
| 6215 | LPFC_RAS_MAX_ENTRY_SIZE, |
| 6216 | dmabuf->virt, dmabuf->phys); |
| 6217 | kfree(dmabuf); |
| 6218 | } |
| 6219 | } |
| 6220 | |
| 6221 | if (ras_fwlog->lwpd.virt) { |
| 6222 | dma_free_coherent(&phba->pcidev->dev, |
| 6223 | sizeof(uint32_t) * 2, |
| 6224 | ras_fwlog->lwpd.virt, |
| 6225 | ras_fwlog->lwpd.phys); |
| 6226 | ras_fwlog->lwpd.virt = NULL; |
| 6227 | } |
| 6228 | |
| 6229 | ras_fwlog->ras_active = false; |
| 6230 | } |
| 6231 | |
| 6232 | /** |
| 6233 | * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support |
| 6234 | * @phba: Pointer to HBA context object. |
| 6235 | * @fwlog_buff_count: Count of buffers to be created. |
| 6236 | * |
| 6237 | * This routine DMA memory for Log Write Position Data[LPWD] and buffer |
| 6238 | * to update FW log is posted to the adapter. |
| 6239 | * Buffer count is calculated based on module param ras_fwlog_buffsize |
| 6240 | * Size of each buffer posted to FW is 64K. |
| 6241 | **/ |
| 6242 | |
| 6243 | static int |
| 6244 | lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba, |
| 6245 | uint32_t fwlog_buff_count) |
| 6246 | { |
| 6247 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6248 | struct lpfc_dmabuf *dmabuf; |
| 6249 | int rc = 0, i = 0; |
| 6250 | |
| 6251 | /* Initialize List */ |
| 6252 | INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list); |
| 6253 | |
| 6254 | /* Allocate memory for the LWPD */ |
| 6255 | ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6256 | sizeof(uint32_t) * 2, |
| 6257 | &ras_fwlog->lwpd.phys, |
| 6258 | GFP_KERNEL); |
| 6259 | if (!ras_fwlog->lwpd.virt) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6260 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6261 | "6185 LWPD Memory Alloc Failed\n"); |
| 6262 | |
| 6263 | return -ENOMEM; |
| 6264 | } |
| 6265 | |
| 6266 | ras_fwlog->fw_buffcount = fwlog_buff_count; |
| 6267 | for (i = 0; i < ras_fwlog->fw_buffcount; i++) { |
| 6268 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 6269 | GFP_KERNEL); |
| 6270 | if (!dmabuf) { |
| 6271 | rc = -ENOMEM; |
| 6272 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6273 | "6186 Memory Alloc failed FW logging"); |
| 6274 | goto free_mem; |
| 6275 | } |
| 6276 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6277 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6278 | LPFC_RAS_MAX_ENTRY_SIZE, |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6279 | &dmabuf->phys, GFP_KERNEL); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6280 | if (!dmabuf->virt) { |
| 6281 | kfree(dmabuf); |
| 6282 | rc = -ENOMEM; |
| 6283 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6284 | "6187 DMA Alloc Failed FW logging"); |
| 6285 | goto free_mem; |
| 6286 | } |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6287 | dmabuf->buffer_tag = i; |
| 6288 | list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list); |
| 6289 | } |
| 6290 | |
| 6291 | free_mem: |
| 6292 | if (rc) |
| 6293 | lpfc_sli4_ras_dma_free(phba); |
| 6294 | |
| 6295 | return rc; |
| 6296 | } |
| 6297 | |
| 6298 | /** |
| 6299 | * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command |
| 6300 | * @phba: pointer to lpfc hba data structure. |
| 6301 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 6302 | * |
| 6303 | * Completion handler for driver's RAS MBX command to the device. |
| 6304 | **/ |
| 6305 | static void |
| 6306 | lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6307 | { |
| 6308 | MAILBOX_t *mb; |
| 6309 | union lpfc_sli4_cfg_shdr *shdr; |
| 6310 | uint32_t shdr_status, shdr_add_status; |
| 6311 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6312 | |
| 6313 | mb = &pmb->u.mb; |
| 6314 | |
| 6315 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6316 | &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr; |
| 6317 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6318 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6319 | |
| 6320 | if (mb->mbxStatus != MBX_SUCCESS || shdr_status) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6321 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6322 | "6188 FW LOG mailbox " |
| 6323 | "completed with status x%x add_status x%x," |
| 6324 | " mbx status x%x\n", |
| 6325 | shdr_status, shdr_add_status, mb->mbxStatus); |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6326 | |
| 6327 | ras_fwlog->ras_hwsupport = false; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6328 | goto disable_ras; |
| 6329 | } |
| 6330 | |
| 6331 | ras_fwlog->ras_active = true; |
| 6332 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6333 | |
| 6334 | return; |
| 6335 | |
| 6336 | disable_ras: |
| 6337 | /* Free RAS DMA memory */ |
| 6338 | lpfc_sli4_ras_dma_free(phba); |
| 6339 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6340 | } |
| 6341 | |
| 6342 | /** |
| 6343 | * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command |
| 6344 | * @phba: pointer to lpfc hba data structure. |
| 6345 | * @fwlog_level: Logging verbosity level. |
| 6346 | * @fwlog_enable: Enable/Disable logging. |
| 6347 | * |
| 6348 | * Initialize memory and post mailbox command to enable FW logging in host |
| 6349 | * memory. |
| 6350 | **/ |
| 6351 | int |
| 6352 | lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba, |
| 6353 | uint32_t fwlog_level, |
| 6354 | uint32_t fwlog_enable) |
| 6355 | { |
| 6356 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6357 | struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL; |
| 6358 | struct lpfc_dmabuf *dmabuf; |
| 6359 | LPFC_MBOXQ_t *mbox; |
| 6360 | uint32_t len = 0, fwlog_buffsize, fwlog_entry_count; |
| 6361 | int rc = 0; |
| 6362 | |
| 6363 | fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE * |
| 6364 | phba->cfg_ras_fwlog_buffsize); |
| 6365 | fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE); |
| 6366 | |
| 6367 | /* |
| 6368 | * If re-enabling FW logging support use earlier allocated |
| 6369 | * DMA buffers while posting MBX command. |
| 6370 | **/ |
| 6371 | if (!ras_fwlog->lwpd.virt) { |
| 6372 | rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count); |
| 6373 | if (rc) { |
| 6374 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6375 | "6189 FW Log Memory Allocation Failed"); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6376 | return rc; |
| 6377 | } |
| 6378 | } |
| 6379 | |
| 6380 | /* Setup Mailbox command */ |
| 6381 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6382 | if (!mbox) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6383 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6384 | "6190 RAS MBX Alloc Failed"); |
| 6385 | rc = -ENOMEM; |
| 6386 | goto mem_free; |
| 6387 | } |
| 6388 | |
| 6389 | ras_fwlog->fw_loglevel = fwlog_level; |
| 6390 | len = (sizeof(struct lpfc_mbx_set_ras_fwlog) - |
| 6391 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6392 | |
| 6393 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL, |
| 6394 | LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION, |
| 6395 | len, LPFC_SLI4_MBX_EMBED); |
| 6396 | |
| 6397 | mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog; |
| 6398 | bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request, |
| 6399 | fwlog_enable); |
| 6400 | bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request, |
| 6401 | ras_fwlog->fw_loglevel); |
| 6402 | bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request, |
| 6403 | ras_fwlog->fw_buffcount); |
| 6404 | bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request, |
| 6405 | LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE); |
| 6406 | |
| 6407 | /* Update DMA buffer address */ |
| 6408 | list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) { |
| 6409 | memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE); |
| 6410 | |
| 6411 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo = |
| 6412 | putPaddrLow(dmabuf->phys); |
| 6413 | |
| 6414 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi = |
| 6415 | putPaddrHigh(dmabuf->phys); |
| 6416 | } |
| 6417 | |
| 6418 | /* Update LPWD address */ |
| 6419 | mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys); |
| 6420 | mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys); |
| 6421 | |
| 6422 | mbox->vport = phba->pport; |
| 6423 | mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl; |
| 6424 | |
| 6425 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6426 | |
| 6427 | if (rc == MBX_NOT_FINISHED) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6428 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6429 | "6191 FW-Log Mailbox failed. " |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6430 | "status %d mbxStatus : x%x", rc, |
| 6431 | bf_get(lpfc_mqe_status, &mbox->u.mqe)); |
| 6432 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6433 | rc = -EIO; |
| 6434 | goto mem_free; |
| 6435 | } else |
| 6436 | rc = 0; |
| 6437 | mem_free: |
| 6438 | if (rc) |
| 6439 | lpfc_sli4_ras_dma_free(phba); |
| 6440 | |
| 6441 | return rc; |
| 6442 | } |
| 6443 | |
| 6444 | /** |
| 6445 | * lpfc_sli4_ras_setup - Check if RAS supported on the adapter |
| 6446 | * @phba: Pointer to HBA context object. |
| 6447 | * |
| 6448 | * Check if RAS is supported on the adapter and initialize it. |
| 6449 | **/ |
| 6450 | void |
| 6451 | lpfc_sli4_ras_setup(struct lpfc_hba *phba) |
| 6452 | { |
| 6453 | /* Check RAS FW Log needs to be enabled or not */ |
| 6454 | if (lpfc_check_fwlog_support(phba)) |
| 6455 | return; |
| 6456 | |
| 6457 | lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level, |
| 6458 | LPFC_RAS_ENABLE_LOGGING); |
| 6459 | } |
| 6460 | |
| 6461 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6462 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 6463 | * @phba: Pointer to HBA context object. |
| 6464 | * |
| 6465 | * This function allocates all SLI4 resource identifiers. |
| 6466 | **/ |
| 6467 | int |
| 6468 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 6469 | { |
| 6470 | int i, rc, error = 0; |
| 6471 | uint16_t count, base; |
| 6472 | unsigned long longs; |
| 6473 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6474 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6475 | 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] | 6476 | if (phba->sli4_hba.extents_in_use) { |
| 6477 | /* |
| 6478 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 6479 | * resource extent count must be read and allocated before |
| 6480 | * provisioning the resource id arrays. |
| 6481 | */ |
| 6482 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 6483 | LPFC_IDX_RSRC_RDY) { |
| 6484 | /* |
| 6485 | * Extent-based resources are set - the driver could |
| 6486 | * be in a port reset. Figure out if any corrective |
| 6487 | * actions need to be taken. |
| 6488 | */ |
| 6489 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6490 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6491 | if (rc != 0) |
| 6492 | error++; |
| 6493 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6494 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6495 | if (rc != 0) |
| 6496 | error++; |
| 6497 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6498 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6499 | if (rc != 0) |
| 6500 | error++; |
| 6501 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6502 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6503 | if (rc != 0) |
| 6504 | error++; |
| 6505 | |
| 6506 | /* |
| 6507 | * It's possible that the number of resources |
| 6508 | * provided to this port instance changed between |
| 6509 | * resets. Detect this condition and reallocate |
| 6510 | * resources. Otherwise, there is no action. |
| 6511 | */ |
| 6512 | if (error) { |
| 6513 | lpfc_printf_log(phba, KERN_INFO, |
| 6514 | LOG_MBOX | LOG_INIT, |
| 6515 | "2931 Detected extent resource " |
| 6516 | "change. Reallocating all " |
| 6517 | "extents.\n"); |
| 6518 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6519 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6520 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6521 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6522 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6523 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6524 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6525 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6526 | } else |
| 6527 | return 0; |
| 6528 | } |
| 6529 | |
| 6530 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6531 | if (unlikely(rc)) |
| 6532 | goto err_exit; |
| 6533 | |
| 6534 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6535 | if (unlikely(rc)) |
| 6536 | goto err_exit; |
| 6537 | |
| 6538 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6539 | if (unlikely(rc)) |
| 6540 | goto err_exit; |
| 6541 | |
| 6542 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6543 | if (unlikely(rc)) |
| 6544 | goto err_exit; |
| 6545 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6546 | LPFC_IDX_RSRC_RDY); |
| 6547 | return rc; |
| 6548 | } else { |
| 6549 | /* |
| 6550 | * The port does not support resource extents. The XRI, VPI, |
| 6551 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 6552 | * Just allocate the bitmasks and provision the resource id |
| 6553 | * arrays. If a port reset is active, the resources don't |
| 6554 | * need any action - just exit. |
| 6555 | */ |
| 6556 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6557 | LPFC_IDX_RSRC_RDY) { |
| 6558 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6559 | lpfc_sli4_remove_rpis(phba); |
| 6560 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6561 | /* RPIs. */ |
| 6562 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6563 | if (count <= 0) { |
| 6564 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6565 | "3279 Invalid provisioning of " |
| 6566 | "rpi:%d\n", count); |
| 6567 | rc = -EINVAL; |
| 6568 | goto err_exit; |
| 6569 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6570 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 6571 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6572 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6573 | sizeof(unsigned long), |
| 6574 | GFP_KERNEL); |
| 6575 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6576 | rc = -ENOMEM; |
| 6577 | goto err_exit; |
| 6578 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6579 | phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6580 | GFP_KERNEL); |
| 6581 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6582 | rc = -ENOMEM; |
| 6583 | goto free_rpi_bmask; |
| 6584 | } |
| 6585 | |
| 6586 | for (i = 0; i < count; i++) |
| 6587 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 6588 | |
| 6589 | /* VPIs. */ |
| 6590 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
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 | "3280 Invalid provisioning of " |
| 6594 | "vpi:%d\n", count); |
| 6595 | rc = -EINVAL; |
| 6596 | goto free_rpi_ids; |
| 6597 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6598 | base = phba->sli4_hba.max_cfg_param.vpi_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->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6601 | GFP_KERNEL); |
| 6602 | if (unlikely(!phba->vpi_bmask)) { |
| 6603 | rc = -ENOMEM; |
| 6604 | goto free_rpi_ids; |
| 6605 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6606 | phba->vpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6607 | GFP_KERNEL); |
| 6608 | if (unlikely(!phba->vpi_ids)) { |
| 6609 | rc = -ENOMEM; |
| 6610 | goto free_vpi_bmask; |
| 6611 | } |
| 6612 | |
| 6613 | for (i = 0; i < count; i++) |
| 6614 | phba->vpi_ids[i] = base + i; |
| 6615 | |
| 6616 | /* XRIs. */ |
| 6617 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6618 | if (count <= 0) { |
| 6619 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6620 | "3281 Invalid provisioning of " |
| 6621 | "xri:%d\n", count); |
| 6622 | rc = -EINVAL; |
| 6623 | goto free_vpi_ids; |
| 6624 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6625 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 6626 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6627 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6628 | sizeof(unsigned long), |
| 6629 | GFP_KERNEL); |
| 6630 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6631 | rc = -ENOMEM; |
| 6632 | goto free_vpi_ids; |
| 6633 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 6634 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6635 | phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6636 | GFP_KERNEL); |
| 6637 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6638 | rc = -ENOMEM; |
| 6639 | goto free_xri_bmask; |
| 6640 | } |
| 6641 | |
| 6642 | for (i = 0; i < count; i++) |
| 6643 | phba->sli4_hba.xri_ids[i] = base + i; |
| 6644 | |
| 6645 | /* VFIs. */ |
| 6646 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6647 | if (count <= 0) { |
| 6648 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6649 | "3282 Invalid provisioning of " |
| 6650 | "vfi:%d\n", count); |
| 6651 | rc = -EINVAL; |
| 6652 | goto free_xri_ids; |
| 6653 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6654 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 6655 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6656 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6657 | sizeof(unsigned long), |
| 6658 | GFP_KERNEL); |
| 6659 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6660 | rc = -ENOMEM; |
| 6661 | goto free_xri_ids; |
| 6662 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6663 | phba->sli4_hba.vfi_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.vfi_ids)) { |
| 6666 | rc = -ENOMEM; |
| 6667 | goto free_vfi_bmask; |
| 6668 | } |
| 6669 | |
| 6670 | for (i = 0; i < count; i++) |
| 6671 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 6672 | |
| 6673 | /* |
| 6674 | * Mark all resources ready. An HBA reset doesn't need |
| 6675 | * to reset the initialization. |
| 6676 | */ |
| 6677 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6678 | LPFC_IDX_RSRC_RDY); |
| 6679 | return 0; |
| 6680 | } |
| 6681 | |
| 6682 | free_vfi_bmask: |
| 6683 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6684 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6685 | free_xri_ids: |
| 6686 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6687 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6688 | free_xri_bmask: |
| 6689 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6690 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6691 | free_vpi_ids: |
| 6692 | kfree(phba->vpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6693 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6694 | free_vpi_bmask: |
| 6695 | kfree(phba->vpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6696 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6697 | free_rpi_ids: |
| 6698 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6699 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6700 | free_rpi_bmask: |
| 6701 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6702 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6703 | err_exit: |
| 6704 | return rc; |
| 6705 | } |
| 6706 | |
| 6707 | /** |
| 6708 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 6709 | * @phba: Pointer to HBA context object. |
| 6710 | * |
| 6711 | * This function allocates the number of elements for the specified |
| 6712 | * resource type. |
| 6713 | **/ |
| 6714 | int |
| 6715 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 6716 | { |
| 6717 | if (phba->sli4_hba.extents_in_use) { |
| 6718 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6719 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6720 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6721 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6722 | } else { |
| 6723 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6724 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6725 | kfree(phba->vpi_ids); |
| 6726 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6727 | kfree(phba->sli4_hba.xri_bmask); |
| 6728 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6729 | kfree(phba->sli4_hba.vfi_bmask); |
| 6730 | kfree(phba->sli4_hba.vfi_ids); |
| 6731 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6732 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6733 | } |
| 6734 | |
| 6735 | return 0; |
| 6736 | } |
| 6737 | |
| 6738 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6739 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 6740 | * @phba: Pointer to HBA context object. |
| 6741 | * @type: The resource extent type. |
| 6742 | * @extnt_count: buffer to hold port extent count response |
| 6743 | * @extnt_size: buffer to hold port extent size response. |
| 6744 | * |
| 6745 | * This function calls the port to read the host allocated extents |
| 6746 | * for a particular type. |
| 6747 | **/ |
| 6748 | int |
| 6749 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 6750 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 6751 | { |
| 6752 | bool emb; |
| 6753 | int rc = 0; |
| 6754 | uint16_t curr_blks = 0; |
| 6755 | uint32_t req_len, emb_len; |
| 6756 | uint32_t alloc_len, mbox_tmo; |
| 6757 | struct list_head *blk_list_head; |
| 6758 | struct lpfc_rsrc_blks *rsrc_blk; |
| 6759 | LPFC_MBOXQ_t *mbox; |
| 6760 | void *virtaddr = NULL; |
| 6761 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6762 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6763 | union lpfc_sli4_cfg_shdr *shdr; |
| 6764 | |
| 6765 | switch (type) { |
| 6766 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6767 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6768 | break; |
| 6769 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6770 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6771 | break; |
| 6772 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6773 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6774 | break; |
| 6775 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6776 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6777 | break; |
| 6778 | default: |
| 6779 | return -EIO; |
| 6780 | } |
| 6781 | |
| 6782 | /* Count the number of extents currently allocatd for this type. */ |
| 6783 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6784 | if (curr_blks == 0) { |
| 6785 | /* |
| 6786 | * The GET_ALLOCATED mailbox does not return the size, |
| 6787 | * just the count. The size should be just the size |
| 6788 | * stored in the current allocated block and all sizes |
| 6789 | * for an extent type are the same so set the return |
| 6790 | * value now. |
| 6791 | */ |
| 6792 | *extnt_size = rsrc_blk->rsrc_size; |
| 6793 | } |
| 6794 | curr_blks++; |
| 6795 | } |
| 6796 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6797 | /* |
| 6798 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6799 | * accounts for extents-specific word. |
| 6800 | */ |
| 6801 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6802 | sizeof(uint32_t); |
| 6803 | |
| 6804 | /* |
| 6805 | * Presume the allocation and response will fit into an embedded |
| 6806 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6807 | */ |
| 6808 | emb = LPFC_SLI4_MBX_EMBED; |
| 6809 | req_len = emb_len; |
| 6810 | if (req_len > emb_len) { |
| 6811 | req_len = curr_blks * sizeof(uint16_t) + |
| 6812 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6813 | sizeof(uint32_t); |
| 6814 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6815 | } |
| 6816 | |
| 6817 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6818 | if (!mbox) |
| 6819 | return -ENOMEM; |
| 6820 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6821 | |
| 6822 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6823 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6824 | req_len, emb); |
| 6825 | if (alloc_len < req_len) { |
| 6826 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6827 | "2983 Allocated DMA memory size (x%x) is " |
| 6828 | "less than the requested DMA memory " |
| 6829 | "size (x%x)\n", alloc_len, req_len); |
| 6830 | rc = -ENOMEM; |
| 6831 | goto err_exit; |
| 6832 | } |
| 6833 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6834 | if (unlikely(rc)) { |
| 6835 | rc = -EIO; |
| 6836 | goto err_exit; |
| 6837 | } |
| 6838 | |
| 6839 | if (!phba->sli4_hba.intr_enable) |
| 6840 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6841 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6842 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6843 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6844 | } |
| 6845 | |
| 6846 | if (unlikely(rc)) { |
| 6847 | rc = -EIO; |
| 6848 | goto err_exit; |
| 6849 | } |
| 6850 | |
| 6851 | /* |
| 6852 | * Figure out where the response is located. Then get local pointers |
| 6853 | * to the response data. The port does not guarantee to respond to |
| 6854 | * all extents counts request so update the local variable with the |
| 6855 | * allocated count from the port. |
| 6856 | */ |
| 6857 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6858 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6859 | shdr = &rsrc_ext->header.cfg_shdr; |
| 6860 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6861 | } else { |
| 6862 | virtaddr = mbox->sge_array->addr[0]; |
| 6863 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6864 | shdr = &n_rsrc->cfg_shdr; |
| 6865 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6866 | } |
| 6867 | |
| 6868 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 6869 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6870 | "2984 Failed to read allocated resources " |
| 6871 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 6872 | type, |
| 6873 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 6874 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 6875 | rc = -EIO; |
| 6876 | goto err_exit; |
| 6877 | } |
| 6878 | err_exit: |
| 6879 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6880 | return rc; |
| 6881 | } |
| 6882 | |
| 6883 | /** |
James Smart | 0ef6996 | 2017-04-21 16:04:50 -0700 | [diff] [blame] | 6884 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6885 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6886 | * @pring: Pointer to driver SLI ring object. |
| 6887 | * @sgl_list: linked link of sgl buffers to post |
| 6888 | * @cnt: number of linked list buffers |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6889 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6890 | * This routine walks the list of buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6891 | * repost them to the port by using SGL block post. This is needed after a |
| 6892 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6893 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
| 6894 | * 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] | 6895 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 6896 | * mailbox command for posting. |
| 6897 | * |
| 6898 | * Returns: 0 = success, non-zero failure. |
| 6899 | **/ |
| 6900 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6901 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
| 6902 | struct list_head *sgl_list, int cnt) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6903 | { |
| 6904 | struct lpfc_sglq *sglq_entry = NULL; |
| 6905 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 6906 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6907 | int status, total_cnt; |
| 6908 | int post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6909 | int last_xritag = NO_XRI; |
| 6910 | LIST_HEAD(prep_sgl_list); |
| 6911 | LIST_HEAD(blck_sgl_list); |
| 6912 | LIST_HEAD(allc_sgl_list); |
| 6913 | LIST_HEAD(post_sgl_list); |
| 6914 | LIST_HEAD(free_sgl_list); |
| 6915 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6916 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6917 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6918 | list_splice_init(sgl_list, &allc_sgl_list); |
| 6919 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6920 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6921 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6922 | total_cnt = cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6923 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6924 | &allc_sgl_list, list) { |
| 6925 | list_del_init(&sglq_entry->list); |
| 6926 | block_cnt++; |
| 6927 | if ((last_xritag != NO_XRI) && |
| 6928 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6929 | /* a hole in xri block, form a sgl posting block */ |
| 6930 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6931 | post_cnt = block_cnt - 1; |
| 6932 | /* prepare list for next posting block */ |
| 6933 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6934 | block_cnt = 1; |
| 6935 | } else { |
| 6936 | /* prepare list for next posting block */ |
| 6937 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6938 | /* enough sgls for non-embed sgl mbox command */ |
| 6939 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6940 | list_splice_init(&prep_sgl_list, |
| 6941 | &blck_sgl_list); |
| 6942 | post_cnt = block_cnt; |
| 6943 | block_cnt = 0; |
| 6944 | } |
| 6945 | } |
| 6946 | num_posted++; |
| 6947 | |
| 6948 | /* keep track of last sgl's xritag */ |
| 6949 | last_xritag = sglq_entry->sli4_xritag; |
| 6950 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6951 | /* end of repost sgl list condition for buffers */ |
| 6952 | if (num_posted == total_cnt) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6953 | if (post_cnt == 0) { |
| 6954 | list_splice_init(&prep_sgl_list, |
| 6955 | &blck_sgl_list); |
| 6956 | post_cnt = block_cnt; |
| 6957 | } else if (block_cnt == 1) { |
| 6958 | status = lpfc_sli4_post_sgl(phba, |
| 6959 | sglq_entry->phys, 0, |
| 6960 | sglq_entry->sli4_xritag); |
| 6961 | if (!status) { |
| 6962 | /* successful, put sgl to posted list */ |
| 6963 | list_add_tail(&sglq_entry->list, |
| 6964 | &post_sgl_list); |
| 6965 | } else { |
| 6966 | /* Failure, put sgl to free list */ |
| 6967 | lpfc_printf_log(phba, KERN_WARNING, |
| 6968 | LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6969 | "3159 Failed to post " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6970 | "sgl, xritag:x%x\n", |
| 6971 | sglq_entry->sli4_xritag); |
| 6972 | list_add_tail(&sglq_entry->list, |
| 6973 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6974 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6975 | } |
| 6976 | } |
| 6977 | } |
| 6978 | |
| 6979 | /* continue until a nembed page worth of sgls */ |
| 6980 | if (post_cnt == 0) |
| 6981 | continue; |
| 6982 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6983 | /* post the buffer list sgls as a block */ |
| 6984 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, |
| 6985 | post_cnt); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6986 | |
| 6987 | if (!status) { |
| 6988 | /* success, put sgl list to posted sgl list */ |
| 6989 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 6990 | } else { |
| 6991 | /* Failure, put sgl list to free sgl list */ |
| 6992 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 6993 | struct lpfc_sglq, |
| 6994 | list); |
| 6995 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6996 | "3160 Failed to post sgl-list, " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6997 | "xritag:x%x-x%x\n", |
| 6998 | sglq_entry_first->sli4_xritag, |
| 6999 | (sglq_entry_first->sli4_xritag + |
| 7000 | post_cnt - 1)); |
| 7001 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7002 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7003 | } |
| 7004 | |
| 7005 | /* don't reset xirtag due to hole in xri block */ |
| 7006 | if (block_cnt == 0) |
| 7007 | last_xritag = NO_XRI; |
| 7008 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7009 | /* reset sgl post count for next round of posting */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7010 | post_cnt = 0; |
| 7011 | } |
| 7012 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7013 | /* free the sgls failed to post */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7014 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 7015 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7016 | /* push sgls posted to the available list */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7017 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7018 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7019 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7020 | list_splice_init(&post_sgl_list, sgl_list); |
| 7021 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7022 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7023 | } else { |
| 7024 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7025 | "3161 Failure to post sgl to port.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7026 | return -EIO; |
| 7027 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7028 | |
| 7029 | /* return the number of XRIs actually posted */ |
| 7030 | return total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7031 | } |
| 7032 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7033 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7034 | * lpfc_sli4_repost_io_sgl_list - Repost all the allocated nvme buffer sgls |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7035 | * @phba: pointer to lpfc hba data structure. |
| 7036 | * |
| 7037 | * This routine walks the list of nvme buffers that have been allocated and |
| 7038 | * repost them to the port by using SGL block post. This is needed after a |
| 7039 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 7040 | * is responsible for moving all nvme buffers on the lpfc_abts_nvme_sgl_list |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7041 | * to the lpfc_io_buf_list. If the repost fails, reject all nvme buffers. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7042 | * |
| 7043 | * Returns: 0 = success, non-zero failure. |
| 7044 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 7045 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7046 | lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7047 | { |
| 7048 | LIST_HEAD(post_nblist); |
| 7049 | int num_posted, rc = 0; |
| 7050 | |
| 7051 | /* get all NVME buffers need to repost to a local list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7052 | lpfc_io_buf_flush(phba, &post_nblist); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7053 | |
| 7054 | /* post the list of nvme buffer sgls to port if available */ |
| 7055 | if (!list_empty(&post_nblist)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7056 | num_posted = lpfc_sli4_post_io_sgl_list( |
| 7057 | phba, &post_nblist, phba->sli4_hba.io_xri_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7058 | /* failed to post any nvme buffer, return error */ |
| 7059 | if (num_posted == 0) |
| 7060 | rc = -EIO; |
| 7061 | } |
| 7062 | return rc; |
| 7063 | } |
| 7064 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 7065 | static void |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7066 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 7067 | { |
| 7068 | uint32_t len; |
| 7069 | |
| 7070 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 7071 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 7072 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7073 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 7074 | LPFC_SLI4_MBX_EMBED); |
| 7075 | |
| 7076 | 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] | 7077 | mbox->u.mqe.un.set_host_data.param_len = |
| 7078 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7079 | snprintf(mbox->u.mqe.un.set_host_data.data, |
| 7080 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 7081 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 7082 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 7083 | } |
| 7084 | |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7085 | int |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7086 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7087 | struct lpfc_queue *drq, int count, int idx) |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7088 | { |
| 7089 | int rc, i; |
| 7090 | struct lpfc_rqe hrqe; |
| 7091 | struct lpfc_rqe drqe; |
| 7092 | struct lpfc_rqb *rqbp; |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7093 | unsigned long flags; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7094 | struct rqb_dmabuf *rqb_buffer; |
| 7095 | LIST_HEAD(rqb_buf_list); |
| 7096 | |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7097 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7098 | rqbp = hrq->rqbp; |
| 7099 | for (i = 0; i < count; i++) { |
| 7100 | /* IF RQ is already full, don't bother */ |
| 7101 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) |
| 7102 | break; |
| 7103 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); |
| 7104 | if (!rqb_buffer) |
| 7105 | break; |
| 7106 | rqb_buffer->hrq = hrq; |
| 7107 | rqb_buffer->drq = drq; |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7108 | rqb_buffer->idx = idx; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7109 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
| 7110 | } |
| 7111 | while (!list_empty(&rqb_buf_list)) { |
| 7112 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, |
| 7113 | hbuf.list); |
| 7114 | |
| 7115 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); |
| 7116 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); |
| 7117 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); |
| 7118 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); |
| 7119 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
| 7120 | if (rc < 0) { |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7121 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7122 | "6421 Cannot post to HRQ %d: %x %x %x " |
| 7123 | "DRQ %x %x\n", |
| 7124 | hrq->queue_id, |
| 7125 | hrq->host_index, |
| 7126 | hrq->hba_index, |
| 7127 | hrq->entry_count, |
| 7128 | drq->host_index, |
| 7129 | drq->hba_index); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7130 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
| 7131 | } else { |
| 7132 | list_add_tail(&rqb_buffer->hbuf.list, |
| 7133 | &rqbp->rqb_buffer_list); |
| 7134 | rqbp->buffer_count++; |
| 7135 | } |
| 7136 | } |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7137 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7138 | return 1; |
| 7139 | } |
| 7140 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7141 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7142 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7143 | * @phba: Pointer to HBA context object. |
| 7144 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7145 | * This function is the main SLI4 device initialization PCI function. This |
| 7146 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7147 | * HBA error attention handler code. Caller is not required to hold any |
| 7148 | * locks. |
| 7149 | **/ |
| 7150 | int |
| 7151 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 7152 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7153 | int rc, i, cnt, len; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7154 | LPFC_MBOXQ_t *mboxq; |
| 7155 | struct lpfc_mqe *mqe; |
| 7156 | uint8_t *vpd; |
| 7157 | uint32_t vpd_size; |
| 7158 | uint32_t ftr_rsp = 0; |
| 7159 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 7160 | struct lpfc_vport *vport = phba->pport; |
| 7161 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7162 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7163 | |
| 7164 | /* Perform a PCI function reset to start from clean */ |
| 7165 | rc = lpfc_pci_function_reset(phba); |
| 7166 | if (unlikely(rc)) |
| 7167 | return -ENODEV; |
| 7168 | |
| 7169 | /* Check the HBA Host Status Register for readyness */ |
| 7170 | rc = lpfc_sli4_post_status_check(phba); |
| 7171 | if (unlikely(rc)) |
| 7172 | return -ENODEV; |
| 7173 | else { |
| 7174 | spin_lock_irq(&phba->hbalock); |
| 7175 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 7176 | spin_unlock_irq(&phba->hbalock); |
| 7177 | } |
| 7178 | |
| 7179 | /* |
| 7180 | * Allocate a single mailbox container for initializing the |
| 7181 | * port. |
| 7182 | */ |
| 7183 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7184 | if (!mboxq) |
| 7185 | return -ENOMEM; |
| 7186 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7187 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7188 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7189 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 7190 | if (!vpd) { |
| 7191 | rc = -ENOMEM; |
| 7192 | goto out_free_mbox; |
| 7193 | } |
| 7194 | |
| 7195 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7196 | if (unlikely(rc)) { |
| 7197 | kfree(vpd); |
| 7198 | goto out_free_mbox; |
| 7199 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7200 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7201 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7202 | 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] | 7203 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7204 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7205 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 7206 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7207 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7208 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7209 | |
| 7210 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 7211 | LPFC_DCBX_CEE_MODE) |
| 7212 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 7213 | else |
| 7214 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 7215 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 7216 | phba->hba_flag &= ~HBA_IOQ_FLUSH; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 7217 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7218 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7219 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7220 | "0376 READ_REV Error. SLI Level %d " |
| 7221 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7222 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7223 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7224 | kfree(vpd); |
| 7225 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7226 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7227 | |
| 7228 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7229 | * Continue initialization with default values even if driver failed |
| 7230 | * to read FCoE param config regions, only read parameters if the |
| 7231 | * board is FCoE |
| 7232 | */ |
| 7233 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 7234 | lpfc_sli4_read_fcoe_params(phba)) |
| 7235 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 7236 | "2570 Failed to read FCoE parameters\n"); |
| 7237 | |
| 7238 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7239 | * Retrieve sli4 device physical port name, failure of doing it |
| 7240 | * is considered as non-fatal. |
| 7241 | */ |
| 7242 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 7243 | if (!rc) |
| 7244 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7245 | "3080 Successful retrieving SLI4 device " |
| 7246 | "physical port name: %s.\n", phba->Port); |
| 7247 | |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 7248 | rc = lpfc_sli4_get_ctl_attr(phba); |
| 7249 | if (!rc) |
| 7250 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7251 | "8351 Successful retrieving SLI4 device " |
| 7252 | "CTL ATTR\n"); |
| 7253 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7254 | /* |
| 7255 | * Evaluate the read rev and vpd data. Populate the driver |
| 7256 | * state with the results. If this routine fails, the failure |
| 7257 | * is not fatal as the driver will use generic values. |
| 7258 | */ |
| 7259 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 7260 | if (unlikely(!rc)) { |
| 7261 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7262 | "0377 Error %d parsing vpd. " |
| 7263 | "Using defaults.\n", rc); |
| 7264 | rc = 0; |
| 7265 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7266 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7267 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7268 | /* Save information as VPD data */ |
| 7269 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 7270 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 7271 | |
| 7272 | /* |
| 7273 | * This is because first G7 ASIC doesn't support the standard |
| 7274 | * 0x5a NVME cmd descriptor type/subtype |
| 7275 | */ |
| 7276 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 7277 | LPFC_SLI_INTF_IF_TYPE_6) && |
| 7278 | (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) && |
| 7279 | (phba->vpd.rev.smRev == 0) && |
| 7280 | (phba->cfg_nvme_embed_cmd == 1)) |
| 7281 | phba->cfg_nvme_embed_cmd = 0; |
| 7282 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7283 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 7284 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 7285 | &mqe->un.read_rev); |
| 7286 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 7287 | &mqe->un.read_rev); |
| 7288 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 7289 | &mqe->un.read_rev); |
| 7290 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 7291 | &mqe->un.read_rev); |
| 7292 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 7293 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 7294 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 7295 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 7296 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 7297 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 7298 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7299 | "(%d):0380 READ_REV Status x%x " |
| 7300 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 7301 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7302 | bf_get(lpfc_mqe_status, mqe), |
| 7303 | phba->vpd.rev.opFwName, |
| 7304 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 7305 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7306 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7307 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 7308 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 7309 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 7310 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7311 | "3362 LUN queue depth changed from %d to %d\n", |
| 7312 | phba->pport->cfg_lun_queue_depth, rc); |
| 7313 | phba->pport->cfg_lun_queue_depth = rc; |
| 7314 | } |
| 7315 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7316 | 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] | 7317 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 7318 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 7319 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7320 | if (rc == MBX_SUCCESS) { |
| 7321 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 7322 | /* Set 1Sec interval to detect UE */ |
| 7323 | phba->eratt_poll_interval = 1; |
| 7324 | phba->sli4_hba.ue_to_sr = bf_get( |
| 7325 | lpfc_mbx_set_feature_UESR, |
| 7326 | &mboxq->u.mqe.un.set_feature); |
| 7327 | phba->sli4_hba.ue_to_rp = bf_get( |
| 7328 | lpfc_mbx_set_feature_UERP, |
| 7329 | &mboxq->u.mqe.un.set_feature); |
| 7330 | } |
| 7331 | } |
| 7332 | |
| 7333 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 7334 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 7335 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 7336 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7337 | if (rc != MBX_SUCCESS) |
| 7338 | phba->mds_diags_support = 0; |
| 7339 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7340 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7341 | /* |
| 7342 | * Discover the port's supported feature set and match it against the |
| 7343 | * hosts requests. |
| 7344 | */ |
| 7345 | lpfc_request_features(phba, mboxq); |
| 7346 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7347 | if (unlikely(rc)) { |
| 7348 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7349 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7350 | } |
| 7351 | |
| 7352 | /* |
| 7353 | * The port must support FCP initiator mode as this is the |
| 7354 | * only mode running in the host. |
| 7355 | */ |
| 7356 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 7357 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7358 | "0378 No support for fcpi mode.\n"); |
| 7359 | ftr_rsp++; |
| 7360 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 7361 | |
| 7362 | /* Performance Hints are ONLY for FCoE */ |
| 7363 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 7364 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 7365 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 7366 | else |
| 7367 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
| 7368 | } |
| 7369 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7370 | /* |
| 7371 | * If the port cannot support the host's requested features |
| 7372 | * then turn off the global config parameters to disable the |
| 7373 | * feature in the driver. This is not a fatal error. |
| 7374 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7375 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 7376 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) { |
| 7377 | phba->cfg_enable_bg = 0; |
| 7378 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7379 | ftr_rsp++; |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7380 | } |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7381 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7382 | |
| 7383 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 7384 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7385 | ftr_rsp++; |
| 7386 | |
| 7387 | if (ftr_rsp) { |
| 7388 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7389 | "0379 Feature Mismatch Data: x%08x %08x " |
| 7390 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 7391 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 7392 | phba->cfg_enable_npiv, phba->max_vpi); |
| 7393 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 7394 | phba->cfg_enable_bg = 0; |
| 7395 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7396 | phba->cfg_enable_npiv = 0; |
| 7397 | } |
| 7398 | |
| 7399 | /* These SLI3 features are assumed in SLI4 */ |
| 7400 | spin_lock_irq(&phba->hbalock); |
| 7401 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 7402 | spin_unlock_irq(&phba->hbalock); |
| 7403 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7404 | /* |
| 7405 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 7406 | * calls depends on these resources to complete port setup. |
| 7407 | */ |
| 7408 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 7409 | if (rc) { |
| 7410 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7411 | "2920 Failed to alloc Resource IDs " |
| 7412 | "rc = x%x\n", rc); |
| 7413 | goto out_free_mbox; |
| 7414 | } |
| 7415 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7416 | lpfc_set_host_data(phba, mboxq); |
| 7417 | |
| 7418 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7419 | if (rc) { |
| 7420 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7421 | "2134 Failed to set host os driver version %x", |
| 7422 | rc); |
| 7423 | } |
| 7424 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7425 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7426 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 7427 | if (rc) { |
| 7428 | phba->link_state = LPFC_HBA_ERROR; |
| 7429 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7430 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7431 | } |
| 7432 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7433 | mboxq->vport = vport; |
| 7434 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7435 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7436 | if (rc == MBX_SUCCESS) { |
| 7437 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 7438 | rc = 0; |
| 7439 | } |
| 7440 | |
| 7441 | /* |
| 7442 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 7443 | * it to the mbuf pool. |
| 7444 | */ |
| 7445 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 7446 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7447 | mboxq->ctx_buf = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7448 | if (unlikely(rc)) { |
| 7449 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7450 | "0382 READ_SPARAM command failed " |
| 7451 | "status %d, mbxStatus x%x\n", |
| 7452 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 7453 | phba->link_state = LPFC_HBA_ERROR; |
| 7454 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7455 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7456 | } |
| 7457 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7458 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7459 | |
| 7460 | /* Update the fc_host data structures with new wwn. */ |
| 7461 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 7462 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 7463 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7464 | /* Create all the SLI4 queues */ |
| 7465 | rc = lpfc_sli4_queue_create(phba); |
| 7466 | if (rc) { |
| 7467 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7468 | "3089 Failed to allocate queues\n"); |
| 7469 | rc = -ENODEV; |
| 7470 | goto out_free_mbox; |
| 7471 | } |
| 7472 | /* Set up all the queues to the device */ |
| 7473 | rc = lpfc_sli4_queue_setup(phba); |
| 7474 | if (unlikely(rc)) { |
| 7475 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7476 | "0381 Error %d during queue setup.\n ", rc); |
| 7477 | goto out_stop_timers; |
| 7478 | } |
| 7479 | /* Initialize the driver internal SLI layer lists. */ |
| 7480 | lpfc_sli4_setup(phba); |
| 7481 | lpfc_sli4_queue_init(phba); |
| 7482 | |
| 7483 | /* update host els xri-sgl sizes and mappings */ |
| 7484 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7485 | if (unlikely(rc)) { |
| 7486 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7487 | "1400 Failed to update xri-sgl size and " |
| 7488 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7489 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7490 | } |
| 7491 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7492 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7493 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 7494 | phba->sli4_hba.els_xri_cnt); |
| 7495 | if (unlikely(rc < 0)) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7496 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7497 | "0582 Error %d during els sgl post " |
| 7498 | "operation\n", rc); |
| 7499 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7500 | goto out_destroy_queue; |
| 7501 | } |
| 7502 | phba->sli4_hba.els_xri_cnt = rc; |
| 7503 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7504 | if (phba->nvmet_support) { |
| 7505 | /* update host nvmet xri-sgl sizes and mappings */ |
| 7506 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 7507 | if (unlikely(rc)) { |
| 7508 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7509 | "6308 Failed to update nvmet-sgl size " |
| 7510 | "and mapping: %d\n", rc); |
| 7511 | goto out_destroy_queue; |
| 7512 | } |
| 7513 | |
| 7514 | /* register the nvmet sgl pool to the port */ |
| 7515 | rc = lpfc_sli4_repost_sgl_list( |
| 7516 | phba, |
| 7517 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 7518 | phba->sli4_hba.nvmet_xri_cnt); |
| 7519 | if (unlikely(rc < 0)) { |
| 7520 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7521 | "3117 Error %d during nvmet " |
| 7522 | "sgl post\n", rc); |
| 7523 | rc = -ENODEV; |
| 7524 | goto out_destroy_queue; |
| 7525 | } |
| 7526 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7527 | |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7528 | /* We allocate an iocbq for every receive context SGL. |
| 7529 | * The additional allocation is for abort and ls handling. |
| 7530 | */ |
| 7531 | cnt = phba->sli4_hba.nvmet_xri_cnt + |
| 7532 | phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7533 | } else { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7534 | /* update host common xri-sgl sizes and mappings */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7535 | rc = lpfc_sli4_io_sgl_update(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7536 | if (unlikely(rc)) { |
| 7537 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7538 | "6082 Failed to update nvme-sgl size " |
| 7539 | "and mapping: %d\n", rc); |
| 7540 | goto out_destroy_queue; |
| 7541 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7542 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7543 | /* register the allocated common sgl pool to the port */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7544 | rc = lpfc_sli4_repost_io_sgl_list(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7545 | if (unlikely(rc)) { |
| 7546 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7547 | "6116 Error %d during nvme sgl post " |
| 7548 | "operation\n", rc); |
| 7549 | /* Some NVME buffers were moved to abort nvme list */ |
| 7550 | /* A pci function reset will repost them */ |
| 7551 | rc = -ENODEV; |
| 7552 | goto out_destroy_queue; |
| 7553 | } |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7554 | /* Each lpfc_io_buf job structure has an iocbq element. |
| 7555 | * This cnt provides for abort, els, ct and ls requests. |
| 7556 | */ |
| 7557 | cnt = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7558 | } |
| 7559 | |
| 7560 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7561 | /* Initialize and populate the iocb list per host */ |
| 7562 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7563 | "2821 initialize iocb list with %d entries\n", |
| 7564 | cnt); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7565 | rc = lpfc_init_iocb_list(phba, cnt); |
| 7566 | if (rc) { |
| 7567 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7568 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7569 | goto out_destroy_queue; |
| 7570 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7571 | } |
| 7572 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7573 | if (phba->nvmet_support) |
| 7574 | lpfc_nvmet_create_targetport(phba); |
| 7575 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7576 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7577 | /* Post initial buffers to all RQs created */ |
| 7578 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 7579 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 7580 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 7581 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 7582 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 7583 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7584 | rqbp->buffer_count = 0; |
| 7585 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7586 | lpfc_post_rq_buffer( |
| 7587 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 7588 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | 2448e48 | 2018-04-09 14:24:24 -0700 | [diff] [blame] | 7589 | phba->cfg_nvmet_mrq_post, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7590 | } |
| 7591 | } |
| 7592 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7593 | /* Post the rpi header region to the device. */ |
| 7594 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 7595 | if (unlikely(rc)) { |
| 7596 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7597 | "0393 Error %d during rpi post operation\n", |
| 7598 | rc); |
| 7599 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7600 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7601 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7602 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7603 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7604 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7605 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7606 | /* |
| 7607 | * The FC Port needs to register FCFI (index 0) |
| 7608 | */ |
| 7609 | lpfc_reg_fcfi(phba, mboxq); |
| 7610 | mboxq->vport = phba->pport; |
| 7611 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7612 | if (rc != MBX_SUCCESS) |
| 7613 | goto out_unset_queue; |
| 7614 | rc = 0; |
| 7615 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 7616 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7617 | } else { |
| 7618 | /* We are a NVME Target mode with MRQ > 1 */ |
| 7619 | |
| 7620 | /* First register the FCFI */ |
| 7621 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 7622 | mboxq->vport = phba->pport; |
| 7623 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7624 | if (rc != MBX_SUCCESS) |
| 7625 | goto out_unset_queue; |
| 7626 | rc = 0; |
| 7627 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 7628 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 7629 | |
| 7630 | /* Next register the MRQs */ |
| 7631 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 7632 | mboxq->vport = phba->pport; |
| 7633 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7634 | if (rc != MBX_SUCCESS) |
| 7635 | goto out_unset_queue; |
| 7636 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7637 | } |
| 7638 | /* Check if the port is configured to be disabled */ |
| 7639 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7640 | } |
| 7641 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7642 | /* Don't post more new bufs if repost already recovered |
| 7643 | * the nvme sgls. |
| 7644 | */ |
| 7645 | if (phba->nvmet_support == 0) { |
| 7646 | if (phba->sli4_hba.io_xri_cnt == 0) { |
| 7647 | len = lpfc_new_io_buf( |
| 7648 | phba, phba->sli4_hba.io_xri_max); |
| 7649 | if (len == 0) { |
| 7650 | rc = -ENOMEM; |
| 7651 | goto out_unset_queue; |
| 7652 | } |
| 7653 | |
| 7654 | if (phba->cfg_xri_rebalancing) |
| 7655 | lpfc_create_multixri_pools(phba); |
| 7656 | } |
| 7657 | } else { |
| 7658 | phba->cfg_xri_rebalancing = 0; |
| 7659 | } |
| 7660 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 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 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7683 | /* start eq_delay heartbeat */ |
| 7684 | if (phba->cfg_auto_imax) |
| 7685 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 7686 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 7687 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7688 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7689 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7690 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7691 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7692 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 7693 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 7694 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 7695 | if (!rc) { |
| 7696 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7697 | "2829 This device supports " |
| 7698 | "Advanced Error Reporting (AER)\n"); |
| 7699 | spin_lock_irq(&phba->hbalock); |
| 7700 | phba->hba_flag |= HBA_AER_ENABLED; |
| 7701 | spin_unlock_irq(&phba->hbalock); |
| 7702 | } else { |
| 7703 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7704 | "2830 This device does not support " |
| 7705 | "Advanced Error Reporting (AER)\n"); |
| 7706 | phba->cfg_aer_support = 0; |
| 7707 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7708 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7709 | } |
| 7710 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7711 | /* |
| 7712 | * The port is ready, set the host's link state to LINK_DOWN |
| 7713 | * in preparation for link interrupts. |
| 7714 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7715 | spin_lock_irq(&phba->hbalock); |
| 7716 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7717 | |
| 7718 | /* Check if physical ports are trunked */ |
| 7719 | if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba)) |
| 7720 | phba->trunk_link.link0.state = LPFC_LINK_DOWN; |
| 7721 | if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba)) |
| 7722 | phba->trunk_link.link1.state = LPFC_LINK_DOWN; |
| 7723 | if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba)) |
| 7724 | phba->trunk_link.link2.state = LPFC_LINK_DOWN; |
| 7725 | if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba)) |
| 7726 | phba->trunk_link.link3.state = LPFC_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7727 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7728 | |
James Smart | e8869f5 | 2019-03-12 16:30:18 -0700 | [diff] [blame] | 7729 | /* Arm the CQs and then EQs on device */ |
| 7730 | lpfc_sli4_arm_cqeq_intr(phba); |
| 7731 | |
| 7732 | /* Indicate device interrupt mode */ |
| 7733 | phba->sli4_hba.intr_enable = 1; |
| 7734 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7735 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 7736 | (phba->hba_flag & LINK_DISABLED)) { |
| 7737 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7738 | "3103 Adapter Link is disabled.\n"); |
| 7739 | lpfc_down_link(phba, mboxq); |
| 7740 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7741 | if (rc != MBX_SUCCESS) { |
| 7742 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7743 | "3104 Adapter failed to issue " |
| 7744 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7745 | goto out_io_buff_free; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7746 | } |
| 7747 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7748 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 7749 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 7750 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 7751 | if (rc) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7752 | goto out_io_buff_free; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7753 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7754 | } |
| 7755 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7756 | return rc; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7757 | out_io_buff_free: |
| 7758 | /* Free allocated IO Buffers */ |
| 7759 | lpfc_io_free(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7760 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7761 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7762 | lpfc_sli4_queue_unset(phba); |
| 7763 | out_destroy_queue: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7764 | lpfc_free_iocb_list(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7765 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7766 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7767 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7768 | out_free_mbox: |
| 7769 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7770 | return rc; |
| 7771 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7772 | |
| 7773 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7774 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7775 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7776 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7777 | * This is the callback function for mailbox timer. The mailbox |
| 7778 | * timer is armed when a new mailbox command is issued and the timer |
| 7779 | * is deleted when the mailbox complete. The function is called by |
| 7780 | * the kernel timer code when a mailbox does not complete within |
| 7781 | * expected time. This function wakes up the worker thread to |
| 7782 | * process the mailbox timeout and returns. All the processing is |
| 7783 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 7784 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7785 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7786 | lpfc_mbox_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7787 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7788 | struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7789 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7790 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7791 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7792 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7793 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7794 | if (!tmo_posted) |
| 7795 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 7796 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 7797 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7798 | if (!tmo_posted) |
| 7799 | lpfc_worker_wake_up(phba); |
| 7800 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7801 | } |
| 7802 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7803 | /** |
| 7804 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 7805 | * are pending |
| 7806 | * @phba: Pointer to HBA context object. |
| 7807 | * |
| 7808 | * This function checks if any mailbox completions are present on the mailbox |
| 7809 | * completion queue. |
| 7810 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 7811 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7812 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 7813 | { |
| 7814 | |
| 7815 | uint32_t idx; |
| 7816 | struct lpfc_queue *mcq; |
| 7817 | struct lpfc_mcqe *mcqe; |
| 7818 | bool pending_completions = false; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7819 | uint8_t qe_valid; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7820 | |
| 7821 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7822 | return false; |
| 7823 | |
| 7824 | /* Check for completions on mailbox completion queue */ |
| 7825 | |
| 7826 | mcq = phba->sli4_hba.mbx_cq; |
| 7827 | idx = mcq->hba_index; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7828 | qe_valid = mcq->qe_valid; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 7829 | while (bf_get_le32(lpfc_cqe_valid, |
| 7830 | (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) { |
| 7831 | mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx)); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7832 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 7833 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 7834 | pending_completions = true; |
| 7835 | break; |
| 7836 | } |
| 7837 | idx = (idx + 1) % mcq->entry_count; |
| 7838 | if (mcq->hba_index == idx) |
| 7839 | break; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7840 | |
| 7841 | /* if the index wrapped around, toggle the valid bit */ |
| 7842 | if (phba->sli4_hba.pc_sli4_params.cqav && !idx) |
| 7843 | qe_valid = (qe_valid) ? 0 : 1; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7844 | } |
| 7845 | return pending_completions; |
| 7846 | |
| 7847 | } |
| 7848 | |
| 7849 | /** |
| 7850 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 7851 | * that were missed. |
| 7852 | * @phba: Pointer to HBA context object. |
| 7853 | * |
| 7854 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 7855 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 7856 | * checks to see if mbox completions are on the mailbox completion queue |
| 7857 | * and will process all the completions associated with the eq for the |
| 7858 | * mailbox completion queue. |
| 7859 | **/ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 7860 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7861 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 7862 | { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7863 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7864 | uint32_t eqidx; |
| 7865 | struct lpfc_queue *fpeq = NULL; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 7866 | struct lpfc_queue *eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7867 | bool mbox_pending; |
| 7868 | |
| 7869 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7870 | return false; |
| 7871 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 7872 | /* Find the EQ associated with the mbox CQ */ |
| 7873 | if (sli4_hba->hdwq) { |
| 7874 | for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) { |
| 7875 | eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq; |
| 7876 | if (eq->queue_id == sli4_hba->mbx_cq->assoc_qid) { |
| 7877 | fpeq = eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7878 | break; |
| 7879 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 7880 | } |
| 7881 | } |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7882 | if (!fpeq) |
| 7883 | return false; |
| 7884 | |
| 7885 | /* Turn off interrupts from this EQ */ |
| 7886 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7887 | sli4_hba->sli4_eq_clr_intr(fpeq); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7888 | |
| 7889 | /* Check to see if a mbox completion is pending */ |
| 7890 | |
| 7891 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 7892 | |
| 7893 | /* |
| 7894 | * If a mbox completion is pending, process all the events on EQ |
| 7895 | * associated with the mbox completion queue (this could include |
| 7896 | * mailbox commands, async events, els commands, receive queue data |
| 7897 | * and fcp commands) |
| 7898 | */ |
| 7899 | |
| 7900 | if (mbox_pending) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7901 | /* process and rearm the EQ */ |
| 7902 | lpfc_sli4_process_eq(phba, fpeq); |
| 7903 | else |
| 7904 | /* Always clear and re-arm the EQ */ |
| 7905 | sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7906 | |
| 7907 | return mbox_pending; |
| 7908 | |
| 7909 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7910 | |
| 7911 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7912 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7913 | * @phba: Pointer to HBA context object. |
| 7914 | * |
| 7915 | * This function is called from worker thread when a mailbox command times out. |
| 7916 | * The caller is not required to hold any locks. This function will reset the |
| 7917 | * HBA and recover all the pending commands. |
| 7918 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7919 | void |
| 7920 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 7921 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7922 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7923 | MAILBOX_t *mb = NULL; |
| 7924 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7925 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7926 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7927 | /* If the mailbox completed, process the completion and return */ |
| 7928 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 7929 | return; |
| 7930 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7931 | if (pmbox != NULL) |
| 7932 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7933 | /* Check the pmbox pointer first. There is a race condition |
| 7934 | * between the mbox timeout handler getting executed in the |
| 7935 | * worklist and the mailbox actually completing. When this |
| 7936 | * race condition occurs, the mbox_active will be NULL. |
| 7937 | */ |
| 7938 | spin_lock_irq(&phba->hbalock); |
| 7939 | if (pmbox == NULL) { |
| 7940 | lpfc_printf_log(phba, KERN_WARNING, |
| 7941 | LOG_MBOX | LOG_SLI, |
| 7942 | "0353 Active Mailbox cleared - mailbox timeout " |
| 7943 | "exiting\n"); |
| 7944 | spin_unlock_irq(&phba->hbalock); |
| 7945 | return; |
| 7946 | } |
| 7947 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7948 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7949 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 7950 | "0310 Mailbox command x%x timeout Data: x%x x%x x%px\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7951 | mb->mbxCommand, |
| 7952 | phba->pport->port_state, |
| 7953 | phba->sli.sli_flag, |
| 7954 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7955 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7956 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7957 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 7958 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7959 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7960 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7961 | spin_lock_irq(&phba->pport->work_port_lock); |
| 7962 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 7963 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 7964 | spin_lock_irq(&phba->hbalock); |
| 7965 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 7966 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7967 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7968 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 7969 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7970 | |
| 7971 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 7972 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7973 | |
| 7974 | /* Reset the HBA device */ |
| 7975 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7976 | } |
| 7977 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7978 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7979 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7980 | * @phba: Pointer to HBA context object. |
| 7981 | * @pmbox: Pointer to mailbox object. |
| 7982 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7983 | * |
| 7984 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7985 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 7986 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7987 | * The mailbox command can be submitted in polling mode, in which case |
| 7988 | * this function will wait in a polling loop for the completion of the |
| 7989 | * mailbox. |
| 7990 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 7991 | * function will submit the command and returns immediately without waiting |
| 7992 | * for the mailbox completion. The no_wait is supported only when HBA |
| 7993 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 7994 | * The SLI interface allows only one mailbox pending at a time. If the |
| 7995 | * mailbox is issued in polling mode and there is already a mailbox |
| 7996 | * pending, then the function will return an error. If the mailbox is issued |
| 7997 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 7998 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 7999 | * The sli layer owns the mailbox object until the completion of mailbox |
| 8000 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 8001 | * return codes the caller owns the mailbox command after the return of |
| 8002 | * the function. |
| 8003 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8004 | static int |
| 8005 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 8006 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8007 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8008 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8009 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8010 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8011 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8012 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8013 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8014 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8015 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8016 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8017 | int processing_queue = 0; |
| 8018 | |
| 8019 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8020 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 8021 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8022 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8023 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8024 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8025 | return MBX_SUCCESS; |
| 8026 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8027 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8028 | pmbox = lpfc_mbox_get(phba); |
| 8029 | if (!pmbox) { |
| 8030 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8031 | return MBX_SUCCESS; |
| 8032 | } |
| 8033 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8034 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8035 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8036 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8037 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8038 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8039 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8040 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8041 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8042 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8043 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8044 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8045 | } |
| 8046 | } |
| 8047 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8048 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8049 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 8050 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8051 | goto out_not_finished; |
| 8052 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8053 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8054 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8055 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 8056 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8057 | goto out_not_finished; |
| 8058 | } |
| 8059 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8060 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8061 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8062 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8063 | status = MBX_SUCCESS; |
| 8064 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8065 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 8066 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8067 | |
| 8068 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8069 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8070 | "(%d):0311 Mailbox command x%x cannot " |
| 8071 | "issue Data: x%x x%x\n", |
| 8072 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8073 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8074 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8075 | } |
| 8076 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8077 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8078 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 8079 | !(hc_copy & HC_MBINT_ENA)) { |
| 8080 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8081 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8082 | "(%d):2528 Mailbox command x%x cannot " |
| 8083 | "issue Data: x%x x%x\n", |
| 8084 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8085 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8086 | goto out_not_finished; |
| 8087 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 8088 | } |
| 8089 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8090 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8091 | /* Polling for a mbox command when another one is already active |
| 8092 | * is not allowed in SLI. Also, the driver must have established |
| 8093 | * SLI2 mode to queue and process multiple mbox commands. |
| 8094 | */ |
| 8095 | |
| 8096 | if (flag & MBX_POLL) { |
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 | |
| 8099 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8100 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8101 | "(%d):2529 Mailbox command x%x " |
| 8102 | "cannot issue Data: x%x x%x\n", |
| 8103 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8104 | pmbox->u.mb.mbxCommand, |
| 8105 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8106 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8107 | } |
| 8108 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8109 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8110 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8111 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8112 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8113 | "(%d):2530 Mailbox command x%x " |
| 8114 | "cannot issue Data: x%x x%x\n", |
| 8115 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8116 | pmbox->u.mb.mbxCommand, |
| 8117 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8118 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8119 | } |
| 8120 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8121 | /* Another mailbox command is still being processed, queue this |
| 8122 | * command to be processed later. |
| 8123 | */ |
| 8124 | lpfc_mbox_put(phba, pmbox); |
| 8125 | |
| 8126 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8127 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8128 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8129 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8130 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8131 | mbx->mbxCommand, |
| 8132 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8133 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8134 | |
| 8135 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8136 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8137 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8138 | if (pmbox->vport) { |
| 8139 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8140 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8141 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8142 | (uint32_t)mbx->mbxCommand, |
| 8143 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8144 | } |
| 8145 | else { |
| 8146 | lpfc_debugfs_disc_trc(phba->pport, |
| 8147 | LPFC_DISC_TRC_MBOX, |
| 8148 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8149 | (uint32_t)mbx->mbxCommand, |
| 8150 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8151 | } |
| 8152 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8153 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8154 | } |
| 8155 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8156 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8157 | |
| 8158 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 8159 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8160 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8161 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8162 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8163 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8164 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8165 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8166 | "(%d):2531 Mailbox command x%x " |
| 8167 | "cannot issue Data: x%x x%x\n", |
| 8168 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8169 | pmbox->u.mb.mbxCommand, |
| 8170 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8171 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8172 | } |
| 8173 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8174 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8175 | 1000); |
| 8176 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8177 | } |
| 8178 | |
| 8179 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8180 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8181 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8182 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8183 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8184 | mbx->mbxCommand, |
| 8185 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8186 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8187 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8188 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8189 | if (pmbox->vport) { |
| 8190 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8191 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8192 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8193 | (uint32_t)mbx->mbxCommand, |
| 8194 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8195 | } |
| 8196 | else { |
| 8197 | lpfc_debugfs_disc_trc(phba->pport, |
| 8198 | LPFC_DISC_TRC_MBOX, |
| 8199 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8200 | (uint32_t)mbx->mbxCommand, |
| 8201 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8202 | } |
| 8203 | } |
| 8204 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8205 | psli->slistat.mbox_cmd++; |
| 8206 | evtctr = psli->slistat.mbox_event; |
| 8207 | |
| 8208 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8209 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8210 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8211 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8212 | /* Populate mbox extension offset word. */ |
| 8213 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8214 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8215 | = (uint8_t *)phba->mbox_ext |
| 8216 | - (uint8_t *)phba->mbox; |
| 8217 | } |
| 8218 | |
| 8219 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8220 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) { |
| 8221 | lpfc_sli_pcimem_bcopy(pmbox->ctx_buf, |
| 8222 | (uint8_t *)phba->mbox_ext, |
| 8223 | pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8224 | } |
| 8225 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8226 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8227 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8228 | /* Populate mbox extension offset word. */ |
| 8229 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8230 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8231 | = MAILBOX_HBA_EXT_OFFSET; |
| 8232 | |
| 8233 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8234 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8235 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 8236 | MAILBOX_HBA_EXT_OFFSET, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8237 | pmbox->ctx_buf, pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8238 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8239 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8240 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8241 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 8242 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8243 | |
| 8244 | /* First copy mbox command data to HBA SLIM, skip past first |
| 8245 | word */ |
| 8246 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8247 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8248 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 8249 | |
| 8250 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8251 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8252 | to_slim = phba->MBslimaddr; |
| 8253 | writel(ldata, to_slim); |
| 8254 | readl(to_slim); /* flush */ |
| 8255 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8256 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8257 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8258 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8259 | } |
| 8260 | |
| 8261 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8262 | |
| 8263 | switch (flag) { |
| 8264 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8265 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8266 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8267 | /* Interrupt board to do it */ |
| 8268 | writel(CA_MBATT, phba->CAregaddr); |
| 8269 | readl(phba->CAregaddr); /* flush */ |
| 8270 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8271 | break; |
| 8272 | |
| 8273 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8274 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8275 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8276 | /* Interrupt board to do it */ |
| 8277 | writel(CA_MBATT, phba->CAregaddr); |
| 8278 | readl(phba->CAregaddr); /* flush */ |
| 8279 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8280 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8281 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8282 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8283 | word0 = le32_to_cpu(word0); |
| 8284 | } else { |
| 8285 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8286 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 8287 | spin_unlock_irqrestore(&phba->hbalock, |
| 8288 | drvr_flag); |
| 8289 | goto out_not_finished; |
| 8290 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8291 | } |
| 8292 | |
| 8293 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8294 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8295 | spin_unlock_irqrestore(&phba->hbalock, |
| 8296 | drvr_flag); |
| 8297 | goto out_not_finished; |
| 8298 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8299 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8300 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8301 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8302 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8303 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 8304 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8305 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8306 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8307 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8308 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8309 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8310 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8311 | } |
| 8312 | |
| 8313 | /* Check if we took a mbox interrupt while we were |
| 8314 | polling */ |
| 8315 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 8316 | && (evtctr != psli->slistat.mbox_event)) |
| 8317 | break; |
| 8318 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8319 | if (i++ > 10) { |
| 8320 | spin_unlock_irqrestore(&phba->hbalock, |
| 8321 | drvr_flag); |
| 8322 | msleep(1); |
| 8323 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8324 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8325 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8326 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8327 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8328 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8329 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8330 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8331 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8332 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8333 | /* Check real SLIM for any errors */ |
| 8334 | slimword0 = readl(phba->MBslimaddr); |
| 8335 | slimmb = (MAILBOX_t *) & slimword0; |
| 8336 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 8337 | && slimmb->mbxStatus) { |
| 8338 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8339 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8340 | word0 = slimword0; |
| 8341 | } |
| 8342 | } |
| 8343 | } else { |
| 8344 | /* First copy command data */ |
| 8345 | word0 = readl(phba->MBslimaddr); |
| 8346 | } |
| 8347 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8348 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8349 | spin_unlock_irqrestore(&phba->hbalock, |
| 8350 | drvr_flag); |
| 8351 | goto out_not_finished; |
| 8352 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8353 | } |
| 8354 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8355 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8356 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8357 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 8358 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8359 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8360 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8361 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8362 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8363 | pmbox->out_ext_byte_len); |
| 8364 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8365 | } else { |
| 8366 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8367 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8368 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8369 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8370 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
| 8371 | lpfc_memcpy_from_slim( |
| 8372 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8373 | phba->MBslimaddr + |
| 8374 | MAILBOX_HBA_EXT_OFFSET, |
| 8375 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8376 | } |
| 8377 | } |
| 8378 | |
| 8379 | writel(HA_MBATT, phba->HAregaddr); |
| 8380 | readl(phba->HAregaddr); /* flush */ |
| 8381 | |
| 8382 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8383 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8384 | } |
| 8385 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8386 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8387 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8388 | |
| 8389 | out_not_finished: |
| 8390 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8391 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8392 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 8393 | } |
| 8394 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8395 | } |
| 8396 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8397 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8398 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 8399 | * @phba: Pointer to HBA context object. |
| 8400 | * |
| 8401 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 8402 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 8403 | * possible outstanding mailbox command before return. |
| 8404 | * |
| 8405 | * Returns: |
| 8406 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 8407 | * the outstanding mailbox command timed out. |
| 8408 | **/ |
| 8409 | static int |
| 8410 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 8411 | { |
| 8412 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8413 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8414 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8415 | |
| 8416 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 8417 | spin_lock_irq(&phba->hbalock); |
| 8418 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8419 | /* Determine how long we might wait for the active mailbox |
| 8420 | * command to be gracefully completed by firmware. |
| 8421 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8422 | if (phba->sli.mbox_active) |
| 8423 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 8424 | phba->sli.mbox_active) * |
| 8425 | 1000) + jiffies; |
| 8426 | spin_unlock_irq(&phba->hbalock); |
| 8427 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8428 | /* Make sure the mailbox is really active */ |
| 8429 | if (timeout) |
| 8430 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 8431 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8432 | /* Wait for the outstnading mailbox command to complete */ |
| 8433 | while (phba->sli.mbox_active) { |
| 8434 | /* Check active mailbox complete status every 2ms */ |
| 8435 | msleep(2); |
| 8436 | if (time_after(jiffies, timeout)) { |
| 8437 | /* Timeout, marked the outstanding cmd not complete */ |
| 8438 | rc = 1; |
| 8439 | break; |
| 8440 | } |
| 8441 | } |
| 8442 | |
| 8443 | /* Can not cleanly block async mailbox command, fails it */ |
| 8444 | if (rc) { |
| 8445 | spin_lock_irq(&phba->hbalock); |
| 8446 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8447 | spin_unlock_irq(&phba->hbalock); |
| 8448 | } |
| 8449 | return rc; |
| 8450 | } |
| 8451 | |
| 8452 | /** |
| 8453 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 8454 | * @phba: Pointer to HBA context object. |
| 8455 | * |
| 8456 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 8457 | * commands from the driver internal pending mailbox queue. It makes sure |
| 8458 | * that there is no outstanding mailbox command before resuming posting |
| 8459 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 8460 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 8461 | * mailbox command posting. |
| 8462 | **/ |
| 8463 | static void |
| 8464 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 8465 | { |
| 8466 | struct lpfc_sli *psli = &phba->sli; |
| 8467 | |
| 8468 | spin_lock_irq(&phba->hbalock); |
| 8469 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8470 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 8471 | spin_unlock_irq(&phba->hbalock); |
| 8472 | return; |
| 8473 | } |
| 8474 | |
| 8475 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 8476 | * successful or timeout, after timing-out the outstanding mailbox |
| 8477 | * command shall always be removed, so just unblock posting async |
| 8478 | * mailbox command and resume |
| 8479 | */ |
| 8480 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8481 | spin_unlock_irq(&phba->hbalock); |
| 8482 | |
| 8483 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 8484 | lpfc_worker_wake_up(phba); |
| 8485 | } |
| 8486 | |
| 8487 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8488 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 8489 | * @phba: Pointer to HBA context object. |
| 8490 | * @mboxq: Pointer to mailbox object. |
| 8491 | * |
| 8492 | * The function waits for the bootstrap mailbox register ready bit from |
| 8493 | * port for twice the regular mailbox command timeout value. |
| 8494 | * |
| 8495 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 8496 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 8497 | **/ |
| 8498 | static int |
| 8499 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8500 | { |
| 8501 | uint32_t db_ready; |
| 8502 | unsigned long timeout; |
| 8503 | struct lpfc_register bmbx_reg; |
| 8504 | |
| 8505 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 8506 | * 1000) + jiffies; |
| 8507 | |
| 8508 | do { |
| 8509 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 8510 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 8511 | if (!db_ready) |
James Smart | e2ffe4d | 2019-03-12 16:30:15 -0700 | [diff] [blame] | 8512 | mdelay(2); |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8513 | |
| 8514 | if (time_after(jiffies, timeout)) |
| 8515 | return MBXERR_ERROR; |
| 8516 | } while (!db_ready); |
| 8517 | |
| 8518 | return 0; |
| 8519 | } |
| 8520 | |
| 8521 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8522 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 8523 | * @phba: Pointer to HBA context object. |
| 8524 | * @mboxq: Pointer to mailbox object. |
| 8525 | * |
| 8526 | * The function posts a mailbox to the port. The mailbox is expected |
| 8527 | * to be comletely filled in and ready for the port to operate on it. |
| 8528 | * This routine executes a synchronous completion operation on the |
| 8529 | * mailbox by polling for its completion. |
| 8530 | * |
| 8531 | * The caller must not be holding any locks when calling this routine. |
| 8532 | * |
| 8533 | * Returns: |
| 8534 | * MBX_SUCCESS - mailbox posted successfully |
| 8535 | * Any of the MBX error values. |
| 8536 | **/ |
| 8537 | static int |
| 8538 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8539 | { |
| 8540 | int rc = MBX_SUCCESS; |
| 8541 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8542 | uint32_t mcqe_status; |
| 8543 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8544 | struct lpfc_sli *psli = &phba->sli; |
| 8545 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 8546 | struct lpfc_bmbx_create *mbox_rgn; |
| 8547 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8548 | |
| 8549 | /* |
| 8550 | * Only one mailbox can be active to the bootstrap mailbox region |
| 8551 | * at a time and there is no queueing provided. |
| 8552 | */ |
| 8553 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8554 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8555 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8556 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8557 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8558 | "cannot issue Data: x%x x%x\n", |
| 8559 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8560 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8561 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8562 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8563 | psli->sli_flag, MBX_POLL); |
| 8564 | return MBXERR_ERROR; |
| 8565 | } |
| 8566 | /* The server grabs the token and owns it until release */ |
| 8567 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8568 | phba->sli.mbox_active = mboxq; |
| 8569 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8570 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8571 | /* wait for bootstrap mbox register for readyness */ |
| 8572 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8573 | if (rc) |
| 8574 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8575 | /* |
| 8576 | * Initialize the bootstrap memory region to avoid stale data areas |
| 8577 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 8578 | * the bmbx mailbox region. |
| 8579 | */ |
| 8580 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 8581 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8582 | lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 8583 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8584 | |
| 8585 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 8586 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8587 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 8588 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8589 | /* wait for bootstrap mbox register for hi-address write done */ |
| 8590 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8591 | if (rc) |
| 8592 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8593 | |
| 8594 | /* Post the low mailbox dma address to the port. */ |
| 8595 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8596 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8597 | /* wait for bootstrap mbox register for low address write done */ |
| 8598 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8599 | if (rc) |
| 8600 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8601 | |
| 8602 | /* |
| 8603 | * Read the CQ to ensure the mailbox has completed. |
| 8604 | * If so, update the mailbox status so that the upper layers |
| 8605 | * can complete the request normally. |
| 8606 | */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8607 | lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 8608 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8609 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8610 | lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 8611 | sizeof(struct lpfc_mcqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8612 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8613 | /* |
| 8614 | * When the CQE status indicates a failure and the mailbox status |
| 8615 | * indicates success then copy the CQE status into the mailbox status |
| 8616 | * (and prefix it with x4000). |
| 8617 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8618 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8619 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 8620 | bf_set(lpfc_mqe_status, mb, |
| 8621 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8622 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8623 | } else |
| 8624 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8625 | |
| 8626 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8627 | "(%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] | 8628 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 8629 | " 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] | 8630 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 8631 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8632 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8633 | bf_get(lpfc_mqe_status, mb), |
| 8634 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 8635 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 8636 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 8637 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 8638 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 8639 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 8640 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 8641 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 8642 | mboxq->mcqe.trailer); |
| 8643 | exit: |
| 8644 | /* We are holding the token, no needed for lock when release */ |
| 8645 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8646 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8647 | phba->sli.mbox_active = NULL; |
| 8648 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8649 | return rc; |
| 8650 | } |
| 8651 | |
| 8652 | /** |
| 8653 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 8654 | * @phba: Pointer to HBA context object. |
| 8655 | * @pmbox: Pointer to mailbox object. |
| 8656 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8657 | * |
| 8658 | * This function is called by discovery code and HBA management code to submit |
| 8659 | * a mailbox command to firmware with SLI-4 interface spec. |
| 8660 | * |
| 8661 | * Return codes the caller owns the mailbox command after the return of the |
| 8662 | * function. |
| 8663 | **/ |
| 8664 | static int |
| 8665 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 8666 | uint32_t flag) |
| 8667 | { |
| 8668 | struct lpfc_sli *psli = &phba->sli; |
| 8669 | unsigned long iflags; |
| 8670 | int rc; |
| 8671 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 8672 | /* dump from issue mailbox command if setup */ |
| 8673 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 8674 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8675 | rc = lpfc_mbox_dev_check(phba); |
| 8676 | if (unlikely(rc)) { |
| 8677 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8678 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8679 | "cannot issue Data: x%x x%x\n", |
| 8680 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8681 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8682 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8683 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8684 | psli->sli_flag, flag); |
| 8685 | goto out_not_finished; |
| 8686 | } |
| 8687 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8688 | /* Detect polling mode and jump to a handler */ |
| 8689 | if (!phba->sli4_hba.intr_enable) { |
| 8690 | if (flag == MBX_POLL) |
| 8691 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8692 | else |
| 8693 | rc = -EIO; |
| 8694 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8695 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8696 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8697 | "(x%x/x%x) failure: " |
| 8698 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8699 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8700 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8701 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8702 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8703 | mboxq), |
| 8704 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8705 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8706 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8707 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8708 | bf_get(lpfc_mcqe_ext_status, |
| 8709 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8710 | psli->sli_flag, flag); |
| 8711 | return rc; |
| 8712 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8713 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8714 | "(%d):2542 Try to issue mailbox command " |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8715 | "x%x (x%x/x%x) synchronously ahead of async " |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8716 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8717 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8718 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8719 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8720 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8721 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8722 | /* Try to block the asynchronous mailbox posting */ |
| 8723 | rc = lpfc_sli4_async_mbox_block(phba); |
| 8724 | if (!rc) { |
| 8725 | /* Successfully blocked, now issue sync mbox cmd */ |
| 8726 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8727 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8728 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8729 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8730 | "(%d):2597 Sync Mailbox command " |
| 8731 | "x%x (x%x/x%x) failure: " |
| 8732 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8733 | "Data: x%x x%x\n,", |
| 8734 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8735 | mboxq->u.mb.mbxCommand, |
| 8736 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8737 | mboxq), |
| 8738 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8739 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8740 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8741 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8742 | bf_get(lpfc_mcqe_ext_status, |
| 8743 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8744 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8745 | /* Unblock the async mailbox posting afterward */ |
| 8746 | lpfc_sli4_async_mbox_unblock(phba); |
| 8747 | } |
| 8748 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8749 | } |
| 8750 | |
| 8751 | /* Now, interrupt mode asynchrous mailbox command */ |
| 8752 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 8753 | if (rc) { |
| 8754 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8755 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8756 | "cannot issue Data: x%x x%x\n", |
| 8757 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8758 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8759 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8760 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8761 | psli->sli_flag, flag); |
| 8762 | goto out_not_finished; |
| 8763 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8764 | |
| 8765 | /* Put the mailbox command to the driver internal FIFO */ |
| 8766 | psli->slistat.mbox_busy++; |
| 8767 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8768 | lpfc_mbox_put(phba, mboxq); |
| 8769 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8770 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8771 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8772 | "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] | 8773 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 8774 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8775 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8776 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8777 | phba->pport->port_state, |
| 8778 | psli->sli_flag, MBX_NOWAIT); |
| 8779 | /* Wake up worker thread to transport mailbox command from head */ |
| 8780 | lpfc_worker_wake_up(phba); |
| 8781 | |
| 8782 | return MBX_BUSY; |
| 8783 | |
| 8784 | out_not_finished: |
| 8785 | return MBX_NOT_FINISHED; |
| 8786 | } |
| 8787 | |
| 8788 | /** |
| 8789 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 8790 | * @phba: Pointer to HBA context object. |
| 8791 | * |
| 8792 | * This function is called by worker thread to send a mailbox command to |
| 8793 | * SLI4 HBA firmware. |
| 8794 | * |
| 8795 | **/ |
| 8796 | int |
| 8797 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 8798 | { |
| 8799 | struct lpfc_sli *psli = &phba->sli; |
| 8800 | LPFC_MBOXQ_t *mboxq; |
| 8801 | int rc = MBX_SUCCESS; |
| 8802 | unsigned long iflags; |
| 8803 | struct lpfc_mqe *mqe; |
| 8804 | uint32_t mbx_cmnd; |
| 8805 | |
| 8806 | /* Check interrupt mode before post async mailbox command */ |
| 8807 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 8808 | return MBX_NOT_FINISHED; |
| 8809 | |
| 8810 | /* Check for mailbox command service token */ |
| 8811 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8812 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8813 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8814 | return MBX_NOT_FINISHED; |
| 8815 | } |
| 8816 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8817 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8818 | return MBX_NOT_FINISHED; |
| 8819 | } |
| 8820 | if (unlikely(phba->sli.mbox_active)) { |
| 8821 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8822 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8823 | "0384 There is pending active mailbox cmd\n"); |
| 8824 | return MBX_NOT_FINISHED; |
| 8825 | } |
| 8826 | /* Take the mailbox command service token */ |
| 8827 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8828 | |
| 8829 | /* Get the next mailbox command from head of queue */ |
| 8830 | mboxq = lpfc_mbox_get(phba); |
| 8831 | |
| 8832 | /* If no more mailbox command waiting for post, we're done */ |
| 8833 | if (!mboxq) { |
| 8834 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8835 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8836 | return MBX_SUCCESS; |
| 8837 | } |
| 8838 | phba->sli.mbox_active = mboxq; |
| 8839 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8840 | |
| 8841 | /* Check device readiness for posting mailbox command */ |
| 8842 | rc = lpfc_mbox_dev_check(phba); |
| 8843 | if (unlikely(rc)) |
| 8844 | /* Driver clean routine will clean up pending mailbox */ |
| 8845 | goto out_not_finished; |
| 8846 | |
| 8847 | /* Prepare the mbox command to be posted */ |
| 8848 | mqe = &mboxq->u.mqe; |
| 8849 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 8850 | |
| 8851 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 8852 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8853 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8854 | |
| 8855 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8856 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8857 | "x%x x%x\n", |
| 8858 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8859 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8860 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8861 | phba->pport->port_state, psli->sli_flag); |
| 8862 | |
| 8863 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 8864 | if (mboxq->vport) { |
| 8865 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 8866 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8867 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 8868 | mbx_cmnd, mqe->un.mb_words[0], |
| 8869 | mqe->un.mb_words[1]); |
| 8870 | } else { |
| 8871 | lpfc_debugfs_disc_trc(phba->pport, |
| 8872 | LPFC_DISC_TRC_MBOX, |
| 8873 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 8874 | mbx_cmnd, mqe->un.mb_words[0], |
| 8875 | mqe->un.mb_words[1]); |
| 8876 | } |
| 8877 | } |
| 8878 | psli->slistat.mbox_cmd++; |
| 8879 | |
| 8880 | /* Post the mailbox command to the port */ |
| 8881 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 8882 | if (rc != MBX_SUCCESS) { |
| 8883 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8884 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8885 | "cannot issue Data: x%x x%x\n", |
| 8886 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8887 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8888 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8889 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8890 | psli->sli_flag, MBX_NOWAIT); |
| 8891 | goto out_not_finished; |
| 8892 | } |
| 8893 | |
| 8894 | return rc; |
| 8895 | |
| 8896 | out_not_finished: |
| 8897 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 8898 | if (phba->sli.mbox_active) { |
| 8899 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8900 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8901 | /* Release the token */ |
| 8902 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8903 | phba->sli.mbox_active = NULL; |
| 8904 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8905 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8906 | |
| 8907 | return MBX_NOT_FINISHED; |
| 8908 | } |
| 8909 | |
| 8910 | /** |
| 8911 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 8912 | * @phba: Pointer to HBA context object. |
| 8913 | * @pmbox: Pointer to mailbox object. |
| 8914 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8915 | * |
| 8916 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 8917 | * the API jump table function pointer from the lpfc_hba struct. |
| 8918 | * |
| 8919 | * Return codes the caller owns the mailbox command after the return of the |
| 8920 | * function. |
| 8921 | **/ |
| 8922 | int |
| 8923 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 8924 | { |
| 8925 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 8926 | } |
| 8927 | |
| 8928 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8929 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8930 | * @phba: The hba struct for which this call is being executed. |
| 8931 | * @dev_grp: The HBA PCI-Device group number. |
| 8932 | * |
| 8933 | * This routine sets up the mbox interface API function jump table in @phba |
| 8934 | * struct. |
| 8935 | * Returns: 0 - success, -ENODEV - failure. |
| 8936 | **/ |
| 8937 | int |
| 8938 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8939 | { |
| 8940 | |
| 8941 | switch (dev_grp) { |
| 8942 | case LPFC_PCI_DEV_LP: |
| 8943 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 8944 | phba->lpfc_sli_handle_slow_ring_event = |
| 8945 | lpfc_sli_handle_slow_ring_event_s3; |
| 8946 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 8947 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 8948 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 8949 | break; |
| 8950 | case LPFC_PCI_DEV_OC: |
| 8951 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 8952 | phba->lpfc_sli_handle_slow_ring_event = |
| 8953 | lpfc_sli_handle_slow_ring_event_s4; |
| 8954 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 8955 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 8956 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 8957 | break; |
| 8958 | default: |
| 8959 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8960 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 8961 | dev_grp); |
| 8962 | return -ENODEV; |
| 8963 | break; |
| 8964 | } |
| 8965 | return 0; |
| 8966 | } |
| 8967 | |
| 8968 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8969 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8970 | * @phba: Pointer to HBA context object. |
| 8971 | * @pring: Pointer to driver SLI ring object. |
| 8972 | * @piocb: Pointer to address of newly added command iocb. |
| 8973 | * |
| 8974 | * This function is called with hbalock held to add a command |
| 8975 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 8976 | * to the ring. |
| 8977 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8978 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8979 | __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] | 8980 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8981 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8982 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8983 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 8984 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8985 | } |
| 8986 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8987 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8988 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8989 | * @phba: Pointer to HBA context object. |
| 8990 | * @pring: Pointer to driver SLI ring object. |
| 8991 | * @piocb: Pointer to address of newly added command iocb. |
| 8992 | * |
| 8993 | * This function is called with hbalock held before a new |
| 8994 | * iocb is submitted to the firmware. This function checks |
| 8995 | * txq to flush the iocbs in txq to Firmware before |
| 8996 | * submitting new iocbs to the Firmware. |
| 8997 | * If there are iocbs in the txq which need to be submitted |
| 8998 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 8999 | * of the txq after dequeuing it from txq. |
| 9000 | * If there is no iocb in the txq then the function will return |
| 9001 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 9002 | * *piocb to find if there are more commands in the txq. |
| 9003 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9004 | static struct lpfc_iocbq * |
| 9005 | 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] | 9006 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9007 | { |
| 9008 | struct lpfc_iocbq * nextiocb; |
| 9009 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9010 | lockdep_assert_held(&phba->hbalock); |
| 9011 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9012 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 9013 | if (!nextiocb) { |
| 9014 | nextiocb = *piocb; |
| 9015 | *piocb = NULL; |
| 9016 | } |
| 9017 | |
| 9018 | return nextiocb; |
| 9019 | } |
| 9020 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9021 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9022 | * __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] | 9023 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9024 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9025 | * @piocb: Pointer to command iocb. |
| 9026 | * @flag: Flag indicating if this command can be put into txq. |
| 9027 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9028 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 9029 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 9030 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 9031 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 9032 | * this function allows only iocbs for posting buffers. This function finds |
| 9033 | * next available slot in the command ring and posts the command to the |
| 9034 | * available slot and writes the port attention register to request HBA start |
| 9035 | * processing new iocb. If there is no slot available in the ring and |
| 9036 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 9037 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9038 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9039 | * This function is called with hbalock held. The function will return success |
| 9040 | * after it successfully submit the iocb to firmware or after adding to the |
| 9041 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9042 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9043 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9044 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9045 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9046 | { |
| 9047 | struct lpfc_iocbq *nextiocb; |
| 9048 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9049 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9050 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9051 | lockdep_assert_held(&phba->hbalock); |
| 9052 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9053 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 9054 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 9055 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 9056 | lpfc_printf_log(phba, KERN_ERR, |
| 9057 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9058 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9059 | piocb->iocb.ulpCommand); |
| 9060 | dump_stack(); |
| 9061 | return IOCB_ERROR; |
| 9062 | } |
| 9063 | |
| 9064 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9065 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 9066 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 9067 | return IOCB_ERROR; |
| 9068 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9069 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 9070 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 9071 | return IOCB_ERROR; |
| 9072 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9073 | /* |
| 9074 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 9075 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9076 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9077 | return IOCB_ERROR; |
| 9078 | |
| 9079 | /* |
| 9080 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9081 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9082 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9083 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9084 | goto iocb_busy; |
| 9085 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9086 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9087 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9088 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9089 | * can be issued if the link is not up. |
| 9090 | */ |
| 9091 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9092 | case CMD_GEN_REQUEST64_CR: |
| 9093 | case CMD_GEN_REQUEST64_CX: |
| 9094 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 9095 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9096 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9097 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 9098 | MENLO_TRANSPORT_TYPE)) |
| 9099 | |
| 9100 | goto iocb_busy; |
| 9101 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9102 | case CMD_QUE_RING_BUF_CN: |
| 9103 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9104 | /* |
| 9105 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 9106 | * completion, iocb_cmpl MUST be 0. |
| 9107 | */ |
| 9108 | if (piocb->iocb_cmpl) |
| 9109 | piocb->iocb_cmpl = NULL; |
| 9110 | /*FALLTHROUGH*/ |
| 9111 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9112 | case CMD_CLOSE_XRI_CN: |
| 9113 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9114 | break; |
| 9115 | default: |
| 9116 | goto iocb_busy; |
| 9117 | } |
| 9118 | |
| 9119 | /* |
| 9120 | * For FCP commands, we must be in a state where we can process link |
| 9121 | * attention events. |
| 9122 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9123 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9124 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9125 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9126 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9127 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9128 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 9129 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 9130 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 9131 | |
| 9132 | if (iocb) |
| 9133 | lpfc_sli_update_ring(phba, pring); |
| 9134 | else |
| 9135 | lpfc_sli_update_full_ring(phba, pring); |
| 9136 | |
| 9137 | if (!piocb) |
| 9138 | return IOCB_SUCCESS; |
| 9139 | |
| 9140 | goto out_busy; |
| 9141 | |
| 9142 | iocb_busy: |
| 9143 | pring->stats.iocb_cmd_delay++; |
| 9144 | |
| 9145 | out_busy: |
| 9146 | |
| 9147 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9148 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9149 | return IOCB_SUCCESS; |
| 9150 | } |
| 9151 | |
| 9152 | return IOCB_BUSY; |
| 9153 | } |
| 9154 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9155 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9156 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 9157 | * @phba: Pointer to HBA context object. |
| 9158 | * @piocb: Pointer to command iocb. |
| 9159 | * @sglq: Pointer to the scatter gather queue object. |
| 9160 | * |
| 9161 | * This routine converts the bpl or bde that is in the IOCB |
| 9162 | * to a sgl list for the sli4 hardware. The physical address |
| 9163 | * of the bpl/bde is converted back to a virtual address. |
| 9164 | * If the IOCB contains a BPL then the list of BDE's is |
| 9165 | * converted to sli4_sge's. If the IOCB contains a single |
| 9166 | * BDE then it is converted to a single sli_sge. |
| 9167 | * The IOCB is still in cpu endianess so the contents of |
| 9168 | * the bpl can be used without byte swapping. |
| 9169 | * |
| 9170 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 9171 | **/ |
| 9172 | static uint16_t |
| 9173 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 9174 | struct lpfc_sglq *sglq) |
| 9175 | { |
| 9176 | uint16_t xritag = NO_XRI; |
| 9177 | struct ulp_bde64 *bpl = NULL; |
| 9178 | struct ulp_bde64 bde; |
| 9179 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9180 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9181 | IOCB_t *icmd; |
| 9182 | int numBdes = 0; |
| 9183 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9184 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 9185 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9186 | |
| 9187 | if (!piocbq || !sglq) |
| 9188 | return xritag; |
| 9189 | |
| 9190 | sgl = (struct sli4_sge *)sglq->sgl; |
| 9191 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9192 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 9193 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9194 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 9195 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 9196 | sizeof(struct ulp_bde64); |
| 9197 | /* The addrHigh and addrLow fields within the IOCB |
| 9198 | * have not been byteswapped yet so there is no |
| 9199 | * need to swap them back. |
| 9200 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9201 | if (piocbq->context3) |
| 9202 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 9203 | else |
| 9204 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9205 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9206 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9207 | if (!bpl) |
| 9208 | return xritag; |
| 9209 | |
| 9210 | for (i = 0; i < numBdes; i++) { |
| 9211 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9212 | sgl->addr_hi = bpl->addrHigh; |
| 9213 | sgl->addr_lo = bpl->addrLow; |
| 9214 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9215 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9216 | if ((i+1) == numBdes) |
| 9217 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9218 | else |
| 9219 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9220 | /* swap the size field back to the cpu so we |
| 9221 | * can assign it to the sgl. |
| 9222 | */ |
| 9223 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 9224 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9225 | /* The offsets in the sgl need to be accumulated |
| 9226 | * separately for the request and reply lists. |
| 9227 | * The request is always first, the reply follows. |
| 9228 | */ |
| 9229 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 9230 | /* add up the reply sg entries */ |
| 9231 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 9232 | inbound++; |
| 9233 | /* first inbound? reset the offset */ |
| 9234 | if (inbound == 1) |
| 9235 | offset = 0; |
| 9236 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 9237 | bf_set(lpfc_sli4_sge_type, sgl, |
| 9238 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9239 | offset += bde.tus.f.bdeSize; |
| 9240 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9241 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9242 | bpl++; |
| 9243 | sgl++; |
| 9244 | } |
| 9245 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 9246 | /* The addrHigh and addrLow fields of the BDE have not |
| 9247 | * been byteswapped yet so they need to be swapped |
| 9248 | * before putting them in the sgl. |
| 9249 | */ |
| 9250 | sgl->addr_hi = |
| 9251 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 9252 | sgl->addr_lo = |
| 9253 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9254 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9255 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9256 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9257 | sgl->sge_len = |
| 9258 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9259 | } |
| 9260 | return sglq->sli4_xritag; |
| 9261 | } |
| 9262 | |
| 9263 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9264 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 9265 | * @phba: Pointer to HBA context object. |
| 9266 | * @piocb: Pointer to command iocb. |
| 9267 | * @wqe: Pointer to the work queue entry. |
| 9268 | * |
| 9269 | * This routine converts the iocb command to its Work Queue Entry |
| 9270 | * equivalent. The wqe pointer should not have any fields set when |
| 9271 | * this routine is called because it will memcpy over them. |
| 9272 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 9273 | * wqe. |
| 9274 | * |
| 9275 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 9276 | **/ |
| 9277 | static int |
| 9278 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9279 | union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9280 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9281 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9282 | uint8_t ct = 0; |
| 9283 | uint32_t fip; |
| 9284 | uint32_t abort_tag; |
| 9285 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 9286 | uint8_t cmnd; |
| 9287 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9288 | uint16_t abrt_iotag; |
| 9289 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9290 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9291 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9292 | int numBdes, i; |
| 9293 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9294 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9295 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9296 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9297 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9298 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9299 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9300 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9301 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9302 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9303 | command_type = ELS_COMMAND_FIP; |
| 9304 | else |
| 9305 | command_type = ELS_COMMAND_NON_FIP; |
| 9306 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9307 | if (phba->fcp_embed_io) |
| 9308 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9309 | /* Some of the fields are in the right position already */ |
| 9310 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 9311 | /* The ct field has moved so reset */ |
| 9312 | wqe->generic.wqe_com.word7 = 0; |
| 9313 | wqe->generic.wqe_com.word10 = 0; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9314 | |
| 9315 | abort_tag = (uint32_t) iocbq->iotag; |
| 9316 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9317 | /* words0-2 bpl convert bde */ |
| 9318 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9319 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9320 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9321 | bpl = (struct ulp_bde64 *) |
| 9322 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 9323 | if (!bpl) |
| 9324 | return IOCB_ERROR; |
| 9325 | |
| 9326 | /* Should already be byte swapped. */ |
| 9327 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 9328 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 9329 | /* swap the size field back to the cpu so we |
| 9330 | * can assign it to the sgl. |
| 9331 | */ |
| 9332 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9333 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 9334 | total_len = 0; |
| 9335 | for (i = 0; i < numBdes; i++) { |
| 9336 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 9337 | total_len += bde.tus.f.bdeSize; |
| 9338 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9339 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9340 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9341 | |
| 9342 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 9343 | cmnd = iocbq->iocb.ulpCommand; |
| 9344 | |
| 9345 | switch (iocbq->iocb.ulpCommand) { |
| 9346 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 9347 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 9348 | ndlp = iocbq->context_un.ndlp; |
| 9349 | else |
| 9350 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9351 | if (!iocbq->iocb.ulpLe) { |
| 9352 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9353 | "2007 Only Limited Edition cmd Format" |
| 9354 | " supported 0x%x\n", |
| 9355 | iocbq->iocb.ulpCommand); |
| 9356 | return IOCB_ERROR; |
| 9357 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9358 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9359 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9360 | /* Els_reguest64 has a TMO */ |
| 9361 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 9362 | iocbq->iocb.ulpTimeout); |
| 9363 | /* Need a VF for word 4 set the vf bit*/ |
| 9364 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 9365 | /* And a VFID for word 12 */ |
| 9366 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9367 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9368 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9369 | iocbq->iocb.ulpContext); |
| 9370 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 9371 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9372 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9373 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9374 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 9375 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9376 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9377 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9378 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9379 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9380 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9381 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9382 | *pcmd == ELS_CMD_SCR || |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 9383 | *pcmd == ELS_CMD_RSCN_XMT || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9384 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 9385 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9386 | *pcmd == ELS_CMD_PLOGI)) { |
| 9387 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 9388 | bf_set(els_req64_sid, &wqe->els_req, |
| 9389 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9390 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 9391 | !(phba->fc_topology == |
| 9392 | LPFC_TOPOLOGY_LOOP)) |
| 9393 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9394 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 9395 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 9396 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 9397 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9398 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 9399 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9400 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 9401 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9402 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9403 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 9404 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9405 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 9406 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 9407 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9408 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 9409 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9410 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9411 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9412 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9413 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9414 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 9415 | iocbq->iocb.un.ulpWord[3]); |
| 9416 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9417 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9418 | /* The entire sequence is transmitted for this IOCB */ |
| 9419 | xmit_len = total_len; |
| 9420 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9421 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 9422 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 9423 | /* fall through */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9424 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9425 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 9426 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9427 | /* word4 relative_offset memcpy */ |
| 9428 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9429 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 9430 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 9431 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 9432 | LPFC_WQE_IOD_WRITE); |
| 9433 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 9434 | LPFC_WQE_LENLOC_WORD12); |
| 9435 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9436 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 9437 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9438 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9439 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9440 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 9441 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9442 | /* word4 iocb=rsvd wqe=rsvd */ |
| 9443 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 9444 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9445 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9446 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9447 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 9448 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9449 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 9450 | LPFC_WQE_LENLOC_WORD3); |
| 9451 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9452 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9453 | case CMD_FCP_IWRITE64_CR: |
| 9454 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9455 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9456 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9457 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 9458 | xmit_len + sizeof(struct fcp_rsp)); |
| 9459 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 9460 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9461 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9462 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9463 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 9464 | iocbq->iocb.ulpFCP2Rcvy); |
| 9465 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 9466 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9467 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9468 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 9469 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9470 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9471 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9472 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9473 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9474 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 9475 | if (iocbq->priority) { |
| 9476 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9477 | (iocbq->priority << 1)); |
| 9478 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9479 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9480 | (phba->cfg_XLanePriority << 1)); |
| 9481 | } |
| 9482 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9483 | /* Note, word 10 is already initialized to 0 */ |
| 9484 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9485 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9486 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9487 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); |
| 9488 | else |
| 9489 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 9490 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9491 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9492 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9493 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9494 | struct fcp_cmnd *fcp_cmnd; |
| 9495 | uint32_t *ptr; |
| 9496 | |
| 9497 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9498 | |
| 9499 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9500 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9501 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9502 | |
| 9503 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9504 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9505 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9506 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9507 | wqe->generic.bde.addrHigh = 0; |
| 9508 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9509 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9510 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 9511 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9512 | |
| 9513 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9514 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9515 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9516 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9517 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9518 | case CMD_FCP_IREAD64_CR: |
| 9519 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9520 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9521 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 9522 | xmit_len + sizeof(struct fcp_rsp)); |
| 9523 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 9524 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9525 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9526 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9527 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 9528 | iocbq->iocb.ulpFCP2Rcvy); |
| 9529 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9530 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9531 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 9532 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 9533 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9534 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9535 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9536 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9537 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9538 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 9539 | if (iocbq->priority) { |
| 9540 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9541 | (iocbq->priority << 1)); |
| 9542 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9543 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9544 | (phba->cfg_XLanePriority << 1)); |
| 9545 | } |
| 9546 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9547 | /* Note, word 10 is already initialized to 0 */ |
| 9548 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9549 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9550 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9551 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); |
| 9552 | else |
| 9553 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0); |
| 9554 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9555 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9556 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9557 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9558 | struct fcp_cmnd *fcp_cmnd; |
| 9559 | uint32_t *ptr; |
| 9560 | |
| 9561 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9562 | |
| 9563 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9564 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9565 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9566 | |
| 9567 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9568 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9569 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9570 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9571 | wqe->generic.bde.addrHigh = 0; |
| 9572 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9573 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9574 | bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); |
| 9575 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9576 | |
| 9577 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9578 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9579 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9580 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9581 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9582 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9583 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9584 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 9585 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 9586 | xmit_len + sizeof(struct fcp_rsp)); |
| 9587 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 9588 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9589 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9590 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9591 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9592 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 9593 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9594 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 9595 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 9596 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 9597 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 9598 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9599 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9600 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9601 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 9602 | if (iocbq->priority) { |
| 9603 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9604 | (iocbq->priority << 1)); |
| 9605 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9606 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9607 | (phba->cfg_XLanePriority << 1)); |
| 9608 | } |
| 9609 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9610 | /* Note, word 10 is already initialized to 0 */ |
| 9611 | |
| 9612 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9613 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9614 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9615 | struct fcp_cmnd *fcp_cmnd; |
| 9616 | uint32_t *ptr; |
| 9617 | |
| 9618 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9619 | |
| 9620 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9621 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9622 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9623 | |
| 9624 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9625 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9626 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9627 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9628 | wqe->generic.bde.addrHigh = 0; |
| 9629 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9630 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9631 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); |
| 9632 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9633 | |
| 9634 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9635 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9636 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9637 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9638 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9639 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9640 | /* For this command calculate the xmit length of the |
| 9641 | * request bde. |
| 9642 | */ |
| 9643 | xmit_len = 0; |
| 9644 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9645 | sizeof(struct ulp_bde64); |
| 9646 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9647 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9648 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 9649 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9650 | xmit_len += bde.tus.f.bdeSize; |
| 9651 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9652 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 9653 | wqe->gen_req.request_payload_len = xmit_len; |
| 9654 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 9655 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9656 | /* word6 context tag copied in memcpy */ |
| 9657 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 9658 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 9659 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9660 | "2015 Invalid CT %x command 0x%x\n", |
| 9661 | ct, iocbq->iocb.ulpCommand); |
| 9662 | return IOCB_ERROR; |
| 9663 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9664 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 9665 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 9666 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 9667 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 9668 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9669 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 9670 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9671 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9672 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9673 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9674 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9675 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9676 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9677 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9678 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 9679 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9680 | /* word4 */ |
| 9681 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9682 | /* word5 iocb=rsvd wge=did */ |
| 9683 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9684 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 9685 | |
| 9686 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9687 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9688 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9689 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 9690 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9691 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 9692 | iocbq->vport->fc_myDID); |
| 9693 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 9694 | bf_set(wqe_els_did, |
| 9695 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 9696 | } |
| 9697 | } |
| 9698 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9699 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 9700 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9701 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 9702 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9703 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9704 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9705 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9706 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9707 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9708 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9709 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9710 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 9711 | LPFC_WQE_LENLOC_WORD3); |
| 9712 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9713 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 9714 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9715 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9716 | iocbq->context2)->virt); |
| 9717 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9718 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9719 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9720 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9721 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9722 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9723 | phba->vpi_ids[phba->pport->vpi]); |
| 9724 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9725 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9726 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9727 | case CMD_CLOSE_XRI_CN: |
| 9728 | case CMD_ABORT_XRI_CN: |
| 9729 | case CMD_ABORT_XRI_CX: |
| 9730 | /* words 0-2 memcpy should be 0 rserved */ |
| 9731 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9732 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 9733 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 9734 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 9735 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 9736 | } else |
| 9737 | fip = 0; |
| 9738 | |
| 9739 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9740 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9741 | * The link is down, or the command was ELS_FIP |
| 9742 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9743 | * on the wire. |
| 9744 | */ |
| 9745 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 9746 | else |
| 9747 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 9748 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9749 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 9750 | wqe->abort_cmd.rsrvd5 = 0; |
| 9751 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9752 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9753 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9754 | /* |
| 9755 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 9756 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 9757 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9758 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 9759 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 9760 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 9761 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9762 | cmnd = CMD_ABORT_XRI_CX; |
| 9763 | command_type = OTHER_COMMAND; |
| 9764 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9765 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9766 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9767 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9768 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9769 | * we re-construct this WQE here based on information in |
| 9770 | * iocbq from scratch. |
| 9771 | */ |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 9772 | memset(wqe, 0, sizeof(*wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9773 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9774 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9775 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 9776 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9777 | LPFC_ABTS_UNSOL_INT) { |
| 9778 | /* ABTS sent by initiator to CT exchange, the |
| 9779 | * RX_ID field will be filled with the newly |
| 9780 | * allocated responder XRI. |
| 9781 | */ |
| 9782 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 9783 | iocbq->sli4_xritag); |
| 9784 | } else { |
| 9785 | /* ABTS sent by responder to CT exchange, the |
| 9786 | * RX_ID field will be filled with the responder |
| 9787 | * RX_ID from ABTS. |
| 9788 | */ |
| 9789 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9790 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9791 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9792 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 9793 | 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] | 9794 | |
| 9795 | /* Use CT=VPI */ |
| 9796 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 9797 | ndlp->nlp_DID); |
| 9798 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 9799 | iocbq->iocb.ulpContext); |
| 9800 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9801 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9802 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9803 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 9804 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 9805 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9806 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 9807 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9808 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 9809 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 9810 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 9811 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 9812 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 9813 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 9814 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 9815 | } |
| 9816 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9817 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9818 | case CMD_SEND_FRAME: |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 9819 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_SEND_FRAME); |
| 9820 | bf_set(wqe_sof, &wqe->generic.wqe_com, 0x2E); /* SOF byte */ |
| 9821 | bf_set(wqe_eof, &wqe->generic.wqe_com, 0x41); /* EOF byte */ |
| 9822 | bf_set(wqe_lenloc, &wqe->generic.wqe_com, 1); |
| 9823 | bf_set(wqe_xbl, &wqe->generic.wqe_com, 1); |
| 9824 | bf_set(wqe_dbde, &wqe->generic.wqe_com, 1); |
| 9825 | bf_set(wqe_xc, &wqe->generic.wqe_com, 1); |
| 9826 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 0xA); |
| 9827 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9828 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9829 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9830 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9831 | case CMD_XRI_ABORTED_CX: |
| 9832 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9833 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 9834 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 9835 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 9836 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 9837 | default: |
| 9838 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9839 | "2014 Invalid command 0x%x\n", |
| 9840 | iocbq->iocb.ulpCommand); |
| 9841 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9842 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9843 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9844 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 9845 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 9846 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 9847 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 9848 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 9849 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 9850 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 9851 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 9852 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9853 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9854 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9855 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 9856 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 9857 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 9858 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 9859 | 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] | 9860 | return 0; |
| 9861 | } |
| 9862 | |
| 9863 | /** |
| 9864 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 9865 | * @phba: Pointer to HBA context object. |
| 9866 | * @ring_number: SLI ring number to issue iocb on. |
| 9867 | * @piocb: Pointer to command iocb. |
| 9868 | * @flag: Flag indicating if this command can be put into txq. |
| 9869 | * |
| 9870 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 9871 | * an iocb command to an HBA with SLI-4 interface spec. |
| 9872 | * |
| 9873 | * This function is called with hbalock held. The function will return success |
| 9874 | * after it successfully submit the iocb to firmware or after adding to the |
| 9875 | * txq. |
| 9876 | **/ |
| 9877 | static int |
| 9878 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 9879 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9880 | { |
| 9881 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9882 | union lpfc_wqe128 wqe; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9883 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9884 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9885 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9886 | /* Get the WQ */ |
| 9887 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 9888 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9889 | wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9890 | } else { |
| 9891 | wq = phba->sli4_hba.els_wq; |
| 9892 | } |
| 9893 | |
| 9894 | /* Get corresponding ring */ |
| 9895 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9896 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9897 | /* |
| 9898 | * The WQE can be either 64 or 128 bytes, |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9899 | */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9900 | |
James Smart | cda7fa18 | 2019-03-04 15:15:43 -0800 | [diff] [blame] | 9901 | lockdep_assert_held(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9902 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9903 | if (piocb->sli4_xritag == NO_XRI) { |
| 9904 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9905 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9906 | sglq = NULL; |
| 9907 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9908 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9909 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9910 | __lpfc_sli_ringtx_put(phba, |
| 9911 | pring, piocb); |
| 9912 | return IOCB_SUCCESS; |
| 9913 | } else { |
| 9914 | return IOCB_BUSY; |
| 9915 | } |
| 9916 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9917 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9918 | if (!sglq) { |
| 9919 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9920 | __lpfc_sli_ringtx_put(phba, |
| 9921 | pring, |
| 9922 | piocb); |
| 9923 | return IOCB_SUCCESS; |
| 9924 | } else |
| 9925 | return IOCB_BUSY; |
| 9926 | } |
| 9927 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9928 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9929 | } else if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9930 | /* These IO's already have an XRI and a mapped sgl. */ |
| 9931 | sglq = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9932 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9933 | /* |
| 9934 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9935 | * sglq is on the active list |
| 9936 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 9937 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9938 | if (!sglq) |
| 9939 | return IOCB_ERROR; |
| 9940 | } |
| 9941 | |
| 9942 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9943 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9944 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9945 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9946 | return IOCB_ERROR; |
| 9947 | } |
| 9948 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9949 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9950 | return IOCB_ERROR; |
| 9951 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9952 | if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9953 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9954 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 9955 | |
| 9956 | return 0; |
| 9957 | } |
| 9958 | |
| 9959 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9960 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 9961 | * |
| 9962 | * This routine wraps the actual lockless version for issusing IOCB function |
| 9963 | * pointer from the lpfc_hba struct. |
| 9964 | * |
| 9965 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9966 | * IOCB_ERROR - Error |
| 9967 | * IOCB_SUCCESS - Success |
| 9968 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9969 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9970 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9971 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 9972 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9973 | { |
| 9974 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9975 | } |
| 9976 | |
| 9977 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9978 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9979 | * @phba: The hba struct for which this call is being executed. |
| 9980 | * @dev_grp: The HBA PCI-Device group number. |
| 9981 | * |
| 9982 | * This routine sets up the SLI interface API function jump table in @phba |
| 9983 | * struct. |
| 9984 | * Returns: 0 - success, -ENODEV - failure. |
| 9985 | **/ |
| 9986 | int |
| 9987 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 9988 | { |
| 9989 | |
| 9990 | switch (dev_grp) { |
| 9991 | case LPFC_PCI_DEV_LP: |
| 9992 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 9993 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 9994 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9995 | case LPFC_PCI_DEV_OC: |
| 9996 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 9997 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 9998 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9999 | default: |
| 10000 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10001 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 10002 | dev_grp); |
| 10003 | return -ENODEV; |
| 10004 | break; |
| 10005 | } |
| 10006 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 10007 | return 0; |
| 10008 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10009 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10010 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10011 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10012 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10013 | * @piocb: Pointer to command iocb. |
| 10014 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10015 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 10016 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10017 | * 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] | 10018 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10019 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10020 | struct lpfc_sli_ring * |
| 10021 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10022 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10023 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10024 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10025 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10026 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 10027 | return NULL; |
| 10028 | /* |
| 10029 | * for abort iocb hba_wqidx should already |
| 10030 | * be setup based on what work queue we used. |
| 10031 | */ |
| 10032 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10033 | lpfc_cmd = (struct lpfc_io_buf *)piocb->context1; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 10034 | piocb->hba_wqidx = lpfc_cmd->hdwq_no; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10035 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10036 | return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10037 | } else { |
| 10038 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 10039 | return NULL; |
| 10040 | piocb->hba_wqidx = 0; |
| 10041 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10042 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10043 | } |
| 10044 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10045 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10046 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10047 | * @phba: Pointer to HBA context object. |
| 10048 | * @pring: Pointer to driver SLI ring object. |
| 10049 | * @piocb: Pointer to command iocb. |
| 10050 | * @flag: Flag indicating if this command can be put into txq. |
| 10051 | * |
| 10052 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 10053 | * function. This function gets the hbalock and calls |
| 10054 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 10055 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 10056 | * functions which do not hold hbalock. |
| 10057 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10058 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10059 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10060 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10061 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10062 | struct lpfc_sli_ring *pring; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10063 | unsigned long iflags; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10064 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10065 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10066 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10067 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 10068 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10069 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10070 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10071 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10072 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10073 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10074 | } else { |
| 10075 | /* For now, SLI2/3 will still use hbalock */ |
| 10076 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10077 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10078 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10079 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10080 | return rc; |
| 10081 | } |
| 10082 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10083 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10084 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10085 | * @phba: Pointer to HBA context object. |
| 10086 | * |
| 10087 | * This function is called while driver attaches with the |
| 10088 | * HBA to setup the extra ring. The extra ring is used |
| 10089 | * only when driver needs to support target mode functionality |
| 10090 | * or IP over FC functionalities. |
| 10091 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10092 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10093 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10094 | static int |
| 10095 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 10096 | { |
| 10097 | struct lpfc_sli *psli; |
| 10098 | struct lpfc_sli_ring *pring; |
| 10099 | |
| 10100 | psli = &phba->sli; |
| 10101 | |
| 10102 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10103 | |
| 10104 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10105 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10106 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10107 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10108 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10109 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10110 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10111 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10112 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10113 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10114 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10115 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10116 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10117 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10118 | |
| 10119 | /* Setup default profile for this ring */ |
| 10120 | pring->iotag_max = 4096; |
| 10121 | pring->num_mask = 1; |
| 10122 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10123 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 10124 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10125 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 10126 | return 0; |
| 10127 | } |
| 10128 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10129 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 10130 | * @phba: Pointer to HBA context object. |
| 10131 | * @iocbq: Pointer to iocb object. |
| 10132 | * |
| 10133 | * The async_event handler calls this routine when it receives |
| 10134 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 10135 | * this event when an Abort Sequence request to an rport fails |
| 10136 | * twice in succession. The abort could be originated by the |
| 10137 | * driver or by the port. The ABTS could have been for an ELS |
| 10138 | * or FCP IO. The port only generates this event when an ABTS |
| 10139 | * fails to complete after one retry. |
| 10140 | */ |
| 10141 | static void |
| 10142 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 10143 | struct lpfc_iocbq *iocbq) |
| 10144 | { |
| 10145 | struct lpfc_nodelist *ndlp = NULL; |
| 10146 | uint16_t rpi = 0, vpi = 0; |
| 10147 | struct lpfc_vport *vport = NULL; |
| 10148 | |
| 10149 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 10150 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 10151 | rpi = iocbq->iocb.ulpContext; |
| 10152 | |
| 10153 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10154 | "3092 Port generated ABTS async event " |
| 10155 | "on vpi %d rpi %d status 0x%x\n", |
| 10156 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 10157 | |
| 10158 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 10159 | if (!vport) |
| 10160 | goto err_exit; |
| 10161 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 10162 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 10163 | goto err_exit; |
| 10164 | |
| 10165 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 10166 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10167 | return; |
| 10168 | |
| 10169 | err_exit: |
| 10170 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10171 | "3095 Event Context not found, no " |
| 10172 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 10173 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 10174 | vpi, rpi); |
| 10175 | } |
| 10176 | |
| 10177 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 10178 | * @phba: pointer to HBA context object. |
| 10179 | * @ndlp: nodelist pointer for the impacted rport. |
| 10180 | * @axri: pointer to the wcqe containing the failed exchange. |
| 10181 | * |
| 10182 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 10183 | * port. The port generates this event when an abort exchange request to an |
| 10184 | * rport fails twice in succession with no reply. The abort could be originated |
| 10185 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 10186 | */ |
| 10187 | void |
| 10188 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 10189 | struct lpfc_nodelist *ndlp, |
| 10190 | struct sli4_wcqe_xri_aborted *axri) |
| 10191 | { |
| 10192 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10193 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10194 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10195 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10196 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10197 | "3115 Node Context not found, driver " |
| 10198 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10199 | return; |
| 10200 | } |
| 10201 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10202 | vport = ndlp->vport; |
| 10203 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10204 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10205 | "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] | 10206 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10207 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10208 | bf_get(lpfc_wcqe_xa_status, axri), |
| 10209 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10210 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10211 | /* |
| 10212 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 10213 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 10214 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 10215 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 10216 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10217 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 10218 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10219 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10220 | } |
| 10221 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10222 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10223 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10224 | * @phba: Pointer to HBA context object. |
| 10225 | * @pring: Pointer to driver SLI ring object. |
| 10226 | * @iocbq: Pointer to iocb object. |
| 10227 | * |
| 10228 | * This function is called by the slow ring event handler |
| 10229 | * function when there is an ASYNC event iocb in the ring. |
| 10230 | * This function is called with no lock held. |
| 10231 | * Currently this function handles only temperature related |
| 10232 | * ASYNC events. The function decodes the temperature sensor |
| 10233 | * event message and posts events for the management applications. |
| 10234 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10235 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10236 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 10237 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 10238 | { |
| 10239 | IOCB_t *icmd; |
| 10240 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10241 | struct temp_event temp_event_data; |
| 10242 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10243 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10244 | |
| 10245 | icmd = &iocbq->iocb; |
| 10246 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10247 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10248 | switch (evt_code) { |
| 10249 | case ASYNC_TEMP_WARN: |
| 10250 | case ASYNC_TEMP_SAFE: |
| 10251 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 10252 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 10253 | if (evt_code == ASYNC_TEMP_WARN) { |
| 10254 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 10255 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10256 | "0347 Adapter is very hot, please take " |
| 10257 | "corrective action. temperature : %d Celsius\n", |
| 10258 | (uint32_t) icmd->ulpContext); |
| 10259 | } else { |
| 10260 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 10261 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10262 | "0340 Adapter temperature is OK now. " |
| 10263 | "temperature : %d Celsius\n", |
| 10264 | (uint32_t) icmd->ulpContext); |
| 10265 | } |
| 10266 | |
| 10267 | /* Send temperature change event to applications */ |
| 10268 | shost = lpfc_shost_from_vport(phba->pport); |
| 10269 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 10270 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 10271 | LPFC_NL_VENDOR_ID); |
| 10272 | break; |
| 10273 | case ASYNC_STATUS_CN: |
| 10274 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 10275 | break; |
| 10276 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10277 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10278 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10279 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 10280 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10281 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 10282 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 10283 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 10284 | "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] | 10285 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10286 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 10287 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 10288 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 10289 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 10290 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10291 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10292 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10293 | } |
| 10294 | |
| 10295 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10296 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10297 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10298 | * @phba: Pointer to HBA context object. |
| 10299 | * |
| 10300 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10301 | * number of iocbs per ring and iotags. This function is |
| 10302 | * called while driver attach to the HBA and before the |
| 10303 | * interrupts are enabled. So there is no need for locking. |
| 10304 | * |
| 10305 | * This function always returns 0. |
| 10306 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10307 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10308 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 10309 | { |
| 10310 | struct lpfc_sli_ring *pring; |
| 10311 | |
| 10312 | pring = phba->sli4_hba.els_wq->pring; |
| 10313 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 10314 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 10315 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10316 | pring->prt[0].type = FC_TYPE_ELS; |
| 10317 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 10318 | lpfc_els_unsol_event; |
| 10319 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 10320 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10321 | pring->prt[1].type = FC_TYPE_ELS; |
| 10322 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 10323 | lpfc_els_unsol_event; |
| 10324 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10325 | /* NameServer Inquiry */ |
| 10326 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 10327 | /* NameServer */ |
| 10328 | pring->prt[2].type = FC_TYPE_CT; |
| 10329 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 10330 | lpfc_ct_unsol_event; |
| 10331 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10332 | /* NameServer response */ |
| 10333 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 10334 | /* NameServer */ |
| 10335 | pring->prt[3].type = FC_TYPE_CT; |
| 10336 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 10337 | lpfc_ct_unsol_event; |
| 10338 | return 0; |
| 10339 | } |
| 10340 | |
| 10341 | /** |
| 10342 | * lpfc_sli_setup - SLI ring setup function |
| 10343 | * @phba: Pointer to HBA context object. |
| 10344 | * |
| 10345 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10346 | * number of iocbs per ring and iotags. This function is |
| 10347 | * called while driver attach to the HBA and before the |
| 10348 | * interrupts are enabled. So there is no need for locking. |
| 10349 | * |
| 10350 | * This function always returns 0. SLI3 only. |
| 10351 | **/ |
| 10352 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10353 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 10354 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10355 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10356 | struct lpfc_sli *psli = &phba->sli; |
| 10357 | struct lpfc_sli_ring *pring; |
| 10358 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10359 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10360 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10361 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10362 | psli->iocbq_lookup = NULL; |
| 10363 | psli->iocbq_lookup_len = 0; |
| 10364 | psli->last_iotag = 0; |
| 10365 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10366 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10367 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10368 | switch (i) { |
| 10369 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 10370 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10371 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 10372 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 10373 | pring->sli.sli3.numCiocb += |
| 10374 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10375 | pring->sli.sli3.numRiocb += |
| 10376 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10377 | pring->sli.sli3.numCiocb += |
| 10378 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10379 | pring->sli.sli3.numRiocb += |
| 10380 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 10381 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10382 | SLI3_IOCB_CMD_SIZE : |
| 10383 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10384 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10385 | SLI3_IOCB_RSP_SIZE : |
| 10386 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10387 | pring->iotag_ctr = 0; |
| 10388 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10389 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10390 | pring->fast_iotag = pring->iotag_max; |
| 10391 | pring->num_mask = 0; |
| 10392 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10393 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10394 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10395 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 10396 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 10397 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10398 | SLI3_IOCB_CMD_SIZE : |
| 10399 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10400 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10401 | SLI3_IOCB_RSP_SIZE : |
| 10402 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10403 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10404 | pring->num_mask = 0; |
| 10405 | break; |
| 10406 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 10407 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10408 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 10409 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 10410 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10411 | SLI3_IOCB_CMD_SIZE : |
| 10412 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10413 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10414 | SLI3_IOCB_RSP_SIZE : |
| 10415 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10416 | pring->fast_iotag = 0; |
| 10417 | pring->iotag_ctr = 0; |
| 10418 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10419 | pring->lpfc_sli_rcv_async_status = |
| 10420 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10421 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10422 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10423 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10424 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10425 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10426 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10427 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10428 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10429 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10430 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10431 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10432 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10433 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10434 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10435 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10436 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10437 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10438 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10439 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10440 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10441 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10442 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10443 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10444 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10445 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10446 | break; |
| 10447 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10448 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 10449 | pring->sli.sli3.sizeCiocb) + |
| 10450 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10451 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10452 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10453 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10454 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 10455 | "SLI2 SLIM Data: x%x x%lx\n", |
| 10456 | phba->brd_no, totiocbsize, |
| 10457 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10458 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10459 | if (phba->cfg_multi_ring_support == 2) |
| 10460 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10461 | |
| 10462 | return 0; |
| 10463 | } |
| 10464 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10465 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10466 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10467 | * @phba: Pointer to HBA context object. |
| 10468 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10469 | * 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] | 10470 | * ring. This function also initializes ring indices of each ring. |
| 10471 | * This function is called during the initialization of the SLI |
| 10472 | * interface of an HBA. |
| 10473 | * This function is called with no lock held and always returns |
| 10474 | * 1. |
| 10475 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10476 | void |
| 10477 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 10478 | { |
| 10479 | struct lpfc_sli *psli; |
| 10480 | struct lpfc_sli_ring *pring; |
| 10481 | int i; |
| 10482 | |
| 10483 | psli = &phba->sli; |
| 10484 | spin_lock_irq(&phba->hbalock); |
| 10485 | INIT_LIST_HEAD(&psli->mboxq); |
| 10486 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 10487 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10488 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10489 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10490 | pring->flag = 0; |
| 10491 | pring->ringno = LPFC_FCP_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10492 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10493 | INIT_LIST_HEAD(&pring->txq); |
| 10494 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10495 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10496 | spin_lock_init(&pring->ring_lock); |
| 10497 | } |
| 10498 | pring = phba->sli4_hba.els_wq->pring; |
| 10499 | pring->flag = 0; |
| 10500 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10501 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10502 | INIT_LIST_HEAD(&pring->txq); |
| 10503 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10504 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10505 | spin_lock_init(&pring->ring_lock); |
| 10506 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10507 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10508 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 10509 | pring->flag = 0; |
| 10510 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10511 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10512 | INIT_LIST_HEAD(&pring->txq); |
| 10513 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10514 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10515 | spin_lock_init(&pring->ring_lock); |
| 10516 | } |
| 10517 | |
| 10518 | spin_unlock_irq(&phba->hbalock); |
| 10519 | } |
| 10520 | |
| 10521 | /** |
| 10522 | * lpfc_sli_queue_init - Queue initialization function |
| 10523 | * @phba: Pointer to HBA context object. |
| 10524 | * |
| 10525 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 10526 | * ring. This function also initializes ring indices of each ring. |
| 10527 | * This function is called during the initialization of the SLI |
| 10528 | * interface of an HBA. |
| 10529 | * This function is called with no lock held and always returns |
| 10530 | * 1. |
| 10531 | **/ |
| 10532 | void |
| 10533 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10534 | { |
| 10535 | struct lpfc_sli *psli; |
| 10536 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10537 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10538 | |
| 10539 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10540 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10541 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10542 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10543 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 10544 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10545 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10546 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10547 | pring->sli.sli3.next_cmdidx = 0; |
| 10548 | pring->sli.sli3.local_getidx = 0; |
| 10549 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10550 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 10551 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10552 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10553 | pring->flag = 0; |
| 10554 | INIT_LIST_HEAD(&pring->txq); |
| 10555 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10556 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10557 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10558 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10559 | } |
| 10560 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10561 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10562 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 10563 | * @phba: Pointer to HBA context object. |
| 10564 | * |
| 10565 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 10566 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 10567 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 10568 | * command; and completed mailbox command queue. It is caller's responsibility |
| 10569 | * to make sure that the driver is in the proper state to flush the mailbox |
| 10570 | * command sub-system. Namely, the posting of mailbox commands into the |
| 10571 | * pending mailbox command queue from the various clients must be stopped; |
| 10572 | * either the HBA is in a state that it will never works on the outstanding |
| 10573 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 10574 | * mailbox command has been completed. |
| 10575 | **/ |
| 10576 | static void |
| 10577 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 10578 | { |
| 10579 | LIST_HEAD(completions); |
| 10580 | struct lpfc_sli *psli = &phba->sli; |
| 10581 | LPFC_MBOXQ_t *pmb; |
| 10582 | unsigned long iflag; |
| 10583 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10584 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10585 | local_bh_disable(); |
| 10586 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10587 | /* Flush all the mailbox commands in the mbox system */ |
| 10588 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10589 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10590 | /* The pending mailbox command queue */ |
| 10591 | list_splice_init(&phba->sli.mboxq, &completions); |
| 10592 | /* The outstanding active mailbox command */ |
| 10593 | if (psli->mbox_active) { |
| 10594 | list_add_tail(&psli->mbox_active->list, &completions); |
| 10595 | psli->mbox_active = NULL; |
| 10596 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10597 | } |
| 10598 | /* The completed mailbox command queue */ |
| 10599 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 10600 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10601 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10602 | /* Enable softirqs again, done with phba->hbalock */ |
| 10603 | local_bh_enable(); |
| 10604 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10605 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 10606 | while (!list_empty(&completions)) { |
| 10607 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 10608 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10609 | if (pmb->mbox_cmpl) |
| 10610 | pmb->mbox_cmpl(phba, pmb); |
| 10611 | } |
| 10612 | } |
| 10613 | |
| 10614 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10615 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10616 | * @vport: Pointer to virtual port object. |
| 10617 | * |
| 10618 | * lpfc_sli_host_down is called to clean up the resources |
| 10619 | * associated with a vport before destroying virtual |
| 10620 | * port data structures. |
| 10621 | * This function does following operations: |
| 10622 | * - Free discovery resources associated with this virtual |
| 10623 | * port. |
| 10624 | * - Free iocbs associated with this virtual port in |
| 10625 | * the txq. |
| 10626 | * - Send abort for all iocb commands associated with this |
| 10627 | * vport in txcmplq. |
| 10628 | * |
| 10629 | * This function is called with no lock held and always returns 1. |
| 10630 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10631 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10632 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 10633 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10634 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10635 | struct lpfc_hba *phba = vport->phba; |
| 10636 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10637 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10638 | struct lpfc_sli_ring *pring; |
| 10639 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10640 | int i; |
| 10641 | unsigned long flags = 0; |
| 10642 | uint16_t prev_pring_flag; |
| 10643 | |
| 10644 | lpfc_cleanup_discovery_resources(vport); |
| 10645 | |
| 10646 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10647 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10648 | /* |
| 10649 | * Error everything on the txq since these iocbs |
| 10650 | * have not been given to the FW yet. |
| 10651 | * Also issue ABTS for everything on the txcmplq |
| 10652 | */ |
| 10653 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10654 | for (i = 0; i < psli->num_rings; i++) { |
| 10655 | pring = &psli->sli3_ring[i]; |
| 10656 | prev_pring_flag = pring->flag; |
| 10657 | /* Only slow rings */ |
| 10658 | if (pring->ringno == LPFC_ELS_RING) { |
| 10659 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10660 | /* Set the lpfc data pending flag */ |
| 10661 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10662 | } |
| 10663 | list_for_each_entry_safe(iocb, next_iocb, |
| 10664 | &pring->txq, list) { |
| 10665 | if (iocb->vport != vport) |
| 10666 | continue; |
| 10667 | list_move_tail(&iocb->list, &completions); |
| 10668 | } |
| 10669 | list_for_each_entry_safe(iocb, next_iocb, |
| 10670 | &pring->txcmplq, list) { |
| 10671 | if (iocb->vport != vport) |
| 10672 | continue; |
| 10673 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10674 | } |
| 10675 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10676 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10677 | } else { |
| 10678 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10679 | pring = qp->pring; |
| 10680 | if (!pring) |
| 10681 | continue; |
| 10682 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10683 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10684 | /* Set the lpfc data pending flag */ |
| 10685 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10686 | } |
| 10687 | prev_pring_flag = pring->flag; |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 10688 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10689 | list_for_each_entry_safe(iocb, next_iocb, |
| 10690 | &pring->txq, list) { |
| 10691 | if (iocb->vport != vport) |
| 10692 | continue; |
| 10693 | list_move_tail(&iocb->list, &completions); |
| 10694 | } |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 10695 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10696 | list_for_each_entry_safe(iocb, next_iocb, |
| 10697 | &pring->txcmplq, list) { |
| 10698 | if (iocb->vport != vport) |
| 10699 | continue; |
| 10700 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10701 | } |
| 10702 | pring->flag = prev_pring_flag; |
| 10703 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10704 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10705 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10706 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10707 | /* Cancel all the IOCBs from the completions list */ |
| 10708 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10709 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10710 | return 1; |
| 10711 | } |
| 10712 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10713 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10714 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10715 | * @phba: Pointer to HBA context object. |
| 10716 | * |
| 10717 | * This function cleans up all iocb, buffers, mailbox commands |
| 10718 | * while shutting down the HBA. This function is called with no |
| 10719 | * lock held and always returns 1. |
| 10720 | * This function does the following to cleanup driver resources: |
| 10721 | * - Free discovery resources for each virtual port |
| 10722 | * - Cleanup any pending fabric iocbs |
| 10723 | * - Iterate through the iocb txq and free each entry |
| 10724 | * in the list. |
| 10725 | * - Free up any buffer posted to the HBA |
| 10726 | * - Free mailbox commands in the mailbox queue. |
| 10727 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10728 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10729 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10730 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10731 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10732 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10733 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10734 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10735 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10736 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10737 | int i; |
| 10738 | |
| 10739 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10740 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10741 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10742 | lpfc_hba_down_prep(phba); |
| 10743 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10744 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10745 | local_bh_disable(); |
| 10746 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10747 | lpfc_fabric_abort_hba(phba); |
| 10748 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10749 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10750 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10751 | /* |
| 10752 | * Error everything on the txq since these iocbs |
| 10753 | * have not been given to the FW yet. |
| 10754 | */ |
| 10755 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10756 | for (i = 0; i < psli->num_rings; i++) { |
| 10757 | pring = &psli->sli3_ring[i]; |
| 10758 | /* Only slow rings */ |
| 10759 | if (pring->ringno == LPFC_ELS_RING) { |
| 10760 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10761 | /* Set the lpfc data pending flag */ |
| 10762 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10763 | } |
| 10764 | list_splice_init(&pring->txq, &completions); |
| 10765 | } |
| 10766 | } else { |
| 10767 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10768 | pring = qp->pring; |
| 10769 | if (!pring) |
| 10770 | continue; |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 10771 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10772 | list_splice_init(&pring->txq, &completions); |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 10773 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10774 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10775 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10776 | /* Set the lpfc data pending flag */ |
| 10777 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10778 | } |
| 10779 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10780 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10781 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10782 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10783 | /* Cancel all the IOCBs from the completions list */ |
| 10784 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10785 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10786 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10787 | spin_lock_irqsave(&phba->hbalock, flags); |
| 10788 | list_splice_init(&phba->elsbuf, &completions); |
| 10789 | phba->elsbuf_cnt = 0; |
| 10790 | phba->elsbuf_prev_cnt = 0; |
| 10791 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10792 | |
| 10793 | while (!list_empty(&completions)) { |
| 10794 | list_remove_head(&completions, buf_ptr, |
| 10795 | struct lpfc_dmabuf, list); |
| 10796 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 10797 | kfree(buf_ptr); |
| 10798 | } |
| 10799 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10800 | /* Enable softirqs again, done with phba->hbalock */ |
| 10801 | local_bh_enable(); |
| 10802 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10803 | /* Return any active mbox cmds */ |
| 10804 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10805 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10806 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10807 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10808 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10809 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10810 | return 1; |
| 10811 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10812 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10813 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10814 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10815 | * @srcp: Source memory pointer. |
| 10816 | * @destp: Destination memory pointer. |
| 10817 | * @cnt: Number of words required to be copied. |
| 10818 | * |
| 10819 | * This function is used for copying data between driver memory |
| 10820 | * and the SLI memory. This function also changes the endianness |
| 10821 | * of each word if native endianness is different from SLI |
| 10822 | * endianness. This function can be called with or without |
| 10823 | * lock. |
| 10824 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10825 | void |
| 10826 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10827 | { |
| 10828 | uint32_t *src = srcp; |
| 10829 | uint32_t *dest = destp; |
| 10830 | uint32_t ldata; |
| 10831 | int i; |
| 10832 | |
| 10833 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 10834 | ldata = *src; |
| 10835 | ldata = le32_to_cpu(ldata); |
| 10836 | *dest = ldata; |
| 10837 | src++; |
| 10838 | dest++; |
| 10839 | } |
| 10840 | } |
| 10841 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10842 | |
| 10843 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 10844 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 10845 | * @srcp: Source memory pointer. |
| 10846 | * @destp: Destination memory pointer. |
| 10847 | * @cnt: Number of words required to be copied. |
| 10848 | * |
| 10849 | * This function is used for copying data between a data structure |
| 10850 | * with big endian representation to local endianness. |
| 10851 | * This function can be called with or without lock. |
| 10852 | **/ |
| 10853 | void |
| 10854 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10855 | { |
| 10856 | uint32_t *src = srcp; |
| 10857 | uint32_t *dest = destp; |
| 10858 | uint32_t ldata; |
| 10859 | int i; |
| 10860 | |
| 10861 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 10862 | ldata = *src; |
| 10863 | ldata = be32_to_cpu(ldata); |
| 10864 | *dest = ldata; |
| 10865 | src++; |
| 10866 | dest++; |
| 10867 | } |
| 10868 | } |
| 10869 | |
| 10870 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10871 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10872 | * @phba: Pointer to HBA context object. |
| 10873 | * @pring: Pointer to driver SLI ring object. |
| 10874 | * @mp: Pointer to driver buffer object. |
| 10875 | * |
| 10876 | * This function is called with no lock held. |
| 10877 | * It always return zero after adding the buffer to the postbufq |
| 10878 | * buffer list. |
| 10879 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10880 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10881 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10882 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10883 | { |
| 10884 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 10885 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10886 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10887 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10888 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10889 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10890 | return 0; |
| 10891 | } |
| 10892 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10893 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10894 | * 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] | 10895 | * @phba: Pointer to HBA context object. |
| 10896 | * |
| 10897 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 10898 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 10899 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 10900 | * does not conflict with tags of buffer posted for unsolicited events. |
| 10901 | * The function returns the allocated tag. The function is called with |
| 10902 | * no locks held. |
| 10903 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10904 | uint32_t |
| 10905 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 10906 | { |
| 10907 | spin_lock_irq(&phba->hbalock); |
| 10908 | phba->buffer_tag_count++; |
| 10909 | /* |
| 10910 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 10911 | * a tag assigned by HBQ. |
| 10912 | */ |
| 10913 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 10914 | spin_unlock_irq(&phba->hbalock); |
| 10915 | return phba->buffer_tag_count; |
| 10916 | } |
| 10917 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10918 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10919 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10920 | * @phba: Pointer to HBA context object. |
| 10921 | * @pring: Pointer to driver SLI ring object. |
| 10922 | * @tag: Buffer tag. |
| 10923 | * |
| 10924 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 10925 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 10926 | * iocb is posted to the response ring with the tag of the buffer. |
| 10927 | * This function searches the pring->postbufq list using the tag |
| 10928 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 10929 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 10930 | * buffer is returned to the caller else NULL is returned. |
| 10931 | * This function is called with no lock held. |
| 10932 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10933 | struct lpfc_dmabuf * |
| 10934 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10935 | uint32_t tag) |
| 10936 | { |
| 10937 | struct lpfc_dmabuf *mp, *next_mp; |
| 10938 | struct list_head *slp = &pring->postbufq; |
| 10939 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10940 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10941 | spin_lock_irq(&phba->hbalock); |
| 10942 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10943 | if (mp->buffer_tag == tag) { |
| 10944 | list_del_init(&mp->list); |
| 10945 | pring->postbufq_cnt--; |
| 10946 | spin_unlock_irq(&phba->hbalock); |
| 10947 | return mp; |
| 10948 | } |
| 10949 | } |
| 10950 | |
| 10951 | spin_unlock_irq(&phba->hbalock); |
| 10952 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10953 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 10954 | "ring %d Data x%lx x%px x%px x%x\n", |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10955 | pring->ringno, (unsigned long) tag, |
| 10956 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10957 | |
| 10958 | return NULL; |
| 10959 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10960 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10961 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10962 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10963 | * @phba: Pointer to HBA context object. |
| 10964 | * @pring: Pointer to driver SLI ring object. |
| 10965 | * @phys: DMA address of the buffer. |
| 10966 | * |
| 10967 | * This function searches the buffer list using the dma_address |
| 10968 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 10969 | * corresponding to the dma_address. The function returns the |
| 10970 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 10971 | * This function is called by the ct and els unsolicited event |
| 10972 | * handlers to get the buffer associated with the unsolicited |
| 10973 | * event. |
| 10974 | * |
| 10975 | * This function is called with no lock held. |
| 10976 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10977 | struct lpfc_dmabuf * |
| 10978 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10979 | dma_addr_t phys) |
| 10980 | { |
| 10981 | struct lpfc_dmabuf *mp, *next_mp; |
| 10982 | struct list_head *slp = &pring->postbufq; |
| 10983 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10984 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10985 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10986 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10987 | if (mp->phys == phys) { |
| 10988 | list_del_init(&mp->list); |
| 10989 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10990 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10991 | return mp; |
| 10992 | } |
| 10993 | } |
| 10994 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10995 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10996 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10997 | "0410 Cannot find virtual addr for mapped buf on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 10998 | "ring %d Data x%llx x%px x%px x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10999 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11000 | slp->next, slp->prev, pring->postbufq_cnt); |
| 11001 | return NULL; |
| 11002 | } |
| 11003 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11004 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11005 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11006 | * @phba: Pointer to HBA context object. |
| 11007 | * @cmdiocb: Pointer to driver command iocb object. |
| 11008 | * @rspiocb: Pointer to driver response iocb object. |
| 11009 | * |
| 11010 | * This function is the completion handler for the abort iocbs for |
| 11011 | * ELS commands. This function is called from the ELS ring event |
| 11012 | * handler with no lock held. This function frees memory resources |
| 11013 | * associated with the abort iocb. |
| 11014 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11015 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11016 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11017 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11018 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11019 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11020 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11021 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11022 | |
| 11023 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11024 | |
| 11025 | /* |
| 11026 | * Assume that the port already completed and returned, or |
| 11027 | * will return the iocb. Just Log the message. |
| 11028 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11029 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 11030 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 11031 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11032 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11033 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11034 | if (irsp->ulpCommand == CMD_ABORT_XRI_CX && |
| 11035 | irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 11036 | irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) { |
| 11037 | spin_unlock_irq(&phba->hbalock); |
| 11038 | goto release_iocb; |
| 11039 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11040 | if (abort_iotag != 0 && |
| 11041 | abort_iotag <= phba->sli.last_iotag) |
| 11042 | abort_iocb = |
| 11043 | phba->sli.iocbq_lookup[abort_iotag]; |
| 11044 | } else |
| 11045 | /* For sli4 the abort_tag is the XRI, |
| 11046 | * so the abort routine puts the iotag of the iocb |
| 11047 | * being aborted in the context field of the abort |
| 11048 | * IOCB. |
| 11049 | */ |
| 11050 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11051 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11052 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11053 | "0327 Cannot abort els iocb x%px " |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11054 | "with tag %x context %x, abort status %x, " |
| 11055 | "abort code %x\n", |
| 11056 | abort_iocb, abort_iotag, abort_context, |
| 11057 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11058 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11059 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2960122 | 2019-08-14 16:56:36 -0700 | [diff] [blame] | 11060 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 11061 | irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) |
| 11062 | lpfc_sli_release_iocbq(phba, abort_iocb); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11063 | } |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11064 | release_iocb: |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11065 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11066 | return; |
| 11067 | } |
| 11068 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11069 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11070 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11071 | * @phba: Pointer to HBA context object. |
| 11072 | * @cmdiocb: Pointer to driver command iocb object. |
| 11073 | * @rspiocb: Pointer to driver response iocb object. |
| 11074 | * |
| 11075 | * The function is called from SLI ring event handler with no |
| 11076 | * lock held. This function is the completion handler for ELS commands |
| 11077 | * which are aborted. The function frees memory resources used for |
| 11078 | * the aborted ELS commands. |
| 11079 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11080 | static void |
| 11081 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11082 | struct lpfc_iocbq *rspiocb) |
| 11083 | { |
| 11084 | IOCB_t *irsp = &rspiocb->iocb; |
| 11085 | |
| 11086 | /* ELS cmd tag <ulpIoTag> completes */ |
| 11087 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11088 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11089 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11090 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11091 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11092 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 11093 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 11094 | else |
| 11095 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11096 | return; |
| 11097 | } |
| 11098 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11099 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11100 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11101 | * @phba: Pointer to HBA context object. |
| 11102 | * @pring: Pointer to driver SLI ring object. |
| 11103 | * @cmdiocb: Pointer to driver command iocb object. |
| 11104 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11105 | * This function issues an abort iocb for the provided command iocb down to |
| 11106 | * the port. Other than the case the outstanding command iocb is an abort |
| 11107 | * request, this function issues abort out unconditionally. This function is |
| 11108 | * called with hbalock held. The function returns 0 when it fails due to |
| 11109 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11110 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11111 | static int |
| 11112 | 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] | 11113 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11114 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11115 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11116 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11117 | IOCB_t *icmd = NULL; |
| 11118 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11119 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11120 | unsigned long iflags; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11121 | struct lpfc_nodelist *ndlp; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11122 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11123 | lockdep_assert_held(&phba->hbalock); |
| 11124 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11125 | /* |
| 11126 | * There are certain command types we don't want to abort. And we |
| 11127 | * don't want to abort commands that are already in the process of |
| 11128 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11129 | */ |
| 11130 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11131 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11132 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11133 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11134 | return 0; |
| 11135 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11136 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11137 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11138 | if (abtsiocbp == NULL) |
| 11139 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11140 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11141 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11142 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11143 | */ |
| 11144 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11145 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11146 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11147 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11148 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11149 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11150 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11151 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11152 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11153 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11154 | if (pring->ringno == LPFC_ELS_RING) { |
| 11155 | ndlp = (struct lpfc_nodelist *)(cmdiocb->context1); |
| 11156 | iabt->un.acxri.abortContextTag = ndlp->nlp_rpi; |
| 11157 | } |
| 11158 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11159 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11160 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11161 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11162 | /* 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] | 11163 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11164 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 11165 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11166 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 11167 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11168 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11169 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11170 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 11171 | else |
| 11172 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 11173 | |
| 11174 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 11175 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 11176 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11177 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 11178 | "0339 Abort xri x%x, original iotag x%x, " |
| 11179 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11180 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11181 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11182 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11183 | |
| 11184 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11185 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 11186 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11187 | return 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11188 | /* Note: both hbalock and ring_lock need to be set here */ |
| 11189 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11190 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11191 | abtsiocbp, 0); |
| 11192 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 11193 | } else { |
| 11194 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11195 | abtsiocbp, 0); |
| 11196 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11197 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11198 | if (retval) |
| 11199 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11200 | |
| 11201 | /* |
| 11202 | * Caller to this routine should check for IOCB_ERROR |
| 11203 | * and handle it properly. This routine no longer removes |
| 11204 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 11205 | */ |
| 11206 | return retval; |
| 11207 | } |
| 11208 | |
| 11209 | /** |
| 11210 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 11211 | * @phba: Pointer to HBA context object. |
| 11212 | * @pring: Pointer to driver SLI ring object. |
| 11213 | * @cmdiocb: Pointer to driver command iocb object. |
| 11214 | * |
| 11215 | * This function issues an abort iocb for the provided command iocb. In case |
| 11216 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 11217 | * ring. Instead, the callback function shall be changed to those commands |
| 11218 | * so that nothing happens when them finishes. This function is called with |
| 11219 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 11220 | * request. |
| 11221 | **/ |
| 11222 | int |
| 11223 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11224 | struct lpfc_iocbq *cmdiocb) |
| 11225 | { |
| 11226 | struct lpfc_vport *vport = cmdiocb->vport; |
| 11227 | int retval = IOCB_ERROR; |
| 11228 | IOCB_t *icmd = NULL; |
| 11229 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11230 | lockdep_assert_held(&phba->hbalock); |
| 11231 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11232 | /* |
| 11233 | * There are certain command types we don't want to abort. And we |
| 11234 | * don't want to abort commands that are already in the process of |
| 11235 | * being aborted. |
| 11236 | */ |
| 11237 | icmd = &cmdiocb->iocb; |
| 11238 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 11239 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11240 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 11241 | return 0; |
| 11242 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 11243 | if (!pring) { |
| 11244 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11245 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11246 | else |
| 11247 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11248 | goto abort_iotag_exit; |
| 11249 | } |
| 11250 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11251 | /* |
| 11252 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 11253 | * the callback so that nothing happens when it finishes. |
| 11254 | */ |
| 11255 | if ((vport->load_flag & FC_UNLOADING) && |
| 11256 | (pring->ringno == LPFC_ELS_RING)) { |
| 11257 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11258 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11259 | else |
| 11260 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11261 | goto abort_iotag_exit; |
| 11262 | } |
| 11263 | |
| 11264 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 11265 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 11266 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11267 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11268 | /* |
| 11269 | * Caller to this routine should check for IOCB_ERROR |
| 11270 | * and handle it properly. This routine no longer removes |
| 11271 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11272 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11273 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11274 | } |
| 11275 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11276 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11277 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 11278 | * @phba: pointer to lpfc HBA data structure. |
| 11279 | * |
| 11280 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 11281 | **/ |
| 11282 | void |
| 11283 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 11284 | { |
| 11285 | struct lpfc_sli *psli = &phba->sli; |
| 11286 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11287 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11288 | int i; |
| 11289 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11290 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11291 | for (i = 0; i < psli->num_rings; i++) { |
| 11292 | pring = &psli->sli3_ring[i]; |
| 11293 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 11294 | } |
| 11295 | return; |
| 11296 | } |
| 11297 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11298 | pring = qp->pring; |
| 11299 | if (!pring) |
| 11300 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 11301 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11302 | } |
| 11303 | } |
| 11304 | |
| 11305 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11306 | * 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] | 11307 | * @iocbq: Pointer to driver iocb object. |
| 11308 | * @vport: Pointer to driver virtual port object. |
| 11309 | * @tgt_id: SCSI ID of the target. |
| 11310 | * @lun_id: LUN ID of the scsi device. |
| 11311 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 11312 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11313 | * 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] | 11314 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 11315 | * 0 if the filtering criteria is met for the given iocb and will return |
| 11316 | * 1 if the filtering criteria is not met. |
| 11317 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 11318 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 11319 | * lun_id parameter. |
| 11320 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 11321 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 11322 | * parameters. |
| 11323 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 11324 | * given iocb is for the SCSI host associated with the given vport. |
| 11325 | * This function is called with no locks held. |
| 11326 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11327 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11328 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 11329 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11330 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11331 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11332 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11333 | int rc = 1; |
| 11334 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11335 | if (iocbq->vport != vport) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11336 | return rc; |
| 11337 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11338 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 11339 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11340 | return rc; |
| 11341 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11342 | lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11343 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11344 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11345 | return rc; |
| 11346 | |
| 11347 | switch (ctx_cmd) { |
| 11348 | case LPFC_CTX_LUN: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11349 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11350 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 11351 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11352 | rc = 0; |
| 11353 | break; |
| 11354 | case LPFC_CTX_TGT: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11355 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11356 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11357 | rc = 0; |
| 11358 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11359 | case LPFC_CTX_HOST: |
| 11360 | rc = 0; |
| 11361 | break; |
| 11362 | default: |
| 11363 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 11364 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11365 | break; |
| 11366 | } |
| 11367 | |
| 11368 | return rc; |
| 11369 | } |
| 11370 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11371 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11372 | * 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] | 11373 | * @vport: Pointer to virtual port. |
| 11374 | * @tgt_id: SCSI ID of the target. |
| 11375 | * @lun_id: LUN ID of the scsi device. |
| 11376 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11377 | * |
| 11378 | * This function returns number of FCP commands pending for the vport. |
| 11379 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 11380 | * commands pending on the vport associated with SCSI device specified |
| 11381 | * by tgt_id and lun_id parameters. |
| 11382 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 11383 | * commands pending on the vport associated with SCSI target specified |
| 11384 | * by tgt_id parameter. |
| 11385 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 11386 | * commands pending on the vport. |
| 11387 | * This function returns the number of iocbs which satisfy the filter. |
| 11388 | * This function is called without any lock held. |
| 11389 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11390 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11391 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 11392 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11393 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11394 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11395 | struct lpfc_iocbq *iocbq; |
| 11396 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11397 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11398 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11399 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 11400 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11401 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11402 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 11403 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11404 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11405 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11406 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11407 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11408 | return sum; |
| 11409 | } |
| 11410 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11411 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11412 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11413 | * @phba: Pointer to HBA context object |
| 11414 | * @cmdiocb: Pointer to command iocb object. |
| 11415 | * @rspiocb: Pointer to response iocb object. |
| 11416 | * |
| 11417 | * This function is called when an aborted FCP iocb completes. This |
| 11418 | * function is called by the ring event handler with no lock held. |
| 11419 | * This function frees the iocb. |
| 11420 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11421 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11422 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11423 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11424 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11425 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 11426 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11427 | "original iotag x%x, abort cmd iotag x%x " |
| 11428 | "status 0x%x, reason 0x%x\n", |
| 11429 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 11430 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 11431 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 11432 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11433 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11434 | return; |
| 11435 | } |
| 11436 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11437 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11438 | * 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] | 11439 | * @vport: Pointer to virtual port. |
| 11440 | * @pring: Pointer to driver SLI ring object. |
| 11441 | * @tgt_id: SCSI ID of the target. |
| 11442 | * @lun_id: LUN ID of the scsi device. |
| 11443 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11444 | * |
| 11445 | * This function sends an abort command for every SCSI command |
| 11446 | * associated with the given virtual port pending on the ring |
| 11447 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11448 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11449 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11450 | * parameters |
| 11451 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11452 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11453 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11454 | * FCP iocbs associated with virtual port. |
| 11455 | * This function returns number of iocbs it failed to abort. |
| 11456 | * This function is called with no locks held. |
| 11457 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11458 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11459 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11460 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11461 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11462 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11463 | struct lpfc_iocbq *iocbq; |
| 11464 | struct lpfc_iocbq *abtsiocb; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11465 | struct lpfc_sli_ring *pring_s4; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11466 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11467 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11468 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11469 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11470 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11471 | if (phba->hba_flag & HBA_IOQ_FLUSH) |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11472 | return errcnt; |
| 11473 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11474 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11475 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11476 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11477 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11478 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11479 | continue; |
| 11480 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11481 | /* |
| 11482 | * If the iocbq is already being aborted, don't take a second |
| 11483 | * action, but do count it. |
| 11484 | */ |
| 11485 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11486 | continue; |
| 11487 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11488 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11489 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11490 | if (abtsiocb == NULL) { |
| 11491 | errcnt++; |
| 11492 | continue; |
| 11493 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11494 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11495 | /* indicate the IO is being aborted by the driver. */ |
| 11496 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11497 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11498 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11499 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11500 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11501 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11502 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 11503 | else |
| 11504 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11505 | abtsiocb->iocb.ulpLe = 1; |
| 11506 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11507 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11508 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11509 | /* 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] | 11510 | abtsiocb->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11511 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11512 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11513 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11514 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11515 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11516 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11517 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11518 | else |
| 11519 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11520 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11521 | /* Setup callback routine and issue the command. */ |
| 11522 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11523 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11524 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11525 | if (!pring_s4) |
| 11526 | continue; |
| 11527 | ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11528 | abtsiocb, 0); |
| 11529 | } else |
| 11530 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11531 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11532 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11533 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11534 | errcnt++; |
| 11535 | continue; |
| 11536 | } |
| 11537 | } |
| 11538 | |
| 11539 | return errcnt; |
| 11540 | } |
| 11541 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11542 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11543 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 11544 | * @vport: Pointer to virtual port. |
| 11545 | * @pring: Pointer to driver SLI ring object. |
| 11546 | * @tgt_id: SCSI ID of the target. |
| 11547 | * @lun_id: LUN ID of the scsi device. |
| 11548 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11549 | * |
| 11550 | * This function sends an abort command for every SCSI command |
| 11551 | * associated with the given virtual port pending on the ring |
| 11552 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11553 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11554 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11555 | * parameters |
| 11556 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11557 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11558 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11559 | * FCP iocbs associated with virtual port. |
| 11560 | * This function returns number of iocbs it aborted . |
| 11561 | * This function is called with no locks held right after a taskmgmt |
| 11562 | * command is sent. |
| 11563 | **/ |
| 11564 | int |
| 11565 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11566 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 11567 | { |
| 11568 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11569 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11570 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11571 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11572 | struct lpfc_iocbq *iocbq; |
| 11573 | IOCB_t *icmd; |
| 11574 | int sum, i, ret_val; |
| 11575 | unsigned long iflags; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11576 | struct lpfc_sli_ring *pring_s4 = NULL; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11577 | |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11578 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11579 | |
| 11580 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11581 | if (phba->hba_flag & HBA_IOQ_FLUSH) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11582 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11583 | return 0; |
| 11584 | } |
| 11585 | sum = 0; |
| 11586 | |
| 11587 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11588 | iocbq = phba->sli.iocbq_lookup[i]; |
| 11589 | |
| 11590 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 11591 | cmd) != 0) |
| 11592 | continue; |
| 11593 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11594 | /* Guard against IO completion being called at same time */ |
| 11595 | lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq); |
| 11596 | spin_lock(&lpfc_cmd->buf_lock); |
| 11597 | |
| 11598 | if (!lpfc_cmd->pCmd) { |
| 11599 | spin_unlock(&lpfc_cmd->buf_lock); |
| 11600 | continue; |
| 11601 | } |
| 11602 | |
| 11603 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11604 | pring_s4 = |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11605 | phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11606 | if (!pring_s4) { |
| 11607 | spin_unlock(&lpfc_cmd->buf_lock); |
| 11608 | continue; |
| 11609 | } |
| 11610 | /* Note: both hbalock and ring_lock must be set here */ |
| 11611 | spin_lock(&pring_s4->ring_lock); |
| 11612 | } |
| 11613 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11614 | /* |
| 11615 | * If the iocbq is already being aborted, don't take a second |
| 11616 | * action, but do count it. |
| 11617 | */ |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11618 | if ((iocbq->iocb_flag & LPFC_DRIVER_ABORTED) || |
| 11619 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
| 11620 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11621 | spin_unlock(&pring_s4->ring_lock); |
| 11622 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11623 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11624 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11625 | |
| 11626 | /* issue ABTS for this IOCB based on iotag */ |
| 11627 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11628 | if (!abtsiocbq) { |
| 11629 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11630 | spin_unlock(&pring_s4->ring_lock); |
| 11631 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11632 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11633 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11634 | |
| 11635 | icmd = &iocbq->iocb; |
| 11636 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11637 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 11638 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11639 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 11640 | iocbq->sli4_xritag; |
| 11641 | else |
| 11642 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 11643 | abtsiocbq->iocb.ulpLe = 1; |
| 11644 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 11645 | abtsiocbq->vport = vport; |
| 11646 | |
| 11647 | /* 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] | 11648 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11649 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11650 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11651 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11652 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11653 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11654 | ndlp = lpfc_cmd->rdata->pnode; |
| 11655 | |
| 11656 | if (lpfc_is_link_up(phba) && |
| 11657 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11658 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11659 | else |
| 11660 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11661 | |
| 11662 | /* Setup callback routine and issue the command. */ |
| 11663 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 11664 | |
| 11665 | /* |
| 11666 | * Indicate the IO is being aborted by the driver and set |
| 11667 | * the caller's flag into the aborted IO. |
| 11668 | */ |
| 11669 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11670 | |
| 11671 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11672 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11673 | abtsiocbq, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11674 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11675 | } else { |
| 11676 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11677 | abtsiocbq, 0); |
| 11678 | } |
| 11679 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11680 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11681 | |
| 11682 | if (ret_val == IOCB_ERROR) |
| 11683 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 11684 | else |
| 11685 | sum++; |
| 11686 | } |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11687 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11688 | return sum; |
| 11689 | } |
| 11690 | |
| 11691 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11692 | * 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] | 11693 | * @phba: Pointer to HBA context object. |
| 11694 | * @cmdiocbq: Pointer to command iocb. |
| 11695 | * @rspiocbq: Pointer to response iocb. |
| 11696 | * |
| 11697 | * This function is the completion handler for iocbs issued using |
| 11698 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 11699 | * ring event handler function without any lock held. This function |
| 11700 | * can be called from both worker thread context and interrupt |
| 11701 | * context. This function also can be called from other thread which |
| 11702 | * cleans up the SLI layer objects. |
| 11703 | * This function copy the contents of the response iocb to the |
| 11704 | * response iocb memory object provided by the caller of |
| 11705 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 11706 | * sleeps for the iocb completion. |
| 11707 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11708 | static void |
| 11709 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 11710 | struct lpfc_iocbq *cmdiocbq, |
| 11711 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11712 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11713 | wait_queue_head_t *pdone_q; |
| 11714 | unsigned long iflags; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11715 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11716 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11717 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11718 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 11719 | |
| 11720 | /* |
| 11721 | * A time out has occurred for the iocb. If a time out |
| 11722 | * completion handler has been supplied, call it. Otherwise, |
| 11723 | * just free the iocbq. |
| 11724 | */ |
| 11725 | |
| 11726 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11727 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 11728 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 11729 | if (cmdiocbq->iocb_cmpl) |
| 11730 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 11731 | else |
| 11732 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 11733 | return; |
| 11734 | } |
| 11735 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11736 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 11737 | if (cmdiocbq->context2 && rspiocbq) |
| 11738 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 11739 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 11740 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11741 | /* Set the exchange busy flag for task management commands */ |
| 11742 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 11743 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11744 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf, |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11745 | cur_iocbq); |
| 11746 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 11747 | } |
| 11748 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11749 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11750 | if (pdone_q) |
| 11751 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11752 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11753 | return; |
| 11754 | } |
| 11755 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11756 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11757 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 11758 | * @phba: Pointer to HBA context object.. |
| 11759 | * @piocbq: Pointer to command iocb. |
| 11760 | * @flag: Flag to test. |
| 11761 | * |
| 11762 | * This routine grabs the hbalock and then test the iocb_flag to |
| 11763 | * see if the passed in flag is set. |
| 11764 | * Returns: |
| 11765 | * 1 if flag is set. |
| 11766 | * 0 if flag is not set. |
| 11767 | **/ |
| 11768 | static int |
| 11769 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 11770 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 11771 | { |
| 11772 | unsigned long iflags; |
| 11773 | int ret; |
| 11774 | |
| 11775 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11776 | ret = piocbq->iocb_flag & flag; |
| 11777 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11778 | return ret; |
| 11779 | |
| 11780 | } |
| 11781 | |
| 11782 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11783 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11784 | * @phba: Pointer to HBA context object.. |
| 11785 | * @pring: Pointer to sli ring. |
| 11786 | * @piocb: Pointer to command iocb. |
| 11787 | * @prspiocbq: Pointer to response iocb. |
| 11788 | * @timeout: Timeout in number of seconds. |
| 11789 | * |
| 11790 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11791 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 11792 | * to handle iocbs which time out. If the field is NULL, the |
| 11793 | * function shall free the iocbq structure. If more clean up is |
| 11794 | * needed, the caller is expected to provide a completion function |
| 11795 | * that will provide the needed clean up. If the iocb command is |
| 11796 | * not completed within timeout seconds, the function will either |
| 11797 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 11798 | * completion function set in the iocb_cmpl field and then return |
| 11799 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 11800 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11801 | * The function waits for the iocb completion using an |
| 11802 | * non-interruptible wait. |
| 11803 | * This function will sleep while waiting for iocb completion. |
| 11804 | * So, this function should not be called from any context which |
| 11805 | * does not allow sleeping. Due to the same reason, this function |
| 11806 | * cannot be called with interrupt disabled. |
| 11807 | * This function assumes that the iocb completions occur while |
| 11808 | * this function sleep. So, this function cannot be called from |
| 11809 | * the thread which process iocb completion for this ring. |
| 11810 | * This function clears the iocb_flag of the iocb object before |
| 11811 | * issuing the iocb and the iocb completion handler sets this |
| 11812 | * flag and wakes this thread when the iocb completes. |
| 11813 | * The contents of the response iocb will be copied to prspiocbq |
| 11814 | * by the completion handler when the command completes. |
| 11815 | * This function returns IOCB_SUCCESS when success. |
| 11816 | * This function is called with no lock held. |
| 11817 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11818 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11819 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11820 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11821 | struct lpfc_iocbq *piocb, |
| 11822 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11823 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11824 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 11825 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11826 | long timeleft, timeout_req = 0; |
| 11827 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11828 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11829 | struct lpfc_iocbq *iocb; |
| 11830 | int txq_cnt = 0; |
| 11831 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11832 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11833 | unsigned long iflags; |
| 11834 | bool iocb_completed = true; |
| 11835 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11836 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 11837 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 11838 | else |
| 11839 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11840 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11841 | * If the caller has provided a response iocbq buffer, then context2 |
| 11842 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11843 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11844 | if (prspiocbq) { |
| 11845 | if (piocb->context2) |
| 11846 | return IOCB_ERROR; |
| 11847 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11848 | } |
| 11849 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11850 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11851 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 11852 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11853 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11854 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11855 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11856 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11857 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11858 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 11859 | writel(creg_val, phba->HCregaddr); |
| 11860 | readl(phba->HCregaddr); /* flush */ |
| 11861 | } |
| 11862 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11863 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 11864 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11865 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 11866 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11867 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11868 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11869 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11870 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11871 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11872 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11873 | /* |
| 11874 | * IOCB timed out. Inform the wake iocb wait |
| 11875 | * completion function and set local status |
| 11876 | */ |
| 11877 | |
| 11878 | iocb_completed = false; |
| 11879 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 11880 | } |
| 11881 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11882 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11883 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11884 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 11885 | /* Note: we are not indicating if the IOCB has a success |
| 11886 | * status or not - that's for the caller to check. |
| 11887 | * IOCB_SUCCESS means just that the command was sent and |
| 11888 | * completed. Not that it completed successfully. |
| 11889 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11890 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11891 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11892 | "0338 IOCB wait timeout error - no " |
| 11893 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11894 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11895 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11896 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11897 | "0330 IOCB wake NOT set, " |
| 11898 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11899 | timeout, (timeleft / jiffies)); |
| 11900 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11901 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11902 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11903 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 11904 | list_for_each_entry(iocb, &pring->txq, list) { |
| 11905 | txq_cnt++; |
| 11906 | } |
| 11907 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 11908 | txcmplq_cnt++; |
| 11909 | } |
| 11910 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11911 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 11912 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 11913 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11914 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11915 | } else { |
| 11916 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11917 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11918 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11919 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11920 | } |
| 11921 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11922 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11923 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11924 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11925 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 11926 | writel(creg_val, phba->HCregaddr); |
| 11927 | readl(phba->HCregaddr); /* flush */ |
| 11928 | } |
| 11929 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11930 | if (prspiocbq) |
| 11931 | piocb->context2 = NULL; |
| 11932 | |
| 11933 | piocb->context_un.wait_queue = NULL; |
| 11934 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11935 | return retval; |
| 11936 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11937 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11938 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11939 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11940 | * @phba: Pointer to HBA context object. |
| 11941 | * @pmboxq: Pointer to driver mailbox object. |
| 11942 | * @timeout: Timeout in number of seconds. |
| 11943 | * |
| 11944 | * This function issues the mailbox to firmware and waits for the |
| 11945 | * mailbox command to complete. If the mailbox command is not |
| 11946 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 11947 | * The function waits for the mailbox completion using an |
| 11948 | * interruptible wait. If the thread is woken up due to a |
| 11949 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 11950 | * should not free the mailbox resources, if this function returns |
| 11951 | * MBX_TIMEOUT. |
| 11952 | * This function will sleep while waiting for mailbox completion. |
| 11953 | * So, this function should not be called from any context which |
| 11954 | * does not allow sleeping. Due to the same reason, this function |
| 11955 | * cannot be called with interrupt disabled. |
| 11956 | * This function assumes that the mailbox completion occurs while |
| 11957 | * this function sleep. So, this function cannot be called from |
| 11958 | * the worker thread which processes mailbox completion. |
| 11959 | * This function is called in the context of HBA management |
| 11960 | * applications. |
| 11961 | * This function returns MBX_SUCCESS when successful. |
| 11962 | * This function is called with no lock held. |
| 11963 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11964 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11965 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11966 | uint32_t timeout) |
| 11967 | { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 11968 | struct completion mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11969 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11970 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11971 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11972 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11973 | /* setup wake call as IOCB callback */ |
| 11974 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11975 | |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 11976 | /* setup context3 field to pass wait_queue pointer to wake function */ |
| 11977 | init_completion(&mbox_done); |
| 11978 | pmboxq->context3 = &mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11979 | /* now issue the command */ |
| 11980 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11981 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 11982 | wait_for_completion_timeout(&mbox_done, |
| 11983 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11984 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11985 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 11986 | pmboxq->context3 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11987 | /* |
| 11988 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 11989 | * else do not free the resources. |
| 11990 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 11991 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11992 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 11993 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11994 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11995 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 11996 | } |
| 11997 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11998 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11999 | return retval; |
| 12000 | } |
| 12001 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12002 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12003 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12004 | * @phba: Pointer to HBA context. |
| 12005 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12006 | * This function is called to shutdown the driver's mailbox sub-system. |
| 12007 | * It first marks the mailbox sub-system is in a block state to prevent |
| 12008 | * the asynchronous mailbox command from issued off the pending mailbox |
| 12009 | * command queue. If the mailbox command sub-system shutdown is due to |
| 12010 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 12011 | * the mailbox sub-system flush routine to forcefully bring down the |
| 12012 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 12013 | * as with offline or HBA function reset), this routine will wait for the |
| 12014 | * outstanding mailbox command to complete before invoking the mailbox |
| 12015 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12016 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12017 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12018 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12019 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12020 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12021 | unsigned long timeout; |
| 12022 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12023 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 12024 | /* delay 100ms for port state */ |
| 12025 | msleep(100); |
| 12026 | lpfc_sli_mbox_sys_flush(phba); |
| 12027 | return; |
| 12028 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12029 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12030 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12031 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 12032 | local_bh_disable(); |
| 12033 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12034 | spin_lock_irq(&phba->hbalock); |
| 12035 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12036 | |
| 12037 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12038 | /* Determine how long we might wait for the active mailbox |
| 12039 | * command to be gracefully completed by firmware. |
| 12040 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12041 | if (phba->sli.mbox_active) |
| 12042 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 12043 | phba->sli.mbox_active) * |
| 12044 | 1000) + jiffies; |
| 12045 | spin_unlock_irq(&phba->hbalock); |
| 12046 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12047 | /* Enable softirqs again, done with phba->hbalock */ |
| 12048 | local_bh_enable(); |
| 12049 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12050 | while (phba->sli.mbox_active) { |
| 12051 | /* Check active mailbox complete status every 2ms */ |
| 12052 | msleep(2); |
| 12053 | if (time_after(jiffies, timeout)) |
| 12054 | /* Timeout, let the mailbox flush routine to |
| 12055 | * forcefully release active mailbox command |
| 12056 | */ |
| 12057 | break; |
| 12058 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12059 | } else { |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12060 | spin_unlock_irq(&phba->hbalock); |
| 12061 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12062 | /* Enable softirqs again, done with phba->hbalock */ |
| 12063 | local_bh_enable(); |
| 12064 | } |
| 12065 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12066 | lpfc_sli_mbox_sys_flush(phba); |
| 12067 | } |
| 12068 | |
| 12069 | /** |
| 12070 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 12071 | * @phba: Pointer to HBA context. |
| 12072 | * |
| 12073 | * This function is called to read the SLI3 device error attention registers |
| 12074 | * for possible error attention events. The caller must hold the hostlock |
| 12075 | * with spin_lock_irq(). |
| 12076 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12077 | * 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] | 12078 | * Register and returns 0 otherwise. |
| 12079 | **/ |
| 12080 | static int |
| 12081 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 12082 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 12083 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12084 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12085 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12086 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12087 | goto unplug_err; |
| 12088 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12089 | if (ha_copy & HA_ERATT) { |
| 12090 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12091 | if (lpfc_sli_read_hs(phba)) |
| 12092 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12093 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12094 | /* Check if there is a deferred error condition is active */ |
| 12095 | if ((HS_FFER1 & phba->work_hs) && |
| 12096 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12097 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12098 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12099 | /* Clear all interrupt enable conditions */ |
| 12100 | writel(0, phba->HCregaddr); |
| 12101 | readl(phba->HCregaddr); |
| 12102 | } |
| 12103 | |
| 12104 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12105 | phba->work_ha |= HA_ERATT; |
| 12106 | /* Indicate polling handles this ERATT */ |
| 12107 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12108 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12109 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12110 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12111 | |
| 12112 | unplug_err: |
| 12113 | /* Set the driver HS work bitmap */ |
| 12114 | phba->work_hs |= UNPLUG_ERR; |
| 12115 | /* Set the driver HA work bitmap */ |
| 12116 | phba->work_ha |= HA_ERATT; |
| 12117 | /* Indicate polling handles this ERATT */ |
| 12118 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12119 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12120 | } |
| 12121 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12122 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12123 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 12124 | * @phba: Pointer to HBA context. |
| 12125 | * |
| 12126 | * This function is called to read the SLI4 device error attention registers |
| 12127 | * for possible error attention events. The caller must hold the hostlock |
| 12128 | * with spin_lock_irq(). |
| 12129 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12130 | * 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] | 12131 | * Register and returns 0 otherwise. |
| 12132 | **/ |
| 12133 | static int |
| 12134 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 12135 | { |
| 12136 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12137 | uint32_t if_type, portsmphr; |
| 12138 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12139 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12140 | /* |
| 12141 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12142 | * registers for error attention. This can be changed later. |
| 12143 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12144 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 12145 | switch (if_type) { |
| 12146 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12147 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 12148 | &uerr_sta_lo) || |
| 12149 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 12150 | &uerr_sta_hi)) { |
| 12151 | phba->work_hs |= UNPLUG_ERR; |
| 12152 | phba->work_ha |= HA_ERATT; |
| 12153 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12154 | return 1; |
| 12155 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12156 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 12157 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 12158 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12159 | "1423 HBA Unrecoverable error: " |
| 12160 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 12161 | "ue_mask_lo_reg=0x%x, " |
| 12162 | "ue_mask_hi_reg=0x%x\n", |
| 12163 | uerr_sta_lo, uerr_sta_hi, |
| 12164 | phba->sli4_hba.ue_mask_lo, |
| 12165 | phba->sli4_hba.ue_mask_hi); |
| 12166 | phba->work_status[0] = uerr_sta_lo; |
| 12167 | phba->work_status[1] = uerr_sta_hi; |
| 12168 | phba->work_ha |= HA_ERATT; |
| 12169 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12170 | return 1; |
| 12171 | } |
| 12172 | break; |
| 12173 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 12174 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12175 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 12176 | &portstat_reg.word0) || |
| 12177 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 12178 | &portsmphr)){ |
| 12179 | phba->work_hs |= UNPLUG_ERR; |
| 12180 | phba->work_ha |= HA_ERATT; |
| 12181 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12182 | return 1; |
| 12183 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12184 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 12185 | phba->work_status[0] = |
| 12186 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 12187 | phba->work_status[1] = |
| 12188 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 12189 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12190 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12191 | "port status reg 0x%x, " |
| 12192 | "port smphr reg 0x%x, " |
| 12193 | "error 1=0x%x, error 2=0x%x\n", |
| 12194 | portstat_reg.word0, |
| 12195 | portsmphr, |
| 12196 | phba->work_status[0], |
| 12197 | phba->work_status[1]); |
| 12198 | phba->work_ha |= HA_ERATT; |
| 12199 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12200 | return 1; |
| 12201 | } |
| 12202 | break; |
| 12203 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 12204 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12205 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12206 | "2886 HBA Error Attention on unsupported " |
| 12207 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12208 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12209 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12210 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12211 | return 0; |
| 12212 | } |
| 12213 | |
| 12214 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12215 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12216 | * @phba: Pointer to HBA context. |
| 12217 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12218 | * 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] | 12219 | * error attention register bit for error attention events. |
| 12220 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12221 | * 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] | 12222 | * Register and returns 0 otherwise. |
| 12223 | **/ |
| 12224 | int |
| 12225 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 12226 | { |
| 12227 | uint32_t ha_copy; |
| 12228 | |
| 12229 | /* If somebody is waiting to handle an eratt, don't process it |
| 12230 | * here. The brdkill function will do this. |
| 12231 | */ |
| 12232 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12233 | return 0; |
| 12234 | |
| 12235 | /* Check if interrupt handler handles this ERATT */ |
| 12236 | spin_lock_irq(&phba->hbalock); |
| 12237 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 12238 | /* Interrupt handler has handled ERATT */ |
| 12239 | spin_unlock_irq(&phba->hbalock); |
| 12240 | return 0; |
| 12241 | } |
| 12242 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12243 | /* |
| 12244 | * If there is deferred error attention, do not check for error |
| 12245 | * attention |
| 12246 | */ |
| 12247 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 12248 | spin_unlock_irq(&phba->hbalock); |
| 12249 | return 0; |
| 12250 | } |
| 12251 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12252 | /* If PCI channel is offline, don't process it */ |
| 12253 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12254 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12255 | return 0; |
| 12256 | } |
| 12257 | |
| 12258 | switch (phba->sli_rev) { |
| 12259 | case LPFC_SLI_REV2: |
| 12260 | case LPFC_SLI_REV3: |
| 12261 | /* Read chip Host Attention (HA) register */ |
| 12262 | ha_copy = lpfc_sli_eratt_read(phba); |
| 12263 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12264 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12265 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12266 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 12267 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12268 | default: |
| 12269 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12270 | "0299 Invalid SLI revision (%d)\n", |
| 12271 | phba->sli_rev); |
| 12272 | ha_copy = 0; |
| 12273 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12274 | } |
| 12275 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12276 | |
| 12277 | return ha_copy; |
| 12278 | } |
| 12279 | |
| 12280 | /** |
| 12281 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 12282 | * @phba: Pointer to HBA context. |
| 12283 | * |
| 12284 | * This inline routine checks whether a device or its PCI slot is in a state |
| 12285 | * that the interrupt should be handled. |
| 12286 | * |
| 12287 | * This function returns 0 if the device or the PCI slot is in a state that |
| 12288 | * interrupt should be handled, otherwise -EIO. |
| 12289 | */ |
| 12290 | static inline int |
| 12291 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 12292 | { |
| 12293 | /* If the pci channel is offline, ignore all the interrupts */ |
| 12294 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 12295 | return -EIO; |
| 12296 | |
| 12297 | /* Update device level interrupt statistics */ |
| 12298 | phba->sli.slistat.sli_intr++; |
| 12299 | |
| 12300 | /* Ignore all interrupts during initialization. */ |
| 12301 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 12302 | return -EIO; |
| 12303 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12304 | return 0; |
| 12305 | } |
| 12306 | |
| 12307 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12308 | * 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] | 12309 | * @irq: Interrupt number. |
| 12310 | * @dev_id: The device context pointer. |
| 12311 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12312 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12313 | * service routine when device with SLI-3 interface spec is enabled with |
| 12314 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 12315 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 12316 | * interrupt mode, this function is called as part of the device-level |
| 12317 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 12318 | * is undergoing initialization, the interrupt handler will not process |
| 12319 | * the interrupt. The link attention and ELS ring attention events are |
| 12320 | * handled by the worker thread. The interrupt handler signals the worker |
| 12321 | * thread and returns for these events. This function is called without |
| 12322 | * 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] | 12323 | * structures. |
| 12324 | * |
| 12325 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12326 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12327 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12328 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12329 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12330 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12331 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12332 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12333 | uint32_t work_ha_copy; |
| 12334 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12335 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12336 | uint32_t control; |
| 12337 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12338 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12339 | struct lpfc_vport *vport; |
| 12340 | struct lpfc_nodelist *ndlp; |
| 12341 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12342 | LPFC_MBOXQ_t *pmb; |
| 12343 | int rc; |
| 12344 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12345 | /* |
| 12346 | * Get the driver's phba structure from the dev_id and |
| 12347 | * assume the HBA is not interrupting. |
| 12348 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12349 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12350 | |
| 12351 | if (unlikely(!phba)) |
| 12352 | return IRQ_NONE; |
| 12353 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12354 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12355 | * Stuff needs to be attented to when this function is invoked as an |
| 12356 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12357 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12358 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12359 | /* Check device state for handling interrupt */ |
| 12360 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12361 | return IRQ_NONE; |
| 12362 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12363 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12364 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12365 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12366 | /* If somebody is waiting to handle an eratt don't process it |
| 12367 | * here. The brdkill function will do this. |
| 12368 | */ |
| 12369 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12370 | ha_copy &= ~HA_ERATT; |
| 12371 | /* Check the need for handling ERATT in interrupt handler */ |
| 12372 | if (ha_copy & HA_ERATT) { |
| 12373 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12374 | /* ERATT polling has handled ERATT */ |
| 12375 | ha_copy &= ~HA_ERATT; |
| 12376 | else |
| 12377 | /* Indicate interrupt handler handles ERATT */ |
| 12378 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12379 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12380 | |
| 12381 | /* |
| 12382 | * If there is deferred error attention, do not check for any |
| 12383 | * interrupt. |
| 12384 | */ |
| 12385 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12386 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12387 | return IRQ_NONE; |
| 12388 | } |
| 12389 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12390 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12391 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 12392 | goto unplug_error; |
| 12393 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12394 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 12395 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12396 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12397 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 12398 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12399 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12400 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12401 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12402 | } else |
| 12403 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12404 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12405 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 12406 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12407 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12408 | if (work_ha_copy & HA_LATT) { |
| 12409 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 12410 | /* |
| 12411 | * Turn off Link Attention interrupts |
| 12412 | * until CLEAR_LA done |
| 12413 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12414 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12415 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12416 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12417 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12418 | control &= ~HC_LAINT_ENA; |
| 12419 | writel(control, phba->HCregaddr); |
| 12420 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12421 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12422 | } |
| 12423 | else |
| 12424 | work_ha_copy &= ~HA_LATT; |
| 12425 | } |
| 12426 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12427 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12428 | /* |
| 12429 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 12430 | * the only slow ring. |
| 12431 | */ |
| 12432 | status = (work_ha_copy & |
| 12433 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12434 | status >>= (4*LPFC_ELS_RING); |
| 12435 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12436 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12437 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12438 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12439 | |
| 12440 | lpfc_debugfs_slow_ring_trc(phba, |
| 12441 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 12442 | control, status, |
| 12443 | (uint32_t)phba->sli.slistat.sli_intr); |
| 12444 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12445 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12446 | lpfc_debugfs_slow_ring_trc(phba, |
| 12447 | "ISR Disable ring:" |
| 12448 | "pwork:x%x hawork:x%x wait:x%x", |
| 12449 | phba->work_ha, work_ha_copy, |
| 12450 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12451 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12452 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12453 | control &= |
| 12454 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12455 | writel(control, phba->HCregaddr); |
| 12456 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12457 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12458 | else { |
| 12459 | lpfc_debugfs_slow_ring_trc(phba, |
| 12460 | "ISR slow ring: pwork:" |
| 12461 | "x%x hawork:x%x wait:x%x", |
| 12462 | phba->work_ha, work_ha_copy, |
| 12463 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12464 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12465 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12466 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12467 | } |
| 12468 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12469 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12470 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12471 | if (lpfc_sli_read_hs(phba)) |
| 12472 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12473 | /* |
| 12474 | * Check if there is a deferred error condition |
| 12475 | * is active |
| 12476 | */ |
| 12477 | if ((HS_FFER1 & phba->work_hs) && |
| 12478 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12479 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 12480 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12481 | phba->hba_flag |= DEFER_ERATT; |
| 12482 | /* Clear all interrupt enable conditions */ |
| 12483 | writel(0, phba->HCregaddr); |
| 12484 | readl(phba->HCregaddr); |
| 12485 | } |
| 12486 | } |
| 12487 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12488 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12489 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12490 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12491 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12492 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12493 | |
| 12494 | /* First check out the status word */ |
| 12495 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 12496 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12497 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12498 | /* |
| 12499 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 12500 | * mbxStatus <status> |
| 12501 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12502 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12503 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12504 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12505 | "Interrupt mbxCommand x%x " |
| 12506 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12507 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12508 | pmbox->mbxCommand, |
| 12509 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12510 | /* clear mailbox attention bit */ |
| 12511 | work_ha_copy &= ~HA_MBATT; |
| 12512 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12513 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12514 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12515 | phba->last_completion_time = jiffies; |
| 12516 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12517 | if (pmb->mbox_cmpl) { |
| 12518 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 12519 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12520 | if (pmb->out_ext_byte_len && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12521 | pmb->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12522 | lpfc_sli_pcimem_bcopy( |
| 12523 | phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12524 | pmb->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12525 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12526 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12527 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12528 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12529 | |
| 12530 | lpfc_debugfs_disc_trc(vport, |
| 12531 | LPFC_DISC_TRC_MBOX_VPORT, |
| 12532 | "MBOX dflt rpi: : " |
| 12533 | "status:x%x rpi:x%x", |
| 12534 | (uint32_t)pmbox->mbxStatus, |
| 12535 | pmbox->un.varWords[0], 0); |
| 12536 | |
| 12537 | if (!pmbox->mbxStatus) { |
| 12538 | mp = (struct lpfc_dmabuf *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12539 | (pmb->ctx_buf); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12540 | ndlp = (struct lpfc_nodelist *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12541 | pmb->ctx_ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12542 | |
| 12543 | /* Reg_LOGIN of dflt RPI was |
| 12544 | * successful. new lets get |
| 12545 | * rid of the RPI using the |
| 12546 | * same mbox buffer. |
| 12547 | */ |
| 12548 | lpfc_unreg_login(phba, |
| 12549 | vport->vpi, |
| 12550 | pmbox->un.varWords[0], |
| 12551 | pmb); |
| 12552 | pmb->mbox_cmpl = |
| 12553 | lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12554 | pmb->ctx_buf = mp; |
| 12555 | pmb->ctx_ndlp = ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12556 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12557 | rc = lpfc_sli_issue_mbox(phba, |
| 12558 | pmb, |
| 12559 | MBX_NOWAIT); |
| 12560 | if (rc != MBX_BUSY) |
| 12561 | lpfc_printf_log(phba, |
| 12562 | KERN_ERR, |
| 12563 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12564 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12565 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12566 | if (rc != MBX_NOT_FINISHED) |
| 12567 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12568 | } |
| 12569 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12570 | spin_lock_irqsave( |
| 12571 | &phba->pport->work_port_lock, |
| 12572 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12573 | phba->pport->work_port_events &= |
| 12574 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12575 | spin_unlock_irqrestore( |
| 12576 | &phba->pport->work_port_lock, |
| 12577 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12578 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12579 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12580 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12581 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12582 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12583 | if ((work_ha_copy & HA_MBATT) && |
| 12584 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12585 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12586 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12587 | do { |
| 12588 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 12589 | MBX_NOWAIT); |
| 12590 | } while (rc == MBX_NOT_FINISHED); |
| 12591 | if (rc != MBX_SUCCESS) |
| 12592 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12593 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12594 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12595 | } |
| 12596 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12597 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12598 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12599 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12600 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12601 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12602 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12603 | unplug_error: |
| 12604 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12605 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12606 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12607 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12608 | |
| 12609 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12610 | * 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] | 12611 | * @irq: Interrupt number. |
| 12612 | * @dev_id: The device context pointer. |
| 12613 | * |
| 12614 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12615 | * service routine when device with SLI-3 interface spec is enabled with |
| 12616 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12617 | * ring event in the HBA. However, when the device is enabled with either |
| 12618 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12619 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12620 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12621 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12622 | * the intrrupt context. This function is called without any lock held. |
| 12623 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12624 | * |
| 12625 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12626 | * returns IRQ_NONE. |
| 12627 | **/ |
| 12628 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12629 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12630 | { |
| 12631 | struct lpfc_hba *phba; |
| 12632 | uint32_t ha_copy; |
| 12633 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12634 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12635 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12636 | |
| 12637 | /* Get the driver's phba structure from the dev_id and |
| 12638 | * assume the HBA is not interrupting. |
| 12639 | */ |
| 12640 | phba = (struct lpfc_hba *) dev_id; |
| 12641 | |
| 12642 | if (unlikely(!phba)) |
| 12643 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12644 | |
| 12645 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12646 | * Stuff needs to be attented to when this function is invoked as an |
| 12647 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12648 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12649 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12650 | /* Check device state for handling interrupt */ |
| 12651 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12652 | return IRQ_NONE; |
| 12653 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12654 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12655 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12656 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12657 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12658 | /* |
| 12659 | * If there is deferred error attention, do not check for |
| 12660 | * any interrupt. |
| 12661 | */ |
| 12662 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12663 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12664 | return IRQ_NONE; |
| 12665 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12666 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 12667 | phba->HAregaddr); |
| 12668 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12669 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12670 | } else |
| 12671 | ha_copy = phba->ha_copy; |
| 12672 | |
| 12673 | /* |
| 12674 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 12675 | */ |
| 12676 | ha_copy &= ~(phba->work_ha_mask); |
| 12677 | |
| 12678 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12679 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12680 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12681 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12682 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12683 | |
| 12684 | if (phba->cfg_multi_ring_support == 2) { |
| 12685 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12686 | * Process all events on extra ring. Take the optimized path |
| 12687 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12688 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12689 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12690 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12691 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12692 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12693 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12694 | status); |
| 12695 | } |
| 12696 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12697 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12698 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12699 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12700 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12701 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12702 | * @irq: Interrupt number. |
| 12703 | * @dev_id: The device context pointer. |
| 12704 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12705 | * This function is the HBA device-level interrupt handler to device with |
| 12706 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 12707 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 12708 | * requires driver attention. This function invokes the slow-path interrupt |
| 12709 | * attention handling function and fast-path interrupt attention handling |
| 12710 | * function in turn to process the relevant HBA attention events. This |
| 12711 | * function is called without any lock held. It gets the hbalock to access |
| 12712 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12713 | * |
| 12714 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12715 | * returns IRQ_NONE. |
| 12716 | **/ |
| 12717 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12718 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12719 | { |
| 12720 | struct lpfc_hba *phba; |
| 12721 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 12722 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12723 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12724 | |
| 12725 | /* |
| 12726 | * Get the driver's phba structure from the dev_id and |
| 12727 | * assume the HBA is not interrupting. |
| 12728 | */ |
| 12729 | phba = (struct lpfc_hba *) dev_id; |
| 12730 | |
| 12731 | if (unlikely(!phba)) |
| 12732 | return IRQ_NONE; |
| 12733 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12734 | /* Check device state for handling interrupt */ |
| 12735 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12736 | return IRQ_NONE; |
| 12737 | |
| 12738 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12739 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 12740 | spin_unlock(&phba->hbalock); |
| 12741 | return IRQ_HANDLED; |
| 12742 | } |
| 12743 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12744 | if (unlikely(!phba->ha_copy)) { |
| 12745 | spin_unlock(&phba->hbalock); |
| 12746 | return IRQ_NONE; |
| 12747 | } else if (phba->ha_copy & HA_ERATT) { |
| 12748 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12749 | /* ERATT polling has handled ERATT */ |
| 12750 | phba->ha_copy &= ~HA_ERATT; |
| 12751 | else |
| 12752 | /* Indicate interrupt handler handles ERATT */ |
| 12753 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12754 | } |
| 12755 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12756 | /* |
| 12757 | * If there is deferred error attention, do not check for any interrupt. |
| 12758 | */ |
| 12759 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 12760 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12761 | return IRQ_NONE; |
| 12762 | } |
| 12763 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12764 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12765 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 12766 | spin_unlock(&phba->hbalock); |
| 12767 | return IRQ_HANDLED; |
| 12768 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12769 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 12770 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12771 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12772 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12773 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12774 | readl(phba->HAregaddr); /* flush */ |
| 12775 | spin_unlock(&phba->hbalock); |
| 12776 | |
| 12777 | /* |
| 12778 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 12779 | */ |
| 12780 | |
| 12781 | /* status of events with mailbox and link attention */ |
| 12782 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 12783 | |
| 12784 | /* status of events with ELS ring */ |
| 12785 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12786 | status2 >>= (4*LPFC_ELS_RING); |
| 12787 | |
| 12788 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12789 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12790 | else |
| 12791 | sp_irq_rc = IRQ_NONE; |
| 12792 | |
| 12793 | /* |
| 12794 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12795 | */ |
| 12796 | |
| 12797 | /* status of events with FCP ring */ |
| 12798 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 12799 | status1 >>= (4*LPFC_FCP_RING); |
| 12800 | |
| 12801 | /* status of events with extra ring */ |
| 12802 | if (phba->cfg_multi_ring_support == 2) { |
| 12803 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 12804 | status2 >>= (4*LPFC_EXTRA_RING); |
| 12805 | } else |
| 12806 | status2 = 0; |
| 12807 | |
| 12808 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12809 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12810 | else |
| 12811 | fp_irq_rc = IRQ_NONE; |
| 12812 | |
| 12813 | /* Return device-level interrupt handling status */ |
| 12814 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12815 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12816 | |
| 12817 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12818 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 12819 | * @phba: pointer to lpfc hba data structure. |
| 12820 | * |
| 12821 | * This routine is invoked by the worker thread to process all the pending |
| 12822 | * SLI4 els abort xri events. |
| 12823 | **/ |
| 12824 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12825 | { |
| 12826 | struct lpfc_cq_event *cq_event; |
| 12827 | |
| 12828 | /* First, declare the els xri abort event has been handled */ |
| 12829 | spin_lock_irq(&phba->hbalock); |
| 12830 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 12831 | spin_unlock_irq(&phba->hbalock); |
| 12832 | /* Now, handle all the els xri abort events */ |
| 12833 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 12834 | /* Get the first event from the head of the event queue */ |
| 12835 | spin_lock_irq(&phba->hbalock); |
| 12836 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 12837 | cq_event, struct lpfc_cq_event, list); |
| 12838 | spin_unlock_irq(&phba->hbalock); |
| 12839 | /* Notify aborted XRI for ELS work queue */ |
| 12840 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12841 | /* Free the event processed back to the free pool */ |
| 12842 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12843 | } |
| 12844 | } |
| 12845 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12846 | /** |
| 12847 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 12848 | * @phba: pointer to lpfc hba data structure |
| 12849 | * @pIocbIn: pointer to the rspiocbq |
| 12850 | * @pIocbOut: pointer to the cmdiocbq |
| 12851 | * @wcqe: pointer to the complete wcqe |
| 12852 | * |
| 12853 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 12854 | * by copying all the IOCB fields from command iocbq and transferring the |
| 12855 | * completion status information from the complete wcqe. |
| 12856 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12857 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12858 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 12859 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12860 | struct lpfc_iocbq *pIocbOut, |
| 12861 | struct lpfc_wcqe_complete *wcqe) |
| 12862 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12863 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12864 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12865 | uint32_t status, max_response; |
| 12866 | struct lpfc_dmabuf *dmabuf; |
| 12867 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12868 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 12869 | |
| 12870 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 12871 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12872 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12873 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 12874 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12875 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 12876 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 12877 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 12878 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 12879 | wcqe->total_data_placed; |
| 12880 | else |
| 12881 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12882 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12883 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12884 | switch (pIocbOut->iocb.ulpCommand) { |
| 12885 | case CMD_ELS_REQUEST64_CR: |
| 12886 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12887 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12888 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 12889 | max_response = bde.tus.f.bdeSize; |
| 12890 | break; |
| 12891 | case CMD_GEN_REQUEST64_CR: |
| 12892 | max_response = 0; |
| 12893 | if (!pIocbOut->context3) |
| 12894 | break; |
| 12895 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 12896 | sizeof(struct ulp_bde64); |
| 12897 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12898 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12899 | for (i = 0; i < numBdes; i++) { |
| 12900 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 12901 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 12902 | max_response += bde.tus.f.bdeSize; |
| 12903 | } |
| 12904 | break; |
| 12905 | default: |
| 12906 | max_response = wcqe->total_data_placed; |
| 12907 | break; |
| 12908 | } |
| 12909 | if (max_response < wcqe->total_data_placed) |
| 12910 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 12911 | else |
| 12912 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 12913 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12914 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12915 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12916 | /* Convert BG errors for completion status */ |
| 12917 | if (status == CQE_STATUS_DI_ERROR) { |
| 12918 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 12919 | |
| 12920 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 12921 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 12922 | else |
| 12923 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 12924 | |
| 12925 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 12926 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 12927 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12928 | BGS_GUARD_ERR_MASK; |
| 12929 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 12930 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12931 | BGS_APPTAG_ERR_MASK; |
| 12932 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 12933 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12934 | BGS_REFTAG_ERR_MASK; |
| 12935 | |
| 12936 | /* Check to see if there was any good data before the error */ |
| 12937 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 12938 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12939 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 12940 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 12941 | wcqe->total_data_placed; |
| 12942 | } |
| 12943 | |
| 12944 | /* |
| 12945 | * Set ALL the error bits to indicate we don't know what |
| 12946 | * type of error it is. |
| 12947 | */ |
| 12948 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 12949 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12950 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 12951 | BGS_GUARD_ERR_MASK); |
| 12952 | } |
| 12953 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12954 | /* Pick up HBA exchange busy condition */ |
| 12955 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 12956 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12957 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 12958 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12959 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12960 | } |
| 12961 | |
| 12962 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12963 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 12964 | * @phba: Pointer to HBA context object. |
| 12965 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12966 | * |
| 12967 | * This routine handles an ELS work-queue completion event and construct |
| 12968 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 12969 | * discovery engine to handle. |
| 12970 | * |
| 12971 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 12972 | **/ |
| 12973 | static struct lpfc_iocbq * |
| 12974 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 12975 | struct lpfc_iocbq *irspiocbq) |
| 12976 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12977 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12978 | struct lpfc_iocbq *cmdiocbq; |
| 12979 | struct lpfc_wcqe_complete *wcqe; |
| 12980 | unsigned long iflags; |
| 12981 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12982 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 12983 | if (unlikely(!pring)) |
| 12984 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12985 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12986 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12987 | pring->stats.iocb_event++; |
| 12988 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 12989 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 12990 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12991 | if (unlikely(!cmdiocbq)) { |
| 12992 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12993 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 12994 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 12995 | wcqe->word0, wcqe->total_data_placed, |
| 12996 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12997 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 12998 | return NULL; |
| 12999 | } |
| 13000 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 13001 | spin_lock_irqsave(&pring->ring_lock, iflags); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13002 | /* Put the iocb back on the txcmplq */ |
| 13003 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 13004 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 13005 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13006 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13007 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13008 | |
| 13009 | return irspiocbq; |
| 13010 | } |
| 13011 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13012 | inline struct lpfc_cq_event * |
| 13013 | lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size) |
| 13014 | { |
| 13015 | struct lpfc_cq_event *cq_event; |
| 13016 | |
| 13017 | /* Allocate a new internal CQ_EVENT entry */ |
| 13018 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 13019 | if (!cq_event) { |
| 13020 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13021 | "0602 Failed to alloc CQ_EVENT entry\n"); |
| 13022 | return NULL; |
| 13023 | } |
| 13024 | |
| 13025 | /* Move the CQE into the event */ |
| 13026 | memcpy(&cq_event->cqe, entry, size); |
| 13027 | return cq_event; |
| 13028 | } |
| 13029 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13030 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13031 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 13032 | * @phba: Pointer to HBA context object. |
| 13033 | * @cqe: Pointer to mailbox completion queue entry. |
| 13034 | * |
| 13035 | * This routine process a mailbox completion queue entry with asynchrous |
| 13036 | * event. |
| 13037 | * |
| 13038 | * Return: true if work posted to worker thread, otherwise false. |
| 13039 | **/ |
| 13040 | static bool |
| 13041 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13042 | { |
| 13043 | struct lpfc_cq_event *cq_event; |
| 13044 | unsigned long iflags; |
| 13045 | |
| 13046 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13047 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 13048 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 13049 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 13050 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13051 | cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe)); |
| 13052 | if (!cq_event) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13053 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13054 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13055 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 13056 | /* Set the async event flag */ |
| 13057 | phba->hba_flag |= ASYNC_EVENT; |
| 13058 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13059 | |
| 13060 | return true; |
| 13061 | } |
| 13062 | |
| 13063 | /** |
| 13064 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 13065 | * @phba: Pointer to HBA context object. |
| 13066 | * @cqe: Pointer to mailbox completion queue entry. |
| 13067 | * |
| 13068 | * This routine process a mailbox completion queue entry with mailbox |
| 13069 | * completion event. |
| 13070 | * |
| 13071 | * Return: true if work posted to worker thread, otherwise false. |
| 13072 | **/ |
| 13073 | static bool |
| 13074 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13075 | { |
| 13076 | uint32_t mcqe_status; |
| 13077 | MAILBOX_t *mbox, *pmbox; |
| 13078 | struct lpfc_mqe *mqe; |
| 13079 | struct lpfc_vport *vport; |
| 13080 | struct lpfc_nodelist *ndlp; |
| 13081 | struct lpfc_dmabuf *mp; |
| 13082 | unsigned long iflags; |
| 13083 | LPFC_MBOXQ_t *pmb; |
| 13084 | bool workposted = false; |
| 13085 | int rc; |
| 13086 | |
| 13087 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 13088 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 13089 | goto out_no_mqe_complete; |
| 13090 | |
| 13091 | /* Get the reference to the active mbox command */ |
| 13092 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13093 | pmb = phba->sli.mbox_active; |
| 13094 | if (unlikely(!pmb)) { |
| 13095 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 13096 | "1832 No pending MBOX command to handle\n"); |
| 13097 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13098 | goto out_no_mqe_complete; |
| 13099 | } |
| 13100 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13101 | mqe = &pmb->u.mqe; |
| 13102 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 13103 | mbox = phba->mbox; |
| 13104 | vport = pmb->vport; |
| 13105 | |
| 13106 | /* Reset heartbeat timer */ |
| 13107 | phba->last_completion_time = jiffies; |
| 13108 | del_timer(&phba->sli.mbox_tmo); |
| 13109 | |
| 13110 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 13111 | if (pmb->mbox_cmpl && mbox) |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13112 | lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13113 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13114 | /* |
| 13115 | * For mcqe errors, conditionally move a modified error code to |
| 13116 | * the mbox so that the error will not be missed. |
| 13117 | */ |
| 13118 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 13119 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 13120 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 13121 | bf_set(lpfc_mqe_status, mqe, |
| 13122 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 13123 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13124 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 13125 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 13126 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 13127 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 13128 | mcqe_status, |
| 13129 | pmbox->un.varWords[0], 0); |
| 13130 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13131 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 13132 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13133 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 13134 | * RID of the PPI using the same mbox buffer. |
| 13135 | */ |
| 13136 | lpfc_unreg_login(phba, vport->vpi, |
| 13137 | pmbox->un.varWords[0], pmb); |
| 13138 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13139 | pmb->ctx_buf = mp; |
| 13140 | pmb->ctx_ndlp = ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13141 | pmb->vport = vport; |
| 13142 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 13143 | if (rc != MBX_BUSY) |
| 13144 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 13145 | LOG_SLI, "0385 rc should " |
| 13146 | "have been MBX_BUSY\n"); |
| 13147 | if (rc != MBX_NOT_FINISHED) |
| 13148 | goto send_current_mbox; |
| 13149 | } |
| 13150 | } |
| 13151 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 13152 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 13153 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 13154 | |
| 13155 | /* There is mailbox completion work to do */ |
| 13156 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13157 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 13158 | phba->work_ha |= HA_MBATT; |
| 13159 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13160 | workposted = true; |
| 13161 | |
| 13162 | send_current_mbox: |
| 13163 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13164 | /* Release the mailbox command posting token */ |
| 13165 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 13166 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 13167 | phba->sli.mbox_active = NULL; |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame^] | 13168 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13169 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13170 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13171 | /* Wake up worker thread to post the next pending mailbox command */ |
| 13172 | lpfc_worker_wake_up(phba); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame^] | 13173 | return workposted; |
| 13174 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13175 | out_no_mqe_complete: |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame^] | 13176 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13177 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13178 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame^] | 13179 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13180 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13181 | } |
| 13182 | |
| 13183 | /** |
| 13184 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 13185 | * @phba: Pointer to HBA context object. |
| 13186 | * @cqe: Pointer to mailbox completion queue entry. |
| 13187 | * |
| 13188 | * This routine process a mailbox completion queue entry, it invokes the |
| 13189 | * proper mailbox complete handling or asynchrous event handling routine |
| 13190 | * according to the MCQE's async bit. |
| 13191 | * |
| 13192 | * Return: true if work posted to worker thread, otherwise false. |
| 13193 | **/ |
| 13194 | static bool |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13195 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13196 | struct lpfc_cqe *cqe) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13197 | { |
| 13198 | struct lpfc_mcqe mcqe; |
| 13199 | bool workposted; |
| 13200 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13201 | cq->CQ_mbox++; |
| 13202 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13203 | /* Copy the mailbox MCQE and convert endian order as needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13204 | lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13205 | |
| 13206 | /* Invoke the proper event handling routine */ |
| 13207 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 13208 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 13209 | else |
| 13210 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 13211 | return workposted; |
| 13212 | } |
| 13213 | |
| 13214 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13215 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 13216 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13217 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13218 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13219 | * |
| 13220 | * This routine handles an ELS work-queue completion event. |
| 13221 | * |
| 13222 | * Return: true if work posted to worker thread, otherwise false. |
| 13223 | **/ |
| 13224 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13225 | 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] | 13226 | struct lpfc_wcqe_complete *wcqe) |
| 13227 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13228 | struct lpfc_iocbq *irspiocbq; |
| 13229 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13230 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13231 | int txq_cnt = 0; |
| 13232 | int txcmplq_cnt = 0; |
| 13233 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13234 | |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13235 | /* Check for response status */ |
| 13236 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13237 | /* Log the error status */ |
| 13238 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13239 | "0357 ELS CQE error: status=x%x: " |
| 13240 | "CQE: %08x %08x %08x %08x\n", |
| 13241 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 13242 | wcqe->word0, wcqe->total_data_placed, |
| 13243 | wcqe->parameter, wcqe->word3); |
| 13244 | } |
| 13245 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13246 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13247 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 13248 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13249 | if (!list_empty(&pring->txq)) |
| 13250 | txq_cnt++; |
| 13251 | if (!list_empty(&pring->txcmplq)) |
| 13252 | txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13253 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 13254 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 13255 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13256 | txq_cnt, phba->iocb_cnt, |
| 13257 | fcp_txcmplq_cnt, |
| 13258 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13259 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13260 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13261 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13262 | /* Save off the slow-path queue event for work thread to process */ |
| 13263 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13264 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13265 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13266 | &phba->sli4_hba.sp_queue_event); |
| 13267 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13268 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13269 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13270 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13271 | } |
| 13272 | |
| 13273 | /** |
| 13274 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 13275 | * @phba: Pointer to HBA context object. |
| 13276 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13277 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13278 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13279 | * proper WQ release routine to the slow-path WQ. |
| 13280 | **/ |
| 13281 | static void |
| 13282 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 13283 | struct lpfc_wcqe_release *wcqe) |
| 13284 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13285 | /* sanity check on queue memory */ |
| 13286 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 13287 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13288 | /* Check for the slow-path ELS work queue */ |
| 13289 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 13290 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 13291 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 13292 | else |
| 13293 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13294 | "2579 Slow-path wqe consume event carries " |
| 13295 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 13296 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 13297 | phba->sli4_hba.els_wq->queue_id); |
| 13298 | } |
| 13299 | |
| 13300 | /** |
| 13301 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 13302 | * @phba: Pointer to HBA context object. |
| 13303 | * @cq: Pointer to a WQ completion queue. |
| 13304 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13305 | * |
| 13306 | * This routine handles an XRI abort event. |
| 13307 | * |
| 13308 | * Return: true if work posted to worker thread, otherwise false. |
| 13309 | **/ |
| 13310 | static bool |
| 13311 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 13312 | struct lpfc_queue *cq, |
| 13313 | struct sli4_wcqe_xri_aborted *wcqe) |
| 13314 | { |
| 13315 | bool workposted = false; |
| 13316 | struct lpfc_cq_event *cq_event; |
| 13317 | unsigned long iflags; |
| 13318 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13319 | switch (cq->subtype) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13320 | case LPFC_IO: |
| 13321 | lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq); |
| 13322 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 13323 | /* Notify aborted XRI for NVME work queue */ |
| 13324 | if (phba->nvmet_support) |
| 13325 | lpfc_sli4_nvmet_xri_aborted(phba, wcqe); |
| 13326 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13327 | workposted = false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13328 | break; |
James Smart | 422c4cb | 2017-11-20 16:00:32 -0800 | [diff] [blame] | 13329 | case LPFC_NVME_LS: /* NVME LS uses ELS resources */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13330 | case LPFC_ELS: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13331 | cq_event = lpfc_cq_event_setup( |
| 13332 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 13333 | if (!cq_event) |
| 13334 | return false; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13335 | cq_event->hdwq = cq->hdwq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13336 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13337 | list_add_tail(&cq_event->list, |
| 13338 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 13339 | /* Set the els xri abort event flag */ |
| 13340 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 13341 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13342 | workposted = true; |
| 13343 | break; |
| 13344 | default: |
| 13345 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13346 | "0603 Invalid CQ subtype %d: " |
| 13347 | "%08x %08x %08x %08x\n", |
| 13348 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 13349 | wcqe->word2, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13350 | workposted = false; |
| 13351 | break; |
| 13352 | } |
| 13353 | return workposted; |
| 13354 | } |
| 13355 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13356 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 13357 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13358 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13359 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13360 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13361 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13362 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13363 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13364 | * |
| 13365 | * Return: true if work posted to worker thread, otherwise false. |
| 13366 | **/ |
| 13367 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13368 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 13369 | { |
| 13370 | bool workposted = false; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13371 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13372 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 13373 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13374 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13375 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13376 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13377 | unsigned long iflags; |
| 13378 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13379 | /* sanity check on queue memory */ |
| 13380 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13381 | return workposted; |
| 13382 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13383 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13384 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13385 | else |
| 13386 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13387 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13388 | goto out; |
| 13389 | |
| 13390 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13391 | switch (status) { |
| 13392 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13393 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13394 | "2537 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 13395 | /* fall through */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13396 | case FC_STATUS_RQ_SUCCESS: |
| 13397 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13398 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13399 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 13400 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13401 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13402 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13403 | goto out; |
| 13404 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13405 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13406 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13407 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13408 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13409 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13410 | |
| 13411 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 13412 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 13413 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13414 | /* Handle MDS Loopback frames */ |
| 13415 | lpfc_sli4_handle_mds_loopback(phba->pport, dma_buf); |
| 13416 | break; |
| 13417 | } |
| 13418 | |
| 13419 | /* save off the frame for the work thread to process */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13420 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13421 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13422 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13423 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13424 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13425 | workposted = true; |
| 13426 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13427 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13428 | if (phba->nvmet_support) { |
| 13429 | tgtp = phba->targetport->private; |
| 13430 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13431 | "6402 RQE Error x%x, posted %d err_cnt " |
| 13432 | "%d: %x %x %x\n", |
| 13433 | status, hrq->RQ_buf_posted, |
| 13434 | hrq->RQ_no_posted_buf, |
| 13435 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13436 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13437 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13438 | } |
| 13439 | /* fallthrough */ |
| 13440 | |
| 13441 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13442 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13443 | /* Post more buffers if possible */ |
| 13444 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13445 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 13446 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13447 | workposted = true; |
| 13448 | break; |
| 13449 | } |
| 13450 | out: |
| 13451 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13452 | } |
| 13453 | |
| 13454 | /** |
| 13455 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 13456 | * @phba: Pointer to HBA context object. |
| 13457 | * @cq: Pointer to the completion queue. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13458 | * @cqe: Pointer to a completion queue entry. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13459 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13460 | * 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] | 13461 | * entry. |
| 13462 | * |
| 13463 | * Return: true if work posted to worker thread, otherwise false. |
| 13464 | **/ |
| 13465 | static bool |
| 13466 | 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] | 13467 | struct lpfc_cqe *cqe) |
| 13468 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13469 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13470 | bool workposted = false; |
| 13471 | |
| 13472 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13473 | lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13474 | |
| 13475 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13476 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13477 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13478 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13479 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13480 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13481 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13482 | break; |
| 13483 | case CQE_CODE_RELEASE_WQE: |
| 13484 | /* Process the WQ release event */ |
| 13485 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13486 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13487 | break; |
| 13488 | case CQE_CODE_XRI_ABORTED: |
| 13489 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13490 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13491 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13492 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13493 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13494 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13495 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13496 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13497 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13498 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13499 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13500 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13501 | default: |
| 13502 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13503 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13504 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13505 | break; |
| 13506 | } |
| 13507 | return workposted; |
| 13508 | } |
| 13509 | |
| 13510 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13511 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 13512 | * @phba: Pointer to HBA context object. |
| 13513 | * @eqe: Pointer to fast-path event queue entry. |
| 13514 | * |
| 13515 | * This routine process a event queue entry from the slow-path event queue. |
| 13516 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13517 | * completion event on a completion queue, if not, an error shall be logged |
| 13518 | * and just return. Otherwise, it will get to the corresponding completion |
| 13519 | * queue and process all the entries on that completion queue, rearm the |
| 13520 | * completion queue, and then return. |
| 13521 | * |
| 13522 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13523 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13524 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13525 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13526 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13527 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13528 | uint16_t cqid; |
| 13529 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13530 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13531 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13532 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13533 | list_for_each_entry(childq, &speq->child_list, list) { |
| 13534 | if (childq->queue_id == cqid) { |
| 13535 | cq = childq; |
| 13536 | break; |
| 13537 | } |
| 13538 | } |
| 13539 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13540 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13541 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13542 | "0365 Slow-path CQ identifier " |
| 13543 | "(%d) does not exist\n", cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13544 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13545 | } |
| 13546 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13547 | /* Save EQ associated with this CQ */ |
| 13548 | cq->assoc_qp = speq; |
| 13549 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13550 | if (!queue_work_on(cq->chann, phba->wq, &cq->spwork)) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13551 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13552 | "0390 Cannot schedule soft IRQ " |
| 13553 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 13554 | cqid, cq->queue_id, raw_smp_processor_id()); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13555 | } |
| 13556 | |
| 13557 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13558 | * __lpfc_sli4_process_cq - Process elements of a CQ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13559 | * @phba: Pointer to HBA context object. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13560 | * @cq: Pointer to CQ to be processed |
| 13561 | * @handler: Routine to process each cqe |
| 13562 | * @delay: Pointer to usdelay to set in case of rescheduling of the handler |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13563 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13564 | * This routine processes completion queue entries in a CQ. While a valid |
| 13565 | * queue element is found, the handler is called. During processing checks |
| 13566 | * are made for periodic doorbell writes to let the hardware know of |
| 13567 | * element consumption. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13568 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13569 | * If the max limit on cqes to process is hit, or there are no more valid |
| 13570 | * entries, the loop stops. If we processed a sufficient number of elements, |
| 13571 | * meaning there is sufficient load, rather than rearming and generating |
| 13572 | * another interrupt, a cq rescheduling delay will be set. A delay of 0 |
| 13573 | * indicates no rescheduling. |
| 13574 | * |
| 13575 | * Returns True if work scheduled, False otherwise. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13576 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13577 | static bool |
| 13578 | __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13579 | bool (*handler)(struct lpfc_hba *, struct lpfc_queue *, |
| 13580 | struct lpfc_cqe *), unsigned long *delay) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13581 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13582 | struct lpfc_cqe *cqe; |
| 13583 | bool workposted = false; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13584 | int count = 0, consumed = 0; |
| 13585 | bool arm = true; |
| 13586 | |
| 13587 | /* default - no reschedule */ |
| 13588 | *delay = 0; |
| 13589 | |
| 13590 | if (cmpxchg(&cq->queue_claimed, 0, 1) != 0) |
| 13591 | goto rearm_and_exit; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13592 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13593 | /* Process all the entries to the CQ */ |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13594 | cq->q_flag = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13595 | cqe = lpfc_sli4_cq_get(cq); |
| 13596 | while (cqe) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13597 | workposted |= handler(phba, cq, cqe); |
| 13598 | __lpfc_sli4_consume_cqe(phba, cq, cqe); |
| 13599 | |
| 13600 | consumed++; |
| 13601 | if (!(++count % cq->max_proc_limit)) |
| 13602 | break; |
| 13603 | |
| 13604 | if (!(count % cq->notify_interval)) { |
| 13605 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 13606 | LPFC_QUEUE_NOARM); |
| 13607 | consumed = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13608 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13609 | |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13610 | if (count == LPFC_NVMET_CQ_NOTIFY) |
| 13611 | cq->q_flag |= HBA_NVMET_CQ_NOTIFY; |
| 13612 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13613 | cqe = lpfc_sli4_cq_get(cq); |
| 13614 | } |
| 13615 | if (count >= phba->cfg_cq_poll_threshold) { |
| 13616 | *delay = 1; |
| 13617 | arm = false; |
| 13618 | } |
| 13619 | |
| 13620 | /* Track the max number of CQEs processed in 1 EQ */ |
| 13621 | if (count > cq->CQ_max_cqe) |
| 13622 | cq->CQ_max_cqe = count; |
| 13623 | |
| 13624 | cq->assoc_qp->EQ_cqe_cnt += count; |
| 13625 | |
| 13626 | /* Catch the no cq entry condition */ |
| 13627 | if (unlikely(count == 0)) |
| 13628 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13629 | "0369 No entry from completion queue " |
| 13630 | "qid=%d\n", cq->queue_id); |
| 13631 | |
| 13632 | cq->queue_claimed = 0; |
| 13633 | |
| 13634 | rearm_and_exit: |
| 13635 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 13636 | arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM); |
| 13637 | |
| 13638 | return workposted; |
| 13639 | } |
| 13640 | |
| 13641 | /** |
| 13642 | * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry |
| 13643 | * @cq: pointer to CQ to process |
| 13644 | * |
| 13645 | * This routine calls the cq processing routine with a handler specific |
| 13646 | * to the type of queue bound to it. |
| 13647 | * |
| 13648 | * The CQ routine returns two values: the first is the calling status, |
| 13649 | * which indicates whether work was queued to the background discovery |
| 13650 | * thread. If true, the routine should wakeup the discovery thread; |
| 13651 | * the second is the delay parameter. If non-zero, rather than rearming |
| 13652 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 13653 | * that it is processed in a subsequent polling action. The value of |
| 13654 | * the delay indicates when to reschedule it. |
| 13655 | **/ |
| 13656 | static void |
| 13657 | __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq) |
| 13658 | { |
| 13659 | struct lpfc_hba *phba = cq->phba; |
| 13660 | unsigned long delay; |
| 13661 | bool workposted = false; |
| 13662 | |
| 13663 | /* Process and rearm the CQ */ |
| 13664 | switch (cq->type) { |
| 13665 | case LPFC_MCQ: |
| 13666 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13667 | lpfc_sli4_sp_handle_mcqe, |
| 13668 | &delay); |
| 13669 | break; |
| 13670 | case LPFC_WCQ: |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13671 | if (cq->subtype == LPFC_IO) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13672 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13673 | lpfc_sli4_fp_handle_cqe, |
| 13674 | &delay); |
| 13675 | else |
| 13676 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13677 | lpfc_sli4_sp_handle_cqe, |
| 13678 | &delay); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13679 | break; |
| 13680 | default: |
| 13681 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13682 | "0370 Invalid completion queue type (%d)\n", |
| 13683 | cq->type); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13684 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13685 | } |
| 13686 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13687 | if (delay) { |
| 13688 | if (!queue_delayed_work_on(cq->chann, phba->wq, |
| 13689 | &cq->sched_spwork, delay)) |
| 13690 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13691 | "0394 Cannot schedule soft IRQ " |
| 13692 | "for cqid=%d on CPU %d\n", |
| 13693 | cq->queue_id, cq->chann); |
| 13694 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13695 | |
| 13696 | /* wake up worker thread if there are works to be done */ |
| 13697 | if (workposted) |
| 13698 | lpfc_worker_wake_up(phba); |
| 13699 | } |
| 13700 | |
| 13701 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13702 | * lpfc_sli4_sp_process_cq - slow-path work handler when started by |
| 13703 | * interrupt |
| 13704 | * @work: pointer to work element |
| 13705 | * |
| 13706 | * translates from the work handler and calls the slow-path handler. |
| 13707 | **/ |
| 13708 | static void |
| 13709 | lpfc_sli4_sp_process_cq(struct work_struct *work) |
| 13710 | { |
| 13711 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork); |
| 13712 | |
| 13713 | __lpfc_sli4_sp_process_cq(cq); |
| 13714 | } |
| 13715 | |
| 13716 | /** |
| 13717 | * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer |
| 13718 | * @work: pointer to work element |
| 13719 | * |
| 13720 | * translates from the work handler and calls the slow-path handler. |
| 13721 | **/ |
| 13722 | static void |
| 13723 | lpfc_sli4_dly_sp_process_cq(struct work_struct *work) |
| 13724 | { |
| 13725 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 13726 | struct lpfc_queue, sched_spwork); |
| 13727 | |
| 13728 | __lpfc_sli4_sp_process_cq(cq); |
| 13729 | } |
| 13730 | |
| 13731 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13732 | * 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] | 13733 | * @phba: Pointer to HBA context object. |
| 13734 | * @cq: Pointer to associated CQ |
| 13735 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13736 | * |
| 13737 | * This routine process a fast-path work queue completion entry from fast-path |
| 13738 | * event queue for FCP command response completion. |
| 13739 | **/ |
| 13740 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13741 | 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] | 13742 | struct lpfc_wcqe_complete *wcqe) |
| 13743 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13744 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13745 | struct lpfc_iocbq *cmdiocbq; |
| 13746 | struct lpfc_iocbq irspiocbq; |
| 13747 | unsigned long iflags; |
| 13748 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13749 | /* Check for response status */ |
| 13750 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13751 | /* If resource errors reported from HBA, reduce queue |
| 13752 | * depth of the SCSI device. |
| 13753 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13754 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 13755 | IOSTAT_LOCAL_REJECT)) && |
| 13756 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 13757 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13758 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13759 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13760 | /* Log the error status */ |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13761 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13762 | "0373 FCP CQE error: status=x%x: " |
| 13763 | "CQE: %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13764 | bf_get(lpfc_wcqe_c_status, wcqe), |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13765 | wcqe->word0, wcqe->total_data_placed, |
| 13766 | wcqe->parameter, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13767 | } |
| 13768 | |
| 13769 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13770 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 13771 | pring->stats.iocb_event++; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 13772 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13773 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13774 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13775 | if (unlikely(!cmdiocbq)) { |
| 13776 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13777 | "0374 FCP complete with no corresponding " |
| 13778 | "cmdiocb: iotag (%d)\n", |
| 13779 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13780 | return; |
| 13781 | } |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13782 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13783 | cmdiocbq->isr_timestamp = cq->isr_timestamp; |
| 13784 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13785 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 13786 | if (cmdiocbq->wqe_cmpl) { |
| 13787 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13788 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13789 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13790 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13791 | } |
| 13792 | |
| 13793 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 13794 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 13795 | return; |
| 13796 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13797 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13798 | "0375 FCP cmdiocb not callback function " |
| 13799 | "iotag: (%d)\n", |
| 13800 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13801 | return; |
| 13802 | } |
| 13803 | |
| 13804 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13805 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13806 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 13807 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13808 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13809 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13810 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13811 | } |
| 13812 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13813 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 13814 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 13815 | } |
| 13816 | |
| 13817 | /** |
| 13818 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 13819 | * @phba: Pointer to HBA context object. |
| 13820 | * @cq: Pointer to completion queue. |
| 13821 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13822 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13823 | * 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] | 13824 | * proper WQ release routine to the slow-path WQ. |
| 13825 | **/ |
| 13826 | static void |
| 13827 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13828 | struct lpfc_wcqe_release *wcqe) |
| 13829 | { |
| 13830 | struct lpfc_queue *childwq; |
| 13831 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13832 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13833 | |
| 13834 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13835 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13836 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13837 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13838 | lpfc_sli4_wq_release(childwq, |
| 13839 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 13840 | if (childwq->q_flag & HBA_NVMET_WQFULL) |
| 13841 | lpfc_nvmet_wqfull_process(phba, childwq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13842 | wqid_matched = true; |
| 13843 | break; |
| 13844 | } |
| 13845 | } |
| 13846 | /* Report warning log message if no match found */ |
| 13847 | if (wqid_matched != true) |
| 13848 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13849 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13850 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13851 | } |
| 13852 | |
| 13853 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13854 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 13855 | * @phba: Pointer to HBA context object. |
| 13856 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 13857 | * |
| 13858 | * This routine process a receive-queue completion queue entry. |
| 13859 | * |
| 13860 | * Return: true if work posted to worker thread, otherwise false. |
| 13861 | **/ |
| 13862 | static bool |
| 13863 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13864 | struct lpfc_rcqe *rcqe) |
| 13865 | { |
| 13866 | bool workposted = false; |
| 13867 | struct lpfc_queue *hrq; |
| 13868 | struct lpfc_queue *drq; |
| 13869 | struct rqb_dmabuf *dma_buf; |
| 13870 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13871 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13872 | uint32_t status, rq_id; |
| 13873 | unsigned long iflags; |
| 13874 | uint32_t fctl, idx; |
| 13875 | |
| 13876 | if ((phba->nvmet_support == 0) || |
| 13877 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 13878 | return workposted; |
| 13879 | |
| 13880 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13881 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 13882 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 13883 | |
| 13884 | /* sanity check on queue memory */ |
| 13885 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13886 | return workposted; |
| 13887 | |
| 13888 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13889 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13890 | else |
| 13891 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13892 | |
| 13893 | if ((phba->nvmet_support == 0) || |
| 13894 | (rq_id != hrq->queue_id)) |
| 13895 | return workposted; |
| 13896 | |
| 13897 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13898 | switch (status) { |
| 13899 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13900 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13901 | "6126 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 13902 | /* fall through */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13903 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13904 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13905 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13906 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 13907 | if (!dma_buf) { |
| 13908 | hrq->RQ_no_buf_found++; |
| 13909 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13910 | goto out; |
| 13911 | } |
| 13912 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13913 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13914 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13915 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13916 | |
| 13917 | /* Just some basic sanity checks on FCP Command frame */ |
| 13918 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
| 13919 | fc_hdr->fh_f_ctl[1] << 8 | |
| 13920 | fc_hdr->fh_f_ctl[2]); |
| 13921 | if (((fctl & |
| 13922 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 13923 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 13924 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 13925 | goto drop; |
| 13926 | |
| 13927 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13928 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 13929 | lpfc_nvmet_unsol_fcp_event( |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13930 | phba, idx, dma_buf, cq->isr_timestamp, |
| 13931 | cq->q_flag & HBA_NVMET_CQ_NOTIFY); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13932 | return false; |
| 13933 | } |
| 13934 | drop: |
James Smart | 22b738a | 2019-03-12 16:30:11 -0700 | [diff] [blame] | 13935 | lpfc_rq_buf_free(phba, &dma_buf->hbuf); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13936 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13937 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13938 | if (phba->nvmet_support) { |
| 13939 | tgtp = phba->targetport->private; |
| 13940 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13941 | "6401 RQE Error x%x, posted %d err_cnt " |
| 13942 | "%d: %x %x %x\n", |
| 13943 | status, hrq->RQ_buf_posted, |
| 13944 | hrq->RQ_no_posted_buf, |
| 13945 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13946 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13947 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13948 | } |
| 13949 | /* fallthrough */ |
| 13950 | |
| 13951 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13952 | hrq->RQ_no_posted_buf++; |
| 13953 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13954 | break; |
| 13955 | } |
| 13956 | out: |
| 13957 | return workposted; |
| 13958 | } |
| 13959 | |
| 13960 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13961 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13962 | * @phba: adapter with cq |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13963 | * @cq: Pointer to the completion queue. |
| 13964 | * @eqe: Pointer to fast-path completion queue entry. |
| 13965 | * |
| 13966 | * This routine process a fast-path work queue completion entry from fast-path |
| 13967 | * event queue for FCP command response completion. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13968 | * |
| 13969 | * Return: true if work posted to worker thread, otherwise false. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13970 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13971 | static bool |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13972 | 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] | 13973 | struct lpfc_cqe *cqe) |
| 13974 | { |
| 13975 | struct lpfc_wcqe_release wcqe; |
| 13976 | bool workposted = false; |
| 13977 | |
| 13978 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13979 | lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13980 | |
| 13981 | /* Check and process for different type of WCQE and dispatch */ |
| 13982 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 13983 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13984 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13985 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13986 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 13987 | phba->last_completion_time = jiffies; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13988 | if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13989 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13990 | (struct lpfc_wcqe_complete *)&wcqe); |
| 13991 | break; |
| 13992 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13993 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13994 | /* Process the WQ release event */ |
| 13995 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 13996 | (struct lpfc_wcqe_release *)&wcqe); |
| 13997 | break; |
| 13998 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13999 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14000 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14001 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14002 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 14003 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 14004 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14005 | case CQE_CODE_RECEIVE_V1: |
| 14006 | case CQE_CODE_RECEIVE: |
| 14007 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14008 | if (cq->subtype == LPFC_NVMET) { |
| 14009 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 14010 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 14011 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14012 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14013 | default: |
| 14014 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14015 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14016 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 14017 | break; |
| 14018 | } |
| 14019 | return workposted; |
| 14020 | } |
| 14021 | |
| 14022 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14023 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14024 | * @phba: Pointer to HBA context object. |
| 14025 | * @eqe: Pointer to fast-path event queue entry. |
| 14026 | * |
| 14027 | * This routine process a event queue entry from the fast-path event queue. |
| 14028 | * It will check the MajorCode and MinorCode to determine this is for a |
| 14029 | * completion event on a completion queue, if not, an error shall be logged |
| 14030 | * and just return. Otherwise, it will get to the corresponding completion |
| 14031 | * queue and process all the entries on the completion queue, rearm the |
| 14032 | * completion queue, and then return. |
| 14033 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14034 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14035 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 14036 | struct lpfc_eqe *eqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14037 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14038 | struct lpfc_queue *cq = NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14039 | uint32_t qidx = eq->hdwq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14040 | uint16_t cqid, id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14041 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14042 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14043 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14044 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14045 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14046 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 14047 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14048 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14049 | } |
| 14050 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14051 | /* Get the reference to the corresponding CQ */ |
| 14052 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 14053 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14054 | /* Use the fast lookup method first */ |
| 14055 | if (cqid <= phba->sli4_hba.cq_max) { |
| 14056 | cq = phba->sli4_hba.cq_lookup[cqid]; |
| 14057 | if (cq) |
| 14058 | goto work_cq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14059 | } |
| 14060 | |
| 14061 | /* Next check for NVMET completion */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14062 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 14063 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 14064 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 14065 | /* Process NVMET unsol rcv */ |
| 14066 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 14067 | goto process_cq; |
| 14068 | } |
| 14069 | } |
| 14070 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14071 | if (phba->sli4_hba.nvmels_cq && |
| 14072 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 14073 | /* Process NVME unsol rcv */ |
| 14074 | cq = phba->sli4_hba.nvmels_cq; |
| 14075 | } |
| 14076 | |
| 14077 | /* Otherwise this is a Slow path event */ |
| 14078 | if (cq == NULL) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14079 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 14080 | phba->sli4_hba.hdwq[qidx].hba_eq); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14081 | return; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14082 | } |
| 14083 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14084 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14085 | if (unlikely(cqid != cq->queue_id)) { |
| 14086 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14087 | "0368 Miss-matched fast-path completion " |
| 14088 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 14089 | cqid, cq->queue_id); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14090 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14091 | } |
| 14092 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14093 | work_cq: |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14094 | #if defined(CONFIG_SCSI_LPFC_DEBUG_FS) |
| 14095 | if (phba->ktime_on) |
| 14096 | cq->isr_timestamp = ktime_get_ns(); |
| 14097 | else |
| 14098 | cq->isr_timestamp = 0; |
| 14099 | #endif |
James Smart | 45aa312 | 2019-01-28 11:14:29 -0800 | [diff] [blame] | 14100 | if (!queue_work_on(cq->chann, phba->wq, &cq->irqwork)) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14101 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14102 | "0363 Cannot schedule soft IRQ " |
| 14103 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 14104 | cqid, cq->queue_id, raw_smp_processor_id()); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14105 | } |
| 14106 | |
| 14107 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14108 | * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry |
| 14109 | * @cq: Pointer to CQ to be processed |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14110 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14111 | * This routine calls the cq processing routine with the handler for |
| 14112 | * fast path CQEs. |
| 14113 | * |
| 14114 | * The CQ routine returns two values: the first is the calling status, |
| 14115 | * which indicates whether work was queued to the background discovery |
| 14116 | * thread. If true, the routine should wakeup the discovery thread; |
| 14117 | * the second is the delay parameter. If non-zero, rather than rearming |
| 14118 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 14119 | * that it is processed in a subsequent polling action. The value of |
| 14120 | * the delay indicates when to reschedule it. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14121 | **/ |
| 14122 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14123 | __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14124 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14125 | struct lpfc_hba *phba = cq->phba; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14126 | unsigned long delay; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14127 | bool workposted = false; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14128 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14129 | /* process and rearm the CQ */ |
| 14130 | workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe, |
| 14131 | &delay); |
| 14132 | |
| 14133 | if (delay) { |
| 14134 | if (!queue_delayed_work_on(cq->chann, phba->wq, |
| 14135 | &cq->sched_irqwork, delay)) |
| 14136 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14137 | "0367 Cannot schedule soft IRQ " |
| 14138 | "for cqid=%d on CPU %d\n", |
| 14139 | cq->queue_id, cq->chann); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14140 | } |
| 14141 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14142 | /* wake up worker thread if there are works to be done */ |
| 14143 | if (workposted) |
| 14144 | lpfc_worker_wake_up(phba); |
| 14145 | } |
| 14146 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14147 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14148 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by |
| 14149 | * interrupt |
| 14150 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14151 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14152 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14153 | **/ |
| 14154 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14155 | lpfc_sli4_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14156 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14157 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14158 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14159 | __lpfc_sli4_hba_process_cq(cq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14160 | } |
| 14161 | |
| 14162 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14163 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by timer |
| 14164 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14165 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14166 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14167 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14168 | static void |
| 14169 | lpfc_sli4_dly_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14170 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14171 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 14172 | struct lpfc_queue, sched_irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14173 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14174 | __lpfc_sli4_hba_process_cq(cq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14175 | } |
| 14176 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14177 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14178 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14179 | * @irq: Interrupt number. |
| 14180 | * @dev_id: The device context pointer. |
| 14181 | * |
| 14182 | * This function is directly called from the PCI layer as an interrupt |
| 14183 | * service routine when device with SLI-4 interface spec is enabled with |
| 14184 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 14185 | * ring event in the HBA. However, when the device is enabled with either |
| 14186 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 14187 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 14188 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 14189 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 14190 | * the intrrupt context. This function is called without any lock held. |
| 14191 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 14192 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 14193 | * equal to that of FCP CQ index. |
| 14194 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14195 | * The link attention and ELS ring attention events are handled |
| 14196 | * by the worker thread. The interrupt handler signals the worker thread |
| 14197 | * and returns for these events. This function is called without any lock |
| 14198 | * held. It gets the hbalock to access and update SLI data structures. |
| 14199 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14200 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 14201 | * returns IRQ_NONE. |
| 14202 | **/ |
| 14203 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14204 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14205 | { |
| 14206 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14207 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14208 | struct lpfc_queue *fpeq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14209 | unsigned long iflag; |
| 14210 | int ecount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14211 | int hba_eqidx; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14212 | struct lpfc_eq_intr_info *eqi; |
| 14213 | uint32_t icnt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14214 | |
| 14215 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14216 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 14217 | phba = hba_eq_hdl->phba; |
| 14218 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14219 | |
| 14220 | if (unlikely(!phba)) |
| 14221 | return IRQ_NONE; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14222 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 14223 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14224 | |
| 14225 | /* Get to the EQ struct associated with this vector */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14226 | fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14227 | if (unlikely(!fpeq)) |
| 14228 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14229 | |
| 14230 | /* Check device state for handling interrupt */ |
| 14231 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 14232 | /* Check again for link_state with lock held */ |
| 14233 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 14234 | if (phba->link_state < LPFC_LINK_DOWN) |
| 14235 | /* Flush, clear interrupt, and rearm the EQ */ |
| 14236 | lpfc_sli4_eq_flush(phba, fpeq); |
| 14237 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 14238 | return IRQ_NONE; |
| 14239 | } |
| 14240 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14241 | eqi = phba->sli4_hba.eq_info; |
| 14242 | icnt = this_cpu_inc_return(eqi->icnt); |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 14243 | fpeq->last_cpu = raw_smp_processor_id(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14244 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14245 | if (icnt > LPFC_EQD_ISR_TRIGGER && |
| 14246 | phba->cfg_irq_chann == 1 && |
| 14247 | phba->cfg_auto_imax && |
| 14248 | fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY && |
| 14249 | phba->sli.sli_flag & LPFC_SLI_USE_EQDR) |
| 14250 | lpfc_sli4_mod_hba_eq_delay(phba, fpeq, LPFC_MAX_AUTO_EQ_DELAY); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14251 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14252 | /* process and rearm the EQ */ |
| 14253 | ecount = lpfc_sli4_process_eq(phba, fpeq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14254 | |
| 14255 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14256 | fpeq->EQ_no_entry++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14257 | if (phba->intr_type == MSIX) |
| 14258 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 14259 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14260 | "0358 MSI-X interrupt with no EQE\n"); |
| 14261 | else |
| 14262 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 14263 | return IRQ_NONE; |
| 14264 | } |
| 14265 | |
| 14266 | return IRQ_HANDLED; |
| 14267 | } /* lpfc_sli4_fp_intr_handler */ |
| 14268 | |
| 14269 | /** |
| 14270 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 14271 | * @irq: Interrupt number. |
| 14272 | * @dev_id: The device context pointer. |
| 14273 | * |
| 14274 | * This function is the device-level interrupt handler to device with SLI-4 |
| 14275 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 14276 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 14277 | * driver attention. This function invokes the slow-path interrupt attention |
| 14278 | * handling function and fast-path interrupt attention handling function in |
| 14279 | * turn to process the relevant HBA attention events. This function is called |
| 14280 | * without any lock held. It gets the hbalock to access and update SLI data |
| 14281 | * structures. |
| 14282 | * |
| 14283 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 14284 | * returns IRQ_NONE. |
| 14285 | **/ |
| 14286 | irqreturn_t |
| 14287 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 14288 | { |
| 14289 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14290 | irqreturn_t hba_irq_rc; |
| 14291 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14292 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14293 | |
| 14294 | /* Get the driver's phba structure from the dev_id */ |
| 14295 | phba = (struct lpfc_hba *)dev_id; |
| 14296 | |
| 14297 | if (unlikely(!phba)) |
| 14298 | return IRQ_NONE; |
| 14299 | |
| 14300 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14301 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 14302 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14303 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14304 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14305 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14306 | if (hba_irq_rc == IRQ_HANDLED) |
| 14307 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14308 | } |
| 14309 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14310 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14311 | } /* lpfc_sli4_intr_handler */ |
| 14312 | |
| 14313 | /** |
| 14314 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 14315 | * @queue: The queue structure to free. |
| 14316 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 14317 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14318 | * the host resident queue. This function must be called after destroying the |
| 14319 | * queue on the HBA. |
| 14320 | **/ |
| 14321 | void |
| 14322 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 14323 | { |
| 14324 | struct lpfc_dmabuf *dmabuf; |
| 14325 | |
| 14326 | if (!queue) |
| 14327 | return; |
| 14328 | |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 14329 | if (!list_empty(&queue->wq_list)) |
| 14330 | list_del(&queue->wq_list); |
| 14331 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14332 | while (!list_empty(&queue->page_list)) { |
| 14333 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 14334 | list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14335 | dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14336 | dmabuf->virt, dmabuf->phys); |
| 14337 | kfree(dmabuf); |
| 14338 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14339 | if (queue->rqbp) { |
| 14340 | lpfc_free_rq_buffer(queue->phba, queue); |
| 14341 | kfree(queue->rqbp); |
| 14342 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 14343 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14344 | if (!list_empty(&queue->cpu_list)) |
| 14345 | list_del(&queue->cpu_list); |
| 14346 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14347 | kfree(queue); |
| 14348 | return; |
| 14349 | } |
| 14350 | |
| 14351 | /** |
| 14352 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 14353 | * @phba: The HBA that this queue is being created on. |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14354 | * @page_size: The size of a queue page |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14355 | * @entry_size: The size of each queue entry for this queue. |
| 14356 | * @entry count: The number of entries that this queue will handle. |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14357 | * @cpu: The cpu that will primarily utilize this queue. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14358 | * |
| 14359 | * This function allocates a queue structure and the DMAable memory used for |
| 14360 | * the host resident queue. This function must be called before creating the |
| 14361 | * queue on the HBA. |
| 14362 | **/ |
| 14363 | struct lpfc_queue * |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14364 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14365 | uint32_t entry_size, uint32_t entry_count, int cpu) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14366 | { |
| 14367 | struct lpfc_queue *queue; |
| 14368 | struct lpfc_dmabuf *dmabuf; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14369 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14370 | uint16_t x, pgcnt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14371 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14372 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14373 | hw_page_size = page_size; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14374 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14375 | pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14376 | |
| 14377 | /* If needed, Adjust page count to match the max the adapter supports */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14378 | if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt) |
| 14379 | pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 14380 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14381 | queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt), |
| 14382 | GFP_KERNEL, cpu_to_node(cpu)); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14383 | if (!queue) |
| 14384 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14385 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14386 | INIT_LIST_HEAD(&queue->list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14387 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 14388 | INIT_LIST_HEAD(&queue->wqfull_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14389 | INIT_LIST_HEAD(&queue->page_list); |
| 14390 | INIT_LIST_HEAD(&queue->child_list); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14391 | INIT_LIST_HEAD(&queue->cpu_list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14392 | |
| 14393 | /* Set queue parameters now. If the system cannot provide memory |
| 14394 | * resources, the free routine needs to know what was allocated. |
| 14395 | */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14396 | queue->page_count = pgcnt; |
| 14397 | queue->q_pgs = (void **)&queue[1]; |
| 14398 | queue->entry_cnt_per_pg = hw_page_size / entry_size; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14399 | queue->entry_size = entry_size; |
| 14400 | queue->entry_count = entry_count; |
| 14401 | queue->page_size = hw_page_size; |
| 14402 | queue->phba = phba; |
| 14403 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14404 | for (x = 0; x < queue->page_count; x++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14405 | dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL, |
| 14406 | dev_to_node(&phba->pcidev->dev)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14407 | if (!dmabuf) |
| 14408 | goto out_fail; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 14409 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 14410 | hw_page_size, &dmabuf->phys, |
| 14411 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14412 | if (!dmabuf->virt) { |
| 14413 | kfree(dmabuf); |
| 14414 | goto out_fail; |
| 14415 | } |
| 14416 | dmabuf->buffer_tag = x; |
| 14417 | list_add_tail(&dmabuf->list, &queue->page_list); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14418 | /* use lpfc_sli4_qe to index a paritcular entry in this page */ |
| 14419 | queue->q_pgs[x] = dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14420 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14421 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
| 14422 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14423 | INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq); |
| 14424 | INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14425 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14426 | /* notify_interval will be set during q creation */ |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14427 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14428 | return queue; |
| 14429 | out_fail: |
| 14430 | lpfc_sli4_queue_free(queue); |
| 14431 | return NULL; |
| 14432 | } |
| 14433 | |
| 14434 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14435 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 14436 | * @phba: HBA structure that indicates port to create a queue on. |
| 14437 | * @pci_barset: PCI BAR set flag. |
| 14438 | * |
| 14439 | * This function shall perform iomap of the specified PCI BAR address to host |
| 14440 | * memory address if not already done so and return it. The returned host |
| 14441 | * memory address can be NULL. |
| 14442 | */ |
| 14443 | static void __iomem * |
| 14444 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 14445 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14446 | if (!phba->pcidev) |
| 14447 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14448 | |
| 14449 | switch (pci_barset) { |
| 14450 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14451 | return phba->pci_bar0_memmap_p; |
| 14452 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14453 | return phba->pci_bar2_memmap_p; |
| 14454 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14455 | return phba->pci_bar4_memmap_p; |
| 14456 | default: |
| 14457 | break; |
| 14458 | } |
| 14459 | return NULL; |
| 14460 | } |
| 14461 | |
| 14462 | /** |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14463 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs |
| 14464 | * @phba: HBA structure that EQs are on. |
| 14465 | * @startq: The starting EQ index to modify |
| 14466 | * @numq: The number of EQs (consecutive indexes) to modify |
| 14467 | * @usdelay: amount of delay |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14468 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14469 | * This function revises the EQ delay on 1 or more EQs. The EQ delay |
| 14470 | * is set either by writing to a register (if supported by the SLI Port) |
| 14471 | * or by mailbox command. The mailbox command allows several EQs to be |
| 14472 | * updated at once. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14473 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14474 | * The @phba struct is used to send a mailbox command to HBA. The @startq |
| 14475 | * is used to get the starting EQ index to change. The @numq value is |
| 14476 | * used to specify how many consecutive EQ indexes, starting at EQ index, |
| 14477 | * are to be changed. This function is asynchronous and will wait for any |
| 14478 | * mailbox commands to finish before returning. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14479 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14480 | * On success this function will return a zero. If unable to allocate |
| 14481 | * enough memory this function will return -ENOMEM. If a mailbox command |
| 14482 | * fails this function will return -ENXIO. Note: on ENXIO, some EQs may |
| 14483 | * have had their delay multipler changed. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14484 | **/ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14485 | void |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14486 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14487 | uint32_t numq, uint32_t usdelay) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14488 | { |
| 14489 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 14490 | LPFC_MBOXQ_t *mbox; |
| 14491 | struct lpfc_queue *eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14492 | int cnt = 0, rc, length; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14493 | uint32_t shdr_status, shdr_add_status; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14494 | uint32_t dmult; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14495 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14496 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14497 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14498 | if (startq >= phba->cfg_irq_chann) |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14499 | return; |
| 14500 | |
| 14501 | if (usdelay > 0xFFFF) { |
| 14502 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME, |
| 14503 | "6429 usdelay %d too large. Scaled down to " |
| 14504 | "0xFFFF.\n", usdelay); |
| 14505 | usdelay = 0xFFFF; |
| 14506 | } |
| 14507 | |
| 14508 | /* set values by EQ_DELAY register if supported */ |
| 14509 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 14510 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14511 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14512 | if (!eq) |
| 14513 | continue; |
| 14514 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14515 | lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14516 | |
| 14517 | if (++cnt >= numq) |
| 14518 | break; |
| 14519 | } |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14520 | return; |
| 14521 | } |
| 14522 | |
| 14523 | /* Otherwise, set values by mailbox cmd */ |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14524 | |
| 14525 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14526 | if (!mbox) { |
| 14527 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_FCP | LOG_NVME, |
| 14528 | "6428 Failed allocating mailbox cmd buffer." |
| 14529 | " EQ delay was not set.\n"); |
| 14530 | return; |
| 14531 | } |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14532 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 14533 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14534 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14535 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 14536 | length, LPFC_SLI4_MBX_EMBED); |
| 14537 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 14538 | |
| 14539 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14540 | dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC; |
| 14541 | if (dmult) |
| 14542 | dmult--; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14543 | if (dmult > LPFC_DMULT_MAX) |
| 14544 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14545 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14546 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14547 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14548 | if (!eq) |
| 14549 | continue; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14550 | eq->q_mode = usdelay; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14551 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 14552 | eq_delay->u.request.eq[cnt].phase = 0; |
| 14553 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14554 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14555 | if (++cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14556 | break; |
| 14557 | } |
| 14558 | eq_delay->u.request.num_eq = cnt; |
| 14559 | |
| 14560 | mbox->vport = phba->pport; |
| 14561 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14562 | mbox->ctx_buf = NULL; |
| 14563 | mbox->ctx_ndlp = NULL; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14564 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14565 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 14566 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14567 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14568 | if (shdr_status || shdr_add_status || rc) { |
| 14569 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14570 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 14571 | "status x%x add_status x%x, mbx status x%x\n", |
| 14572 | shdr_status, shdr_add_status, rc); |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14573 | } |
| 14574 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14575 | return; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14576 | } |
| 14577 | |
| 14578 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14579 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 14580 | * @phba: HBA structure that indicates port to create a queue on. |
| 14581 | * @eq: The queue structure to use to create the event queue. |
| 14582 | * @imax: The maximum interrupt per second limit. |
| 14583 | * |
| 14584 | * This function creates an event queue, as detailed in @eq, on a port, |
| 14585 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 14586 | * |
| 14587 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 14588 | * is used to get the entry count and entry size that are necessary to |
| 14589 | * determine the number of pages to allocate and use for this queue. This |
| 14590 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 14591 | * event queue. This function is asynchronous and will wait for the mailbox |
| 14592 | * command to finish before continuing. |
| 14593 | * |
| 14594 | * 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] | 14595 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14596 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14597 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14598 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14599 | 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] | 14600 | { |
| 14601 | struct lpfc_mbx_eq_create *eq_create; |
| 14602 | LPFC_MBOXQ_t *mbox; |
| 14603 | int rc, length, status = 0; |
| 14604 | struct lpfc_dmabuf *dmabuf; |
| 14605 | uint32_t shdr_status, shdr_add_status; |
| 14606 | union lpfc_sli4_cfg_shdr *shdr; |
| 14607 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14608 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14609 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14610 | /* sanity check on queue memory */ |
| 14611 | if (!eq) |
| 14612 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14613 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14614 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14615 | |
| 14616 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14617 | if (!mbox) |
| 14618 | return -ENOMEM; |
| 14619 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 14620 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14621 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14622 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 14623 | length, LPFC_SLI4_MBX_EMBED); |
| 14624 | eq_create = &mbox->u.mqe.un.eq_create; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14625 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14626 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 14627 | eq->page_count); |
| 14628 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 14629 | LPFC_EQE_SIZE); |
| 14630 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14631 | |
| 14632 | /* Use version 2 of CREATE_EQ if eqav is set */ |
| 14633 | if (phba->sli4_hba.pc_sli4_params.eqav) { |
| 14634 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14635 | LPFC_Q_CREATE_VERSION_2); |
| 14636 | bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context, |
| 14637 | phba->sli4_hba.pc_sli4_params.eqav); |
| 14638 | } |
| 14639 | |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 14640 | /* don't setup delay multiplier using EQ_CREATE */ |
| 14641 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14642 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 14643 | dmult); |
| 14644 | switch (eq->entry_count) { |
| 14645 | default: |
| 14646 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14647 | "0360 Unsupported EQ count. (%d)\n", |
| 14648 | eq->entry_count); |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 14649 | if (eq->entry_count < 256) { |
| 14650 | status = -EINVAL; |
| 14651 | goto out; |
| 14652 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 14653 | /* fall through - otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14654 | case 256: |
| 14655 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14656 | LPFC_EQ_CNT_256); |
| 14657 | break; |
| 14658 | case 512: |
| 14659 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14660 | LPFC_EQ_CNT_512); |
| 14661 | break; |
| 14662 | case 1024: |
| 14663 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14664 | LPFC_EQ_CNT_1024); |
| 14665 | break; |
| 14666 | case 2048: |
| 14667 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14668 | LPFC_EQ_CNT_2048); |
| 14669 | break; |
| 14670 | case 4096: |
| 14671 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14672 | LPFC_EQ_CNT_4096); |
| 14673 | break; |
| 14674 | } |
| 14675 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14676 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14677 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14678 | putPaddrLow(dmabuf->phys); |
| 14679 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14680 | putPaddrHigh(dmabuf->phys); |
| 14681 | } |
| 14682 | mbox->vport = phba->pport; |
| 14683 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14684 | mbox->ctx_buf = NULL; |
| 14685 | mbox->ctx_ndlp = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14686 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14687 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14688 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14689 | if (shdr_status || shdr_add_status || rc) { |
| 14690 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14691 | "2500 EQ_CREATE mailbox failed with " |
| 14692 | "status x%x add_status x%x, mbx status x%x\n", |
| 14693 | shdr_status, shdr_add_status, rc); |
| 14694 | status = -ENXIO; |
| 14695 | } |
| 14696 | eq->type = LPFC_EQ; |
| 14697 | eq->subtype = LPFC_NONE; |
| 14698 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 14699 | if (eq->queue_id == 0xFFFF) |
| 14700 | status = -ENXIO; |
| 14701 | eq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14702 | eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL; |
| 14703 | eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT; |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 14704 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14705 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14706 | return status; |
| 14707 | } |
| 14708 | |
| 14709 | /** |
| 14710 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 14711 | * @phba: HBA structure that indicates port to create a queue on. |
| 14712 | * @cq: The queue structure to use to create the completion queue. |
| 14713 | * @eq: The event queue to bind this completion queue to. |
| 14714 | * |
| 14715 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 14716 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 14717 | * |
| 14718 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14719 | * is used to get the entry count and entry size that are necessary to |
| 14720 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14721 | * is used to indicate which event queue to bind this completion queue to. This |
| 14722 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 14723 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14724 | * command to finish before continuing. |
| 14725 | * |
| 14726 | * 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] | 14727 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14728 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14729 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14730 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14731 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14732 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 14733 | { |
| 14734 | struct lpfc_mbx_cq_create *cq_create; |
| 14735 | struct lpfc_dmabuf *dmabuf; |
| 14736 | LPFC_MBOXQ_t *mbox; |
| 14737 | int rc, length, status = 0; |
| 14738 | uint32_t shdr_status, shdr_add_status; |
| 14739 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14740 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14741 | /* sanity check on queue memory */ |
| 14742 | if (!cq || !eq) |
| 14743 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14744 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14745 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14746 | if (!mbox) |
| 14747 | return -ENOMEM; |
| 14748 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 14749 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14750 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14751 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 14752 | length, LPFC_SLI4_MBX_EMBED); |
| 14753 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14754 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14755 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 14756 | cq->page_count); |
| 14757 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 14758 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14759 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14760 | phba->sli4_hba.pc_sli4_params.cqv); |
| 14761 | 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] | 14762 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, |
| 14763 | (cq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14764 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 14765 | eq->queue_id); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14766 | bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context, |
| 14767 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14768 | } else { |
| 14769 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 14770 | eq->queue_id); |
| 14771 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14772 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14773 | case 2048: |
| 14774 | case 4096: |
| 14775 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 14776 | LPFC_Q_CREATE_VERSION_2) { |
| 14777 | cq_create->u.request.context.lpfc_cq_context_count = |
| 14778 | cq->entry_count; |
| 14779 | bf_set(lpfc_cq_context_count, |
| 14780 | &cq_create->u.request.context, |
| 14781 | LPFC_CQ_CNT_WORD7); |
| 14782 | break; |
| 14783 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 14784 | /* fall through */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14785 | default: |
| 14786 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14787 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14788 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14789 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14790 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14791 | if (cq->entry_count < 256) { |
| 14792 | status = -EINVAL; |
| 14793 | goto out; |
| 14794 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 14795 | /* fall through - otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14796 | case 256: |
| 14797 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14798 | LPFC_CQ_CNT_256); |
| 14799 | break; |
| 14800 | case 512: |
| 14801 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14802 | LPFC_CQ_CNT_512); |
| 14803 | break; |
| 14804 | case 1024: |
| 14805 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14806 | LPFC_CQ_CNT_1024); |
| 14807 | break; |
| 14808 | } |
| 14809 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14810 | memset(dmabuf->virt, 0, cq->page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14811 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14812 | putPaddrLow(dmabuf->phys); |
| 14813 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14814 | putPaddrHigh(dmabuf->phys); |
| 14815 | } |
| 14816 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14817 | |
| 14818 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14819 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14820 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14821 | if (shdr_status || shdr_add_status || rc) { |
| 14822 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14823 | "2501 CQ_CREATE mailbox failed with " |
| 14824 | "status x%x add_status x%x, mbx status x%x\n", |
| 14825 | shdr_status, shdr_add_status, rc); |
| 14826 | status = -ENXIO; |
| 14827 | goto out; |
| 14828 | } |
| 14829 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 14830 | if (cq->queue_id == 0xFFFF) { |
| 14831 | status = -ENXIO; |
| 14832 | goto out; |
| 14833 | } |
| 14834 | /* link the cq onto the parent eq child list */ |
| 14835 | list_add_tail(&cq->list, &eq->child_list); |
| 14836 | /* Set up completion queue's type and subtype */ |
| 14837 | cq->type = type; |
| 14838 | cq->subtype = subtype; |
| 14839 | 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] | 14840 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14841 | cq->assoc_qp = eq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14842 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14843 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 14844 | cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, cq->entry_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14845 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14846 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 14847 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14848 | out: |
| 14849 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14850 | return status; |
| 14851 | } |
| 14852 | |
| 14853 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14854 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 14855 | * @phba: HBA structure that indicates port to create a queue on. |
| 14856 | * @cqp: The queue structure array to use to create the completion queues. |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14857 | * @hdwq: The hardware queue array with the EQ to bind completion queues to. |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14858 | * |
| 14859 | * This function creates a set of completion queue, s to support MRQ |
| 14860 | * as detailed in @cqp, on a port, |
| 14861 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 14862 | * |
| 14863 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14864 | * is used to get the entry count and entry size that are necessary to |
| 14865 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14866 | * is used to indicate which event queue to bind this completion queue to. This |
| 14867 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 14868 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14869 | * command to finish before continuing. |
| 14870 | * |
| 14871 | * On success this function will return a zero. If unable to allocate enough |
| 14872 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14873 | * fails this function will return -ENXIO. |
| 14874 | **/ |
| 14875 | int |
| 14876 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14877 | struct lpfc_sli4_hdw_queue *hdwq, uint32_t type, |
| 14878 | uint32_t subtype) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14879 | { |
| 14880 | struct lpfc_queue *cq; |
| 14881 | struct lpfc_queue *eq; |
| 14882 | struct lpfc_mbx_cq_create_set *cq_set; |
| 14883 | struct lpfc_dmabuf *dmabuf; |
| 14884 | LPFC_MBOXQ_t *mbox; |
| 14885 | int rc, length, alloclen, status = 0; |
| 14886 | int cnt, idx, numcq, page_idx = 0; |
| 14887 | uint32_t shdr_status, shdr_add_status; |
| 14888 | union lpfc_sli4_cfg_shdr *shdr; |
| 14889 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14890 | |
| 14891 | /* sanity check on queue memory */ |
| 14892 | numcq = phba->cfg_nvmet_mrq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14893 | if (!cqp || !hdwq || !numcq) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14894 | return -ENODEV; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14895 | |
| 14896 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14897 | if (!mbox) |
| 14898 | return -ENOMEM; |
| 14899 | |
| 14900 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 14901 | length += ((numcq * cqp[0]->page_count) * |
| 14902 | sizeof(struct dma_address)); |
| 14903 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14904 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 14905 | LPFC_SLI4_MBX_NEMBED); |
| 14906 | if (alloclen < length) { |
| 14907 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14908 | "3098 Allocated DMA memory size (%d) is " |
| 14909 | "less than the requested DMA memory size " |
| 14910 | "(%d)\n", alloclen, length); |
| 14911 | status = -ENOMEM; |
| 14912 | goto out; |
| 14913 | } |
| 14914 | cq_set = mbox->sge_array->addr[0]; |
| 14915 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 14916 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 14917 | |
| 14918 | for (idx = 0; idx < numcq; idx++) { |
| 14919 | cq = cqp[idx]; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14920 | eq = hdwq[idx].hba_eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14921 | if (!cq || !eq) { |
| 14922 | status = -ENOMEM; |
| 14923 | goto out; |
| 14924 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14925 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14926 | hw_page_size = cq->page_size; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14927 | |
| 14928 | switch (idx) { |
| 14929 | case 0: |
| 14930 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 14931 | &cq_set->u.request, |
| 14932 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 14933 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 14934 | &cq_set->u.request, cq->page_count); |
| 14935 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 14936 | &cq_set->u.request, 1); |
| 14937 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 14938 | &cq_set->u.request, 1); |
| 14939 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 14940 | &cq_set->u.request, 0); |
| 14941 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 14942 | &cq_set->u.request, numcq); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14943 | bf_set(lpfc_mbx_cq_create_set_autovalid, |
| 14944 | &cq_set->u.request, |
| 14945 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14946 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14947 | case 2048: |
| 14948 | case 4096: |
| 14949 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 14950 | LPFC_Q_CREATE_VERSION_2) { |
| 14951 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14952 | &cq_set->u.request, |
| 14953 | cq->entry_count); |
| 14954 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14955 | &cq_set->u.request, |
| 14956 | LPFC_CQ_CNT_WORD7); |
| 14957 | break; |
| 14958 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 14959 | /* fall through */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14960 | default: |
| 14961 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14962 | "3118 Bad CQ count. (%d)\n", |
| 14963 | cq->entry_count); |
| 14964 | if (cq->entry_count < 256) { |
| 14965 | status = -EINVAL; |
| 14966 | goto out; |
| 14967 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 14968 | /* fall through - otherwise default to smallest */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14969 | case 256: |
| 14970 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14971 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 14972 | break; |
| 14973 | case 512: |
| 14974 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14975 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 14976 | break; |
| 14977 | case 1024: |
| 14978 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14979 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 14980 | break; |
| 14981 | } |
| 14982 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 14983 | &cq_set->u.request, eq->queue_id); |
| 14984 | break; |
| 14985 | case 1: |
| 14986 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 14987 | &cq_set->u.request, eq->queue_id); |
| 14988 | break; |
| 14989 | case 2: |
| 14990 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 14991 | &cq_set->u.request, eq->queue_id); |
| 14992 | break; |
| 14993 | case 3: |
| 14994 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 14995 | &cq_set->u.request, eq->queue_id); |
| 14996 | break; |
| 14997 | case 4: |
| 14998 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 14999 | &cq_set->u.request, eq->queue_id); |
| 15000 | break; |
| 15001 | case 5: |
| 15002 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 15003 | &cq_set->u.request, eq->queue_id); |
| 15004 | break; |
| 15005 | case 6: |
| 15006 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 15007 | &cq_set->u.request, eq->queue_id); |
| 15008 | break; |
| 15009 | case 7: |
| 15010 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 15011 | &cq_set->u.request, eq->queue_id); |
| 15012 | break; |
| 15013 | case 8: |
| 15014 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 15015 | &cq_set->u.request, eq->queue_id); |
| 15016 | break; |
| 15017 | case 9: |
| 15018 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 15019 | &cq_set->u.request, eq->queue_id); |
| 15020 | break; |
| 15021 | case 10: |
| 15022 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 15023 | &cq_set->u.request, eq->queue_id); |
| 15024 | break; |
| 15025 | case 11: |
| 15026 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 15027 | &cq_set->u.request, eq->queue_id); |
| 15028 | break; |
| 15029 | case 12: |
| 15030 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 15031 | &cq_set->u.request, eq->queue_id); |
| 15032 | break; |
| 15033 | case 13: |
| 15034 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 15035 | &cq_set->u.request, eq->queue_id); |
| 15036 | break; |
| 15037 | case 14: |
| 15038 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 15039 | &cq_set->u.request, eq->queue_id); |
| 15040 | break; |
| 15041 | case 15: |
| 15042 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 15043 | &cq_set->u.request, eq->queue_id); |
| 15044 | break; |
| 15045 | } |
| 15046 | |
| 15047 | /* link the cq onto the parent eq child list */ |
| 15048 | list_add_tail(&cq->list, &eq->child_list); |
| 15049 | /* Set up completion queue's type and subtype */ |
| 15050 | cq->type = type; |
| 15051 | cq->subtype = subtype; |
| 15052 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15053 | cq->assoc_qp = eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15054 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15055 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 15056 | cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, |
| 15057 | cq->entry_count); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15058 | cq->chann = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15059 | |
| 15060 | rc = 0; |
| 15061 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 15062 | memset(dmabuf->virt, 0, hw_page_size); |
| 15063 | cnt = page_idx + dmabuf->buffer_tag; |
| 15064 | cq_set->u.request.page[cnt].addr_lo = |
| 15065 | putPaddrLow(dmabuf->phys); |
| 15066 | cq_set->u.request.page[cnt].addr_hi = |
| 15067 | putPaddrHigh(dmabuf->phys); |
| 15068 | rc++; |
| 15069 | } |
| 15070 | page_idx += rc; |
| 15071 | } |
| 15072 | |
| 15073 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15074 | |
| 15075 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15076 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15077 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15078 | if (shdr_status || shdr_add_status || rc) { |
| 15079 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15080 | "3119 CQ_CREATE_SET mailbox failed with " |
| 15081 | "status x%x add_status x%x, mbx status x%x\n", |
| 15082 | shdr_status, shdr_add_status, rc); |
| 15083 | status = -ENXIO; |
| 15084 | goto out; |
| 15085 | } |
| 15086 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 15087 | if (rc == 0xFFFF) { |
| 15088 | status = -ENXIO; |
| 15089 | goto out; |
| 15090 | } |
| 15091 | |
| 15092 | for (idx = 0; idx < numcq; idx++) { |
| 15093 | cq = cqp[idx]; |
| 15094 | cq->queue_id = rc + idx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15095 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 15096 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15097 | } |
| 15098 | |
| 15099 | out: |
| 15100 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 15101 | return status; |
| 15102 | } |
| 15103 | |
| 15104 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15105 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15106 | * @phba: HBA structure that indicates port to create a queue on. |
| 15107 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15108 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 15109 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15110 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15111 | * This function provides failback (fb) functionality when the |
| 15112 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 15113 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15114 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15115 | * This routine cannot fail as all attributes were previously accessed and |
| 15116 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15117 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15118 | static void |
| 15119 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15120 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15121 | { |
| 15122 | struct lpfc_mbx_mq_create *mq_create; |
| 15123 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15124 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15125 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15126 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 15127 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15128 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15129 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 15130 | length, LPFC_SLI4_MBX_EMBED); |
| 15131 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15132 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15133 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15134 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15135 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15136 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 15137 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15138 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15139 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15140 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15141 | break; |
| 15142 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15143 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15144 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15145 | break; |
| 15146 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15147 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15148 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15149 | break; |
| 15150 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15151 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15152 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15153 | break; |
| 15154 | } |
| 15155 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 15156 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15157 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15158 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15159 | putPaddrHigh(dmabuf->phys); |
| 15160 | } |
| 15161 | } |
| 15162 | |
| 15163 | /** |
| 15164 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 15165 | * @phba: HBA structure that indicates port to create a queue on. |
| 15166 | * @mq: The queue structure to use to create the mailbox queue. |
| 15167 | * @cq: The completion queue to associate with this cq. |
| 15168 | * @subtype: The queue's subtype. |
| 15169 | * |
| 15170 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 15171 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 15172 | * |
| 15173 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15174 | * is used to get the entry count and entry size that are necessary to |
| 15175 | * determine the number of pages to allocate and use for this queue. This |
| 15176 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 15177 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 15178 | * command to finish before continuing. |
| 15179 | * |
| 15180 | * 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] | 15181 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15182 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15183 | **/ |
| 15184 | int32_t |
| 15185 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15186 | struct lpfc_queue *cq, uint32_t subtype) |
| 15187 | { |
| 15188 | struct lpfc_mbx_mq_create *mq_create; |
| 15189 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 15190 | struct lpfc_dmabuf *dmabuf; |
| 15191 | LPFC_MBOXQ_t *mbox; |
| 15192 | int rc, length, status = 0; |
| 15193 | uint32_t shdr_status, shdr_add_status; |
| 15194 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15195 | 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] | 15196 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15197 | /* sanity check on queue memory */ |
| 15198 | if (!mq || !cq) |
| 15199 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15200 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15201 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15202 | |
| 15203 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15204 | if (!mbox) |
| 15205 | return -ENOMEM; |
| 15206 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 15207 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15208 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15209 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 15210 | length, LPFC_SLI4_MBX_EMBED); |
| 15211 | |
| 15212 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15213 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15214 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 15215 | &mq_create_ext->u.request, mq->page_count); |
| 15216 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 15217 | &mq_create_ext->u.request, 1); |
| 15218 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15219 | &mq_create_ext->u.request, 1); |
| 15220 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 15221 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15222 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 15223 | &mq_create_ext->u.request, 1); |
| 15224 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 15225 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15226 | 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] | 15227 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15228 | phba->sli4_hba.pc_sli4_params.mqv); |
| 15229 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 15230 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 15231 | cq->queue_id); |
| 15232 | else |
| 15233 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 15234 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15235 | switch (mq->entry_count) { |
| 15236 | default: |
| 15237 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15238 | "0362 Unsupported MQ count. (%d)\n", |
| 15239 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15240 | if (mq->entry_count < 16) { |
| 15241 | status = -EINVAL; |
| 15242 | goto out; |
| 15243 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15244 | /* fall through - otherwise default to smallest count */ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15245 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15246 | bf_set(lpfc_mq_context_ring_size, |
| 15247 | &mq_create_ext->u.request.context, |
| 15248 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15249 | break; |
| 15250 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15251 | bf_set(lpfc_mq_context_ring_size, |
| 15252 | &mq_create_ext->u.request.context, |
| 15253 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15254 | break; |
| 15255 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15256 | bf_set(lpfc_mq_context_ring_size, |
| 15257 | &mq_create_ext->u.request.context, |
| 15258 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15259 | break; |
| 15260 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15261 | bf_set(lpfc_mq_context_ring_size, |
| 15262 | &mq_create_ext->u.request.context, |
| 15263 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15264 | break; |
| 15265 | } |
| 15266 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15267 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15268 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15269 | putPaddrLow(dmabuf->phys); |
| 15270 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15271 | putPaddrHigh(dmabuf->phys); |
| 15272 | } |
| 15273 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15274 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15275 | &mq_create_ext->u.response); |
| 15276 | if (rc != MBX_SUCCESS) { |
| 15277 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15278 | "2795 MQ_CREATE_EXT failed with " |
| 15279 | "status x%x. Failback to MQ_CREATE.\n", |
| 15280 | rc); |
| 15281 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 15282 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15283 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15284 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 15285 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15286 | &mq_create->u.response); |
| 15287 | } |
| 15288 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15289 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15290 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15291 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15292 | if (shdr_status || shdr_add_status || rc) { |
| 15293 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15294 | "2502 MQ_CREATE mailbox failed with " |
| 15295 | "status x%x add_status x%x, mbx status x%x\n", |
| 15296 | shdr_status, shdr_add_status, rc); |
| 15297 | status = -ENXIO; |
| 15298 | goto out; |
| 15299 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15300 | if (mq->queue_id == 0xFFFF) { |
| 15301 | status = -ENXIO; |
| 15302 | goto out; |
| 15303 | } |
| 15304 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15305 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15306 | mq->subtype = subtype; |
| 15307 | mq->host_index = 0; |
| 15308 | mq->hba_index = 0; |
| 15309 | |
| 15310 | /* link the mq onto the parent cq child list */ |
| 15311 | list_add_tail(&mq->list, &cq->child_list); |
| 15312 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15313 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15314 | return status; |
| 15315 | } |
| 15316 | |
| 15317 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15318 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 15319 | * @phba: HBA structure that indicates port to create a queue on. |
| 15320 | * @wq: The queue structure to use to create the work queue. |
| 15321 | * @cq: The completion queue to bind this work queue to. |
| 15322 | * @subtype: The subtype of the work queue indicating its functionality. |
| 15323 | * |
| 15324 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 15325 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 15326 | * |
| 15327 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 15328 | * is used to get the entry count and entry size that are necessary to |
| 15329 | * determine the number of pages to allocate and use for this queue. The @cq |
| 15330 | * is used to indicate which completion queue to bind this work queue to. This |
| 15331 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 15332 | * work queue. This function is asynchronous and will wait for the mailbox |
| 15333 | * command to finish before continuing. |
| 15334 | * |
| 15335 | * 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] | 15336 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15337 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15338 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15339 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15340 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 15341 | struct lpfc_queue *cq, uint32_t subtype) |
| 15342 | { |
| 15343 | struct lpfc_mbx_wq_create *wq_create; |
| 15344 | struct lpfc_dmabuf *dmabuf; |
| 15345 | LPFC_MBOXQ_t *mbox; |
| 15346 | int rc, length, status = 0; |
| 15347 | uint32_t shdr_status, shdr_add_status; |
| 15348 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15349 | 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] | 15350 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15351 | void __iomem *bar_memmap_p; |
| 15352 | uint32_t db_offset; |
| 15353 | uint16_t pci_barset; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15354 | uint8_t dpp_barset; |
| 15355 | uint32_t dpp_offset; |
| 15356 | unsigned long pg_addr; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15357 | uint8_t wq_create_version; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15358 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15359 | /* sanity check on queue memory */ |
| 15360 | if (!wq || !cq) |
| 15361 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15362 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15363 | hw_page_size = wq->page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15364 | |
| 15365 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15366 | if (!mbox) |
| 15367 | return -ENOMEM; |
| 15368 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 15369 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15370 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15371 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 15372 | length, LPFC_SLI4_MBX_EMBED); |
| 15373 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15374 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15375 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 15376 | wq->page_count); |
| 15377 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 15378 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15379 | |
| 15380 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15381 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15382 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15383 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 15384 | if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) || |
| 15385 | (wq->page_size > SLI4_PAGE_SIZE)) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15386 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15387 | else |
| 15388 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15389 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15390 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15391 | if (phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) |
| 15392 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15393 | else |
| 15394 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15395 | |
| 15396 | switch (wq_create_version) { |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15397 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15398 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 15399 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 15400 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15401 | LPFC_Q_CREATE_VERSION_1); |
| 15402 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15403 | switch (wq->entry_size) { |
| 15404 | default: |
| 15405 | case 64: |
| 15406 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15407 | &wq_create->u.request_1, |
| 15408 | LPFC_WQ_WQE_SIZE_64); |
| 15409 | break; |
| 15410 | case 128: |
| 15411 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15412 | &wq_create->u.request_1, |
| 15413 | LPFC_WQ_WQE_SIZE_128); |
| 15414 | break; |
| 15415 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15416 | /* Request DPP by default */ |
| 15417 | 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] | 15418 | bf_set(lpfc_mbx_wq_create_page_size, |
| 15419 | &wq_create->u.request_1, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15420 | (wq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15421 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15422 | break; |
| 15423 | default: |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15424 | page = wq_create->u.request.page; |
| 15425 | break; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15426 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15427 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15428 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15429 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15430 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 15431 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15432 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15433 | |
| 15434 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15435 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 15436 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15437 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15438 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15439 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15440 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15441 | if (shdr_status || shdr_add_status || rc) { |
| 15442 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15443 | "2503 WQ_CREATE mailbox failed with " |
| 15444 | "status x%x add_status x%x, mbx status x%x\n", |
| 15445 | shdr_status, shdr_add_status, rc); |
| 15446 | status = -ENXIO; |
| 15447 | goto out; |
| 15448 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15449 | |
| 15450 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) |
| 15451 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, |
| 15452 | &wq_create->u.response); |
| 15453 | else |
| 15454 | wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id, |
| 15455 | &wq_create->u.response_1); |
| 15456 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15457 | if (wq->queue_id == 0xFFFF) { |
| 15458 | status = -ENXIO; |
| 15459 | goto out; |
| 15460 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15461 | |
| 15462 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 15463 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) { |
| 15464 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15465 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 15466 | &wq_create->u.response); |
| 15467 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15468 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15469 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15470 | "3265 WQ[%d] doorbell format " |
| 15471 | "not supported: x%x\n", |
| 15472 | wq->queue_id, wq->db_format); |
| 15473 | status = -EINVAL; |
| 15474 | goto out; |
| 15475 | } |
| 15476 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 15477 | &wq_create->u.response); |
| 15478 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15479 | pci_barset); |
| 15480 | if (!bar_memmap_p) { |
| 15481 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15482 | "3263 WQ[%d] failed to memmap " |
| 15483 | "pci barset:x%x\n", |
| 15484 | wq->queue_id, pci_barset); |
| 15485 | status = -ENOMEM; |
| 15486 | goto out; |
| 15487 | } |
| 15488 | db_offset = wq_create->u.response.doorbell_offset; |
| 15489 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 15490 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 15491 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15492 | "3252 WQ[%d] doorbell offset " |
| 15493 | "not supported: x%x\n", |
| 15494 | wq->queue_id, db_offset); |
| 15495 | status = -EINVAL; |
| 15496 | goto out; |
| 15497 | } |
| 15498 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15499 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15500 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 15501 | "format:x%x\n", wq->queue_id, |
| 15502 | pci_barset, db_offset, wq->db_format); |
| 15503 | } else |
| 15504 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15505 | } else { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15506 | /* Check if DPP was honored by the firmware */ |
| 15507 | wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp, |
| 15508 | &wq_create->u.response_1); |
| 15509 | if (wq->dpp_enable) { |
| 15510 | pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set, |
| 15511 | &wq_create->u.response_1); |
| 15512 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15513 | pci_barset); |
| 15514 | if (!bar_memmap_p) { |
| 15515 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15516 | "3267 WQ[%d] failed to memmap " |
| 15517 | "pci barset:x%x\n", |
| 15518 | wq->queue_id, pci_barset); |
| 15519 | status = -ENOMEM; |
| 15520 | goto out; |
| 15521 | } |
| 15522 | db_offset = wq_create->u.response_1.doorbell_offset; |
| 15523 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15524 | wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id, |
| 15525 | &wq_create->u.response_1); |
| 15526 | dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar, |
| 15527 | &wq_create->u.response_1); |
| 15528 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15529 | dpp_barset); |
| 15530 | if (!bar_memmap_p) { |
| 15531 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15532 | "3268 WQ[%d] failed to memmap " |
| 15533 | "pci barset:x%x\n", |
| 15534 | wq->queue_id, dpp_barset); |
| 15535 | status = -ENOMEM; |
| 15536 | goto out; |
| 15537 | } |
| 15538 | dpp_offset = wq_create->u.response_1.dpp_offset; |
| 15539 | wq->dpp_regaddr = bar_memmap_p + dpp_offset; |
| 15540 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15541 | "3271 WQ[%d]: barset:x%x, offset:x%x, " |
| 15542 | "dpp_id:x%x dpp_barset:x%x " |
| 15543 | "dpp_offset:x%x\n", |
| 15544 | wq->queue_id, pci_barset, db_offset, |
| 15545 | wq->dpp_id, dpp_barset, dpp_offset); |
| 15546 | |
| 15547 | /* Enable combined writes for DPP aperture */ |
| 15548 | pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK; |
| 15549 | #ifdef CONFIG_X86 |
| 15550 | rc = set_memory_wc(pg_addr, 1); |
| 15551 | if (rc) { |
| 15552 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15553 | "3272 Cannot setup Combined " |
| 15554 | "Write on WQ[%d] - disable DPP\n", |
| 15555 | wq->queue_id); |
| 15556 | phba->cfg_enable_dpp = 0; |
| 15557 | } |
| 15558 | #else |
| 15559 | phba->cfg_enable_dpp = 0; |
| 15560 | #endif |
| 15561 | } else |
| 15562 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15563 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15564 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 15565 | if (wq->pring == NULL) { |
| 15566 | status = -ENOMEM; |
| 15567 | goto out; |
| 15568 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15569 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15570 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15571 | wq->subtype = subtype; |
| 15572 | wq->host_index = 0; |
| 15573 | wq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15574 | wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15575 | |
| 15576 | /* link the wq onto the parent cq child list */ |
| 15577 | list_add_tail(&wq->list, &cq->child_list); |
| 15578 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15579 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15580 | return status; |
| 15581 | } |
| 15582 | |
| 15583 | /** |
| 15584 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 15585 | * @phba: HBA structure that indicates port to create a queue on. |
| 15586 | * @hrq: The queue structure to use to create the header receive queue. |
| 15587 | * @drq: The queue structure to use to create the data receive queue. |
| 15588 | * @cq: The completion queue to bind this work queue to. |
| 15589 | * |
| 15590 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15591 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15592 | * to the HBA. |
| 15593 | * |
| 15594 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15595 | * struct is used to get the entry count that is necessary to determine the |
| 15596 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15597 | * completion queue to bind received buffers that are posted to these queues to. |
| 15598 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15599 | * receive queue pair. This function is asynchronous and will wait for the |
| 15600 | * mailbox command to finish before continuing. |
| 15601 | * |
| 15602 | * 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] | 15603 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15604 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15605 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15606 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15607 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15608 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 15609 | { |
| 15610 | struct lpfc_mbx_rq_create *rq_create; |
| 15611 | struct lpfc_dmabuf *dmabuf; |
| 15612 | LPFC_MBOXQ_t *mbox; |
| 15613 | int rc, length, status = 0; |
| 15614 | uint32_t shdr_status, shdr_add_status; |
| 15615 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15616 | 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] | 15617 | void __iomem *bar_memmap_p; |
| 15618 | uint32_t db_offset; |
| 15619 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15620 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15621 | /* sanity check on queue memory */ |
| 15622 | if (!hrq || !drq || !cq) |
| 15623 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15624 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15625 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15626 | |
| 15627 | if (hrq->entry_count != drq->entry_count) |
| 15628 | return -EINVAL; |
| 15629 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15630 | if (!mbox) |
| 15631 | return -ENOMEM; |
| 15632 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 15633 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15634 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15635 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15636 | length, LPFC_SLI4_MBX_EMBED); |
| 15637 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15638 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15639 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15640 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15641 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15642 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15643 | &rq_create->u.request.context, |
| 15644 | hrq->entry_count); |
| 15645 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15646 | bf_set(lpfc_rq_context_rqe_size, |
| 15647 | &rq_create->u.request.context, |
| 15648 | LPFC_RQE_SIZE_8); |
| 15649 | bf_set(lpfc_rq_context_page_size, |
| 15650 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 15651 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15652 | } else { |
| 15653 | switch (hrq->entry_count) { |
| 15654 | default: |
| 15655 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15656 | "2535 Unsupported RQ count. (%d)\n", |
| 15657 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15658 | if (hrq->entry_count < 512) { |
| 15659 | status = -EINVAL; |
| 15660 | goto out; |
| 15661 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15662 | /* fall through - otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15663 | case 512: |
| 15664 | bf_set(lpfc_rq_context_rqe_count, |
| 15665 | &rq_create->u.request.context, |
| 15666 | LPFC_RQ_RING_SIZE_512); |
| 15667 | break; |
| 15668 | case 1024: |
| 15669 | bf_set(lpfc_rq_context_rqe_count, |
| 15670 | &rq_create->u.request.context, |
| 15671 | LPFC_RQ_RING_SIZE_1024); |
| 15672 | break; |
| 15673 | case 2048: |
| 15674 | bf_set(lpfc_rq_context_rqe_count, |
| 15675 | &rq_create->u.request.context, |
| 15676 | LPFC_RQ_RING_SIZE_2048); |
| 15677 | break; |
| 15678 | case 4096: |
| 15679 | bf_set(lpfc_rq_context_rqe_count, |
| 15680 | &rq_create->u.request.context, |
| 15681 | LPFC_RQ_RING_SIZE_4096); |
| 15682 | break; |
| 15683 | } |
| 15684 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 15685 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15686 | } |
| 15687 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15688 | cq->queue_id); |
| 15689 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15690 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15691 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15692 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15693 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15694 | putPaddrLow(dmabuf->phys); |
| 15695 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15696 | putPaddrHigh(dmabuf->phys); |
| 15697 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15698 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15699 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 15700 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15701 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15702 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15703 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15704 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15705 | if (shdr_status || shdr_add_status || rc) { |
| 15706 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15707 | "2504 RQ_CREATE mailbox failed with " |
| 15708 | "status x%x add_status x%x, mbx status x%x\n", |
| 15709 | shdr_status, shdr_add_status, rc); |
| 15710 | status = -ENXIO; |
| 15711 | goto out; |
| 15712 | } |
| 15713 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15714 | if (hrq->queue_id == 0xFFFF) { |
| 15715 | status = -ENXIO; |
| 15716 | goto out; |
| 15717 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15718 | |
| 15719 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15720 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 15721 | &rq_create->u.response); |
| 15722 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15723 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15724 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15725 | "3262 RQ [%d] doorbell format not " |
| 15726 | "supported: x%x\n", hrq->queue_id, |
| 15727 | hrq->db_format); |
| 15728 | status = -EINVAL; |
| 15729 | goto out; |
| 15730 | } |
| 15731 | |
| 15732 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 15733 | &rq_create->u.response); |
| 15734 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 15735 | if (!bar_memmap_p) { |
| 15736 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15737 | "3269 RQ[%d] failed to memmap pci " |
| 15738 | "barset:x%x\n", hrq->queue_id, |
| 15739 | pci_barset); |
| 15740 | status = -ENOMEM; |
| 15741 | goto out; |
| 15742 | } |
| 15743 | |
| 15744 | db_offset = rq_create->u.response.doorbell_offset; |
| 15745 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 15746 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 15747 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15748 | "3270 RQ[%d] doorbell offset not " |
| 15749 | "supported: x%x\n", hrq->queue_id, |
| 15750 | db_offset); |
| 15751 | status = -EINVAL; |
| 15752 | goto out; |
| 15753 | } |
| 15754 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 15755 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 15756 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 15757 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 15758 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15759 | } else { |
| 15760 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15761 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15762 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15763 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15764 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15765 | hrq->subtype = subtype; |
| 15766 | hrq->host_index = 0; |
| 15767 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15768 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15769 | |
| 15770 | /* now create the data queue */ |
| 15771 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15772 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15773 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15774 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15775 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15776 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15777 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15778 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15779 | if (subtype == LPFC_NVMET) |
| 15780 | rq_create->u.request.context.buffer_size = |
| 15781 | LPFC_NVMET_DATA_BUF_SIZE; |
| 15782 | else |
| 15783 | rq_create->u.request.context.buffer_size = |
| 15784 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15785 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 15786 | LPFC_RQE_SIZE_8); |
| 15787 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 15788 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15789 | } else { |
| 15790 | switch (drq->entry_count) { |
| 15791 | default: |
| 15792 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15793 | "2536 Unsupported RQ count. (%d)\n", |
| 15794 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15795 | if (drq->entry_count < 512) { |
| 15796 | status = -EINVAL; |
| 15797 | goto out; |
| 15798 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15799 | /* fall through - otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15800 | case 512: |
| 15801 | bf_set(lpfc_rq_context_rqe_count, |
| 15802 | &rq_create->u.request.context, |
| 15803 | LPFC_RQ_RING_SIZE_512); |
| 15804 | break; |
| 15805 | case 1024: |
| 15806 | bf_set(lpfc_rq_context_rqe_count, |
| 15807 | &rq_create->u.request.context, |
| 15808 | LPFC_RQ_RING_SIZE_1024); |
| 15809 | break; |
| 15810 | case 2048: |
| 15811 | bf_set(lpfc_rq_context_rqe_count, |
| 15812 | &rq_create->u.request.context, |
| 15813 | LPFC_RQ_RING_SIZE_2048); |
| 15814 | break; |
| 15815 | case 4096: |
| 15816 | bf_set(lpfc_rq_context_rqe_count, |
| 15817 | &rq_create->u.request.context, |
| 15818 | LPFC_RQ_RING_SIZE_4096); |
| 15819 | break; |
| 15820 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15821 | if (subtype == LPFC_NVMET) |
| 15822 | bf_set(lpfc_rq_context_buf_size, |
| 15823 | &rq_create->u.request.context, |
| 15824 | LPFC_NVMET_DATA_BUF_SIZE); |
| 15825 | else |
| 15826 | bf_set(lpfc_rq_context_buf_size, |
| 15827 | &rq_create->u.request.context, |
| 15828 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15829 | } |
| 15830 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15831 | cq->queue_id); |
| 15832 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15833 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15834 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 15835 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15836 | putPaddrLow(dmabuf->phys); |
| 15837 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15838 | putPaddrHigh(dmabuf->phys); |
| 15839 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15840 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15841 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15842 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15843 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15844 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15845 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15846 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15847 | if (shdr_status || shdr_add_status || rc) { |
| 15848 | status = -ENXIO; |
| 15849 | goto out; |
| 15850 | } |
| 15851 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15852 | if (drq->queue_id == 0xFFFF) { |
| 15853 | status = -ENXIO; |
| 15854 | goto out; |
| 15855 | } |
| 15856 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15857 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15858 | drq->subtype = subtype; |
| 15859 | drq->host_index = 0; |
| 15860 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15861 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15862 | |
| 15863 | /* link the header and data RQs onto the parent cq child list */ |
| 15864 | list_add_tail(&hrq->list, &cq->child_list); |
| 15865 | list_add_tail(&drq->list, &cq->child_list); |
| 15866 | |
| 15867 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15868 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15869 | return status; |
| 15870 | } |
| 15871 | |
| 15872 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15873 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 15874 | * @phba: HBA structure that indicates port to create a queue on. |
| 15875 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 15876 | * @drqp: The queue structure array to use to create the data receive queues. |
| 15877 | * @cqp: The completion queue array to bind these receive queues to. |
| 15878 | * |
| 15879 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15880 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15881 | * to the HBA. |
| 15882 | * |
| 15883 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15884 | * struct is used to get the entry count that is necessary to determine the |
| 15885 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15886 | * completion queue to bind received buffers that are posted to these queues to. |
| 15887 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15888 | * receive queue pair. This function is asynchronous and will wait for the |
| 15889 | * mailbox command to finish before continuing. |
| 15890 | * |
| 15891 | * On success this function will return a zero. If unable to allocate enough |
| 15892 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15893 | * fails this function will return -ENXIO. |
| 15894 | **/ |
| 15895 | int |
| 15896 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 15897 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 15898 | uint32_t subtype) |
| 15899 | { |
| 15900 | struct lpfc_queue *hrq, *drq, *cq; |
| 15901 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 15902 | struct lpfc_dmabuf *dmabuf; |
| 15903 | LPFC_MBOXQ_t *mbox; |
| 15904 | int rc, length, alloclen, status = 0; |
| 15905 | int cnt, idx, numrq, page_idx = 0; |
| 15906 | uint32_t shdr_status, shdr_add_status; |
| 15907 | union lpfc_sli4_cfg_shdr *shdr; |
| 15908 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15909 | |
| 15910 | numrq = phba->cfg_nvmet_mrq; |
| 15911 | /* sanity check on array memory */ |
| 15912 | if (!hrqp || !drqp || !cqp || !numrq) |
| 15913 | return -ENODEV; |
| 15914 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15915 | hw_page_size = SLI4_PAGE_SIZE; |
| 15916 | |
| 15917 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15918 | if (!mbox) |
| 15919 | return -ENOMEM; |
| 15920 | |
| 15921 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 15922 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 15923 | sizeof(struct dma_address)); |
| 15924 | |
| 15925 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15926 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 15927 | LPFC_SLI4_MBX_NEMBED); |
| 15928 | if (alloclen < length) { |
| 15929 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15930 | "3099 Allocated DMA memory size (%d) is " |
| 15931 | "less than the requested DMA memory size " |
| 15932 | "(%d)\n", alloclen, length); |
| 15933 | status = -ENOMEM; |
| 15934 | goto out; |
| 15935 | } |
| 15936 | |
| 15937 | |
| 15938 | |
| 15939 | rq_create = mbox->sge_array->addr[0]; |
| 15940 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 15941 | |
| 15942 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 15943 | cnt = 0; |
| 15944 | |
| 15945 | for (idx = 0; idx < numrq; idx++) { |
| 15946 | hrq = hrqp[idx]; |
| 15947 | drq = drqp[idx]; |
| 15948 | cq = cqp[idx]; |
| 15949 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15950 | /* sanity check on queue memory */ |
| 15951 | if (!hrq || !drq || !cq) { |
| 15952 | status = -ENODEV; |
| 15953 | goto out; |
| 15954 | } |
| 15955 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 15956 | if (hrq->entry_count != drq->entry_count) { |
| 15957 | status = -EINVAL; |
| 15958 | goto out; |
| 15959 | } |
| 15960 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15961 | if (idx == 0) { |
| 15962 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 15963 | &rq_create->u.request, |
| 15964 | hrq->page_count); |
| 15965 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 15966 | &rq_create->u.request, (numrq * 2)); |
| 15967 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 15968 | 1); |
| 15969 | bf_set(lpfc_rq_context_base_cq, |
| 15970 | &rq_create->u.request.context, |
| 15971 | cq->queue_id); |
| 15972 | bf_set(lpfc_rq_context_data_size, |
| 15973 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15974 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15975 | bf_set(lpfc_rq_context_hdr_size, |
| 15976 | &rq_create->u.request.context, |
| 15977 | LPFC_HDR_BUF_SIZE); |
| 15978 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15979 | &rq_create->u.request.context, |
| 15980 | hrq->entry_count); |
| 15981 | bf_set(lpfc_rq_context_rqe_size, |
| 15982 | &rq_create->u.request.context, |
| 15983 | LPFC_RQE_SIZE_8); |
| 15984 | bf_set(lpfc_rq_context_page_size, |
| 15985 | &rq_create->u.request.context, |
| 15986 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 15987 | } |
| 15988 | rc = 0; |
| 15989 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 15990 | memset(dmabuf->virt, 0, hw_page_size); |
| 15991 | cnt = page_idx + dmabuf->buffer_tag; |
| 15992 | rq_create->u.request.page[cnt].addr_lo = |
| 15993 | putPaddrLow(dmabuf->phys); |
| 15994 | rq_create->u.request.page[cnt].addr_hi = |
| 15995 | putPaddrHigh(dmabuf->phys); |
| 15996 | rc++; |
| 15997 | } |
| 15998 | page_idx += rc; |
| 15999 | |
| 16000 | rc = 0; |
| 16001 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 16002 | memset(dmabuf->virt, 0, hw_page_size); |
| 16003 | cnt = page_idx + dmabuf->buffer_tag; |
| 16004 | rq_create->u.request.page[cnt].addr_lo = |
| 16005 | putPaddrLow(dmabuf->phys); |
| 16006 | rq_create->u.request.page[cnt].addr_hi = |
| 16007 | putPaddrHigh(dmabuf->phys); |
| 16008 | rc++; |
| 16009 | } |
| 16010 | page_idx += rc; |
| 16011 | |
| 16012 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 16013 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16014 | hrq->type = LPFC_HRQ; |
| 16015 | hrq->assoc_qid = cq->queue_id; |
| 16016 | hrq->subtype = subtype; |
| 16017 | hrq->host_index = 0; |
| 16018 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16019 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16020 | |
| 16021 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 16022 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16023 | drq->type = LPFC_DRQ; |
| 16024 | drq->assoc_qid = cq->queue_id; |
| 16025 | drq->subtype = subtype; |
| 16026 | drq->host_index = 0; |
| 16027 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16028 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16029 | |
| 16030 | list_add_tail(&hrq->list, &cq->child_list); |
| 16031 | list_add_tail(&drq->list, &cq->child_list); |
| 16032 | } |
| 16033 | |
| 16034 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16035 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16036 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16037 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16038 | if (shdr_status || shdr_add_status || rc) { |
| 16039 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16040 | "3120 RQ_CREATE mailbox failed with " |
| 16041 | "status x%x add_status x%x, mbx status x%x\n", |
| 16042 | shdr_status, shdr_add_status, rc); |
| 16043 | status = -ENXIO; |
| 16044 | goto out; |
| 16045 | } |
| 16046 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16047 | if (rc == 0xFFFF) { |
| 16048 | status = -ENXIO; |
| 16049 | goto out; |
| 16050 | } |
| 16051 | |
| 16052 | /* Initialize all RQs with associated queue id */ |
| 16053 | for (idx = 0; idx < numrq; idx++) { |
| 16054 | hrq = hrqp[idx]; |
| 16055 | hrq->queue_id = rc + (2 * idx); |
| 16056 | drq = drqp[idx]; |
| 16057 | drq->queue_id = rc + (2 * idx) + 1; |
| 16058 | } |
| 16059 | |
| 16060 | out: |
| 16061 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16062 | return status; |
| 16063 | } |
| 16064 | |
| 16065 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16066 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 16067 | * @eq: The queue structure associated with the queue to destroy. |
| 16068 | * |
| 16069 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 16070 | * command, specific to the type of queue, to the HBA. |
| 16071 | * |
| 16072 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 16073 | * |
| 16074 | * 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] | 16075 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16076 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16077 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16078 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 16079 | { |
| 16080 | LPFC_MBOXQ_t *mbox; |
| 16081 | int rc, length, status = 0; |
| 16082 | uint32_t shdr_status, shdr_add_status; |
| 16083 | union lpfc_sli4_cfg_shdr *shdr; |
| 16084 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16085 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16086 | if (!eq) |
| 16087 | return -ENODEV; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16088 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16089 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16090 | if (!mbox) |
| 16091 | return -ENOMEM; |
| 16092 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 16093 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16094 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16095 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 16096 | length, LPFC_SLI4_MBX_EMBED); |
| 16097 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 16098 | eq->queue_id); |
| 16099 | mbox->vport = eq->phba->pport; |
| 16100 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16101 | |
| 16102 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 16103 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16104 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16105 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 16106 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16107 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16108 | if (shdr_status || shdr_add_status || rc) { |
| 16109 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16110 | "2505 EQ_DESTROY mailbox failed with " |
| 16111 | "status x%x add_status x%x, mbx status x%x\n", |
| 16112 | shdr_status, shdr_add_status, rc); |
| 16113 | status = -ENXIO; |
| 16114 | } |
| 16115 | |
| 16116 | /* Remove eq from any list */ |
| 16117 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16118 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16119 | return status; |
| 16120 | } |
| 16121 | |
| 16122 | /** |
| 16123 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 16124 | * @cq: The queue structure associated with the queue to destroy. |
| 16125 | * |
| 16126 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 16127 | * command, specific to the type of queue, to the HBA. |
| 16128 | * |
| 16129 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 16130 | * |
| 16131 | * 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] | 16132 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16133 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16134 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16135 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 16136 | { |
| 16137 | LPFC_MBOXQ_t *mbox; |
| 16138 | int rc, length, status = 0; |
| 16139 | uint32_t shdr_status, shdr_add_status; |
| 16140 | union lpfc_sli4_cfg_shdr *shdr; |
| 16141 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16142 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16143 | if (!cq) |
| 16144 | return -ENODEV; |
| 16145 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16146 | if (!mbox) |
| 16147 | return -ENOMEM; |
| 16148 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 16149 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16150 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16151 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 16152 | length, LPFC_SLI4_MBX_EMBED); |
| 16153 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 16154 | cq->queue_id); |
| 16155 | mbox->vport = cq->phba->pport; |
| 16156 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16157 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 16158 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16159 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16160 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 16161 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16162 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16163 | if (shdr_status || shdr_add_status || rc) { |
| 16164 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16165 | "2506 CQ_DESTROY mailbox failed with " |
| 16166 | "status x%x add_status x%x, mbx status x%x\n", |
| 16167 | shdr_status, shdr_add_status, rc); |
| 16168 | status = -ENXIO; |
| 16169 | } |
| 16170 | /* Remove cq from any list */ |
| 16171 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16172 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16173 | return status; |
| 16174 | } |
| 16175 | |
| 16176 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16177 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 16178 | * @qm: The queue structure associated with the queue to destroy. |
| 16179 | * |
| 16180 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 16181 | * command, specific to the type of queue, to the HBA. |
| 16182 | * |
| 16183 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 16184 | * |
| 16185 | * 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] | 16186 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16187 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16188 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16189 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 16190 | { |
| 16191 | LPFC_MBOXQ_t *mbox; |
| 16192 | int rc, length, status = 0; |
| 16193 | uint32_t shdr_status, shdr_add_status; |
| 16194 | union lpfc_sli4_cfg_shdr *shdr; |
| 16195 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16196 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16197 | if (!mq) |
| 16198 | return -ENODEV; |
| 16199 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16200 | if (!mbox) |
| 16201 | return -ENOMEM; |
| 16202 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 16203 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16204 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16205 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 16206 | length, LPFC_SLI4_MBX_EMBED); |
| 16207 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 16208 | mq->queue_id); |
| 16209 | mbox->vport = mq->phba->pport; |
| 16210 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16211 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 16212 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16213 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16214 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 16215 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16216 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16217 | if (shdr_status || shdr_add_status || rc) { |
| 16218 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16219 | "2507 MQ_DESTROY mailbox failed with " |
| 16220 | "status x%x add_status x%x, mbx status x%x\n", |
| 16221 | shdr_status, shdr_add_status, rc); |
| 16222 | status = -ENXIO; |
| 16223 | } |
| 16224 | /* Remove mq from any list */ |
| 16225 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16226 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16227 | return status; |
| 16228 | } |
| 16229 | |
| 16230 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16231 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 16232 | * @wq: The queue structure associated with the queue to destroy. |
| 16233 | * |
| 16234 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 16235 | * command, specific to the type of queue, to the HBA. |
| 16236 | * |
| 16237 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 16238 | * |
| 16239 | * 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] | 16240 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16241 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16242 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16243 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 16244 | { |
| 16245 | LPFC_MBOXQ_t *mbox; |
| 16246 | int rc, length, status = 0; |
| 16247 | uint32_t shdr_status, shdr_add_status; |
| 16248 | union lpfc_sli4_cfg_shdr *shdr; |
| 16249 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16250 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16251 | if (!wq) |
| 16252 | return -ENODEV; |
| 16253 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16254 | if (!mbox) |
| 16255 | return -ENOMEM; |
| 16256 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 16257 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16258 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16259 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 16260 | length, LPFC_SLI4_MBX_EMBED); |
| 16261 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 16262 | wq->queue_id); |
| 16263 | mbox->vport = wq->phba->pport; |
| 16264 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16265 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 16266 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16267 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 16268 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16269 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16270 | if (shdr_status || shdr_add_status || rc) { |
| 16271 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16272 | "2508 WQ_DESTROY mailbox failed with " |
| 16273 | "status x%x add_status x%x, mbx status x%x\n", |
| 16274 | shdr_status, shdr_add_status, rc); |
| 16275 | status = -ENXIO; |
| 16276 | } |
| 16277 | /* Remove wq from any list */ |
| 16278 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 16279 | kfree(wq->pring); |
| 16280 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16281 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16282 | return status; |
| 16283 | } |
| 16284 | |
| 16285 | /** |
| 16286 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 16287 | * @rq: The queue structure associated with the queue to destroy. |
| 16288 | * |
| 16289 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 16290 | * command, specific to the type of queue, to the HBA. |
| 16291 | * |
| 16292 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 16293 | * |
| 16294 | * 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] | 16295 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16296 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16297 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16298 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 16299 | struct lpfc_queue *drq) |
| 16300 | { |
| 16301 | LPFC_MBOXQ_t *mbox; |
| 16302 | int rc, length, status = 0; |
| 16303 | uint32_t shdr_status, shdr_add_status; |
| 16304 | union lpfc_sli4_cfg_shdr *shdr; |
| 16305 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16306 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16307 | if (!hrq || !drq) |
| 16308 | return -ENODEV; |
| 16309 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16310 | if (!mbox) |
| 16311 | return -ENOMEM; |
| 16312 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16313 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16314 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16315 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 16316 | length, LPFC_SLI4_MBX_EMBED); |
| 16317 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16318 | hrq->queue_id); |
| 16319 | mbox->vport = hrq->phba->pport; |
| 16320 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16321 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 16322 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16323 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16324 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16325 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16326 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16327 | if (shdr_status || shdr_add_status || rc) { |
| 16328 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16329 | "2509 RQ_DESTROY mailbox failed with " |
| 16330 | "status x%x add_status x%x, mbx status x%x\n", |
| 16331 | shdr_status, shdr_add_status, rc); |
| 16332 | if (rc != MBX_TIMEOUT) |
| 16333 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 16334 | return -ENXIO; |
| 16335 | } |
| 16336 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16337 | drq->queue_id); |
| 16338 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 16339 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16340 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16341 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16342 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16343 | if (shdr_status || shdr_add_status || rc) { |
| 16344 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16345 | "2510 RQ_DESTROY mailbox failed with " |
| 16346 | "status x%x add_status x%x, mbx status x%x\n", |
| 16347 | shdr_status, shdr_add_status, rc); |
| 16348 | status = -ENXIO; |
| 16349 | } |
| 16350 | list_del_init(&hrq->list); |
| 16351 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16352 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16353 | return status; |
| 16354 | } |
| 16355 | |
| 16356 | /** |
| 16357 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 16358 | * @phba: The virtual port for which this call being executed. |
| 16359 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 16360 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 16361 | * @xritag: the xritag that ties this io to the SGL pages. |
| 16362 | * |
| 16363 | * This routine will post the sgl pages for the IO that has the xritag |
| 16364 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 16365 | * creation and persists for as long as the driver is loaded. |
| 16366 | * if the caller has fewer than 256 scatter gather segments to map then |
| 16367 | * pdma_phys_addr1 should be 0. |
| 16368 | * If the caller needs to map more than 256 scatter gather segment then |
| 16369 | * pdma_phys_addr1 should be a valid physical address. |
| 16370 | * physical address for SGLs must be 64 byte aligned. |
| 16371 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 16372 | * the second sgl can have between 1 and 256 entries. |
| 16373 | * |
| 16374 | * Return codes: |
| 16375 | * 0 - Success |
| 16376 | * -ENXIO, -ENOMEM - Failure |
| 16377 | **/ |
| 16378 | int |
| 16379 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 16380 | dma_addr_t pdma_phys_addr0, |
| 16381 | dma_addr_t pdma_phys_addr1, |
| 16382 | uint16_t xritag) |
| 16383 | { |
| 16384 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 16385 | LPFC_MBOXQ_t *mbox; |
| 16386 | int rc; |
| 16387 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16388 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16389 | union lpfc_sli4_cfg_shdr *shdr; |
| 16390 | |
| 16391 | if (xritag == NO_XRI) { |
| 16392 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16393 | "0364 Invalid param:\n"); |
| 16394 | return -EINVAL; |
| 16395 | } |
| 16396 | |
| 16397 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16398 | if (!mbox) |
| 16399 | return -ENOMEM; |
| 16400 | |
| 16401 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16402 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16403 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16404 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16405 | |
| 16406 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 16407 | &mbox->u.mqe.un.post_sgl_pages; |
| 16408 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 16409 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 16410 | |
| 16411 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 16412 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 16413 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 16414 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 16415 | |
| 16416 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 16417 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 16418 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 16419 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 16420 | if (!phba->sli4_hba.intr_enable) |
| 16421 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16422 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16423 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16424 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16425 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16426 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16427 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 16428 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16429 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16430 | if (rc != MBX_TIMEOUT) |
| 16431 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16432 | if (shdr_status || shdr_add_status || rc) { |
| 16433 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16434 | "2511 POST_SGL mailbox failed with " |
| 16435 | "status x%x add_status x%x, mbx status x%x\n", |
| 16436 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16437 | } |
| 16438 | return 0; |
| 16439 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16440 | |
| 16441 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16442 | * 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] | 16443 | * @phba: pointer to lpfc hba data structure. |
| 16444 | * |
| 16445 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16446 | * HBA consistent with the SLI-4 interface spec. This routine |
| 16447 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 16448 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16449 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16450 | * Returns |
| 16451 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 16452 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 16453 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16454 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16455 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 16456 | { |
| 16457 | unsigned long xri; |
| 16458 | |
| 16459 | /* |
| 16460 | * Fetch the next logical xri. Because this index is logical, |
| 16461 | * the driver starts at 0 each time. |
| 16462 | */ |
| 16463 | spin_lock_irq(&phba->hbalock); |
| 16464 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 16465 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 16466 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 16467 | spin_unlock_irq(&phba->hbalock); |
| 16468 | return NO_XRI; |
| 16469 | } else { |
| 16470 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 16471 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16472 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16473 | spin_unlock_irq(&phba->hbalock); |
| 16474 | return xri; |
| 16475 | } |
| 16476 | |
| 16477 | /** |
| 16478 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16479 | * @phba: pointer to lpfc hba data structure. |
| 16480 | * |
| 16481 | * This routine is invoked to release an xri to the pool of |
| 16482 | * available rpis maintained by the driver. |
| 16483 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16484 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16485 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16486 | { |
| 16487 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16488 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 16489 | } |
| 16490 | } |
| 16491 | |
| 16492 | /** |
| 16493 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16494 | * @phba: pointer to lpfc hba data structure. |
| 16495 | * |
| 16496 | * This routine is invoked to release an xri to the pool of |
| 16497 | * available rpis maintained by the driver. |
| 16498 | **/ |
| 16499 | void |
| 16500 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16501 | { |
| 16502 | spin_lock_irq(&phba->hbalock); |
| 16503 | __lpfc_sli4_free_xri(phba, xri); |
| 16504 | spin_unlock_irq(&phba->hbalock); |
| 16505 | } |
| 16506 | |
| 16507 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16508 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 16509 | * @phba: Pointer to HBA context object. |
| 16510 | * |
| 16511 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 16512 | * it will return 0xffff. |
| 16513 | * The function returns the allocated xritag if successful, else returns zero. |
| 16514 | * Zero is not a valid xritag. |
| 16515 | * The caller is not required to hold any lock. |
| 16516 | **/ |
| 16517 | uint16_t |
| 16518 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 16519 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16520 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16521 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16522 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 16523 | if (xri_index == NO_XRI) |
| 16524 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 16525 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 16526 | " Max XRI is %d, Used XRI is %d\n", |
| 16527 | xri_index, |
| 16528 | phba->sli4_hba.max_cfg_param.max_xri, |
| 16529 | phba->sli4_hba.max_cfg_param.xri_used); |
| 16530 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16531 | } |
| 16532 | |
| 16533 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16534 | * 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] | 16535 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16536 | * @post_sgl_list: pointer to els sgl entry list. |
| 16537 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16538 | * |
| 16539 | * This routine is invoked to post a block of driver's sgl pages to the |
| 16540 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 16541 | * is only called when the driver is loading and after all IO has been |
| 16542 | * stopped. |
| 16543 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16544 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16545 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16546 | struct list_head *post_sgl_list, |
| 16547 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16548 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16549 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16550 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16551 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16552 | void *viraddr; |
| 16553 | LPFC_MBOXQ_t *mbox; |
| 16554 | uint32_t reqlen, alloclen, pg_pairs; |
| 16555 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16556 | uint16_t xritag_start = 0; |
| 16557 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16558 | uint32_t shdr_status, shdr_add_status; |
| 16559 | union lpfc_sli4_cfg_shdr *shdr; |
| 16560 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16561 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16562 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16563 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16564 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16565 | "2559 Block sgl registration required DMA " |
| 16566 | "size (%d) great than a page\n", reqlen); |
| 16567 | return -ENOMEM; |
| 16568 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16569 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16570 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16571 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16572 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16573 | |
| 16574 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16575 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16576 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16577 | LPFC_SLI4_MBX_NEMBED); |
| 16578 | |
| 16579 | if (alloclen < reqlen) { |
| 16580 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16581 | "0285 Allocated DMA memory size (%d) is " |
| 16582 | "less than the requested DMA memory " |
| 16583 | "size (%d)\n", alloclen, reqlen); |
| 16584 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16585 | return -ENOMEM; |
| 16586 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16587 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16588 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16589 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16590 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16591 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16592 | pg_pairs = 0; |
| 16593 | 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] | 16594 | /* Set up the sge entry */ |
| 16595 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16596 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 16597 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16598 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 16599 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16600 | cpu_to_le32(putPaddrLow(0)); |
| 16601 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16602 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16603 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16604 | /* Keep the first xritag on the list */ |
| 16605 | if (pg_pairs == 0) |
| 16606 | xritag_start = sglq_entry->sli4_xritag; |
| 16607 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16608 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16609 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16610 | |
| 16611 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16612 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16613 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16614 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16615 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16616 | if (!phba->sli4_hba.intr_enable) |
| 16617 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16618 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16619 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16620 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16621 | } |
| 16622 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16623 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16624 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16625 | if (rc != MBX_TIMEOUT) |
| 16626 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16627 | if (shdr_status || shdr_add_status || rc) { |
| 16628 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16629 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 16630 | "status x%x add_status x%x mbx status x%x\n", |
| 16631 | shdr_status, shdr_add_status, rc); |
| 16632 | rc = -ENXIO; |
| 16633 | } |
| 16634 | return rc; |
| 16635 | } |
| 16636 | |
| 16637 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16638 | * lpfc_sli4_post_io_sgl_block - post a block of nvme sgl list to firmware |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16639 | * @phba: pointer to lpfc hba data structure. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16640 | * @nblist: pointer to nvme buffer list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16641 | * @count: number of scsi buffers on the list. |
| 16642 | * |
| 16643 | * This routine is invoked to post a block of @count scsi sgl pages from a |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16644 | * SCSI buffer list @nblist to the HBA using non-embedded mailbox command. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16645 | * No Lock is held. |
| 16646 | * |
| 16647 | **/ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16648 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16649 | lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist, |
| 16650 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16651 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16652 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16653 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16654 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16655 | void *viraddr; |
| 16656 | LPFC_MBOXQ_t *mbox; |
| 16657 | uint32_t reqlen, alloclen, pg_pairs; |
| 16658 | uint32_t mbox_tmo; |
| 16659 | uint16_t xritag_start = 0; |
| 16660 | int rc = 0; |
| 16661 | uint32_t shdr_status, shdr_add_status; |
| 16662 | dma_addr_t pdma_phys_bpl1; |
| 16663 | union lpfc_sli4_cfg_shdr *shdr; |
| 16664 | |
| 16665 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16666 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16667 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16668 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16669 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16670 | "6118 Block sgl registration required DMA " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16671 | "size (%d) great than a page\n", reqlen); |
| 16672 | return -ENOMEM; |
| 16673 | } |
| 16674 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16675 | if (!mbox) { |
| 16676 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16677 | "6119 Failed to allocate mbox cmd memory\n"); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16678 | return -ENOMEM; |
| 16679 | } |
| 16680 | |
| 16681 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16682 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16683 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16684 | reqlen, LPFC_SLI4_MBX_NEMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16685 | |
| 16686 | if (alloclen < reqlen) { |
| 16687 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16688 | "6120 Allocated DMA memory size (%d) is " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16689 | "less than the requested DMA memory " |
| 16690 | "size (%d)\n", alloclen, reqlen); |
| 16691 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16692 | return -ENOMEM; |
| 16693 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16694 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16695 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16696 | viraddr = mbox->sge_array->addr[0]; |
| 16697 | |
| 16698 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 16699 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16700 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16701 | |
| 16702 | pg_pairs = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16703 | list_for_each_entry(lpfc_ncmd, nblist, list) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16704 | /* Set up the sge entry */ |
| 16705 | sgl_pg_pairs->sgl_pg0_addr_lo = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16706 | cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16707 | sgl_pg_pairs->sgl_pg0_addr_hi = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16708 | cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16709 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16710 | pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl + |
| 16711 | SGL_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16712 | else |
| 16713 | pdma_phys_bpl1 = 0; |
| 16714 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16715 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 16716 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16717 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 16718 | /* Keep the first xritag on the list */ |
| 16719 | if (pg_pairs == 0) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16720 | xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16721 | sgl_pg_pairs++; |
| 16722 | pg_pairs++; |
| 16723 | } |
| 16724 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 16725 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 16726 | /* Perform endian conversion if necessary */ |
| 16727 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 16728 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16729 | if (!phba->sli4_hba.intr_enable) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16730 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16731 | } else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16732 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16733 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16734 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16735 | shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16736 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16737 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16738 | if (rc != MBX_TIMEOUT) |
| 16739 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16740 | if (shdr_status || shdr_add_status || rc) { |
| 16741 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16742 | "6125 POST_SGL_BLOCK mailbox command failed " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16743 | "status x%x add_status x%x mbx status x%x\n", |
| 16744 | shdr_status, shdr_add_status, rc); |
| 16745 | rc = -ENXIO; |
| 16746 | } |
| 16747 | return rc; |
| 16748 | } |
| 16749 | |
| 16750 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16751 | * lpfc_sli4_post_io_sgl_list - Post blocks of nvme buffer sgls from a list |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16752 | * @phba: pointer to lpfc hba data structure. |
| 16753 | * @post_nblist: pointer to the nvme buffer list. |
| 16754 | * |
| 16755 | * This routine walks a list of nvme buffers that was passed in. It attempts |
| 16756 | * to construct blocks of nvme buffer sgls which contains contiguous xris and |
| 16757 | * uses the non-embedded SGL block post mailbox commands to post to the port. |
| 16758 | * For single NVME buffer sgl with non-contiguous xri, if any, it shall use |
| 16759 | * embedded SGL post mailbox command for posting. The @post_nblist passed in |
| 16760 | * must be local list, thus no lock is needed when manipulate the list. |
| 16761 | * |
| 16762 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
| 16763 | **/ |
| 16764 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16765 | lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba, |
| 16766 | struct list_head *post_nblist, int sb_count) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16767 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16768 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16769 | int status, sgl_size; |
| 16770 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
| 16771 | dma_addr_t pdma_phys_sgl1; |
| 16772 | int last_xritag = NO_XRI; |
| 16773 | int cur_xritag; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16774 | LIST_HEAD(prep_nblist); |
| 16775 | LIST_HEAD(blck_nblist); |
| 16776 | LIST_HEAD(nvme_nblist); |
| 16777 | |
| 16778 | /* sanity check */ |
| 16779 | if (sb_count <= 0) |
| 16780 | return -EINVAL; |
| 16781 | |
| 16782 | sgl_size = phba->cfg_sg_dma_buf_size; |
| 16783 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) { |
| 16784 | list_del_init(&lpfc_ncmd->list); |
| 16785 | block_cnt++; |
| 16786 | if ((last_xritag != NO_XRI) && |
| 16787 | (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) { |
| 16788 | /* a hole in xri block, form a sgl posting block */ |
| 16789 | list_splice_init(&prep_nblist, &blck_nblist); |
| 16790 | post_cnt = block_cnt - 1; |
| 16791 | /* prepare list for next posting block */ |
| 16792 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 16793 | block_cnt = 1; |
| 16794 | } else { |
| 16795 | /* prepare list for next posting block */ |
| 16796 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 16797 | /* enough sgls for non-embed sgl mbox command */ |
| 16798 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 16799 | list_splice_init(&prep_nblist, &blck_nblist); |
| 16800 | post_cnt = block_cnt; |
| 16801 | block_cnt = 0; |
| 16802 | } |
| 16803 | } |
| 16804 | num_posting++; |
| 16805 | last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 16806 | |
| 16807 | /* end of repost sgl list condition for NVME buffers */ |
| 16808 | if (num_posting == sb_count) { |
| 16809 | if (post_cnt == 0) { |
| 16810 | /* last sgl posting block */ |
| 16811 | list_splice_init(&prep_nblist, &blck_nblist); |
| 16812 | post_cnt = block_cnt; |
| 16813 | } else if (block_cnt == 1) { |
| 16814 | /* last single sgl with non-contiguous xri */ |
| 16815 | if (sgl_size > SGL_PAGE_SIZE) |
| 16816 | pdma_phys_sgl1 = |
| 16817 | lpfc_ncmd->dma_phys_sgl + |
| 16818 | SGL_PAGE_SIZE; |
| 16819 | else |
| 16820 | pdma_phys_sgl1 = 0; |
| 16821 | cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 16822 | status = lpfc_sli4_post_sgl( |
| 16823 | phba, lpfc_ncmd->dma_phys_sgl, |
| 16824 | pdma_phys_sgl1, cur_xritag); |
| 16825 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16826 | /* Post error. Buffer unavailable. */ |
| 16827 | lpfc_ncmd->flags |= |
| 16828 | LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16829 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16830 | /* Post success. Bffer available. */ |
| 16831 | lpfc_ncmd->flags &= |
| 16832 | ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16833 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 16834 | num_posted++; |
| 16835 | } |
| 16836 | /* success, put on NVME buffer sgl list */ |
| 16837 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 16838 | } |
| 16839 | } |
| 16840 | |
| 16841 | /* continue until a nembed page worth of sgls */ |
| 16842 | if (post_cnt == 0) |
| 16843 | continue; |
| 16844 | |
| 16845 | /* post block of NVME buffer list sgls */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16846 | status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist, |
| 16847 | post_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16848 | |
| 16849 | /* don't reset xirtag due to hole in xri block */ |
| 16850 | if (block_cnt == 0) |
| 16851 | last_xritag = NO_XRI; |
| 16852 | |
| 16853 | /* reset NVME buffer post count for next round of posting */ |
| 16854 | post_cnt = 0; |
| 16855 | |
| 16856 | /* put posted NVME buffer-sgl posted on NVME buffer sgl list */ |
| 16857 | while (!list_empty(&blck_nblist)) { |
| 16858 | list_remove_head(&blck_nblist, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16859 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16860 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16861 | /* Post error. Mark buffer unavailable. */ |
| 16862 | lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16863 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16864 | /* Post success, Mark buffer available. */ |
| 16865 | lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16866 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 16867 | num_posted++; |
| 16868 | } |
| 16869 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 16870 | } |
| 16871 | } |
| 16872 | /* Push NVME buffers with sgl posted to the available list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16873 | lpfc_io_buf_replenish(phba, &nvme_nblist); |
| 16874 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16875 | return num_posted; |
| 16876 | } |
| 16877 | |
| 16878 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16879 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 16880 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 16881 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16882 | * |
| 16883 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 16884 | * valid type of frame that the LPFC driver will handle. This function will |
| 16885 | * return a zero if the frame is a valid frame or a non zero value when the |
| 16886 | * frame does not pass the check. |
| 16887 | **/ |
| 16888 | static int |
| 16889 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 16890 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 16891 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16892 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16893 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16894 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 16895 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 16896 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16897 | switch (fc_hdr->fh_r_ctl) { |
| 16898 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 16899 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 16900 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 16901 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 16902 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 16903 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 16904 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 16905 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 16906 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 16907 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 16908 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 16909 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 16910 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 16911 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 16912 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 16913 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 16914 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 16915 | case FC_RCTL_BA_PRMT: |
| 16916 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 16917 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 16918 | case FC_RCTL_P_RJT: /* port reject */ |
| 16919 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 16920 | case FC_RCTL_P_BSY: /* port busy */ |
| 16921 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 16922 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 16923 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16924 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16925 | case FC_RCTL_END: /* end */ |
| 16926 | break; |
| 16927 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 16928 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16929 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 16930 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 16931 | default: |
| 16932 | goto drop; |
| 16933 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16934 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16935 | switch (fc_hdr->fh_type) { |
| 16936 | case FC_TYPE_BLS: |
| 16937 | case FC_TYPE_ELS: |
| 16938 | case FC_TYPE_FCP: |
| 16939 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16940 | case FC_TYPE_NVME: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16941 | break; |
| 16942 | case FC_TYPE_IP: |
| 16943 | case FC_TYPE_ILS: |
| 16944 | default: |
| 16945 | goto drop; |
| 16946 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16947 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16948 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16949 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 16950 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16951 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 16952 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 16953 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 16954 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 16955 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16956 | return 0; |
| 16957 | drop: |
| 16958 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16959 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 16960 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16961 | return 1; |
| 16962 | } |
| 16963 | |
| 16964 | /** |
| 16965 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 16966 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16967 | * |
| 16968 | * This function processes the FC header to retrieve the VFI from the VF |
| 16969 | * header, if one exists. This function will return the VFI if one exists |
| 16970 | * or 0 if no VSAN Header exists. |
| 16971 | **/ |
| 16972 | static uint32_t |
| 16973 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 16974 | { |
| 16975 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16976 | |
| 16977 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 16978 | return 0; |
| 16979 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 16980 | } |
| 16981 | |
| 16982 | /** |
| 16983 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 16984 | * @phba: Pointer to the HBA structure to search for the vport on |
| 16985 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16986 | * @fcfi: The FC Fabric ID that the frame came from |
| 16987 | * |
| 16988 | * This function searches the @phba for a vport that matches the content of the |
| 16989 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 16990 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 16991 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 16992 | * vport. |
| 16993 | **/ |
| 16994 | static struct lpfc_vport * |
| 16995 | 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] | 16996 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16997 | { |
| 16998 | struct lpfc_vport **vports; |
| 16999 | struct lpfc_vport *vport = NULL; |
| 17000 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17001 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 17002 | if (did == Fabric_DID) |
| 17003 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17004 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 17005 | !(phba->link_state == LPFC_HBA_READY)) |
| 17006 | return phba->pport; |
| 17007 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17008 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17009 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17010 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 17011 | if (phba->fcf.fcfi == fcfi && |
| 17012 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 17013 | vports[i]->fc_myDID == did) { |
| 17014 | vport = vports[i]; |
| 17015 | break; |
| 17016 | } |
| 17017 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17018 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17019 | lpfc_destroy_vport_work_array(phba, vports); |
| 17020 | return vport; |
| 17021 | } |
| 17022 | |
| 17023 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17024 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 17025 | * @vport: The vport to work on. |
| 17026 | * |
| 17027 | * This function updates the receive sequence time stamp for this vport. The |
| 17028 | * receive sequence time stamp indicates the time that the last frame of the |
| 17029 | * the sequence that has been idle for the longest amount of time was received. |
| 17030 | * the driver uses this time stamp to indicate if any received sequences have |
| 17031 | * timed out. |
| 17032 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17033 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17034 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 17035 | { |
| 17036 | struct lpfc_dmabuf *h_buf; |
| 17037 | struct hbq_dmabuf *dmabuf = NULL; |
| 17038 | |
| 17039 | /* get the oldest sequence on the rcv list */ |
| 17040 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 17041 | struct lpfc_dmabuf, list); |
| 17042 | if (!h_buf) |
| 17043 | return; |
| 17044 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17045 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 17046 | } |
| 17047 | |
| 17048 | /** |
| 17049 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 17050 | * @vport: The vport that the received sequences were sent to. |
| 17051 | * |
| 17052 | * This function cleans up all outstanding received sequences. This is called |
| 17053 | * by the driver when a link event or user action invalidates all the received |
| 17054 | * sequences. |
| 17055 | **/ |
| 17056 | void |
| 17057 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 17058 | { |
| 17059 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17060 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17061 | struct hbq_dmabuf *dmabuf = NULL; |
| 17062 | |
| 17063 | /* start with the oldest sequence on the rcv list */ |
| 17064 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17065 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17066 | list_del_init(&dmabuf->hbuf.list); |
| 17067 | list_for_each_entry_safe(d_buf, dnext, |
| 17068 | &dmabuf->dbuf.list, list) { |
| 17069 | list_del_init(&d_buf->list); |
| 17070 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17071 | } |
| 17072 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17073 | } |
| 17074 | } |
| 17075 | |
| 17076 | /** |
| 17077 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 17078 | * @vport: The vport that the received sequences were sent to. |
| 17079 | * |
| 17080 | * This function determines whether any received sequences have timed out by |
| 17081 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 17082 | * indicates that there is at least one timed out sequence this routine will |
| 17083 | * go through the received sequences one at a time from most inactive to most |
| 17084 | * active to determine which ones need to be cleaned up. Once it has determined |
| 17085 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 17086 | * without sending an abort. |
| 17087 | **/ |
| 17088 | void |
| 17089 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 17090 | { |
| 17091 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17092 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17093 | struct hbq_dmabuf *dmabuf = NULL; |
| 17094 | unsigned long timeout; |
| 17095 | int abort_count = 0; |
| 17096 | |
| 17097 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17098 | vport->rcv_buffer_time_stamp); |
| 17099 | if (list_empty(&vport->rcv_buffer_list) || |
| 17100 | time_before(jiffies, timeout)) |
| 17101 | return; |
| 17102 | /* start with the oldest sequence on the rcv list */ |
| 17103 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17104 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17105 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17106 | dmabuf->time_stamp); |
| 17107 | if (time_before(jiffies, timeout)) |
| 17108 | break; |
| 17109 | abort_count++; |
| 17110 | list_del_init(&dmabuf->hbuf.list); |
| 17111 | list_for_each_entry_safe(d_buf, dnext, |
| 17112 | &dmabuf->dbuf.list, list) { |
| 17113 | list_del_init(&d_buf->list); |
| 17114 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17115 | } |
| 17116 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17117 | } |
| 17118 | if (abort_count) |
| 17119 | lpfc_update_rcv_time_stamp(vport); |
| 17120 | } |
| 17121 | |
| 17122 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17123 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 17124 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 17125 | * |
| 17126 | * This function searches through the existing incomplete sequences that have |
| 17127 | * been sent to this @vport. If the frame matches one of the incomplete |
| 17128 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 17129 | * make up that sequence. If no sequence is found that matches this frame then |
| 17130 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 17131 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 17132 | * the frame was linked to. |
| 17133 | **/ |
| 17134 | static struct hbq_dmabuf * |
| 17135 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17136 | { |
| 17137 | struct fc_frame_header *new_hdr; |
| 17138 | struct fc_frame_header *temp_hdr; |
| 17139 | struct lpfc_dmabuf *d_buf; |
| 17140 | struct lpfc_dmabuf *h_buf; |
| 17141 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17142 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17143 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17144 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17145 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17146 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17147 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17148 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17149 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 17150 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17151 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17152 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17153 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17154 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17155 | continue; |
| 17156 | /* found a pending sequence that matches this frame */ |
| 17157 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17158 | break; |
| 17159 | } |
| 17160 | if (!seq_dmabuf) { |
| 17161 | /* |
| 17162 | * This indicates first frame received for this sequence. |
| 17163 | * Queue the buffer on the vport's rcv_buffer_list. |
| 17164 | */ |
| 17165 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17166 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17167 | return dmabuf; |
| 17168 | } |
| 17169 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17170 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 17171 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17172 | list_del_init(&seq_dmabuf->hbuf.list); |
| 17173 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17174 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17175 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17176 | return dmabuf; |
| 17177 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17178 | /* move this sequence to the tail to indicate a young sequence */ |
| 17179 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17180 | seq_dmabuf->time_stamp = jiffies; |
| 17181 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17182 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 17183 | temp_hdr = dmabuf->hbuf.virt; |
| 17184 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 17185 | return seq_dmabuf; |
| 17186 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17187 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17188 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 17189 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17190 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17191 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 17192 | /* |
| 17193 | * If the frame's sequence count is greater than the frame on |
| 17194 | * the list then insert the frame right after this frame |
| 17195 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17196 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 17197 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17198 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17199 | found = 1; |
| 17200 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17201 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17202 | |
| 17203 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 17204 | break; |
| 17205 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17206 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17207 | |
| 17208 | if (found) |
| 17209 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17210 | return NULL; |
| 17211 | } |
| 17212 | |
| 17213 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17214 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 17215 | * @vport: pointer to a vitural port |
| 17216 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17217 | * |
| 17218 | * This function tries to abort from the partially assembed sequence, described |
| 17219 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 17220 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 17221 | * the frames from the partially assembled sequence. |
| 17222 | * |
| 17223 | * Return |
| 17224 | * true -- if there is matching partially assembled sequence present and all |
| 17225 | * the frames freed with the sequence; |
| 17226 | * false -- if there is no matching partially assembled sequence present so |
| 17227 | * nothing got aborted in the lower layer driver |
| 17228 | **/ |
| 17229 | static bool |
| 17230 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 17231 | struct hbq_dmabuf *dmabuf) |
| 17232 | { |
| 17233 | struct fc_frame_header *new_hdr; |
| 17234 | struct fc_frame_header *temp_hdr; |
| 17235 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 17236 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17237 | |
| 17238 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 17239 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 17240 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 17241 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17242 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17243 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17244 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17245 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17246 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17247 | continue; |
| 17248 | /* found a pending sequence that matches this frame */ |
| 17249 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17250 | break; |
| 17251 | } |
| 17252 | |
| 17253 | /* Free up all the frames from the partially assembled sequence */ |
| 17254 | if (seq_dmabuf) { |
| 17255 | list_for_each_entry_safe(d_buf, n_buf, |
| 17256 | &seq_dmabuf->dbuf.list, list) { |
| 17257 | list_del_init(&d_buf->list); |
| 17258 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17259 | } |
| 17260 | return true; |
| 17261 | } |
| 17262 | return false; |
| 17263 | } |
| 17264 | |
| 17265 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17266 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 17267 | * @vport: pointer to a vitural port |
| 17268 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17269 | * |
| 17270 | * This function tries to abort from the assembed sequence from upper level |
| 17271 | * protocol, described by the information from basic abbort @dmabuf. It |
| 17272 | * checks to see whether such pending context exists at upper level protocol. |
| 17273 | * If so, it shall clean up the pending context. |
| 17274 | * |
| 17275 | * Return |
| 17276 | * true -- if there is matching pending context of the sequence cleaned |
| 17277 | * at ulp; |
| 17278 | * false -- if there is no matching pending context of the sequence present |
| 17279 | * at ulp. |
| 17280 | **/ |
| 17281 | static bool |
| 17282 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17283 | { |
| 17284 | struct lpfc_hba *phba = vport->phba; |
| 17285 | int handled; |
| 17286 | |
| 17287 | /* Accepting abort at ulp with SLI4 only */ |
| 17288 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 17289 | return false; |
| 17290 | |
| 17291 | /* Register all caring upper level protocols to attend abort */ |
| 17292 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 17293 | if (handled) |
| 17294 | return true; |
| 17295 | |
| 17296 | return false; |
| 17297 | } |
| 17298 | |
| 17299 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17300 | * 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] | 17301 | * @phba: Pointer to HBA context object. |
| 17302 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 17303 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 17304 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17305 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17306 | * event. It properly releases the memory allocated to the sequence abort |
| 17307 | * accept iocb. |
| 17308 | **/ |
| 17309 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17310 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17311 | struct lpfc_iocbq *cmd_iocbq, |
| 17312 | struct lpfc_iocbq *rsp_iocbq) |
| 17313 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17314 | struct lpfc_nodelist *ndlp; |
| 17315 | |
| 17316 | if (cmd_iocbq) { |
| 17317 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 17318 | lpfc_nlp_put(ndlp); |
| 17319 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17320 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17321 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17322 | |
| 17323 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 17324 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 17325 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17326 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 17327 | rsp_iocbq->iocb.ulpStatus, |
| 17328 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17329 | } |
| 17330 | |
| 17331 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17332 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 17333 | * @phba: Pointer to HBA context object. |
| 17334 | * @xri: xri id in transaction. |
| 17335 | * |
| 17336 | * This function validates the xri maps to the known range of XRIs allocated an |
| 17337 | * used by the driver. |
| 17338 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17339 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17340 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 17341 | uint16_t xri) |
| 17342 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17343 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17344 | |
| 17345 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 17346 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 17347 | return i; |
| 17348 | } |
| 17349 | return NO_XRI; |
| 17350 | } |
| 17351 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17352 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17353 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17354 | * @phba: Pointer to HBA context object. |
| 17355 | * @fc_hdr: pointer to a FC frame header. |
| 17356 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17357 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17358 | * event after aborting the sequence handling. |
| 17359 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17360 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17361 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 17362 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17363 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17364 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17365 | struct lpfc_iocbq *ctiocb = NULL; |
| 17366 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17367 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17368 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17369 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17370 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17371 | |
| 17372 | if (!lpfc_is_link_up(phba)) |
| 17373 | return; |
| 17374 | |
| 17375 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 17376 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17377 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17378 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17379 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17380 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 17381 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17382 | if (!ndlp) { |
| 17383 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17384 | "1268 Failed to allocate ndlp for " |
| 17385 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 17386 | return; |
| 17387 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17388 | /* Put ndlp onto pport node list */ |
| 17389 | lpfc_enqueue_node(vport, ndlp); |
| 17390 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 17391 | /* re-setup ndlp without removing from node list */ |
| 17392 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 17393 | if (!ndlp) { |
| 17394 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17395 | "3275 Failed to active ndlp found " |
| 17396 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 17397 | return; |
| 17398 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17399 | } |
| 17400 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17401 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17402 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 17403 | if (!ctiocb) |
| 17404 | return; |
| 17405 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17406 | /* Extract the F_CTL field from FC_HDR */ |
| 17407 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 17408 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17409 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17410 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17411 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17412 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 17413 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 17414 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 17415 | |
| 17416 | /* Fill in the rest of iocb fields */ |
| 17417 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 17418 | icmd->ulpBdeCount = 0; |
| 17419 | icmd->ulpLe = 1; |
| 17420 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17421 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17422 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17423 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17424 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17425 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17426 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17427 | ctiocb->sli4_xritag = NO_XRI; |
| 17428 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17429 | if (fctl & FC_FC_EX_CTX) |
| 17430 | /* Exchange responder sent the abort so we |
| 17431 | * own the oxid. |
| 17432 | */ |
| 17433 | xri = oxid; |
| 17434 | else |
| 17435 | xri = rxid; |
| 17436 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 17437 | if (lxri != NO_XRI) |
| 17438 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 17439 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17440 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 17441 | * the oxid maps to the FCP XRI range, the port no longer has |
| 17442 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 17443 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17444 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17445 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17446 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17447 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17448 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17449 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17450 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17451 | } |
| 17452 | |
| 17453 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 17454 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 17455 | * the IOCB for a BA_RJT. |
| 17456 | */ |
| 17457 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17458 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17459 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17460 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17461 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17462 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17463 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17464 | if (fctl & FC_FC_EX_CTX) { |
| 17465 | /* ABTS sent by responder to CT exchange, construction |
| 17466 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 17467 | * field and RX_ID from ABTS for RX_ID field. |
| 17468 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17469 | 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] | 17470 | } else { |
| 17471 | /* ABTS sent by initiator to CT exchange, construction |
| 17472 | * 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] | 17473 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17474 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17475 | 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] | 17476 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 17477 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17478 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17479 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17480 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17481 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 17482 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 17483 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17484 | |
| 17485 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 17486 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17487 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 17488 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 17489 | "xri x%x, Data x%x\n", |
| 17490 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 17491 | phba->link_state); |
| 17492 | lpfc_nlp_put(ndlp); |
| 17493 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17494 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 17495 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17496 | } |
| 17497 | |
| 17498 | /** |
| 17499 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 17500 | * @vport: Pointer to the vport on which this sequence was received |
| 17501 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17502 | * |
| 17503 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 17504 | * receive sequence is only partially assembed by the driver, it shall abort |
| 17505 | * the partially assembled frames for the sequence. Otherwise, if the |
| 17506 | * unsolicited receive sequence has been completely assembled and passed to |
| 17507 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 17508 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 17509 | * accept to accept the abort. |
| 17510 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17511 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17512 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 17513 | struct hbq_dmabuf *dmabuf) |
| 17514 | { |
| 17515 | struct lpfc_hba *phba = vport->phba; |
| 17516 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17517 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17518 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17519 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17520 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 17521 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17522 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17523 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17524 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17525 | /* ABTS by responder to exchange, no cleanup needed */ |
| 17526 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17527 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17528 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 17529 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 17530 | if (aborted == false) |
| 17531 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17532 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17533 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17534 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17535 | if (phba->nvmet_support) { |
| 17536 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 17537 | return; |
| 17538 | } |
| 17539 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17540 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 17541 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17542 | } |
| 17543 | |
| 17544 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17545 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 17546 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17547 | * |
| 17548 | * This function checks the sequence, starting with the frame described by |
| 17549 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 17550 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 17551 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 17552 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 17553 | * set. 3) That there are no holes in the sequence count. The function will |
| 17554 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 17555 | **/ |
| 17556 | static int |
| 17557 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 17558 | { |
| 17559 | struct fc_frame_header *hdr; |
| 17560 | struct lpfc_dmabuf *d_buf; |
| 17561 | struct hbq_dmabuf *seq_dmabuf; |
| 17562 | uint32_t fctl; |
| 17563 | int seq_count = 0; |
| 17564 | |
| 17565 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17566 | /* make sure first fame of sequence has a sequence count of zero */ |
| 17567 | if (hdr->fh_seq_cnt != seq_count) |
| 17568 | return 0; |
| 17569 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17570 | hdr->fh_f_ctl[1] << 8 | |
| 17571 | hdr->fh_f_ctl[2]); |
| 17572 | /* If last frame of sequence we can return success. */ |
| 17573 | if (fctl & FC_FC_END_SEQ) |
| 17574 | return 1; |
| 17575 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 17576 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17577 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17578 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17579 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17580 | return 0; |
| 17581 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17582 | hdr->fh_f_ctl[1] << 8 | |
| 17583 | hdr->fh_f_ctl[2]); |
| 17584 | /* If last frame of sequence we can return success. */ |
| 17585 | if (fctl & FC_FC_END_SEQ) |
| 17586 | return 1; |
| 17587 | } |
| 17588 | return 0; |
| 17589 | } |
| 17590 | |
| 17591 | /** |
| 17592 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 17593 | * @vport: Pointer to the vport on which this sequence was received |
| 17594 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17595 | * |
| 17596 | * This function takes a sequence, described by a list of frames, and creates |
| 17597 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 17598 | * used to issue to the generic unsolicited sequence handler. This routine |
| 17599 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 17600 | * to allocate an iocbq then it throw out the received frames that were not |
| 17601 | * able to be described and return a pointer to the first iocbq. If unable to |
| 17602 | * allocate any iocbqs (including the first) this function will return NULL. |
| 17603 | **/ |
| 17604 | static struct lpfc_iocbq * |
| 17605 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 17606 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17607 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17608 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 17609 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 17610 | struct fc_frame_header *fc_hdr; |
| 17611 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17612 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17613 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17614 | |
| 17615 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17616 | /* remove from receive buffer list */ |
| 17617 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17618 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17619 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17620 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17621 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17622 | /* Get an iocbq struct to fill in. */ |
| 17623 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17624 | if (first_iocbq) { |
| 17625 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17626 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17627 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17628 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17629 | |
| 17630 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 17631 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 17632 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 17633 | first_iocbq->iocb.un.rcvels.parmRo = |
| 17634 | sli4_did_from_fc_hdr(fc_hdr); |
| 17635 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 17636 | } else |
| 17637 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17638 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 17639 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 17640 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 17641 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 17642 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 17643 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17644 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17645 | tot_len = bf_get(lpfc_rcqe_length, |
| 17646 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17647 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17648 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 17649 | first_iocbq->context3 = NULL; |
| 17650 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17651 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 17652 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17653 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17654 | else |
| 17655 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 17656 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17657 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17658 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17659 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17660 | } |
| 17661 | iocbq = first_iocbq; |
| 17662 | /* |
| 17663 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 17664 | * of buffers for this sequence and save two buffers in each IOCBq |
| 17665 | */ |
| 17666 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 17667 | if (!iocbq) { |
| 17668 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17669 | continue; |
| 17670 | } |
| 17671 | if (!iocbq->context3) { |
| 17672 | iocbq->context3 = d_buf; |
| 17673 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17674 | /* We need to get the size out of the right CQE */ |
| 17675 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17676 | len = bf_get(lpfc_rcqe_length, |
| 17677 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17678 | pbde = (struct ulp_bde64 *) |
| 17679 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 17680 | if (len > LPFC_DATA_BUF_SIZE) |
| 17681 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 17682 | else |
| 17683 | pbde->tus.f.bdeSize = len; |
| 17684 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17685 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 17686 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17687 | } else { |
| 17688 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17689 | if (!iocbq) { |
| 17690 | if (first_iocbq) { |
| 17691 | first_iocbq->iocb.ulpStatus = |
| 17692 | IOSTAT_FCP_RSP_ERROR; |
| 17693 | first_iocbq->iocb.un.ulpWord[4] = |
| 17694 | IOERR_NO_RESOURCES; |
| 17695 | } |
| 17696 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17697 | continue; |
| 17698 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17699 | /* We need to get the size out of the right CQE */ |
| 17700 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17701 | len = bf_get(lpfc_rcqe_length, |
| 17702 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17703 | iocbq->context2 = d_buf; |
| 17704 | iocbq->context3 = NULL; |
| 17705 | iocbq->iocb.ulpBdeCount = 1; |
| 17706 | if (len > LPFC_DATA_BUF_SIZE) |
| 17707 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 17708 | LPFC_DATA_BUF_SIZE; |
| 17709 | else |
| 17710 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 17711 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17712 | tot_len += len; |
| 17713 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 17714 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17715 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 17716 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 17717 | } |
| 17718 | } |
| 17719 | return first_iocbq; |
| 17720 | } |
| 17721 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17722 | static void |
| 17723 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 17724 | struct hbq_dmabuf *seq_dmabuf) |
| 17725 | { |
| 17726 | struct fc_frame_header *fc_hdr; |
| 17727 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 17728 | struct lpfc_hba *phba = vport->phba; |
| 17729 | |
| 17730 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17731 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 17732 | if (!iocbq) { |
| 17733 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17734 | "2707 Ring %d handler: Failed to allocate " |
| 17735 | "iocb Rctl x%x Type x%x received\n", |
| 17736 | LPFC_ELS_RING, |
| 17737 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17738 | return; |
| 17739 | } |
| 17740 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17741 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17742 | iocbq, fc_hdr->fh_r_ctl, |
| 17743 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17744 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17745 | "2540 Ring %d handler: unexpected Rctl " |
| 17746 | "x%x Type x%x received\n", |
| 17747 | LPFC_ELS_RING, |
| 17748 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17749 | |
| 17750 | /* Free iocb created in lpfc_prep_seq */ |
| 17751 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 17752 | &iocbq->list, list) { |
| 17753 | list_del_init(&curr_iocb->list); |
| 17754 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 17755 | } |
| 17756 | lpfc_sli_release_iocbq(phba, iocbq); |
| 17757 | } |
| 17758 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17759 | static void |
| 17760 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 17761 | struct lpfc_iocbq *rspiocb) |
| 17762 | { |
| 17763 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 17764 | |
| 17765 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17766 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17767 | kfree(pcmd); |
| 17768 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17769 | lpfc_drain_txq(phba); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17770 | } |
| 17771 | |
| 17772 | static void |
| 17773 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 17774 | struct hbq_dmabuf *dmabuf) |
| 17775 | { |
| 17776 | struct fc_frame_header *fc_hdr; |
| 17777 | struct lpfc_hba *phba = vport->phba; |
| 17778 | struct lpfc_iocbq *iocbq = NULL; |
| 17779 | union lpfc_wqe *wqe; |
| 17780 | struct lpfc_dmabuf *pcmd = NULL; |
| 17781 | uint32_t frame_len; |
| 17782 | int rc; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17783 | unsigned long iflags; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17784 | |
| 17785 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17786 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17787 | |
| 17788 | /* Send the received frame back */ |
| 17789 | iocbq = lpfc_sli_get_iocbq(phba); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17790 | if (!iocbq) { |
| 17791 | /* Queue cq event and wakeup worker thread to process it */ |
| 17792 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 17793 | list_add_tail(&dmabuf->cq_event.list, |
| 17794 | &phba->sli4_hba.sp_queue_event); |
| 17795 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
| 17796 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 17797 | lpfc_worker_wake_up(phba); |
| 17798 | return; |
| 17799 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17800 | |
| 17801 | /* Allocate buffer for command payload */ |
| 17802 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 17803 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17804 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17805 | &pcmd->phys); |
| 17806 | if (!pcmd || !pcmd->virt) |
| 17807 | goto exit; |
| 17808 | |
| 17809 | INIT_LIST_HEAD(&pcmd->list); |
| 17810 | |
| 17811 | /* copyin the payload */ |
| 17812 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 17813 | |
| 17814 | /* fill in BDE's for command */ |
| 17815 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 17816 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 17817 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 17818 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 17819 | |
| 17820 | iocbq->context2 = pcmd; |
| 17821 | iocbq->vport = vport; |
| 17822 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 17823 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 17824 | |
| 17825 | /* |
| 17826 | * Setup rest of the iocb as though it were a WQE |
| 17827 | * Build the SEND_FRAME WQE |
| 17828 | */ |
| 17829 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 17830 | |
| 17831 | wqe->send_frame.frame_len = frame_len; |
| 17832 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 17833 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 17834 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 17835 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 17836 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 17837 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 17838 | |
| 17839 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 17840 | iocbq->iocb.ulpLe = 1; |
| 17841 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 17842 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 17843 | if (rc == IOCB_ERROR) |
| 17844 | goto exit; |
| 17845 | |
| 17846 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17847 | return; |
| 17848 | |
| 17849 | exit: |
| 17850 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 17851 | "2023 Unable to process MDS loopback frame\n"); |
| 17852 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17853 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17854 | kfree(pcmd); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 17855 | if (iocbq) |
| 17856 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17857 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17858 | } |
| 17859 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17860 | /** |
| 17861 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 17862 | * @phba: Pointer to HBA context object. |
| 17863 | * |
| 17864 | * This function is called with no lock held. This function processes all |
| 17865 | * the received buffers and gives it to upper layers when a received buffer |
| 17866 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17867 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17868 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 17869 | * appropriate receive function when the final frame in a sequence is received. |
| 17870 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17871 | void |
| 17872 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 17873 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17874 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17875 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17876 | struct fc_frame_header *fc_hdr; |
| 17877 | struct lpfc_vport *vport; |
| 17878 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17879 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17880 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17881 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17882 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17883 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17884 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 17885 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 17886 | vport = phba->pport; |
| 17887 | /* Handle MDS Loopback frames */ |
| 17888 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 17889 | return; |
| 17890 | } |
| 17891 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17892 | /* check to see if this a valid type of frame */ |
| 17893 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 17894 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17895 | return; |
| 17896 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17897 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17898 | if ((bf_get(lpfc_cqe_code, |
| 17899 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 17900 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 17901 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17902 | else |
| 17903 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 17904 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17905 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 17906 | if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) { |
| 17907 | vport = phba->pport; |
| 17908 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 17909 | "2023 MDS Loopback %d bytes\n", |
| 17910 | bf_get(lpfc_rcqe_length, |
| 17911 | &dmabuf->cq_event.cqe.rcqe_cmpl)); |
| 17912 | /* Handle MDS Loopback frames */ |
| 17913 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 17914 | return; |
| 17915 | } |
| 17916 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17917 | /* d_id this frame is directed to */ |
| 17918 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 17919 | |
| 17920 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17921 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17922 | /* throw out the frame */ |
| 17923 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17924 | return; |
| 17925 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17926 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17927 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 17928 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 17929 | (did != Fabric_DID)) { |
| 17930 | /* |
| 17931 | * Throw out the frame if we are not pt2pt. |
| 17932 | * The pt2pt protocol allows for discovery frames |
| 17933 | * to be received without a registered VPI. |
| 17934 | */ |
| 17935 | if (!(vport->fc_flag & FC_PT2PT) || |
| 17936 | (phba->link_state == LPFC_HBA_READY)) { |
| 17937 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17938 | return; |
| 17939 | } |
| 17940 | } |
| 17941 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17942 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 17943 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 17944 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 17945 | return; |
| 17946 | } |
| 17947 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17948 | /* Link this frame */ |
| 17949 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 17950 | if (!seq_dmabuf) { |
| 17951 | /* unable to add frame to vport - throw it out */ |
| 17952 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17953 | return; |
| 17954 | } |
| 17955 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17956 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17957 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17958 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17959 | /* Send the complete sequence to the upper layer protocol */ |
| 17960 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17961 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17962 | |
| 17963 | /** |
| 17964 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 17965 | * @phba: pointer to lpfc hba data structure. |
| 17966 | * |
| 17967 | * This routine is invoked to post rpi header templates to the |
| 17968 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17969 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 17970 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17971 | * |
| 17972 | * This routine does not require any locks. It's usage is expected |
| 17973 | * to be driver load or reset recovery when the driver is |
| 17974 | * sequential. |
| 17975 | * |
| 17976 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17977 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17978 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17979 | * When this error occurs, the driver is not guaranteed |
| 17980 | * to have any rpi regions posted to the device and |
| 17981 | * must either attempt to repost the regions or take a |
| 17982 | * fatal error. |
| 17983 | **/ |
| 17984 | int |
| 17985 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 17986 | { |
| 17987 | struct lpfc_rpi_hdr *rpi_page; |
| 17988 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17989 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17990 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17991 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 17992 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 17993 | goto exit; |
| 17994 | if (phba->sli4_hba.extents_in_use) |
| 17995 | return -EIO; |
| 17996 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17997 | 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] | 17998 | /* |
| 17999 | * Assign the rpi headers a physical rpi only if the driver |
| 18000 | * has not initialized those resources. A port reset only |
| 18001 | * needs the headers posted. |
| 18002 | */ |
| 18003 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 18004 | LPFC_RPI_RSRC_RDY) |
| 18005 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 18006 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18007 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 18008 | if (rc != MBX_SUCCESS) { |
| 18009 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18010 | "2008 Error %d posting all rpi " |
| 18011 | "headers\n", rc); |
| 18012 | rc = -EIO; |
| 18013 | break; |
| 18014 | } |
| 18015 | } |
| 18016 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18017 | exit: |
| 18018 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 18019 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18020 | return rc; |
| 18021 | } |
| 18022 | |
| 18023 | /** |
| 18024 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 18025 | * @phba: pointer to lpfc hba data structure. |
| 18026 | * @rpi_page: pointer to the rpi memory region. |
| 18027 | * |
| 18028 | * This routine is invoked to post a single rpi header to the |
| 18029 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 18030 | * maps up to 64 rpi context regions. |
| 18031 | * |
| 18032 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18033 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18034 | * -ENOMEM - No available memory |
| 18035 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18036 | **/ |
| 18037 | int |
| 18038 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 18039 | { |
| 18040 | LPFC_MBOXQ_t *mboxq; |
| 18041 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 18042 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18043 | uint32_t shdr_status, shdr_add_status; |
| 18044 | union lpfc_sli4_cfg_shdr *shdr; |
| 18045 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18046 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18047 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18048 | return rc; |
| 18049 | if (phba->sli4_hba.extents_in_use) |
| 18050 | return -EIO; |
| 18051 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18052 | /* The port is notified of the header region via a mailbox command. */ |
| 18053 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18054 | if (!mboxq) { |
| 18055 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18056 | "2001 Unable to allocate memory for issuing " |
| 18057 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 18058 | return -ENOMEM; |
| 18059 | } |
| 18060 | |
| 18061 | /* Post all rpi memory regions to the port. */ |
| 18062 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18063 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18064 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 18065 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 18066 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 18067 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18068 | |
| 18069 | |
| 18070 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18071 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 18072 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18073 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 18074 | hdr_tmpl, rpi_page->page_count); |
| 18075 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18076 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 18077 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 18078 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18079 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 18080 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18081 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18082 | if (rc != MBX_TIMEOUT) |
| 18083 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18084 | if (shdr_status || shdr_add_status || rc) { |
| 18085 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18086 | "2514 POST_RPI_HDR mailbox failed with " |
| 18087 | "status x%x add_status x%x, mbx status x%x\n", |
| 18088 | shdr_status, shdr_add_status, rc); |
| 18089 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 18090 | } else { |
| 18091 | /* |
| 18092 | * The next_rpi stores the next logical module-64 rpi value used |
| 18093 | * to post physical rpis in subsequent rpi postings. |
| 18094 | */ |
| 18095 | spin_lock_irq(&phba->hbalock); |
| 18096 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 18097 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18098 | } |
| 18099 | return rc; |
| 18100 | } |
| 18101 | |
| 18102 | /** |
| 18103 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 18104 | * @phba: pointer to lpfc hba data structure. |
| 18105 | * |
| 18106 | * This routine is invoked to post rpi header templates to the |
| 18107 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18108 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18109 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18110 | * |
| 18111 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18112 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18113 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 18114 | **/ |
| 18115 | int |
| 18116 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 18117 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18118 | unsigned long rpi; |
| 18119 | uint16_t max_rpi, rpi_limit; |
| 18120 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18121 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18122 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18123 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18124 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18125 | * Fetch the next logical rpi. Because this index is logical, |
| 18126 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18127 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18128 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18129 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 18130 | rpi_limit = phba->sli4_hba.next_rpi; |
| 18131 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18132 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 18133 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18134 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 18135 | else { |
| 18136 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 18137 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 18138 | phba->sli4_hba.rpi_count++; |
| 18139 | } |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 18140 | lpfc_printf_log(phba, KERN_INFO, |
| 18141 | LOG_NODE | LOG_DISCOVERY, |
| 18142 | "0001 Allocated rpi:x%x max:x%x lim:x%x\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18143 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18144 | |
| 18145 | /* |
| 18146 | * 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] | 18147 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18148 | */ |
| 18149 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 18150 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18151 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18152 | return rpi; |
| 18153 | } |
| 18154 | |
| 18155 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18156 | * RPI header postings are not required for SLI4 ports capable of |
| 18157 | * extents. |
| 18158 | */ |
| 18159 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18160 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18161 | return rpi; |
| 18162 | } |
| 18163 | |
| 18164 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18165 | * If the driver is running low on rpi resources, allocate another |
| 18166 | * page now. Note that the next_rpi value is used because |
| 18167 | * it represents how many are actually in use whereas max_rpi notes |
| 18168 | * how many are supported max by the device. |
| 18169 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18170 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18171 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18172 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 18173 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 18174 | if (!rpi_hdr) { |
| 18175 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18176 | "2002 Error Could not grow rpi " |
| 18177 | "count\n"); |
| 18178 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18179 | lrpi = rpi_hdr->start_rpi; |
| 18180 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18181 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 18182 | } |
| 18183 | } |
| 18184 | |
| 18185 | return rpi; |
| 18186 | } |
| 18187 | |
| 18188 | /** |
| 18189 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18190 | * @phba: pointer to lpfc hba data structure. |
| 18191 | * |
| 18192 | * This routine is invoked to release an rpi to the pool of |
| 18193 | * available rpis maintained by the driver. |
| 18194 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18195 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18196 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18197 | { |
| 18198 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 18199 | phba->sli4_hba.rpi_count--; |
| 18200 | phba->sli4_hba.max_cfg_param.rpi_used--; |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 18201 | } else { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 18202 | lpfc_printf_log(phba, KERN_INFO, |
| 18203 | LOG_NODE | LOG_DISCOVERY, |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 18204 | "2016 rpi %x not inuse\n", |
| 18205 | rpi); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18206 | } |
| 18207 | } |
| 18208 | |
| 18209 | /** |
| 18210 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18211 | * @phba: pointer to lpfc hba data structure. |
| 18212 | * |
| 18213 | * This routine is invoked to release an rpi to the pool of |
| 18214 | * available rpis maintained by the driver. |
| 18215 | **/ |
| 18216 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18217 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18218 | { |
| 18219 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18220 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18221 | spin_unlock_irq(&phba->hbalock); |
| 18222 | } |
| 18223 | |
| 18224 | /** |
| 18225 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 18226 | * @phba: pointer to lpfc hba data structure. |
| 18227 | * |
| 18228 | * This routine is invoked to remove the memory region that |
| 18229 | * provided rpi via a bitmask. |
| 18230 | **/ |
| 18231 | void |
| 18232 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 18233 | { |
| 18234 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18235 | kfree(phba->sli4_hba.rpi_ids); |
| 18236 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18237 | } |
| 18238 | |
| 18239 | /** |
| 18240 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 18241 | * @phba: pointer to lpfc hba data structure. |
| 18242 | * |
| 18243 | * This routine is invoked to remove the memory region that |
| 18244 | * provided rpi via a bitmask. |
| 18245 | **/ |
| 18246 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18247 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 18248 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18249 | { |
| 18250 | LPFC_MBOXQ_t *mboxq; |
| 18251 | struct lpfc_hba *phba = ndlp->phba; |
| 18252 | int rc; |
| 18253 | |
| 18254 | /* The port is notified of the header region via a mailbox command. */ |
| 18255 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18256 | if (!mboxq) |
| 18257 | return -ENOMEM; |
| 18258 | |
| 18259 | /* Post all rpi memory regions to the port. */ |
| 18260 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18261 | if (cmpl) { |
| 18262 | mboxq->mbox_cmpl = cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 18263 | mboxq->ctx_buf = arg; |
| 18264 | mboxq->ctx_ndlp = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 18265 | } else |
| 18266 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18267 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18268 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18269 | if (rc == MBX_NOT_FINISHED) { |
| 18270 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18271 | "2010 Resume RPI Mailbox failed " |
| 18272 | "status %d, mbxStatus x%x\n", rc, |
| 18273 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 18274 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18275 | return -EIO; |
| 18276 | } |
| 18277 | return 0; |
| 18278 | } |
| 18279 | |
| 18280 | /** |
| 18281 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18282 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18283 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18284 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18285 | * |
| 18286 | * Returns: |
| 18287 | * 0 success |
| 18288 | * -Evalue otherwise |
| 18289 | **/ |
| 18290 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18291 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18292 | { |
| 18293 | LPFC_MBOXQ_t *mboxq; |
| 18294 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18295 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18296 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18297 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18298 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18299 | if (!mboxq) |
| 18300 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18301 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18302 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18303 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18304 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18305 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18306 | "2022 INIT VPI Mailbox failed " |
| 18307 | "status %d, mbxStatus x%x\n", rc, |
| 18308 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18309 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18310 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18311 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18312 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18313 | |
| 18314 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18315 | } |
| 18316 | |
| 18317 | /** |
| 18318 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 18319 | * @phba: pointer to lpfc hba data structure. |
| 18320 | * @mboxq: Pointer to mailbox object. |
| 18321 | * |
| 18322 | * This routine is invoked to manually add a single FCF record. The caller |
| 18323 | * must pass a completely initialized FCF_Record. This routine takes |
| 18324 | * care of the nonembedded mailbox operations. |
| 18325 | **/ |
| 18326 | static void |
| 18327 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 18328 | { |
| 18329 | void *virt_addr; |
| 18330 | union lpfc_sli4_cfg_shdr *shdr; |
| 18331 | uint32_t shdr_status, shdr_add_status; |
| 18332 | |
| 18333 | virt_addr = mboxq->sge_array->addr[0]; |
| 18334 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 18335 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 18336 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18337 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18338 | |
| 18339 | if ((shdr_status || shdr_add_status) && |
| 18340 | (shdr_status != STATUS_FCF_IN_USE)) |
| 18341 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18342 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 18343 | "status x%x add_status x%x\n", |
| 18344 | shdr_status, shdr_add_status); |
| 18345 | |
| 18346 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18347 | } |
| 18348 | |
| 18349 | /** |
| 18350 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 18351 | * @phba: pointer to lpfc hba data structure. |
| 18352 | * @fcf_record: pointer to the initialized fcf record to add. |
| 18353 | * |
| 18354 | * This routine is invoked to manually add a single FCF record. The caller |
| 18355 | * must pass a completely initialized FCF_Record. This routine takes |
| 18356 | * care of the nonembedded mailbox operations. |
| 18357 | **/ |
| 18358 | int |
| 18359 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 18360 | { |
| 18361 | int rc = 0; |
| 18362 | LPFC_MBOXQ_t *mboxq; |
| 18363 | uint8_t *bytep; |
| 18364 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18365 | struct lpfc_mbx_sge sge; |
| 18366 | uint32_t alloc_len, req_len; |
| 18367 | uint32_t fcfindex; |
| 18368 | |
| 18369 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18370 | if (!mboxq) { |
| 18371 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18372 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 18373 | return -ENOMEM; |
| 18374 | } |
| 18375 | |
| 18376 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 18377 | sizeof(uint32_t); |
| 18378 | |
| 18379 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 18380 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18381 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 18382 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 18383 | if (alloc_len < req_len) { |
| 18384 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18385 | "2523 Allocated DMA memory size (x%x) is " |
| 18386 | "less than the requested DMA memory " |
| 18387 | "size (x%x)\n", alloc_len, req_len); |
| 18388 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18389 | return -ENOMEM; |
| 18390 | } |
| 18391 | |
| 18392 | /* |
| 18393 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 18394 | * routine only uses a single SGE. |
| 18395 | */ |
| 18396 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18397 | virt_addr = mboxq->sge_array->addr[0]; |
| 18398 | /* |
| 18399 | * Configure the FCF record for FCFI 0. This is the driver's |
| 18400 | * hardcoded default and gets used in nonFIP mode. |
| 18401 | */ |
| 18402 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 18403 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 18404 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 18405 | |
| 18406 | /* |
| 18407 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 18408 | * the FCoE header plus word10. The data copy needs to be endian |
| 18409 | * correct. |
| 18410 | */ |
| 18411 | bytep += sizeof(uint32_t); |
| 18412 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 18413 | mboxq->vport = phba->pport; |
| 18414 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 18415 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18416 | if (rc == MBX_NOT_FINISHED) { |
| 18417 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18418 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 18419 | "status 0x%x\n", rc); |
| 18420 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18421 | rc = -EIO; |
| 18422 | } else |
| 18423 | rc = 0; |
| 18424 | |
| 18425 | return rc; |
| 18426 | } |
| 18427 | |
| 18428 | /** |
| 18429 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 18430 | * @phba: pointer to lpfc hba data structure. |
| 18431 | * @fcf_record: pointer to the fcf record to write the default data. |
| 18432 | * @fcf_index: FCF table entry index. |
| 18433 | * |
| 18434 | * This routine is invoked to build the driver's default FCF record. The |
| 18435 | * values used are hardcoded. This routine handles memory initialization. |
| 18436 | * |
| 18437 | **/ |
| 18438 | void |
| 18439 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 18440 | struct fcf_record *fcf_record, |
| 18441 | uint16_t fcf_index) |
| 18442 | { |
| 18443 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 18444 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 18445 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 18446 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 18447 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 18448 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 18449 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 18450 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 18451 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 18452 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 18453 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 18454 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 18455 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 18456 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 18457 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18458 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 18459 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 18460 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 18461 | /* Set the VLAN bit map */ |
| 18462 | if (phba->valid_vlan) { |
| 18463 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 18464 | = 1 << (phba->vlan_id % 8); |
| 18465 | } |
| 18466 | } |
| 18467 | |
| 18468 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18469 | * 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] | 18470 | * @phba: pointer to lpfc hba data structure. |
| 18471 | * @fcf_index: FCF table entry offset. |
| 18472 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18473 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 18474 | * record and processing it one at a time starting from the @fcf_index |
| 18475 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 18476 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18477 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18478 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18479 | **/ |
| 18480 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18481 | 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] | 18482 | { |
| 18483 | int rc = 0, error; |
| 18484 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18485 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18486 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 18487 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18488 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18489 | if (!mboxq) { |
| 18490 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18491 | "2000 Failed to allocate mbox for " |
| 18492 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18493 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18494 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18495 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18496 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18497 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18498 | if (rc) { |
| 18499 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18500 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18501 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18502 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18503 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18504 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18505 | |
| 18506 | spin_lock_irq(&phba->hbalock); |
| 18507 | phba->hba_flag |= FCF_TS_INPROG; |
| 18508 | spin_unlock_irq(&phba->hbalock); |
| 18509 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18510 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18511 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18512 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18513 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 18514 | /* Reset eligible FCF count for new scan */ |
| 18515 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 18516 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18517 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18518 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18519 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18520 | if (error) { |
| 18521 | if (mboxq) |
| 18522 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18523 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18524 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18525 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18526 | spin_unlock_irq(&phba->hbalock); |
| 18527 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18528 | return error; |
| 18529 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18530 | |
| 18531 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18532 | * 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] | 18533 | * @phba: pointer to lpfc hba data structure. |
| 18534 | * @fcf_index: FCF table entry offset. |
| 18535 | * |
| 18536 | * 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] | 18537 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18538 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18539 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18540 | * otherwise. |
| 18541 | **/ |
| 18542 | int |
| 18543 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18544 | { |
| 18545 | int rc = 0, error; |
| 18546 | LPFC_MBOXQ_t *mboxq; |
| 18547 | |
| 18548 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18549 | if (!mboxq) { |
| 18550 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18551 | "2763 Failed to allocate mbox for " |
| 18552 | "READ_FCF cmd\n"); |
| 18553 | error = -ENOMEM; |
| 18554 | goto fail_fcf_read; |
| 18555 | } |
| 18556 | /* Construct the read FCF record mailbox command */ |
| 18557 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18558 | if (rc) { |
| 18559 | error = -EINVAL; |
| 18560 | goto fail_fcf_read; |
| 18561 | } |
| 18562 | /* Issue the mailbox command asynchronously */ |
| 18563 | mboxq->vport = phba->pport; |
| 18564 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 18565 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18566 | if (rc == MBX_NOT_FINISHED) |
| 18567 | error = -EIO; |
| 18568 | else |
| 18569 | error = 0; |
| 18570 | |
| 18571 | fail_fcf_read: |
| 18572 | if (error && mboxq) |
| 18573 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18574 | return error; |
| 18575 | } |
| 18576 | |
| 18577 | /** |
| 18578 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 18579 | * @phba: pointer to lpfc hba data structure. |
| 18580 | * @fcf_index: FCF table entry offset. |
| 18581 | * |
| 18582 | * 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] | 18583 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18584 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18585 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18586 | * otherwise. |
| 18587 | **/ |
| 18588 | int |
| 18589 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18590 | { |
| 18591 | int rc = 0, error; |
| 18592 | LPFC_MBOXQ_t *mboxq; |
| 18593 | |
| 18594 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18595 | if (!mboxq) { |
| 18596 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18597 | "2758 Failed to allocate mbox for " |
| 18598 | "READ_FCF cmd\n"); |
| 18599 | error = -ENOMEM; |
| 18600 | goto fail_fcf_read; |
| 18601 | } |
| 18602 | /* Construct the read FCF record mailbox command */ |
| 18603 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18604 | if (rc) { |
| 18605 | error = -EINVAL; |
| 18606 | goto fail_fcf_read; |
| 18607 | } |
| 18608 | /* Issue the mailbox command asynchronously */ |
| 18609 | mboxq->vport = phba->pport; |
| 18610 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 18611 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18612 | if (rc == MBX_NOT_FINISHED) |
| 18613 | error = -EIO; |
| 18614 | else |
| 18615 | error = 0; |
| 18616 | |
| 18617 | fail_fcf_read: |
| 18618 | if (error && mboxq) |
| 18619 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18620 | return error; |
| 18621 | } |
| 18622 | |
| 18623 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18624 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18625 | * phba pointer to the lpfc_hba struct for this port. |
| 18626 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 18627 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 18628 | * rr_bmask based on their priority level. Starting from the highest priority |
| 18629 | * to the lowest. The most likely FCF candidate will be in the highest |
| 18630 | * priority group. When this routine is called it searches the fcf_pri list for |
| 18631 | * next lowest priority group and repopulates the rr_bmask with only those |
| 18632 | * fcf_indexes. |
| 18633 | * returns: |
| 18634 | * 1=success 0=failure |
| 18635 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18636 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18637 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 18638 | { |
| 18639 | uint16_t next_fcf_pri; |
| 18640 | uint16_t last_index; |
| 18641 | struct lpfc_fcf_pri *fcf_pri; |
| 18642 | int rc; |
| 18643 | int ret = 0; |
| 18644 | |
| 18645 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 18646 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18647 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 18648 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18649 | |
| 18650 | /* Verify the priority list has 2 or more entries */ |
| 18651 | spin_lock_irq(&phba->hbalock); |
| 18652 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 18653 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 18654 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18655 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 18656 | "3061 Last IDX %d\n", last_index); |
| 18657 | return 0; /* Empty rr list */ |
| 18658 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18659 | spin_unlock_irq(&phba->hbalock); |
| 18660 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18661 | next_fcf_pri = 0; |
| 18662 | /* |
| 18663 | * Clear the rr_bmask and set all of the bits that are at this |
| 18664 | * priority. |
| 18665 | */ |
| 18666 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 18667 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 18668 | spin_lock_irq(&phba->hbalock); |
| 18669 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18670 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 18671 | continue; |
| 18672 | /* |
| 18673 | * the 1st priority that has not FLOGI failed |
| 18674 | * will be the highest. |
| 18675 | */ |
| 18676 | if (!next_fcf_pri) |
| 18677 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18678 | spin_unlock_irq(&phba->hbalock); |
| 18679 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18680 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18681 | fcf_pri->fcf_rec.fcf_index); |
| 18682 | if (rc) |
| 18683 | return 0; |
| 18684 | } |
| 18685 | spin_lock_irq(&phba->hbalock); |
| 18686 | } |
| 18687 | /* |
| 18688 | * if next_fcf_pri was not set above and the list is not empty then |
| 18689 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 18690 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18691 | */ |
| 18692 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 18693 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18694 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 18695 | /* |
| 18696 | * the 1st priority that has not FLOGI failed |
| 18697 | * will be the highest. |
| 18698 | */ |
| 18699 | if (!next_fcf_pri) |
| 18700 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18701 | spin_unlock_irq(&phba->hbalock); |
| 18702 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18703 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18704 | fcf_pri->fcf_rec.fcf_index); |
| 18705 | if (rc) |
| 18706 | return 0; |
| 18707 | } |
| 18708 | spin_lock_irq(&phba->hbalock); |
| 18709 | } |
| 18710 | } else |
| 18711 | ret = 1; |
| 18712 | spin_unlock_irq(&phba->hbalock); |
| 18713 | |
| 18714 | return ret; |
| 18715 | } |
| 18716 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18717 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 18718 | * @phba: pointer to lpfc hba data structure. |
| 18719 | * |
| 18720 | * This routine is to get the next eligible FCF record index in a round |
| 18721 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18722 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18723 | * shall be returned, otherwise, the next eligible FCF record's index |
| 18724 | * shall be returned. |
| 18725 | **/ |
| 18726 | uint16_t |
| 18727 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 18728 | { |
| 18729 | uint16_t next_fcf_index; |
| 18730 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18731 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18732 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18733 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 18734 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18735 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18736 | /* Determine the next fcf index to check */ |
| 18737 | 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] | 18738 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18739 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18740 | next_fcf_index); |
| 18741 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18742 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18743 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18744 | /* |
| 18745 | * If we have wrapped then we need to clear the bits that |
| 18746 | * have been tested so that we can detect when we should |
| 18747 | * change the priority level. |
| 18748 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18749 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18750 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18751 | } |
| 18752 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18753 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18754 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18755 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 18756 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 18757 | /* |
| 18758 | * If next fcf index is not found check if there are lower |
| 18759 | * Priority level fcf's in the fcf_priority list. |
| 18760 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 18761 | * at that level and continue the selection process. |
| 18762 | */ |
| 18763 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18764 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18765 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 18766 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 18767 | |
| 18768 | return LPFC_FCOE_FCF_NEXT_NONE; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18769 | } |
| 18770 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18771 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 18772 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18773 | LPFC_FCF_FLOGI_FAILED) { |
| 18774 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 18775 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 18776 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18777 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18778 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18779 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18780 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18781 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 18782 | next_fcf_index); |
| 18783 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18784 | return next_fcf_index; |
| 18785 | } |
| 18786 | |
| 18787 | /** |
| 18788 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 18789 | * @phba: pointer to lpfc hba data structure. |
| 18790 | * |
| 18791 | * 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] | 18792 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18793 | * does not go beyond the range of the driver allocated bmask dimension |
| 18794 | * before setting the bit. |
| 18795 | * |
| 18796 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 18797 | * -EINVAL. |
| 18798 | **/ |
| 18799 | int |
| 18800 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18801 | { |
| 18802 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18803 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18804 | "2610 FCF (x%x) reached driver's book " |
| 18805 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18806 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18807 | return -EINVAL; |
| 18808 | } |
| 18809 | /* Set the eligible FCF record index bmask */ |
| 18810 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 18811 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18812 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18813 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18814 | "bmask\n", fcf_index); |
| 18815 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18816 | return 0; |
| 18817 | } |
| 18818 | |
| 18819 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18820 | * 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] | 18821 | * @phba: pointer to lpfc hba data structure. |
| 18822 | * |
| 18823 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18824 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18825 | * does not go beyond the range of the driver allocated bmask dimension |
| 18826 | * before clearing the bit. |
| 18827 | **/ |
| 18828 | void |
| 18829 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18830 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18831 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18832 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18833 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18834 | "2762 FCF (x%x) reached driver's book " |
| 18835 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18836 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18837 | return; |
| 18838 | } |
| 18839 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18840 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18841 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 18842 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18843 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 18844 | list_del_init(&fcf_pri->list); |
| 18845 | break; |
| 18846 | } |
| 18847 | } |
| 18848 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18849 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18850 | |
| 18851 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18852 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18853 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18854 | } |
| 18855 | |
| 18856 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18857 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 18858 | * @phba: pointer to lpfc hba data structure. |
| 18859 | * |
| 18860 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 18861 | * command. If the mailbox command returned failure, it will try to stop the |
| 18862 | * FCF rediscover wait timer. |
| 18863 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18864 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18865 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 18866 | { |
| 18867 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18868 | uint32_t shdr_status, shdr_add_status; |
| 18869 | |
| 18870 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18871 | |
| 18872 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 18873 | &redisc_fcf->header.cfg_shdr.response); |
| 18874 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 18875 | &redisc_fcf->header.cfg_shdr.response); |
| 18876 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18877 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18878 | "2746 Requesting for FCF rediscovery failed " |
| 18879 | "status x%x add_status x%x\n", |
| 18880 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18881 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18882 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18883 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18884 | spin_unlock_irq(&phba->hbalock); |
| 18885 | /* |
| 18886 | * CVL event triggered FCF rediscover request failed, |
| 18887 | * last resort to re-try current registered FCF entry. |
| 18888 | */ |
| 18889 | lpfc_retry_pport_discovery(phba); |
| 18890 | } else { |
| 18891 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18892 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18893 | spin_unlock_irq(&phba->hbalock); |
| 18894 | /* |
| 18895 | * DEAD FCF event triggered FCF rediscover request |
| 18896 | * failed, last resort to fail over as a link down |
| 18897 | * to FCF registration. |
| 18898 | */ |
| 18899 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 18900 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18901 | } else { |
| 18902 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18903 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18904 | /* |
| 18905 | * Start FCF rediscovery wait timer for pending FCF |
| 18906 | * before rescan FCF record table. |
| 18907 | */ |
| 18908 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18909 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18910 | |
| 18911 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18912 | } |
| 18913 | |
| 18914 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18915 | * 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] | 18916 | * @phba: pointer to lpfc hba data structure. |
| 18917 | * |
| 18918 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 18919 | * by the port. |
| 18920 | **/ |
| 18921 | int |
| 18922 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 18923 | { |
| 18924 | LPFC_MBOXQ_t *mbox; |
| 18925 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18926 | int rc, length; |
| 18927 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18928 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 18929 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 18930 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18931 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18932 | if (!mbox) { |
| 18933 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18934 | "2745 Failed to allocate mbox for " |
| 18935 | "requesting FCF rediscover.\n"); |
| 18936 | return -ENOMEM; |
| 18937 | } |
| 18938 | |
| 18939 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 18940 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 18941 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18942 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 18943 | length, LPFC_SLI4_MBX_EMBED); |
| 18944 | |
| 18945 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18946 | /* Set count to 0 for invalidating the entire FCF database */ |
| 18947 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 18948 | |
| 18949 | /* Issue the mailbox command asynchronously */ |
| 18950 | mbox->vport = phba->pport; |
| 18951 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 18952 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 18953 | |
| 18954 | if (rc == MBX_NOT_FINISHED) { |
| 18955 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18956 | return -EIO; |
| 18957 | } |
| 18958 | return 0; |
| 18959 | } |
| 18960 | |
| 18961 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18962 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 18963 | * @phba: pointer to lpfc hba data structure. |
| 18964 | * |
| 18965 | * This function is the failover routine as a last resort to the FCF DEAD |
| 18966 | * event when driver failed to perform fast FCF failover. |
| 18967 | **/ |
| 18968 | void |
| 18969 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 18970 | { |
| 18971 | uint32_t link_state; |
| 18972 | |
| 18973 | /* |
| 18974 | * Last resort as FCF DEAD event failover will treat this as |
| 18975 | * a link down, but save the link state because we don't want |
| 18976 | * it to be changed to Link Down unless it is already down. |
| 18977 | */ |
| 18978 | link_state = phba->link_state; |
| 18979 | lpfc_linkdown(phba); |
| 18980 | phba->link_state = link_state; |
| 18981 | |
| 18982 | /* Unregister FCF if no devices connected to it */ |
| 18983 | lpfc_unregister_unused_fcf(phba); |
| 18984 | } |
| 18985 | |
| 18986 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18987 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18988 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18989 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18990 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18991 | * This function gets SLI3 port configure region 23 data through memory dump |
| 18992 | * mailbox command. When it successfully retrieves data, the size of the data |
| 18993 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18994 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18995 | static uint32_t |
| 18996 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18997 | { |
| 18998 | LPFC_MBOXQ_t *pmb = NULL; |
| 18999 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19000 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19001 | int rc; |
| 19002 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19003 | if (!rgn23_data) |
| 19004 | return 0; |
| 19005 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19006 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19007 | if (!pmb) { |
| 19008 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19009 | "2600 failed to allocate mailbox memory\n"); |
| 19010 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19011 | } |
| 19012 | mb = &pmb->u.mb; |
| 19013 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19014 | do { |
| 19015 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 19016 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 19017 | |
| 19018 | if (rc != MBX_SUCCESS) { |
| 19019 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19020 | "2601 failed to read config " |
| 19021 | "region 23, rc 0x%x Status 0x%x\n", |
| 19022 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19023 | mb->un.varDmp.word_cnt = 0; |
| 19024 | } |
| 19025 | /* |
| 19026 | * dump mem may return a zero when finished or we got a |
| 19027 | * mailbox error, either way we are done. |
| 19028 | */ |
| 19029 | if (mb->un.varDmp.word_cnt == 0) |
| 19030 | break; |
| 19031 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 19032 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 19033 | |
| 19034 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19035 | rgn23_data + offset, |
| 19036 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19037 | offset += mb->un.varDmp.word_cnt; |
| 19038 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 19039 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19040 | mempool_free(pmb, phba->mbox_mem_pool); |
| 19041 | return offset; |
| 19042 | } |
| 19043 | |
| 19044 | /** |
| 19045 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 19046 | * @phba: pointer to lpfc hba data structure. |
| 19047 | * @rgn23_data: pointer to configure region 23 data. |
| 19048 | * |
| 19049 | * This function gets SLI4 port configure region 23 data through memory dump |
| 19050 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19051 | * will be returned, otherwise, 0 will be returned. |
| 19052 | **/ |
| 19053 | static uint32_t |
| 19054 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 19055 | { |
| 19056 | LPFC_MBOXQ_t *mboxq = NULL; |
| 19057 | struct lpfc_dmabuf *mp = NULL; |
| 19058 | struct lpfc_mqe *mqe; |
| 19059 | uint32_t data_length = 0; |
| 19060 | int rc; |
| 19061 | |
| 19062 | if (!rgn23_data) |
| 19063 | return 0; |
| 19064 | |
| 19065 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19066 | if (!mboxq) { |
| 19067 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19068 | "3105 failed to allocate mailbox memory\n"); |
| 19069 | return 0; |
| 19070 | } |
| 19071 | |
| 19072 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 19073 | goto out; |
| 19074 | mqe = &mboxq->u.mqe; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19075 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19076 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 19077 | if (rc) |
| 19078 | goto out; |
| 19079 | data_length = mqe->un.mb_words[5]; |
| 19080 | if (data_length == 0) |
| 19081 | goto out; |
| 19082 | if (data_length > DMP_RGN23_SIZE) { |
| 19083 | data_length = 0; |
| 19084 | goto out; |
| 19085 | } |
| 19086 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 19087 | out: |
| 19088 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 19089 | if (mp) { |
| 19090 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19091 | kfree(mp); |
| 19092 | } |
| 19093 | return data_length; |
| 19094 | } |
| 19095 | |
| 19096 | /** |
| 19097 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 19098 | * @phba: pointer to lpfc hba data structure. |
| 19099 | * |
| 19100 | * This function read region 23 and parse TLV for port status to |
| 19101 | * decide if the user disaled the port. If the TLV indicates the |
| 19102 | * port is disabled, the hba_flag is set accordingly. |
| 19103 | **/ |
| 19104 | void |
| 19105 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 19106 | { |
| 19107 | uint8_t *rgn23_data = NULL; |
| 19108 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 19109 | uint32_t offset = 0; |
| 19110 | |
| 19111 | /* Get adapter Region 23 data */ |
| 19112 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 19113 | if (!rgn23_data) |
| 19114 | goto out; |
| 19115 | |
| 19116 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 19117 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 19118 | else { |
| 19119 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 19120 | &phba->sli4_hba.sli_intf); |
| 19121 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 19122 | goto out; |
| 19123 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 19124 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19125 | |
| 19126 | if (!data_size) |
| 19127 | goto out; |
| 19128 | |
| 19129 | /* Check the region signature first */ |
| 19130 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 19131 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19132 | "2619 Config region 23 has bad signature\n"); |
| 19133 | goto out; |
| 19134 | } |
| 19135 | offset += 4; |
| 19136 | |
| 19137 | /* Check the data structure version */ |
| 19138 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 19139 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19140 | "2620 Config region 23 has bad version\n"); |
| 19141 | goto out; |
| 19142 | } |
| 19143 | offset += 4; |
| 19144 | |
| 19145 | /* Parse TLV entries in the region */ |
| 19146 | while (offset < data_size) { |
| 19147 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 19148 | break; |
| 19149 | /* |
| 19150 | * If the TLV is not driver specific TLV or driver id is |
| 19151 | * not linux driver id, skip the record. |
| 19152 | */ |
| 19153 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 19154 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 19155 | (rgn23_data[offset + 3] != 0)) { |
| 19156 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19157 | continue; |
| 19158 | } |
| 19159 | |
| 19160 | /* Driver found a driver specific TLV in the config region */ |
| 19161 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 19162 | offset += 4; |
| 19163 | tlv_offset = 0; |
| 19164 | |
| 19165 | /* |
| 19166 | * Search for configured port state sub-TLV. |
| 19167 | */ |
| 19168 | while ((offset < data_size) && |
| 19169 | (tlv_offset < sub_tlv_len)) { |
| 19170 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 19171 | offset += 4; |
| 19172 | tlv_offset += 4; |
| 19173 | break; |
| 19174 | } |
| 19175 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 19176 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19177 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 19178 | continue; |
| 19179 | } |
| 19180 | |
| 19181 | /* This HBA contains PORT_STE configured */ |
| 19182 | if (!rgn23_data[offset + 2]) |
| 19183 | phba->hba_flag |= LINK_DISABLED; |
| 19184 | |
| 19185 | goto out; |
| 19186 | } |
| 19187 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19188 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19189 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19190 | kfree(rgn23_data); |
| 19191 | return; |
| 19192 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19193 | |
| 19194 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19195 | * lpfc_wr_object - write an object to the firmware |
| 19196 | * @phba: HBA structure that indicates port to create a queue on. |
| 19197 | * @dmabuf_list: list of dmabufs to write to the port. |
| 19198 | * @size: the total byte value of the objects to write to the port. |
| 19199 | * @offset: the current offset to be used to start the transfer. |
| 19200 | * |
| 19201 | * This routine will create a wr_object mailbox command to send to the port. |
| 19202 | * the mailbox command will be constructed using the dma buffers described in |
| 19203 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 19204 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 19205 | * used to indicate the starting offset of the transfer and will also return |
| 19206 | * the offset after the write object mailbox has completed. @size is used to |
| 19207 | * determine the end of the object and whether the eof bit should be set. |
| 19208 | * |
| 19209 | * Return 0 is successful and offset will contain the the new offset to use |
| 19210 | * for the next write. |
| 19211 | * Return negative value for error cases. |
| 19212 | **/ |
| 19213 | int |
| 19214 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 19215 | uint32_t size, uint32_t *offset) |
| 19216 | { |
| 19217 | struct lpfc_mbx_wr_object *wr_object; |
| 19218 | LPFC_MBOXQ_t *mbox; |
| 19219 | int rc = 0, i = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19220 | uint32_t shdr_status, shdr_add_status, shdr_change_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19221 | uint32_t mbox_tmo; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19222 | struct lpfc_dmabuf *dmabuf; |
| 19223 | uint32_t written = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19224 | bool check_change_status = false; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19225 | |
| 19226 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19227 | if (!mbox) |
| 19228 | return -ENOMEM; |
| 19229 | |
| 19230 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 19231 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 19232 | sizeof(struct lpfc_mbx_wr_object) - |
| 19233 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 19234 | |
| 19235 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 19236 | wr_object->u.request.write_offset = *offset; |
| 19237 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 19238 | wr_object->u.request.object_name[0] = |
| 19239 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 19240 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 19241 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 19242 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 19243 | break; |
| 19244 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 19245 | wr_object->u.request.bde[i].addrHigh = |
| 19246 | putPaddrHigh(dmabuf->phys); |
| 19247 | if (written + SLI4_PAGE_SIZE >= size) { |
| 19248 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19249 | (size - written); |
| 19250 | written += (size - written); |
| 19251 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19252 | bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1); |
| 19253 | check_change_status = true; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19254 | } else { |
| 19255 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19256 | SLI4_PAGE_SIZE; |
| 19257 | written += SLI4_PAGE_SIZE; |
| 19258 | } |
| 19259 | i++; |
| 19260 | } |
| 19261 | wr_object->u.request.bde_count = i; |
| 19262 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 19263 | if (!phba->sli4_hba.intr_enable) |
| 19264 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 19265 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 19266 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19267 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 19268 | } |
| 19269 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19270 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 19271 | &wr_object->header.cfg_shdr.response); |
| 19272 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 19273 | &wr_object->header.cfg_shdr.response); |
| 19274 | if (check_change_status) { |
| 19275 | shdr_change_status = bf_get(lpfc_wr_object_change_status, |
| 19276 | &wr_object->u.response); |
| 19277 | switch (shdr_change_status) { |
| 19278 | case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET): |
| 19279 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19280 | "3198 Firmware write complete: System " |
| 19281 | "reboot required to instantiate\n"); |
| 19282 | break; |
| 19283 | case (LPFC_CHANGE_STATUS_FW_RESET): |
| 19284 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19285 | "3199 Firmware write complete: Firmware" |
| 19286 | " reset required to instantiate\n"); |
| 19287 | break; |
| 19288 | case (LPFC_CHANGE_STATUS_PORT_MIGRATION): |
| 19289 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19290 | "3200 Firmware write complete: Port " |
| 19291 | "Migration or PCI Reset required to " |
| 19292 | "instantiate\n"); |
| 19293 | break; |
| 19294 | case (LPFC_CHANGE_STATUS_PCI_RESET): |
| 19295 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19296 | "3201 Firmware write complete: PCI " |
| 19297 | "Reset required to instantiate\n"); |
| 19298 | break; |
| 19299 | default: |
| 19300 | break; |
| 19301 | } |
| 19302 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19303 | if (rc != MBX_TIMEOUT) |
| 19304 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19305 | if (shdr_status || shdr_add_status || rc) { |
| 19306 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19307 | "3025 Write Object mailbox failed with " |
| 19308 | "status x%x add_status x%x, mbx status x%x\n", |
| 19309 | shdr_status, shdr_add_status, rc); |
| 19310 | rc = -ENXIO; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 19311 | *offset = shdr_add_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19312 | } else |
| 19313 | *offset += wr_object->u.response.actual_write_length; |
| 19314 | return rc; |
| 19315 | } |
| 19316 | |
| 19317 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19318 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 19319 | * @vport: pointer to vport data structure. |
| 19320 | * |
| 19321 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 19322 | * and REG_VPI mailbox commands associated with the vport. This function |
| 19323 | * is called when driver want to restart discovery of the vport due to |
| 19324 | * a Clear Virtual Link event. |
| 19325 | **/ |
| 19326 | void |
| 19327 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 19328 | { |
| 19329 | struct lpfc_hba *phba = vport->phba; |
| 19330 | LPFC_MBOXQ_t *mb, *nextmb; |
| 19331 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19332 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19333 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19334 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19335 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19336 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19337 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19338 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19339 | spin_lock_irq(&phba->hbalock); |
| 19340 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 19341 | if (mb->vport != vport) |
| 19342 | continue; |
| 19343 | |
| 19344 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19345 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19346 | continue; |
| 19347 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19348 | list_del(&mb->list); |
| 19349 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 19350 | } |
| 19351 | /* Clean up active mailbox command with the vport */ |
| 19352 | mb = phba->sli.mbox_active; |
| 19353 | if (mb && (mb->vport == vport)) { |
| 19354 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 19355 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 19356 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19357 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19358 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19359 | /* Put reference count for delayed processing */ |
| 19360 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 19361 | /* Unregister the RPI when mailbox complete */ |
| 19362 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19363 | } |
| 19364 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19365 | /* Cleanup any mailbox completions which are not yet processed */ |
| 19366 | do { |
| 19367 | restart_loop = 0; |
| 19368 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 19369 | /* |
| 19370 | * If this mailox is already processed or it is |
| 19371 | * for another vport ignore it. |
| 19372 | */ |
| 19373 | if ((mb->vport != vport) || |
| 19374 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 19375 | continue; |
| 19376 | |
| 19377 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19378 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19379 | continue; |
| 19380 | |
| 19381 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19382 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19383 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19384 | /* Unregister the RPI when mailbox complete */ |
| 19385 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19386 | restart_loop = 1; |
| 19387 | spin_unlock_irq(&phba->hbalock); |
| 19388 | spin_lock(shost->host_lock); |
| 19389 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19390 | spin_unlock(shost->host_lock); |
| 19391 | spin_lock_irq(&phba->hbalock); |
| 19392 | break; |
| 19393 | } |
| 19394 | } |
| 19395 | } while (restart_loop); |
| 19396 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19397 | spin_unlock_irq(&phba->hbalock); |
| 19398 | |
| 19399 | /* Release the cleaned-up mailbox commands */ |
| 19400 | while (!list_empty(&mbox_cmd_list)) { |
| 19401 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19402 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19403 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19404 | if (mp) { |
| 19405 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19406 | kfree(mp); |
| 19407 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19408 | mb->ctx_buf = NULL; |
| 19409 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
| 19410 | mb->ctx_ndlp = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19411 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19412 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19413 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19414 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19415 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19416 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19417 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19418 | mempool_free(mb, phba->mbox_mem_pool); |
| 19419 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19420 | |
| 19421 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 19422 | if (act_mbx_ndlp) { |
| 19423 | spin_lock(shost->host_lock); |
| 19424 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19425 | spin_unlock(shost->host_lock); |
| 19426 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19427 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19428 | } |
| 19429 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19430 | /** |
| 19431 | * lpfc_drain_txq - Drain the txq |
| 19432 | * @phba: Pointer to HBA context object. |
| 19433 | * |
| 19434 | * This function attempt to submit IOCBs on the txq |
| 19435 | * to the adapter. For SLI4 adapters, the txq contains |
| 19436 | * ELS IOCBs that have been deferred because the there |
| 19437 | * are no SGLs. This congestion can occur with large |
| 19438 | * vport counts during node discovery. |
| 19439 | **/ |
| 19440 | |
| 19441 | uint32_t |
| 19442 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 19443 | { |
| 19444 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19445 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 19446 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19447 | unsigned long iflags = 0; |
| 19448 | char *fail_msg = NULL; |
| 19449 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19450 | union lpfc_wqe128 wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 19451 | uint32_t txq_cnt = 0; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19452 | struct lpfc_queue *wq; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19453 | |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19454 | if (phba->link_flag & LS_MDS_LOOPBACK) { |
| 19455 | /* MDS WQE are posted only to first WQ*/ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19456 | wq = phba->sli4_hba.hdwq[0].io_wq; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19457 | if (unlikely(!wq)) |
| 19458 | return 0; |
| 19459 | pring = wq->pring; |
| 19460 | } else { |
| 19461 | wq = phba->sli4_hba.els_wq; |
| 19462 | if (unlikely(!wq)) |
| 19463 | return 0; |
| 19464 | pring = lpfc_phba_elsring(phba); |
| 19465 | } |
| 19466 | |
| 19467 | if (unlikely(!pring) || list_empty(&pring->txq)) |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 19468 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19469 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19470 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19471 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 19472 | txq_cnt++; |
| 19473 | } |
| 19474 | |
| 19475 | if (txq_cnt > pring->txq_max) |
| 19476 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19477 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19478 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19479 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19480 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19481 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19482 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19483 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19484 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19485 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19486 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19487 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19488 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19489 | break; |
| 19490 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19491 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19492 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19493 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19494 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19495 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19496 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19497 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19498 | |
| 19499 | /* The xri and iocb resources secured, |
| 19500 | * attempt to issue request |
| 19501 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19502 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19503 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 19504 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 19505 | fail_msg = "to convert bpl to sgl"; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19506 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19507 | fail_msg = "to convert iocb to wqe"; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19508 | else if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19509 | fail_msg = " - Wq is full"; |
| 19510 | else |
| 19511 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 19512 | |
| 19513 | if (fail_msg) { |
| 19514 | /* Failed means we can't issue and need to cancel */ |
| 19515 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19516 | "2822 IOCB failed %s iotag 0x%x " |
| 19517 | "xri 0x%x\n", |
| 19518 | fail_msg, |
| 19519 | piocbq->iotag, piocbq->sli4_xritag); |
| 19520 | list_add_tail(&piocbq->list, &completions); |
| 19521 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19522 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19523 | } |
| 19524 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19525 | /* Cancel all the IOCBs that cannot be issued */ |
| 19526 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 19527 | IOERR_SLI_ABORTED); |
| 19528 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19529 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19530 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19531 | |
| 19532 | /** |
| 19533 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 19534 | * @phba: Pointer to HBA context object. |
| 19535 | * @pwqe: Pointer to command WQE. |
| 19536 | * @sglq: Pointer to the scatter gather queue object. |
| 19537 | * |
| 19538 | * This routine converts the bpl or bde that is in the WQE |
| 19539 | * to a sgl list for the sli4 hardware. The physical address |
| 19540 | * of the bpl/bde is converted back to a virtual address. |
| 19541 | * If the WQE contains a BPL then the list of BDE's is |
| 19542 | * converted to sli4_sge's. If the WQE contains a single |
| 19543 | * BDE then it is converted to a single sli_sge. |
| 19544 | * The WQE is still in cpu endianness so the contents of |
| 19545 | * the bpl can be used without byte swapping. |
| 19546 | * |
| 19547 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 19548 | */ |
| 19549 | static uint16_t |
| 19550 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 19551 | struct lpfc_sglq *sglq) |
| 19552 | { |
| 19553 | uint16_t xritag = NO_XRI; |
| 19554 | struct ulp_bde64 *bpl = NULL; |
| 19555 | struct ulp_bde64 bde; |
| 19556 | struct sli4_sge *sgl = NULL; |
| 19557 | struct lpfc_dmabuf *dmabuf; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19558 | union lpfc_wqe128 *wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19559 | int numBdes = 0; |
| 19560 | int i = 0; |
| 19561 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 19562 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 19563 | uint32_t cmd; |
| 19564 | |
| 19565 | if (!pwqeq || !sglq) |
| 19566 | return xritag; |
| 19567 | |
| 19568 | sgl = (struct sli4_sge *)sglq->sgl; |
| 19569 | wqe = &pwqeq->wqe; |
| 19570 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 19571 | |
| 19572 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 19573 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 19574 | return sglq->sli4_xritag; |
| 19575 | numBdes = pwqeq->rsvd2; |
| 19576 | if (numBdes) { |
| 19577 | /* The addrHigh and addrLow fields within the WQE |
| 19578 | * have not been byteswapped yet so there is no |
| 19579 | * need to swap them back. |
| 19580 | */ |
| 19581 | if (pwqeq->context3) |
| 19582 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 19583 | else |
| 19584 | return xritag; |
| 19585 | |
| 19586 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 19587 | if (!bpl) |
| 19588 | return xritag; |
| 19589 | |
| 19590 | for (i = 0; i < numBdes; i++) { |
| 19591 | /* Should already be byte swapped. */ |
| 19592 | sgl->addr_hi = bpl->addrHigh; |
| 19593 | sgl->addr_lo = bpl->addrLow; |
| 19594 | |
| 19595 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19596 | if ((i+1) == numBdes) |
| 19597 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19598 | else |
| 19599 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 19600 | /* swap the size field back to the cpu so we |
| 19601 | * can assign it to the sgl. |
| 19602 | */ |
| 19603 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 19604 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 19605 | /* The offsets in the sgl need to be accumulated |
| 19606 | * separately for the request and reply lists. |
| 19607 | * The request is always first, the reply follows. |
| 19608 | */ |
| 19609 | switch (cmd) { |
| 19610 | case CMD_GEN_REQUEST64_WQE: |
| 19611 | /* add up the reply sg entries */ |
| 19612 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 19613 | inbound++; |
| 19614 | /* first inbound? reset the offset */ |
| 19615 | if (inbound == 1) |
| 19616 | offset = 0; |
| 19617 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19618 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19619 | LPFC_SGE_TYPE_DATA); |
| 19620 | offset += bde.tus.f.bdeSize; |
| 19621 | break; |
| 19622 | case CMD_FCP_TRSP64_WQE: |
| 19623 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 19624 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19625 | LPFC_SGE_TYPE_DATA); |
| 19626 | break; |
| 19627 | case CMD_FCP_TSEND64_WQE: |
| 19628 | case CMD_FCP_TRECEIVE64_WQE: |
| 19629 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19630 | bpl->tus.f.bdeFlags); |
| 19631 | if (i < 3) |
| 19632 | offset = 0; |
| 19633 | else |
| 19634 | offset += bde.tus.f.bdeSize; |
| 19635 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19636 | break; |
| 19637 | } |
| 19638 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19639 | bpl++; |
| 19640 | sgl++; |
| 19641 | } |
| 19642 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 19643 | /* The addrHigh and addrLow fields of the BDE have not |
| 19644 | * been byteswapped yet so they need to be swapped |
| 19645 | * before putting them in the sgl. |
| 19646 | */ |
| 19647 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 19648 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 19649 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19650 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19651 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19652 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 19653 | } |
| 19654 | return sglq->sli4_xritag; |
| 19655 | } |
| 19656 | |
| 19657 | /** |
| 19658 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 19659 | * @phba: Pointer to HBA context object. |
| 19660 | * @ring_number: Base sli ring number |
| 19661 | * @pwqe: Pointer to command WQE. |
| 19662 | **/ |
| 19663 | int |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19664 | lpfc_sli4_issue_wqe(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19665 | struct lpfc_iocbq *pwqe) |
| 19666 | { |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19667 | union lpfc_wqe128 *wqe = &pwqe->wqe; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19668 | struct lpfc_nvmet_rcv_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19669 | struct lpfc_queue *wq; |
| 19670 | struct lpfc_sglq *sglq; |
| 19671 | struct lpfc_sli_ring *pring; |
| 19672 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19673 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19674 | |
| 19675 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 19676 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 19677 | pring = phba->sli4_hba.nvmels_wq->pring; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19678 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19679 | qp, wq_access); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19680 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 19681 | if (!sglq) { |
| 19682 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19683 | return WQE_BUSY; |
| 19684 | } |
| 19685 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19686 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19687 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 19688 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19689 | return WQE_ERROR; |
| 19690 | } |
| 19691 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19692 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19693 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 19694 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19695 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19696 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19697 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19698 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19699 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19700 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19701 | return 0; |
| 19702 | } |
| 19703 | |
| 19704 | /* NVME_FCREQ and NVME_ABTS requests */ |
| 19705 | if (pwqe->iocb_flag & LPFC_IO_NVME) { |
| 19706 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19707 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19708 | pring = wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19709 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19710 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19711 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19712 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19713 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19714 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19715 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19716 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19717 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19718 | } |
| 19719 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19720 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19721 | return 0; |
| 19722 | } |
| 19723 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19724 | /* NVMET requests */ |
| 19725 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 19726 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19727 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19728 | pring = wq->pring; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19729 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19730 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 19731 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19732 | if (pwqe->sli4_xritag == NO_XRI) { |
| 19733 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19734 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19735 | } |
| 19736 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19737 | pwqe->sli4_xritag); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19738 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19739 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19740 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19741 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19742 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19743 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19744 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19745 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19746 | } |
| 19747 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19748 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19749 | return 0; |
| 19750 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19751 | return WQE_ERROR; |
| 19752 | } |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19753 | |
| 19754 | #ifdef LPFC_MXP_STAT |
| 19755 | /** |
| 19756 | * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count |
| 19757 | * @phba: pointer to lpfc hba data structure. |
| 19758 | * @hwqid: belong to which HWQ. |
| 19759 | * |
| 19760 | * The purpose of this routine is to take a snapshot of pbl, pvt and busy count |
| 19761 | * 15 seconds after a test case is running. |
| 19762 | * |
| 19763 | * The user should call lpfc_debugfs_multixripools_write before running a test |
| 19764 | * case to clear stat_snapshot_taken. Then the user starts a test case. During |
| 19765 | * test case is running, stat_snapshot_taken is incremented by 1 every time when |
| 19766 | * this routine is called from heartbeat timer. When stat_snapshot_taken is |
| 19767 | * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken. |
| 19768 | **/ |
| 19769 | void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid) |
| 19770 | { |
| 19771 | struct lpfc_sli4_hdw_queue *qp; |
| 19772 | struct lpfc_multixri_pool *multixri_pool; |
| 19773 | struct lpfc_pvt_pool *pvt_pool; |
| 19774 | struct lpfc_pbl_pool *pbl_pool; |
| 19775 | u32 txcmplq_cnt; |
| 19776 | |
| 19777 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 19778 | multixri_pool = qp->p_multixri_pool; |
| 19779 | if (!multixri_pool) |
| 19780 | return; |
| 19781 | |
| 19782 | if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) { |
| 19783 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 19784 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19785 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19786 | |
| 19787 | multixri_pool->stat_pbl_count = pbl_pool->count; |
| 19788 | multixri_pool->stat_pvt_count = pvt_pool->count; |
| 19789 | multixri_pool->stat_busy_count = txcmplq_cnt; |
| 19790 | } |
| 19791 | |
| 19792 | multixri_pool->stat_snapshot_taken++; |
| 19793 | } |
| 19794 | #endif |
| 19795 | |
| 19796 | /** |
| 19797 | * lpfc_adjust_pvt_pool_count - Adjust private pool count |
| 19798 | * @phba: pointer to lpfc hba data structure. |
| 19799 | * @hwqid: belong to which HWQ. |
| 19800 | * |
| 19801 | * This routine moves some XRIs from private to public pool when private pool |
| 19802 | * is not busy. |
| 19803 | **/ |
| 19804 | void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid) |
| 19805 | { |
| 19806 | struct lpfc_multixri_pool *multixri_pool; |
| 19807 | u32 io_req_count; |
| 19808 | u32 prev_io_req_count; |
| 19809 | |
| 19810 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 19811 | if (!multixri_pool) |
| 19812 | return; |
| 19813 | io_req_count = multixri_pool->io_req_count; |
| 19814 | prev_io_req_count = multixri_pool->prev_io_req_count; |
| 19815 | |
| 19816 | if (prev_io_req_count != io_req_count) { |
| 19817 | /* Private pool is busy */ |
| 19818 | multixri_pool->prev_io_req_count = io_req_count; |
| 19819 | } else { |
| 19820 | /* Private pool is not busy. |
| 19821 | * Move XRIs from private to public pool. |
| 19822 | */ |
| 19823 | lpfc_move_xri_pvt_to_pbl(phba, hwqid); |
| 19824 | } |
| 19825 | } |
| 19826 | |
| 19827 | /** |
| 19828 | * lpfc_adjust_high_watermark - Adjust high watermark |
| 19829 | * @phba: pointer to lpfc hba data structure. |
| 19830 | * @hwqid: belong to which HWQ. |
| 19831 | * |
| 19832 | * This routine sets high watermark as number of outstanding XRIs, |
| 19833 | * but make sure the new value is between xri_limit/2 and xri_limit. |
| 19834 | **/ |
| 19835 | void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid) |
| 19836 | { |
| 19837 | u32 new_watermark; |
| 19838 | u32 watermark_max; |
| 19839 | u32 watermark_min; |
| 19840 | u32 xri_limit; |
| 19841 | u32 txcmplq_cnt; |
| 19842 | u32 abts_io_bufs; |
| 19843 | struct lpfc_multixri_pool *multixri_pool; |
| 19844 | struct lpfc_sli4_hdw_queue *qp; |
| 19845 | |
| 19846 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 19847 | multixri_pool = qp->p_multixri_pool; |
| 19848 | if (!multixri_pool) |
| 19849 | return; |
| 19850 | xri_limit = multixri_pool->xri_limit; |
| 19851 | |
| 19852 | watermark_max = xri_limit; |
| 19853 | watermark_min = xri_limit / 2; |
| 19854 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19855 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19856 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19857 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19858 | |
| 19859 | new_watermark = txcmplq_cnt + abts_io_bufs; |
| 19860 | new_watermark = min(watermark_max, new_watermark); |
| 19861 | new_watermark = max(watermark_min, new_watermark); |
| 19862 | multixri_pool->pvt_pool.high_watermark = new_watermark; |
| 19863 | |
| 19864 | #ifdef LPFC_MXP_STAT |
| 19865 | multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm, |
| 19866 | new_watermark); |
| 19867 | #endif |
| 19868 | } |
| 19869 | |
| 19870 | /** |
| 19871 | * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool |
| 19872 | * @phba: pointer to lpfc hba data structure. |
| 19873 | * @hwqid: belong to which HWQ. |
| 19874 | * |
| 19875 | * This routine is called from hearbeat timer when pvt_pool is idle. |
| 19876 | * All free XRIs are moved from private to public pool on hwqid with 2 steps. |
| 19877 | * The first step moves (all - low_watermark) amount of XRIs. |
| 19878 | * The second step moves the rest of XRIs. |
| 19879 | **/ |
| 19880 | void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid) |
| 19881 | { |
| 19882 | struct lpfc_pbl_pool *pbl_pool; |
| 19883 | struct lpfc_pvt_pool *pvt_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19884 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19885 | struct lpfc_io_buf *lpfc_ncmd; |
| 19886 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 19887 | unsigned long iflag; |
| 19888 | struct list_head tmp_list; |
| 19889 | u32 tmp_count; |
| 19890 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19891 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 19892 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 19893 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19894 | tmp_count = 0; |
| 19895 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19896 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool); |
| 19897 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19898 | |
| 19899 | if (pvt_pool->count > pvt_pool->low_watermark) { |
| 19900 | /* Step 1: move (all - low_watermark) from pvt_pool |
| 19901 | * to pbl_pool |
| 19902 | */ |
| 19903 | |
| 19904 | /* Move low watermark of bufs from pvt_pool to tmp_list */ |
| 19905 | INIT_LIST_HEAD(&tmp_list); |
| 19906 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 19907 | &pvt_pool->list, list) { |
| 19908 | list_move_tail(&lpfc_ncmd->list, &tmp_list); |
| 19909 | tmp_count++; |
| 19910 | if (tmp_count >= pvt_pool->low_watermark) |
| 19911 | break; |
| 19912 | } |
| 19913 | |
| 19914 | /* Move all bufs from pvt_pool to pbl_pool */ |
| 19915 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 19916 | |
| 19917 | /* Move all bufs from tmp_list to pvt_pool */ |
| 19918 | list_splice(&tmp_list, &pvt_pool->list); |
| 19919 | |
| 19920 | pbl_pool->count += (pvt_pool->count - tmp_count); |
| 19921 | pvt_pool->count = tmp_count; |
| 19922 | } else { |
| 19923 | /* Step 2: move the rest from pvt_pool to pbl_pool */ |
| 19924 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 19925 | pbl_pool->count += pvt_pool->count; |
| 19926 | pvt_pool->count = 0; |
| 19927 | } |
| 19928 | |
| 19929 | spin_unlock(&pvt_pool->lock); |
| 19930 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 19931 | } |
| 19932 | |
| 19933 | /** |
| 19934 | * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 19935 | * @phba: pointer to lpfc hba data structure |
| 19936 | * @pbl_pool: specified public free XRI pool |
| 19937 | * @pvt_pool: specified private free XRI pool |
| 19938 | * @count: number of XRIs to move |
| 19939 | * |
| 19940 | * This routine tries to move some free common bufs from the specified pbl_pool |
| 19941 | * to the specified pvt_pool. It might move less than count XRIs if there's not |
| 19942 | * enough in public pool. |
| 19943 | * |
| 19944 | * Return: |
| 19945 | * true - if XRIs are successfully moved from the specified pbl_pool to the |
| 19946 | * specified pvt_pool |
| 19947 | * false - if the specified pbl_pool is empty or locked by someone else |
| 19948 | **/ |
| 19949 | static bool |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19950 | _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp, |
| 19951 | struct lpfc_pbl_pool *pbl_pool, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19952 | struct lpfc_pvt_pool *pvt_pool, u32 count) |
| 19953 | { |
| 19954 | struct lpfc_io_buf *lpfc_ncmd; |
| 19955 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 19956 | unsigned long iflag; |
| 19957 | int ret; |
| 19958 | |
| 19959 | ret = spin_trylock_irqsave(&pbl_pool->lock, iflag); |
| 19960 | if (ret) { |
| 19961 | if (pbl_pool->count) { |
| 19962 | /* Move a batch of XRIs from public to private pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19963 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19964 | list_for_each_entry_safe(lpfc_ncmd, |
| 19965 | lpfc_ncmd_next, |
| 19966 | &pbl_pool->list, |
| 19967 | list) { |
| 19968 | list_move_tail(&lpfc_ncmd->list, |
| 19969 | &pvt_pool->list); |
| 19970 | pvt_pool->count++; |
| 19971 | pbl_pool->count--; |
| 19972 | count--; |
| 19973 | if (count == 0) |
| 19974 | break; |
| 19975 | } |
| 19976 | |
| 19977 | spin_unlock(&pvt_pool->lock); |
| 19978 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 19979 | return true; |
| 19980 | } |
| 19981 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 19982 | } |
| 19983 | |
| 19984 | return false; |
| 19985 | } |
| 19986 | |
| 19987 | /** |
| 19988 | * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 19989 | * @phba: pointer to lpfc hba data structure. |
| 19990 | * @hwqid: belong to which HWQ. |
| 19991 | * @count: number of XRIs to move |
| 19992 | * |
| 19993 | * This routine tries to find some free common bufs in one of public pools with |
| 19994 | * Round Robin method. The search always starts from local hwqid, then the next |
| 19995 | * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found, |
| 19996 | * a batch of free common bufs are moved to private pool on hwqid. |
| 19997 | * It might move less than count XRIs if there's not enough in public pool. |
| 19998 | **/ |
| 19999 | void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count) |
| 20000 | { |
| 20001 | struct lpfc_multixri_pool *multixri_pool; |
| 20002 | struct lpfc_multixri_pool *next_multixri_pool; |
| 20003 | struct lpfc_pvt_pool *pvt_pool; |
| 20004 | struct lpfc_pbl_pool *pbl_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20005 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20006 | u32 next_hwqid; |
| 20007 | u32 hwq_count; |
| 20008 | int ret; |
| 20009 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20010 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20011 | multixri_pool = qp->p_multixri_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20012 | pvt_pool = &multixri_pool->pvt_pool; |
| 20013 | pbl_pool = &multixri_pool->pbl_pool; |
| 20014 | |
| 20015 | /* Check if local pbl_pool is available */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20016 | ret = _lpfc_move_xri_pbl_to_pvt(phba, qp, pbl_pool, pvt_pool, count); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20017 | if (ret) { |
| 20018 | #ifdef LPFC_MXP_STAT |
| 20019 | multixri_pool->local_pbl_hit_count++; |
| 20020 | #endif |
| 20021 | return; |
| 20022 | } |
| 20023 | |
| 20024 | hwq_count = phba->cfg_hdw_queue; |
| 20025 | |
| 20026 | /* Get the next hwqid which was found last time */ |
| 20027 | next_hwqid = multixri_pool->rrb_next_hwqid; |
| 20028 | |
| 20029 | do { |
| 20030 | /* Go to next hwq */ |
| 20031 | next_hwqid = (next_hwqid + 1) % hwq_count; |
| 20032 | |
| 20033 | next_multixri_pool = |
| 20034 | phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool; |
| 20035 | pbl_pool = &next_multixri_pool->pbl_pool; |
| 20036 | |
| 20037 | /* Check if the public free xri pool is available */ |
| 20038 | ret = _lpfc_move_xri_pbl_to_pvt( |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20039 | phba, qp, pbl_pool, pvt_pool, count); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20040 | |
| 20041 | /* Exit while-loop if success or all hwqid are checked */ |
| 20042 | } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid); |
| 20043 | |
| 20044 | /* Starting point for the next time */ |
| 20045 | multixri_pool->rrb_next_hwqid = next_hwqid; |
| 20046 | |
| 20047 | if (!ret) { |
| 20048 | /* stats: all public pools are empty*/ |
| 20049 | multixri_pool->pbl_empty_count++; |
| 20050 | } |
| 20051 | |
| 20052 | #ifdef LPFC_MXP_STAT |
| 20053 | if (ret) { |
| 20054 | if (next_hwqid == hwqid) |
| 20055 | multixri_pool->local_pbl_hit_count++; |
| 20056 | else |
| 20057 | multixri_pool->other_pbl_hit_count++; |
| 20058 | } |
| 20059 | #endif |
| 20060 | } |
| 20061 | |
| 20062 | /** |
| 20063 | * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark |
| 20064 | * @phba: pointer to lpfc hba data structure. |
| 20065 | * @qp: belong to which HWQ. |
| 20066 | * |
| 20067 | * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than |
| 20068 | * low watermark. |
| 20069 | **/ |
| 20070 | void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid) |
| 20071 | { |
| 20072 | struct lpfc_multixri_pool *multixri_pool; |
| 20073 | struct lpfc_pvt_pool *pvt_pool; |
| 20074 | |
| 20075 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 20076 | pvt_pool = &multixri_pool->pvt_pool; |
| 20077 | |
| 20078 | if (pvt_pool->count < pvt_pool->low_watermark) |
| 20079 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20080 | } |
| 20081 | |
| 20082 | /** |
| 20083 | * lpfc_release_io_buf - Return one IO buf back to free pool |
| 20084 | * @phba: pointer to lpfc hba data structure. |
| 20085 | * @lpfc_ncmd: IO buf to be returned. |
| 20086 | * @qp: belong to which HWQ. |
| 20087 | * |
| 20088 | * This routine returns one IO buf back to free pool. If this is an urgent IO, |
| 20089 | * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1, |
| 20090 | * the IO buf is returned to pbl_pool or pvt_pool based on watermark and |
| 20091 | * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to |
| 20092 | * lpfc_io_buf_list_put. |
| 20093 | **/ |
| 20094 | void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd, |
| 20095 | struct lpfc_sli4_hdw_queue *qp) |
| 20096 | { |
| 20097 | unsigned long iflag; |
| 20098 | struct lpfc_pbl_pool *pbl_pool; |
| 20099 | struct lpfc_pvt_pool *pvt_pool; |
| 20100 | struct lpfc_epd_pool *epd_pool; |
| 20101 | u32 txcmplq_cnt; |
| 20102 | u32 xri_owned; |
| 20103 | u32 xri_limit; |
| 20104 | u32 abts_io_bufs; |
| 20105 | |
| 20106 | /* MUST zero fields if buffer is reused by another protocol */ |
| 20107 | lpfc_ncmd->nvmeCmd = NULL; |
| 20108 | lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL; |
| 20109 | lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL; |
| 20110 | |
| 20111 | if (phba->cfg_xri_rebalancing) { |
| 20112 | if (lpfc_ncmd->expedite) { |
| 20113 | /* Return to expedite pool */ |
| 20114 | epd_pool = &phba->epd_pool; |
| 20115 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20116 | list_add_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 20117 | epd_pool->count++; |
| 20118 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20119 | return; |
| 20120 | } |
| 20121 | |
| 20122 | /* Avoid invalid access if an IO sneaks in and is being rejected |
| 20123 | * just _after_ xri pools are destroyed in lpfc_offline. |
| 20124 | * Nothing much can be done at this point. |
| 20125 | */ |
| 20126 | if (!qp->p_multixri_pool) |
| 20127 | return; |
| 20128 | |
| 20129 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 20130 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 20131 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20132 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20133 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20134 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20135 | |
| 20136 | xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs; |
| 20137 | xri_limit = qp->p_multixri_pool->xri_limit; |
| 20138 | |
| 20139 | #ifdef LPFC_MXP_STAT |
| 20140 | if (xri_owned <= xri_limit) |
| 20141 | qp->p_multixri_pool->below_limit_count++; |
| 20142 | else |
| 20143 | qp->p_multixri_pool->above_limit_count++; |
| 20144 | #endif |
| 20145 | |
| 20146 | /* XRI goes to either public or private free xri pool |
| 20147 | * based on watermark and xri_limit |
| 20148 | */ |
| 20149 | if ((pvt_pool->count < pvt_pool->low_watermark) || |
| 20150 | (xri_owned < xri_limit && |
| 20151 | pvt_pool->count < pvt_pool->high_watermark)) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20152 | lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, |
| 20153 | qp, free_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20154 | list_add_tail(&lpfc_ncmd->list, |
| 20155 | &pvt_pool->list); |
| 20156 | pvt_pool->count++; |
| 20157 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20158 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20159 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, |
| 20160 | qp, free_pub_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20161 | list_add_tail(&lpfc_ncmd->list, |
| 20162 | &pbl_pool->list); |
| 20163 | pbl_pool->count++; |
| 20164 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20165 | } |
| 20166 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20167 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag, |
| 20168 | qp, free_xri); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20169 | list_add_tail(&lpfc_ncmd->list, |
| 20170 | &qp->lpfc_io_buf_list_put); |
| 20171 | qp->put_io_bufs++; |
| 20172 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, |
| 20173 | iflag); |
| 20174 | } |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20175 | |
| 20176 | if (phba->cfg_xpsgl && !phba->nvmet_support && |
| 20177 | !list_empty(&lpfc_ncmd->dma_sgl_xtra_list)) |
| 20178 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 20179 | |
| 20180 | if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list)) |
| 20181 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20182 | } |
| 20183 | |
| 20184 | /** |
| 20185 | * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool |
| 20186 | * @phba: pointer to lpfc hba data structure. |
| 20187 | * @pvt_pool: pointer to private pool data structure. |
| 20188 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20189 | * |
| 20190 | * This routine tries to get one free IO buf from private pool. |
| 20191 | * |
| 20192 | * Return: |
| 20193 | * pointer to one free IO buf - if private pool is not empty |
| 20194 | * NULL - if private pool is empty |
| 20195 | **/ |
| 20196 | static struct lpfc_io_buf * |
| 20197 | lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20198 | struct lpfc_sli4_hdw_queue *qp, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20199 | struct lpfc_pvt_pool *pvt_pool, |
| 20200 | struct lpfc_nodelist *ndlp) |
| 20201 | { |
| 20202 | struct lpfc_io_buf *lpfc_ncmd; |
| 20203 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20204 | unsigned long iflag; |
| 20205 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20206 | lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, qp, alloc_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20207 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20208 | &pvt_pool->list, list) { |
| 20209 | if (lpfc_test_rrq_active( |
| 20210 | phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag)) |
| 20211 | continue; |
| 20212 | list_del(&lpfc_ncmd->list); |
| 20213 | pvt_pool->count--; |
| 20214 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20215 | return lpfc_ncmd; |
| 20216 | } |
| 20217 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20218 | |
| 20219 | return NULL; |
| 20220 | } |
| 20221 | |
| 20222 | /** |
| 20223 | * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool |
| 20224 | * @phba: pointer to lpfc hba data structure. |
| 20225 | * |
| 20226 | * This routine tries to get one free IO buf from expedite pool. |
| 20227 | * |
| 20228 | * Return: |
| 20229 | * pointer to one free IO buf - if expedite pool is not empty |
| 20230 | * NULL - if expedite pool is empty |
| 20231 | **/ |
| 20232 | static struct lpfc_io_buf * |
| 20233 | lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba) |
| 20234 | { |
| 20235 | struct lpfc_io_buf *lpfc_ncmd; |
| 20236 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20237 | unsigned long iflag; |
| 20238 | struct lpfc_epd_pool *epd_pool; |
| 20239 | |
| 20240 | epd_pool = &phba->epd_pool; |
| 20241 | lpfc_ncmd = NULL; |
| 20242 | |
| 20243 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20244 | if (epd_pool->count > 0) { |
| 20245 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20246 | &epd_pool->list, list) { |
| 20247 | list_del(&lpfc_ncmd->list); |
| 20248 | epd_pool->count--; |
| 20249 | break; |
| 20250 | } |
| 20251 | } |
| 20252 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20253 | |
| 20254 | return lpfc_ncmd; |
| 20255 | } |
| 20256 | |
| 20257 | /** |
| 20258 | * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs |
| 20259 | * @phba: pointer to lpfc hba data structure. |
| 20260 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20261 | * @hwqid: belong to which HWQ |
| 20262 | * @expedite: 1 means this request is urgent. |
| 20263 | * |
| 20264 | * This routine will do the following actions and then return a pointer to |
| 20265 | * one free IO buf. |
| 20266 | * |
| 20267 | * 1. If private free xri count is empty, move some XRIs from public to |
| 20268 | * private pool. |
| 20269 | * 2. Get one XRI from private free xri pool. |
| 20270 | * 3. If we fail to get one from pvt_pool and this is an expedite request, |
| 20271 | * get one free xri from expedite pool. |
| 20272 | * |
| 20273 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20274 | * The caller should pass NULL for ndlp on NVME side. |
| 20275 | * |
| 20276 | * Return: |
| 20277 | * pointer to one free IO buf - if private pool is not empty |
| 20278 | * NULL - if private pool is empty |
| 20279 | **/ |
| 20280 | static struct lpfc_io_buf * |
| 20281 | lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba, |
| 20282 | struct lpfc_nodelist *ndlp, |
| 20283 | int hwqid, int expedite) |
| 20284 | { |
| 20285 | struct lpfc_sli4_hdw_queue *qp; |
| 20286 | struct lpfc_multixri_pool *multixri_pool; |
| 20287 | struct lpfc_pvt_pool *pvt_pool; |
| 20288 | struct lpfc_io_buf *lpfc_ncmd; |
| 20289 | |
| 20290 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20291 | lpfc_ncmd = NULL; |
| 20292 | multixri_pool = qp->p_multixri_pool; |
| 20293 | pvt_pool = &multixri_pool->pvt_pool; |
| 20294 | multixri_pool->io_req_count++; |
| 20295 | |
| 20296 | /* If pvt_pool is empty, move some XRIs from public to private pool */ |
| 20297 | if (pvt_pool->count == 0) |
| 20298 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20299 | |
| 20300 | /* Get one XRI from private free xri pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20301 | lpfc_ncmd = lpfc_get_io_buf_from_private_pool(phba, qp, pvt_pool, ndlp); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20302 | |
| 20303 | if (lpfc_ncmd) { |
| 20304 | lpfc_ncmd->hdwq = qp; |
| 20305 | lpfc_ncmd->hdwq_no = hwqid; |
| 20306 | } else if (expedite) { |
| 20307 | /* If we fail to get one from pvt_pool and this is an expedite |
| 20308 | * request, get one free xri from expedite pool. |
| 20309 | */ |
| 20310 | lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba); |
| 20311 | } |
| 20312 | |
| 20313 | return lpfc_ncmd; |
| 20314 | } |
| 20315 | |
| 20316 | static inline struct lpfc_io_buf * |
| 20317 | lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx) |
| 20318 | { |
| 20319 | struct lpfc_sli4_hdw_queue *qp; |
| 20320 | struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next; |
| 20321 | |
| 20322 | qp = &phba->sli4_hba.hdwq[idx]; |
| 20323 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 20324 | &qp->lpfc_io_buf_list_get, list) { |
| 20325 | if (lpfc_test_rrq_active(phba, ndlp, |
| 20326 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 20327 | continue; |
| 20328 | |
| 20329 | if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED) |
| 20330 | continue; |
| 20331 | |
| 20332 | list_del_init(&lpfc_cmd->list); |
| 20333 | qp->get_io_bufs--; |
| 20334 | lpfc_cmd->hdwq = qp; |
| 20335 | lpfc_cmd->hdwq_no = idx; |
| 20336 | return lpfc_cmd; |
| 20337 | } |
| 20338 | return NULL; |
| 20339 | } |
| 20340 | |
| 20341 | /** |
| 20342 | * lpfc_get_io_buf - Get one IO buffer from free pool |
| 20343 | * @phba: The HBA for which this call is being executed. |
| 20344 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20345 | * @hwqid: belong to which HWQ |
| 20346 | * @expedite: 1 means this request is urgent. |
| 20347 | * |
| 20348 | * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1, |
| 20349 | * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes |
| 20350 | * a IO buffer from head of @hdwq io_buf_list and returns to caller. |
| 20351 | * |
| 20352 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20353 | * The caller should pass NULL for ndlp on NVME side. |
| 20354 | * |
| 20355 | * Return codes: |
| 20356 | * NULL - Error |
| 20357 | * Pointer to lpfc_io_buf - Success |
| 20358 | **/ |
| 20359 | struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba, |
| 20360 | struct lpfc_nodelist *ndlp, |
| 20361 | u32 hwqid, int expedite) |
| 20362 | { |
| 20363 | struct lpfc_sli4_hdw_queue *qp; |
| 20364 | unsigned long iflag; |
| 20365 | struct lpfc_io_buf *lpfc_cmd; |
| 20366 | |
| 20367 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20368 | lpfc_cmd = NULL; |
| 20369 | |
| 20370 | if (phba->cfg_xri_rebalancing) |
| 20371 | lpfc_cmd = lpfc_get_io_buf_from_multixri_pools( |
| 20372 | phba, ndlp, hwqid, expedite); |
| 20373 | else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20374 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag, |
| 20375 | qp, alloc_xri_get); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20376 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite) |
| 20377 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20378 | if (!lpfc_cmd) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20379 | lpfc_qp_spin_lock(&qp->io_buf_list_put_lock, |
| 20380 | qp, alloc_xri_put); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20381 | list_splice(&qp->lpfc_io_buf_list_put, |
| 20382 | &qp->lpfc_io_buf_list_get); |
| 20383 | qp->get_io_bufs += qp->put_io_bufs; |
| 20384 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 20385 | qp->put_io_bufs = 0; |
| 20386 | spin_unlock(&qp->io_buf_list_put_lock); |
| 20387 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || |
| 20388 | expedite) |
| 20389 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20390 | } |
| 20391 | spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag); |
| 20392 | } |
| 20393 | |
| 20394 | return lpfc_cmd; |
| 20395 | } |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20396 | |
| 20397 | /** |
| 20398 | * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool |
| 20399 | * @phba: The HBA for which this call is being executed. |
| 20400 | * @lpfc_buf: IO buf structure to append the SGL chunk |
| 20401 | * |
| 20402 | * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool, |
| 20403 | * and will allocate an SGL chunk if the pool is empty. |
| 20404 | * |
| 20405 | * Return codes: |
| 20406 | * NULL - Error |
| 20407 | * Pointer to sli4_hybrid_sgl - Success |
| 20408 | **/ |
| 20409 | struct sli4_hybrid_sgl * |
| 20410 | lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 20411 | { |
| 20412 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20413 | struct sli4_hybrid_sgl *tmp = NULL; |
| 20414 | struct sli4_hybrid_sgl *allocated_sgl = NULL; |
| 20415 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20416 | struct list_head *buf_list = &hdwq->sgl_list; |
| 20417 | |
| 20418 | spin_lock_irq(&hdwq->hdwq_lock); |
| 20419 | |
| 20420 | if (likely(!list_empty(buf_list))) { |
| 20421 | /* break off 1 chunk from the sgl_list */ |
| 20422 | list_for_each_entry_safe(list_entry, tmp, |
| 20423 | buf_list, list_node) { |
| 20424 | list_move_tail(&list_entry->list_node, |
| 20425 | &lpfc_buf->dma_sgl_xtra_list); |
| 20426 | break; |
| 20427 | } |
| 20428 | } else { |
| 20429 | /* allocate more */ |
| 20430 | spin_unlock_irq(&hdwq->hdwq_lock); |
| 20431 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
| 20432 | cpu_to_node(smp_processor_id())); |
| 20433 | if (!tmp) { |
| 20434 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20435 | "8353 error kmalloc memory for HDWQ " |
| 20436 | "%d %s\n", |
| 20437 | lpfc_buf->hdwq_no, __func__); |
| 20438 | return NULL; |
| 20439 | } |
| 20440 | |
| 20441 | tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool, |
| 20442 | GFP_ATOMIC, &tmp->dma_phys_sgl); |
| 20443 | if (!tmp->dma_sgl) { |
| 20444 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20445 | "8354 error pool_alloc memory for HDWQ " |
| 20446 | "%d %s\n", |
| 20447 | lpfc_buf->hdwq_no, __func__); |
| 20448 | kfree(tmp); |
| 20449 | return NULL; |
| 20450 | } |
| 20451 | |
| 20452 | spin_lock_irq(&hdwq->hdwq_lock); |
| 20453 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list); |
| 20454 | } |
| 20455 | |
| 20456 | allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list, |
| 20457 | struct sli4_hybrid_sgl, |
| 20458 | list_node); |
| 20459 | |
| 20460 | spin_unlock_irq(&hdwq->hdwq_lock); |
| 20461 | |
| 20462 | return allocated_sgl; |
| 20463 | } |
| 20464 | |
| 20465 | /** |
| 20466 | * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool |
| 20467 | * @phba: The HBA for which this call is being executed. |
| 20468 | * @lpfc_buf: IO buf structure with the SGL chunk |
| 20469 | * |
| 20470 | * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool. |
| 20471 | * |
| 20472 | * Return codes: |
| 20473 | * 0 - Success |
| 20474 | * -EINVAL - Error |
| 20475 | **/ |
| 20476 | int |
| 20477 | lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 20478 | { |
| 20479 | int rc = 0; |
| 20480 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20481 | struct sli4_hybrid_sgl *tmp = NULL; |
| 20482 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20483 | struct list_head *buf_list = &hdwq->sgl_list; |
| 20484 | |
| 20485 | spin_lock_irq(&hdwq->hdwq_lock); |
| 20486 | |
| 20487 | if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) { |
| 20488 | list_for_each_entry_safe(list_entry, tmp, |
| 20489 | &lpfc_buf->dma_sgl_xtra_list, |
| 20490 | list_node) { |
| 20491 | list_move_tail(&list_entry->list_node, |
| 20492 | buf_list); |
| 20493 | } |
| 20494 | } else { |
| 20495 | rc = -EINVAL; |
| 20496 | } |
| 20497 | |
| 20498 | spin_unlock_irq(&hdwq->hdwq_lock); |
| 20499 | return rc; |
| 20500 | } |
| 20501 | |
| 20502 | /** |
| 20503 | * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool |
| 20504 | * @phba: phba object |
| 20505 | * @hdwq: hdwq to cleanup sgl buff resources on |
| 20506 | * |
| 20507 | * This routine frees all SGL chunks of hdwq SGL chunk pool. |
| 20508 | * |
| 20509 | * Return codes: |
| 20510 | * None |
| 20511 | **/ |
| 20512 | void |
| 20513 | lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba, |
| 20514 | struct lpfc_sli4_hdw_queue *hdwq) |
| 20515 | { |
| 20516 | struct list_head *buf_list = &hdwq->sgl_list; |
| 20517 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20518 | struct sli4_hybrid_sgl *tmp = NULL; |
| 20519 | |
| 20520 | spin_lock_irq(&hdwq->hdwq_lock); |
| 20521 | |
| 20522 | /* Free sgl pool */ |
| 20523 | list_for_each_entry_safe(list_entry, tmp, |
| 20524 | buf_list, list_node) { |
| 20525 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 20526 | list_entry->dma_sgl, |
| 20527 | list_entry->dma_phys_sgl); |
| 20528 | list_del(&list_entry->list_node); |
| 20529 | kfree(list_entry); |
| 20530 | } |
| 20531 | |
| 20532 | spin_unlock_irq(&hdwq->hdwq_lock); |
| 20533 | } |
| 20534 | |
| 20535 | /** |
| 20536 | * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq |
| 20537 | * @phba: The HBA for which this call is being executed. |
| 20538 | * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer |
| 20539 | * |
| 20540 | * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool, |
| 20541 | * and will allocate an CMD/RSP buffer if the pool is empty. |
| 20542 | * |
| 20543 | * Return codes: |
| 20544 | * NULL - Error |
| 20545 | * Pointer to fcp_cmd_rsp_buf - Success |
| 20546 | **/ |
| 20547 | struct fcp_cmd_rsp_buf * |
| 20548 | lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 20549 | struct lpfc_io_buf *lpfc_buf) |
| 20550 | { |
| 20551 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 20552 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 20553 | struct fcp_cmd_rsp_buf *allocated_buf = NULL; |
| 20554 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20555 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
| 20556 | |
| 20557 | spin_lock_irq(&hdwq->hdwq_lock); |
| 20558 | |
| 20559 | if (likely(!list_empty(buf_list))) { |
| 20560 | /* break off 1 chunk from the list */ |
| 20561 | list_for_each_entry_safe(list_entry, tmp, |
| 20562 | buf_list, |
| 20563 | list_node) { |
| 20564 | list_move_tail(&list_entry->list_node, |
| 20565 | &lpfc_buf->dma_cmd_rsp_list); |
| 20566 | break; |
| 20567 | } |
| 20568 | } else { |
| 20569 | /* allocate more */ |
| 20570 | spin_unlock_irq(&hdwq->hdwq_lock); |
| 20571 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
| 20572 | cpu_to_node(smp_processor_id())); |
| 20573 | if (!tmp) { |
| 20574 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20575 | "8355 error kmalloc memory for HDWQ " |
| 20576 | "%d %s\n", |
| 20577 | lpfc_buf->hdwq_no, __func__); |
| 20578 | return NULL; |
| 20579 | } |
| 20580 | |
| 20581 | tmp->fcp_cmnd = dma_pool_alloc(phba->lpfc_cmd_rsp_buf_pool, |
| 20582 | GFP_ATOMIC, |
| 20583 | &tmp->fcp_cmd_rsp_dma_handle); |
| 20584 | |
| 20585 | if (!tmp->fcp_cmnd) { |
| 20586 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20587 | "8356 error pool_alloc memory for HDWQ " |
| 20588 | "%d %s\n", |
| 20589 | lpfc_buf->hdwq_no, __func__); |
| 20590 | kfree(tmp); |
| 20591 | return NULL; |
| 20592 | } |
| 20593 | |
| 20594 | tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd + |
| 20595 | sizeof(struct fcp_cmnd)); |
| 20596 | |
| 20597 | spin_lock_irq(&hdwq->hdwq_lock); |
| 20598 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list); |
| 20599 | } |
| 20600 | |
| 20601 | allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list, |
| 20602 | struct fcp_cmd_rsp_buf, |
| 20603 | list_node); |
| 20604 | |
| 20605 | spin_unlock_irq(&hdwq->hdwq_lock); |
| 20606 | |
| 20607 | return allocated_buf; |
| 20608 | } |
| 20609 | |
| 20610 | /** |
| 20611 | * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool |
| 20612 | * @phba: The HBA for which this call is being executed. |
| 20613 | * @lpfc_buf: IO buf structure with the CMD/RSP buf |
| 20614 | * |
| 20615 | * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool. |
| 20616 | * |
| 20617 | * Return codes: |
| 20618 | * 0 - Success |
| 20619 | * -EINVAL - Error |
| 20620 | **/ |
| 20621 | int |
| 20622 | lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 20623 | struct lpfc_io_buf *lpfc_buf) |
| 20624 | { |
| 20625 | int rc = 0; |
| 20626 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 20627 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 20628 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20629 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
| 20630 | |
| 20631 | spin_lock_irq(&hdwq->hdwq_lock); |
| 20632 | |
| 20633 | if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) { |
| 20634 | list_for_each_entry_safe(list_entry, tmp, |
| 20635 | &lpfc_buf->dma_cmd_rsp_list, |
| 20636 | list_node) { |
| 20637 | list_move_tail(&list_entry->list_node, |
| 20638 | buf_list); |
| 20639 | } |
| 20640 | } else { |
| 20641 | rc = -EINVAL; |
| 20642 | } |
| 20643 | |
| 20644 | spin_unlock_irq(&hdwq->hdwq_lock); |
| 20645 | return rc; |
| 20646 | } |
| 20647 | |
| 20648 | /** |
| 20649 | * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool |
| 20650 | * @phba: phba object |
| 20651 | * @hdwq: hdwq to cleanup cmd rsp buff resources on |
| 20652 | * |
| 20653 | * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool. |
| 20654 | * |
| 20655 | * Return codes: |
| 20656 | * None |
| 20657 | **/ |
| 20658 | void |
| 20659 | lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 20660 | struct lpfc_sli4_hdw_queue *hdwq) |
| 20661 | { |
| 20662 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
| 20663 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 20664 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 20665 | |
| 20666 | spin_lock_irq(&hdwq->hdwq_lock); |
| 20667 | |
| 20668 | /* Free cmd_rsp buf pool */ |
| 20669 | list_for_each_entry_safe(list_entry, tmp, |
| 20670 | buf_list, |
| 20671 | list_node) { |
| 20672 | dma_pool_free(phba->lpfc_cmd_rsp_buf_pool, |
| 20673 | list_entry->fcp_cmnd, |
| 20674 | list_entry->fcp_cmd_rsp_dma_handle); |
| 20675 | list_del(&list_entry->list_node); |
| 20676 | kfree(list_entry); |
| 20677 | } |
| 20678 | |
| 20679 | spin_unlock_irq(&hdwq->hdwq_lock); |
| 20680 | } |