| 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 | 145e5a8 | 2020-01-27 16:23:12 -0800 | [diff] [blame^] | 4 | * Copyright (C) 2017-2020 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 | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 90 | static struct lpfc_cqe *lpfc_sli4_cq_get(struct lpfc_queue *q); |
| 91 | static void __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, |
| 92 | struct lpfc_queue *cq, |
| 93 | struct lpfc_cqe *cqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 94 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 95 | static IOCB_t * |
| 96 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 97 | { |
| 98 | return &iocbq->iocb; |
| 99 | } |
| 100 | |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 101 | #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN) |
| 102 | /** |
| 103 | * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function |
| 104 | * @srcp: Source memory pointer. |
| 105 | * @destp: Destination memory pointer. |
| 106 | * @cnt: Number of words required to be copied. |
| 107 | * Must be a multiple of sizeof(uint64_t) |
| 108 | * |
| 109 | * This function is used for copying data between driver memory |
| 110 | * and the SLI WQ. This function also changes the endianness |
| 111 | * of each word if native endianness is different from SLI |
| 112 | * endianness. This function can be called with or without |
| 113 | * lock. |
| 114 | **/ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 115 | static void |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 116 | lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 117 | { |
| 118 | uint64_t *src = srcp; |
| 119 | uint64_t *dest = destp; |
| 120 | int i; |
| 121 | |
| 122 | for (i = 0; i < (int)cnt; i += sizeof(uint64_t)) |
| 123 | *dest++ = *src++; |
| 124 | } |
| 125 | #else |
| 126 | #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c) |
| 127 | #endif |
| 128 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 129 | /** |
| 130 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 131 | * @q: The Work Queue to operate on. |
| 132 | * @wqe: The work Queue Entry to put on the Work queue. |
| 133 | * |
| 134 | * This routine will copy the contents of @wqe to the next available entry on |
| 135 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 136 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 137 | * successful. If no entries are available on @q then this function will return |
| 138 | * -ENOMEM. |
| 139 | * The caller is expected to hold the hbalock when calling this routine. |
| 140 | **/ |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 141 | static int |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 142 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 143 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 144 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 145 | struct lpfc_register doorbell; |
| 146 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 147 | uint32_t idx; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 148 | uint32_t i = 0; |
| 149 | uint8_t *tmp; |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame] | 150 | u32 if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 151 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 152 | /* sanity check on queue memory */ |
| 153 | if (unlikely(!q)) |
| 154 | return -ENOMEM; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 155 | temp_wqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 156 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 157 | /* 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] | 158 | idx = ((q->host_index + 1) % q->entry_count); |
| 159 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 160 | q->WQ_overflow++; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 161 | return -EBUSY; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 162 | } |
| 163 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 164 | /* set consumption flag every once in a while */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 165 | if (!((q->host_index + 1) % q->notify_interval)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 166 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | 04673e3 | 2018-01-30 15:58:45 -0800 | [diff] [blame] | 167 | else |
| 168 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 0); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 169 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 170 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 171 | lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 172 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 173 | /* write to DPP aperture taking advatage of Combined Writes */ |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 174 | tmp = (uint8_t *)temp_wqe; |
| 175 | #ifdef __raw_writeq |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 176 | for (i = 0; i < q->entry_size; i += sizeof(uint64_t)) |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 177 | __raw_writeq(*((uint64_t *)(tmp + i)), |
| 178 | q->dpp_regaddr + i); |
| 179 | #else |
| 180 | for (i = 0; i < q->entry_size; i += sizeof(uint32_t)) |
| 181 | __raw_writel(*((uint32_t *)(tmp + i)), |
| 182 | q->dpp_regaddr + i); |
| 183 | #endif |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 184 | } |
| 185 | /* ensure WQE bcopy and DPP flushed before doorbell write */ |
James Smart | 6b3b3bd | 2016-12-19 15:07:30 -0800 | [diff] [blame] | 186 | wmb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 187 | |
| 188 | /* Update the host index before invoking device */ |
| 189 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 190 | |
| 191 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 192 | |
| 193 | /* Ring Doorbell */ |
| 194 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 195 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 196 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 197 | bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1); |
| 198 | bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1); |
| 199 | bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell, |
| 200 | q->dpp_id); |
| 201 | bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell, |
| 202 | q->queue_id); |
| 203 | } else { |
| 204 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 205 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame] | 206 | |
| 207 | /* Leave bits <23:16> clear for if_type 6 dpp */ |
| 208 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 209 | &q->phba->sli4_hba.sli_intf); |
| 210 | if (if_type != LPFC_SLI_INTF_IF_TYPE_6) |
| 211 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, |
| 212 | host_index); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 213 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 214 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 215 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 216 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 217 | } else { |
| 218 | return -EINVAL; |
| 219 | } |
| 220 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 227 | * @q: The Work Queue to operate on. |
| 228 | * @index: The index to advance the hba index to. |
| 229 | * |
| 230 | * This routine will update the HBA index of a queue to reflect consumption of |
| 231 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 232 | * an entry the host calls this function to update the queue's internal |
| 233 | * pointers. This routine returns the number of entries that were consumed by |
| 234 | * the HBA. |
| 235 | **/ |
| 236 | static uint32_t |
| 237 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 238 | { |
| 239 | uint32_t released = 0; |
| 240 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 241 | /* sanity check on queue memory */ |
| 242 | if (unlikely(!q)) |
| 243 | return 0; |
| 244 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 245 | if (q->hba_index == index) |
| 246 | return 0; |
| 247 | do { |
| 248 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 249 | released++; |
| 250 | } while (q->hba_index != index); |
| 251 | return released; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 256 | * @q: The Mailbox Queue to operate on. |
| 257 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 258 | * |
| 259 | * This routine will copy the contents of @mqe to the next available entry on |
| 260 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 261 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 262 | * successful. If no entries are available on @q then this function will return |
| 263 | * -ENOMEM. |
| 264 | * The caller is expected to hold the hbalock when calling this routine. |
| 265 | **/ |
| 266 | static uint32_t |
| 267 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 268 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 269 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 270 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 271 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 272 | /* sanity check on queue memory */ |
| 273 | if (unlikely(!q)) |
| 274 | return -ENOMEM; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 275 | temp_mqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 276 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 277 | /* If the host has not yet processed the next entry then we are done */ |
| 278 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 279 | return -ENOMEM; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 280 | lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 281 | /* Save off the mailbox pointer for completion */ |
| 282 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 283 | |
| 284 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 285 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 286 | |
| 287 | /* Ring Doorbell */ |
| 288 | doorbell.word0 = 0; |
| 289 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 290 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 291 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 297 | * @q: The Mailbox Queue to operate on. |
| 298 | * |
| 299 | * This routine will update the HBA index of a queue to reflect consumption of |
| 300 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 301 | * an entry the host calls this function to update the queue's internal |
| 302 | * pointers. This routine returns the number of entries that were consumed by |
| 303 | * the HBA. |
| 304 | **/ |
| 305 | static uint32_t |
| 306 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 307 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 308 | /* sanity check on queue memory */ |
| 309 | if (unlikely(!q)) |
| 310 | return 0; |
| 311 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 312 | /* Clear the mailbox pointer for completion */ |
| 313 | q->phba->mbox = NULL; |
| 314 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 315 | return 1; |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 320 | * @q: The Event Queue to get the first valid EQE from |
| 321 | * |
| 322 | * This routine will get the first valid Event Queue Entry from @q, update |
| 323 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 324 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 325 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 326 | **/ |
| 327 | static struct lpfc_eqe * |
| 328 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 329 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 330 | struct lpfc_eqe *eqe; |
| 331 | |
| 332 | /* sanity check on queue memory */ |
| 333 | if (unlikely(!q)) |
| 334 | return NULL; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 335 | eqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 336 | |
| 337 | /* If the next EQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 338 | if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 339 | return NULL; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 340 | |
| 341 | /* |
| 342 | * insert barrier for instruction interlock : data from the hardware |
| 343 | * 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] | 344 | * upon. Speculative instructions were allowing a bcopy at the start |
| 345 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 346 | * after our return, to copy data before the valid bit check above |
| 347 | * was done. As such, some of the copied data was stale. The barrier |
| 348 | * ensures the check is before any data is copied. |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 349 | */ |
| 350 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 351 | return eqe; |
| 352 | } |
| 353 | |
| 354 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 355 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 356 | * @q: The Event Queue to disable interrupts |
| 357 | * |
| 358 | **/ |
James Smart | 92f3b32 | 2019-03-20 10:44:22 -0700 | [diff] [blame] | 359 | void |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 360 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 361 | { |
| 362 | struct lpfc_register doorbell; |
| 363 | |
| 364 | doorbell.word0 = 0; |
| 365 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 366 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 367 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 368 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 369 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 370 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 374 | * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ |
| 375 | * @q: The Event Queue to disable interrupts |
| 376 | * |
| 377 | **/ |
James Smart | 92f3b32 | 2019-03-20 10:44:22 -0700 | [diff] [blame] | 378 | void |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 379 | lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q) |
| 380 | { |
| 381 | struct lpfc_register doorbell; |
| 382 | |
| 383 | doorbell.word0 = 0; |
James Smart | aad59d5 | 2018-09-10 10:30:47 -0700 | [diff] [blame] | 384 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 385 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 386 | } |
| 387 | |
| 388 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 389 | * lpfc_sli4_write_eq_db - write EQ DB for eqe's consumed or arm state |
| 390 | * @phba: adapter with EQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 391 | * @q: The Event Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 392 | * @count: Number of elements that have been consumed |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 393 | * @arm: Indicates whether the host wants to arms this CQ. |
| 394 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 395 | * This routine will notify the HBA, by ringing the doorbell, that count |
| 396 | * number of EQEs have been processed. The @arm parameter indicates whether |
| 397 | * the queue should be rearmed when ringing the doorbell. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 398 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 399 | void |
| 400 | lpfc_sli4_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 401 | uint32_t count, bool arm) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 402 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 403 | struct lpfc_register doorbell; |
| 404 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 405 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 406 | if (unlikely(!q || (count == 0 && !arm))) |
| 407 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 408 | |
| 409 | /* ring doorbell for number popped */ |
| 410 | doorbell.word0 = 0; |
| 411 | if (arm) { |
| 412 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 413 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 414 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 415 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 416 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 417 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 418 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 419 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 420 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 421 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 422 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 423 | readl(q->phba->sli4_hba.EQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 427 | * lpfc_sli4_if6_write_eq_db - write EQ DB for eqe's consumed or arm state |
| 428 | * @phba: adapter with EQ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 429 | * @q: The Event Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 430 | * @count: Number of elements that have been consumed |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 431 | * @arm: Indicates whether the host wants to arms this CQ. |
| 432 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 433 | * This routine will notify the HBA, by ringing the doorbell, that count |
| 434 | * number of EQEs have been processed. The @arm parameter indicates whether |
| 435 | * the queue should be rearmed when ringing the doorbell. |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 436 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 437 | void |
| 438 | lpfc_sli4_if6_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 439 | uint32_t count, bool arm) |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 440 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 441 | struct lpfc_register doorbell; |
| 442 | |
| 443 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 444 | if (unlikely(!q || (count == 0 && !arm))) |
| 445 | return; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 446 | |
| 447 | /* ring doorbell for number popped */ |
| 448 | doorbell.word0 = 0; |
| 449 | if (arm) |
| 450 | bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 451 | bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, count); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 452 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
| 453 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 454 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 455 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 456 | readl(q->phba->sli4_hba.EQDBregaddr); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static void |
| 460 | __lpfc_sli4_consume_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 461 | struct lpfc_eqe *eqe) |
| 462 | { |
| 463 | if (!phba->sli4_hba.pc_sli4_params.eqav) |
| 464 | bf_set_le32(lpfc_eqe_valid, eqe, 0); |
| 465 | |
| 466 | eq->host_index = ((eq->host_index + 1) % eq->entry_count); |
| 467 | |
| 468 | /* if the index wrapped around, toggle the valid bit */ |
| 469 | if (phba->sli4_hba.pc_sli4_params.eqav && !eq->host_index) |
| 470 | eq->qe_valid = (eq->qe_valid) ? 0 : 1; |
| 471 | } |
| 472 | |
| 473 | static void |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 474 | lpfc_sli4_eqcq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 475 | { |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 476 | struct lpfc_eqe *eqe = NULL; |
| 477 | u32 eq_count = 0, cq_count = 0; |
| 478 | struct lpfc_cqe *cqe = NULL; |
| 479 | struct lpfc_queue *cq = NULL, *childq = NULL; |
| 480 | int cqid = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 481 | |
| 482 | /* walk all the EQ entries and drop on the floor */ |
| 483 | eqe = lpfc_sli4_eq_get(eq); |
| 484 | while (eqe) { |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 485 | /* Get the reference to the corresponding CQ */ |
| 486 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 487 | cq = NULL; |
| 488 | |
| 489 | list_for_each_entry(childq, &eq->child_list, list) { |
| 490 | if (childq->queue_id == cqid) { |
| 491 | cq = childq; |
| 492 | break; |
| 493 | } |
| 494 | } |
| 495 | /* If CQ is valid, iterate through it and drop all the CQEs */ |
| 496 | if (cq) { |
| 497 | cqe = lpfc_sli4_cq_get(cq); |
| 498 | while (cqe) { |
| 499 | __lpfc_sli4_consume_cqe(phba, cq, cqe); |
| 500 | cq_count++; |
| 501 | cqe = lpfc_sli4_cq_get(cq); |
| 502 | } |
| 503 | /* Clear and re-arm the CQ */ |
| 504 | phba->sli4_hba.sli4_write_cq_db(phba, cq, cq_count, |
| 505 | LPFC_QUEUE_REARM); |
| 506 | cq_count = 0; |
| 507 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 508 | __lpfc_sli4_consume_eqe(phba, eq, eqe); |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 509 | eq_count++; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 510 | eqe = lpfc_sli4_eq_get(eq); |
| 511 | } |
| 512 | |
| 513 | /* Clear and re-arm the EQ */ |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 514 | phba->sli4_hba.sli4_write_eq_db(phba, eq, eq_count, LPFC_QUEUE_REARM); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | static int |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 518 | lpfc_sli4_process_eq(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 519 | uint8_t rearm) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 520 | { |
| 521 | struct lpfc_eqe *eqe; |
| 522 | int count = 0, consumed = 0; |
| 523 | |
| 524 | if (cmpxchg(&eq->queue_claimed, 0, 1) != 0) |
| 525 | goto rearm_and_exit; |
| 526 | |
| 527 | eqe = lpfc_sli4_eq_get(eq); |
| 528 | while (eqe) { |
| 529 | lpfc_sli4_hba_handle_eqe(phba, eq, eqe); |
| 530 | __lpfc_sli4_consume_eqe(phba, eq, eqe); |
| 531 | |
| 532 | consumed++; |
| 533 | if (!(++count % eq->max_proc_limit)) |
| 534 | break; |
| 535 | |
| 536 | if (!(count % eq->notify_interval)) { |
| 537 | phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, |
| 538 | LPFC_QUEUE_NOARM); |
| 539 | consumed = 0; |
| 540 | } |
| 541 | |
| 542 | eqe = lpfc_sli4_eq_get(eq); |
| 543 | } |
| 544 | eq->EQ_processed += count; |
| 545 | |
| 546 | /* Track the max number of EQEs processed in 1 intr */ |
| 547 | if (count > eq->EQ_max_eqe) |
| 548 | eq->EQ_max_eqe = count; |
| 549 | |
| 550 | eq->queue_claimed = 0; |
| 551 | |
| 552 | rearm_and_exit: |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 553 | /* Always clear the EQ. */ |
| 554 | phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, rearm); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 555 | |
| 556 | return count; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 560 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 561 | * @q: The Completion Queue to get the first valid CQE from |
| 562 | * |
| 563 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 564 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 565 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 566 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 567 | **/ |
| 568 | static struct lpfc_cqe * |
| 569 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 570 | { |
| 571 | struct lpfc_cqe *cqe; |
| 572 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 573 | /* sanity check on queue memory */ |
| 574 | if (unlikely(!q)) |
| 575 | return NULL; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 576 | cqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 577 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 578 | /* If the next CQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 579 | if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 580 | return NULL; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 581 | |
| 582 | /* |
| 583 | * insert barrier for instruction interlock : data from the hardware |
| 584 | * 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] | 585 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 586 | * instructions allowing action on content before valid bit checked, |
| 587 | * add barrier here as well. May not be needed as "content" is a |
| 588 | * single 32-bit entity here (vs multi word structure for cq's). |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 589 | */ |
| 590 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 591 | return cqe; |
| 592 | } |
| 593 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 594 | static void |
| 595 | __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 596 | struct lpfc_cqe *cqe) |
| 597 | { |
| 598 | if (!phba->sli4_hba.pc_sli4_params.cqav) |
| 599 | bf_set_le32(lpfc_cqe_valid, cqe, 0); |
| 600 | |
| 601 | cq->host_index = ((cq->host_index + 1) % cq->entry_count); |
| 602 | |
| 603 | /* if the index wrapped around, toggle the valid bit */ |
| 604 | if (phba->sli4_hba.pc_sli4_params.cqav && !cq->host_index) |
| 605 | cq->qe_valid = (cq->qe_valid) ? 0 : 1; |
| 606 | } |
| 607 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 608 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 609 | * lpfc_sli4_write_cq_db - write cq DB for entries consumed or arm state. |
| 610 | * @phba: the adapter with the CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 611 | * @q: The Completion Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 612 | * @count: the number of elements that were consumed |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 613 | * @arm: Indicates whether the host wants to arms this CQ. |
| 614 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 615 | * This routine will notify the HBA, by ringing the doorbell, that the |
| 616 | * CQEs have been processed. The @arm parameter specifies whether the |
| 617 | * queue should be rearmed when ringing the doorbell. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 618 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 619 | void |
| 620 | lpfc_sli4_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 621 | uint32_t count, bool arm) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 622 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 623 | struct lpfc_register doorbell; |
| 624 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 625 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 626 | if (unlikely(!q || (count == 0 && !arm))) |
| 627 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 628 | |
| 629 | /* ring doorbell for number popped */ |
| 630 | doorbell.word0 = 0; |
| 631 | if (arm) |
| 632 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 633 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 634 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 635 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 636 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 637 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 638 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 642 | * lpfc_sli4_if6_write_cq_db - write cq DB for entries consumed or arm state. |
| 643 | * @phba: the adapter with the CQ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 644 | * @q: The Completion Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 645 | * @count: the number of elements that were consumed |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 646 | * @arm: Indicates whether the host wants to arms this CQ. |
| 647 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 648 | * This routine will notify the HBA, by ringing the doorbell, that the |
| 649 | * CQEs have been processed. The @arm parameter specifies whether the |
| 650 | * queue should be rearmed when ringing the doorbell. |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 651 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 652 | void |
| 653 | lpfc_sli4_if6_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 654 | uint32_t count, bool arm) |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 655 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 656 | struct lpfc_register doorbell; |
| 657 | |
| 658 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 659 | if (unlikely(!q || (count == 0 && !arm))) |
| 660 | return; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 661 | |
| 662 | /* ring doorbell for number popped */ |
| 663 | doorbell.word0 = 0; |
| 664 | if (arm) |
| 665 | bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 666 | bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, count); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 667 | bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id); |
| 668 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 672 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 673 | * @q: The Header Receive Queue to operate on. |
| 674 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 675 | * |
| 676 | * This routine will copy the contents of @wqe to the next available entry on |
| 677 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 678 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 679 | * index that the rqe was copied to if successful. If no entries are available |
| 680 | * on @q then this function will return -ENOMEM. |
| 681 | * The caller is expected to hold the hbalock when calling this routine. |
| 682 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 683 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 684 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 685 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 686 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 687 | struct lpfc_rqe *temp_hrqe; |
| 688 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 689 | struct lpfc_register doorbell; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 690 | int hq_put_index; |
| 691 | int dq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 692 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 693 | /* sanity check on queue memory */ |
| 694 | if (unlikely(!hq) || unlikely(!dq)) |
| 695 | return -ENOMEM; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 696 | hq_put_index = hq->host_index; |
| 697 | dq_put_index = dq->host_index; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 698 | temp_hrqe = lpfc_sli4_qe(hq, hq_put_index); |
| 699 | temp_drqe = lpfc_sli4_qe(dq, dq_put_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 700 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 701 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 702 | return -EINVAL; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 703 | if (hq_put_index != dq_put_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 704 | return -EINVAL; |
| 705 | /* 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] | 706 | if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 707 | return -EBUSY; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 708 | lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 709 | lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 710 | |
| 711 | /* Update the host index to point to the next slot */ |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 712 | hq->host_index = ((hq_put_index + 1) % hq->entry_count); |
| 713 | dq->host_index = ((dq_put_index + 1) % dq->entry_count); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 714 | hq->RQ_buf_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 715 | |
| 716 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 717 | if (!(hq->host_index % hq->notify_interval)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 718 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 719 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 720 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 721 | hq->notify_interval); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 722 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 723 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 724 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 725 | hq->notify_interval); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 726 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 727 | hq->host_index); |
| 728 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 729 | } else { |
| 730 | return -EINVAL; |
| 731 | } |
| 732 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 733 | } |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 734 | return hq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | /** |
| 738 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 739 | * @q: The Header Receive Queue to operate on. |
| 740 | * |
| 741 | * This routine will update the HBA index of a queue to reflect consumption of |
| 742 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 743 | * consumed an entry the host calls this function to update the queue's |
| 744 | * internal pointers. This routine returns the number of entries that were |
| 745 | * consumed by the HBA. |
| 746 | **/ |
| 747 | static uint32_t |
| 748 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 749 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 750 | /* sanity check on queue memory */ |
| 751 | if (unlikely(!hq) || unlikely(!dq)) |
| 752 | return 0; |
| 753 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 754 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 755 | return 0; |
| 756 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 757 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 758 | return 1; |
| 759 | } |
| 760 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 761 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 762 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 763 | * @phba: Pointer to HBA context object. |
| 764 | * @pring: Pointer to driver SLI ring object. |
| 765 | * |
| 766 | * This function returns pointer to next command iocb entry |
| 767 | * in the command ring. The caller must hold hbalock to prevent |
| 768 | * other threads consume the next command iocb. |
| 769 | * SLI-2/SLI-3 provide different sized iocbs. |
| 770 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 771 | static inline IOCB_t * |
| 772 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 773 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 774 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 775 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 776 | } |
| 777 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 778 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 779 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 780 | * @phba: Pointer to HBA context object. |
| 781 | * @pring: Pointer to driver SLI ring object. |
| 782 | * |
| 783 | * This function returns pointer to next response iocb entry |
| 784 | * in the response ring. The caller must hold hbalock to make sure |
| 785 | * that no other thread consume the next response iocb. |
| 786 | * SLI-2/SLI-3 provide different sized iocbs. |
| 787 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 788 | static inline IOCB_t * |
| 789 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 790 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 791 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 792 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 793 | } |
| 794 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 795 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 796 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 797 | * @phba: Pointer to HBA context object. |
| 798 | * |
| 799 | * This function is called with hbalock held. This function |
| 800 | * allocates a new driver iocb object from the iocb pool. If the |
| 801 | * allocation is successful, it returns pointer to the newly |
| 802 | * allocated iocb object else it returns NULL. |
| 803 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 804 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 805 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 806 | { |
| 807 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 808 | struct lpfc_iocbq * iocbq = NULL; |
| 809 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 810 | lockdep_assert_held(&phba->hbalock); |
| 811 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 812 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 813 | if (iocbq) |
| 814 | phba->iocb_cnt++; |
| 815 | if (phba->iocb_cnt > phba->iocb_max) |
| 816 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 817 | return iocbq; |
| 818 | } |
| 819 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 820 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 821 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 822 | * @phba: Pointer to HBA context object. |
| 823 | * @xritag: XRI value. |
| 824 | * |
| 825 | * This function clears the sglq pointer from the array of acive |
| 826 | * sglq's. The xritag that is passed in is used to index into the |
| 827 | * array. Before the xritag can be used it needs to be adjusted |
| 828 | * by subtracting the xribase. |
| 829 | * |
| 830 | * Returns sglq ponter = success, NULL = Failure. |
| 831 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 832 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 833 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 834 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 835 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 836 | |
| 837 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 838 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 839 | return sglq; |
| 840 | } |
| 841 | |
| 842 | /** |
| 843 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 844 | * @phba: Pointer to HBA context object. |
| 845 | * @xritag: XRI value. |
| 846 | * |
| 847 | * This function returns the sglq pointer from the array of acive |
| 848 | * sglq's. The xritag that is passed in is used to index into the |
| 849 | * array. Before the xritag can be used it needs to be adjusted |
| 850 | * by subtracting the xribase. |
| 851 | * |
| 852 | * Returns sglq ponter = success, NULL = Failure. |
| 853 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 854 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 855 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 856 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 857 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 858 | |
| 859 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 860 | return sglq; |
| 861 | } |
| 862 | |
| 863 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 864 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 865 | * @phba: Pointer to HBA context object. |
| 866 | * @xritag: xri used in this exchange. |
| 867 | * @rrq: The RRQ to be cleared. |
| 868 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 869 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 870 | void |
| 871 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 872 | uint16_t xritag, |
| 873 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 874 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 875 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 876 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 877 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 878 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 879 | |
| 880 | /* The target DID could have been swapped (cable swap) |
| 881 | * we should use the ndlp from the findnode if it is |
| 882 | * available. |
| 883 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 884 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 885 | ndlp = rrq->ndlp; |
| 886 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 887 | if (!ndlp) |
| 888 | goto out; |
| 889 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 890 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 891 | rrq->send_rrq = 0; |
| 892 | rrq->xritag = 0; |
| 893 | rrq->rrq_stop_time = 0; |
| 894 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 895 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 896 | mempool_free(rrq, phba->rrq_pool); |
| 897 | } |
| 898 | |
| 899 | /** |
| 900 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 901 | * @phba: Pointer to HBA context object. |
| 902 | * |
| 903 | * This function is called with hbalock held. This function |
| 904 | * Checks if stop_time (ratov from setting rrq active) has |
| 905 | * been reached, if it has and the send_rrq flag is set then |
| 906 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 907 | * then it will just call the routine to clear the rrq and |
| 908 | * free the rrq resource. |
| 909 | * The timer is set to the next rrq that is going to expire before |
| 910 | * leaving the routine. |
| 911 | * |
| 912 | **/ |
| 913 | void |
| 914 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 915 | { |
| 916 | struct lpfc_node_rrq *rrq; |
| 917 | struct lpfc_node_rrq *nextrrq; |
| 918 | unsigned long next_time; |
| 919 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 920 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 921 | |
| 922 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 923 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 924 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 925 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 926 | &phba->active_rrq_list, list) { |
| 927 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 928 | list_move(&rrq->list, &send_rrq); |
| 929 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 930 | next_time = rrq->rrq_stop_time; |
| 931 | } |
| 932 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 933 | if ((!list_empty(&phba->active_rrq_list)) && |
| 934 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 935 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 936 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 937 | list_del(&rrq->list); |
Bart Van Assche | ffd4381 | 2019-03-28 11:06:17 -0700 | [diff] [blame] | 938 | if (!rrq->send_rrq) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 939 | /* this call will free the rrq */ |
Bart Van Assche | ffd4381 | 2019-03-28 11:06:17 -0700 | [diff] [blame] | 940 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 941 | } else if (lpfc_send_rrq(phba, rrq)) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 942 | /* if we send the rrq then the completion handler |
| 943 | * will clear the bit in the xribitmap. |
| 944 | */ |
| 945 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 946 | rrq); |
| 947 | } |
| 948 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | /** |
| 952 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 953 | * @vport: Pointer to vport context object. |
| 954 | * @xri: The xri used in the exchange. |
| 955 | * @did: The targets DID for this exchange. |
| 956 | * |
| 957 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 958 | * rrq = rrq for this xri and target. |
| 959 | **/ |
| 960 | struct lpfc_node_rrq * |
| 961 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 962 | { |
| 963 | struct lpfc_hba *phba = vport->phba; |
| 964 | struct lpfc_node_rrq *rrq; |
| 965 | struct lpfc_node_rrq *nextrrq; |
| 966 | unsigned long iflags; |
| 967 | |
| 968 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 969 | return NULL; |
| 970 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 971 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 972 | if (rrq->vport == vport && rrq->xritag == xri && |
| 973 | rrq->nlp_DID == did){ |
| 974 | list_del(&rrq->list); |
| 975 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 976 | return rrq; |
| 977 | } |
| 978 | } |
| 979 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 980 | return NULL; |
| 981 | } |
| 982 | |
| 983 | /** |
| 984 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 985 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 986 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 987 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 988 | * phba->active_rrq_list and clear the rrq. |
| 989 | * 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] | 990 | **/ |
| 991 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 992 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 993 | |
| 994 | { |
| 995 | struct lpfc_hba *phba = vport->phba; |
| 996 | struct lpfc_node_rrq *rrq; |
| 997 | struct lpfc_node_rrq *nextrrq; |
| 998 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 999 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1000 | |
| 1001 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 1002 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1003 | if (!ndlp) { |
| 1004 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 1005 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1006 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1007 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1008 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 1009 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 1010 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1011 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1012 | |
| 1013 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 1014 | list_del(&rrq->list); |
| 1015 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1016 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1020 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1021 | * @phba: Pointer to HBA context object. |
| 1022 | * @ndlp: Targets nodelist pointer for this exchange. |
| 1023 | * @xritag the xri in the bitmap to test. |
| 1024 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1025 | * This function returns: |
| 1026 | * 0 = rrq not active for this xri |
| 1027 | * 1 = rrq is valid for this xri. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1028 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1029 | int |
| 1030 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1031 | uint16_t xritag) |
| 1032 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1033 | if (!ndlp) |
| 1034 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1035 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1036 | return 0; |
| 1037 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
Colin Ian King | 258f84f | 2019-02-12 15:29:45 +0000 | [diff] [blame] | 1038 | return 1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1039 | else |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
| 1043 | /** |
| 1044 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 1045 | * @phba: Pointer to HBA context object. |
| 1046 | * @ndlp: nodelist pointer for this target. |
| 1047 | * @xritag: xri used in this exchange. |
| 1048 | * @rxid: Remote Exchange ID. |
| 1049 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 1050 | * |
| 1051 | * This function takes the hbalock. |
| 1052 | * The active bit is always set in the active rrq xri_bitmap even |
| 1053 | * if there is no slot avaiable for the other rrq information. |
| 1054 | * |
| 1055 | * returns 0 rrq actived for this xri |
| 1056 | * < 0 No memory or invalid ndlp. |
| 1057 | **/ |
| 1058 | int |
| 1059 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1060 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1061 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1062 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1063 | struct lpfc_node_rrq *rrq; |
| 1064 | int empty; |
| 1065 | |
| 1066 | if (!ndlp) |
| 1067 | return -EINVAL; |
| 1068 | |
| 1069 | if (!phba->cfg_enable_rrq) |
| 1070 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1071 | |
| 1072 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1073 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1074 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 1075 | goto out; |
| 1076 | } |
| 1077 | |
| 1078 | /* |
| 1079 | * set the active bit even if there is no mem available. |
| 1080 | */ |
| 1081 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 1082 | goto out; |
| 1083 | |
| 1084 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 1085 | goto out; |
| 1086 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1087 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1088 | goto out; |
| 1089 | |
| 1090 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1091 | goto out; |
| 1092 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1093 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1094 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 1095 | if (!rrq) { |
| 1096 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1097 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 1098 | " DID:0x%x Send:%d\n", |
| 1099 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1100 | return -EINVAL; |
| 1101 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 1102 | if (phba->cfg_enable_rrq == 1) |
| 1103 | rrq->send_rrq = send_rrq; |
| 1104 | else |
| 1105 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1106 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1107 | rrq->rrq_stop_time = jiffies + |
| 1108 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1109 | rrq->ndlp = ndlp; |
| 1110 | rrq->nlp_DID = ndlp->nlp_DID; |
| 1111 | rrq->vport = ndlp->vport; |
| 1112 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1113 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1114 | empty = list_empty(&phba->active_rrq_list); |
| 1115 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 1116 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1117 | if (empty) |
| 1118 | lpfc_worker_wake_up(phba); |
| 1119 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1120 | return 0; |
| 1121 | out: |
| 1122 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1123 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1124 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 1125 | " DID:0x%x Send:%d\n", |
| 1126 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1127 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1131 | * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1132 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1133 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1134 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1135 | * The driver calls this function with either the nvme ls ring lock |
| 1136 | * or the fc els ring lock held depending on the iocb usage. This function |
| 1137 | * gets a new driver sglq object from the sglq list. If the list is not empty |
| 1138 | * then it is successful, it returns pointer to the newly allocated sglq |
| 1139 | * object else it returns NULL. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1140 | **/ |
| 1141 | static struct lpfc_sglq * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1142 | __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] | 1143 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1144 | 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] | 1145 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1146 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1147 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1148 | struct lpfc_nodelist *ndlp; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1149 | struct lpfc_sli_ring *pring = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1150 | int found = 0; |
| 1151 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1152 | if (piocbq->iocb_flag & LPFC_IO_NVME_LS) |
| 1153 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 1154 | else |
| 1155 | pring = lpfc_phba_elsring(phba); |
| 1156 | |
| 1157 | lockdep_assert_held(&pring->ring_lock); |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1158 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1159 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1160 | lpfc_cmd = (struct lpfc_io_buf *) piocbq->context1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1161 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 1162 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1163 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1164 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1165 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 1166 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 1167 | ndlp = NULL; |
| 1168 | else |
| 1169 | ndlp = piocbq->context_un.ndlp; |
| 1170 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1171 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1172 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1173 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1174 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 1175 | list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1176 | start_sglq = sglq; |
| 1177 | while (!found) { |
| 1178 | if (!sglq) |
James Smart | d11f54b | 2017-03-04 09:30:24 -0800 | [diff] [blame] | 1179 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1180 | if (ndlp && ndlp->active_rrqs_xri_bitmap && |
| 1181 | test_bit(sglq->sli4_lxritag, |
| 1182 | ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1183 | /* This xri has an rrq outstanding for this DID. |
| 1184 | * put it back in the list and get another xri. |
| 1185 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1186 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1187 | sglq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1188 | list_remove_head(lpfc_els_sgl_list, sglq, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1189 | struct lpfc_sglq, list); |
| 1190 | if (sglq == start_sglq) { |
James Smart | 14041bd | 2017-06-01 21:07:01 -0700 | [diff] [blame] | 1191 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1192 | sglq = NULL; |
| 1193 | break; |
| 1194 | } else |
| 1195 | continue; |
| 1196 | } |
| 1197 | sglq->ndlp = ndlp; |
| 1198 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1199 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1200 | sglq->state = SGL_ALLOCATED; |
| 1201 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1202 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1203 | return sglq; |
| 1204 | } |
| 1205 | |
| 1206 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1207 | * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool |
| 1208 | * @phba: Pointer to HBA context object. |
| 1209 | * @piocb: Pointer to the iocbq. |
| 1210 | * |
| 1211 | * This function is called with the sgl_list lock held. This function |
| 1212 | * gets a new driver sglq object from the sglq list. If the |
| 1213 | * list is not empty then it is successful, it returns pointer to the newly |
| 1214 | * allocated sglq object else it returns NULL. |
| 1215 | **/ |
| 1216 | struct lpfc_sglq * |
| 1217 | __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
| 1218 | { |
| 1219 | struct list_head *lpfc_nvmet_sgl_list; |
| 1220 | struct lpfc_sglq *sglq = NULL; |
| 1221 | |
| 1222 | lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list; |
| 1223 | |
| 1224 | lockdep_assert_held(&phba->sli4_hba.sgl_list_lock); |
| 1225 | |
| 1226 | list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list); |
| 1227 | if (!sglq) |
| 1228 | return NULL; |
| 1229 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
| 1230 | sglq->state = SGL_ALLOCATED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1231 | return sglq; |
| 1232 | } |
| 1233 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1234 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1235 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1236 | * @phba: Pointer to HBA context object. |
| 1237 | * |
| 1238 | * This function is called with no lock held. This function |
| 1239 | * allocates a new driver iocb object from the iocb pool. If the |
| 1240 | * allocation is successful, it returns pointer to the newly |
| 1241 | * allocated iocb object else it returns NULL. |
| 1242 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1243 | struct lpfc_iocbq * |
| 1244 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1245 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1246 | struct lpfc_iocbq * iocbq = NULL; |
| 1247 | unsigned long iflags; |
| 1248 | |
| 1249 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1250 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 1251 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1252 | return iocbq; |
| 1253 | } |
| 1254 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1255 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1256 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 1257 | * @phba: Pointer to HBA context object. |
| 1258 | * @iocbq: Pointer to driver iocb object. |
| 1259 | * |
| 1260 | * This function is called with hbalock held to release driver |
| 1261 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1262 | * does not change for each use of the iocb object. This function |
| 1263 | * clears all other fields of the iocb object when it is freed. |
| 1264 | * The sqlq structure that holds the xritag and phys and virtual |
| 1265 | * mappings for the scatter gather list is retrieved from the |
| 1266 | * active array of sglq. The get of the sglq pointer also clears |
| 1267 | * the entry in the array. If the status of the IO indiactes that |
| 1268 | * this IO was aborted then the sglq entry it put on the |
| 1269 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1270 | * 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] | 1271 | * entry is added to the free list (lpfc_els_sgl_list). |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1272 | **/ |
| 1273 | static void |
| 1274 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1275 | { |
| 1276 | struct lpfc_sglq *sglq; |
| 1277 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1278 | unsigned long iflag = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1279 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1280 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1281 | lockdep_assert_held(&phba->hbalock); |
| 1282 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1283 | if (iocbq->sli4_xritag == NO_XRI) |
| 1284 | sglq = NULL; |
| 1285 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1286 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1287 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1288 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1289 | if (sglq) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1290 | if (iocbq->iocb_flag & LPFC_IO_NVMET) { |
| 1291 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1292 | iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1293 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1294 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1295 | list_add_tail(&sglq->list, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1296 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 1297 | spin_unlock_irqrestore( |
| 1298 | &phba->sli4_hba.sgl_list_lock, iflag); |
| 1299 | goto out; |
| 1300 | } |
| 1301 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1302 | pring = phba->sli4_hba.els_wq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1303 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1304 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1305 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1306 | iflag); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1307 | list_add(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1308 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1309 | spin_unlock_irqrestore( |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1310 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1311 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1312 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1313 | iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1314 | sglq->state = SGL_FREED; |
| 1315 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1316 | list_add_tail(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1317 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1318 | spin_unlock_irqrestore( |
| 1319 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1320 | |
| 1321 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1322 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1323 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1324 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1325 | } |
| 1326 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1327 | out: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1328 | /* |
| 1329 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1330 | */ |
| 1331 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1332 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1333 | iocbq->sli4_xritag = NO_XRI; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1334 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | |
| 1335 | LPFC_IO_NVME_LS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1336 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1337 | } |
| 1338 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1339 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1340 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1341 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1342 | * @phba: Pointer to HBA context object. |
| 1343 | * @iocbq: Pointer to driver iocb object. |
| 1344 | * |
| 1345 | * This function is called with hbalock held to release driver |
| 1346 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1347 | * does not change for each use of the iocb object. This function |
| 1348 | * clears all other fields of the iocb object when it is freed. |
| 1349 | **/ |
| 1350 | static void |
| 1351 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1352 | { |
| 1353 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1354 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1355 | lockdep_assert_held(&phba->hbalock); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1356 | |
| 1357 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1358 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1359 | */ |
| 1360 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1361 | iocbq->sli4_xritag = NO_XRI; |
| 1362 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1363 | } |
| 1364 | |
| 1365 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1366 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1367 | * @phba: Pointer to HBA context object. |
| 1368 | * @iocbq: Pointer to driver iocb object. |
| 1369 | * |
| 1370 | * This function is called with hbalock held to release driver |
| 1371 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1372 | * does not change for each use of the iocb object. This function |
| 1373 | * clears all other fields of the iocb object when it is freed. |
| 1374 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1375 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1376 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1377 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1378 | lockdep_assert_held(&phba->hbalock); |
| 1379 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1380 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1381 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1382 | } |
| 1383 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1384 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1385 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1386 | * @phba: Pointer to HBA context object. |
| 1387 | * @iocbq: Pointer to driver iocb object. |
| 1388 | * |
| 1389 | * This function is called with no lock held to release the iocb to |
| 1390 | * iocb pool. |
| 1391 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1392 | void |
| 1393 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1394 | { |
| 1395 | unsigned long iflags; |
| 1396 | |
| 1397 | /* |
| 1398 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1399 | */ |
| 1400 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1401 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1402 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1403 | } |
| 1404 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1405 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1406 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1407 | * @phba: Pointer to HBA context object. |
| 1408 | * @iocblist: List of IOCBs. |
| 1409 | * @ulpstatus: ULP status in IOCB command field. |
| 1410 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1411 | * |
| 1412 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1413 | * on the list by invoking the complete callback function associated with the |
| 1414 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1415 | * fields. |
| 1416 | **/ |
| 1417 | void |
| 1418 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1419 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1420 | { |
| 1421 | struct lpfc_iocbq *piocb; |
| 1422 | |
| 1423 | while (!list_empty(iocblist)) { |
| 1424 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | 84f2ddf | 2019-08-14 16:56:55 -0700 | [diff] [blame] | 1425 | if (!piocb->iocb_cmpl) { |
| 1426 | if (piocb->iocb_flag & LPFC_IO_NVME) |
| 1427 | lpfc_nvme_cancel_iocb(phba, piocb); |
| 1428 | else |
| 1429 | lpfc_sli_release_iocbq(phba, piocb); |
| 1430 | } else { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1431 | piocb->iocb.ulpStatus = ulpstatus; |
| 1432 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1433 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1434 | } |
| 1435 | } |
| 1436 | return; |
| 1437 | } |
| 1438 | |
| 1439 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1440 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1441 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1442 | * |
| 1443 | * This function is called by ring event handler function to get the iocb type. |
| 1444 | * This function translates the iocb command to an iocb command type used to |
| 1445 | * decide the final disposition of each completed IOCB. |
| 1446 | * The function returns |
| 1447 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1448 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1449 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1450 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1451 | * |
| 1452 | * The caller is not required to hold any lock. |
| 1453 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1454 | static lpfc_iocb_type |
| 1455 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1456 | { |
| 1457 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1458 | |
| 1459 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1460 | return 0; |
| 1461 | |
| 1462 | switch (iocb_cmnd) { |
| 1463 | case CMD_XMIT_SEQUENCE_CR: |
| 1464 | case CMD_XMIT_SEQUENCE_CX: |
| 1465 | case CMD_XMIT_BCAST_CN: |
| 1466 | case CMD_XMIT_BCAST_CX: |
| 1467 | case CMD_ELS_REQUEST_CR: |
| 1468 | case CMD_ELS_REQUEST_CX: |
| 1469 | case CMD_CREATE_XRI_CR: |
| 1470 | case CMD_CREATE_XRI_CX: |
| 1471 | case CMD_GET_RPI_CN: |
| 1472 | case CMD_XMIT_ELS_RSP_CX: |
| 1473 | case CMD_GET_RPI_CR: |
| 1474 | case CMD_FCP_IWRITE_CR: |
| 1475 | case CMD_FCP_IWRITE_CX: |
| 1476 | case CMD_FCP_IREAD_CR: |
| 1477 | case CMD_FCP_IREAD_CX: |
| 1478 | case CMD_FCP_ICMND_CR: |
| 1479 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1480 | case CMD_FCP_TSEND_CX: |
| 1481 | case CMD_FCP_TRSP_CX: |
| 1482 | case CMD_FCP_TRECEIVE_CX: |
| 1483 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1484 | case CMD_ADAPTER_MSG: |
| 1485 | case CMD_ADAPTER_DUMP: |
| 1486 | case CMD_XMIT_SEQUENCE64_CR: |
| 1487 | case CMD_XMIT_SEQUENCE64_CX: |
| 1488 | case CMD_XMIT_BCAST64_CN: |
| 1489 | case CMD_XMIT_BCAST64_CX: |
| 1490 | case CMD_ELS_REQUEST64_CR: |
| 1491 | case CMD_ELS_REQUEST64_CX: |
| 1492 | case CMD_FCP_IWRITE64_CR: |
| 1493 | case CMD_FCP_IWRITE64_CX: |
| 1494 | case CMD_FCP_IREAD64_CR: |
| 1495 | case CMD_FCP_IREAD64_CX: |
| 1496 | case CMD_FCP_ICMND64_CR: |
| 1497 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1498 | case CMD_FCP_TSEND64_CX: |
| 1499 | case CMD_FCP_TRSP64_CX: |
| 1500 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1501 | case CMD_GEN_REQUEST64_CR: |
| 1502 | case CMD_GEN_REQUEST64_CX: |
| 1503 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1504 | case DSSCMD_IWRITE64_CR: |
| 1505 | case DSSCMD_IWRITE64_CX: |
| 1506 | case DSSCMD_IREAD64_CR: |
| 1507 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1508 | type = LPFC_SOL_IOCB; |
| 1509 | break; |
| 1510 | case CMD_ABORT_XRI_CN: |
| 1511 | case CMD_ABORT_XRI_CX: |
| 1512 | case CMD_CLOSE_XRI_CN: |
| 1513 | case CMD_CLOSE_XRI_CX: |
| 1514 | case CMD_XRI_ABORTED_CX: |
| 1515 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1516 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1517 | type = LPFC_ABORT_IOCB; |
| 1518 | break; |
| 1519 | case CMD_RCV_SEQUENCE_CX: |
| 1520 | case CMD_RCV_ELS_REQ_CX: |
| 1521 | case CMD_RCV_SEQUENCE64_CX: |
| 1522 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1523 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1524 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1525 | case CMD_IOCB_RCV_ELS64_CX: |
| 1526 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1527 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1528 | type = LPFC_UNSOL_IOCB; |
| 1529 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1530 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1531 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1532 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1533 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1534 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1535 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1536 | case CMD_IOCB_RET_HBQE64_CN: |
| 1537 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1538 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1539 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1540 | case CMD_IOCB_LOGENTRY_CN: |
| 1541 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1542 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1543 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1544 | type = LPFC_UNKNOWN_IOCB; |
| 1545 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1546 | default: |
| 1547 | type = LPFC_UNKNOWN_IOCB; |
| 1548 | break; |
| 1549 | } |
| 1550 | |
| 1551 | return type; |
| 1552 | } |
| 1553 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1554 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1555 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1556 | * @phba: Pointer to HBA context object. |
| 1557 | * |
| 1558 | * This function is called from SLI initialization code |
| 1559 | * to configure every ring of the HBA's SLI interface. The |
| 1560 | * caller is not required to hold any lock. This function issues |
| 1561 | * a config_ring mailbox command for each ring. |
| 1562 | * This function returns zero if successful else returns a negative |
| 1563 | * error code. |
| 1564 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1565 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1566 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1567 | { |
| 1568 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1569 | LPFC_MBOXQ_t *pmb; |
| 1570 | MAILBOX_t *pmbox; |
| 1571 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1572 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1573 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1574 | if (!pmb) |
| 1575 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1576 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1577 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1578 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1579 | lpfc_config_ring(phba, i, pmb); |
| 1580 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1581 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1582 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1583 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1584 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1585 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1586 | rc, pmbox->mbxCommand, |
| 1587 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1588 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1589 | ret = -ENXIO; |
| 1590 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1591 | } |
| 1592 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1593 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1594 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1595 | } |
| 1596 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1597 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1598 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1599 | * @phba: Pointer to HBA context object. |
| 1600 | * @pring: Pointer to driver SLI ring object. |
| 1601 | * @piocb: Pointer to the driver iocb object. |
| 1602 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1603 | * The driver calls this function with the hbalock held for SLI3 ports or |
| 1604 | * the ring lock held for SLI4 ports. The function adds the |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1605 | * new iocb to txcmplq of the given ring. This function always returns |
| 1606 | * 0. If this function is called for ELS ring, this function checks if |
| 1607 | * there is a vport associated with the ELS command. This function also |
| 1608 | * starts els_tmofunc timer if this is an ELS command. |
| 1609 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1610 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1611 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1612 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1613 | { |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1614 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1615 | lockdep_assert_held(&pring->ring_lock); |
| 1616 | else |
| 1617 | lockdep_assert_held(&phba->hbalock); |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1618 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1619 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1620 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1621 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1622 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1623 | pring->txcmplq_cnt++; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1624 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1625 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1626 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1627 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1628 | BUG_ON(!piocb->vport); |
| 1629 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1630 | mod_timer(&piocb->vport->els_tmofunc, |
| 1631 | jiffies + |
| 1632 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 1633 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1634 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1635 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1636 | } |
| 1637 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1638 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1639 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1640 | * @phba: Pointer to HBA context object. |
| 1641 | * @pring: Pointer to driver SLI ring object. |
| 1642 | * |
| 1643 | * This function is called with hbalock held to get next |
| 1644 | * iocb in txq of the given ring. If there is any iocb in |
| 1645 | * the txq, the function returns first iocb in the list after |
| 1646 | * removing the iocb from the list, else it returns NULL. |
| 1647 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1648 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1649 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1650 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1651 | struct lpfc_iocbq *cmd_iocb; |
| 1652 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1653 | lockdep_assert_held(&phba->hbalock); |
| 1654 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1655 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1656 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1657 | } |
| 1658 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1659 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1660 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1661 | * @phba: Pointer to HBA context object. |
| 1662 | * @pring: Pointer to driver SLI ring object. |
| 1663 | * |
| 1664 | * This function is called with hbalock held and the caller must post the |
| 1665 | * iocb without releasing the lock. If the caller releases the lock, |
| 1666 | * iocb slot returned by the function is not guaranteed to be available. |
| 1667 | * The function returns pointer to the next available iocb slot if there |
| 1668 | * is available slot in the ring, else it returns NULL. |
| 1669 | * If the get index of the ring is ahead of the put index, the function |
| 1670 | * will post an error attention event to the worker thread to take the |
| 1671 | * HBA to offline state. |
| 1672 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1673 | static IOCB_t * |
| 1674 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1675 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1676 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1677 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1678 | |
| 1679 | lockdep_assert_held(&phba->hbalock); |
| 1680 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1681 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1682 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1683 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1684 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1685 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1686 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1688 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1689 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1690 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1692 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1693 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1694 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1695 | pring->sli.sli3.local_getidx, |
| 1696 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1697 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1698 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1699 | /* |
| 1700 | * All error attention handlers are posted to |
| 1701 | * worker thread |
| 1702 | */ |
| 1703 | phba->work_ha |= HA_ERATT; |
| 1704 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1705 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1706 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1707 | |
| 1708 | return NULL; |
| 1709 | } |
| 1710 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1711 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1712 | return NULL; |
| 1713 | } |
| 1714 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1715 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1716 | } |
| 1717 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1718 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1719 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1720 | * @phba: Pointer to HBA context object. |
| 1721 | * @iocbq: Pointer to driver iocb object. |
| 1722 | * |
| 1723 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1724 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1725 | * array and assigns a new iotag. |
| 1726 | * The function returns the allocated iotag if successful, else returns zero. |
| 1727 | * Zero is not a valid iotag. |
| 1728 | * The caller is not required to hold any lock. |
| 1729 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1730 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1731 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1732 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1733 | struct lpfc_iocbq **new_arr; |
| 1734 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1735 | size_t new_len; |
| 1736 | struct lpfc_sli *psli = &phba->sli; |
| 1737 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1738 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1739 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1740 | iotag = psli->last_iotag; |
| 1741 | if(++iotag < psli->iocbq_lookup_len) { |
| 1742 | psli->last_iotag = iotag; |
| 1743 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1744 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1745 | iocbq->iotag = iotag; |
| 1746 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1747 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1748 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1749 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1750 | spin_unlock_irq(&phba->hbalock); |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1751 | new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1752 | GFP_KERNEL); |
| 1753 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1754 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1755 | old_arr = psli->iocbq_lookup; |
| 1756 | if (new_len <= psli->iocbq_lookup_len) { |
| 1757 | /* highly unprobable case */ |
| 1758 | kfree(new_arr); |
| 1759 | iotag = psli->last_iotag; |
| 1760 | if(++iotag < psli->iocbq_lookup_len) { |
| 1761 | psli->last_iotag = iotag; |
| 1762 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1763 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1764 | iocbq->iotag = iotag; |
| 1765 | return iotag; |
| 1766 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1767 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1768 | return 0; |
| 1769 | } |
| 1770 | if (psli->iocbq_lookup) |
| 1771 | memcpy(new_arr, old_arr, |
| 1772 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1773 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1774 | psli->iocbq_lookup = new_arr; |
| 1775 | psli->iocbq_lookup_len = new_len; |
| 1776 | psli->last_iotag = iotag; |
| 1777 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1778 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1779 | iocbq->iotag = iotag; |
| 1780 | kfree(old_arr); |
| 1781 | return iotag; |
| 1782 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1783 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1784 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1785 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1786 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1787 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1788 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1789 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1790 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1791 | } |
| 1792 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1793 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1794 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1795 | * @phba: Pointer to HBA context object. |
| 1796 | * @pring: Pointer to driver SLI ring object. |
| 1797 | * @iocb: Pointer to iocb slot in the ring. |
| 1798 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1799 | * posted to firmware. |
| 1800 | * |
| 1801 | * This function is called with hbalock held to post a new iocb to |
| 1802 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1803 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1804 | * a completion call back for this iocb else the function will free the |
| 1805 | * iocb object. |
| 1806 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1807 | static void |
| 1808 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1809 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1810 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1811 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1812 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1813 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1814 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1815 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1816 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1817 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1818 | if (pring->ringno == LPFC_ELS_RING) { |
| 1819 | lpfc_debugfs_slow_ring_trc(phba, |
| 1820 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1821 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1822 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1823 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1824 | } |
| 1825 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1826 | /* |
| 1827 | * Issue iocb command to adapter |
| 1828 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1829 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1830 | wmb(); |
| 1831 | pring->stats.iocb_cmd++; |
| 1832 | |
| 1833 | /* |
| 1834 | * If there is no completion routine to call, we can release the |
| 1835 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1836 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1837 | */ |
| 1838 | if (nextiocb->iocb_cmpl) |
| 1839 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1840 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1841 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1842 | |
| 1843 | /* |
| 1844 | * Let the HBA know what IOCB slot will be the next one the |
| 1845 | * driver will put a command into. |
| 1846 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1847 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1848 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 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_full_ring - Update the 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 | * The caller is not required to hold any lock for calling this function. |
| 1857 | * This function updates the chip attention bits for the ring to inform firmware |
| 1858 | * that there are pending work to be done for this ring and requests an |
| 1859 | * interrupt when there is space available in the ring. This function is |
| 1860 | * called when the driver is unable to post more iocbs to the ring due |
| 1861 | * to unavailability of space in the ring. |
| 1862 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1863 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1864 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1865 | { |
| 1866 | int ringno = pring->ringno; |
| 1867 | |
| 1868 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1869 | |
| 1870 | wmb(); |
| 1871 | |
| 1872 | /* |
| 1873 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1874 | * The HBA will tell us when an IOCB entry is available. |
| 1875 | */ |
| 1876 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1877 | readl(phba->CAregaddr); /* flush */ |
| 1878 | |
| 1879 | pring->stats.iocb_cmd_full++; |
| 1880 | } |
| 1881 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1882 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1883 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1884 | * @phba: Pointer to HBA context object. |
| 1885 | * @pring: Pointer to driver SLI ring object. |
| 1886 | * |
| 1887 | * This function updates the chip attention register bit for the |
| 1888 | * given ring to inform HBA that there is more work to be done |
| 1889 | * in this ring. The caller is not required to hold any lock. |
| 1890 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1891 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1892 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1893 | { |
| 1894 | int ringno = pring->ringno; |
| 1895 | |
| 1896 | /* |
| 1897 | * Tell the HBA that there is work to do in this ring. |
| 1898 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1899 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1900 | wmb(); |
| 1901 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1902 | readl(phba->CAregaddr); /* flush */ |
| 1903 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1904 | } |
| 1905 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1906 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1907 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1908 | * @phba: Pointer to HBA context object. |
| 1909 | * @pring: Pointer to driver SLI ring object. |
| 1910 | * |
| 1911 | * This function is called with hbalock held to post pending iocbs |
| 1912 | * in the txq to the firmware. This function is called when driver |
| 1913 | * detects space available in the ring. |
| 1914 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1915 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1916 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1917 | { |
| 1918 | IOCB_t *iocb; |
| 1919 | struct lpfc_iocbq *nextiocb; |
| 1920 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1921 | lockdep_assert_held(&phba->hbalock); |
| 1922 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1923 | /* |
| 1924 | * Check to see if: |
| 1925 | * (a) there is anything on the txq to send |
| 1926 | * (b) link is up |
| 1927 | * (c) link attention events can be processed (fcp ring only) |
| 1928 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1929 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1930 | |
| 1931 | if (lpfc_is_link_up(phba) && |
| 1932 | (!list_empty(&pring->txq)) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1933 | (pring->ringno != LPFC_FCP_RING || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1934 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1935 | |
| 1936 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1937 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1938 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1939 | |
| 1940 | if (iocb) |
| 1941 | lpfc_sli_update_ring(phba, pring); |
| 1942 | else |
| 1943 | lpfc_sli_update_full_ring(phba, pring); |
| 1944 | } |
| 1945 | |
| 1946 | return; |
| 1947 | } |
| 1948 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1949 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1950 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1951 | * @phba: Pointer to HBA context object. |
| 1952 | * @hbqno: HBQ number. |
| 1953 | * |
| 1954 | * This function is called with hbalock held to get the next |
| 1955 | * available slot for the given HBQ. If there is free slot |
| 1956 | * available for the HBQ it will return pointer to the next available |
| 1957 | * HBQ entry else it will return NULL. |
| 1958 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1959 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1960 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1961 | { |
| 1962 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1963 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1964 | lockdep_assert_held(&phba->hbalock); |
| 1965 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1966 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1967 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1968 | hbqp->next_hbqPutIdx = 0; |
| 1969 | |
| 1970 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1971 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1972 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1973 | |
| 1974 | hbqp->local_hbqGetIdx = getidx; |
| 1975 | |
| 1976 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1977 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1978 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1979 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1980 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1981 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1982 | hbqp->entry_count); |
| 1983 | |
| 1984 | phba->link_state = LPFC_HBA_ERROR; |
| 1985 | return NULL; |
| 1986 | } |
| 1987 | |
| 1988 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1989 | return NULL; |
| 1990 | } |
| 1991 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1992 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1993 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1994 | } |
| 1995 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1996 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1997 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1998 | * @phba: Pointer to HBA context object. |
| 1999 | * |
| 2000 | * This function is called with no lock held to free all the |
| 2001 | * hbq buffers while uninitializing the SLI interface. It also |
| 2002 | * frees the HBQ buffers returned by the firmware but not yet |
| 2003 | * processed by the upper layers. |
| 2004 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2005 | void |
| 2006 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 2007 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2008 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 2009 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2010 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2011 | int i, hbq_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2012 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2013 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2014 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2015 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2016 | for (i = 0; i < hbq_count; ++i) { |
| 2017 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 2018 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 2019 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 2020 | list_del(&hbq_buf->dbuf.list); |
| 2021 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 2022 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2023 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2024 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2025 | |
| 2026 | /* Mark the HBQs not in use */ |
| 2027 | phba->hbq_in_use = 0; |
| 2028 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2029 | } |
| 2030 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2031 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2032 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2033 | * @phba: Pointer to HBA context object. |
| 2034 | * @hbqno: HBQ number. |
| 2035 | * @hbq_buf: Pointer to HBQ buffer. |
| 2036 | * |
| 2037 | * This function is called with the hbalock held to post a |
| 2038 | * hbq buffer to the firmware. If the function finds an empty |
| 2039 | * slot in the HBQ, it will post the buffer. The function will return |
| 2040 | * pointer to the hbq entry if it successfully post the buffer |
| 2041 | * else it will return NULL. |
| 2042 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2043 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2044 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2045 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2046 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2047 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2048 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 2049 | } |
| 2050 | |
| 2051 | /** |
| 2052 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 2053 | * @phba: Pointer to HBA context object. |
| 2054 | * @hbqno: HBQ number. |
| 2055 | * @hbq_buf: Pointer to HBQ buffer. |
| 2056 | * |
| 2057 | * This function is called with the hbalock held to post a hbq buffer to the |
| 2058 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 2059 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 2060 | * it successfully post the buffer else it will return an error. |
| 2061 | **/ |
| 2062 | static int |
| 2063 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 2064 | struct hbq_dmabuf *hbq_buf) |
| 2065 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2066 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2067 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2068 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2069 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2070 | /* Get next HBQ entry slot to use */ |
| 2071 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 2072 | if (hbqe) { |
| 2073 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 2074 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2075 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 2076 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2077 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2078 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2079 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 2080 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 2081 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2082 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 2083 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2084 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2085 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2086 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2087 | return 0; |
| 2088 | } else |
| 2089 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2090 | } |
| 2091 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2092 | /** |
| 2093 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 2094 | * @phba: Pointer to HBA context object. |
| 2095 | * @hbqno: HBQ number. |
| 2096 | * @hbq_buf: Pointer to HBQ buffer. |
| 2097 | * |
| 2098 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 2099 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 2100 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 2101 | **/ |
| 2102 | static int |
| 2103 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 2104 | struct hbq_dmabuf *hbq_buf) |
| 2105 | { |
| 2106 | int rc; |
| 2107 | struct lpfc_rqe hrqe; |
| 2108 | struct lpfc_rqe drqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2109 | struct lpfc_queue *hrq; |
| 2110 | struct lpfc_queue *drq; |
| 2111 | |
| 2112 | if (hbqno != LPFC_ELS_HBQ) |
| 2113 | return 1; |
| 2114 | hrq = phba->sli4_hba.hdr_rq; |
| 2115 | drq = phba->sli4_hba.dat_rq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2116 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2117 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2118 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 2119 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 2120 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 2121 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2122 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2123 | if (rc < 0) |
| 2124 | return rc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2125 | hbq_buf->tag = (rc | (hbqno << 16)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2126 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 2127 | return 0; |
| 2128 | } |
| 2129 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2130 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2131 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 2132 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2133 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2134 | .mask_count = 0, |
| 2135 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2136 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2137 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2138 | .init_count = 40, |
| 2139 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2140 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2141 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2142 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2143 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2144 | &lpfc_els_hbq, |
| 2145 | }; |
| 2146 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2147 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2148 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2149 | * @phba: Pointer to HBA context object. |
| 2150 | * @hbqno: HBQ number. |
| 2151 | * @count: Number of HBQ buffers to be posted. |
| 2152 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2153 | * This function is called with no lock held to post more hbq buffers to the |
| 2154 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 2155 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2156 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 2157 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2158 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 2159 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2160 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2161 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2162 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2163 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2164 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2165 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2166 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2167 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 2168 | lpfc_hbq_defs[hbqno]->entry_count) |
| 2169 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 2170 | phba->hbqs[hbqno].buffer_count; |
| 2171 | if (!count) |
| 2172 | return 0; |
| 2173 | /* Allocate HBQ entries */ |
| 2174 | for (i = 0; i < count; i++) { |
| 2175 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 2176 | if (!hbq_buffer) |
| 2177 | break; |
| 2178 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 2179 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2180 | /* Check whether HBQ is still in use */ |
| 2181 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2182 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2183 | goto err; |
| 2184 | while (!list_empty(&hbq_buf_list)) { |
| 2185 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2186 | dbuf.list); |
| 2187 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 2188 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2189 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2190 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2191 | posted++; |
| 2192 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2193 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2194 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2195 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2196 | return posted; |
| 2197 | err: |
| 2198 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 2199 | while (!list_empty(&hbq_buf_list)) { |
| 2200 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2201 | dbuf.list); |
| 2202 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 2203 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2204 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2205 | } |
| 2206 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2207 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2208 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2209 | * @phba: Pointer to HBA context object. |
| 2210 | * @qno: HBQ number. |
| 2211 | * |
| 2212 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2213 | * is called with no lock held. The function returns the number of HBQ entries |
| 2214 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2215 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2216 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2217 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2218 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2219 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2220 | return 0; |
| 2221 | else |
| 2222 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2223 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2224 | } |
| 2225 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2226 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2227 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2228 | * @phba: Pointer to HBA context object. |
| 2229 | * @qno: HBQ queue number. |
| 2230 | * |
| 2231 | * This function is called from SLI initialization code path with |
| 2232 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2233 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2234 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2235 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2236 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2237 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2238 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2239 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2240 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2241 | else |
| 2242 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2243 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2244 | } |
| 2245 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2246 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2247 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 2248 | * @phba: Pointer to HBA context object. |
| 2249 | * @hbqno: HBQ number. |
| 2250 | * |
| 2251 | * This function removes the first hbq buffer on an hbq list and returns a |
| 2252 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2253 | **/ |
| 2254 | static struct hbq_dmabuf * |
| 2255 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 2256 | { |
| 2257 | struct lpfc_dmabuf *d_buf; |
| 2258 | |
| 2259 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 2260 | if (!d_buf) |
| 2261 | return NULL; |
| 2262 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2263 | } |
| 2264 | |
| 2265 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2266 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list |
| 2267 | * @phba: Pointer to HBA context object. |
| 2268 | * @hbqno: HBQ number. |
| 2269 | * |
| 2270 | * This function removes the first RQ buffer on an RQ buffer list and returns a |
| 2271 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2272 | **/ |
| 2273 | static struct rqb_dmabuf * |
| 2274 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) |
| 2275 | { |
| 2276 | struct lpfc_dmabuf *h_buf; |
| 2277 | struct lpfc_rqb *rqbp; |
| 2278 | |
| 2279 | rqbp = hrq->rqbp; |
| 2280 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 2281 | struct lpfc_dmabuf, list); |
| 2282 | if (!h_buf) |
| 2283 | return NULL; |
| 2284 | rqbp->buffer_count--; |
| 2285 | return container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 2286 | } |
| 2287 | |
| 2288 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2289 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2290 | * @phba: Pointer to HBA context object. |
| 2291 | * @tag: Tag of the hbq buffer. |
| 2292 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2293 | * This function searches for the hbq buffer associated with the given tag in |
| 2294 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2295 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2296 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2297 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2298 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2299 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2300 | struct lpfc_dmabuf *d_buf; |
| 2301 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2302 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2303 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2304 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2305 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2306 | return NULL; |
| 2307 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2308 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2309 | 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] | 2310 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2311 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2312 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2313 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2314 | } |
| 2315 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2316 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2317 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2318 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2319 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2320 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2321 | } |
| 2322 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2323 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2324 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2325 | * @phba: Pointer to HBA context object. |
| 2326 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2327 | * |
| 2328 | * This function is called with hbalock. This function gives back |
| 2329 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2330 | * post the buffer, it will free the buffer. |
| 2331 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2332 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2333 | 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] | 2334 | { |
| 2335 | uint32_t hbqno; |
| 2336 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2337 | if (hbq_buffer) { |
| 2338 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2339 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2340 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2341 | } |
| 2342 | } |
| 2343 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2344 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2345 | * 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] | 2346 | * @mbxCommand: mailbox command code. |
| 2347 | * |
| 2348 | * This function is called by the mailbox event handler function to verify |
| 2349 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2350 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2351 | * and the mailbox event handler will take the HBA offline. |
| 2352 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2353 | static int |
| 2354 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2355 | { |
| 2356 | uint8_t ret; |
| 2357 | |
| 2358 | switch (mbxCommand) { |
| 2359 | case MBX_LOAD_SM: |
| 2360 | case MBX_READ_NV: |
| 2361 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2362 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | case MBX_RUN_BIU_DIAG: |
| 2364 | case MBX_INIT_LINK: |
| 2365 | case MBX_DOWN_LINK: |
| 2366 | case MBX_CONFIG_LINK: |
| 2367 | case MBX_CONFIG_RING: |
| 2368 | case MBX_RESET_RING: |
| 2369 | case MBX_READ_CONFIG: |
| 2370 | case MBX_READ_RCONFIG: |
| 2371 | case MBX_READ_SPARM: |
| 2372 | case MBX_READ_STATUS: |
| 2373 | case MBX_READ_RPI: |
| 2374 | case MBX_READ_XRI: |
| 2375 | case MBX_READ_REV: |
| 2376 | case MBX_READ_LNK_STAT: |
| 2377 | case MBX_REG_LOGIN: |
| 2378 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2379 | case MBX_CLEAR_LA: |
| 2380 | case MBX_DUMP_MEMORY: |
| 2381 | case MBX_DUMP_CONTEXT: |
| 2382 | case MBX_RUN_DIAGS: |
| 2383 | case MBX_RESTART: |
| 2384 | case MBX_UPDATE_CFG: |
| 2385 | case MBX_DOWN_LOAD: |
| 2386 | case MBX_DEL_LD_ENTRY: |
| 2387 | case MBX_RUN_PROGRAM: |
| 2388 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2389 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2390 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2391 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2392 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2393 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2394 | case MBX_LOAD_AREA: |
| 2395 | case MBX_RUN_BIU_DIAG64: |
| 2396 | case MBX_CONFIG_PORT: |
| 2397 | case MBX_READ_SPARM64: |
| 2398 | case MBX_READ_RPI64: |
| 2399 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2400 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2401 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2402 | case MBX_SET_DEBUG: |
| 2403 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2404 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2405 | case MBX_REG_VPI: |
| 2406 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2407 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2408 | case MBX_PORT_CAPABILITIES: |
| 2409 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2410 | case MBX_SLI4_CONFIG: |
| 2411 | case MBX_SLI4_REQ_FTRS: |
| 2412 | case MBX_REG_FCFI: |
| 2413 | case MBX_UNREG_FCFI: |
| 2414 | case MBX_REG_VFI: |
| 2415 | case MBX_UNREG_VFI: |
| 2416 | case MBX_INIT_VPI: |
| 2417 | case MBX_INIT_VFI: |
| 2418 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2419 | case MBX_READ_EVENT_LOG_STATUS: |
| 2420 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2421 | case MBX_SECURITY_MGMT: |
| 2422 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2423 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2424 | ret = mbxCommand; |
| 2425 | break; |
| 2426 | default: |
| 2427 | ret = MBX_SHUTDOWN; |
| 2428 | break; |
| 2429 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2430 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2431 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2432 | |
| 2433 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2434 | * 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] | 2435 | * @phba: Pointer to HBA context object. |
| 2436 | * @pmboxq: Pointer to mailbox command. |
| 2437 | * |
| 2438 | * This is completion handler function for mailbox commands issued from |
| 2439 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2440 | * mailbox event handler function with no lock held. This function |
| 2441 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2442 | * of the mailbox. |
| 2443 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2444 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2445 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2446 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2447 | unsigned long drvr_flag; |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2448 | struct completion *pmbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2449 | |
| 2450 | /* |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2451 | * If pmbox_done is empty, the driver thread gave up waiting and |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2452 | * continued running. |
| 2453 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2454 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2455 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2456 | pmbox_done = (struct completion *)pmboxq->context3; |
| 2457 | if (pmbox_done) |
| 2458 | complete(pmbox_done); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2459 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2460 | return; |
| 2461 | } |
| 2462 | |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2463 | static void |
| 2464 | __lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 2465 | { |
| 2466 | unsigned long iflags; |
| 2467 | |
| 2468 | if (ndlp->nlp_flag & NLP_RELEASE_RPI) { |
| 2469 | lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi); |
| 2470 | spin_lock_irqsave(&vport->phba->ndlp_lock, iflags); |
| 2471 | ndlp->nlp_flag &= ~NLP_RELEASE_RPI; |
| 2472 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
| 2473 | spin_unlock_irqrestore(&vport->phba->ndlp_lock, iflags); |
| 2474 | } |
| 2475 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 2476 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2477 | |
| 2478 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2479 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2480 | * @phba: Pointer to HBA context object. |
| 2481 | * @pmb: Pointer to mailbox object. |
| 2482 | * |
| 2483 | * This function is the default mailbox completion handler. It |
| 2484 | * frees the memory resources associated with the completed mailbox |
| 2485 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2486 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2487 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2488 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2489 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2490 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2491 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2492 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2493 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2494 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2495 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2496 | int rc; |
| 2497 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2498 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2499 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2500 | if (mp) { |
| 2501 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2502 | kfree(mp); |
| 2503 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2504 | |
| 2505 | /* |
| 2506 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2507 | * is in re-discovery driver need to cleanup the RPI. |
| 2508 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2509 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2510 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2511 | !pmb->u.mb.mbxStatus) { |
| 2512 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2513 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2514 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2515 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2516 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2517 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2518 | if (rc != MBX_NOT_FINISHED) |
| 2519 | return; |
| 2520 | } |
| 2521 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2522 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2523 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2524 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2525 | shost = lpfc_shost_from_vport(vport); |
| 2526 | spin_lock_irq(shost->host_lock); |
| 2527 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2528 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2529 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2530 | } |
| 2531 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2532 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2533 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2534 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2535 | pmb->ctx_buf = NULL; |
| 2536 | pmb->ctx_ndlp = NULL; |
| 2537 | } |
| 2538 | |
| 2539 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2540 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 2541 | |
| 2542 | /* Check to see if there are any deferred events to process */ |
| 2543 | if (ndlp) { |
| 2544 | lpfc_printf_vlog( |
| 2545 | vport, |
| 2546 | KERN_INFO, LOG_MBOX | LOG_DISCOVERY, |
| 2547 | "1438 UNREG cmpl deferred mbox x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2548 | "on NPort x%x Data: x%x x%x %px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2549 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2550 | ndlp->nlp_flag, ndlp->nlp_defer_did, ndlp); |
| 2551 | |
| 2552 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2553 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2554 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2555 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
| 2556 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2557 | } else { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2558 | __lpfc_sli_rpi_release(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2559 | } |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 2560 | if (vport->load_flag & FC_UNLOADING) |
| 2561 | lpfc_nlp_put(ndlp); |
James Smart | 9b16406 | 2019-03-12 16:30:06 -0700 | [diff] [blame] | 2562 | pmb->ctx_ndlp = NULL; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2563 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2564 | } |
| 2565 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2566 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2567 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2568 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2569 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2570 | "2860 SLI authentication is required " |
| 2571 | "for INIT_LINK but has not done yet\n"); |
| 2572 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2573 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2574 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2575 | else |
| 2576 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2577 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2578 | /** |
| 2579 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2580 | * @phba: Pointer to HBA context object. |
| 2581 | * @pmb: Pointer to mailbox object. |
| 2582 | * |
| 2583 | * This function is the unreg rpi mailbox completion handler. It |
| 2584 | * frees the memory resources associated with the completed mailbox |
| 2585 | * command. An additional refrenece is put on the ndlp to prevent |
| 2586 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2587 | * the unreg mailbox command completes, this routine puts the |
| 2588 | * reference back. |
| 2589 | * |
| 2590 | **/ |
| 2591 | void |
| 2592 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2593 | { |
| 2594 | struct lpfc_vport *vport = pmb->vport; |
| 2595 | struct lpfc_nodelist *ndlp; |
| 2596 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2597 | ndlp = pmb->ctx_ndlp; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2598 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2599 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2600 | (bf_get(lpfc_sli_intf_if_type, |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 2601 | &phba->sli4_hba.sli_intf) >= |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2602 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2603 | if (ndlp) { |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2604 | lpfc_printf_vlog( |
| 2605 | vport, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 2606 | "0010 UNREG_LOGIN vpi:%x " |
| 2607 | "rpi:%x DID:%x defer x%x flg x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2608 | "map:%x %px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2609 | vport->vpi, ndlp->nlp_rpi, |
| 2610 | ndlp->nlp_DID, ndlp->nlp_defer_did, |
| 2611 | ndlp->nlp_flag, |
| 2612 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2613 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2614 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2615 | |
| 2616 | /* Check to see if there are any deferred |
| 2617 | * events to process |
| 2618 | */ |
| 2619 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2620 | (ndlp->nlp_defer_did != |
| 2621 | NLP_EVT_NOTHING_PENDING)) { |
| 2622 | lpfc_printf_vlog( |
| 2623 | vport, KERN_INFO, LOG_DISCOVERY, |
| 2624 | "4111 UNREG cmpl deferred " |
| 2625 | "clr x%x on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2626 | "NPort x%x Data: x%x x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2627 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2628 | ndlp->nlp_defer_did, ndlp); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2629 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2630 | ndlp->nlp_defer_did = |
| 2631 | NLP_EVT_NOTHING_PENDING; |
| 2632 | lpfc_issue_els_plogi( |
| 2633 | vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2634 | } else { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2635 | __lpfc_sli_rpi_release(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2636 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2637 | } |
| 2638 | } |
| 2639 | } |
| 2640 | |
| 2641 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2642 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2643 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2644 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2645 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2646 | * @phba: Pointer to HBA context object. |
| 2647 | * |
| 2648 | * This function is called with no lock held. This function processes all |
| 2649 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2650 | * service routine processes mailbox completion interrupt and adds completed |
| 2651 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2652 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2653 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2654 | * function returns the mailbox commands to the upper layer by calling the |
| 2655 | * completion handler function of each mailbox. |
| 2656 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2657 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2658 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2659 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2660 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2661 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2662 | int rc; |
| 2663 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2664 | |
| 2665 | phba->sli.slistat.mbox_event++; |
| 2666 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2667 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2668 | spin_lock_irq(&phba->hbalock); |
| 2669 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2670 | spin_unlock_irq(&phba->hbalock); |
| 2671 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2672 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2673 | do { |
| 2674 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2675 | if (pmb == NULL) |
| 2676 | break; |
| 2677 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2678 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2679 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2680 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2681 | if (pmb->vport) { |
| 2682 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2683 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2684 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2685 | (uint32_t)pmbox->mbxCommand, |
| 2686 | pmbox->un.varWords[0], |
| 2687 | pmbox->un.varWords[1]); |
| 2688 | } |
| 2689 | else { |
| 2690 | lpfc_debugfs_disc_trc(phba->pport, |
| 2691 | LPFC_DISC_TRC_MBOX, |
| 2692 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2693 | (uint32_t)pmbox->mbxCommand, |
| 2694 | pmbox->un.varWords[0], |
| 2695 | pmbox->un.varWords[1]); |
| 2696 | } |
| 2697 | } |
| 2698 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2699 | /* |
| 2700 | * It is a fatal error if unknown mbox command completion. |
| 2701 | */ |
| 2702 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2703 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2704 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2705 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2706 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2707 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 2708 | pmb->vport ? pmb->vport->vpi : |
| 2709 | LPFC_VPORT_UNKNOWN, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2710 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2711 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2712 | pmb), |
| 2713 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2714 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2715 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2716 | phba->work_hs = HS_FFER3; |
| 2717 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2718 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2719 | } |
| 2720 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2721 | if (pmbox->mbxStatus) { |
| 2722 | phba->sli.slistat.mbox_stat_err++; |
| 2723 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2724 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2725 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2726 | LOG_MBOX | LOG_SLI, |
| 2727 | "(%d):0305 Mbox cmd cmpl " |
| 2728 | "error - RETRYing Data: x%x " |
| 2729 | "(x%x/x%x) x%x x%x x%x\n", |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 2730 | pmb->vport ? pmb->vport->vpi : |
| 2731 | LPFC_VPORT_UNKNOWN, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2732 | pmbox->mbxCommand, |
| 2733 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2734 | pmb), |
| 2735 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2736 | pmb), |
| 2737 | pmbox->mbxStatus, |
| 2738 | pmbox->un.varWords[0], |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 2739 | pmb->vport ? pmb->vport->port_state : |
| 2740 | LPFC_VPORT_UNKNOWN); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 | pmbox->mbxStatus = 0; |
| 2742 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2743 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2744 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2745 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2746 | } |
| 2747 | } |
| 2748 | |
| 2749 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2750 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
Sakari Ailus | 2d44d16 | 2019-09-04 19:04:23 +0300 | [diff] [blame] | 2751 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl %ps " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2752 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2753 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2754 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2755 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2756 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2757 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | pmb->mbox_cmpl, |
| 2759 | *((uint32_t *) pmbox), |
| 2760 | pmbox->un.varWords[0], |
| 2761 | pmbox->un.varWords[1], |
| 2762 | pmbox->un.varWords[2], |
| 2763 | pmbox->un.varWords[3], |
| 2764 | pmbox->un.varWords[4], |
| 2765 | pmbox->un.varWords[5], |
| 2766 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2767 | pmbox->un.varWords[7], |
| 2768 | pmbox->un.varWords[8], |
| 2769 | pmbox->un.varWords[9], |
| 2770 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2771 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2772 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2773 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2774 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2775 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2777 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2778 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2779 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2780 | * @phba: Pointer to HBA context object. |
| 2781 | * @pring: Pointer to driver SLI ring object. |
| 2782 | * @tag: buffer tag. |
| 2783 | * |
| 2784 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2785 | * is set in the tag the buffer is posted for a particular exchange, |
| 2786 | * the function will return the buffer without replacing the buffer. |
| 2787 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2788 | * returns the buffer and also posts another buffer to the firmware. |
| 2789 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2790 | static struct lpfc_dmabuf * |
| 2791 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2792 | struct lpfc_sli_ring *pring, |
| 2793 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2794 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2795 | struct hbq_dmabuf *hbq_entry; |
| 2796 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2797 | if (tag & QUE_BUFTAG_BIT) |
| 2798 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2799 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2800 | if (!hbq_entry) |
| 2801 | return NULL; |
| 2802 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2803 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2804 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2805 | /** |
| 2806 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2807 | * @phba: Pointer to HBA context object. |
| 2808 | * @pring: Pointer to driver SLI ring object. |
| 2809 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2810 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2811 | * @fch_type: the type for the first frame of the sequence. |
| 2812 | * |
| 2813 | * This function is called with no lock held. This function uses the r_ctl and |
| 2814 | * type of the received sequence to find the correct callback function to call |
| 2815 | * to process the sequence. |
| 2816 | **/ |
| 2817 | static int |
| 2818 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2819 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2820 | uint32_t fch_type) |
| 2821 | { |
| 2822 | int i; |
| 2823 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2824 | switch (fch_type) { |
| 2825 | case FC_TYPE_NVME: |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2826 | lpfc_nvmet_unsol_ls_event(phba, pring, saveq); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2827 | return 1; |
| 2828 | default: |
| 2829 | break; |
| 2830 | } |
| 2831 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2832 | /* unSolicited Responses */ |
| 2833 | if (pring->prt[0].profile) { |
| 2834 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2835 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2836 | saveq); |
| 2837 | return 1; |
| 2838 | } |
| 2839 | /* We must search, based on rctl / type |
| 2840 | for the right routine */ |
| 2841 | for (i = 0; i < pring->num_mask; i++) { |
| 2842 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2843 | (pring->prt[i].type == fch_type)) { |
| 2844 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2845 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2846 | (phba, pring, saveq); |
| 2847 | return 1; |
| 2848 | } |
| 2849 | } |
| 2850 | return 0; |
| 2851 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2852 | |
| 2853 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2854 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2855 | * @phba: Pointer to HBA context object. |
| 2856 | * @pring: Pointer to driver SLI ring object. |
| 2857 | * @saveq: Pointer to the unsolicited iocb. |
| 2858 | * |
| 2859 | * This function is called with no lock held by the ring event handler |
| 2860 | * when there is an unsolicited iocb posted to the response ring by the |
| 2861 | * firmware. This function gets the buffer associated with the iocbs |
| 2862 | * and calls the event handler for the ring. This function handles both |
| 2863 | * qring buffers and hbq buffers. |
| 2864 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2865 | * upper layer functions will free the iocb objects. |
| 2866 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2867 | static int |
| 2868 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2869 | struct lpfc_iocbq *saveq) |
| 2870 | { |
| 2871 | IOCB_t * irsp; |
| 2872 | WORD5 * w5p; |
| 2873 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2874 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2875 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2876 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2877 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2878 | |
| 2879 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2880 | if (pring->lpfc_sli_rcv_async_status) |
| 2881 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2882 | else |
| 2883 | lpfc_printf_log(phba, |
| 2884 | KERN_WARNING, |
| 2885 | LOG_SLI, |
| 2886 | "0316 Ring %d handler: unexpected " |
| 2887 | "ASYNC_STATUS iocb received evt_code " |
| 2888 | "0x%x\n", |
| 2889 | pring->ringno, |
| 2890 | irsp->un.asyncstat.evt_code); |
| 2891 | return 1; |
| 2892 | } |
| 2893 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2894 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2895 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2896 | if (irsp->ulpBdeCount > 0) { |
| 2897 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2898 | irsp->un.ulpWord[3]); |
| 2899 | lpfc_in_buf_free(phba, dmzbuf); |
| 2900 | } |
| 2901 | |
| 2902 | if (irsp->ulpBdeCount > 1) { |
| 2903 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2904 | irsp->unsli3.sli3Words[3]); |
| 2905 | lpfc_in_buf_free(phba, dmzbuf); |
| 2906 | } |
| 2907 | |
| 2908 | if (irsp->ulpBdeCount > 2) { |
| 2909 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2910 | irsp->unsli3.sli3Words[7]); |
| 2911 | lpfc_in_buf_free(phba, dmzbuf); |
| 2912 | } |
| 2913 | |
| 2914 | return 1; |
| 2915 | } |
| 2916 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2917 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2918 | if (irsp->ulpBdeCount != 0) { |
| 2919 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2920 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2921 | if (!saveq->context2) |
| 2922 | lpfc_printf_log(phba, |
| 2923 | KERN_ERR, |
| 2924 | LOG_SLI, |
| 2925 | "0341 Ring %d Cannot find buffer for " |
| 2926 | "an unsolicited iocb. tag 0x%x\n", |
| 2927 | pring->ringno, |
| 2928 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2929 | } |
| 2930 | if (irsp->ulpBdeCount == 2) { |
| 2931 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2932 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2933 | if (!saveq->context3) |
| 2934 | lpfc_printf_log(phba, |
| 2935 | KERN_ERR, |
| 2936 | LOG_SLI, |
| 2937 | "0342 Ring %d Cannot find buffer for an" |
| 2938 | " unsolicited iocb. tag 0x%x\n", |
| 2939 | pring->ringno, |
| 2940 | irsp->unsli3.sli3Words[7]); |
| 2941 | } |
| 2942 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2943 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2944 | if (irsp->ulpBdeCount != 0) { |
| 2945 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2946 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2947 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2948 | lpfc_printf_log(phba, |
| 2949 | KERN_ERR, |
| 2950 | LOG_SLI, |
| 2951 | "0343 Ring %d Cannot find " |
| 2952 | "buffer for an unsolicited iocb" |
| 2953 | ". tag 0x%x\n", pring->ringno, |
| 2954 | irsp->un.ulpWord[3]); |
| 2955 | } |
| 2956 | if (irsp->ulpBdeCount == 2) { |
| 2957 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2958 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2959 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2960 | lpfc_printf_log(phba, |
| 2961 | KERN_ERR, |
| 2962 | LOG_SLI, |
| 2963 | "0344 Ring %d Cannot find " |
| 2964 | "buffer for an unsolicited " |
| 2965 | "iocb. tag 0x%x\n", |
| 2966 | pring->ringno, |
| 2967 | irsp->unsli3.sli3Words[7]); |
| 2968 | } |
| 2969 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2970 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2971 | if (irsp->ulpBdeCount != 0 && |
| 2972 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2973 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2974 | int found = 0; |
| 2975 | |
| 2976 | /* search continue save q for same XRI */ |
| 2977 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2978 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2979 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2980 | list_add_tail(&saveq->list, &iocbq->list); |
| 2981 | found = 1; |
| 2982 | break; |
| 2983 | } |
| 2984 | } |
| 2985 | if (!found) |
| 2986 | list_add_tail(&saveq->clist, |
| 2987 | &pring->iocb_continue_saveq); |
| 2988 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2989 | list_del_init(&iocbq->clist); |
| 2990 | saveq = iocbq; |
| 2991 | irsp = &(saveq->iocb); |
| 2992 | } else |
| 2993 | return 0; |
| 2994 | } |
| 2995 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2996 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2997 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2998 | Rctl = FC_RCTL_ELS_REQ; |
| 2999 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3000 | } else { |
| 3001 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 3002 | Rctl = w5p->hcsw.Rctl; |
| 3003 | Type = w5p->hcsw.Type; |
| 3004 | |
| 3005 | /* Firmware Workaround */ |
| 3006 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 3007 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 3008 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3009 | Rctl = FC_RCTL_ELS_REQ; |
| 3010 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3011 | w5p->hcsw.Rctl = Rctl; |
| 3012 | w5p->hcsw.Type = Type; |
| 3013 | } |
| 3014 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3015 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3016 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3017 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3018 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3019 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3020 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3021 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3022 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3023 | } |
| 3024 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3025 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3026 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3027 | * @phba: Pointer to HBA context object. |
| 3028 | * @pring: Pointer to driver SLI ring object. |
| 3029 | * @prspiocb: Pointer to response iocb object. |
| 3030 | * |
| 3031 | * This function looks up the iocb_lookup table to get the command iocb |
| 3032 | * corresponding to the given response iocb using the iotag of the |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3033 | * response iocb. The driver calls this function with the hbalock held |
| 3034 | * for SLI3 ports or the ring lock held for SLI4 ports. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3035 | * This function returns the command iocb object if it finds the command |
| 3036 | * iocb else returns NULL. |
| 3037 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3038 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3039 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 3040 | struct lpfc_sli_ring *pring, |
| 3041 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3042 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3043 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 3044 | uint16_t iotag; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3045 | spinlock_t *temp_lock = NULL; |
| 3046 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3047 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3048 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3049 | temp_lock = &pring->ring_lock; |
| 3050 | else |
| 3051 | temp_lock = &phba->hbalock; |
| 3052 | |
| 3053 | spin_lock_irqsave(temp_lock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3054 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3055 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3056 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3057 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3058 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3059 | /* remove from txcmpl queue list */ |
| 3060 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3061 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3062 | pring->txcmplq_cnt--; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3063 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3064 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3065 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3066 | } |
| 3067 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3068 | spin_unlock_irqrestore(temp_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3069 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3070 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3071 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3072 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3073 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3074 | return NULL; |
| 3075 | } |
| 3076 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3077 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3078 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 3079 | * @phba: Pointer to HBA context object. |
| 3080 | * @pring: Pointer to driver SLI ring object. |
| 3081 | * @iotag: IOCB tag. |
| 3082 | * |
| 3083 | * 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] | 3084 | * corresponding to the given iotag. The driver calls this function with |
| 3085 | * 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] | 3086 | * This function returns the command iocb object if it finds the command |
| 3087 | * iocb else returns NULL. |
| 3088 | **/ |
| 3089 | static struct lpfc_iocbq * |
| 3090 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 3091 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 3092 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3093 | struct lpfc_iocbq *cmd_iocb = NULL; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3094 | spinlock_t *temp_lock = NULL; |
| 3095 | unsigned long iflag = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3096 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3097 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3098 | temp_lock = &pring->ring_lock; |
| 3099 | else |
| 3100 | temp_lock = &phba->hbalock; |
| 3101 | |
| 3102 | spin_lock_irqsave(temp_lock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3103 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3104 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3105 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 3106 | /* remove from txcmpl queue list */ |
| 3107 | list_del_init(&cmd_iocb->list); |
| 3108 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3109 | pring->txcmplq_cnt--; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3110 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3111 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3112 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3113 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3114 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3115 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3116 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3117 | "0372 iotag x%x lookup error: max iotag (x%x) " |
| 3118 | "iocb_flag x%x\n", |
| 3119 | iotag, phba->sli.last_iotag, |
| 3120 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3121 | return NULL; |
| 3122 | } |
| 3123 | |
| 3124 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3125 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3126 | * @phba: Pointer to HBA context object. |
| 3127 | * @pring: Pointer to driver SLI ring object. |
| 3128 | * @saveq: Pointer to the response iocb to be processed. |
| 3129 | * |
| 3130 | * This function is called by the ring event handler for non-fcp |
| 3131 | * rings when there is a new response iocb in the response ring. |
| 3132 | * The caller is not required to hold any locks. This function |
| 3133 | * gets the command iocb associated with the response iocb and |
| 3134 | * calls the completion handler for the command iocb. If there |
| 3135 | * is no completion handler, the function will free the resources |
| 3136 | * associated with command iocb. If the response iocb is for |
| 3137 | * an already aborted command iocb, the status of the completion |
| 3138 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 3139 | * This function always returns 1. |
| 3140 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3141 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3142 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3143 | struct lpfc_iocbq *saveq) |
| 3144 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3145 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3146 | int rc = 1; |
| 3147 | unsigned long iflag; |
| 3148 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3149 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3150 | if (cmdiocbp) { |
| 3151 | if (cmdiocbp->iocb_cmpl) { |
| 3152 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3153 | * If an ELS command failed send an event to mgmt |
| 3154 | * application. |
| 3155 | */ |
| 3156 | if (saveq->iocb.ulpStatus && |
| 3157 | (pring->ringno == LPFC_ELS_RING) && |
| 3158 | (cmdiocbp->iocb.ulpCommand == |
| 3159 | CMD_ELS_REQUEST64_CR)) |
| 3160 | lpfc_send_els_failure_event(phba, |
| 3161 | cmdiocbp, saveq); |
| 3162 | |
| 3163 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3164 | * Post all ELS completions to the worker thread. |
| 3165 | * All other are passed to the completion callback. |
| 3166 | */ |
| 3167 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3168 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3169 | (cmdiocbp->iocb_flag & |
| 3170 | LPFC_DRIVER_ABORTED)) { |
| 3171 | spin_lock_irqsave(&phba->hbalock, |
| 3172 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3173 | cmdiocbp->iocb_flag &= |
| 3174 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3175 | spin_unlock_irqrestore(&phba->hbalock, |
| 3176 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3177 | saveq->iocb.ulpStatus = |
| 3178 | IOSTAT_LOCAL_REJECT; |
| 3179 | saveq->iocb.un.ulpWord[4] = |
| 3180 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3181 | |
| 3182 | /* Firmware could still be in progress |
| 3183 | * of DMAing payload, so don't free data |
| 3184 | * buffer till after a hbeat. |
| 3185 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3186 | spin_lock_irqsave(&phba->hbalock, |
| 3187 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3188 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3189 | spin_unlock_irqrestore(&phba->hbalock, |
| 3190 | iflag); |
| 3191 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3192 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3193 | if (saveq->iocb_flag & |
| 3194 | LPFC_EXCHANGE_BUSY) { |
| 3195 | /* Set cmdiocb flag for the |
| 3196 | * exchange busy so sgl (xri) |
| 3197 | * will not be released until |
| 3198 | * the abort xri is received |
| 3199 | * from hba. |
| 3200 | */ |
| 3201 | spin_lock_irqsave( |
| 3202 | &phba->hbalock, iflag); |
| 3203 | cmdiocbp->iocb_flag |= |
| 3204 | LPFC_EXCHANGE_BUSY; |
| 3205 | spin_unlock_irqrestore( |
| 3206 | &phba->hbalock, iflag); |
| 3207 | } |
| 3208 | if (cmdiocbp->iocb_flag & |
| 3209 | LPFC_DRIVER_ABORTED) { |
| 3210 | /* |
| 3211 | * Clear LPFC_DRIVER_ABORTED |
| 3212 | * bit in case it was driver |
| 3213 | * initiated abort. |
| 3214 | */ |
| 3215 | spin_lock_irqsave( |
| 3216 | &phba->hbalock, iflag); |
| 3217 | cmdiocbp->iocb_flag &= |
| 3218 | ~LPFC_DRIVER_ABORTED; |
| 3219 | spin_unlock_irqrestore( |
| 3220 | &phba->hbalock, iflag); |
| 3221 | cmdiocbp->iocb.ulpStatus = |
| 3222 | IOSTAT_LOCAL_REJECT; |
| 3223 | cmdiocbp->iocb.un.ulpWord[4] = |
| 3224 | IOERR_ABORT_REQUESTED; |
| 3225 | /* |
| 3226 | * For SLI4, irsiocb contains |
| 3227 | * NO_XRI in sli_xritag, it |
| 3228 | * shall not affect releasing |
| 3229 | * sgl (xri) process. |
| 3230 | */ |
| 3231 | saveq->iocb.ulpStatus = |
| 3232 | IOSTAT_LOCAL_REJECT; |
| 3233 | saveq->iocb.un.ulpWord[4] = |
| 3234 | IOERR_SLI_ABORTED; |
| 3235 | spin_lock_irqsave( |
| 3236 | &phba->hbalock, iflag); |
| 3237 | saveq->iocb_flag |= |
| 3238 | LPFC_DELAY_MEM_FREE; |
| 3239 | spin_unlock_irqrestore( |
| 3240 | &phba->hbalock, iflag); |
| 3241 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3242 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3243 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3244 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3245 | } else |
| 3246 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3247 | } else { |
| 3248 | /* |
| 3249 | * Unknown initiating command based on the response iotag. |
| 3250 | * This could be the case on the ELS ring because of |
| 3251 | * lpfc_els_abort(). |
| 3252 | */ |
| 3253 | if (pring->ringno != LPFC_ELS_RING) { |
| 3254 | /* |
| 3255 | * Ring <ringno> handler: unexpected completion IoTag |
| 3256 | * <IoTag> |
| 3257 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3258 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3259 | "0322 Ring %d handler: " |
| 3260 | "unexpected completion IoTag x%x " |
| 3261 | "Data: x%x x%x x%x x%x\n", |
| 3262 | pring->ringno, |
| 3263 | saveq->iocb.ulpIoTag, |
| 3264 | saveq->iocb.ulpStatus, |
| 3265 | saveq->iocb.un.ulpWord[4], |
| 3266 | saveq->iocb.ulpCommand, |
| 3267 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3268 | } |
| 3269 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3270 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3271 | return rc; |
| 3272 | } |
| 3273 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3274 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3275 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3276 | * @phba: Pointer to HBA context object. |
| 3277 | * @pring: Pointer to driver SLI ring object. |
| 3278 | * |
| 3279 | * This function is called from the iocb ring event handlers when |
| 3280 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 3281 | * an error attention condition to the worker thread and the worker |
| 3282 | * thread will transition the HBA to offline state. |
| 3283 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3284 | static void |
| 3285 | 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] | 3286 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3287 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3288 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3289 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3290 | * rsp ring <portRspMax> |
| 3291 | */ |
| 3292 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3293 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3294 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3295 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3296 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3297 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3298 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3299 | |
| 3300 | /* |
| 3301 | * All error attention handlers are posted to |
| 3302 | * worker thread |
| 3303 | */ |
| 3304 | phba->work_ha |= HA_ERATT; |
| 3305 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3306 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3307 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3308 | |
| 3309 | return; |
| 3310 | } |
| 3311 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3312 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3313 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3314 | * @ptr: Pointer to address of HBA context object. |
| 3315 | * |
| 3316 | * This function is invoked by the Error Attention polling timer when the |
| 3317 | * timer times out. It will check the SLI Error Attention register for |
| 3318 | * possible attention events. If so, it will post an Error Attention event |
| 3319 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 3320 | * Error Attention polling timer for the next poll. |
| 3321 | **/ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3322 | void lpfc_poll_eratt(struct timer_list *t) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3323 | { |
| 3324 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3325 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3326 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3327 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3328 | phba = from_timer(phba, t, eratt_poll); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3329 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3330 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 3331 | sli_intr = phba->sli.slistat.sli_intr; |
| 3332 | |
| 3333 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 3334 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 3335 | sli_intr); |
| 3336 | else |
| 3337 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 3338 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3339 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 3340 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3341 | phba->sli.slistat.sli_ips = cnt; |
| 3342 | |
| 3343 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 3344 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3345 | /* Check chip HA register for error event */ |
| 3346 | eratt = lpfc_sli_check_eratt(phba); |
| 3347 | |
| 3348 | if (eratt) |
| 3349 | /* Tell the worker thread there is work to do */ |
| 3350 | lpfc_worker_wake_up(phba); |
| 3351 | else |
| 3352 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3353 | mod_timer(&phba->eratt_poll, |
| 3354 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3355 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3356 | return; |
| 3357 | } |
| 3358 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3359 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3360 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3361 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3362 | * @phba: Pointer to HBA context object. |
| 3363 | * @pring: Pointer to driver SLI ring object. |
| 3364 | * @mask: Host attention register mask for this ring. |
| 3365 | * |
| 3366 | * This function is called from the interrupt context when there is a ring |
| 3367 | * event for the fcp ring. The caller does not hold any lock. |
| 3368 | * 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] | 3369 | * 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] | 3370 | * LE bit set. The function will call the completion handler of the command iocb |
| 3371 | * if the response iocb indicates a completion for a command iocb or it is |
| 3372 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 3373 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3374 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3375 | * to check it explicitly. |
| 3376 | */ |
| 3377 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3378 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 3379 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3380 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3381 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3382 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3383 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3384 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 3385 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | uint32_t status; |
| 3387 | uint32_t portRspPut, portRspMax; |
| 3388 | int rc = 1; |
| 3389 | lpfc_iocb_type type; |
| 3390 | unsigned long iflag; |
| 3391 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3393 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3394 | pring->stats.iocb_event++; |
| 3395 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3396 | /* |
| 3397 | * The next available response entry should never exceed the maximum |
| 3398 | * entries. If it does, treat it as an adapter hardware error. |
| 3399 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3400 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3401 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3402 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3403 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3404 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | return 1; |
| 3406 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3407 | if (phba->fcp_ring_in_use) { |
| 3408 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3409 | return 1; |
| 3410 | } else |
| 3411 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3412 | |
| 3413 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3414 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3415 | /* |
| 3416 | * Fetch an entry off the ring and copy it into a local data |
| 3417 | * structure. The copy involves a byte-swap since the |
| 3418 | * network byte order and pci byte orders are different. |
| 3419 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3420 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3421 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3422 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3423 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3424 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3425 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3426 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3427 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3428 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3429 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3430 | irsp = &rspiocbq.iocb; |
| 3431 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3432 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3433 | pring->stats.iocb_rsp++; |
| 3434 | rsp_cmpl++; |
| 3435 | |
| 3436 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3437 | /* |
| 3438 | * If resource errors reported from HBA, reduce |
| 3439 | * queuedepths of the SCSI device. |
| 3440 | */ |
| 3441 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3442 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3443 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3444 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3445 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3446 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3447 | } |
| 3448 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3449 | /* Rsp ring <ringno> error: IOCB */ |
| 3450 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3451 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3452 | "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] | 3453 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3454 | irsp->un.ulpWord[0], |
| 3455 | irsp->un.ulpWord[1], |
| 3456 | irsp->un.ulpWord[2], |
| 3457 | irsp->un.ulpWord[3], |
| 3458 | irsp->un.ulpWord[4], |
| 3459 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3460 | *(uint32_t *)&irsp->un1, |
| 3461 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | switch (type) { |
| 3465 | case LPFC_ABORT_IOCB: |
| 3466 | case LPFC_SOL_IOCB: |
| 3467 | /* |
| 3468 | * Idle exchange closed via ABTS from port. No iocb |
| 3469 | * resources need to be recovered. |
| 3470 | */ |
| 3471 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3472 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3473 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3474 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3475 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3476 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3477 | break; |
| 3478 | } |
| 3479 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3480 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3481 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3482 | &rspiocbq); |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3483 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3484 | if (unlikely(!cmdiocbq)) |
| 3485 | break; |
| 3486 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3487 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3488 | if (cmdiocbq->iocb_cmpl) { |
| 3489 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3490 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3491 | &rspiocbq); |
| 3492 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3493 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3494 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3495 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3496 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3497 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3498 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3499 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3500 | default: |
| 3501 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3502 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3503 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3504 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3505 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3506 | dev_warn(&((phba->pcidev)->dev), |
| 3507 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3508 | phba->brd_no, adaptermsg); |
| 3509 | } else { |
| 3510 | /* Unknown IOCB command */ |
| 3511 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3512 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3513 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3514 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3515 | irsp->ulpStatus, |
| 3516 | irsp->ulpIoTag, |
| 3517 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3518 | } |
| 3519 | break; |
| 3520 | } |
| 3521 | |
| 3522 | /* |
| 3523 | * The response IOCB has been processed. Update the ring |
| 3524 | * pointer in SLIM. If the port response put pointer has not |
| 3525 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3526 | * response put pointer. |
| 3527 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3528 | writel(pring->sli.sli3.rspidx, |
| 3529 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3530 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3531 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3532 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3533 | } |
| 3534 | |
| 3535 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3536 | pring->stats.iocb_rsp_full++; |
| 3537 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3538 | writel(status, phba->CAregaddr); |
| 3539 | readl(phba->CAregaddr); |
| 3540 | } |
| 3541 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3542 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3543 | pring->stats.iocb_cmd_empty++; |
| 3544 | |
| 3545 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3546 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3547 | lpfc_sli_resume_iocb(phba, pring); |
| 3548 | |
| 3549 | if ((pring->lpfc_sli_cmd_available)) |
| 3550 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3551 | |
| 3552 | } |
| 3553 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3554 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3555 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3556 | return rc; |
| 3557 | } |
| 3558 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3559 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3560 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3561 | * @phba: Pointer to HBA context object. |
| 3562 | * @pring: Pointer to driver SLI ring object. |
| 3563 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3564 | * |
| 3565 | * This function is called from the worker thread when there is a slow-path |
| 3566 | * response IOCB to process. This function chains all the response iocbs until |
| 3567 | * seeing the iocb with the LE bit set. The function will call |
| 3568 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3569 | * completion of a command iocb. The function will call the |
| 3570 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3571 | * The function frees the resources or calls the completion handler if this |
| 3572 | * iocb is an abort completion. The function returns NULL when the response |
| 3573 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3574 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3575 | * response iocb passed in. |
| 3576 | **/ |
| 3577 | static struct lpfc_iocbq * |
| 3578 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3579 | struct lpfc_iocbq *rspiocbp) |
| 3580 | { |
| 3581 | struct lpfc_iocbq *saveq; |
| 3582 | struct lpfc_iocbq *cmdiocbp; |
| 3583 | struct lpfc_iocbq *next_iocb; |
| 3584 | IOCB_t *irsp = NULL; |
| 3585 | uint32_t free_saveq; |
| 3586 | uint8_t iocb_cmd_type; |
| 3587 | lpfc_iocb_type type; |
| 3588 | unsigned long iflag; |
| 3589 | int rc; |
| 3590 | |
| 3591 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3592 | /* First add the response iocb to the countinueq list */ |
| 3593 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3594 | pring->iocb_continueq_cnt++; |
| 3595 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3596 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3597 | irsp = &rspiocbp->iocb; |
| 3598 | if (irsp->ulpLe) { |
| 3599 | /* |
| 3600 | * By default, the driver expects to free all resources |
| 3601 | * associated with this iocb completion. |
| 3602 | */ |
| 3603 | free_saveq = 1; |
| 3604 | saveq = list_get_first(&pring->iocb_continueq, |
| 3605 | struct lpfc_iocbq, list); |
| 3606 | irsp = &(saveq->iocb); |
| 3607 | list_del_init(&pring->iocb_continueq); |
| 3608 | pring->iocb_continueq_cnt = 0; |
| 3609 | |
| 3610 | pring->stats.iocb_rsp++; |
| 3611 | |
| 3612 | /* |
| 3613 | * If resource errors reported from HBA, reduce |
| 3614 | * queuedepths of the SCSI device. |
| 3615 | */ |
| 3616 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3617 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3618 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3619 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3620 | phba->lpfc_rampdown_queue_depth(phba); |
| 3621 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3622 | } |
| 3623 | |
| 3624 | if (irsp->ulpStatus) { |
| 3625 | /* Rsp ring <ringno> error: IOCB */ |
| 3626 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3627 | "0328 Rsp Ring %d error: " |
| 3628 | "IOCB Data: " |
| 3629 | "x%x x%x x%x x%x " |
| 3630 | "x%x x%x x%x x%x " |
| 3631 | "x%x x%x x%x x%x " |
| 3632 | "x%x x%x x%x x%x\n", |
| 3633 | pring->ringno, |
| 3634 | irsp->un.ulpWord[0], |
| 3635 | irsp->un.ulpWord[1], |
| 3636 | irsp->un.ulpWord[2], |
| 3637 | irsp->un.ulpWord[3], |
| 3638 | irsp->un.ulpWord[4], |
| 3639 | irsp->un.ulpWord[5], |
| 3640 | *(((uint32_t *) irsp) + 6), |
| 3641 | *(((uint32_t *) irsp) + 7), |
| 3642 | *(((uint32_t *) irsp) + 8), |
| 3643 | *(((uint32_t *) irsp) + 9), |
| 3644 | *(((uint32_t *) irsp) + 10), |
| 3645 | *(((uint32_t *) irsp) + 11), |
| 3646 | *(((uint32_t *) irsp) + 12), |
| 3647 | *(((uint32_t *) irsp) + 13), |
| 3648 | *(((uint32_t *) irsp) + 14), |
| 3649 | *(((uint32_t *) irsp) + 15)); |
| 3650 | } |
| 3651 | |
| 3652 | /* |
| 3653 | * Fetch the IOCB command type and call the correct completion |
| 3654 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3655 | * get freed back to the lpfc_iocb_list by the discovery |
| 3656 | * kernel thread. |
| 3657 | */ |
| 3658 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3659 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3660 | switch (type) { |
| 3661 | case LPFC_SOL_IOCB: |
| 3662 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3663 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3664 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3665 | break; |
| 3666 | |
| 3667 | case LPFC_UNSOL_IOCB: |
| 3668 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3669 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3670 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3671 | if (!rc) |
| 3672 | free_saveq = 0; |
| 3673 | break; |
| 3674 | |
| 3675 | case LPFC_ABORT_IOCB: |
| 3676 | cmdiocbp = NULL; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3677 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) { |
| 3678 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3679 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3680 | saveq); |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3681 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3682 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3683 | if (cmdiocbp) { |
| 3684 | /* Call the specified completion routine */ |
| 3685 | if (cmdiocbp->iocb_cmpl) { |
| 3686 | spin_unlock_irqrestore(&phba->hbalock, |
| 3687 | iflag); |
| 3688 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3689 | saveq); |
| 3690 | spin_lock_irqsave(&phba->hbalock, |
| 3691 | iflag); |
| 3692 | } else |
| 3693 | __lpfc_sli_release_iocbq(phba, |
| 3694 | cmdiocbp); |
| 3695 | } |
| 3696 | break; |
| 3697 | |
| 3698 | case LPFC_UNKNOWN_IOCB: |
| 3699 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3700 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3701 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3702 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3703 | MAX_MSG_DATA); |
| 3704 | dev_warn(&((phba->pcidev)->dev), |
| 3705 | "lpfc%d: %s\n", |
| 3706 | phba->brd_no, adaptermsg); |
| 3707 | } else { |
| 3708 | /* Unknown IOCB command */ |
| 3709 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3710 | "0335 Unknown IOCB " |
| 3711 | "command Data: x%x " |
| 3712 | "x%x x%x x%x\n", |
| 3713 | irsp->ulpCommand, |
| 3714 | irsp->ulpStatus, |
| 3715 | irsp->ulpIoTag, |
| 3716 | irsp->ulpContext); |
| 3717 | } |
| 3718 | break; |
| 3719 | } |
| 3720 | |
| 3721 | if (free_saveq) { |
| 3722 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3723 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3724 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3725 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3726 | } |
| 3727 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3728 | } |
| 3729 | rspiocbp = NULL; |
| 3730 | } |
| 3731 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3732 | return rspiocbp; |
| 3733 | } |
| 3734 | |
| 3735 | /** |
| 3736 | * 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] | 3737 | * @phba: Pointer to HBA context object. |
| 3738 | * @pring: Pointer to driver SLI ring object. |
| 3739 | * @mask: Host attention register mask for this ring. |
| 3740 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3741 | * This routine wraps the actual slow_ring event process routine from the |
| 3742 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3743 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3744 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3745 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3746 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3747 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3748 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3749 | } |
| 3750 | |
| 3751 | /** |
| 3752 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3753 | * @phba: Pointer to HBA context object. |
| 3754 | * @pring: Pointer to driver SLI ring object. |
| 3755 | * @mask: Host attention register mask for this ring. |
| 3756 | * |
| 3757 | * This function is called from the worker thread when there is a ring event |
| 3758 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3759 | * remove each response iocb in the response ring and calls the handle |
| 3760 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3761 | **/ |
| 3762 | static void |
| 3763 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3764 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3765 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3766 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3767 | IOCB_t *entry; |
| 3768 | IOCB_t *irsp = NULL; |
| 3769 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3770 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3771 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3772 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3773 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3774 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3775 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3776 | pring->stats.iocb_event++; |
| 3777 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3778 | /* |
| 3779 | * The next available response entry should never exceed the maximum |
| 3780 | * entries. If it does, treat it as an adapter hardware error. |
| 3781 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3782 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3783 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3784 | if (portRspPut >= portRspMax) { |
| 3785 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3786 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3787 | * rsp ring <portRspMax> |
| 3788 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3789 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3790 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3791 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3792 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3793 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3794 | phba->link_state = LPFC_HBA_ERROR; |
| 3795 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3796 | |
| 3797 | phba->work_hs = HS_FFER3; |
| 3798 | lpfc_handle_eratt(phba); |
| 3799 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3800 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3804 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3805 | /* |
| 3806 | * Build a completion list and call the appropriate handler. |
| 3807 | * The process is to get the next available response iocb, get |
| 3808 | * a free iocb from the list, copy the response data into the |
| 3809 | * free iocb, insert to the continuation list, and update the |
| 3810 | * next response index to slim. This process makes response |
| 3811 | * iocb's in the ring available to DMA as fast as possible but |
| 3812 | * pays a penalty for a copy operation. Since the iocb is |
| 3813 | * only 32 bytes, this penalty is considered small relative to |
| 3814 | * the PCI reads for register values and a slim write. When |
| 3815 | * the ulpLe field is set, the entire Command has been |
| 3816 | * received. |
| 3817 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3818 | entry = lpfc_resp_iocb(phba, pring); |
| 3819 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3820 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3821 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3822 | if (rspiocbp == NULL) { |
| 3823 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3824 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3825 | break; |
| 3826 | } |
| 3827 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3828 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3829 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3830 | irsp = &rspiocbp->iocb; |
| 3831 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3832 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3833 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3834 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3835 | if (pring->ringno == LPFC_ELS_RING) { |
| 3836 | lpfc_debugfs_slow_ring_trc(phba, |
| 3837 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3838 | *(((uint32_t *) irsp) + 4), |
| 3839 | *(((uint32_t *) irsp) + 6), |
| 3840 | *(((uint32_t *) irsp) + 7)); |
| 3841 | } |
| 3842 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3843 | writel(pring->sli.sli3.rspidx, |
| 3844 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3845 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3846 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3847 | /* Handle the response IOCB */ |
| 3848 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3849 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3850 | |
| 3851 | /* |
| 3852 | * If the port response put pointer has not been updated, sync |
| 3853 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3854 | * response put pointer. |
| 3855 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3856 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3857 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3858 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3859 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3860 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3861 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3862 | /* At least one response entry has been freed */ |
| 3863 | pring->stats.iocb_rsp_full++; |
| 3864 | /* SET RxRE_RSP in Chip Att register */ |
| 3865 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3866 | writel(status, phba->CAregaddr); |
| 3867 | readl(phba->CAregaddr); /* flush */ |
| 3868 | } |
| 3869 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3870 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3871 | pring->stats.iocb_cmd_empty++; |
| 3872 | |
| 3873 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3874 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3875 | lpfc_sli_resume_iocb(phba, pring); |
| 3876 | |
| 3877 | if ((pring->lpfc_sli_cmd_available)) |
| 3878 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3879 | |
| 3880 | } |
| 3881 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3882 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3883 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3884 | } |
| 3885 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3886 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3887 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3888 | * @phba: Pointer to HBA context object. |
| 3889 | * @pring: Pointer to driver SLI ring object. |
| 3890 | * @mask: Host attention register mask for this ring. |
| 3891 | * |
| 3892 | * This function is called from the worker thread when there is a pending |
| 3893 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3894 | * queue. The caller does not hold any lock. The function will remove each |
| 3895 | * response iocb from the response worker queue and calls the handle |
| 3896 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3897 | **/ |
| 3898 | static void |
| 3899 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3900 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3901 | { |
| 3902 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3903 | struct hbq_dmabuf *dmabuf; |
| 3904 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3905 | unsigned long iflag; |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3906 | int count = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3907 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3908 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3909 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3910 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3911 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3912 | /* Get the response iocb from the head of work queue */ |
| 3913 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3914 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3915 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3916 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3917 | |
| 3918 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3919 | case CQE_CODE_COMPL_WQE: |
| 3920 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3921 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3922 | /* Translate ELS WCQE to response IOCBQ */ |
| 3923 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3924 | irspiocbq); |
| 3925 | if (irspiocbq) |
| 3926 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3927 | irspiocbq); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3928 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3929 | break; |
| 3930 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3931 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3932 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3933 | cq_event); |
| 3934 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3935 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3936 | break; |
| 3937 | default: |
| 3938 | break; |
| 3939 | } |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3940 | |
| 3941 | /* Limit the number of events to 64 to avoid soft lockups */ |
| 3942 | if (count == 64) |
| 3943 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3944 | } |
| 3945 | } |
| 3946 | |
| 3947 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3948 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3949 | * @phba: Pointer to HBA context object. |
| 3950 | * @pring: Pointer to driver SLI ring object. |
| 3951 | * |
| 3952 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3953 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3954 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3955 | * the return of this function. The caller is not required to hold any locks. |
| 3956 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3957 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3958 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3959 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3960 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3961 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3962 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3963 | if (pring->ringno == LPFC_ELS_RING) { |
| 3964 | lpfc_fabric_abort_hba(phba); |
| 3965 | } |
| 3966 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3967 | /* Error everything on txq and txcmplq |
| 3968 | * First do the txq. |
| 3969 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3970 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3971 | spin_lock_irq(&pring->ring_lock); |
| 3972 | list_splice_init(&pring->txq, &completions); |
| 3973 | pring->txq_cnt = 0; |
| 3974 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3975 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3976 | spin_lock_irq(&phba->hbalock); |
| 3977 | /* Next issue ABTS for everything on the txcmplq */ |
| 3978 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3979 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3980 | spin_unlock_irq(&phba->hbalock); |
| 3981 | } else { |
| 3982 | spin_lock_irq(&phba->hbalock); |
| 3983 | list_splice_init(&pring->txq, &completions); |
| 3984 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3985 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3986 | /* Next issue ABTS for everything on the txcmplq */ |
| 3987 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3988 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3989 | spin_unlock_irq(&phba->hbalock); |
| 3990 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3991 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3992 | /* Cancel all the IOCBs from the completions list */ |
| 3993 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3994 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3995 | } |
| 3996 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3997 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3998 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 3999 | * @phba: Pointer to HBA context object. |
| 4000 | * @pring: Pointer to driver SLI ring object. |
| 4001 | * |
| 4002 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 4003 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 4004 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 4005 | * the return of this function. The caller is not required to hold any locks. |
| 4006 | **/ |
| 4007 | void |
| 4008 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 4009 | { |
| 4010 | struct lpfc_sli *psli = &phba->sli; |
| 4011 | struct lpfc_sli_ring *pring; |
| 4012 | uint32_t i; |
| 4013 | |
| 4014 | /* Look on all the FCP Rings for the iotag */ |
| 4015 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4016 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4017 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4018 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 4019 | } |
| 4020 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4021 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4022 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 4023 | } |
| 4024 | } |
| 4025 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4026 | /** |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4027 | * lpfc_sli_flush_io_rings - flush all iocbs in the IO ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4028 | * @phba: Pointer to HBA context object. |
| 4029 | * |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4030 | * 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] | 4031 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 4032 | * for all the iocb commands in txcmplq, they will just be returned with |
| 4033 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 4034 | * slot has been permanently disabled. |
| 4035 | **/ |
| 4036 | void |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4037 | lpfc_sli_flush_io_rings(struct lpfc_hba *phba) |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4038 | { |
| 4039 | LIST_HEAD(txq); |
| 4040 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4041 | struct lpfc_sli *psli = &phba->sli; |
| 4042 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4043 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4044 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4045 | |
| 4046 | spin_lock_irq(&phba->hbalock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4047 | /* Indicate the I/O queues are flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4048 | phba->hba_flag |= HBA_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4049 | spin_unlock_irq(&phba->hbalock); |
| 4050 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4051 | /* Look on all the FCP Rings for the iotag */ |
| 4052 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4053 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4054 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4055 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4056 | spin_lock_irq(&pring->ring_lock); |
| 4057 | /* Retrieve everything on txq */ |
| 4058 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4059 | list_for_each_entry_safe(piocb, next_iocb, |
| 4060 | &pring->txcmplq, list) |
| 4061 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4062 | /* Retrieve everything on the txcmplq */ |
| 4063 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4064 | pring->txq_cnt = 0; |
| 4065 | pring->txcmplq_cnt = 0; |
| 4066 | spin_unlock_irq(&pring->ring_lock); |
| 4067 | |
| 4068 | /* Flush the txq */ |
| 4069 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 4070 | IOSTAT_LOCAL_REJECT, |
| 4071 | IOERR_SLI_DOWN); |
| 4072 | /* Flush the txcmpq */ |
| 4073 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4074 | IOSTAT_LOCAL_REJECT, |
| 4075 | IOERR_SLI_DOWN); |
| 4076 | } |
| 4077 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4078 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4079 | |
| 4080 | spin_lock_irq(&phba->hbalock); |
| 4081 | /* Retrieve everything on txq */ |
| 4082 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4083 | list_for_each_entry_safe(piocb, next_iocb, |
| 4084 | &pring->txcmplq, list) |
| 4085 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4086 | /* Retrieve everything on the txcmplq */ |
| 4087 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4088 | pring->txq_cnt = 0; |
| 4089 | pring->txcmplq_cnt = 0; |
| 4090 | spin_unlock_irq(&phba->hbalock); |
| 4091 | |
| 4092 | /* Flush the txq */ |
| 4093 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 4094 | IOERR_SLI_DOWN); |
| 4095 | /* Flush the txcmpq */ |
| 4096 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 4097 | IOERR_SLI_DOWN); |
| 4098 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4102 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4103 | * @phba: Pointer to HBA context object. |
| 4104 | * @mask: Bit mask to be checked. |
| 4105 | * |
| 4106 | * This function reads the host status register and compares |
| 4107 | * with the provided bit mask to check if HBA completed |
| 4108 | * the restart. This function will wait in a loop for the |
| 4109 | * HBA to complete restart. If the HBA does not restart within |
| 4110 | * 15 iterations, the function will reset the HBA again. The |
| 4111 | * function returns 1 when HBA fail to restart otherwise returns |
| 4112 | * zero. |
| 4113 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4114 | static int |
| 4115 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4116 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4117 | uint32_t status; |
| 4118 | int i = 0; |
| 4119 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4120 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4121 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4122 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4123 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4124 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4125 | /* |
| 4126 | * Check status register every 100ms for 5 retries, then every |
| 4127 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 4128 | * every 2.5 sec for 4. |
| 4129 | * Break our of the loop if errors occurred during init. |
| 4130 | */ |
| 4131 | while (((status & mask) != mask) && |
| 4132 | !(status & HS_FFERM) && |
| 4133 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4134 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4135 | if (i <= 5) |
| 4136 | msleep(10); |
| 4137 | else if (i <= 10) |
| 4138 | msleep(500); |
| 4139 | else |
| 4140 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4141 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4142 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4143 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4144 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4145 | lpfc_sli_brdrestart(phba); |
| 4146 | } |
| 4147 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4148 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 4149 | retval = 1; |
| 4150 | break; |
| 4151 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4152 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4153 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4154 | /* Check to see if any errors occurred during init */ |
| 4155 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4156 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4157 | "2751 Adapter failed to restart, " |
| 4158 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 4159 | status, |
| 4160 | readl(phba->MBslimaddr + 0xa8), |
| 4161 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4162 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4163 | retval = 1; |
| 4164 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4165 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4166 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4167 | } |
| 4168 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4169 | /** |
| 4170 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 4171 | * @phba: Pointer to HBA context object. |
| 4172 | * @mask: Bit mask to be checked. |
| 4173 | * |
| 4174 | * This function checks the host status register to check if HBA is |
| 4175 | * ready. This function will wait in a loop for the HBA to be ready |
| 4176 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 4177 | * function again. The function returns 1 when HBA fail to be ready |
| 4178 | * otherwise returns zero. |
| 4179 | **/ |
| 4180 | static int |
| 4181 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 4182 | { |
| 4183 | uint32_t status; |
| 4184 | int retval = 0; |
| 4185 | |
| 4186 | /* Read the HBA Host Status Register */ |
| 4187 | status = lpfc_sli4_post_status_check(phba); |
| 4188 | |
| 4189 | if (status) { |
| 4190 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 4191 | lpfc_sli_brdrestart(phba); |
| 4192 | status = lpfc_sli4_post_status_check(phba); |
| 4193 | } |
| 4194 | |
| 4195 | /* Check to see if any errors occurred during init */ |
| 4196 | if (status) { |
| 4197 | phba->link_state = LPFC_HBA_ERROR; |
| 4198 | retval = 1; |
| 4199 | } else |
| 4200 | phba->sli4_hba.intr_enable = 0; |
| 4201 | |
| 4202 | return retval; |
| 4203 | } |
| 4204 | |
| 4205 | /** |
| 4206 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 4207 | * @phba: Pointer to HBA context object. |
| 4208 | * @mask: Bit mask to be checked. |
| 4209 | * |
| 4210 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 4211 | * from the API jump table function pointer from the lpfc_hba struct. |
| 4212 | **/ |
| 4213 | int |
| 4214 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 4215 | { |
| 4216 | return phba->lpfc_sli_brdready(phba, mask); |
| 4217 | } |
| 4218 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4219 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 4220 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4221 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4222 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4223 | * @phba: Pointer to HBA context object. |
| 4224 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 4225 | * This function is called before resetting an HBA. This function is called |
| 4226 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4227 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4228 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4229 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4230 | uint32_t __iomem *resp_buf; |
| 4231 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4232 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4233 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4234 | int i; |
| 4235 | uint8_t hdrtype; |
| 4236 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 4237 | lockdep_assert_held(&phba->hbalock); |
| 4238 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4239 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 4240 | if (hdrtype != 0x80 || |
| 4241 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 4242 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 4243 | return; |
| 4244 | |
| 4245 | /* |
| 4246 | * Tell the other part of the chip to suspend temporarily all |
| 4247 | * its DMA activity. |
| 4248 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4249 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4250 | |
| 4251 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4252 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 4253 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4254 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 4255 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4256 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4257 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4258 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4259 | return; |
| 4260 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4261 | /* Clear Chip error bit */ |
| 4262 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4263 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4264 | } |
| 4265 | |
| 4266 | mbox = 0; |
| 4267 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 4268 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 4269 | |
| 4270 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4271 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4272 | writel(mbox, mbox_buf); |
| 4273 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4274 | for (i = 0; i < 50; i++) { |
| 4275 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4276 | return; |
| 4277 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 4278 | mdelay(1); |
| 4279 | else |
| 4280 | break; |
| 4281 | } |
| 4282 | resp_data = 0; |
| 4283 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4284 | return; |
| 4285 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4286 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4287 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4288 | goto restore_hc; |
| 4289 | else |
| 4290 | goto clear_errat; |
| 4291 | } |
| 4292 | |
| 4293 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4294 | resp_data = 0; |
| 4295 | for (i = 0; i < 500; i++) { |
| 4296 | if (lpfc_readl(resp_buf, &resp_data)) |
| 4297 | return; |
| 4298 | if (resp_data != mbox) |
| 4299 | mdelay(1); |
| 4300 | else |
| 4301 | break; |
| 4302 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4303 | |
| 4304 | clear_errat: |
| 4305 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4306 | while (++i < 500) { |
| 4307 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4308 | return; |
| 4309 | if (!(ha_copy & HA_ERATT)) |
| 4310 | mdelay(1); |
| 4311 | else |
| 4312 | break; |
| 4313 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4314 | |
| 4315 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 4316 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4317 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4321 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4322 | writel(hc_copy, phba->HCregaddr); |
| 4323 | readl(phba->HCregaddr); /* flush */ |
| 4324 | } |
| 4325 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4326 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4327 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4328 | * @phba: Pointer to HBA context object. |
| 4329 | * |
| 4330 | * This function issues a kill_board mailbox command and waits for |
| 4331 | * the error attention interrupt. This function is called for stopping |
| 4332 | * the firmware processing. The caller is not required to hold any |
| 4333 | * locks. This function calls lpfc_hba_down_post function to free |
| 4334 | * any pending commands after the kill. The function will return 1 when it |
| 4335 | * fails to kill the board else will return 0. |
| 4336 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4337 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4338 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4339 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4340 | struct lpfc_sli *psli; |
| 4341 | LPFC_MBOXQ_t *pmb; |
| 4342 | uint32_t status; |
| 4343 | uint32_t ha_copy; |
| 4344 | int retval; |
| 4345 | int i = 0; |
| 4346 | |
| 4347 | psli = &phba->sli; |
| 4348 | |
| 4349 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4350 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4351 | "0329 Kill HBA Data: x%x x%x\n", |
| 4352 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4353 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4354 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4355 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4356 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4357 | |
| 4358 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4359 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4360 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 4361 | spin_unlock_irq(&phba->hbalock); |
| 4362 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4363 | return 1; |
| 4364 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4365 | status &= ~HC_ERINT_ENA; |
| 4366 | writel(status, phba->HCregaddr); |
| 4367 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4368 | phba->link_flag |= LS_IGNORE_ERATT; |
| 4369 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4370 | |
| 4371 | lpfc_kill_board(phba, pmb); |
| 4372 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4373 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4374 | |
| 4375 | if (retval != MBX_SUCCESS) { |
| 4376 | if (retval != MBX_BUSY) |
| 4377 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4378 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4379 | "2752 KILL_BOARD command failed retval %d\n", |
| 4380 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4381 | spin_lock_irq(&phba->hbalock); |
| 4382 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4383 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4384 | return 1; |
| 4385 | } |
| 4386 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4387 | spin_lock_irq(&phba->hbalock); |
| 4388 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 4389 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4390 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4391 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4392 | |
| 4393 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 4394 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 4395 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 4396 | * board is now undefined. |
| 4397 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4398 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4399 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4400 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 4401 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4402 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4403 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4404 | } |
| 4405 | |
| 4406 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4407 | if (ha_copy & HA_ERATT) { |
| 4408 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4409 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4410 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4411 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4412 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4413 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4414 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4415 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4416 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4417 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4418 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4419 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4420 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4421 | } |
| 4422 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4423 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4424 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4425 | * @phba: Pointer to HBA context object. |
| 4426 | * |
| 4427 | * This function resets the HBA by writing HC_INITFF to the control |
| 4428 | * register. After the HBA resets, this function resets all the iocb ring |
| 4429 | * indices. This function disables PCI layer parity checking during |
| 4430 | * the reset. |
| 4431 | * This function returns 0 always. |
| 4432 | * The caller is not required to hold any locks. |
| 4433 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4434 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4435 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4436 | { |
| 4437 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4438 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4439 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4440 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4441 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4442 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4443 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4444 | /* Reset HBA */ |
| 4445 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4446 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4447 | (phba->pport) ? phba->pport->port_state : 0, |
| 4448 | psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4449 | |
| 4450 | /* perform board reset */ |
| 4451 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4452 | phba->link_events = 0; |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4453 | if (phba->pport) { |
| 4454 | phba->pport->fc_myDID = 0; |
| 4455 | phba->pport->fc_prevDID = 0; |
| 4456 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4457 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4458 | /* Turn off parity checking and serr during the physical reset */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 4459 | if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) |
| 4460 | return -EIO; |
| 4461 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4462 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4463 | (cfg_value & |
| 4464 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4465 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4466 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4467 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4468 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4469 | writel(HC_INITFF, phba->HCregaddr); |
| 4470 | mdelay(1); |
| 4471 | readl(phba->HCregaddr); /* flush */ |
| 4472 | writel(0, phba->HCregaddr); |
| 4473 | readl(phba->HCregaddr); /* flush */ |
| 4474 | |
| 4475 | /* Restore PCI cmd register */ |
| 4476 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4477 | |
| 4478 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4479 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4480 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4481 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4482 | pring->sli.sli3.rspidx = 0; |
| 4483 | pring->sli.sli3.next_cmdidx = 0; |
| 4484 | pring->sli.sli3.local_getidx = 0; |
| 4485 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4486 | pring->missbufcnt = 0; |
| 4487 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4488 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4489 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4490 | return 0; |
| 4491 | } |
| 4492 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4493 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4494 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4495 | * @phba: Pointer to HBA context object. |
| 4496 | * |
| 4497 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4498 | * checking during resets the device. The caller is not required to hold |
| 4499 | * any locks. |
| 4500 | * |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 4501 | * This function returns 0 on success else returns negative error code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4502 | **/ |
| 4503 | int |
| 4504 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4505 | { |
| 4506 | struct lpfc_sli *psli = &phba->sli; |
| 4507 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4508 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4509 | |
| 4510 | /* Reset HBA */ |
| 4511 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4512 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4513 | phba->pport->port_state, psli->sli_flag, |
| 4514 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4515 | |
| 4516 | /* perform board reset */ |
| 4517 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4518 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4519 | phba->pport->fc_myDID = 0; |
| 4520 | phba->pport->fc_prevDID = 0; |
| 4521 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4522 | spin_lock_irq(&phba->hbalock); |
| 4523 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4524 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4525 | spin_unlock_irq(&phba->hbalock); |
| 4526 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4527 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4528 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4529 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4530 | return rc; |
| 4531 | } |
| 4532 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4533 | /* Now physically reset the device */ |
| 4534 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4535 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4536 | |
| 4537 | /* Turn off parity checking and serr during the physical reset */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 4538 | if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) { |
| 4539 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4540 | "3205 PCI read Config failed\n"); |
| 4541 | return -EIO; |
| 4542 | } |
| 4543 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4544 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4545 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4546 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4547 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4548 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4549 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4550 | /* Restore PCI cmd register */ |
| 4551 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4552 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4553 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4554 | } |
| 4555 | |
| 4556 | /** |
| 4557 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4558 | * @phba: Pointer to HBA context object. |
| 4559 | * |
| 4560 | * This function is called in the SLI initialization code path to |
| 4561 | * restart the HBA. The caller is not required to hold any lock. |
| 4562 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4563 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4564 | * function to free any pending commands. The function enables |
| 4565 | * POST only during the first initialization. The function returns zero. |
| 4566 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4567 | * command before the return of this function. |
| 4568 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4569 | static int |
| 4570 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4571 | { |
| 4572 | MAILBOX_t *mb; |
| 4573 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4574 | volatile uint32_t word0; |
| 4575 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4576 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4577 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4578 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4579 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4580 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4581 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4582 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4583 | psli = &phba->sli; |
| 4584 | |
| 4585 | /* Restart HBA */ |
| 4586 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4587 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4588 | (phba->pport) ? phba->pport->port_state : 0, |
| 4589 | psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4590 | |
| 4591 | word0 = 0; |
| 4592 | mb = (MAILBOX_t *) &word0; |
| 4593 | mb->mbxCommand = MBX_RESTART; |
| 4594 | mb->mbxHc = 1; |
| 4595 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4596 | lpfc_reset_barrier(phba); |
| 4597 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4598 | to_slim = phba->MBslimaddr; |
| 4599 | writel(*(uint32_t *) mb, to_slim); |
| 4600 | readl(to_slim); /* flush */ |
| 4601 | |
| 4602 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4603 | if (phba->pport && phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4604 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4605 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4606 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4607 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4608 | writel(*(uint32_t *) mb, to_slim); |
| 4609 | readl(to_slim); /* flush */ |
| 4610 | |
| 4611 | lpfc_sli_brdreset(phba); |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4612 | if (phba->pport) |
| 4613 | phba->pport->stopped = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4614 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4615 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4616 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4617 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4618 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4619 | psli->stats_start = ktime_get_seconds(); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4620 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4621 | /* Give the INITFF and Post time to settle. */ |
| 4622 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4623 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4624 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4625 | if (hba_aer_enabled) |
| 4626 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4627 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4628 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4629 | |
| 4630 | return 0; |
| 4631 | } |
| 4632 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4633 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4634 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4635 | * @phba: Pointer to HBA context object. |
| 4636 | * |
| 4637 | * This function is called in the SLI initialization code path to restart |
| 4638 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4639 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4640 | * free any pending commands. |
| 4641 | **/ |
| 4642 | static int |
| 4643 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4644 | { |
| 4645 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4646 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4647 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4648 | |
| 4649 | /* Restart HBA */ |
| 4650 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4651 | "0296 Restart HBA Data: x%x x%x\n", |
| 4652 | phba->pport->port_state, psli->sli_flag); |
| 4653 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4654 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4655 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4656 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4657 | rc = lpfc_sli4_brdreset(phba); |
James Smart | 4fb86a6 | 2019-09-03 14:54:41 -0700 | [diff] [blame] | 4658 | if (rc) { |
| 4659 | phba->link_state = LPFC_HBA_ERROR; |
| 4660 | goto hba_down_queue; |
| 4661 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4662 | |
| 4663 | spin_lock_irq(&phba->hbalock); |
| 4664 | phba->pport->stopped = 0; |
| 4665 | phba->link_state = LPFC_INIT_START; |
| 4666 | phba->hba_flag = 0; |
| 4667 | spin_unlock_irq(&phba->hbalock); |
| 4668 | |
| 4669 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4670 | psli->stats_start = ktime_get_seconds(); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4671 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4672 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4673 | if (hba_aer_enabled) |
| 4674 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4675 | |
James Smart | 4fb86a6 | 2019-09-03 14:54:41 -0700 | [diff] [blame] | 4676 | hba_down_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4677 | lpfc_hba_down_post(phba); |
James Smart | 569dbe8 | 2017-06-15 22:56:47 -0700 | [diff] [blame] | 4678 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4679 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4680 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4681 | } |
| 4682 | |
| 4683 | /** |
| 4684 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4685 | * @phba: Pointer to HBA context object. |
| 4686 | * |
| 4687 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4688 | * API jump table function pointer from the lpfc_hba struct. |
| 4689 | **/ |
| 4690 | int |
| 4691 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4692 | { |
| 4693 | return phba->lpfc_sli_brdrestart(phba); |
| 4694 | } |
| 4695 | |
| 4696 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4697 | * 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] | 4698 | * @phba: Pointer to HBA context object. |
| 4699 | * |
| 4700 | * This function is called after a HBA restart to wait for successful |
| 4701 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4702 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4703 | * iteration, the function will restart the HBA again. The function returns |
| 4704 | * zero if HBA successfully restarted else returns negative error code. |
| 4705 | **/ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4706 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4707 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4708 | { |
| 4709 | uint32_t status, i = 0; |
| 4710 | |
| 4711 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4712 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4713 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4714 | |
| 4715 | /* Check status register to see what current state is */ |
| 4716 | i = 0; |
| 4717 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4718 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4719 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4720 | * retries, then every 1 sec for 50 retires for a total of |
| 4721 | * ~60 seconds before reset the board again and check every |
| 4722 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4723 | * board ready is required by the Falcon FIPS zeroization |
| 4724 | * complete, and any reset the board in between shall cause |
| 4725 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4726 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4727 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4728 | /* Adapter failed to init, timeout, status reg |
| 4729 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4730 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4731 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4732 | "timeout, status reg x%x, " |
| 4733 | "FW Data: A8 x%x AC x%x\n", status, |
| 4734 | readl(phba->MBslimaddr + 0xa8), |
| 4735 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4736 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4737 | return -ETIMEDOUT; |
| 4738 | } |
| 4739 | |
| 4740 | /* Check to see if any errors occurred during init */ |
| 4741 | if (status & HS_FFERM) { |
| 4742 | /* ERROR: During chipset initialization */ |
| 4743 | /* Adapter failed to init, chipset, status reg |
| 4744 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4745 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4746 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4747 | "chipset, status reg x%x, " |
| 4748 | "FW Data: A8 x%x AC x%x\n", status, |
| 4749 | readl(phba->MBslimaddr + 0xa8), |
| 4750 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4751 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4752 | return -EIO; |
| 4753 | } |
| 4754 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4755 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4756 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4757 | else if (i <= 100) |
| 4758 | msleep(100); |
| 4759 | else |
| 4760 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4761 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4762 | if (i == 150) { |
| 4763 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4764 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4765 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4766 | } |
| 4767 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4768 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4769 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | /* Check to see if any errors occurred during init */ |
| 4773 | if (status & HS_FFERM) { |
| 4774 | /* ERROR: During chipset initialization */ |
| 4775 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4776 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4777 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4778 | "status reg x%x, " |
| 4779 | "FW Data: A8 x%x AC x%x\n", status, |
| 4780 | readl(phba->MBslimaddr + 0xa8), |
| 4781 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4782 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4783 | return -EIO; |
| 4784 | } |
| 4785 | |
| 4786 | /* Clear all interrupt enable conditions */ |
| 4787 | writel(0, phba->HCregaddr); |
| 4788 | readl(phba->HCregaddr); /* flush */ |
| 4789 | |
| 4790 | /* setup host attn register */ |
| 4791 | writel(0xffffffff, phba->HAregaddr); |
| 4792 | readl(phba->HAregaddr); /* flush */ |
| 4793 | return 0; |
| 4794 | } |
| 4795 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4796 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4797 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4798 | * |
| 4799 | * This function calculates and returns the number of HBQs required to be |
| 4800 | * configured. |
| 4801 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4802 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4803 | lpfc_sli_hbq_count(void) |
| 4804 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4805 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4806 | } |
| 4807 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4808 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4809 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4810 | * |
| 4811 | * This function adds the number of hbq entries in every HBQ to get |
| 4812 | * the total number of hbq entries required for the HBA and returns |
| 4813 | * the total count. |
| 4814 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4815 | static int |
| 4816 | lpfc_sli_hbq_entry_count(void) |
| 4817 | { |
| 4818 | int hbq_count = lpfc_sli_hbq_count(); |
| 4819 | int count = 0; |
| 4820 | int i; |
| 4821 | |
| 4822 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4823 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4824 | return count; |
| 4825 | } |
| 4826 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4827 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4828 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4829 | * |
| 4830 | * This function calculates amount of memory required for all hbq entries |
| 4831 | * to be configured and returns the total memory required. |
| 4832 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4833 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4834 | lpfc_sli_hbq_size(void) |
| 4835 | { |
| 4836 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4837 | } |
| 4838 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4839 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4840 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4841 | * @phba: Pointer to HBA context object. |
| 4842 | * |
| 4843 | * This function is called during the SLI initialization to configure |
| 4844 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4845 | * required to hold any locks. This function will return zero if successful |
| 4846 | * else it will return negative error code. |
| 4847 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4848 | static int |
| 4849 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4850 | { |
| 4851 | int hbq_count = lpfc_sli_hbq_count(); |
| 4852 | LPFC_MBOXQ_t *pmb; |
| 4853 | MAILBOX_t *pmbox; |
| 4854 | uint32_t hbqno; |
| 4855 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4856 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4857 | /* Get a Mailbox buffer to setup mailbox |
| 4858 | * commands for HBA initialization |
| 4859 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4860 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4861 | |
| 4862 | if (!pmb) |
| 4863 | return -ENOMEM; |
| 4864 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4865 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4866 | |
| 4867 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4868 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4869 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4870 | |
| 4871 | hbq_entry_index = 0; |
| 4872 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4873 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4874 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4875 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4876 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4877 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4878 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4879 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4880 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4881 | |
| 4882 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4883 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4884 | mbxStatus <status>, ring <num> */ |
| 4885 | |
| 4886 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4887 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4888 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4889 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4890 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4891 | pmbox->mbxStatus, hbqno); |
| 4892 | |
| 4893 | phba->link_state = LPFC_HBA_ERROR; |
| 4894 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4895 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4896 | } |
| 4897 | } |
| 4898 | phba->hbq_count = hbq_count; |
| 4899 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4900 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4901 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4902 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4903 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4904 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4905 | return 0; |
| 4906 | } |
| 4907 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4908 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4909 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4910 | * @phba: Pointer to HBA context object. |
| 4911 | * |
| 4912 | * This function is called during the SLI initialization to configure |
| 4913 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4914 | * required to hold any locks. This function will return zero if successful |
| 4915 | * else it will return negative error code. |
| 4916 | **/ |
| 4917 | static int |
| 4918 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4919 | { |
| 4920 | phba->hbq_in_use = 1; |
James Smart | 999fbbc | 2019-12-18 15:58:06 -0800 | [diff] [blame] | 4921 | /** |
| 4922 | * Specific case when the MDS diagnostics is enabled and supported. |
| 4923 | * The receive buffer count is truncated to manage the incoming |
| 4924 | * traffic. |
| 4925 | **/ |
| 4926 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) |
| 4927 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 4928 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count >> 1; |
| 4929 | else |
| 4930 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 4931 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4932 | phba->hbq_count = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4933 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4934 | /* Initially populate or replenish the HBQs */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4935 | return 0; |
| 4936 | } |
| 4937 | |
| 4938 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4939 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4940 | * @phba: Pointer to HBA context object. |
| 4941 | * @sli_mode: sli mode - 2/3 |
| 4942 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4943 | * This function is called by the sli initialization code path |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4944 | * to issue config_port mailbox command. This function restarts the |
| 4945 | * HBA firmware and issues a config_port mailbox command to configure |
| 4946 | * the SLI interface in the sli mode specified by sli_mode |
| 4947 | * variable. The caller is not required to hold any locks. |
| 4948 | * The function returns 0 if successful, else returns negative error |
| 4949 | * code. |
| 4950 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4951 | int |
| 4952 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4953 | { |
| 4954 | LPFC_MBOXQ_t *pmb; |
| 4955 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4956 | |
| 4957 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4958 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4959 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4960 | return -ENOMEM; |
| 4961 | } |
| 4962 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4963 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4964 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4965 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4966 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4967 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4968 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4969 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4970 | rc = lpfc_sli_chipset_init(phba); |
| 4971 | if (rc) |
| 4972 | break; |
| 4973 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4974 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4975 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4976 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4977 | resetcount++; |
| 4978 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4979 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4980 | * value of 0 means the call was successful. Any other |
| 4981 | * nonzero value is a failure, but if ERESTART is returned, |
| 4982 | * the driver may reset the HBA and try again. |
| 4983 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4984 | rc = lpfc_config_port_prep(phba); |
| 4985 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4986 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4987 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4988 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4989 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4990 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4991 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4992 | lpfc_config_port(phba, pmb); |
| 4993 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4994 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4995 | LPFC_SLI3_HBQ_ENABLED | |
| 4996 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4997 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4998 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4999 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5000 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5001 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5002 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5003 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5004 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5005 | spin_unlock_irq(&phba->hbalock); |
| 5006 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5007 | } else { |
| 5008 | /* Allow asynchronous mailbox command to go through */ |
| 5009 | spin_lock_irq(&phba->hbalock); |
| 5010 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 5011 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5012 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5013 | |
| 5014 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 5015 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 5016 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5017 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5018 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5019 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5020 | if (!done) { |
| 5021 | rc = -EINVAL; |
| 5022 | goto do_prep_failed; |
| 5023 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5024 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 5025 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5026 | rc = -ENXIO; |
| 5027 | goto do_prep_failed; |
| 5028 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5029 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5030 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5031 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 5032 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 5033 | phba->max_vpi : phba->max_vports; |
| 5034 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5035 | } else |
| 5036 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5037 | phba->fips_level = 0; |
| 5038 | phba->fips_spec_rev = 0; |
| 5039 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5040 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5041 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 5042 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 5043 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5044 | "2850 Security Crypto Active. FIPS x%d " |
| 5045 | "(Spec Rev: x%d)", |
| 5046 | phba->fips_level, phba->fips_spec_rev); |
| 5047 | } |
| 5048 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 5049 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5050 | "2856 Config Port Security Crypto " |
| 5051 | "Error: x%x ", |
| 5052 | pmb->u.mb.un.varCfgPort.sec_err); |
| 5053 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5054 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5055 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5056 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5057 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 5058 | |
| 5059 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 5060 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5061 | |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5062 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 5063 | if (pmb->u.mb.un.varCfgPort.gbg == 0) { |
| 5064 | phba->cfg_enable_bg = 0; |
| 5065 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5066 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5067 | "0443 Adapter did not grant " |
| 5068 | "BlockGuard\n"); |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5069 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5070 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5071 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 5072 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5073 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5074 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5075 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5076 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5077 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5078 | return rc; |
| 5079 | } |
| 5080 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5081 | |
| 5082 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5083 | * lpfc_sli_hba_setup - SLI initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5084 | * @phba: Pointer to HBA context object. |
| 5085 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5086 | * This function is the main SLI initialization function. This function |
| 5087 | * is called by the HBA initialization code, HBA reset code and HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5088 | * error attention handler code. Caller is not required to hold any |
| 5089 | * locks. This function issues config_port mailbox command to configure |
| 5090 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 5091 | * calls the config_port_post function to issue init_link mailbox |
| 5092 | * command and to start the discovery. The function will return zero |
| 5093 | * if successful, else it will return negative error code. |
| 5094 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5095 | int |
| 5096 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 5097 | { |
| 5098 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5099 | int mode = 3, i; |
| 5100 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5101 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5102 | switch (phba->cfg_sli_mode) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5103 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 5104 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5105 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5106 | "1824 NPIV enabled: Override sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5107 | "parameter (%d) to auto (0).\n", |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5108 | phba->cfg_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5109 | break; |
| 5110 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5111 | mode = 2; |
| 5112 | break; |
| 5113 | case 0: |
| 5114 | case 3: |
| 5115 | break; |
| 5116 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5117 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5118 | "1819 Unrecognized sli_mode parameter: %d.\n", |
| 5119 | phba->cfg_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5120 | |
| 5121 | break; |
| 5122 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 5123 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5124 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5125 | rc = lpfc_sli_config_port(phba, mode); |
| 5126 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5127 | if (rc && phba->cfg_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5128 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5129 | "1820 Unable to select SLI-3. " |
| 5130 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5131 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5132 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | 4597663f | 2016-07-06 12:36:01 -0700 | [diff] [blame] | 5133 | else if (rc && mode == 2) |
| 5134 | rc = lpfc_sli_config_port(phba, 3); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5135 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5136 | goto lpfc_sli_hba_setup_error; |
| 5137 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5138 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 5139 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 5140 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 5141 | if (!rc) { |
| 5142 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5143 | "2709 This device supports " |
| 5144 | "Advanced Error Reporting (AER)\n"); |
| 5145 | spin_lock_irq(&phba->hbalock); |
| 5146 | phba->hba_flag |= HBA_AER_ENABLED; |
| 5147 | spin_unlock_irq(&phba->hbalock); |
| 5148 | } else { |
| 5149 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5150 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 5151 | "Advanced Error Reporting (AER): %d\n", |
| 5152 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5153 | phba->cfg_aer_support = 0; |
| 5154 | } |
| 5155 | } |
| 5156 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5157 | if (phba->sli_rev == 3) { |
| 5158 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 5159 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5160 | } else { |
| 5161 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 5162 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5163 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5167 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 5168 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5169 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5170 | |
| 5171 | if (rc) |
| 5172 | goto lpfc_sli_hba_setup_error; |
| 5173 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5174 | /* Initialize VPIs. */ |
| 5175 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 5176 | /* |
| 5177 | * The VPI bitmask and physical ID array are allocated |
| 5178 | * and initialized once only - at driver load. A port |
| 5179 | * reset doesn't need to reinitialize this memory. |
| 5180 | */ |
| 5181 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 5182 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5183 | phba->vpi_bmask = kcalloc(longs, |
| 5184 | sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5185 | GFP_KERNEL); |
| 5186 | if (!phba->vpi_bmask) { |
| 5187 | rc = -ENOMEM; |
| 5188 | goto lpfc_sli_hba_setup_error; |
| 5189 | } |
| 5190 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5191 | phba->vpi_ids = kcalloc(phba->max_vpi + 1, |
| 5192 | sizeof(uint16_t), |
| 5193 | GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5194 | if (!phba->vpi_ids) { |
| 5195 | kfree(phba->vpi_bmask); |
| 5196 | rc = -ENOMEM; |
| 5197 | goto lpfc_sli_hba_setup_error; |
| 5198 | } |
| 5199 | for (i = 0; i < phba->max_vpi; i++) |
| 5200 | phba->vpi_ids[i] = i; |
| 5201 | } |
| 5202 | } |
| 5203 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5204 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5205 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 5206 | rc = lpfc_sli_hbq_setup(phba); |
| 5207 | if (rc) |
| 5208 | goto lpfc_sli_hba_setup_error; |
| 5209 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5210 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5211 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5212 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5213 | |
| 5214 | rc = lpfc_config_port_post(phba); |
| 5215 | if (rc) |
| 5216 | goto lpfc_sli_hba_setup_error; |
| 5217 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5218 | return rc; |
| 5219 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5220 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5221 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 5222 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5223 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5224 | return rc; |
| 5225 | } |
| 5226 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5227 | /** |
| 5228 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 5229 | * @phba: Pointer to HBA context object. |
| 5230 | * @mboxq: mailbox pointer. |
| 5231 | * This function issue a dump mailbox command to read config region |
| 5232 | * 23 and parse the records in the region and populate driver |
| 5233 | * data structure. |
| 5234 | **/ |
| 5235 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5236 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5237 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5238 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5239 | struct lpfc_dmabuf *mp; |
| 5240 | struct lpfc_mqe *mqe; |
| 5241 | uint32_t data_length; |
| 5242 | int rc; |
| 5243 | |
| 5244 | /* Program the default value of vlan_id and fc_map */ |
| 5245 | phba->valid_vlan = 0; |
| 5246 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5247 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5248 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5249 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5250 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5251 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5252 | return -ENOMEM; |
| 5253 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5254 | mqe = &mboxq->u.mqe; |
| 5255 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 5256 | rc = -ENOMEM; |
| 5257 | goto out_free_mboxq; |
| 5258 | } |
| 5259 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5260 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5261 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5262 | |
| 5263 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5264 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 5265 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5266 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5267 | "CQ: x%x x%x x%x x%x\n", |
| 5268 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5269 | bf_get(lpfc_mqe_command, mqe), |
| 5270 | bf_get(lpfc_mqe_status, mqe), |
| 5271 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 5272 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 5273 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 5274 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 5275 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 5276 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 5277 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 5278 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 5279 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 5280 | mboxq->mcqe.word0, |
| 5281 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 5282 | mboxq->mcqe.trailer); |
| 5283 | |
| 5284 | if (rc) { |
| 5285 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5286 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5287 | rc = -EIO; |
| 5288 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5289 | } |
| 5290 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 5291 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5292 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5293 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5294 | rc = -EIO; |
| 5295 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5296 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5297 | |
| 5298 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 5299 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5300 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5301 | rc = 0; |
| 5302 | |
| 5303 | out_free_mboxq: |
| 5304 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5305 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5306 | } |
| 5307 | |
| 5308 | /** |
| 5309 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 5310 | * @phba: pointer to lpfc hba data structure. |
| 5311 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 5312 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 5313 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 5314 | * On output, the number of data bytes in @vpd. |
| 5315 | * |
| 5316 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 5317 | * addition, this routine gets the port vpd data. |
| 5318 | * |
| 5319 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5320 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5321 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5322 | **/ |
| 5323 | static int |
| 5324 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 5325 | uint8_t *vpd, uint32_t *vpd_size) |
| 5326 | { |
| 5327 | int rc = 0; |
| 5328 | uint32_t dma_size; |
| 5329 | struct lpfc_dmabuf *dmabuf; |
| 5330 | struct lpfc_mqe *mqe; |
| 5331 | |
| 5332 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5333 | if (!dmabuf) |
| 5334 | return -ENOMEM; |
| 5335 | |
| 5336 | /* |
| 5337 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 5338 | * mailbox command. |
| 5339 | */ |
| 5340 | dma_size = *vpd_size; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 5341 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, dma_size, |
| 5342 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5343 | if (!dmabuf->virt) { |
| 5344 | kfree(dmabuf); |
| 5345 | return -ENOMEM; |
| 5346 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5347 | |
| 5348 | /* |
| 5349 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 5350 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 5351 | * in SLI3. This code corrects the conflicts. |
| 5352 | */ |
| 5353 | lpfc_read_rev(phba, mboxq); |
| 5354 | mqe = &mboxq->u.mqe; |
| 5355 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 5356 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 5357 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 5358 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 5359 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 5360 | |
| 5361 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5362 | if (rc) { |
| 5363 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5364 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 5365 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5366 | return -EIO; |
| 5367 | } |
| 5368 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5369 | /* |
| 5370 | * The available vpd length cannot be bigger than the |
| 5371 | * DMA buffer passed to the port. Catch the less than |
| 5372 | * case and update the caller's size. |
| 5373 | */ |
| 5374 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 5375 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 5376 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5377 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 5378 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5379 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5380 | dmabuf->virt, dmabuf->phys); |
| 5381 | kfree(dmabuf); |
| 5382 | return 0; |
| 5383 | } |
| 5384 | |
| 5385 | /** |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5386 | * lpfc_sli4_get_ctl_attr - Retrieve SLI4 device controller attributes |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5387 | * @phba: pointer to lpfc hba data structure. |
| 5388 | * |
| 5389 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5390 | * is attached to. |
| 5391 | * |
| 5392 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5393 | * 0 - successful |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5394 | * otherwise - failed to retrieve controller attributes |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5395 | **/ |
| 5396 | static int |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5397 | lpfc_sli4_get_ctl_attr(struct lpfc_hba *phba) |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5398 | { |
| 5399 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5400 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 5401 | struct lpfc_controller_attribute *cntl_attr; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5402 | void *virtaddr = NULL; |
| 5403 | uint32_t alloclen, reqlen; |
| 5404 | uint32_t shdr_status, shdr_add_status; |
| 5405 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5406 | int rc; |
| 5407 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5408 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5409 | if (!mboxq) |
| 5410 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5411 | |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5412 | /* Send COMMON_GET_CNTL_ATTRIBUTES mbox cmd */ |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5413 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 5414 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5415 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 5416 | LPFC_SLI4_MBX_NEMBED); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5417 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5418 | if (alloclen < reqlen) { |
| 5419 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5420 | "3084 Allocated DMA memory size (%d) is " |
| 5421 | "less than the requested DMA memory size " |
| 5422 | "(%d)\n", alloclen, reqlen); |
| 5423 | rc = -ENOMEM; |
| 5424 | goto out_free_mboxq; |
| 5425 | } |
| 5426 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5427 | virtaddr = mboxq->sge_array->addr[0]; |
| 5428 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5429 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5430 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5431 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5432 | if (shdr_status || shdr_add_status || rc) { |
| 5433 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5434 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5435 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5436 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5437 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5438 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5439 | rc, shdr_status, shdr_add_status); |
| 5440 | rc = -ENXIO; |
| 5441 | goto out_free_mboxq; |
| 5442 | } |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5443 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5444 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5445 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5446 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5447 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5448 | phba->sli4_hba.lnk_info.lnk_no = |
| 5449 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5450 | |
| 5451 | memset(phba->BIOSVersion, 0, sizeof(phba->BIOSVersion)); |
| 5452 | strlcat(phba->BIOSVersion, (char *)cntl_attr->bios_ver_str, |
| 5453 | sizeof(phba->BIOSVersion)); |
| 5454 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5455 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5456 | "3086 lnk_type:%d, lnk_numb:%d, bios_ver:%s\n", |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5457 | phba->sli4_hba.lnk_info.lnk_tp, |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5458 | phba->sli4_hba.lnk_info.lnk_no, |
| 5459 | phba->BIOSVersion); |
| 5460 | out_free_mboxq: |
| 5461 | if (rc != MBX_TIMEOUT) { |
| 5462 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5463 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5464 | else |
| 5465 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5466 | } |
| 5467 | return rc; |
| 5468 | } |
| 5469 | |
| 5470 | /** |
| 5471 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 5472 | * @phba: pointer to lpfc hba data structure. |
| 5473 | * |
| 5474 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5475 | * is attached to. |
| 5476 | * |
| 5477 | * Return codes |
| 5478 | * 0 - successful |
| 5479 | * otherwise - failed to retrieve physical port name |
| 5480 | **/ |
| 5481 | static int |
| 5482 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 5483 | { |
| 5484 | LPFC_MBOXQ_t *mboxq; |
| 5485 | struct lpfc_mbx_get_port_name *get_port_name; |
| 5486 | uint32_t shdr_status, shdr_add_status; |
| 5487 | union lpfc_sli4_cfg_shdr *shdr; |
| 5488 | char cport_name = 0; |
| 5489 | int rc; |
| 5490 | |
| 5491 | /* We assume nothing at this point */ |
| 5492 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5493 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 5494 | |
| 5495 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5496 | if (!mboxq) |
| 5497 | return -ENOMEM; |
| 5498 | /* obtain link type and link number via READ_CONFIG */ |
| 5499 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5500 | lpfc_sli4_read_config(phba); |
| 5501 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 5502 | goto retrieve_ppname; |
| 5503 | |
| 5504 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 5505 | rc = lpfc_sli4_get_ctl_attr(phba); |
| 5506 | if (rc) |
| 5507 | goto out_free_mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5508 | |
| 5509 | retrieve_ppname: |
| 5510 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5511 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5512 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5513 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5514 | LPFC_SLI4_MBX_EMBED); |
| 5515 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5516 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5517 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5518 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5519 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5520 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5521 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5522 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5523 | if (shdr_status || shdr_add_status || rc) { |
| 5524 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5525 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5526 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5527 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5528 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5529 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5530 | rc, shdr_status, shdr_add_status); |
| 5531 | rc = -ENXIO; |
| 5532 | goto out_free_mboxq; |
| 5533 | } |
| 5534 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5535 | case LPFC_LINK_NUMBER_0: |
| 5536 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5537 | &get_port_name->u.response); |
| 5538 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5539 | break; |
| 5540 | case LPFC_LINK_NUMBER_1: |
| 5541 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5542 | &get_port_name->u.response); |
| 5543 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5544 | break; |
| 5545 | case LPFC_LINK_NUMBER_2: |
| 5546 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5547 | &get_port_name->u.response); |
| 5548 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5549 | break; |
| 5550 | case LPFC_LINK_NUMBER_3: |
| 5551 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5552 | &get_port_name->u.response); |
| 5553 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5554 | break; |
| 5555 | default: |
| 5556 | break; |
| 5557 | } |
| 5558 | |
| 5559 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5560 | phba->Port[0] = cport_name; |
| 5561 | phba->Port[1] = '\0'; |
| 5562 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5563 | "3091 SLI get port name: %s\n", phba->Port); |
| 5564 | } |
| 5565 | |
| 5566 | out_free_mboxq: |
| 5567 | if (rc != MBX_TIMEOUT) { |
| 5568 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5569 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5570 | else |
| 5571 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5572 | } |
| 5573 | return rc; |
| 5574 | } |
| 5575 | |
| 5576 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5577 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5578 | * @phba: pointer to lpfc hba data structure. |
| 5579 | * |
| 5580 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5581 | * event queues |
| 5582 | **/ |
| 5583 | static void |
| 5584 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5585 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5586 | int qidx; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5587 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5588 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5589 | struct lpfc_queue *eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5590 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5591 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM); |
| 5592 | 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] | 5593 | if (sli4_hba->nvmels_cq) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5594 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0, |
| 5595 | LPFC_QUEUE_REARM); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5596 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5597 | if (sli4_hba->hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5598 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5599 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5600 | qp = &sli4_hba->hdwq[qidx]; |
| 5601 | /* ARM the corresponding CQ */ |
James Smart | 01f2ef6 | 2019-08-28 16:19:11 -0700 | [diff] [blame] | 5602 | sli4_hba->sli4_write_cq_db(phba, qp->io_cq, 0, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 5603 | LPFC_QUEUE_REARM); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5604 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5605 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5606 | /* Loop thru all IRQ vectors */ |
| 5607 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 5608 | eq = sli4_hba->hba_eq_hdl[qidx].eq; |
| 5609 | /* ARM the corresponding EQ */ |
| 5610 | sli4_hba->sli4_write_eq_db(phba, eq, |
| 5611 | 0, LPFC_QUEUE_REARM); |
| 5612 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5613 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5614 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5615 | if (phba->nvmet_support) { |
| 5616 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5617 | sli4_hba->sli4_write_cq_db(phba, |
| 5618 | sli4_hba->nvmet_cqset[qidx], 0, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5619 | LPFC_QUEUE_REARM); |
| 5620 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5621 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5622 | } |
| 5623 | |
| 5624 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5625 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5626 | * @phba: Pointer to HBA context object. |
| 5627 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5628 | * @extnt_count: buffer to hold port available extent count. |
| 5629 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5630 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5631 | * This function calls the port and retrievs the number of available |
| 5632 | * extents and their size for a particular extent type. |
| 5633 | * |
| 5634 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5635 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5636 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5637 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5638 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5639 | { |
| 5640 | int rc = 0; |
| 5641 | uint32_t length; |
| 5642 | uint32_t mbox_tmo; |
| 5643 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5644 | LPFC_MBOXQ_t *mbox; |
| 5645 | |
| 5646 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5647 | if (!mbox) |
| 5648 | return -ENOMEM; |
| 5649 | |
| 5650 | /* Find out how many extents are available for this resource type */ |
| 5651 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5652 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5653 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5654 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5655 | length, LPFC_SLI4_MBX_EMBED); |
| 5656 | |
| 5657 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5658 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5659 | LPFC_SLI4_MBX_EMBED); |
| 5660 | if (unlikely(rc)) { |
| 5661 | rc = -EIO; |
| 5662 | goto err_exit; |
| 5663 | } |
| 5664 | |
| 5665 | if (!phba->sli4_hba.intr_enable) |
| 5666 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5667 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5668 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5669 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5670 | } |
| 5671 | if (unlikely(rc)) { |
| 5672 | rc = -EIO; |
| 5673 | goto err_exit; |
| 5674 | } |
| 5675 | |
| 5676 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5677 | if (bf_get(lpfc_mbox_hdr_status, |
| 5678 | &rsrc_info->header.cfg_shdr.response)) { |
| 5679 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5680 | "2930 Failed to get resource extents " |
| 5681 | "Status 0x%x Add'l Status 0x%x\n", |
| 5682 | bf_get(lpfc_mbox_hdr_status, |
| 5683 | &rsrc_info->header.cfg_shdr.response), |
| 5684 | bf_get(lpfc_mbox_hdr_add_status, |
| 5685 | &rsrc_info->header.cfg_shdr.response)); |
| 5686 | rc = -EIO; |
| 5687 | goto err_exit; |
| 5688 | } |
| 5689 | |
| 5690 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5691 | &rsrc_info->u.rsp); |
| 5692 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5693 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5694 | |
| 5695 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5696 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5697 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5698 | |
| 5699 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5700 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5701 | return rc; |
| 5702 | } |
| 5703 | |
| 5704 | /** |
| 5705 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5706 | * @phba: Pointer to HBA context object. |
| 5707 | * @type: The extent type to check. |
| 5708 | * |
| 5709 | * This function reads the current available extents from the port and checks |
| 5710 | * if the extent count or extent size has changed since the last access. |
| 5711 | * Callers use this routine post port reset to understand if there is a |
| 5712 | * extent reprovisioning requirement. |
| 5713 | * |
| 5714 | * Returns: |
| 5715 | * -Error: error indicates problem. |
| 5716 | * 1: Extent count or size has changed. |
| 5717 | * 0: No changes. |
| 5718 | **/ |
| 5719 | static int |
| 5720 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5721 | { |
| 5722 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5723 | uint16_t size_diff, rsrc_ext_size; |
| 5724 | int rc = 0; |
| 5725 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5726 | struct list_head *rsrc_blk_list = NULL; |
| 5727 | |
| 5728 | size_diff = 0; |
| 5729 | curr_ext_cnt = 0; |
| 5730 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5731 | &rsrc_ext_cnt, |
| 5732 | &rsrc_ext_size); |
| 5733 | if (unlikely(rc)) |
| 5734 | return -EIO; |
| 5735 | |
| 5736 | switch (type) { |
| 5737 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5738 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5739 | break; |
| 5740 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5741 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5742 | break; |
| 5743 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5744 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5745 | break; |
| 5746 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5747 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5748 | break; |
| 5749 | default: |
| 5750 | break; |
| 5751 | } |
| 5752 | |
| 5753 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5754 | curr_ext_cnt++; |
| 5755 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5756 | size_diff++; |
| 5757 | } |
| 5758 | |
| 5759 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5760 | rc = 1; |
| 5761 | |
| 5762 | return rc; |
| 5763 | } |
| 5764 | |
| 5765 | /** |
| 5766 | * lpfc_sli4_cfg_post_extnts - |
| 5767 | * @phba: Pointer to HBA context object. |
| 5768 | * @extnt_cnt - number of available extents. |
| 5769 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5770 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5771 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5772 | * |
| 5773 | * This function executes the extents allocation request. It also |
| 5774 | * takes care of the amount of memory needed to allocate or get the |
| 5775 | * allocated extents. It is the caller's responsibility to evaluate |
| 5776 | * the response. |
| 5777 | * |
| 5778 | * Returns: |
| 5779 | * -Error: Error value describes the condition found. |
| 5780 | * 0: if successful |
| 5781 | **/ |
| 5782 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5783 | 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] | 5784 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5785 | { |
| 5786 | int rc = 0; |
| 5787 | uint32_t req_len; |
| 5788 | uint32_t emb_len; |
| 5789 | uint32_t alloc_len, mbox_tmo; |
| 5790 | |
| 5791 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5792 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5793 | |
| 5794 | /* |
| 5795 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5796 | * accounts for extents-specific word. |
| 5797 | */ |
| 5798 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5799 | sizeof(uint32_t); |
| 5800 | |
| 5801 | /* |
| 5802 | * Presume the allocation and response will fit into an embedded |
| 5803 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5804 | */ |
| 5805 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5806 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5807 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5808 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5809 | sizeof(uint32_t); |
| 5810 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5811 | } |
| 5812 | |
| 5813 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5814 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5815 | req_len, *emb); |
| 5816 | if (alloc_len < req_len) { |
| 5817 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5818 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5819 | "less than the requested DMA memory " |
| 5820 | "size (x%x)\n", alloc_len, req_len); |
| 5821 | return -ENOMEM; |
| 5822 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5823 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5824 | if (unlikely(rc)) |
| 5825 | return -EIO; |
| 5826 | |
| 5827 | if (!phba->sli4_hba.intr_enable) |
| 5828 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5829 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5830 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5831 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5832 | } |
| 5833 | |
| 5834 | if (unlikely(rc)) |
| 5835 | rc = -EIO; |
| 5836 | return rc; |
| 5837 | } |
| 5838 | |
| 5839 | /** |
| 5840 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5841 | * @phba: Pointer to HBA context object. |
| 5842 | * @type: The resource extent type to allocate. |
| 5843 | * |
| 5844 | * This function allocates the number of elements for the specified |
| 5845 | * resource type. |
| 5846 | **/ |
| 5847 | static int |
| 5848 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5849 | { |
| 5850 | bool emb = false; |
| 5851 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5852 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5853 | uint16_t *ids; |
| 5854 | int i, rc; |
| 5855 | unsigned long longs; |
| 5856 | unsigned long *bmask; |
| 5857 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5858 | LPFC_MBOXQ_t *mbox; |
| 5859 | uint32_t length; |
| 5860 | struct lpfc_id_range *id_array = NULL; |
| 5861 | void *virtaddr = NULL; |
| 5862 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5863 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5864 | struct list_head *ext_blk_list; |
| 5865 | |
| 5866 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5867 | &rsrc_cnt, |
| 5868 | &rsrc_size); |
| 5869 | if (unlikely(rc)) |
| 5870 | return -EIO; |
| 5871 | |
| 5872 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5873 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5874 | "3009 No available Resource Extents " |
| 5875 | "for resource type 0x%x: Count: 0x%x, " |
| 5876 | "Size 0x%x\n", type, rsrc_cnt, |
| 5877 | rsrc_size); |
| 5878 | return -ENOMEM; |
| 5879 | } |
| 5880 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5881 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5882 | "2903 Post resource extents type-0x%x: " |
| 5883 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5884 | |
| 5885 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5886 | if (!mbox) |
| 5887 | return -ENOMEM; |
| 5888 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5889 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5890 | if (unlikely(rc)) { |
| 5891 | rc = -EIO; |
| 5892 | goto err_exit; |
| 5893 | } |
| 5894 | |
| 5895 | /* |
| 5896 | * Figure out where the response is located. Then get local pointers |
| 5897 | * to the response data. The port does not guarantee to respond to |
| 5898 | * all extents counts request so update the local variable with the |
| 5899 | * allocated count from the port. |
| 5900 | */ |
| 5901 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5902 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5903 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5904 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5905 | } else { |
| 5906 | virtaddr = mbox->sge_array->addr[0]; |
| 5907 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5908 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5909 | id_array = &n_rsrc->id; |
| 5910 | } |
| 5911 | |
| 5912 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5913 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5914 | |
| 5915 | /* |
| 5916 | * Based on the resource size and count, correct the base and max |
| 5917 | * resource values. |
| 5918 | */ |
| 5919 | length = sizeof(struct lpfc_rsrc_blks); |
| 5920 | switch (type) { |
| 5921 | case LPFC_RSC_TYPE_FCOE_RPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5922 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5923 | sizeof(unsigned long), |
| 5924 | GFP_KERNEL); |
| 5925 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5926 | rc = -ENOMEM; |
| 5927 | goto err_exit; |
| 5928 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5929 | phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5930 | sizeof(uint16_t), |
| 5931 | GFP_KERNEL); |
| 5932 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5933 | kfree(phba->sli4_hba.rpi_bmask); |
| 5934 | rc = -ENOMEM; |
| 5935 | goto err_exit; |
| 5936 | } |
| 5937 | |
| 5938 | /* |
| 5939 | * The next_rpi was initialized with the maximum available |
| 5940 | * count but the port may allocate a smaller number. Catch |
| 5941 | * that case and update the next_rpi. |
| 5942 | */ |
| 5943 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5944 | |
| 5945 | /* Initialize local ptrs for common extent processing later. */ |
| 5946 | bmask = phba->sli4_hba.rpi_bmask; |
| 5947 | ids = phba->sli4_hba.rpi_ids; |
| 5948 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5949 | break; |
| 5950 | case LPFC_RSC_TYPE_FCOE_VPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5951 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5952 | GFP_KERNEL); |
| 5953 | if (unlikely(!phba->vpi_bmask)) { |
| 5954 | rc = -ENOMEM; |
| 5955 | goto err_exit; |
| 5956 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5957 | phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5958 | GFP_KERNEL); |
| 5959 | if (unlikely(!phba->vpi_ids)) { |
| 5960 | kfree(phba->vpi_bmask); |
| 5961 | rc = -ENOMEM; |
| 5962 | goto err_exit; |
| 5963 | } |
| 5964 | |
| 5965 | /* Initialize local ptrs for common extent processing later. */ |
| 5966 | bmask = phba->vpi_bmask; |
| 5967 | ids = phba->vpi_ids; |
| 5968 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5969 | break; |
| 5970 | case LPFC_RSC_TYPE_FCOE_XRI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5971 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5972 | sizeof(unsigned long), |
| 5973 | GFP_KERNEL); |
| 5974 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5975 | rc = -ENOMEM; |
| 5976 | goto err_exit; |
| 5977 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5978 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5979 | phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5980 | sizeof(uint16_t), |
| 5981 | GFP_KERNEL); |
| 5982 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5983 | kfree(phba->sli4_hba.xri_bmask); |
| 5984 | rc = -ENOMEM; |
| 5985 | goto err_exit; |
| 5986 | } |
| 5987 | |
| 5988 | /* Initialize local ptrs for common extent processing later. */ |
| 5989 | bmask = phba->sli4_hba.xri_bmask; |
| 5990 | ids = phba->sli4_hba.xri_ids; |
| 5991 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5992 | break; |
| 5993 | case LPFC_RSC_TYPE_FCOE_VFI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5994 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5995 | sizeof(unsigned long), |
| 5996 | GFP_KERNEL); |
| 5997 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5998 | rc = -ENOMEM; |
| 5999 | goto err_exit; |
| 6000 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6001 | phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6002 | sizeof(uint16_t), |
| 6003 | GFP_KERNEL); |
| 6004 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6005 | kfree(phba->sli4_hba.vfi_bmask); |
| 6006 | rc = -ENOMEM; |
| 6007 | goto err_exit; |
| 6008 | } |
| 6009 | |
| 6010 | /* Initialize local ptrs for common extent processing later. */ |
| 6011 | bmask = phba->sli4_hba.vfi_bmask; |
| 6012 | ids = phba->sli4_hba.vfi_ids; |
| 6013 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6014 | break; |
| 6015 | default: |
| 6016 | /* Unsupported Opcode. Fail call. */ |
| 6017 | id_array = NULL; |
| 6018 | bmask = NULL; |
| 6019 | ids = NULL; |
| 6020 | ext_blk_list = NULL; |
| 6021 | goto err_exit; |
| 6022 | } |
| 6023 | |
| 6024 | /* |
| 6025 | * Complete initializing the extent configuration with the |
| 6026 | * allocated ids assigned to this function. The bitmask serves |
| 6027 | * as an index into the array and manages the available ids. The |
| 6028 | * array just stores the ids communicated to the port via the wqes. |
| 6029 | */ |
| 6030 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 6031 | if ((i % 2) == 0) |
| 6032 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 6033 | &id_array[k]); |
| 6034 | else |
| 6035 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 6036 | &id_array[k]); |
| 6037 | |
| 6038 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 6039 | if (unlikely(!rsrc_blks)) { |
| 6040 | rc = -ENOMEM; |
| 6041 | kfree(bmask); |
| 6042 | kfree(ids); |
| 6043 | goto err_exit; |
| 6044 | } |
| 6045 | rsrc_blks->rsrc_start = rsrc_id; |
| 6046 | rsrc_blks->rsrc_size = rsrc_size; |
| 6047 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 6048 | rsrc_start = rsrc_id; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6049 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6050 | phba->sli4_hba.io_xri_start = rsrc_start + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6051 | lpfc_sli4_get_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6052 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6053 | |
| 6054 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 6055 | ids[j] = rsrc_id; |
| 6056 | rsrc_id++; |
| 6057 | j++; |
| 6058 | } |
| 6059 | /* Entire word processed. Get next word.*/ |
| 6060 | if ((i % 2) == 1) |
| 6061 | k++; |
| 6062 | } |
| 6063 | err_exit: |
| 6064 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6065 | return rc; |
| 6066 | } |
| 6067 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6068 | |
| 6069 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6070 | /** |
| 6071 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 6072 | * @phba: Pointer to HBA context object. |
| 6073 | * @type: the extent's type. |
| 6074 | * |
| 6075 | * This function deallocates all extents of a particular resource type. |
| 6076 | * SLI4 does not allow for deallocating a particular extent range. It |
| 6077 | * is the caller's responsibility to release all kernel memory resources. |
| 6078 | **/ |
| 6079 | static int |
| 6080 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 6081 | { |
| 6082 | int rc; |
| 6083 | uint32_t length, mbox_tmo = 0; |
| 6084 | LPFC_MBOXQ_t *mbox; |
| 6085 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 6086 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 6087 | |
| 6088 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6089 | if (!mbox) |
| 6090 | return -ENOMEM; |
| 6091 | |
| 6092 | /* |
| 6093 | * This function sends an embedded mailbox because it only sends the |
| 6094 | * the resource type. All extents of this type are released by the |
| 6095 | * port. |
| 6096 | */ |
| 6097 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 6098 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6099 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6100 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 6101 | length, LPFC_SLI4_MBX_EMBED); |
| 6102 | |
| 6103 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 6104 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 6105 | LPFC_SLI4_MBX_EMBED); |
| 6106 | if (unlikely(rc)) { |
| 6107 | rc = -EIO; |
| 6108 | goto out_free_mbox; |
| 6109 | } |
| 6110 | if (!phba->sli4_hba.intr_enable) |
| 6111 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6112 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6113 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6114 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6115 | } |
| 6116 | if (unlikely(rc)) { |
| 6117 | rc = -EIO; |
| 6118 | goto out_free_mbox; |
| 6119 | } |
| 6120 | |
| 6121 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 6122 | if (bf_get(lpfc_mbox_hdr_status, |
| 6123 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 6124 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6125 | "2919 Failed to release resource extents " |
| 6126 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 6127 | "Resource memory not released.\n", |
| 6128 | type, |
| 6129 | bf_get(lpfc_mbox_hdr_status, |
| 6130 | &dealloc_rsrc->header.cfg_shdr.response), |
| 6131 | bf_get(lpfc_mbox_hdr_add_status, |
| 6132 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 6133 | rc = -EIO; |
| 6134 | goto out_free_mbox; |
| 6135 | } |
| 6136 | |
| 6137 | /* Release kernel memory resources for the specific type. */ |
| 6138 | switch (type) { |
| 6139 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6140 | kfree(phba->vpi_bmask); |
| 6141 | kfree(phba->vpi_ids); |
| 6142 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6143 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6144 | &phba->lpfc_vpi_blk_list, list) { |
| 6145 | list_del_init(&rsrc_blk->list); |
| 6146 | kfree(rsrc_blk); |
| 6147 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6148 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6149 | break; |
| 6150 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6151 | kfree(phba->sli4_hba.xri_bmask); |
| 6152 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6153 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6154 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 6155 | list_del_init(&rsrc_blk->list); |
| 6156 | kfree(rsrc_blk); |
| 6157 | } |
| 6158 | break; |
| 6159 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6160 | kfree(phba->sli4_hba.vfi_bmask); |
| 6161 | kfree(phba->sli4_hba.vfi_ids); |
| 6162 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6163 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6164 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 6165 | list_del_init(&rsrc_blk->list); |
| 6166 | kfree(rsrc_blk); |
| 6167 | } |
| 6168 | break; |
| 6169 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6170 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 6171 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6172 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 6173 | list_del_init(&rsrc_blk->list); |
| 6174 | kfree(rsrc_blk); |
| 6175 | } |
| 6176 | break; |
| 6177 | default: |
| 6178 | break; |
| 6179 | } |
| 6180 | |
| 6181 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6182 | |
| 6183 | out_free_mbox: |
| 6184 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6185 | return rc; |
| 6186 | } |
| 6187 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 6188 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6189 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 6190 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6191 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6192 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6193 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6194 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 6195 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6196 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6197 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 6198 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6199 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6200 | switch (feature) { |
| 6201 | case LPFC_SET_UE_RECOVERY: |
| 6202 | bf_set(lpfc_mbx_set_feature_UER, |
| 6203 | &mbox->u.mqe.un.set_feature, 1); |
| 6204 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 6205 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6206 | break; |
| 6207 | case LPFC_SET_MDS_DIAGS: |
| 6208 | bf_set(lpfc_mbx_set_feature_mds, |
| 6209 | &mbox->u.mqe.un.set_feature, 1); |
| 6210 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 6211 | &mbox->u.mqe.un.set_feature, 1); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6212 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 6213 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6214 | break; |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 6215 | case LPFC_SET_DUAL_DUMP: |
| 6216 | bf_set(lpfc_mbx_set_feature_dd, |
| 6217 | &mbox->u.mqe.un.set_feature, LPFC_ENABLE_DUAL_DUMP); |
| 6218 | bf_set(lpfc_mbx_set_feature_ddquery, |
| 6219 | &mbox->u.mqe.un.set_feature, 0); |
| 6220 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_DUAL_DUMP; |
| 6221 | mbox->u.mqe.un.set_feature.param_len = 4; |
| 6222 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6223 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6224 | |
| 6225 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6226 | } |
| 6227 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6228 | /** |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6229 | * lpfc_ras_stop_fwlog: Disable FW logging by the adapter |
| 6230 | * @phba: Pointer to HBA context object. |
| 6231 | * |
| 6232 | * Disable FW logging into host memory on the adapter. To |
| 6233 | * be done before reading logs from the host memory. |
| 6234 | **/ |
| 6235 | void |
| 6236 | lpfc_ras_stop_fwlog(struct lpfc_hba *phba) |
| 6237 | { |
| 6238 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6239 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6240 | spin_lock_irq(&phba->hbalock); |
| 6241 | ras_fwlog->state = INACTIVE; |
| 6242 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6243 | |
| 6244 | /* Disable FW logging to host memory */ |
| 6245 | writel(LPFC_CTL_PDEV_CTL_DDL_RAS, |
| 6246 | phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET); |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6247 | |
| 6248 | /* Wait 10ms for firmware to stop using DMA buffer */ |
| 6249 | usleep_range(10 * 1000, 20 * 1000); |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6250 | } |
| 6251 | |
| 6252 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6253 | * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging. |
| 6254 | * @phba: Pointer to HBA context object. |
| 6255 | * |
| 6256 | * This function is called to free memory allocated for RAS FW logging |
| 6257 | * support in the driver. |
| 6258 | **/ |
| 6259 | void |
| 6260 | lpfc_sli4_ras_dma_free(struct lpfc_hba *phba) |
| 6261 | { |
| 6262 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6263 | struct lpfc_dmabuf *dmabuf, *next; |
| 6264 | |
| 6265 | if (!list_empty(&ras_fwlog->fwlog_buff_list)) { |
| 6266 | list_for_each_entry_safe(dmabuf, next, |
| 6267 | &ras_fwlog->fwlog_buff_list, |
| 6268 | list) { |
| 6269 | list_del(&dmabuf->list); |
| 6270 | dma_free_coherent(&phba->pcidev->dev, |
| 6271 | LPFC_RAS_MAX_ENTRY_SIZE, |
| 6272 | dmabuf->virt, dmabuf->phys); |
| 6273 | kfree(dmabuf); |
| 6274 | } |
| 6275 | } |
| 6276 | |
| 6277 | if (ras_fwlog->lwpd.virt) { |
| 6278 | dma_free_coherent(&phba->pcidev->dev, |
| 6279 | sizeof(uint32_t) * 2, |
| 6280 | ras_fwlog->lwpd.virt, |
| 6281 | ras_fwlog->lwpd.phys); |
| 6282 | ras_fwlog->lwpd.virt = NULL; |
| 6283 | } |
| 6284 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6285 | spin_lock_irq(&phba->hbalock); |
| 6286 | ras_fwlog->state = INACTIVE; |
| 6287 | spin_unlock_irq(&phba->hbalock); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6288 | } |
| 6289 | |
| 6290 | /** |
| 6291 | * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support |
| 6292 | * @phba: Pointer to HBA context object. |
| 6293 | * @fwlog_buff_count: Count of buffers to be created. |
| 6294 | * |
| 6295 | * This routine DMA memory for Log Write Position Data[LPWD] and buffer |
| 6296 | * to update FW log is posted to the adapter. |
| 6297 | * Buffer count is calculated based on module param ras_fwlog_buffsize |
| 6298 | * Size of each buffer posted to FW is 64K. |
| 6299 | **/ |
| 6300 | |
| 6301 | static int |
| 6302 | lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba, |
| 6303 | uint32_t fwlog_buff_count) |
| 6304 | { |
| 6305 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6306 | struct lpfc_dmabuf *dmabuf; |
| 6307 | int rc = 0, i = 0; |
| 6308 | |
| 6309 | /* Initialize List */ |
| 6310 | INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list); |
| 6311 | |
| 6312 | /* Allocate memory for the LWPD */ |
| 6313 | ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6314 | sizeof(uint32_t) * 2, |
| 6315 | &ras_fwlog->lwpd.phys, |
| 6316 | GFP_KERNEL); |
| 6317 | if (!ras_fwlog->lwpd.virt) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6318 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6319 | "6185 LWPD Memory Alloc Failed\n"); |
| 6320 | |
| 6321 | return -ENOMEM; |
| 6322 | } |
| 6323 | |
| 6324 | ras_fwlog->fw_buffcount = fwlog_buff_count; |
| 6325 | for (i = 0; i < ras_fwlog->fw_buffcount; i++) { |
| 6326 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 6327 | GFP_KERNEL); |
| 6328 | if (!dmabuf) { |
| 6329 | rc = -ENOMEM; |
| 6330 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6331 | "6186 Memory Alloc failed FW logging"); |
| 6332 | goto free_mem; |
| 6333 | } |
| 6334 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6335 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6336 | LPFC_RAS_MAX_ENTRY_SIZE, |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6337 | &dmabuf->phys, GFP_KERNEL); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6338 | if (!dmabuf->virt) { |
| 6339 | kfree(dmabuf); |
| 6340 | rc = -ENOMEM; |
| 6341 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6342 | "6187 DMA Alloc Failed FW logging"); |
| 6343 | goto free_mem; |
| 6344 | } |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6345 | dmabuf->buffer_tag = i; |
| 6346 | list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list); |
| 6347 | } |
| 6348 | |
| 6349 | free_mem: |
| 6350 | if (rc) |
| 6351 | lpfc_sli4_ras_dma_free(phba); |
| 6352 | |
| 6353 | return rc; |
| 6354 | } |
| 6355 | |
| 6356 | /** |
| 6357 | * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command |
| 6358 | * @phba: pointer to lpfc hba data structure. |
| 6359 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 6360 | * |
| 6361 | * Completion handler for driver's RAS MBX command to the device. |
| 6362 | **/ |
| 6363 | static void |
| 6364 | lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6365 | { |
| 6366 | MAILBOX_t *mb; |
| 6367 | union lpfc_sli4_cfg_shdr *shdr; |
| 6368 | uint32_t shdr_status, shdr_add_status; |
| 6369 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6370 | |
| 6371 | mb = &pmb->u.mb; |
| 6372 | |
| 6373 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6374 | &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr; |
| 6375 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6376 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6377 | |
| 6378 | if (mb->mbxStatus != MBX_SUCCESS || shdr_status) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6379 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6380 | "6188 FW LOG mailbox " |
| 6381 | "completed with status x%x add_status x%x," |
| 6382 | " mbx status x%x\n", |
| 6383 | shdr_status, shdr_add_status, mb->mbxStatus); |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6384 | |
| 6385 | ras_fwlog->ras_hwsupport = false; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6386 | goto disable_ras; |
| 6387 | } |
| 6388 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6389 | spin_lock_irq(&phba->hbalock); |
| 6390 | ras_fwlog->state = ACTIVE; |
| 6391 | spin_unlock_irq(&phba->hbalock); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6392 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6393 | |
| 6394 | return; |
| 6395 | |
| 6396 | disable_ras: |
| 6397 | /* Free RAS DMA memory */ |
| 6398 | lpfc_sli4_ras_dma_free(phba); |
| 6399 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6400 | } |
| 6401 | |
| 6402 | /** |
| 6403 | * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command |
| 6404 | * @phba: pointer to lpfc hba data structure. |
| 6405 | * @fwlog_level: Logging verbosity level. |
| 6406 | * @fwlog_enable: Enable/Disable logging. |
| 6407 | * |
| 6408 | * Initialize memory and post mailbox command to enable FW logging in host |
| 6409 | * memory. |
| 6410 | **/ |
| 6411 | int |
| 6412 | lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba, |
| 6413 | uint32_t fwlog_level, |
| 6414 | uint32_t fwlog_enable) |
| 6415 | { |
| 6416 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6417 | struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL; |
| 6418 | struct lpfc_dmabuf *dmabuf; |
| 6419 | LPFC_MBOXQ_t *mbox; |
| 6420 | uint32_t len = 0, fwlog_buffsize, fwlog_entry_count; |
| 6421 | int rc = 0; |
| 6422 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6423 | spin_lock_irq(&phba->hbalock); |
| 6424 | ras_fwlog->state = INACTIVE; |
| 6425 | spin_unlock_irq(&phba->hbalock); |
| 6426 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6427 | fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE * |
| 6428 | phba->cfg_ras_fwlog_buffsize); |
| 6429 | fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE); |
| 6430 | |
| 6431 | /* |
| 6432 | * If re-enabling FW logging support use earlier allocated |
| 6433 | * DMA buffers while posting MBX command. |
| 6434 | **/ |
| 6435 | if (!ras_fwlog->lwpd.virt) { |
| 6436 | rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count); |
| 6437 | if (rc) { |
| 6438 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6439 | "6189 FW Log Memory Allocation Failed"); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6440 | return rc; |
| 6441 | } |
| 6442 | } |
| 6443 | |
| 6444 | /* Setup Mailbox command */ |
| 6445 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6446 | if (!mbox) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6447 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6448 | "6190 RAS MBX Alloc Failed"); |
| 6449 | rc = -ENOMEM; |
| 6450 | goto mem_free; |
| 6451 | } |
| 6452 | |
| 6453 | ras_fwlog->fw_loglevel = fwlog_level; |
| 6454 | len = (sizeof(struct lpfc_mbx_set_ras_fwlog) - |
| 6455 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6456 | |
| 6457 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL, |
| 6458 | LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION, |
| 6459 | len, LPFC_SLI4_MBX_EMBED); |
| 6460 | |
| 6461 | mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog; |
| 6462 | bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request, |
| 6463 | fwlog_enable); |
| 6464 | bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request, |
| 6465 | ras_fwlog->fw_loglevel); |
| 6466 | bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request, |
| 6467 | ras_fwlog->fw_buffcount); |
| 6468 | bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request, |
| 6469 | LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE); |
| 6470 | |
| 6471 | /* Update DMA buffer address */ |
| 6472 | list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) { |
| 6473 | memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE); |
| 6474 | |
| 6475 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo = |
| 6476 | putPaddrLow(dmabuf->phys); |
| 6477 | |
| 6478 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi = |
| 6479 | putPaddrHigh(dmabuf->phys); |
| 6480 | } |
| 6481 | |
| 6482 | /* Update LPWD address */ |
| 6483 | mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys); |
| 6484 | mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys); |
| 6485 | |
James Smart | 95bfc6d | 2019-10-18 14:18:27 -0700 | [diff] [blame] | 6486 | spin_lock_irq(&phba->hbalock); |
| 6487 | ras_fwlog->state = REG_INPROGRESS; |
| 6488 | spin_unlock_irq(&phba->hbalock); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6489 | mbox->vport = phba->pport; |
| 6490 | mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl; |
| 6491 | |
| 6492 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6493 | |
| 6494 | if (rc == MBX_NOT_FINISHED) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6495 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6496 | "6191 FW-Log Mailbox failed. " |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6497 | "status %d mbxStatus : x%x", rc, |
| 6498 | bf_get(lpfc_mqe_status, &mbox->u.mqe)); |
| 6499 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6500 | rc = -EIO; |
| 6501 | goto mem_free; |
| 6502 | } else |
| 6503 | rc = 0; |
| 6504 | mem_free: |
| 6505 | if (rc) |
| 6506 | lpfc_sli4_ras_dma_free(phba); |
| 6507 | |
| 6508 | return rc; |
| 6509 | } |
| 6510 | |
| 6511 | /** |
| 6512 | * lpfc_sli4_ras_setup - Check if RAS supported on the adapter |
| 6513 | * @phba: Pointer to HBA context object. |
| 6514 | * |
| 6515 | * Check if RAS is supported on the adapter and initialize it. |
| 6516 | **/ |
| 6517 | void |
| 6518 | lpfc_sli4_ras_setup(struct lpfc_hba *phba) |
| 6519 | { |
| 6520 | /* Check RAS FW Log needs to be enabled or not */ |
| 6521 | if (lpfc_check_fwlog_support(phba)) |
| 6522 | return; |
| 6523 | |
| 6524 | lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level, |
| 6525 | LPFC_RAS_ENABLE_LOGGING); |
| 6526 | } |
| 6527 | |
| 6528 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6529 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 6530 | * @phba: Pointer to HBA context object. |
| 6531 | * |
| 6532 | * This function allocates all SLI4 resource identifiers. |
| 6533 | **/ |
| 6534 | int |
| 6535 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 6536 | { |
| 6537 | int i, rc, error = 0; |
| 6538 | uint16_t count, base; |
| 6539 | unsigned long longs; |
| 6540 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6541 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6542 | 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] | 6543 | if (phba->sli4_hba.extents_in_use) { |
| 6544 | /* |
| 6545 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 6546 | * resource extent count must be read and allocated before |
| 6547 | * provisioning the resource id arrays. |
| 6548 | */ |
| 6549 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 6550 | LPFC_IDX_RSRC_RDY) { |
| 6551 | /* |
| 6552 | * Extent-based resources are set - the driver could |
| 6553 | * be in a port reset. Figure out if any corrective |
| 6554 | * actions need to be taken. |
| 6555 | */ |
| 6556 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6557 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6558 | if (rc != 0) |
| 6559 | error++; |
| 6560 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6561 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6562 | if (rc != 0) |
| 6563 | error++; |
| 6564 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6565 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6566 | if (rc != 0) |
| 6567 | error++; |
| 6568 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6569 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6570 | if (rc != 0) |
| 6571 | error++; |
| 6572 | |
| 6573 | /* |
| 6574 | * It's possible that the number of resources |
| 6575 | * provided to this port instance changed between |
| 6576 | * resets. Detect this condition and reallocate |
| 6577 | * resources. Otherwise, there is no action. |
| 6578 | */ |
| 6579 | if (error) { |
| 6580 | lpfc_printf_log(phba, KERN_INFO, |
| 6581 | LOG_MBOX | LOG_INIT, |
| 6582 | "2931 Detected extent resource " |
| 6583 | "change. Reallocating all " |
| 6584 | "extents.\n"); |
| 6585 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6586 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6587 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6588 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6589 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6590 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6591 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6592 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6593 | } else |
| 6594 | return 0; |
| 6595 | } |
| 6596 | |
| 6597 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6598 | if (unlikely(rc)) |
| 6599 | goto err_exit; |
| 6600 | |
| 6601 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6602 | if (unlikely(rc)) |
| 6603 | goto err_exit; |
| 6604 | |
| 6605 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6606 | if (unlikely(rc)) |
| 6607 | goto err_exit; |
| 6608 | |
| 6609 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6610 | if (unlikely(rc)) |
| 6611 | goto err_exit; |
| 6612 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6613 | LPFC_IDX_RSRC_RDY); |
| 6614 | return rc; |
| 6615 | } else { |
| 6616 | /* |
| 6617 | * The port does not support resource extents. The XRI, VPI, |
| 6618 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 6619 | * Just allocate the bitmasks and provision the resource id |
| 6620 | * arrays. If a port reset is active, the resources don't |
| 6621 | * need any action - just exit. |
| 6622 | */ |
| 6623 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6624 | LPFC_IDX_RSRC_RDY) { |
| 6625 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6626 | lpfc_sli4_remove_rpis(phba); |
| 6627 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6628 | /* RPIs. */ |
| 6629 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6630 | if (count <= 0) { |
| 6631 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6632 | "3279 Invalid provisioning of " |
| 6633 | "rpi:%d\n", count); |
| 6634 | rc = -EINVAL; |
| 6635 | goto err_exit; |
| 6636 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6637 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 6638 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6639 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6640 | sizeof(unsigned long), |
| 6641 | GFP_KERNEL); |
| 6642 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6643 | rc = -ENOMEM; |
| 6644 | goto err_exit; |
| 6645 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6646 | phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6647 | GFP_KERNEL); |
| 6648 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6649 | rc = -ENOMEM; |
| 6650 | goto free_rpi_bmask; |
| 6651 | } |
| 6652 | |
| 6653 | for (i = 0; i < count; i++) |
| 6654 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 6655 | |
| 6656 | /* VPIs. */ |
| 6657 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6658 | if (count <= 0) { |
| 6659 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6660 | "3280 Invalid provisioning of " |
| 6661 | "vpi:%d\n", count); |
| 6662 | rc = -EINVAL; |
| 6663 | goto free_rpi_ids; |
| 6664 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6665 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6666 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6667 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6668 | GFP_KERNEL); |
| 6669 | if (unlikely(!phba->vpi_bmask)) { |
| 6670 | rc = -ENOMEM; |
| 6671 | goto free_rpi_ids; |
| 6672 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6673 | phba->vpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6674 | GFP_KERNEL); |
| 6675 | if (unlikely(!phba->vpi_ids)) { |
| 6676 | rc = -ENOMEM; |
| 6677 | goto free_vpi_bmask; |
| 6678 | } |
| 6679 | |
| 6680 | for (i = 0; i < count; i++) |
| 6681 | phba->vpi_ids[i] = base + i; |
| 6682 | |
| 6683 | /* XRIs. */ |
| 6684 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6685 | if (count <= 0) { |
| 6686 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6687 | "3281 Invalid provisioning of " |
| 6688 | "xri:%d\n", count); |
| 6689 | rc = -EINVAL; |
| 6690 | goto free_vpi_ids; |
| 6691 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6692 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 6693 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6694 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6695 | sizeof(unsigned long), |
| 6696 | GFP_KERNEL); |
| 6697 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6698 | rc = -ENOMEM; |
| 6699 | goto free_vpi_ids; |
| 6700 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 6701 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6702 | phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6703 | GFP_KERNEL); |
| 6704 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6705 | rc = -ENOMEM; |
| 6706 | goto free_xri_bmask; |
| 6707 | } |
| 6708 | |
| 6709 | for (i = 0; i < count; i++) |
| 6710 | phba->sli4_hba.xri_ids[i] = base + i; |
| 6711 | |
| 6712 | /* VFIs. */ |
| 6713 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6714 | if (count <= 0) { |
| 6715 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6716 | "3282 Invalid provisioning of " |
| 6717 | "vfi:%d\n", count); |
| 6718 | rc = -EINVAL; |
| 6719 | goto free_xri_ids; |
| 6720 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6721 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 6722 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6723 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6724 | sizeof(unsigned long), |
| 6725 | GFP_KERNEL); |
| 6726 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6727 | rc = -ENOMEM; |
| 6728 | goto free_xri_ids; |
| 6729 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6730 | phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6731 | GFP_KERNEL); |
| 6732 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6733 | rc = -ENOMEM; |
| 6734 | goto free_vfi_bmask; |
| 6735 | } |
| 6736 | |
| 6737 | for (i = 0; i < count; i++) |
| 6738 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 6739 | |
| 6740 | /* |
| 6741 | * Mark all resources ready. An HBA reset doesn't need |
| 6742 | * to reset the initialization. |
| 6743 | */ |
| 6744 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6745 | LPFC_IDX_RSRC_RDY); |
| 6746 | return 0; |
| 6747 | } |
| 6748 | |
| 6749 | free_vfi_bmask: |
| 6750 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6751 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6752 | free_xri_ids: |
| 6753 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6754 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6755 | free_xri_bmask: |
| 6756 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6757 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6758 | free_vpi_ids: |
| 6759 | kfree(phba->vpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6760 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6761 | free_vpi_bmask: |
| 6762 | kfree(phba->vpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6763 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6764 | free_rpi_ids: |
| 6765 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6766 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6767 | free_rpi_bmask: |
| 6768 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6769 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6770 | err_exit: |
| 6771 | return rc; |
| 6772 | } |
| 6773 | |
| 6774 | /** |
| 6775 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 6776 | * @phba: Pointer to HBA context object. |
| 6777 | * |
| 6778 | * This function allocates the number of elements for the specified |
| 6779 | * resource type. |
| 6780 | **/ |
| 6781 | int |
| 6782 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 6783 | { |
| 6784 | if (phba->sli4_hba.extents_in_use) { |
| 6785 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6786 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6787 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6788 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6789 | } else { |
| 6790 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6791 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6792 | kfree(phba->vpi_ids); |
| 6793 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6794 | kfree(phba->sli4_hba.xri_bmask); |
| 6795 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6796 | kfree(phba->sli4_hba.vfi_bmask); |
| 6797 | kfree(phba->sli4_hba.vfi_ids); |
| 6798 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6799 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6800 | } |
| 6801 | |
| 6802 | return 0; |
| 6803 | } |
| 6804 | |
| 6805 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6806 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 6807 | * @phba: Pointer to HBA context object. |
| 6808 | * @type: The resource extent type. |
| 6809 | * @extnt_count: buffer to hold port extent count response |
| 6810 | * @extnt_size: buffer to hold port extent size response. |
| 6811 | * |
| 6812 | * This function calls the port to read the host allocated extents |
| 6813 | * for a particular type. |
| 6814 | **/ |
| 6815 | int |
| 6816 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 6817 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 6818 | { |
| 6819 | bool emb; |
| 6820 | int rc = 0; |
| 6821 | uint16_t curr_blks = 0; |
| 6822 | uint32_t req_len, emb_len; |
| 6823 | uint32_t alloc_len, mbox_tmo; |
| 6824 | struct list_head *blk_list_head; |
| 6825 | struct lpfc_rsrc_blks *rsrc_blk; |
| 6826 | LPFC_MBOXQ_t *mbox; |
| 6827 | void *virtaddr = NULL; |
| 6828 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6829 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6830 | union lpfc_sli4_cfg_shdr *shdr; |
| 6831 | |
| 6832 | switch (type) { |
| 6833 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6834 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6835 | break; |
| 6836 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6837 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6838 | break; |
| 6839 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6840 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6841 | break; |
| 6842 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6843 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6844 | break; |
| 6845 | default: |
| 6846 | return -EIO; |
| 6847 | } |
| 6848 | |
| 6849 | /* Count the number of extents currently allocatd for this type. */ |
| 6850 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6851 | if (curr_blks == 0) { |
| 6852 | /* |
| 6853 | * The GET_ALLOCATED mailbox does not return the size, |
| 6854 | * just the count. The size should be just the size |
| 6855 | * stored in the current allocated block and all sizes |
| 6856 | * for an extent type are the same so set the return |
| 6857 | * value now. |
| 6858 | */ |
| 6859 | *extnt_size = rsrc_blk->rsrc_size; |
| 6860 | } |
| 6861 | curr_blks++; |
| 6862 | } |
| 6863 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6864 | /* |
| 6865 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6866 | * accounts for extents-specific word. |
| 6867 | */ |
| 6868 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6869 | sizeof(uint32_t); |
| 6870 | |
| 6871 | /* |
| 6872 | * Presume the allocation and response will fit into an embedded |
| 6873 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6874 | */ |
| 6875 | emb = LPFC_SLI4_MBX_EMBED; |
| 6876 | req_len = emb_len; |
| 6877 | if (req_len > emb_len) { |
| 6878 | req_len = curr_blks * sizeof(uint16_t) + |
| 6879 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6880 | sizeof(uint32_t); |
| 6881 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6882 | } |
| 6883 | |
| 6884 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6885 | if (!mbox) |
| 6886 | return -ENOMEM; |
| 6887 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6888 | |
| 6889 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6890 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6891 | req_len, emb); |
| 6892 | if (alloc_len < req_len) { |
| 6893 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6894 | "2983 Allocated DMA memory size (x%x) is " |
| 6895 | "less than the requested DMA memory " |
| 6896 | "size (x%x)\n", alloc_len, req_len); |
| 6897 | rc = -ENOMEM; |
| 6898 | goto err_exit; |
| 6899 | } |
| 6900 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6901 | if (unlikely(rc)) { |
| 6902 | rc = -EIO; |
| 6903 | goto err_exit; |
| 6904 | } |
| 6905 | |
| 6906 | if (!phba->sli4_hba.intr_enable) |
| 6907 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6908 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6909 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6910 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6911 | } |
| 6912 | |
| 6913 | if (unlikely(rc)) { |
| 6914 | rc = -EIO; |
| 6915 | goto err_exit; |
| 6916 | } |
| 6917 | |
| 6918 | /* |
| 6919 | * Figure out where the response is located. Then get local pointers |
| 6920 | * to the response data. The port does not guarantee to respond to |
| 6921 | * all extents counts request so update the local variable with the |
| 6922 | * allocated count from the port. |
| 6923 | */ |
| 6924 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6925 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6926 | shdr = &rsrc_ext->header.cfg_shdr; |
| 6927 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6928 | } else { |
| 6929 | virtaddr = mbox->sge_array->addr[0]; |
| 6930 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6931 | shdr = &n_rsrc->cfg_shdr; |
| 6932 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6933 | } |
| 6934 | |
| 6935 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 6936 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6937 | "2984 Failed to read allocated resources " |
| 6938 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 6939 | type, |
| 6940 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 6941 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 6942 | rc = -EIO; |
| 6943 | goto err_exit; |
| 6944 | } |
| 6945 | err_exit: |
| 6946 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6947 | return rc; |
| 6948 | } |
| 6949 | |
| 6950 | /** |
James Smart | 0ef6996 | 2017-04-21 16:04:50 -0700 | [diff] [blame] | 6951 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6952 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6953 | * @pring: Pointer to driver SLI ring object. |
| 6954 | * @sgl_list: linked link of sgl buffers to post |
| 6955 | * @cnt: number of linked list buffers |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6956 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6957 | * This routine walks the list of buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6958 | * repost them to the port by using SGL block post. This is needed after a |
| 6959 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6960 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
| 6961 | * 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] | 6962 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 6963 | * mailbox command for posting. |
| 6964 | * |
| 6965 | * Returns: 0 = success, non-zero failure. |
| 6966 | **/ |
| 6967 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6968 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
| 6969 | struct list_head *sgl_list, int cnt) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6970 | { |
| 6971 | struct lpfc_sglq *sglq_entry = NULL; |
| 6972 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 6973 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6974 | int status, total_cnt; |
| 6975 | int post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6976 | int last_xritag = NO_XRI; |
| 6977 | LIST_HEAD(prep_sgl_list); |
| 6978 | LIST_HEAD(blck_sgl_list); |
| 6979 | LIST_HEAD(allc_sgl_list); |
| 6980 | LIST_HEAD(post_sgl_list); |
| 6981 | LIST_HEAD(free_sgl_list); |
| 6982 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6983 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6984 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6985 | list_splice_init(sgl_list, &allc_sgl_list); |
| 6986 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6987 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6988 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6989 | total_cnt = cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6990 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6991 | &allc_sgl_list, list) { |
| 6992 | list_del_init(&sglq_entry->list); |
| 6993 | block_cnt++; |
| 6994 | if ((last_xritag != NO_XRI) && |
| 6995 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6996 | /* a hole in xri block, form a sgl posting block */ |
| 6997 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6998 | post_cnt = block_cnt - 1; |
| 6999 | /* prepare list for next posting block */ |
| 7000 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 7001 | block_cnt = 1; |
| 7002 | } else { |
| 7003 | /* prepare list for next posting block */ |
| 7004 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 7005 | /* enough sgls for non-embed sgl mbox command */ |
| 7006 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 7007 | list_splice_init(&prep_sgl_list, |
| 7008 | &blck_sgl_list); |
| 7009 | post_cnt = block_cnt; |
| 7010 | block_cnt = 0; |
| 7011 | } |
| 7012 | } |
| 7013 | num_posted++; |
| 7014 | |
| 7015 | /* keep track of last sgl's xritag */ |
| 7016 | last_xritag = sglq_entry->sli4_xritag; |
| 7017 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7018 | /* end of repost sgl list condition for buffers */ |
| 7019 | if (num_posted == total_cnt) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7020 | if (post_cnt == 0) { |
| 7021 | list_splice_init(&prep_sgl_list, |
| 7022 | &blck_sgl_list); |
| 7023 | post_cnt = block_cnt; |
| 7024 | } else if (block_cnt == 1) { |
| 7025 | status = lpfc_sli4_post_sgl(phba, |
| 7026 | sglq_entry->phys, 0, |
| 7027 | sglq_entry->sli4_xritag); |
| 7028 | if (!status) { |
| 7029 | /* successful, put sgl to posted list */ |
| 7030 | list_add_tail(&sglq_entry->list, |
| 7031 | &post_sgl_list); |
| 7032 | } else { |
| 7033 | /* Failure, put sgl to free list */ |
| 7034 | lpfc_printf_log(phba, KERN_WARNING, |
| 7035 | LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7036 | "3159 Failed to post " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7037 | "sgl, xritag:x%x\n", |
| 7038 | sglq_entry->sli4_xritag); |
| 7039 | list_add_tail(&sglq_entry->list, |
| 7040 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7041 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7042 | } |
| 7043 | } |
| 7044 | } |
| 7045 | |
| 7046 | /* continue until a nembed page worth of sgls */ |
| 7047 | if (post_cnt == 0) |
| 7048 | continue; |
| 7049 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7050 | /* post the buffer list sgls as a block */ |
| 7051 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, |
| 7052 | post_cnt); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7053 | |
| 7054 | if (!status) { |
| 7055 | /* success, put sgl list to posted sgl list */ |
| 7056 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 7057 | } else { |
| 7058 | /* Failure, put sgl list to free sgl list */ |
| 7059 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 7060 | struct lpfc_sglq, |
| 7061 | list); |
| 7062 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7063 | "3160 Failed to post sgl-list, " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7064 | "xritag:x%x-x%x\n", |
| 7065 | sglq_entry_first->sli4_xritag, |
| 7066 | (sglq_entry_first->sli4_xritag + |
| 7067 | post_cnt - 1)); |
| 7068 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7069 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7070 | } |
| 7071 | |
| 7072 | /* don't reset xirtag due to hole in xri block */ |
| 7073 | if (block_cnt == 0) |
| 7074 | last_xritag = NO_XRI; |
| 7075 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7076 | /* reset sgl post count for next round of posting */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7077 | post_cnt = 0; |
| 7078 | } |
| 7079 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7080 | /* free the sgls failed to post */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7081 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 7082 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7083 | /* push sgls posted to the available list */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7084 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7085 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7086 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7087 | list_splice_init(&post_sgl_list, sgl_list); |
| 7088 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7089 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7090 | } else { |
| 7091 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7092 | "3161 Failure to post sgl to port.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7093 | return -EIO; |
| 7094 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7095 | |
| 7096 | /* return the number of XRIs actually posted */ |
| 7097 | return total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7098 | } |
| 7099 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7100 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7101 | * 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] | 7102 | * @phba: pointer to lpfc hba data structure. |
| 7103 | * |
| 7104 | * This routine walks the list of nvme buffers that have been allocated and |
| 7105 | * repost them to the port by using SGL block post. This is needed after a |
| 7106 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 7107 | * 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] | 7108 | * 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] | 7109 | * |
| 7110 | * Returns: 0 = success, non-zero failure. |
| 7111 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 7112 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7113 | lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7114 | { |
| 7115 | LIST_HEAD(post_nblist); |
| 7116 | int num_posted, rc = 0; |
| 7117 | |
| 7118 | /* get all NVME buffers need to repost to a local list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7119 | lpfc_io_buf_flush(phba, &post_nblist); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7120 | |
| 7121 | /* post the list of nvme buffer sgls to port if available */ |
| 7122 | if (!list_empty(&post_nblist)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7123 | num_posted = lpfc_sli4_post_io_sgl_list( |
| 7124 | phba, &post_nblist, phba->sli4_hba.io_xri_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7125 | /* failed to post any nvme buffer, return error */ |
| 7126 | if (num_posted == 0) |
| 7127 | rc = -EIO; |
| 7128 | } |
| 7129 | return rc; |
| 7130 | } |
| 7131 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 7132 | static void |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7133 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 7134 | { |
| 7135 | uint32_t len; |
| 7136 | |
| 7137 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 7138 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 7139 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7140 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 7141 | LPFC_SLI4_MBX_EMBED); |
| 7142 | |
| 7143 | 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] | 7144 | mbox->u.mqe.un.set_host_data.param_len = |
| 7145 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7146 | snprintf(mbox->u.mqe.un.set_host_data.data, |
| 7147 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 7148 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 7149 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 7150 | } |
| 7151 | |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7152 | int |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7153 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7154 | struct lpfc_queue *drq, int count, int idx) |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7155 | { |
| 7156 | int rc, i; |
| 7157 | struct lpfc_rqe hrqe; |
| 7158 | struct lpfc_rqe drqe; |
| 7159 | struct lpfc_rqb *rqbp; |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7160 | unsigned long flags; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7161 | struct rqb_dmabuf *rqb_buffer; |
| 7162 | LIST_HEAD(rqb_buf_list); |
| 7163 | |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7164 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7165 | rqbp = hrq->rqbp; |
| 7166 | for (i = 0; i < count; i++) { |
| 7167 | /* IF RQ is already full, don't bother */ |
| 7168 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) |
| 7169 | break; |
| 7170 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); |
| 7171 | if (!rqb_buffer) |
| 7172 | break; |
| 7173 | rqb_buffer->hrq = hrq; |
| 7174 | rqb_buffer->drq = drq; |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7175 | rqb_buffer->idx = idx; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7176 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
| 7177 | } |
| 7178 | while (!list_empty(&rqb_buf_list)) { |
| 7179 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, |
| 7180 | hbuf.list); |
| 7181 | |
| 7182 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); |
| 7183 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); |
| 7184 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); |
| 7185 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); |
| 7186 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
| 7187 | if (rc < 0) { |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7188 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7189 | "6421 Cannot post to HRQ %d: %x %x %x " |
| 7190 | "DRQ %x %x\n", |
| 7191 | hrq->queue_id, |
| 7192 | hrq->host_index, |
| 7193 | hrq->hba_index, |
| 7194 | hrq->entry_count, |
| 7195 | drq->host_index, |
| 7196 | drq->hba_index); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7197 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
| 7198 | } else { |
| 7199 | list_add_tail(&rqb_buffer->hbuf.list, |
| 7200 | &rqbp->rqb_buffer_list); |
| 7201 | rqbp->buffer_count++; |
| 7202 | } |
| 7203 | } |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7204 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7205 | return 1; |
| 7206 | } |
| 7207 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7208 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7209 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7210 | * @phba: Pointer to HBA context object. |
| 7211 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7212 | * This function is the main SLI4 device initialization PCI function. This |
| 7213 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7214 | * HBA error attention handler code. Caller is not required to hold any |
| 7215 | * locks. |
| 7216 | **/ |
| 7217 | int |
| 7218 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 7219 | { |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 7220 | int rc, i, cnt, len, dd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7221 | LPFC_MBOXQ_t *mboxq; |
| 7222 | struct lpfc_mqe *mqe; |
| 7223 | uint8_t *vpd; |
| 7224 | uint32_t vpd_size; |
| 7225 | uint32_t ftr_rsp = 0; |
| 7226 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 7227 | struct lpfc_vport *vport = phba->pport; |
| 7228 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7229 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7230 | |
| 7231 | /* Perform a PCI function reset to start from clean */ |
| 7232 | rc = lpfc_pci_function_reset(phba); |
| 7233 | if (unlikely(rc)) |
| 7234 | return -ENODEV; |
| 7235 | |
| 7236 | /* Check the HBA Host Status Register for readyness */ |
| 7237 | rc = lpfc_sli4_post_status_check(phba); |
| 7238 | if (unlikely(rc)) |
| 7239 | return -ENODEV; |
| 7240 | else { |
| 7241 | spin_lock_irq(&phba->hbalock); |
| 7242 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 7243 | spin_unlock_irq(&phba->hbalock); |
| 7244 | } |
| 7245 | |
| 7246 | /* |
| 7247 | * Allocate a single mailbox container for initializing the |
| 7248 | * port. |
| 7249 | */ |
| 7250 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7251 | if (!mboxq) |
| 7252 | return -ENOMEM; |
| 7253 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7254 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7255 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7256 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 7257 | if (!vpd) { |
| 7258 | rc = -ENOMEM; |
| 7259 | goto out_free_mbox; |
| 7260 | } |
| 7261 | |
| 7262 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7263 | if (unlikely(rc)) { |
| 7264 | kfree(vpd); |
| 7265 | goto out_free_mbox; |
| 7266 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7267 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7268 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7269 | 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] | 7270 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7271 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7272 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 7273 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7274 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7275 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7276 | |
| 7277 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 7278 | LPFC_DCBX_CEE_MODE) |
| 7279 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 7280 | else |
| 7281 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 7282 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 7283 | phba->hba_flag &= ~HBA_IOQ_FLUSH; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 7284 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7285 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7286 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7287 | "0376 READ_REV Error. SLI Level %d " |
| 7288 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7289 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7290 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7291 | kfree(vpd); |
| 7292 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7293 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7294 | |
| 7295 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7296 | * Continue initialization with default values even if driver failed |
| 7297 | * to read FCoE param config regions, only read parameters if the |
| 7298 | * board is FCoE |
| 7299 | */ |
| 7300 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 7301 | lpfc_sli4_read_fcoe_params(phba)) |
| 7302 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 7303 | "2570 Failed to read FCoE parameters\n"); |
| 7304 | |
| 7305 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7306 | * Retrieve sli4 device physical port name, failure of doing it |
| 7307 | * is considered as non-fatal. |
| 7308 | */ |
| 7309 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 7310 | if (!rc) |
| 7311 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7312 | "3080 Successful retrieving SLI4 device " |
| 7313 | "physical port name: %s.\n", phba->Port); |
| 7314 | |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 7315 | rc = lpfc_sli4_get_ctl_attr(phba); |
| 7316 | if (!rc) |
| 7317 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7318 | "8351 Successful retrieving SLI4 device " |
| 7319 | "CTL ATTR\n"); |
| 7320 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7321 | /* |
| 7322 | * Evaluate the read rev and vpd data. Populate the driver |
| 7323 | * state with the results. If this routine fails, the failure |
| 7324 | * is not fatal as the driver will use generic values. |
| 7325 | */ |
| 7326 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 7327 | if (unlikely(!rc)) { |
| 7328 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7329 | "0377 Error %d parsing vpd. " |
| 7330 | "Using defaults.\n", rc); |
| 7331 | rc = 0; |
| 7332 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7333 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7334 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7335 | /* Save information as VPD data */ |
| 7336 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 7337 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 7338 | |
| 7339 | /* |
| 7340 | * This is because first G7 ASIC doesn't support the standard |
| 7341 | * 0x5a NVME cmd descriptor type/subtype |
| 7342 | */ |
| 7343 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 7344 | LPFC_SLI_INTF_IF_TYPE_6) && |
| 7345 | (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) && |
| 7346 | (phba->vpd.rev.smRev == 0) && |
| 7347 | (phba->cfg_nvme_embed_cmd == 1)) |
| 7348 | phba->cfg_nvme_embed_cmd = 0; |
| 7349 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7350 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 7351 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 7352 | &mqe->un.read_rev); |
| 7353 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 7354 | &mqe->un.read_rev); |
| 7355 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 7356 | &mqe->un.read_rev); |
| 7357 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 7358 | &mqe->un.read_rev); |
| 7359 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 7360 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 7361 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 7362 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 7363 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 7364 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 7365 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7366 | "(%d):0380 READ_REV Status x%x " |
| 7367 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 7368 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7369 | bf_get(lpfc_mqe_status, mqe), |
| 7370 | phba->vpd.rev.opFwName, |
| 7371 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 7372 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7373 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7374 | 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] | 7375 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 7376 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 7377 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7378 | if (rc == MBX_SUCCESS) { |
| 7379 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 7380 | /* Set 1Sec interval to detect UE */ |
| 7381 | phba->eratt_poll_interval = 1; |
| 7382 | phba->sli4_hba.ue_to_sr = bf_get( |
| 7383 | lpfc_mbx_set_feature_UESR, |
| 7384 | &mboxq->u.mqe.un.set_feature); |
| 7385 | phba->sli4_hba.ue_to_rp = bf_get( |
| 7386 | lpfc_mbx_set_feature_UERP, |
| 7387 | &mboxq->u.mqe.un.set_feature); |
| 7388 | } |
| 7389 | } |
| 7390 | |
| 7391 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 7392 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 7393 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 7394 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7395 | if (rc != MBX_SUCCESS) |
| 7396 | phba->mds_diags_support = 0; |
| 7397 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7398 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7399 | /* |
| 7400 | * Discover the port's supported feature set and match it against the |
| 7401 | * hosts requests. |
| 7402 | */ |
| 7403 | lpfc_request_features(phba, mboxq); |
| 7404 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7405 | if (unlikely(rc)) { |
| 7406 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7407 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7408 | } |
| 7409 | |
| 7410 | /* |
| 7411 | * The port must support FCP initiator mode as this is the |
| 7412 | * only mode running in the host. |
| 7413 | */ |
| 7414 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 7415 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7416 | "0378 No support for fcpi mode.\n"); |
| 7417 | ftr_rsp++; |
| 7418 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 7419 | |
| 7420 | /* Performance Hints are ONLY for FCoE */ |
| 7421 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 7422 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 7423 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 7424 | else |
| 7425 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
| 7426 | } |
| 7427 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7428 | /* |
| 7429 | * If the port cannot support the host's requested features |
| 7430 | * then turn off the global config parameters to disable the |
| 7431 | * feature in the driver. This is not a fatal error. |
| 7432 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7433 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 7434 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) { |
| 7435 | phba->cfg_enable_bg = 0; |
| 7436 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7437 | ftr_rsp++; |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7438 | } |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7439 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7440 | |
| 7441 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 7442 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7443 | ftr_rsp++; |
| 7444 | |
| 7445 | if (ftr_rsp) { |
| 7446 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7447 | "0379 Feature Mismatch Data: x%08x %08x " |
| 7448 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 7449 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 7450 | phba->cfg_enable_npiv, phba->max_vpi); |
| 7451 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 7452 | phba->cfg_enable_bg = 0; |
| 7453 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7454 | phba->cfg_enable_npiv = 0; |
| 7455 | } |
| 7456 | |
| 7457 | /* These SLI3 features are assumed in SLI4 */ |
| 7458 | spin_lock_irq(&phba->hbalock); |
| 7459 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 7460 | spin_unlock_irq(&phba->hbalock); |
| 7461 | |
James Smart | 171f6c4 | 2019-11-04 16:57:07 -0800 | [diff] [blame] | 7462 | /* Always try to enable dual dump feature if we can */ |
| 7463 | lpfc_set_features(phba, mboxq, LPFC_SET_DUAL_DUMP); |
| 7464 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7465 | dd = bf_get(lpfc_mbx_set_feature_dd, &mboxq->u.mqe.un.set_feature); |
| 7466 | if ((rc == MBX_SUCCESS) && (dd == LPFC_ENABLE_DUAL_DUMP)) |
| 7467 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_INIT, |
| 7468 | "6448 Dual Dump is enabled\n"); |
| 7469 | else |
| 7470 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_INIT, |
| 7471 | "6447 Dual Dump Mailbox x%x (x%x/x%x) failed, " |
| 7472 | "rc:x%x dd:x%x\n", |
| 7473 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 7474 | lpfc_sli_config_mbox_subsys_get( |
| 7475 | phba, mboxq), |
| 7476 | lpfc_sli_config_mbox_opcode_get( |
| 7477 | phba, mboxq), |
| 7478 | rc, dd); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7479 | /* |
| 7480 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 7481 | * calls depends on these resources to complete port setup. |
| 7482 | */ |
| 7483 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 7484 | if (rc) { |
| 7485 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7486 | "2920 Failed to alloc Resource IDs " |
| 7487 | "rc = x%x\n", rc); |
| 7488 | goto out_free_mbox; |
| 7489 | } |
| 7490 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7491 | lpfc_set_host_data(phba, mboxq); |
| 7492 | |
| 7493 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7494 | if (rc) { |
| 7495 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7496 | "2134 Failed to set host os driver version %x", |
| 7497 | rc); |
| 7498 | } |
| 7499 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7500 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7501 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 7502 | if (rc) { |
| 7503 | phba->link_state = LPFC_HBA_ERROR; |
| 7504 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7505 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7506 | } |
| 7507 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7508 | mboxq->vport = vport; |
| 7509 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7510 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7511 | if (rc == MBX_SUCCESS) { |
| 7512 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 7513 | rc = 0; |
| 7514 | } |
| 7515 | |
| 7516 | /* |
| 7517 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 7518 | * it to the mbuf pool. |
| 7519 | */ |
| 7520 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 7521 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7522 | mboxq->ctx_buf = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7523 | if (unlikely(rc)) { |
| 7524 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7525 | "0382 READ_SPARAM command failed " |
| 7526 | "status %d, mbxStatus x%x\n", |
| 7527 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 7528 | phba->link_state = LPFC_HBA_ERROR; |
| 7529 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7530 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7531 | } |
| 7532 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7533 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7534 | |
| 7535 | /* Update the fc_host data structures with new wwn. */ |
| 7536 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 7537 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 7538 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7539 | /* Create all the SLI4 queues */ |
| 7540 | rc = lpfc_sli4_queue_create(phba); |
| 7541 | if (rc) { |
| 7542 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7543 | "3089 Failed to allocate queues\n"); |
| 7544 | rc = -ENODEV; |
| 7545 | goto out_free_mbox; |
| 7546 | } |
| 7547 | /* Set up all the queues to the device */ |
| 7548 | rc = lpfc_sli4_queue_setup(phba); |
| 7549 | if (unlikely(rc)) { |
| 7550 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7551 | "0381 Error %d during queue setup.\n ", rc); |
| 7552 | goto out_stop_timers; |
| 7553 | } |
| 7554 | /* Initialize the driver internal SLI layer lists. */ |
| 7555 | lpfc_sli4_setup(phba); |
| 7556 | lpfc_sli4_queue_init(phba); |
| 7557 | |
| 7558 | /* update host els xri-sgl sizes and mappings */ |
| 7559 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7560 | if (unlikely(rc)) { |
| 7561 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7562 | "1400 Failed to update xri-sgl size and " |
| 7563 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7564 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7565 | } |
| 7566 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7567 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7568 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 7569 | phba->sli4_hba.els_xri_cnt); |
| 7570 | if (unlikely(rc < 0)) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7571 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7572 | "0582 Error %d during els sgl post " |
| 7573 | "operation\n", rc); |
| 7574 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7575 | goto out_destroy_queue; |
| 7576 | } |
| 7577 | phba->sli4_hba.els_xri_cnt = rc; |
| 7578 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7579 | if (phba->nvmet_support) { |
| 7580 | /* update host nvmet xri-sgl sizes and mappings */ |
| 7581 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 7582 | if (unlikely(rc)) { |
| 7583 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7584 | "6308 Failed to update nvmet-sgl size " |
| 7585 | "and mapping: %d\n", rc); |
| 7586 | goto out_destroy_queue; |
| 7587 | } |
| 7588 | |
| 7589 | /* register the nvmet sgl pool to the port */ |
| 7590 | rc = lpfc_sli4_repost_sgl_list( |
| 7591 | phba, |
| 7592 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 7593 | phba->sli4_hba.nvmet_xri_cnt); |
| 7594 | if (unlikely(rc < 0)) { |
| 7595 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7596 | "3117 Error %d during nvmet " |
| 7597 | "sgl post\n", rc); |
| 7598 | rc = -ENODEV; |
| 7599 | goto out_destroy_queue; |
| 7600 | } |
| 7601 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7602 | |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7603 | /* We allocate an iocbq for every receive context SGL. |
| 7604 | * The additional allocation is for abort and ls handling. |
| 7605 | */ |
| 7606 | cnt = phba->sli4_hba.nvmet_xri_cnt + |
| 7607 | phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7608 | } else { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7609 | /* update host common xri-sgl sizes and mappings */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7610 | rc = lpfc_sli4_io_sgl_update(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7611 | if (unlikely(rc)) { |
| 7612 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7613 | "6082 Failed to update nvme-sgl size " |
| 7614 | "and mapping: %d\n", rc); |
| 7615 | goto out_destroy_queue; |
| 7616 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7617 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7618 | /* register the allocated common sgl pool to the port */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7619 | rc = lpfc_sli4_repost_io_sgl_list(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7620 | if (unlikely(rc)) { |
| 7621 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7622 | "6116 Error %d during nvme sgl post " |
| 7623 | "operation\n", rc); |
| 7624 | /* Some NVME buffers were moved to abort nvme list */ |
| 7625 | /* A pci function reset will repost them */ |
| 7626 | rc = -ENODEV; |
| 7627 | goto out_destroy_queue; |
| 7628 | } |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7629 | /* Each lpfc_io_buf job structure has an iocbq element. |
| 7630 | * This cnt provides for abort, els, ct and ls requests. |
| 7631 | */ |
| 7632 | cnt = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7633 | } |
| 7634 | |
| 7635 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7636 | /* Initialize and populate the iocb list per host */ |
| 7637 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7638 | "2821 initialize iocb list with %d entries\n", |
| 7639 | cnt); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7640 | rc = lpfc_init_iocb_list(phba, cnt); |
| 7641 | if (rc) { |
| 7642 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7643 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7644 | goto out_destroy_queue; |
| 7645 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7646 | } |
| 7647 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7648 | if (phba->nvmet_support) |
| 7649 | lpfc_nvmet_create_targetport(phba); |
| 7650 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7651 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7652 | /* Post initial buffers to all RQs created */ |
| 7653 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 7654 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 7655 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 7656 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 7657 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 7658 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7659 | rqbp->buffer_count = 0; |
| 7660 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7661 | lpfc_post_rq_buffer( |
| 7662 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 7663 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | 2448e48 | 2018-04-09 14:24:24 -0700 | [diff] [blame] | 7664 | phba->cfg_nvmet_mrq_post, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7665 | } |
| 7666 | } |
| 7667 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7668 | /* Post the rpi header region to the device. */ |
| 7669 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 7670 | if (unlikely(rc)) { |
| 7671 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7672 | "0393 Error %d during rpi post operation\n", |
| 7673 | rc); |
| 7674 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7675 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7676 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7677 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7678 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7679 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7680 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7681 | /* |
| 7682 | * The FC Port needs to register FCFI (index 0) |
| 7683 | */ |
| 7684 | lpfc_reg_fcfi(phba, mboxq); |
| 7685 | mboxq->vport = phba->pport; |
| 7686 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7687 | if (rc != MBX_SUCCESS) |
| 7688 | goto out_unset_queue; |
| 7689 | rc = 0; |
| 7690 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 7691 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7692 | } else { |
| 7693 | /* We are a NVME Target mode with MRQ > 1 */ |
| 7694 | |
| 7695 | /* First register the FCFI */ |
| 7696 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 7697 | mboxq->vport = phba->pport; |
| 7698 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7699 | if (rc != MBX_SUCCESS) |
| 7700 | goto out_unset_queue; |
| 7701 | rc = 0; |
| 7702 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 7703 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 7704 | |
| 7705 | /* Next register the MRQs */ |
| 7706 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 7707 | mboxq->vport = phba->pport; |
| 7708 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7709 | if (rc != MBX_SUCCESS) |
| 7710 | goto out_unset_queue; |
| 7711 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7712 | } |
| 7713 | /* Check if the port is configured to be disabled */ |
| 7714 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7715 | } |
| 7716 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7717 | /* Don't post more new bufs if repost already recovered |
| 7718 | * the nvme sgls. |
| 7719 | */ |
| 7720 | if (phba->nvmet_support == 0) { |
| 7721 | if (phba->sli4_hba.io_xri_cnt == 0) { |
| 7722 | len = lpfc_new_io_buf( |
| 7723 | phba, phba->sli4_hba.io_xri_max); |
| 7724 | if (len == 0) { |
| 7725 | rc = -ENOMEM; |
| 7726 | goto out_unset_queue; |
| 7727 | } |
| 7728 | |
| 7729 | if (phba->cfg_xri_rebalancing) |
| 7730 | lpfc_create_multixri_pools(phba); |
| 7731 | } |
| 7732 | } else { |
| 7733 | phba->cfg_xri_rebalancing = 0; |
| 7734 | } |
| 7735 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7736 | /* Allow asynchronous mailbox command to go through */ |
| 7737 | spin_lock_irq(&phba->hbalock); |
| 7738 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7739 | spin_unlock_irq(&phba->hbalock); |
| 7740 | |
| 7741 | /* Post receive buffers to the device */ |
| 7742 | lpfc_sli4_rb_setup(phba); |
| 7743 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7744 | /* Reset HBA FCF states after HBA reset */ |
| 7745 | phba->fcf.fcf_flag = 0; |
| 7746 | phba->fcf.current_rec.flag = 0; |
| 7747 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7748 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7749 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7750 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7751 | |
| 7752 | /* Start heart beat timer */ |
| 7753 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7754 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7755 | phba->hb_outstanding = 0; |
| 7756 | phba->last_completion_time = jiffies; |
| 7757 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7758 | /* start eq_delay heartbeat */ |
| 7759 | if (phba->cfg_auto_imax) |
| 7760 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 7761 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 7762 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7763 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7764 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7765 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7766 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7767 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 7768 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 7769 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 7770 | if (!rc) { |
| 7771 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7772 | "2829 This device supports " |
| 7773 | "Advanced Error Reporting (AER)\n"); |
| 7774 | spin_lock_irq(&phba->hbalock); |
| 7775 | phba->hba_flag |= HBA_AER_ENABLED; |
| 7776 | spin_unlock_irq(&phba->hbalock); |
| 7777 | } else { |
| 7778 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7779 | "2830 This device does not support " |
| 7780 | "Advanced Error Reporting (AER)\n"); |
| 7781 | phba->cfg_aer_support = 0; |
| 7782 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7783 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7784 | } |
| 7785 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7786 | /* |
| 7787 | * The port is ready, set the host's link state to LINK_DOWN |
| 7788 | * in preparation for link interrupts. |
| 7789 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7790 | spin_lock_irq(&phba->hbalock); |
| 7791 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7792 | |
| 7793 | /* Check if physical ports are trunked */ |
| 7794 | if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba)) |
| 7795 | phba->trunk_link.link0.state = LPFC_LINK_DOWN; |
| 7796 | if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba)) |
| 7797 | phba->trunk_link.link1.state = LPFC_LINK_DOWN; |
| 7798 | if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba)) |
| 7799 | phba->trunk_link.link2.state = LPFC_LINK_DOWN; |
| 7800 | if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba)) |
| 7801 | phba->trunk_link.link3.state = LPFC_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7802 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7803 | |
James Smart | e8869f5 | 2019-03-12 16:30:18 -0700 | [diff] [blame] | 7804 | /* Arm the CQs and then EQs on device */ |
| 7805 | lpfc_sli4_arm_cqeq_intr(phba); |
| 7806 | |
| 7807 | /* Indicate device interrupt mode */ |
| 7808 | phba->sli4_hba.intr_enable = 1; |
| 7809 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7810 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 7811 | (phba->hba_flag & LINK_DISABLED)) { |
| 7812 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7813 | "3103 Adapter Link is disabled.\n"); |
| 7814 | lpfc_down_link(phba, mboxq); |
| 7815 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7816 | if (rc != MBX_SUCCESS) { |
| 7817 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7818 | "3104 Adapter failed to issue " |
| 7819 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7820 | goto out_io_buff_free; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7821 | } |
| 7822 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7823 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 7824 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 7825 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 7826 | if (rc) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7827 | goto out_io_buff_free; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7828 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7829 | } |
| 7830 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7831 | return rc; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7832 | out_io_buff_free: |
| 7833 | /* Free allocated IO Buffers */ |
| 7834 | lpfc_io_free(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7835 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7836 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7837 | lpfc_sli4_queue_unset(phba); |
| 7838 | out_destroy_queue: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7839 | lpfc_free_iocb_list(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7840 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7841 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7842 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7843 | out_free_mbox: |
| 7844 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7845 | return rc; |
| 7846 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7847 | |
| 7848 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7849 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7850 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7851 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7852 | * This is the callback function for mailbox timer. The mailbox |
| 7853 | * timer is armed when a new mailbox command is issued and the timer |
| 7854 | * is deleted when the mailbox complete. The function is called by |
| 7855 | * the kernel timer code when a mailbox does not complete within |
| 7856 | * expected time. This function wakes up the worker thread to |
| 7857 | * process the mailbox timeout and returns. All the processing is |
| 7858 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 7859 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7860 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7861 | lpfc_mbox_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7862 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7863 | struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7864 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7865 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7866 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7867 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7868 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7869 | if (!tmo_posted) |
| 7870 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 7871 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 7872 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7873 | if (!tmo_posted) |
| 7874 | lpfc_worker_wake_up(phba); |
| 7875 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7876 | } |
| 7877 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7878 | /** |
| 7879 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 7880 | * are pending |
| 7881 | * @phba: Pointer to HBA context object. |
| 7882 | * |
| 7883 | * This function checks if any mailbox completions are present on the mailbox |
| 7884 | * completion queue. |
| 7885 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 7886 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7887 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 7888 | { |
| 7889 | |
| 7890 | uint32_t idx; |
| 7891 | struct lpfc_queue *mcq; |
| 7892 | struct lpfc_mcqe *mcqe; |
| 7893 | bool pending_completions = false; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7894 | uint8_t qe_valid; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7895 | |
| 7896 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7897 | return false; |
| 7898 | |
| 7899 | /* Check for completions on mailbox completion queue */ |
| 7900 | |
| 7901 | mcq = phba->sli4_hba.mbx_cq; |
| 7902 | idx = mcq->hba_index; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7903 | qe_valid = mcq->qe_valid; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 7904 | while (bf_get_le32(lpfc_cqe_valid, |
| 7905 | (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) { |
| 7906 | mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx)); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7907 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 7908 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 7909 | pending_completions = true; |
| 7910 | break; |
| 7911 | } |
| 7912 | idx = (idx + 1) % mcq->entry_count; |
| 7913 | if (mcq->hba_index == idx) |
| 7914 | break; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7915 | |
| 7916 | /* if the index wrapped around, toggle the valid bit */ |
| 7917 | if (phba->sli4_hba.pc_sli4_params.cqav && !idx) |
| 7918 | qe_valid = (qe_valid) ? 0 : 1; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7919 | } |
| 7920 | return pending_completions; |
| 7921 | |
| 7922 | } |
| 7923 | |
| 7924 | /** |
| 7925 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 7926 | * that were missed. |
| 7927 | * @phba: Pointer to HBA context object. |
| 7928 | * |
| 7929 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 7930 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 7931 | * checks to see if mbox completions are on the mailbox completion queue |
| 7932 | * and will process all the completions associated with the eq for the |
| 7933 | * mailbox completion queue. |
| 7934 | **/ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 7935 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7936 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 7937 | { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7938 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7939 | uint32_t eqidx; |
| 7940 | struct lpfc_queue *fpeq = NULL; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 7941 | struct lpfc_queue *eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7942 | bool mbox_pending; |
| 7943 | |
| 7944 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7945 | return false; |
| 7946 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 7947 | /* Find the EQ associated with the mbox CQ */ |
| 7948 | if (sli4_hba->hdwq) { |
| 7949 | for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) { |
| 7950 | eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq; |
Daniel Wagner | 535fb49 | 2019-10-18 18:21:11 +0200 | [diff] [blame] | 7951 | if (eq && eq->queue_id == sli4_hba->mbx_cq->assoc_qid) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 7952 | fpeq = eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7953 | break; |
| 7954 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 7955 | } |
| 7956 | } |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7957 | if (!fpeq) |
| 7958 | return false; |
| 7959 | |
| 7960 | /* Turn off interrupts from this EQ */ |
| 7961 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7962 | sli4_hba->sli4_eq_clr_intr(fpeq); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7963 | |
| 7964 | /* Check to see if a mbox completion is pending */ |
| 7965 | |
| 7966 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 7967 | |
| 7968 | /* |
| 7969 | * If a mbox completion is pending, process all the events on EQ |
| 7970 | * associated with the mbox completion queue (this could include |
| 7971 | * mailbox commands, async events, els commands, receive queue data |
| 7972 | * and fcp commands) |
| 7973 | */ |
| 7974 | |
| 7975 | if (mbox_pending) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7976 | /* process and rearm the EQ */ |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 7977 | lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7978 | else |
| 7979 | /* Always clear and re-arm the EQ */ |
| 7980 | sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7981 | |
| 7982 | return mbox_pending; |
| 7983 | |
| 7984 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7985 | |
| 7986 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7987 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7988 | * @phba: Pointer to HBA context object. |
| 7989 | * |
| 7990 | * This function is called from worker thread when a mailbox command times out. |
| 7991 | * The caller is not required to hold any locks. This function will reset the |
| 7992 | * HBA and recover all the pending commands. |
| 7993 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7994 | void |
| 7995 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 7996 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7997 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7998 | MAILBOX_t *mb = NULL; |
| 7999 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8000 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8001 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8002 | /* If the mailbox completed, process the completion and return */ |
| 8003 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 8004 | return; |
| 8005 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 8006 | if (pmbox != NULL) |
| 8007 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8008 | /* Check the pmbox pointer first. There is a race condition |
| 8009 | * between the mbox timeout handler getting executed in the |
| 8010 | * worklist and the mailbox actually completing. When this |
| 8011 | * race condition occurs, the mbox_active will be NULL. |
| 8012 | */ |
| 8013 | spin_lock_irq(&phba->hbalock); |
| 8014 | if (pmbox == NULL) { |
| 8015 | lpfc_printf_log(phba, KERN_WARNING, |
| 8016 | LOG_MBOX | LOG_SLI, |
| 8017 | "0353 Active Mailbox cleared - mailbox timeout " |
| 8018 | "exiting\n"); |
| 8019 | spin_unlock_irq(&phba->hbalock); |
| 8020 | return; |
| 8021 | } |
| 8022 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8023 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8024 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 8025 | "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] | 8026 | mb->mbxCommand, |
| 8027 | phba->pport->port_state, |
| 8028 | phba->sli.sli_flag, |
| 8029 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8030 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8031 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8032 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 8033 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8034 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8035 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8036 | spin_lock_irq(&phba->pport->work_port_lock); |
| 8037 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 8038 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 8039 | spin_lock_irq(&phba->hbalock); |
| 8040 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 8041 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8042 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8043 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 8044 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8045 | |
| 8046 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8047 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8048 | |
| 8049 | /* Reset the HBA device */ |
| 8050 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8051 | } |
| 8052 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8053 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8054 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8055 | * @phba: Pointer to HBA context object. |
| 8056 | * @pmbox: Pointer to mailbox object. |
| 8057 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8058 | * |
| 8059 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8060 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 8061 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8062 | * The mailbox command can be submitted in polling mode, in which case |
| 8063 | * this function will wait in a polling loop for the completion of the |
| 8064 | * mailbox. |
| 8065 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 8066 | * function will submit the command and returns immediately without waiting |
| 8067 | * for the mailbox completion. The no_wait is supported only when HBA |
| 8068 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 8069 | * The SLI interface allows only one mailbox pending at a time. If the |
| 8070 | * mailbox is issued in polling mode and there is already a mailbox |
| 8071 | * pending, then the function will return an error. If the mailbox is issued |
| 8072 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 8073 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 8074 | * The sli layer owns the mailbox object until the completion of mailbox |
| 8075 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 8076 | * return codes the caller owns the mailbox command after the return of |
| 8077 | * the function. |
| 8078 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8079 | static int |
| 8080 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 8081 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8082 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8083 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8084 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8085 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8086 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8087 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8088 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8089 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8090 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8091 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8092 | int processing_queue = 0; |
| 8093 | |
| 8094 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8095 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 8096 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8097 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8098 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8099 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8100 | return MBX_SUCCESS; |
| 8101 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8102 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8103 | pmbox = lpfc_mbox_get(phba); |
| 8104 | if (!pmbox) { |
| 8105 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8106 | return MBX_SUCCESS; |
| 8107 | } |
| 8108 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8109 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8110 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8111 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8112 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8113 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8114 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8115 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8116 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8117 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8118 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8119 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8120 | } |
| 8121 | } |
| 8122 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8123 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8124 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 8125 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8126 | goto out_not_finished; |
| 8127 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8128 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8129 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8130 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 8131 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8132 | goto out_not_finished; |
| 8133 | } |
| 8134 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8135 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8136 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8137 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8138 | status = MBX_SUCCESS; |
| 8139 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8140 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 8141 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8142 | |
| 8143 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8144 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8145 | "(%d):0311 Mailbox command x%x cannot " |
| 8146 | "issue Data: x%x x%x\n", |
| 8147 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8148 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8149 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8150 | } |
| 8151 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8152 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8153 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 8154 | !(hc_copy & HC_MBINT_ENA)) { |
| 8155 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8156 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8157 | "(%d):2528 Mailbox command x%x cannot " |
| 8158 | "issue Data: x%x x%x\n", |
| 8159 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8160 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8161 | goto out_not_finished; |
| 8162 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 8163 | } |
| 8164 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8165 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8166 | /* Polling for a mbox command when another one is already active |
| 8167 | * is not allowed in SLI. Also, the driver must have established |
| 8168 | * SLI2 mode to queue and process multiple mbox commands. |
| 8169 | */ |
| 8170 | |
| 8171 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8172 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8173 | |
| 8174 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8175 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8176 | "(%d):2529 Mailbox command x%x " |
| 8177 | "cannot issue Data: x%x x%x\n", |
| 8178 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8179 | pmbox->u.mb.mbxCommand, |
| 8180 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8181 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8182 | } |
| 8183 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8184 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8185 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8186 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8187 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8188 | "(%d):2530 Mailbox command x%x " |
| 8189 | "cannot issue Data: x%x x%x\n", |
| 8190 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8191 | pmbox->u.mb.mbxCommand, |
| 8192 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8193 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8194 | } |
| 8195 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8196 | /* Another mailbox command is still being processed, queue this |
| 8197 | * command to be processed later. |
| 8198 | */ |
| 8199 | lpfc_mbox_put(phba, pmbox); |
| 8200 | |
| 8201 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8202 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8203 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8204 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8205 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8206 | mbx->mbxCommand, |
| 8207 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8208 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8209 | |
| 8210 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8211 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8212 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8213 | if (pmbox->vport) { |
| 8214 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8215 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8216 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8217 | (uint32_t)mbx->mbxCommand, |
| 8218 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8219 | } |
| 8220 | else { |
| 8221 | lpfc_debugfs_disc_trc(phba->pport, |
| 8222 | LPFC_DISC_TRC_MBOX, |
| 8223 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8224 | (uint32_t)mbx->mbxCommand, |
| 8225 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8226 | } |
| 8227 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8228 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8229 | } |
| 8230 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8231 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8232 | |
| 8233 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 8234 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8235 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8236 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8237 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8238 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8239 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8240 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8241 | "(%d):2531 Mailbox command x%x " |
| 8242 | "cannot issue Data: x%x x%x\n", |
| 8243 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8244 | pmbox->u.mb.mbxCommand, |
| 8245 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8246 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8247 | } |
| 8248 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8249 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8250 | 1000); |
| 8251 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8252 | } |
| 8253 | |
| 8254 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8255 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8256 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8257 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8258 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8259 | mbx->mbxCommand, |
| 8260 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8261 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8262 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8263 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8264 | if (pmbox->vport) { |
| 8265 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8266 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8267 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8268 | (uint32_t)mbx->mbxCommand, |
| 8269 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8270 | } |
| 8271 | else { |
| 8272 | lpfc_debugfs_disc_trc(phba->pport, |
| 8273 | LPFC_DISC_TRC_MBOX, |
| 8274 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8275 | (uint32_t)mbx->mbxCommand, |
| 8276 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8277 | } |
| 8278 | } |
| 8279 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8280 | psli->slistat.mbox_cmd++; |
| 8281 | evtctr = psli->slistat.mbox_event; |
| 8282 | |
| 8283 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8284 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8285 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8286 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8287 | /* Populate mbox extension offset word. */ |
| 8288 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8289 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8290 | = (uint8_t *)phba->mbox_ext |
| 8291 | - (uint8_t *)phba->mbox; |
| 8292 | } |
| 8293 | |
| 8294 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8295 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) { |
| 8296 | lpfc_sli_pcimem_bcopy(pmbox->ctx_buf, |
| 8297 | (uint8_t *)phba->mbox_ext, |
| 8298 | pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8299 | } |
| 8300 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8301 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8302 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8303 | /* Populate mbox extension offset word. */ |
| 8304 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8305 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8306 | = MAILBOX_HBA_EXT_OFFSET; |
| 8307 | |
| 8308 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8309 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8310 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 8311 | MAILBOX_HBA_EXT_OFFSET, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8312 | pmbox->ctx_buf, pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8313 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8314 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8315 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8316 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 8317 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8318 | |
| 8319 | /* First copy mbox command data to HBA SLIM, skip past first |
| 8320 | word */ |
| 8321 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8322 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8323 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 8324 | |
| 8325 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8326 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8327 | to_slim = phba->MBslimaddr; |
| 8328 | writel(ldata, to_slim); |
| 8329 | readl(to_slim); /* flush */ |
| 8330 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8331 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8332 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8333 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8334 | } |
| 8335 | |
| 8336 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8337 | |
| 8338 | switch (flag) { |
| 8339 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8340 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8341 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8342 | /* Interrupt board to do it */ |
| 8343 | writel(CA_MBATT, phba->CAregaddr); |
| 8344 | readl(phba->CAregaddr); /* flush */ |
| 8345 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8346 | break; |
| 8347 | |
| 8348 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8349 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8350 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8351 | /* Interrupt board to do it */ |
| 8352 | writel(CA_MBATT, phba->CAregaddr); |
| 8353 | readl(phba->CAregaddr); /* flush */ |
| 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 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8357 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8358 | word0 = le32_to_cpu(word0); |
| 8359 | } else { |
| 8360 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8361 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 8362 | spin_unlock_irqrestore(&phba->hbalock, |
| 8363 | drvr_flag); |
| 8364 | goto out_not_finished; |
| 8365 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8366 | } |
| 8367 | |
| 8368 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8369 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8370 | spin_unlock_irqrestore(&phba->hbalock, |
| 8371 | drvr_flag); |
| 8372 | goto out_not_finished; |
| 8373 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8374 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8375 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8376 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8377 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8378 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 8379 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8380 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8381 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8382 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8383 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8384 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8385 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8386 | } |
| 8387 | |
| 8388 | /* Check if we took a mbox interrupt while we were |
| 8389 | polling */ |
| 8390 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 8391 | && (evtctr != psli->slistat.mbox_event)) |
| 8392 | break; |
| 8393 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8394 | if (i++ > 10) { |
| 8395 | spin_unlock_irqrestore(&phba->hbalock, |
| 8396 | drvr_flag); |
| 8397 | msleep(1); |
| 8398 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8399 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8400 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8401 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8402 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8403 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8404 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8405 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8406 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8407 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8408 | /* Check real SLIM for any errors */ |
| 8409 | slimword0 = readl(phba->MBslimaddr); |
| 8410 | slimmb = (MAILBOX_t *) & slimword0; |
| 8411 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 8412 | && slimmb->mbxStatus) { |
| 8413 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8414 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8415 | word0 = slimword0; |
| 8416 | } |
| 8417 | } |
| 8418 | } else { |
| 8419 | /* First copy command data */ |
| 8420 | word0 = readl(phba->MBslimaddr); |
| 8421 | } |
| 8422 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8423 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8424 | spin_unlock_irqrestore(&phba->hbalock, |
| 8425 | drvr_flag); |
| 8426 | goto out_not_finished; |
| 8427 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8428 | } |
| 8429 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8430 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8431 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8432 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 8433 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8434 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8435 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8436 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8437 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8438 | pmbox->out_ext_byte_len); |
| 8439 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8440 | } else { |
| 8441 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8442 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8443 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8444 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8445 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
| 8446 | lpfc_memcpy_from_slim( |
| 8447 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8448 | phba->MBslimaddr + |
| 8449 | MAILBOX_HBA_EXT_OFFSET, |
| 8450 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8451 | } |
| 8452 | } |
| 8453 | |
| 8454 | writel(HA_MBATT, phba->HAregaddr); |
| 8455 | readl(phba->HAregaddr); /* flush */ |
| 8456 | |
| 8457 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8458 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8459 | } |
| 8460 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8461 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8462 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8463 | |
| 8464 | out_not_finished: |
| 8465 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8466 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8467 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 8468 | } |
| 8469 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8470 | } |
| 8471 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8472 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8473 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 8474 | * @phba: Pointer to HBA context object. |
| 8475 | * |
| 8476 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 8477 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 8478 | * possible outstanding mailbox command before return. |
| 8479 | * |
| 8480 | * Returns: |
| 8481 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 8482 | * the outstanding mailbox command timed out. |
| 8483 | **/ |
| 8484 | static int |
| 8485 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 8486 | { |
| 8487 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8488 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8489 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8490 | |
| 8491 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 8492 | spin_lock_irq(&phba->hbalock); |
| 8493 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8494 | /* Determine how long we might wait for the active mailbox |
| 8495 | * command to be gracefully completed by firmware. |
| 8496 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8497 | if (phba->sli.mbox_active) |
| 8498 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 8499 | phba->sli.mbox_active) * |
| 8500 | 1000) + jiffies; |
| 8501 | spin_unlock_irq(&phba->hbalock); |
| 8502 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8503 | /* Make sure the mailbox is really active */ |
| 8504 | if (timeout) |
| 8505 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 8506 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8507 | /* Wait for the outstnading mailbox command to complete */ |
| 8508 | while (phba->sli.mbox_active) { |
| 8509 | /* Check active mailbox complete status every 2ms */ |
| 8510 | msleep(2); |
| 8511 | if (time_after(jiffies, timeout)) { |
| 8512 | /* Timeout, marked the outstanding cmd not complete */ |
| 8513 | rc = 1; |
| 8514 | break; |
| 8515 | } |
| 8516 | } |
| 8517 | |
| 8518 | /* Can not cleanly block async mailbox command, fails it */ |
| 8519 | if (rc) { |
| 8520 | spin_lock_irq(&phba->hbalock); |
| 8521 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8522 | spin_unlock_irq(&phba->hbalock); |
| 8523 | } |
| 8524 | return rc; |
| 8525 | } |
| 8526 | |
| 8527 | /** |
| 8528 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 8529 | * @phba: Pointer to HBA context object. |
| 8530 | * |
| 8531 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 8532 | * commands from the driver internal pending mailbox queue. It makes sure |
| 8533 | * that there is no outstanding mailbox command before resuming posting |
| 8534 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 8535 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 8536 | * mailbox command posting. |
| 8537 | **/ |
| 8538 | static void |
| 8539 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 8540 | { |
| 8541 | struct lpfc_sli *psli = &phba->sli; |
| 8542 | |
| 8543 | spin_lock_irq(&phba->hbalock); |
| 8544 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8545 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 8546 | spin_unlock_irq(&phba->hbalock); |
| 8547 | return; |
| 8548 | } |
| 8549 | |
| 8550 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 8551 | * successful or timeout, after timing-out the outstanding mailbox |
| 8552 | * command shall always be removed, so just unblock posting async |
| 8553 | * mailbox command and resume |
| 8554 | */ |
| 8555 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8556 | spin_unlock_irq(&phba->hbalock); |
| 8557 | |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 8558 | /* wake up worker thread to post asynchronous mailbox command */ |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8559 | lpfc_worker_wake_up(phba); |
| 8560 | } |
| 8561 | |
| 8562 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8563 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 8564 | * @phba: Pointer to HBA context object. |
| 8565 | * @mboxq: Pointer to mailbox object. |
| 8566 | * |
| 8567 | * The function waits for the bootstrap mailbox register ready bit from |
| 8568 | * port for twice the regular mailbox command timeout value. |
| 8569 | * |
| 8570 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 8571 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 8572 | **/ |
| 8573 | static int |
| 8574 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8575 | { |
| 8576 | uint32_t db_ready; |
| 8577 | unsigned long timeout; |
| 8578 | struct lpfc_register bmbx_reg; |
| 8579 | |
| 8580 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 8581 | * 1000) + jiffies; |
| 8582 | |
| 8583 | do { |
| 8584 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 8585 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 8586 | if (!db_ready) |
James Smart | e2ffe4d | 2019-03-12 16:30:15 -0700 | [diff] [blame] | 8587 | mdelay(2); |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8588 | |
| 8589 | if (time_after(jiffies, timeout)) |
| 8590 | return MBXERR_ERROR; |
| 8591 | } while (!db_ready); |
| 8592 | |
| 8593 | return 0; |
| 8594 | } |
| 8595 | |
| 8596 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8597 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 8598 | * @phba: Pointer to HBA context object. |
| 8599 | * @mboxq: Pointer to mailbox object. |
| 8600 | * |
| 8601 | * The function posts a mailbox to the port. The mailbox is expected |
| 8602 | * to be comletely filled in and ready for the port to operate on it. |
| 8603 | * This routine executes a synchronous completion operation on the |
| 8604 | * mailbox by polling for its completion. |
| 8605 | * |
| 8606 | * The caller must not be holding any locks when calling this routine. |
| 8607 | * |
| 8608 | * Returns: |
| 8609 | * MBX_SUCCESS - mailbox posted successfully |
| 8610 | * Any of the MBX error values. |
| 8611 | **/ |
| 8612 | static int |
| 8613 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8614 | { |
| 8615 | int rc = MBX_SUCCESS; |
| 8616 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8617 | uint32_t mcqe_status; |
| 8618 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8619 | struct lpfc_sli *psli = &phba->sli; |
| 8620 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 8621 | struct lpfc_bmbx_create *mbox_rgn; |
| 8622 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8623 | |
| 8624 | /* |
| 8625 | * Only one mailbox can be active to the bootstrap mailbox region |
| 8626 | * at a time and there is no queueing provided. |
| 8627 | */ |
| 8628 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8629 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8630 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8631 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8632 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8633 | "cannot issue Data: x%x x%x\n", |
| 8634 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8635 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8636 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8637 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8638 | psli->sli_flag, MBX_POLL); |
| 8639 | return MBXERR_ERROR; |
| 8640 | } |
| 8641 | /* The server grabs the token and owns it until release */ |
| 8642 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8643 | phba->sli.mbox_active = mboxq; |
| 8644 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8645 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8646 | /* wait for bootstrap mbox register for readyness */ |
| 8647 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8648 | if (rc) |
| 8649 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8650 | /* |
| 8651 | * Initialize the bootstrap memory region to avoid stale data areas |
| 8652 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 8653 | * the bmbx mailbox region. |
| 8654 | */ |
| 8655 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 8656 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8657 | lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 8658 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8659 | |
| 8660 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 8661 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8662 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 8663 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8664 | /* wait for bootstrap mbox register for hi-address write done */ |
| 8665 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8666 | if (rc) |
| 8667 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8668 | |
| 8669 | /* Post the low mailbox dma address to the port. */ |
| 8670 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8671 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8672 | /* wait for bootstrap mbox register for low address write done */ |
| 8673 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8674 | if (rc) |
| 8675 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8676 | |
| 8677 | /* |
| 8678 | * Read the CQ to ensure the mailbox has completed. |
| 8679 | * If so, update the mailbox status so that the upper layers |
| 8680 | * can complete the request normally. |
| 8681 | */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8682 | lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 8683 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8684 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8685 | lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 8686 | sizeof(struct lpfc_mcqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8687 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8688 | /* |
| 8689 | * When the CQE status indicates a failure and the mailbox status |
| 8690 | * indicates success then copy the CQE status into the mailbox status |
| 8691 | * (and prefix it with x4000). |
| 8692 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8693 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8694 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 8695 | bf_set(lpfc_mqe_status, mb, |
| 8696 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8697 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8698 | } else |
| 8699 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8700 | |
| 8701 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8702 | "(%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] | 8703 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 8704 | " 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] | 8705 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 8706 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8707 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8708 | bf_get(lpfc_mqe_status, mb), |
| 8709 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 8710 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 8711 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 8712 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 8713 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 8714 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 8715 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 8716 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 8717 | mboxq->mcqe.trailer); |
| 8718 | exit: |
| 8719 | /* We are holding the token, no needed for lock when release */ |
| 8720 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8721 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8722 | phba->sli.mbox_active = NULL; |
| 8723 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8724 | return rc; |
| 8725 | } |
| 8726 | |
| 8727 | /** |
| 8728 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 8729 | * @phba: Pointer to HBA context object. |
| 8730 | * @pmbox: Pointer to mailbox object. |
| 8731 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8732 | * |
| 8733 | * This function is called by discovery code and HBA management code to submit |
| 8734 | * a mailbox command to firmware with SLI-4 interface spec. |
| 8735 | * |
| 8736 | * Return codes the caller owns the mailbox command after the return of the |
| 8737 | * function. |
| 8738 | **/ |
| 8739 | static int |
| 8740 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 8741 | uint32_t flag) |
| 8742 | { |
| 8743 | struct lpfc_sli *psli = &phba->sli; |
| 8744 | unsigned long iflags; |
| 8745 | int rc; |
| 8746 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 8747 | /* dump from issue mailbox command if setup */ |
| 8748 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 8749 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8750 | rc = lpfc_mbox_dev_check(phba); |
| 8751 | if (unlikely(rc)) { |
| 8752 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8753 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8754 | "cannot issue Data: x%x x%x\n", |
| 8755 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8756 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8757 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8758 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8759 | psli->sli_flag, flag); |
| 8760 | goto out_not_finished; |
| 8761 | } |
| 8762 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8763 | /* Detect polling mode and jump to a handler */ |
| 8764 | if (!phba->sli4_hba.intr_enable) { |
| 8765 | if (flag == MBX_POLL) |
| 8766 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8767 | else |
| 8768 | rc = -EIO; |
| 8769 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8770 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8771 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8772 | "(x%x/x%x) failure: " |
| 8773 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8774 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8775 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8776 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8777 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8778 | mboxq), |
| 8779 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8780 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8781 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8782 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8783 | bf_get(lpfc_mcqe_ext_status, |
| 8784 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8785 | psli->sli_flag, flag); |
| 8786 | return rc; |
| 8787 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8788 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8789 | "(%d):2542 Try to issue mailbox command " |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8790 | "x%x (x%x/x%x) synchronously ahead of async " |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8791 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8792 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8793 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8794 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8795 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8796 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8797 | /* Try to block the asynchronous mailbox posting */ |
| 8798 | rc = lpfc_sli4_async_mbox_block(phba); |
| 8799 | if (!rc) { |
| 8800 | /* Successfully blocked, now issue sync mbox cmd */ |
| 8801 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8802 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8803 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8804 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8805 | "(%d):2597 Sync Mailbox command " |
| 8806 | "x%x (x%x/x%x) failure: " |
| 8807 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8808 | "Data: x%x x%x\n,", |
| 8809 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8810 | mboxq->u.mb.mbxCommand, |
| 8811 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8812 | mboxq), |
| 8813 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8814 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8815 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8816 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8817 | bf_get(lpfc_mcqe_ext_status, |
| 8818 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8819 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8820 | /* Unblock the async mailbox posting afterward */ |
| 8821 | lpfc_sli4_async_mbox_unblock(phba); |
| 8822 | } |
| 8823 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8824 | } |
| 8825 | |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 8826 | /* Now, interrupt mode asynchronous mailbox command */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8827 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 8828 | if (rc) { |
| 8829 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8830 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8831 | "cannot issue Data: x%x x%x\n", |
| 8832 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8833 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8834 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8835 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8836 | psli->sli_flag, flag); |
| 8837 | goto out_not_finished; |
| 8838 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8839 | |
| 8840 | /* Put the mailbox command to the driver internal FIFO */ |
| 8841 | psli->slistat.mbox_busy++; |
| 8842 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8843 | lpfc_mbox_put(phba, mboxq); |
| 8844 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8845 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8846 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8847 | "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] | 8848 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 8849 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8850 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8851 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8852 | phba->pport->port_state, |
| 8853 | psli->sli_flag, MBX_NOWAIT); |
| 8854 | /* Wake up worker thread to transport mailbox command from head */ |
| 8855 | lpfc_worker_wake_up(phba); |
| 8856 | |
| 8857 | return MBX_BUSY; |
| 8858 | |
| 8859 | out_not_finished: |
| 8860 | return MBX_NOT_FINISHED; |
| 8861 | } |
| 8862 | |
| 8863 | /** |
| 8864 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 8865 | * @phba: Pointer to HBA context object. |
| 8866 | * |
| 8867 | * This function is called by worker thread to send a mailbox command to |
| 8868 | * SLI4 HBA firmware. |
| 8869 | * |
| 8870 | **/ |
| 8871 | int |
| 8872 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 8873 | { |
| 8874 | struct lpfc_sli *psli = &phba->sli; |
| 8875 | LPFC_MBOXQ_t *mboxq; |
| 8876 | int rc = MBX_SUCCESS; |
| 8877 | unsigned long iflags; |
| 8878 | struct lpfc_mqe *mqe; |
| 8879 | uint32_t mbx_cmnd; |
| 8880 | |
| 8881 | /* Check interrupt mode before post async mailbox command */ |
| 8882 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 8883 | return MBX_NOT_FINISHED; |
| 8884 | |
| 8885 | /* Check for mailbox command service token */ |
| 8886 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8887 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8888 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8889 | return MBX_NOT_FINISHED; |
| 8890 | } |
| 8891 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8892 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8893 | return MBX_NOT_FINISHED; |
| 8894 | } |
| 8895 | if (unlikely(phba->sli.mbox_active)) { |
| 8896 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8897 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8898 | "0384 There is pending active mailbox cmd\n"); |
| 8899 | return MBX_NOT_FINISHED; |
| 8900 | } |
| 8901 | /* Take the mailbox command service token */ |
| 8902 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8903 | |
| 8904 | /* Get the next mailbox command from head of queue */ |
| 8905 | mboxq = lpfc_mbox_get(phba); |
| 8906 | |
| 8907 | /* If no more mailbox command waiting for post, we're done */ |
| 8908 | if (!mboxq) { |
| 8909 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8910 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8911 | return MBX_SUCCESS; |
| 8912 | } |
| 8913 | phba->sli.mbox_active = mboxq; |
| 8914 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8915 | |
| 8916 | /* Check device readiness for posting mailbox command */ |
| 8917 | rc = lpfc_mbox_dev_check(phba); |
| 8918 | if (unlikely(rc)) |
| 8919 | /* Driver clean routine will clean up pending mailbox */ |
| 8920 | goto out_not_finished; |
| 8921 | |
| 8922 | /* Prepare the mbox command to be posted */ |
| 8923 | mqe = &mboxq->u.mqe; |
| 8924 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 8925 | |
| 8926 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 8927 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8928 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8929 | |
| 8930 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8931 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8932 | "x%x x%x\n", |
| 8933 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8934 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8935 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8936 | phba->pport->port_state, psli->sli_flag); |
| 8937 | |
| 8938 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 8939 | if (mboxq->vport) { |
| 8940 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 8941 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8942 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 8943 | mbx_cmnd, mqe->un.mb_words[0], |
| 8944 | mqe->un.mb_words[1]); |
| 8945 | } else { |
| 8946 | lpfc_debugfs_disc_trc(phba->pport, |
| 8947 | LPFC_DISC_TRC_MBOX, |
| 8948 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 8949 | mbx_cmnd, mqe->un.mb_words[0], |
| 8950 | mqe->un.mb_words[1]); |
| 8951 | } |
| 8952 | } |
| 8953 | psli->slistat.mbox_cmd++; |
| 8954 | |
| 8955 | /* Post the mailbox command to the port */ |
| 8956 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 8957 | if (rc != MBX_SUCCESS) { |
| 8958 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8959 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8960 | "cannot issue Data: x%x x%x\n", |
| 8961 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8962 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8963 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8964 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8965 | psli->sli_flag, MBX_NOWAIT); |
| 8966 | goto out_not_finished; |
| 8967 | } |
| 8968 | |
| 8969 | return rc; |
| 8970 | |
| 8971 | out_not_finished: |
| 8972 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 8973 | if (phba->sli.mbox_active) { |
| 8974 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8975 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8976 | /* Release the token */ |
| 8977 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8978 | phba->sli.mbox_active = NULL; |
| 8979 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8980 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8981 | |
| 8982 | return MBX_NOT_FINISHED; |
| 8983 | } |
| 8984 | |
| 8985 | /** |
| 8986 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 8987 | * @phba: Pointer to HBA context object. |
| 8988 | * @pmbox: Pointer to mailbox object. |
| 8989 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8990 | * |
| 8991 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 8992 | * the API jump table function pointer from the lpfc_hba struct. |
| 8993 | * |
| 8994 | * Return codes the caller owns the mailbox command after the return of the |
| 8995 | * function. |
| 8996 | **/ |
| 8997 | int |
| 8998 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 8999 | { |
| 9000 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 9001 | } |
| 9002 | |
| 9003 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9004 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9005 | * @phba: The hba struct for which this call is being executed. |
| 9006 | * @dev_grp: The HBA PCI-Device group number. |
| 9007 | * |
| 9008 | * This routine sets up the mbox interface API function jump table in @phba |
| 9009 | * struct. |
| 9010 | * Returns: 0 - success, -ENODEV - failure. |
| 9011 | **/ |
| 9012 | int |
| 9013 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 9014 | { |
| 9015 | |
| 9016 | switch (dev_grp) { |
| 9017 | case LPFC_PCI_DEV_LP: |
| 9018 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 9019 | phba->lpfc_sli_handle_slow_ring_event = |
| 9020 | lpfc_sli_handle_slow_ring_event_s3; |
| 9021 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 9022 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 9023 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 9024 | break; |
| 9025 | case LPFC_PCI_DEV_OC: |
| 9026 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 9027 | phba->lpfc_sli_handle_slow_ring_event = |
| 9028 | lpfc_sli_handle_slow_ring_event_s4; |
| 9029 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 9030 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 9031 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 9032 | break; |
| 9033 | default: |
| 9034 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9035 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 9036 | dev_grp); |
| 9037 | return -ENODEV; |
| 9038 | break; |
| 9039 | } |
| 9040 | return 0; |
| 9041 | } |
| 9042 | |
| 9043 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9044 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9045 | * @phba: Pointer to HBA context object. |
| 9046 | * @pring: Pointer to driver SLI ring object. |
| 9047 | * @piocb: Pointer to address of newly added command iocb. |
| 9048 | * |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 9049 | * This function is called with hbalock held for SLI3 ports or |
| 9050 | * the ring lock held for SLI4 ports to add a command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9051 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 9052 | * to the ring. |
| 9053 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9054 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9055 | __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] | 9056 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9057 | { |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 9058 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9059 | lockdep_assert_held(&pring->ring_lock); |
| 9060 | else |
| 9061 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9062 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 9063 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9064 | } |
| 9065 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9066 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9067 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9068 | * @phba: Pointer to HBA context object. |
| 9069 | * @pring: Pointer to driver SLI ring object. |
| 9070 | * @piocb: Pointer to address of newly added command iocb. |
| 9071 | * |
| 9072 | * This function is called with hbalock held before a new |
| 9073 | * iocb is submitted to the firmware. This function checks |
| 9074 | * txq to flush the iocbs in txq to Firmware before |
| 9075 | * submitting new iocbs to the Firmware. |
| 9076 | * If there are iocbs in the txq which need to be submitted |
| 9077 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 9078 | * of the txq after dequeuing it from txq. |
| 9079 | * If there is no iocb in the txq then the function will return |
| 9080 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 9081 | * *piocb to find if there are more commands in the txq. |
| 9082 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9083 | static struct lpfc_iocbq * |
| 9084 | 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] | 9085 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9086 | { |
| 9087 | struct lpfc_iocbq * nextiocb; |
| 9088 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9089 | lockdep_assert_held(&phba->hbalock); |
| 9090 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9091 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 9092 | if (!nextiocb) { |
| 9093 | nextiocb = *piocb; |
| 9094 | *piocb = NULL; |
| 9095 | } |
| 9096 | |
| 9097 | return nextiocb; |
| 9098 | } |
| 9099 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9100 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9101 | * __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] | 9102 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9103 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9104 | * @piocb: Pointer to command iocb. |
| 9105 | * @flag: Flag indicating if this command can be put into txq. |
| 9106 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9107 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 9108 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 9109 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 9110 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 9111 | * this function allows only iocbs for posting buffers. This function finds |
| 9112 | * next available slot in the command ring and posts the command to the |
| 9113 | * available slot and writes the port attention register to request HBA start |
| 9114 | * processing new iocb. If there is no slot available in the ring and |
| 9115 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 9116 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9117 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9118 | * This function is called with hbalock held. The function will return success |
| 9119 | * after it successfully submit the iocb to firmware or after adding to the |
| 9120 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9121 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9122 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9123 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9124 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9125 | { |
| 9126 | struct lpfc_iocbq *nextiocb; |
| 9127 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9128 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9129 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9130 | lockdep_assert_held(&phba->hbalock); |
| 9131 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9132 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 9133 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 9134 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 9135 | lpfc_printf_log(phba, KERN_ERR, |
| 9136 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9137 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9138 | piocb->iocb.ulpCommand); |
| 9139 | dump_stack(); |
| 9140 | return IOCB_ERROR; |
| 9141 | } |
| 9142 | |
| 9143 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9144 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 9145 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 9146 | return IOCB_ERROR; |
| 9147 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9148 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 9149 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 9150 | return IOCB_ERROR; |
| 9151 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9152 | /* |
| 9153 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 9154 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9155 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9156 | return IOCB_ERROR; |
| 9157 | |
| 9158 | /* |
| 9159 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9160 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9161 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9162 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9163 | goto iocb_busy; |
| 9164 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9165 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9166 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9167 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9168 | * can be issued if the link is not up. |
| 9169 | */ |
| 9170 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9171 | case CMD_GEN_REQUEST64_CR: |
| 9172 | case CMD_GEN_REQUEST64_CX: |
| 9173 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 9174 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9175 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9176 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 9177 | MENLO_TRANSPORT_TYPE)) |
| 9178 | |
| 9179 | goto iocb_busy; |
| 9180 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9181 | case CMD_QUE_RING_BUF_CN: |
| 9182 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9183 | /* |
| 9184 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 9185 | * completion, iocb_cmpl MUST be 0. |
| 9186 | */ |
| 9187 | if (piocb->iocb_cmpl) |
| 9188 | piocb->iocb_cmpl = NULL; |
| 9189 | /*FALLTHROUGH*/ |
| 9190 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9191 | case CMD_CLOSE_XRI_CN: |
| 9192 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9193 | break; |
| 9194 | default: |
| 9195 | goto iocb_busy; |
| 9196 | } |
| 9197 | |
| 9198 | /* |
| 9199 | * For FCP commands, we must be in a state where we can process link |
| 9200 | * attention events. |
| 9201 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9202 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9203 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9204 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9205 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9206 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9207 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 9208 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 9209 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 9210 | |
| 9211 | if (iocb) |
| 9212 | lpfc_sli_update_ring(phba, pring); |
| 9213 | else |
| 9214 | lpfc_sli_update_full_ring(phba, pring); |
| 9215 | |
| 9216 | if (!piocb) |
| 9217 | return IOCB_SUCCESS; |
| 9218 | |
| 9219 | goto out_busy; |
| 9220 | |
| 9221 | iocb_busy: |
| 9222 | pring->stats.iocb_cmd_delay++; |
| 9223 | |
| 9224 | out_busy: |
| 9225 | |
| 9226 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9227 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9228 | return IOCB_SUCCESS; |
| 9229 | } |
| 9230 | |
| 9231 | return IOCB_BUSY; |
| 9232 | } |
| 9233 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9234 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9235 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 9236 | * @phba: Pointer to HBA context object. |
| 9237 | * @piocb: Pointer to command iocb. |
| 9238 | * @sglq: Pointer to the scatter gather queue object. |
| 9239 | * |
| 9240 | * This routine converts the bpl or bde that is in the IOCB |
| 9241 | * to a sgl list for the sli4 hardware. The physical address |
| 9242 | * of the bpl/bde is converted back to a virtual address. |
| 9243 | * If the IOCB contains a BPL then the list of BDE's is |
| 9244 | * converted to sli4_sge's. If the IOCB contains a single |
| 9245 | * BDE then it is converted to a single sli_sge. |
| 9246 | * The IOCB is still in cpu endianess so the contents of |
| 9247 | * the bpl can be used without byte swapping. |
| 9248 | * |
| 9249 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 9250 | **/ |
| 9251 | static uint16_t |
| 9252 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 9253 | struct lpfc_sglq *sglq) |
| 9254 | { |
| 9255 | uint16_t xritag = NO_XRI; |
| 9256 | struct ulp_bde64 *bpl = NULL; |
| 9257 | struct ulp_bde64 bde; |
| 9258 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9259 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9260 | IOCB_t *icmd; |
| 9261 | int numBdes = 0; |
| 9262 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9263 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 9264 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9265 | |
| 9266 | if (!piocbq || !sglq) |
| 9267 | return xritag; |
| 9268 | |
| 9269 | sgl = (struct sli4_sge *)sglq->sgl; |
| 9270 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9271 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 9272 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9273 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 9274 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 9275 | sizeof(struct ulp_bde64); |
| 9276 | /* The addrHigh and addrLow fields within the IOCB |
| 9277 | * have not been byteswapped yet so there is no |
| 9278 | * need to swap them back. |
| 9279 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9280 | if (piocbq->context3) |
| 9281 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 9282 | else |
| 9283 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9284 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9285 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9286 | if (!bpl) |
| 9287 | return xritag; |
| 9288 | |
| 9289 | for (i = 0; i < numBdes; i++) { |
| 9290 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9291 | sgl->addr_hi = bpl->addrHigh; |
| 9292 | sgl->addr_lo = bpl->addrLow; |
| 9293 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9294 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9295 | if ((i+1) == numBdes) |
| 9296 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9297 | else |
| 9298 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9299 | /* swap the size field back to the cpu so we |
| 9300 | * can assign it to the sgl. |
| 9301 | */ |
| 9302 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 9303 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9304 | /* The offsets in the sgl need to be accumulated |
| 9305 | * separately for the request and reply lists. |
| 9306 | * The request is always first, the reply follows. |
| 9307 | */ |
| 9308 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 9309 | /* add up the reply sg entries */ |
| 9310 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 9311 | inbound++; |
| 9312 | /* first inbound? reset the offset */ |
| 9313 | if (inbound == 1) |
| 9314 | offset = 0; |
| 9315 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 9316 | bf_set(lpfc_sli4_sge_type, sgl, |
| 9317 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9318 | offset += bde.tus.f.bdeSize; |
| 9319 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9320 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9321 | bpl++; |
| 9322 | sgl++; |
| 9323 | } |
| 9324 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 9325 | /* The addrHigh and addrLow fields of the BDE have not |
| 9326 | * been byteswapped yet so they need to be swapped |
| 9327 | * before putting them in the sgl. |
| 9328 | */ |
| 9329 | sgl->addr_hi = |
| 9330 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 9331 | sgl->addr_lo = |
| 9332 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9333 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9334 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9335 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9336 | sgl->sge_len = |
| 9337 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9338 | } |
| 9339 | return sglq->sli4_xritag; |
| 9340 | } |
| 9341 | |
| 9342 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9343 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 9344 | * @phba: Pointer to HBA context object. |
| 9345 | * @piocb: Pointer to command iocb. |
| 9346 | * @wqe: Pointer to the work queue entry. |
| 9347 | * |
| 9348 | * This routine converts the iocb command to its Work Queue Entry |
| 9349 | * equivalent. The wqe pointer should not have any fields set when |
| 9350 | * this routine is called because it will memcpy over them. |
| 9351 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 9352 | * wqe. |
| 9353 | * |
| 9354 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 9355 | **/ |
| 9356 | static int |
| 9357 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9358 | union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9359 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9360 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9361 | uint8_t ct = 0; |
| 9362 | uint32_t fip; |
| 9363 | uint32_t abort_tag; |
| 9364 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 9365 | uint8_t cmnd; |
| 9366 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9367 | uint16_t abrt_iotag; |
| 9368 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9369 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9370 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9371 | int numBdes, i; |
| 9372 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9373 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9374 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9375 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9376 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9377 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9378 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9379 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9380 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9381 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9382 | command_type = ELS_COMMAND_FIP; |
| 9383 | else |
| 9384 | command_type = ELS_COMMAND_NON_FIP; |
| 9385 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9386 | if (phba->fcp_embed_io) |
| 9387 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9388 | /* Some of the fields are in the right position already */ |
| 9389 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 9390 | /* The ct field has moved so reset */ |
| 9391 | wqe->generic.wqe_com.word7 = 0; |
| 9392 | wqe->generic.wqe_com.word10 = 0; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9393 | |
| 9394 | abort_tag = (uint32_t) iocbq->iotag; |
| 9395 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9396 | /* words0-2 bpl convert bde */ |
| 9397 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9398 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9399 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9400 | bpl = (struct ulp_bde64 *) |
| 9401 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 9402 | if (!bpl) |
| 9403 | return IOCB_ERROR; |
| 9404 | |
| 9405 | /* Should already be byte swapped. */ |
| 9406 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 9407 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 9408 | /* swap the size field back to the cpu so we |
| 9409 | * can assign it to the sgl. |
| 9410 | */ |
| 9411 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9412 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 9413 | total_len = 0; |
| 9414 | for (i = 0; i < numBdes; i++) { |
| 9415 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 9416 | total_len += bde.tus.f.bdeSize; |
| 9417 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9418 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9419 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9420 | |
| 9421 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 9422 | cmnd = iocbq->iocb.ulpCommand; |
| 9423 | |
| 9424 | switch (iocbq->iocb.ulpCommand) { |
| 9425 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 9426 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 9427 | ndlp = iocbq->context_un.ndlp; |
| 9428 | else |
| 9429 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9430 | if (!iocbq->iocb.ulpLe) { |
| 9431 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9432 | "2007 Only Limited Edition cmd Format" |
| 9433 | " supported 0x%x\n", |
| 9434 | iocbq->iocb.ulpCommand); |
| 9435 | return IOCB_ERROR; |
| 9436 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9437 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9438 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9439 | /* Els_reguest64 has a TMO */ |
| 9440 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 9441 | iocbq->iocb.ulpTimeout); |
| 9442 | /* Need a VF for word 4 set the vf bit*/ |
| 9443 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 9444 | /* And a VFID for word 12 */ |
| 9445 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9446 | ct = ((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_ctxt_tag, &wqe->els_req.wqe_com, |
| 9448 | iocbq->iocb.ulpContext); |
| 9449 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 9450 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9451 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9452 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9453 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 9454 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9455 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9456 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9457 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9458 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9459 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9460 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9461 | *pcmd == ELS_CMD_SCR || |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 9462 | *pcmd == ELS_CMD_RSCN_XMT || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9463 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 9464 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9465 | *pcmd == ELS_CMD_PLOGI)) { |
| 9466 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 9467 | bf_set(els_req64_sid, &wqe->els_req, |
| 9468 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9469 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 9470 | !(phba->fc_topology == |
| 9471 | LPFC_TOPOLOGY_LOOP)) |
| 9472 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9473 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 9474 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 9475 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 9476 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9477 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 9478 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9479 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 9480 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9481 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9482 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 9483 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9484 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 9485 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 9486 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9487 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 9488 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9489 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9490 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9491 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9492 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9493 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 9494 | iocbq->iocb.un.ulpWord[3]); |
| 9495 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9496 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9497 | /* The entire sequence is transmitted for this IOCB */ |
| 9498 | xmit_len = total_len; |
| 9499 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9500 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 9501 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 9502 | /* fall through */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9503 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9504 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 9505 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9506 | /* word4 relative_offset memcpy */ |
| 9507 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9508 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 9509 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 9510 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 9511 | LPFC_WQE_IOD_WRITE); |
| 9512 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 9513 | LPFC_WQE_LENLOC_WORD12); |
| 9514 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9515 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 9516 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9517 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9518 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9519 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 9520 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9521 | /* word4 iocb=rsvd wqe=rsvd */ |
| 9522 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 9523 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9524 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9525 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9526 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 9527 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9528 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 9529 | LPFC_WQE_LENLOC_WORD3); |
| 9530 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9531 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9532 | case CMD_FCP_IWRITE64_CR: |
| 9533 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9534 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9535 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9536 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 9537 | xmit_len + sizeof(struct fcp_rsp)); |
| 9538 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 9539 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9540 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9541 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9542 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 9543 | iocbq->iocb.ulpFCP2Rcvy); |
| 9544 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 9545 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9546 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9547 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 9548 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9549 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9550 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9551 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9552 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9553 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 9554 | if (iocbq->priority) { |
| 9555 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9556 | (iocbq->priority << 1)); |
| 9557 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9558 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9559 | (phba->cfg_XLanePriority << 1)); |
| 9560 | } |
| 9561 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9562 | /* Note, word 10 is already initialized to 0 */ |
| 9563 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9564 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9565 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9566 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); |
| 9567 | else |
| 9568 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 9569 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9570 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9571 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9572 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9573 | struct fcp_cmnd *fcp_cmnd; |
| 9574 | uint32_t *ptr; |
| 9575 | |
| 9576 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9577 | |
| 9578 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9579 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9580 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9581 | |
| 9582 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9583 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9584 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9585 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9586 | wqe->generic.bde.addrHigh = 0; |
| 9587 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9588 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9589 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 9590 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9591 | |
| 9592 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9593 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9594 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9595 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9596 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9597 | case CMD_FCP_IREAD64_CR: |
| 9598 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9599 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9600 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 9601 | xmit_len + sizeof(struct fcp_rsp)); |
| 9602 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 9603 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9604 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9605 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9606 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 9607 | iocbq->iocb.ulpFCP2Rcvy); |
| 9608 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9609 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9610 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 9611 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 9612 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9613 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9614 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9615 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9616 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9617 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 9618 | if (iocbq->priority) { |
| 9619 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9620 | (iocbq->priority << 1)); |
| 9621 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9622 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9623 | (phba->cfg_XLanePriority << 1)); |
| 9624 | } |
| 9625 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9626 | /* Note, word 10 is already initialized to 0 */ |
| 9627 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9628 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9629 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9630 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); |
| 9631 | else |
| 9632 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0); |
| 9633 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9634 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9635 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9636 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9637 | struct fcp_cmnd *fcp_cmnd; |
| 9638 | uint32_t *ptr; |
| 9639 | |
| 9640 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9641 | |
| 9642 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9643 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9644 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9645 | |
| 9646 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9647 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9648 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9649 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9650 | wqe->generic.bde.addrHigh = 0; |
| 9651 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9652 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9653 | bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); |
| 9654 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9655 | |
| 9656 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9657 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9658 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9659 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9660 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9661 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9662 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9663 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 9664 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 9665 | xmit_len + sizeof(struct fcp_rsp)); |
| 9666 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 9667 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9668 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9669 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9670 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9671 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 9672 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9673 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 9674 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 9675 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 9676 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 9677 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9678 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9679 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9680 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 9681 | if (iocbq->priority) { |
| 9682 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9683 | (iocbq->priority << 1)); |
| 9684 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9685 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9686 | (phba->cfg_XLanePriority << 1)); |
| 9687 | } |
| 9688 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9689 | /* Note, word 10 is already initialized to 0 */ |
| 9690 | |
| 9691 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9692 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9693 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9694 | struct fcp_cmnd *fcp_cmnd; |
| 9695 | uint32_t *ptr; |
| 9696 | |
| 9697 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9698 | |
| 9699 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9700 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9701 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9702 | |
| 9703 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9704 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9705 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9706 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9707 | wqe->generic.bde.addrHigh = 0; |
| 9708 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9709 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9710 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); |
| 9711 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9712 | |
| 9713 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9714 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9715 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9716 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9717 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9718 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9719 | /* For this command calculate the xmit length of the |
| 9720 | * request bde. |
| 9721 | */ |
| 9722 | xmit_len = 0; |
| 9723 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9724 | sizeof(struct ulp_bde64); |
| 9725 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9726 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9727 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 9728 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9729 | xmit_len += bde.tus.f.bdeSize; |
| 9730 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9731 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 9732 | wqe->gen_req.request_payload_len = xmit_len; |
| 9733 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 9734 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9735 | /* word6 context tag copied in memcpy */ |
| 9736 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 9737 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 9738 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9739 | "2015 Invalid CT %x command 0x%x\n", |
| 9740 | ct, iocbq->iocb.ulpCommand); |
| 9741 | return IOCB_ERROR; |
| 9742 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9743 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 9744 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 9745 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 9746 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 9747 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9748 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 9749 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9750 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9751 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9752 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9753 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9754 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9755 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9756 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9757 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 9758 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9759 | /* word4 */ |
| 9760 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9761 | /* word5 iocb=rsvd wge=did */ |
| 9762 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9763 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 9764 | |
| 9765 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9766 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9767 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9768 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 9769 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9770 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 9771 | iocbq->vport->fc_myDID); |
| 9772 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 9773 | bf_set(wqe_els_did, |
| 9774 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 9775 | } |
| 9776 | } |
| 9777 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9778 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 9779 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9780 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 9781 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9782 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9783 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9784 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9785 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9786 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9787 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9788 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9789 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 9790 | LPFC_WQE_LENLOC_WORD3); |
| 9791 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9792 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 9793 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9794 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9795 | iocbq->context2)->virt); |
| 9796 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9797 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9798 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9799 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9800 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9801 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9802 | phba->vpi_ids[phba->pport->vpi]); |
| 9803 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9804 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9805 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9806 | case CMD_CLOSE_XRI_CN: |
| 9807 | case CMD_ABORT_XRI_CN: |
| 9808 | case CMD_ABORT_XRI_CX: |
| 9809 | /* words 0-2 memcpy should be 0 rserved */ |
| 9810 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9811 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 9812 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 9813 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 9814 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 9815 | } else |
| 9816 | fip = 0; |
| 9817 | |
| 9818 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9819 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9820 | * The link is down, or the command was ELS_FIP |
| 9821 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9822 | * on the wire. |
| 9823 | */ |
| 9824 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 9825 | else |
| 9826 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 9827 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9828 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 9829 | wqe->abort_cmd.rsrvd5 = 0; |
| 9830 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9831 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9832 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9833 | /* |
| 9834 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 9835 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 9836 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9837 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 9838 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 9839 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 9840 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9841 | cmnd = CMD_ABORT_XRI_CX; |
| 9842 | command_type = OTHER_COMMAND; |
| 9843 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9844 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9845 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9846 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9847 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9848 | * we re-construct this WQE here based on information in |
| 9849 | * iocbq from scratch. |
| 9850 | */ |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 9851 | memset(wqe, 0, sizeof(*wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9852 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9853 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9854 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 9855 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9856 | LPFC_ABTS_UNSOL_INT) { |
| 9857 | /* ABTS sent by initiator to CT exchange, the |
| 9858 | * RX_ID field will be filled with the newly |
| 9859 | * allocated responder XRI. |
| 9860 | */ |
| 9861 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 9862 | iocbq->sli4_xritag); |
| 9863 | } else { |
| 9864 | /* ABTS sent by responder to CT exchange, the |
| 9865 | * RX_ID field will be filled with the responder |
| 9866 | * RX_ID from ABTS. |
| 9867 | */ |
| 9868 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9869 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9870 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9871 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 9872 | 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] | 9873 | |
| 9874 | /* Use CT=VPI */ |
| 9875 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 9876 | ndlp->nlp_DID); |
| 9877 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 9878 | iocbq->iocb.ulpContext); |
| 9879 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9880 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9881 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9882 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 9883 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 9884 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9885 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 9886 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9887 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 9888 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 9889 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 9890 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 9891 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 9892 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 9893 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 9894 | } |
| 9895 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9896 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9897 | case CMD_SEND_FRAME: |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 9898 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_SEND_FRAME); |
| 9899 | bf_set(wqe_sof, &wqe->generic.wqe_com, 0x2E); /* SOF byte */ |
| 9900 | bf_set(wqe_eof, &wqe->generic.wqe_com, 0x41); /* EOF byte */ |
| 9901 | bf_set(wqe_lenloc, &wqe->generic.wqe_com, 1); |
| 9902 | bf_set(wqe_xbl, &wqe->generic.wqe_com, 1); |
| 9903 | bf_set(wqe_dbde, &wqe->generic.wqe_com, 1); |
| 9904 | bf_set(wqe_xc, &wqe->generic.wqe_com, 1); |
| 9905 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 0xA); |
| 9906 | 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] | 9907 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9908 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9909 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9910 | case CMD_XRI_ABORTED_CX: |
| 9911 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9912 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 9913 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 9914 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 9915 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 9916 | default: |
| 9917 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9918 | "2014 Invalid command 0x%x\n", |
| 9919 | iocbq->iocb.ulpCommand); |
| 9920 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9921 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9922 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9923 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 9924 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 9925 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 9926 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 9927 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 9928 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 9929 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 9930 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 9931 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9932 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9933 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9934 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 9935 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 9936 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 9937 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 9938 | 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] | 9939 | return 0; |
| 9940 | } |
| 9941 | |
| 9942 | /** |
| 9943 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 9944 | * @phba: Pointer to HBA context object. |
| 9945 | * @ring_number: SLI ring number to issue iocb on. |
| 9946 | * @piocb: Pointer to command iocb. |
| 9947 | * @flag: Flag indicating if this command can be put into txq. |
| 9948 | * |
| 9949 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 9950 | * an iocb command to an HBA with SLI-4 interface spec. |
| 9951 | * |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame] | 9952 | * This function is called with ringlock held. The function will return success |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9953 | * after it successfully submit the iocb to firmware or after adding to the |
| 9954 | * txq. |
| 9955 | **/ |
| 9956 | static int |
| 9957 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 9958 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9959 | { |
| 9960 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9961 | union lpfc_wqe128 wqe; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9962 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9963 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9964 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9965 | /* Get the WQ */ |
| 9966 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 9967 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9968 | wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9969 | } else { |
| 9970 | wq = phba->sli4_hba.els_wq; |
| 9971 | } |
| 9972 | |
| 9973 | /* Get corresponding ring */ |
| 9974 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9975 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9976 | /* |
| 9977 | * The WQE can be either 64 or 128 bytes, |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9978 | */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9979 | |
James Smart | cda7fa18 | 2019-03-04 15:15:43 -0800 | [diff] [blame] | 9980 | lockdep_assert_held(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9981 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9982 | if (piocb->sli4_xritag == NO_XRI) { |
| 9983 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9984 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9985 | sglq = NULL; |
| 9986 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9987 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9988 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9989 | __lpfc_sli_ringtx_put(phba, |
| 9990 | pring, piocb); |
| 9991 | return IOCB_SUCCESS; |
| 9992 | } else { |
| 9993 | return IOCB_BUSY; |
| 9994 | } |
| 9995 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9996 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9997 | if (!sglq) { |
| 9998 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9999 | __lpfc_sli_ringtx_put(phba, |
| 10000 | pring, |
| 10001 | piocb); |
| 10002 | return IOCB_SUCCESS; |
| 10003 | } else |
| 10004 | return IOCB_BUSY; |
| 10005 | } |
| 10006 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10007 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 10008 | } else if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10009 | /* These IO's already have an XRI and a mapped sgl. */ |
| 10010 | sglq = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 10011 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10012 | /* |
| 10013 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10014 | * sglq is on the active list |
| 10015 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 10016 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10017 | if (!sglq) |
| 10018 | return IOCB_ERROR; |
| 10019 | } |
| 10020 | |
| 10021 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10022 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10023 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10024 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10025 | return IOCB_ERROR; |
| 10026 | } |
| 10027 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10028 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10029 | return IOCB_ERROR; |
| 10030 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10031 | if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10032 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10033 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 10034 | |
| 10035 | return 0; |
| 10036 | } |
| 10037 | |
| 10038 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10039 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 10040 | * |
| 10041 | * This routine wraps the actual lockless version for issusing IOCB function |
| 10042 | * pointer from the lpfc_hba struct. |
| 10043 | * |
| 10044 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10045 | * IOCB_ERROR - Error |
| 10046 | * IOCB_SUCCESS - Success |
| 10047 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10048 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10049 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10050 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 10051 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10052 | { |
| 10053 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10054 | } |
| 10055 | |
| 10056 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10057 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10058 | * @phba: The hba struct for which this call is being executed. |
| 10059 | * @dev_grp: The HBA PCI-Device group number. |
| 10060 | * |
| 10061 | * This routine sets up the SLI interface API function jump table in @phba |
| 10062 | * struct. |
| 10063 | * Returns: 0 - success, -ENODEV - failure. |
| 10064 | **/ |
| 10065 | int |
| 10066 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 10067 | { |
| 10068 | |
| 10069 | switch (dev_grp) { |
| 10070 | case LPFC_PCI_DEV_LP: |
| 10071 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 10072 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 10073 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10074 | case LPFC_PCI_DEV_OC: |
| 10075 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 10076 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 10077 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10078 | default: |
| 10079 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10080 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 10081 | dev_grp); |
| 10082 | return -ENODEV; |
| 10083 | break; |
| 10084 | } |
| 10085 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 10086 | return 0; |
| 10087 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10088 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10089 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10090 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10091 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10092 | * @piocb: Pointer to command iocb. |
| 10093 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10094 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 10095 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10096 | * 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] | 10097 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10098 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10099 | struct lpfc_sli_ring * |
| 10100 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10101 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10102 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10103 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10104 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10105 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 10106 | return NULL; |
| 10107 | /* |
| 10108 | * for abort iocb hba_wqidx should already |
| 10109 | * be setup based on what work queue we used. |
| 10110 | */ |
| 10111 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10112 | lpfc_cmd = (struct lpfc_io_buf *)piocb->context1; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 10113 | piocb->hba_wqidx = lpfc_cmd->hdwq_no; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10114 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10115 | return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10116 | } else { |
| 10117 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 10118 | return NULL; |
| 10119 | piocb->hba_wqidx = 0; |
| 10120 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10121 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10122 | } |
| 10123 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10124 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10125 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10126 | * @phba: Pointer to HBA context object. |
| 10127 | * @pring: Pointer to driver SLI ring object. |
| 10128 | * @piocb: Pointer to command iocb. |
| 10129 | * @flag: Flag indicating if this command can be put into txq. |
| 10130 | * |
| 10131 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 10132 | * function. This function gets the hbalock and calls |
| 10133 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 10134 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 10135 | * functions which do not hold hbalock. |
| 10136 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10137 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10138 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10139 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10140 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10141 | struct lpfc_sli_ring *pring; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 10142 | struct lpfc_queue *eq; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10143 | unsigned long iflags; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10144 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10145 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10146 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 10147 | eq = phba->sli4_hba.hdwq[piocb->hba_wqidx].hba_eq; |
| 10148 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10149 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 10150 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10151 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10152 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10153 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10154 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10155 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 10156 | |
| 10157 | lpfc_sli4_poll_eq(eq, LPFC_POLL_FASTPATH); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10158 | } else { |
| 10159 | /* For now, SLI2/3 will still use hbalock */ |
| 10160 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10161 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10162 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10163 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10164 | return rc; |
| 10165 | } |
| 10166 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10167 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10168 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10169 | * @phba: Pointer to HBA context object. |
| 10170 | * |
| 10171 | * This function is called while driver attaches with the |
| 10172 | * HBA to setup the extra ring. The extra ring is used |
| 10173 | * only when driver needs to support target mode functionality |
| 10174 | * or IP over FC functionalities. |
| 10175 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10176 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10177 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10178 | static int |
| 10179 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 10180 | { |
| 10181 | struct lpfc_sli *psli; |
| 10182 | struct lpfc_sli_ring *pring; |
| 10183 | |
| 10184 | psli = &phba->sli; |
| 10185 | |
| 10186 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10187 | |
| 10188 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10189 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10190 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10191 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10192 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10193 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10194 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10195 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10196 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10197 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10198 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10199 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10200 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10201 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10202 | |
| 10203 | /* Setup default profile for this ring */ |
| 10204 | pring->iotag_max = 4096; |
| 10205 | pring->num_mask = 1; |
| 10206 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10207 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 10208 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10209 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 10210 | return 0; |
| 10211 | } |
| 10212 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10213 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 10214 | * @phba: Pointer to HBA context object. |
| 10215 | * @iocbq: Pointer to iocb object. |
| 10216 | * |
| 10217 | * The async_event handler calls this routine when it receives |
| 10218 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 10219 | * this event when an Abort Sequence request to an rport fails |
| 10220 | * twice in succession. The abort could be originated by the |
| 10221 | * driver or by the port. The ABTS could have been for an ELS |
| 10222 | * or FCP IO. The port only generates this event when an ABTS |
| 10223 | * fails to complete after one retry. |
| 10224 | */ |
| 10225 | static void |
| 10226 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 10227 | struct lpfc_iocbq *iocbq) |
| 10228 | { |
| 10229 | struct lpfc_nodelist *ndlp = NULL; |
| 10230 | uint16_t rpi = 0, vpi = 0; |
| 10231 | struct lpfc_vport *vport = NULL; |
| 10232 | |
| 10233 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 10234 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 10235 | rpi = iocbq->iocb.ulpContext; |
| 10236 | |
| 10237 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10238 | "3092 Port generated ABTS async event " |
| 10239 | "on vpi %d rpi %d status 0x%x\n", |
| 10240 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 10241 | |
| 10242 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 10243 | if (!vport) |
| 10244 | goto err_exit; |
| 10245 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 10246 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 10247 | goto err_exit; |
| 10248 | |
| 10249 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 10250 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10251 | return; |
| 10252 | |
| 10253 | err_exit: |
| 10254 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10255 | "3095 Event Context not found, no " |
| 10256 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 10257 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 10258 | vpi, rpi); |
| 10259 | } |
| 10260 | |
| 10261 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 10262 | * @phba: pointer to HBA context object. |
| 10263 | * @ndlp: nodelist pointer for the impacted rport. |
| 10264 | * @axri: pointer to the wcqe containing the failed exchange. |
| 10265 | * |
| 10266 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 10267 | * port. The port generates this event when an abort exchange request to an |
| 10268 | * rport fails twice in succession with no reply. The abort could be originated |
| 10269 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 10270 | */ |
| 10271 | void |
| 10272 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 10273 | struct lpfc_nodelist *ndlp, |
| 10274 | struct sli4_wcqe_xri_aborted *axri) |
| 10275 | { |
| 10276 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10277 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10278 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10279 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10280 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10281 | "3115 Node Context not found, driver " |
| 10282 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10283 | return; |
| 10284 | } |
| 10285 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10286 | vport = ndlp->vport; |
| 10287 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10288 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10289 | "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] | 10290 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10291 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10292 | bf_get(lpfc_wcqe_xa_status, axri), |
| 10293 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10294 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10295 | /* |
| 10296 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 10297 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 10298 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 10299 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 10300 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10301 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 10302 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10303 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10304 | } |
| 10305 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10306 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10307 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10308 | * @phba: Pointer to HBA context object. |
| 10309 | * @pring: Pointer to driver SLI ring object. |
| 10310 | * @iocbq: Pointer to iocb object. |
| 10311 | * |
| 10312 | * This function is called by the slow ring event handler |
| 10313 | * function when there is an ASYNC event iocb in the ring. |
| 10314 | * This function is called with no lock held. |
| 10315 | * Currently this function handles only temperature related |
| 10316 | * ASYNC events. The function decodes the temperature sensor |
| 10317 | * event message and posts events for the management applications. |
| 10318 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10319 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10320 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 10321 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 10322 | { |
| 10323 | IOCB_t *icmd; |
| 10324 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10325 | struct temp_event temp_event_data; |
| 10326 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10327 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10328 | |
| 10329 | icmd = &iocbq->iocb; |
| 10330 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10331 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10332 | switch (evt_code) { |
| 10333 | case ASYNC_TEMP_WARN: |
| 10334 | case ASYNC_TEMP_SAFE: |
| 10335 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 10336 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 10337 | if (evt_code == ASYNC_TEMP_WARN) { |
| 10338 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 10339 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10340 | "0347 Adapter is very hot, please take " |
| 10341 | "corrective action. temperature : %d Celsius\n", |
| 10342 | (uint32_t) icmd->ulpContext); |
| 10343 | } else { |
| 10344 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 10345 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10346 | "0340 Adapter temperature is OK now. " |
| 10347 | "temperature : %d Celsius\n", |
| 10348 | (uint32_t) icmd->ulpContext); |
| 10349 | } |
| 10350 | |
| 10351 | /* Send temperature change event to applications */ |
| 10352 | shost = lpfc_shost_from_vport(phba->pport); |
| 10353 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 10354 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 10355 | LPFC_NL_VENDOR_ID); |
| 10356 | break; |
| 10357 | case ASYNC_STATUS_CN: |
| 10358 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 10359 | break; |
| 10360 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10361 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10362 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10363 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 10364 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10365 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 10366 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 10367 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 10368 | "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] | 10369 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10370 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 10371 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 10372 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 10373 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 10374 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10375 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10376 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10377 | } |
| 10378 | |
| 10379 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10380 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10381 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10382 | * @phba: Pointer to HBA context object. |
| 10383 | * |
| 10384 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10385 | * number of iocbs per ring and iotags. This function is |
| 10386 | * called while driver attach to the HBA and before the |
| 10387 | * interrupts are enabled. So there is no need for locking. |
| 10388 | * |
| 10389 | * This function always returns 0. |
| 10390 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10391 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10392 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 10393 | { |
| 10394 | struct lpfc_sli_ring *pring; |
| 10395 | |
| 10396 | pring = phba->sli4_hba.els_wq->pring; |
| 10397 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 10398 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 10399 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10400 | pring->prt[0].type = FC_TYPE_ELS; |
| 10401 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 10402 | lpfc_els_unsol_event; |
| 10403 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 10404 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10405 | pring->prt[1].type = FC_TYPE_ELS; |
| 10406 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 10407 | lpfc_els_unsol_event; |
| 10408 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10409 | /* NameServer Inquiry */ |
| 10410 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 10411 | /* NameServer */ |
| 10412 | pring->prt[2].type = FC_TYPE_CT; |
| 10413 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 10414 | lpfc_ct_unsol_event; |
| 10415 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10416 | /* NameServer response */ |
| 10417 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 10418 | /* NameServer */ |
| 10419 | pring->prt[3].type = FC_TYPE_CT; |
| 10420 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 10421 | lpfc_ct_unsol_event; |
| 10422 | return 0; |
| 10423 | } |
| 10424 | |
| 10425 | /** |
| 10426 | * lpfc_sli_setup - SLI ring setup function |
| 10427 | * @phba: Pointer to HBA context object. |
| 10428 | * |
| 10429 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10430 | * number of iocbs per ring and iotags. This function is |
| 10431 | * called while driver attach to the HBA and before the |
| 10432 | * interrupts are enabled. So there is no need for locking. |
| 10433 | * |
| 10434 | * This function always returns 0. SLI3 only. |
| 10435 | **/ |
| 10436 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10437 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 10438 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10439 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10440 | struct lpfc_sli *psli = &phba->sli; |
| 10441 | struct lpfc_sli_ring *pring; |
| 10442 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10443 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10444 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10445 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10446 | psli->iocbq_lookup = NULL; |
| 10447 | psli->iocbq_lookup_len = 0; |
| 10448 | psli->last_iotag = 0; |
| 10449 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10450 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10451 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10452 | switch (i) { |
| 10453 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 10454 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10455 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 10456 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 10457 | pring->sli.sli3.numCiocb += |
| 10458 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10459 | pring->sli.sli3.numRiocb += |
| 10460 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10461 | pring->sli.sli3.numCiocb += |
| 10462 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10463 | pring->sli.sli3.numRiocb += |
| 10464 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 10465 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10466 | SLI3_IOCB_CMD_SIZE : |
| 10467 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10468 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10469 | SLI3_IOCB_RSP_SIZE : |
| 10470 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10471 | pring->iotag_ctr = 0; |
| 10472 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10473 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10474 | pring->fast_iotag = pring->iotag_max; |
| 10475 | pring->num_mask = 0; |
| 10476 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10477 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10478 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10479 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 10480 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 10481 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10482 | SLI3_IOCB_CMD_SIZE : |
| 10483 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10484 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10485 | SLI3_IOCB_RSP_SIZE : |
| 10486 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10487 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10488 | pring->num_mask = 0; |
| 10489 | break; |
| 10490 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 10491 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10492 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 10493 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 10494 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10495 | SLI3_IOCB_CMD_SIZE : |
| 10496 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10497 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10498 | SLI3_IOCB_RSP_SIZE : |
| 10499 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10500 | pring->fast_iotag = 0; |
| 10501 | pring->iotag_ctr = 0; |
| 10502 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10503 | pring->lpfc_sli_rcv_async_status = |
| 10504 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10505 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10506 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10507 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10508 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10509 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10510 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10511 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10512 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10513 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10514 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10515 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10516 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10517 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10518 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10519 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10520 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10521 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10522 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10523 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10524 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10525 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10526 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10527 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10528 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10529 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10530 | break; |
| 10531 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10532 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 10533 | pring->sli.sli3.sizeCiocb) + |
| 10534 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10535 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10536 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10537 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10538 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 10539 | "SLI2 SLIM Data: x%x x%lx\n", |
| 10540 | phba->brd_no, totiocbsize, |
| 10541 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10542 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10543 | if (phba->cfg_multi_ring_support == 2) |
| 10544 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10545 | |
| 10546 | return 0; |
| 10547 | } |
| 10548 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10549 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10550 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10551 | * @phba: Pointer to HBA context object. |
| 10552 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10553 | * 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] | 10554 | * ring. This function also initializes ring indices of each ring. |
| 10555 | * This function is called during the initialization of the SLI |
| 10556 | * interface of an HBA. |
| 10557 | * This function is called with no lock held and always returns |
| 10558 | * 1. |
| 10559 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10560 | void |
| 10561 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 10562 | { |
| 10563 | struct lpfc_sli *psli; |
| 10564 | struct lpfc_sli_ring *pring; |
| 10565 | int i; |
| 10566 | |
| 10567 | psli = &phba->sli; |
| 10568 | spin_lock_irq(&phba->hbalock); |
| 10569 | INIT_LIST_HEAD(&psli->mboxq); |
| 10570 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 10571 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10572 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10573 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10574 | pring->flag = 0; |
| 10575 | pring->ringno = LPFC_FCP_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10576 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10577 | INIT_LIST_HEAD(&pring->txq); |
| 10578 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10579 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10580 | spin_lock_init(&pring->ring_lock); |
| 10581 | } |
| 10582 | pring = phba->sli4_hba.els_wq->pring; |
| 10583 | pring->flag = 0; |
| 10584 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10585 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10586 | INIT_LIST_HEAD(&pring->txq); |
| 10587 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10588 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10589 | spin_lock_init(&pring->ring_lock); |
| 10590 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10591 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10592 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 10593 | pring->flag = 0; |
| 10594 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10595 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10596 | INIT_LIST_HEAD(&pring->txq); |
| 10597 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10598 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10599 | spin_lock_init(&pring->ring_lock); |
| 10600 | } |
| 10601 | |
| 10602 | spin_unlock_irq(&phba->hbalock); |
| 10603 | } |
| 10604 | |
| 10605 | /** |
| 10606 | * lpfc_sli_queue_init - Queue initialization function |
| 10607 | * @phba: Pointer to HBA context object. |
| 10608 | * |
| 10609 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 10610 | * ring. This function also initializes ring indices of each ring. |
| 10611 | * This function is called during the initialization of the SLI |
| 10612 | * interface of an HBA. |
| 10613 | * This function is called with no lock held and always returns |
| 10614 | * 1. |
| 10615 | **/ |
| 10616 | void |
| 10617 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10618 | { |
| 10619 | struct lpfc_sli *psli; |
| 10620 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10621 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10622 | |
| 10623 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10624 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10625 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10626 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10627 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 10628 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10629 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10630 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10631 | pring->sli.sli3.next_cmdidx = 0; |
| 10632 | pring->sli.sli3.local_getidx = 0; |
| 10633 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10634 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 10635 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10636 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10637 | pring->flag = 0; |
| 10638 | INIT_LIST_HEAD(&pring->txq); |
| 10639 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10640 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10641 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10642 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10643 | } |
| 10644 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10645 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10646 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 10647 | * @phba: Pointer to HBA context object. |
| 10648 | * |
| 10649 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 10650 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 10651 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 10652 | * command; and completed mailbox command queue. It is caller's responsibility |
| 10653 | * to make sure that the driver is in the proper state to flush the mailbox |
| 10654 | * command sub-system. Namely, the posting of mailbox commands into the |
| 10655 | * pending mailbox command queue from the various clients must be stopped; |
| 10656 | * either the HBA is in a state that it will never works on the outstanding |
| 10657 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 10658 | * mailbox command has been completed. |
| 10659 | **/ |
| 10660 | static void |
| 10661 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 10662 | { |
| 10663 | LIST_HEAD(completions); |
| 10664 | struct lpfc_sli *psli = &phba->sli; |
| 10665 | LPFC_MBOXQ_t *pmb; |
| 10666 | unsigned long iflag; |
| 10667 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10668 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10669 | local_bh_disable(); |
| 10670 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10671 | /* Flush all the mailbox commands in the mbox system */ |
| 10672 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10673 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10674 | /* The pending mailbox command queue */ |
| 10675 | list_splice_init(&phba->sli.mboxq, &completions); |
| 10676 | /* The outstanding active mailbox command */ |
| 10677 | if (psli->mbox_active) { |
| 10678 | list_add_tail(&psli->mbox_active->list, &completions); |
| 10679 | psli->mbox_active = NULL; |
| 10680 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10681 | } |
| 10682 | /* The completed mailbox command queue */ |
| 10683 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 10684 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10685 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10686 | /* Enable softirqs again, done with phba->hbalock */ |
| 10687 | local_bh_enable(); |
| 10688 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10689 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 10690 | while (!list_empty(&completions)) { |
| 10691 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 10692 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10693 | if (pmb->mbox_cmpl) |
| 10694 | pmb->mbox_cmpl(phba, pmb); |
| 10695 | } |
| 10696 | } |
| 10697 | |
| 10698 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10699 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10700 | * @vport: Pointer to virtual port object. |
| 10701 | * |
| 10702 | * lpfc_sli_host_down is called to clean up the resources |
| 10703 | * associated with a vport before destroying virtual |
| 10704 | * port data structures. |
| 10705 | * This function does following operations: |
| 10706 | * - Free discovery resources associated with this virtual |
| 10707 | * port. |
| 10708 | * - Free iocbs associated with this virtual port in |
| 10709 | * the txq. |
| 10710 | * - Send abort for all iocb commands associated with this |
| 10711 | * vport in txcmplq. |
| 10712 | * |
| 10713 | * This function is called with no lock held and always returns 1. |
| 10714 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10715 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10716 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 10717 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10718 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10719 | struct lpfc_hba *phba = vport->phba; |
| 10720 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10721 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10722 | struct lpfc_sli_ring *pring; |
| 10723 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10724 | int i; |
| 10725 | unsigned long flags = 0; |
| 10726 | uint16_t prev_pring_flag; |
| 10727 | |
| 10728 | lpfc_cleanup_discovery_resources(vport); |
| 10729 | |
| 10730 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10731 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10732 | /* |
| 10733 | * Error everything on the txq since these iocbs |
| 10734 | * have not been given to the FW yet. |
| 10735 | * Also issue ABTS for everything on the txcmplq |
| 10736 | */ |
| 10737 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10738 | for (i = 0; i < psli->num_rings; i++) { |
| 10739 | pring = &psli->sli3_ring[i]; |
| 10740 | prev_pring_flag = pring->flag; |
| 10741 | /* Only slow rings */ |
| 10742 | if (pring->ringno == LPFC_ELS_RING) { |
| 10743 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10744 | /* Set the lpfc data pending flag */ |
| 10745 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10746 | } |
| 10747 | list_for_each_entry_safe(iocb, next_iocb, |
| 10748 | &pring->txq, list) { |
| 10749 | if (iocb->vport != vport) |
| 10750 | continue; |
| 10751 | list_move_tail(&iocb->list, &completions); |
| 10752 | } |
| 10753 | list_for_each_entry_safe(iocb, next_iocb, |
| 10754 | &pring->txcmplq, list) { |
| 10755 | if (iocb->vport != vport) |
| 10756 | continue; |
| 10757 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10758 | } |
| 10759 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10760 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10761 | } else { |
| 10762 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10763 | pring = qp->pring; |
| 10764 | if (!pring) |
| 10765 | continue; |
| 10766 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10767 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10768 | /* Set the lpfc data pending flag */ |
| 10769 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10770 | } |
| 10771 | prev_pring_flag = pring->flag; |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 10772 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10773 | list_for_each_entry_safe(iocb, next_iocb, |
| 10774 | &pring->txq, list) { |
| 10775 | if (iocb->vport != vport) |
| 10776 | continue; |
| 10777 | list_move_tail(&iocb->list, &completions); |
| 10778 | } |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 10779 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10780 | list_for_each_entry_safe(iocb, next_iocb, |
| 10781 | &pring->txcmplq, list) { |
| 10782 | if (iocb->vport != vport) |
| 10783 | continue; |
| 10784 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10785 | } |
| 10786 | pring->flag = prev_pring_flag; |
| 10787 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10788 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10789 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10790 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10791 | /* Cancel all the IOCBs from the completions list */ |
| 10792 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10793 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10794 | return 1; |
| 10795 | } |
| 10796 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10797 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10798 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10799 | * @phba: Pointer to HBA context object. |
| 10800 | * |
| 10801 | * This function cleans up all iocb, buffers, mailbox commands |
| 10802 | * while shutting down the HBA. This function is called with no |
| 10803 | * lock held and always returns 1. |
| 10804 | * This function does the following to cleanup driver resources: |
| 10805 | * - Free discovery resources for each virtual port |
| 10806 | * - Cleanup any pending fabric iocbs |
| 10807 | * - Iterate through the iocb txq and free each entry |
| 10808 | * in the list. |
| 10809 | * - Free up any buffer posted to the HBA |
| 10810 | * - Free mailbox commands in the mailbox queue. |
| 10811 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10812 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10813 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10814 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10815 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10816 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10817 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10818 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10819 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10820 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10821 | int i; |
| 10822 | |
| 10823 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10824 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10825 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10826 | lpfc_hba_down_prep(phba); |
| 10827 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10828 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10829 | local_bh_disable(); |
| 10830 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10831 | lpfc_fabric_abort_hba(phba); |
| 10832 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10833 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10834 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10835 | /* |
| 10836 | * Error everything on the txq since these iocbs |
| 10837 | * have not been given to the FW yet. |
| 10838 | */ |
| 10839 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10840 | for (i = 0; i < psli->num_rings; i++) { |
| 10841 | pring = &psli->sli3_ring[i]; |
| 10842 | /* Only slow rings */ |
| 10843 | if (pring->ringno == LPFC_ELS_RING) { |
| 10844 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10845 | /* Set the lpfc data pending flag */ |
| 10846 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10847 | } |
| 10848 | list_splice_init(&pring->txq, &completions); |
| 10849 | } |
| 10850 | } else { |
| 10851 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10852 | pring = qp->pring; |
| 10853 | if (!pring) |
| 10854 | continue; |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 10855 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10856 | list_splice_init(&pring->txq, &completions); |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 10857 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10858 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10859 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10860 | /* Set the lpfc data pending flag */ |
| 10861 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10862 | } |
| 10863 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10864 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10865 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10866 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10867 | /* Cancel all the IOCBs from the completions list */ |
| 10868 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10869 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10870 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10871 | spin_lock_irqsave(&phba->hbalock, flags); |
| 10872 | list_splice_init(&phba->elsbuf, &completions); |
| 10873 | phba->elsbuf_cnt = 0; |
| 10874 | phba->elsbuf_prev_cnt = 0; |
| 10875 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10876 | |
| 10877 | while (!list_empty(&completions)) { |
| 10878 | list_remove_head(&completions, buf_ptr, |
| 10879 | struct lpfc_dmabuf, list); |
| 10880 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 10881 | kfree(buf_ptr); |
| 10882 | } |
| 10883 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10884 | /* Enable softirqs again, done with phba->hbalock */ |
| 10885 | local_bh_enable(); |
| 10886 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10887 | /* Return any active mbox cmds */ |
| 10888 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10889 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10890 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10891 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10892 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10893 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10894 | return 1; |
| 10895 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10896 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10897 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10898 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10899 | * @srcp: Source memory pointer. |
| 10900 | * @destp: Destination memory pointer. |
| 10901 | * @cnt: Number of words required to be copied. |
| 10902 | * |
| 10903 | * This function is used for copying data between driver memory |
| 10904 | * and the SLI memory. This function also changes the endianness |
| 10905 | * of each word if native endianness is different from SLI |
| 10906 | * endianness. This function can be called with or without |
| 10907 | * lock. |
| 10908 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10909 | void |
| 10910 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10911 | { |
| 10912 | uint32_t *src = srcp; |
| 10913 | uint32_t *dest = destp; |
| 10914 | uint32_t ldata; |
| 10915 | int i; |
| 10916 | |
| 10917 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 10918 | ldata = *src; |
| 10919 | ldata = le32_to_cpu(ldata); |
| 10920 | *dest = ldata; |
| 10921 | src++; |
| 10922 | dest++; |
| 10923 | } |
| 10924 | } |
| 10925 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10926 | |
| 10927 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 10928 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 10929 | * @srcp: Source memory pointer. |
| 10930 | * @destp: Destination memory pointer. |
| 10931 | * @cnt: Number of words required to be copied. |
| 10932 | * |
| 10933 | * This function is used for copying data between a data structure |
| 10934 | * with big endian representation to local endianness. |
| 10935 | * This function can be called with or without lock. |
| 10936 | **/ |
| 10937 | void |
| 10938 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10939 | { |
| 10940 | uint32_t *src = srcp; |
| 10941 | uint32_t *dest = destp; |
| 10942 | uint32_t ldata; |
| 10943 | int i; |
| 10944 | |
| 10945 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 10946 | ldata = *src; |
| 10947 | ldata = be32_to_cpu(ldata); |
| 10948 | *dest = ldata; |
| 10949 | src++; |
| 10950 | dest++; |
| 10951 | } |
| 10952 | } |
| 10953 | |
| 10954 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10955 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10956 | * @phba: Pointer to HBA context object. |
| 10957 | * @pring: Pointer to driver SLI ring object. |
| 10958 | * @mp: Pointer to driver buffer object. |
| 10959 | * |
| 10960 | * This function is called with no lock held. |
| 10961 | * It always return zero after adding the buffer to the postbufq |
| 10962 | * buffer list. |
| 10963 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10964 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10965 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10966 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10967 | { |
| 10968 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 10969 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10970 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10971 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10972 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10973 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10974 | return 0; |
| 10975 | } |
| 10976 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10977 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10978 | * 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] | 10979 | * @phba: Pointer to HBA context object. |
| 10980 | * |
| 10981 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 10982 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 10983 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 10984 | * does not conflict with tags of buffer posted for unsolicited events. |
| 10985 | * The function returns the allocated tag. The function is called with |
| 10986 | * no locks held. |
| 10987 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10988 | uint32_t |
| 10989 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 10990 | { |
| 10991 | spin_lock_irq(&phba->hbalock); |
| 10992 | phba->buffer_tag_count++; |
| 10993 | /* |
| 10994 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 10995 | * a tag assigned by HBQ. |
| 10996 | */ |
| 10997 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 10998 | spin_unlock_irq(&phba->hbalock); |
| 10999 | return phba->buffer_tag_count; |
| 11000 | } |
| 11001 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11002 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11003 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11004 | * @phba: Pointer to HBA context object. |
| 11005 | * @pring: Pointer to driver SLI ring object. |
| 11006 | * @tag: Buffer tag. |
| 11007 | * |
| 11008 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 11009 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 11010 | * iocb is posted to the response ring with the tag of the buffer. |
| 11011 | * This function searches the pring->postbufq list using the tag |
| 11012 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 11013 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 11014 | * buffer is returned to the caller else NULL is returned. |
| 11015 | * This function is called with no lock held. |
| 11016 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11017 | struct lpfc_dmabuf * |
| 11018 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11019 | uint32_t tag) |
| 11020 | { |
| 11021 | struct lpfc_dmabuf *mp, *next_mp; |
| 11022 | struct list_head *slp = &pring->postbufq; |
| 11023 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11024 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11025 | spin_lock_irq(&phba->hbalock); |
| 11026 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 11027 | if (mp->buffer_tag == tag) { |
| 11028 | list_del_init(&mp->list); |
| 11029 | pring->postbufq_cnt--; |
| 11030 | spin_unlock_irq(&phba->hbalock); |
| 11031 | return mp; |
| 11032 | } |
| 11033 | } |
| 11034 | |
| 11035 | spin_unlock_irq(&phba->hbalock); |
| 11036 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11037 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11038 | "ring %d Data x%lx x%px x%px x%x\n", |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 11039 | pring->ringno, (unsigned long) tag, |
| 11040 | slp->next, slp->prev, pring->postbufq_cnt); |
| 11041 | |
| 11042 | return NULL; |
| 11043 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11044 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11045 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11046 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11047 | * @phba: Pointer to HBA context object. |
| 11048 | * @pring: Pointer to driver SLI ring object. |
| 11049 | * @phys: DMA address of the buffer. |
| 11050 | * |
| 11051 | * This function searches the buffer list using the dma_address |
| 11052 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 11053 | * corresponding to the dma_address. The function returns the |
| 11054 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 11055 | * This function is called by the ct and els unsolicited event |
| 11056 | * handlers to get the buffer associated with the unsolicited |
| 11057 | * event. |
| 11058 | * |
| 11059 | * This function is called with no lock held. |
| 11060 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11061 | struct lpfc_dmabuf * |
| 11062 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11063 | dma_addr_t phys) |
| 11064 | { |
| 11065 | struct lpfc_dmabuf *mp, *next_mp; |
| 11066 | struct list_head *slp = &pring->postbufq; |
| 11067 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11068 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11069 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11070 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 11071 | if (mp->phys == phys) { |
| 11072 | list_del_init(&mp->list); |
| 11073 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11074 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11075 | return mp; |
| 11076 | } |
| 11077 | } |
| 11078 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11079 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11080 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11081 | "0410 Cannot find virtual addr for mapped buf on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11082 | "ring %d Data x%llx x%px x%px x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11083 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11084 | slp->next, slp->prev, pring->postbufq_cnt); |
| 11085 | return NULL; |
| 11086 | } |
| 11087 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11088 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11089 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11090 | * @phba: Pointer to HBA context object. |
| 11091 | * @cmdiocb: Pointer to driver command iocb object. |
| 11092 | * @rspiocb: Pointer to driver response iocb object. |
| 11093 | * |
| 11094 | * This function is the completion handler for the abort iocbs for |
| 11095 | * ELS commands. This function is called from the ELS ring event |
| 11096 | * handler with no lock held. This function frees memory resources |
| 11097 | * associated with the abort iocb. |
| 11098 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11099 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11100 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11101 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11102 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11103 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11104 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11105 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11106 | |
| 11107 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11108 | |
| 11109 | /* |
| 11110 | * Assume that the port already completed and returned, or |
| 11111 | * will return the iocb. Just Log the message. |
| 11112 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11113 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 11114 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 11115 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11116 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11117 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11118 | if (irsp->ulpCommand == CMD_ABORT_XRI_CX && |
| 11119 | irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 11120 | irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) { |
| 11121 | spin_unlock_irq(&phba->hbalock); |
| 11122 | goto release_iocb; |
| 11123 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11124 | if (abort_iotag != 0 && |
| 11125 | abort_iotag <= phba->sli.last_iotag) |
| 11126 | abort_iocb = |
| 11127 | phba->sli.iocbq_lookup[abort_iotag]; |
| 11128 | } else |
| 11129 | /* For sli4 the abort_tag is the XRI, |
| 11130 | * so the abort routine puts the iotag of the iocb |
| 11131 | * being aborted in the context field of the abort |
| 11132 | * IOCB. |
| 11133 | */ |
| 11134 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11135 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11136 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11137 | "0327 Cannot abort els iocb x%px " |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11138 | "with tag %x context %x, abort status %x, " |
| 11139 | "abort code %x\n", |
| 11140 | abort_iocb, abort_iotag, abort_context, |
| 11141 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11142 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11143 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11144 | } |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11145 | release_iocb: |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11146 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11147 | return; |
| 11148 | } |
| 11149 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11150 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11151 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11152 | * @phba: Pointer to HBA context object. |
| 11153 | * @cmdiocb: Pointer to driver command iocb object. |
| 11154 | * @rspiocb: Pointer to driver response iocb object. |
| 11155 | * |
| 11156 | * The function is called from SLI ring event handler with no |
| 11157 | * lock held. This function is the completion handler for ELS commands |
| 11158 | * which are aborted. The function frees memory resources used for |
| 11159 | * the aborted ELS commands. |
| 11160 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11161 | static void |
| 11162 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11163 | struct lpfc_iocbq *rspiocb) |
| 11164 | { |
| 11165 | IOCB_t *irsp = &rspiocb->iocb; |
| 11166 | |
| 11167 | /* ELS cmd tag <ulpIoTag> completes */ |
| 11168 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11169 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11170 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11171 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11172 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11173 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 11174 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 11175 | else |
| 11176 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11177 | return; |
| 11178 | } |
| 11179 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11180 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11181 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11182 | * @phba: Pointer to HBA context object. |
| 11183 | * @pring: Pointer to driver SLI ring object. |
| 11184 | * @cmdiocb: Pointer to driver command iocb object. |
| 11185 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11186 | * This function issues an abort iocb for the provided command iocb down to |
| 11187 | * the port. Other than the case the outstanding command iocb is an abort |
| 11188 | * request, this function issues abort out unconditionally. This function is |
| 11189 | * called with hbalock held. The function returns 0 when it fails due to |
| 11190 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11191 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11192 | static int |
| 11193 | 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] | 11194 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11195 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11196 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11197 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11198 | IOCB_t *icmd = NULL; |
| 11199 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11200 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11201 | unsigned long iflags; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11202 | struct lpfc_nodelist *ndlp; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11203 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11204 | lockdep_assert_held(&phba->hbalock); |
| 11205 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11206 | /* |
| 11207 | * There are certain command types we don't want to abort. And we |
| 11208 | * don't want to abort commands that are already in the process of |
| 11209 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11210 | */ |
| 11211 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11212 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11213 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11214 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11215 | return 0; |
| 11216 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11217 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11218 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11219 | if (abtsiocbp == NULL) |
| 11220 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11221 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11222 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11223 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11224 | */ |
| 11225 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11226 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11227 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11228 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11229 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11230 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11231 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11232 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11233 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11234 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11235 | if (pring->ringno == LPFC_ELS_RING) { |
| 11236 | ndlp = (struct lpfc_nodelist *)(cmdiocb->context1); |
| 11237 | iabt->un.acxri.abortContextTag = ndlp->nlp_rpi; |
| 11238 | } |
| 11239 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11240 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11241 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11242 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11243 | /* 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] | 11244 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11245 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 11246 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11247 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 11248 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11249 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11250 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11251 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 11252 | else |
| 11253 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 11254 | |
| 11255 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 11256 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 11257 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11258 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 11259 | "0339 Abort xri x%x, original iotag x%x, " |
| 11260 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11261 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11262 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11263 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11264 | |
| 11265 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11266 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 11267 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11268 | return 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11269 | /* Note: both hbalock and ring_lock need to be set here */ |
| 11270 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11271 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11272 | abtsiocbp, 0); |
| 11273 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 11274 | } else { |
| 11275 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11276 | abtsiocbp, 0); |
| 11277 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11278 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11279 | if (retval) |
| 11280 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11281 | |
| 11282 | /* |
| 11283 | * Caller to this routine should check for IOCB_ERROR |
| 11284 | * and handle it properly. This routine no longer removes |
| 11285 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 11286 | */ |
| 11287 | return retval; |
| 11288 | } |
| 11289 | |
| 11290 | /** |
| 11291 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 11292 | * @phba: Pointer to HBA context object. |
| 11293 | * @pring: Pointer to driver SLI ring object. |
| 11294 | * @cmdiocb: Pointer to driver command iocb object. |
| 11295 | * |
| 11296 | * This function issues an abort iocb for the provided command iocb. In case |
| 11297 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 11298 | * ring. Instead, the callback function shall be changed to those commands |
| 11299 | * so that nothing happens when them finishes. This function is called with |
| 11300 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 11301 | * request. |
| 11302 | **/ |
| 11303 | int |
| 11304 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11305 | struct lpfc_iocbq *cmdiocb) |
| 11306 | { |
| 11307 | struct lpfc_vport *vport = cmdiocb->vport; |
| 11308 | int retval = IOCB_ERROR; |
| 11309 | IOCB_t *icmd = NULL; |
| 11310 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11311 | lockdep_assert_held(&phba->hbalock); |
| 11312 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11313 | /* |
| 11314 | * There are certain command types we don't want to abort. And we |
| 11315 | * don't want to abort commands that are already in the process of |
| 11316 | * being aborted. |
| 11317 | */ |
| 11318 | icmd = &cmdiocb->iocb; |
| 11319 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 11320 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11321 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 11322 | return 0; |
| 11323 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 11324 | if (!pring) { |
| 11325 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11326 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11327 | else |
| 11328 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11329 | goto abort_iotag_exit; |
| 11330 | } |
| 11331 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11332 | /* |
| 11333 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 11334 | * the callback so that nothing happens when it finishes. |
| 11335 | */ |
| 11336 | if ((vport->load_flag & FC_UNLOADING) && |
| 11337 | (pring->ringno == LPFC_ELS_RING)) { |
| 11338 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11339 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11340 | else |
| 11341 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11342 | goto abort_iotag_exit; |
| 11343 | } |
| 11344 | |
| 11345 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 11346 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 11347 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11348 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11349 | /* |
| 11350 | * Caller to this routine should check for IOCB_ERROR |
| 11351 | * and handle it properly. This routine no longer removes |
| 11352 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11353 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11354 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11355 | } |
| 11356 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11357 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11358 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 11359 | * @phba: pointer to lpfc HBA data structure. |
| 11360 | * |
| 11361 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 11362 | **/ |
| 11363 | void |
| 11364 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 11365 | { |
| 11366 | struct lpfc_sli *psli = &phba->sli; |
| 11367 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11368 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11369 | int i; |
| 11370 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11371 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11372 | for (i = 0; i < psli->num_rings; i++) { |
| 11373 | pring = &psli->sli3_ring[i]; |
| 11374 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 11375 | } |
| 11376 | return; |
| 11377 | } |
| 11378 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11379 | pring = qp->pring; |
| 11380 | if (!pring) |
| 11381 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 11382 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11383 | } |
| 11384 | } |
| 11385 | |
| 11386 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11387 | * 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] | 11388 | * @iocbq: Pointer to driver iocb object. |
| 11389 | * @vport: Pointer to driver virtual port object. |
| 11390 | * @tgt_id: SCSI ID of the target. |
| 11391 | * @lun_id: LUN ID of the scsi device. |
| 11392 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 11393 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11394 | * 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] | 11395 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 11396 | * 0 if the filtering criteria is met for the given iocb and will return |
| 11397 | * 1 if the filtering criteria is not met. |
| 11398 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 11399 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 11400 | * lun_id parameter. |
| 11401 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 11402 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 11403 | * parameters. |
| 11404 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 11405 | * given iocb is for the SCSI host associated with the given vport. |
| 11406 | * This function is called with no locks held. |
| 11407 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11408 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11409 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 11410 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11411 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11412 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11413 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11414 | int rc = 1; |
| 11415 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11416 | if (iocbq->vport != vport) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11417 | return rc; |
| 11418 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11419 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 11420 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11421 | return rc; |
| 11422 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11423 | 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] | 11424 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11425 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11426 | return rc; |
| 11427 | |
| 11428 | switch (ctx_cmd) { |
| 11429 | case LPFC_CTX_LUN: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11430 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11431 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 11432 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11433 | rc = 0; |
| 11434 | break; |
| 11435 | case LPFC_CTX_TGT: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11436 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11437 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11438 | rc = 0; |
| 11439 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11440 | case LPFC_CTX_HOST: |
| 11441 | rc = 0; |
| 11442 | break; |
| 11443 | default: |
| 11444 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 11445 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11446 | break; |
| 11447 | } |
| 11448 | |
| 11449 | return rc; |
| 11450 | } |
| 11451 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11452 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11453 | * 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] | 11454 | * @vport: Pointer to virtual port. |
| 11455 | * @tgt_id: SCSI ID of the target. |
| 11456 | * @lun_id: LUN ID of the scsi device. |
| 11457 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11458 | * |
| 11459 | * This function returns number of FCP commands pending for the vport. |
| 11460 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 11461 | * commands pending on the vport associated with SCSI device specified |
| 11462 | * by tgt_id and lun_id parameters. |
| 11463 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 11464 | * commands pending on the vport associated with SCSI target specified |
| 11465 | * by tgt_id parameter. |
| 11466 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 11467 | * commands pending on the vport. |
| 11468 | * This function returns the number of iocbs which satisfy the filter. |
| 11469 | * This function is called without any lock held. |
| 11470 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11471 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11472 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 11473 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11474 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11475 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11476 | struct lpfc_iocbq *iocbq; |
| 11477 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11478 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11479 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11480 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 11481 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11482 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11483 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 11484 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11485 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11486 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11487 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11488 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11489 | return sum; |
| 11490 | } |
| 11491 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11492 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11493 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11494 | * @phba: Pointer to HBA context object |
| 11495 | * @cmdiocb: Pointer to command iocb object. |
| 11496 | * @rspiocb: Pointer to response iocb object. |
| 11497 | * |
| 11498 | * This function is called when an aborted FCP iocb completes. This |
| 11499 | * function is called by the ring event handler with no lock held. |
| 11500 | * This function frees the iocb. |
| 11501 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11502 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11503 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11504 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11505 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11506 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 11507 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11508 | "original iotag x%x, abort cmd iotag x%x " |
| 11509 | "status 0x%x, reason 0x%x\n", |
| 11510 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 11511 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 11512 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 11513 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11514 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11515 | return; |
| 11516 | } |
| 11517 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11518 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11519 | * 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] | 11520 | * @vport: Pointer to virtual port. |
| 11521 | * @pring: Pointer to driver SLI ring object. |
| 11522 | * @tgt_id: SCSI ID of the target. |
| 11523 | * @lun_id: LUN ID of the scsi device. |
| 11524 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11525 | * |
| 11526 | * This function sends an abort command for every SCSI command |
| 11527 | * associated with the given virtual port pending on the ring |
| 11528 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11529 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11530 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11531 | * parameters |
| 11532 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11533 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11534 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11535 | * FCP iocbs associated with virtual port. |
| 11536 | * This function returns number of iocbs it failed to abort. |
| 11537 | * This function is called with no locks held. |
| 11538 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11539 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11540 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11541 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11542 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11543 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11544 | struct lpfc_iocbq *iocbq; |
| 11545 | struct lpfc_iocbq *abtsiocb; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11546 | struct lpfc_sli_ring *pring_s4; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11547 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11548 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11549 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11550 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11551 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11552 | if (phba->hba_flag & HBA_IOQ_FLUSH) |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11553 | return errcnt; |
| 11554 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11555 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11556 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11557 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11558 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11559 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11560 | continue; |
| 11561 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11562 | /* |
| 11563 | * If the iocbq is already being aborted, don't take a second |
| 11564 | * action, but do count it. |
| 11565 | */ |
| 11566 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11567 | continue; |
| 11568 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11569 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11570 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11571 | if (abtsiocb == NULL) { |
| 11572 | errcnt++; |
| 11573 | continue; |
| 11574 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11575 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11576 | /* indicate the IO is being aborted by the driver. */ |
| 11577 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11578 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11579 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11580 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11581 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11582 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11583 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 11584 | else |
| 11585 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11586 | abtsiocb->iocb.ulpLe = 1; |
| 11587 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11588 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11589 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11590 | /* 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] | 11591 | abtsiocb->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11592 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11593 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11594 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11595 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11596 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11597 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11598 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11599 | else |
| 11600 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11601 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11602 | /* Setup callback routine and issue the command. */ |
| 11603 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11604 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11605 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11606 | if (!pring_s4) |
| 11607 | continue; |
| 11608 | ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11609 | abtsiocb, 0); |
| 11610 | } else |
| 11611 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11612 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11613 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11614 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11615 | errcnt++; |
| 11616 | continue; |
| 11617 | } |
| 11618 | } |
| 11619 | |
| 11620 | return errcnt; |
| 11621 | } |
| 11622 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11623 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11624 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 11625 | * @vport: Pointer to virtual port. |
| 11626 | * @pring: Pointer to driver SLI ring object. |
| 11627 | * @tgt_id: SCSI ID of the target. |
| 11628 | * @lun_id: LUN ID of the scsi device. |
| 11629 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11630 | * |
| 11631 | * This function sends an abort command for every SCSI command |
| 11632 | * associated with the given virtual port pending on the ring |
| 11633 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11634 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11635 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11636 | * parameters |
| 11637 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11638 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11639 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11640 | * FCP iocbs associated with virtual port. |
| 11641 | * This function returns number of iocbs it aborted . |
| 11642 | * This function is called with no locks held right after a taskmgmt |
| 11643 | * command is sent. |
| 11644 | **/ |
| 11645 | int |
| 11646 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11647 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 11648 | { |
| 11649 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11650 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11651 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11652 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11653 | struct lpfc_iocbq *iocbq; |
| 11654 | IOCB_t *icmd; |
| 11655 | int sum, i, ret_val; |
| 11656 | unsigned long iflags; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11657 | struct lpfc_sli_ring *pring_s4 = NULL; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11658 | |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11659 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11660 | |
| 11661 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11662 | if (phba->hba_flag & HBA_IOQ_FLUSH) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11663 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11664 | return 0; |
| 11665 | } |
| 11666 | sum = 0; |
| 11667 | |
| 11668 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11669 | iocbq = phba->sli.iocbq_lookup[i]; |
| 11670 | |
| 11671 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 11672 | cmd) != 0) |
| 11673 | continue; |
| 11674 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11675 | /* Guard against IO completion being called at same time */ |
| 11676 | lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq); |
| 11677 | spin_lock(&lpfc_cmd->buf_lock); |
| 11678 | |
| 11679 | if (!lpfc_cmd->pCmd) { |
| 11680 | spin_unlock(&lpfc_cmd->buf_lock); |
| 11681 | continue; |
| 11682 | } |
| 11683 | |
| 11684 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11685 | pring_s4 = |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11686 | phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11687 | if (!pring_s4) { |
| 11688 | spin_unlock(&lpfc_cmd->buf_lock); |
| 11689 | continue; |
| 11690 | } |
| 11691 | /* Note: both hbalock and ring_lock must be set here */ |
| 11692 | spin_lock(&pring_s4->ring_lock); |
| 11693 | } |
| 11694 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11695 | /* |
| 11696 | * If the iocbq is already being aborted, don't take a second |
| 11697 | * action, but do count it. |
| 11698 | */ |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11699 | if ((iocbq->iocb_flag & LPFC_DRIVER_ABORTED) || |
| 11700 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
| 11701 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11702 | spin_unlock(&pring_s4->ring_lock); |
| 11703 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11704 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11705 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11706 | |
| 11707 | /* issue ABTS for this IOCB based on iotag */ |
| 11708 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11709 | if (!abtsiocbq) { |
| 11710 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11711 | spin_unlock(&pring_s4->ring_lock); |
| 11712 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11713 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11714 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11715 | |
| 11716 | icmd = &iocbq->iocb; |
| 11717 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11718 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 11719 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11720 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 11721 | iocbq->sli4_xritag; |
| 11722 | else |
| 11723 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 11724 | abtsiocbq->iocb.ulpLe = 1; |
| 11725 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 11726 | abtsiocbq->vport = vport; |
| 11727 | |
| 11728 | /* 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] | 11729 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11730 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11731 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11732 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11733 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11734 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11735 | ndlp = lpfc_cmd->rdata->pnode; |
| 11736 | |
| 11737 | if (lpfc_is_link_up(phba) && |
| 11738 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11739 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11740 | else |
| 11741 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11742 | |
| 11743 | /* Setup callback routine and issue the command. */ |
| 11744 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 11745 | |
| 11746 | /* |
| 11747 | * Indicate the IO is being aborted by the driver and set |
| 11748 | * the caller's flag into the aborted IO. |
| 11749 | */ |
| 11750 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11751 | |
| 11752 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11753 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11754 | abtsiocbq, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11755 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11756 | } else { |
| 11757 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11758 | abtsiocbq, 0); |
| 11759 | } |
| 11760 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11761 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11762 | |
| 11763 | if (ret_val == IOCB_ERROR) |
| 11764 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 11765 | else |
| 11766 | sum++; |
| 11767 | } |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11768 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11769 | return sum; |
| 11770 | } |
| 11771 | |
| 11772 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11773 | * 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] | 11774 | * @phba: Pointer to HBA context object. |
| 11775 | * @cmdiocbq: Pointer to command iocb. |
| 11776 | * @rspiocbq: Pointer to response iocb. |
| 11777 | * |
| 11778 | * This function is the completion handler for iocbs issued using |
| 11779 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 11780 | * ring event handler function without any lock held. This function |
| 11781 | * can be called from both worker thread context and interrupt |
| 11782 | * context. This function also can be called from other thread which |
| 11783 | * cleans up the SLI layer objects. |
| 11784 | * This function copy the contents of the response iocb to the |
| 11785 | * response iocb memory object provided by the caller of |
| 11786 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 11787 | * sleeps for the iocb completion. |
| 11788 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11789 | static void |
| 11790 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 11791 | struct lpfc_iocbq *cmdiocbq, |
| 11792 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11793 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11794 | wait_queue_head_t *pdone_q; |
| 11795 | unsigned long iflags; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11796 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11797 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11798 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11799 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 11800 | |
| 11801 | /* |
| 11802 | * A time out has occurred for the iocb. If a time out |
| 11803 | * completion handler has been supplied, call it. Otherwise, |
| 11804 | * just free the iocbq. |
| 11805 | */ |
| 11806 | |
| 11807 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11808 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 11809 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 11810 | if (cmdiocbq->iocb_cmpl) |
| 11811 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 11812 | else |
| 11813 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 11814 | return; |
| 11815 | } |
| 11816 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11817 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 11818 | if (cmdiocbq->context2 && rspiocbq) |
| 11819 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 11820 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 11821 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11822 | /* Set the exchange busy flag for task management commands */ |
| 11823 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 11824 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11825 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf, |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11826 | cur_iocbq); |
James Smart | 324e1c4 | 2019-10-18 14:18:21 -0700 | [diff] [blame] | 11827 | if (rspiocbq && (rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY)) |
| 11828 | lpfc_cmd->flags |= LPFC_SBUF_XBUSY; |
| 11829 | else |
| 11830 | lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11831 | } |
| 11832 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11833 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11834 | if (pdone_q) |
| 11835 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11836 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11837 | return; |
| 11838 | } |
| 11839 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11840 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11841 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 11842 | * @phba: Pointer to HBA context object.. |
| 11843 | * @piocbq: Pointer to command iocb. |
| 11844 | * @flag: Flag to test. |
| 11845 | * |
| 11846 | * This routine grabs the hbalock and then test the iocb_flag to |
| 11847 | * see if the passed in flag is set. |
| 11848 | * Returns: |
| 11849 | * 1 if flag is set. |
| 11850 | * 0 if flag is not set. |
| 11851 | **/ |
| 11852 | static int |
| 11853 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 11854 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 11855 | { |
| 11856 | unsigned long iflags; |
| 11857 | int ret; |
| 11858 | |
| 11859 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11860 | ret = piocbq->iocb_flag & flag; |
| 11861 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11862 | return ret; |
| 11863 | |
| 11864 | } |
| 11865 | |
| 11866 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11867 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11868 | * @phba: Pointer to HBA context object.. |
| 11869 | * @pring: Pointer to sli ring. |
| 11870 | * @piocb: Pointer to command iocb. |
| 11871 | * @prspiocbq: Pointer to response iocb. |
| 11872 | * @timeout: Timeout in number of seconds. |
| 11873 | * |
| 11874 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11875 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 11876 | * to handle iocbs which time out. If the field is NULL, the |
| 11877 | * function shall free the iocbq structure. If more clean up is |
| 11878 | * needed, the caller is expected to provide a completion function |
| 11879 | * that will provide the needed clean up. If the iocb command is |
| 11880 | * not completed within timeout seconds, the function will either |
| 11881 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 11882 | * completion function set in the iocb_cmpl field and then return |
| 11883 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 11884 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11885 | * The function waits for the iocb completion using an |
| 11886 | * non-interruptible wait. |
| 11887 | * This function will sleep while waiting for iocb completion. |
| 11888 | * So, this function should not be called from any context which |
| 11889 | * does not allow sleeping. Due to the same reason, this function |
| 11890 | * cannot be called with interrupt disabled. |
| 11891 | * This function assumes that the iocb completions occur while |
| 11892 | * this function sleep. So, this function cannot be called from |
| 11893 | * the thread which process iocb completion for this ring. |
| 11894 | * This function clears the iocb_flag of the iocb object before |
| 11895 | * issuing the iocb and the iocb completion handler sets this |
| 11896 | * flag and wakes this thread when the iocb completes. |
| 11897 | * The contents of the response iocb will be copied to prspiocbq |
| 11898 | * by the completion handler when the command completes. |
| 11899 | * This function returns IOCB_SUCCESS when success. |
| 11900 | * This function is called with no lock held. |
| 11901 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11902 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11903 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11904 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11905 | struct lpfc_iocbq *piocb, |
| 11906 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11907 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11908 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 11909 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11910 | long timeleft, timeout_req = 0; |
| 11911 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11912 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11913 | struct lpfc_iocbq *iocb; |
| 11914 | int txq_cnt = 0; |
| 11915 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11916 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11917 | unsigned long iflags; |
| 11918 | bool iocb_completed = true; |
| 11919 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11920 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 11921 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 11922 | else |
| 11923 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11924 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11925 | * If the caller has provided a response iocbq buffer, then context2 |
| 11926 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11927 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11928 | if (prspiocbq) { |
| 11929 | if (piocb->context2) |
| 11930 | return IOCB_ERROR; |
| 11931 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11932 | } |
| 11933 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11934 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11935 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 11936 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11937 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11938 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11939 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11940 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11941 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11942 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 11943 | writel(creg_val, phba->HCregaddr); |
| 11944 | readl(phba->HCregaddr); /* flush */ |
| 11945 | } |
| 11946 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11947 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 11948 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11949 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 11950 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11951 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11952 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11953 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11954 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11955 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11956 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11957 | /* |
| 11958 | * IOCB timed out. Inform the wake iocb wait |
| 11959 | * completion function and set local status |
| 11960 | */ |
| 11961 | |
| 11962 | iocb_completed = false; |
| 11963 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 11964 | } |
| 11965 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11966 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11967 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11968 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 11969 | /* Note: we are not indicating if the IOCB has a success |
| 11970 | * status or not - that's for the caller to check. |
| 11971 | * IOCB_SUCCESS means just that the command was sent and |
| 11972 | * completed. Not that it completed successfully. |
| 11973 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11974 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11975 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11976 | "0338 IOCB wait timeout error - no " |
| 11977 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11978 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11979 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11980 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11981 | "0330 IOCB wake NOT set, " |
| 11982 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11983 | timeout, (timeleft / jiffies)); |
| 11984 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11985 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11986 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11987 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 11988 | list_for_each_entry(iocb, &pring->txq, list) { |
| 11989 | txq_cnt++; |
| 11990 | } |
| 11991 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 11992 | txcmplq_cnt++; |
| 11993 | } |
| 11994 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11995 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 11996 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 11997 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11998 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11999 | } else { |
| 12000 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12001 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12002 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12003 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12004 | } |
| 12005 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12006 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12007 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 12008 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12009 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 12010 | writel(creg_val, phba->HCregaddr); |
| 12011 | readl(phba->HCregaddr); /* flush */ |
| 12012 | } |
| 12013 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12014 | if (prspiocbq) |
| 12015 | piocb->context2 = NULL; |
| 12016 | |
| 12017 | piocb->context_un.wait_queue = NULL; |
| 12018 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12019 | return retval; |
| 12020 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12021 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12022 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12023 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12024 | * @phba: Pointer to HBA context object. |
| 12025 | * @pmboxq: Pointer to driver mailbox object. |
| 12026 | * @timeout: Timeout in number of seconds. |
| 12027 | * |
| 12028 | * This function issues the mailbox to firmware and waits for the |
| 12029 | * mailbox command to complete. If the mailbox command is not |
| 12030 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 12031 | * The function waits for the mailbox completion using an |
| 12032 | * interruptible wait. If the thread is woken up due to a |
| 12033 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 12034 | * should not free the mailbox resources, if this function returns |
| 12035 | * MBX_TIMEOUT. |
| 12036 | * This function will sleep while waiting for mailbox completion. |
| 12037 | * So, this function should not be called from any context which |
| 12038 | * does not allow sleeping. Due to the same reason, this function |
| 12039 | * cannot be called with interrupt disabled. |
| 12040 | * This function assumes that the mailbox completion occurs while |
| 12041 | * this function sleep. So, this function cannot be called from |
| 12042 | * the worker thread which processes mailbox completion. |
| 12043 | * This function is called in the context of HBA management |
| 12044 | * applications. |
| 12045 | * This function returns MBX_SUCCESS when successful. |
| 12046 | * This function is called with no lock held. |
| 12047 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12048 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12049 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12050 | uint32_t timeout) |
| 12051 | { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12052 | struct completion mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12053 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12054 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12055 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 12056 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12057 | /* setup wake call as IOCB callback */ |
| 12058 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12059 | |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12060 | /* setup context3 field to pass wait_queue pointer to wake function */ |
| 12061 | init_completion(&mbox_done); |
| 12062 | pmboxq->context3 = &mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12063 | /* now issue the command */ |
| 12064 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12065 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12066 | wait_for_completion_timeout(&mbox_done, |
| 12067 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12068 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12069 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12070 | pmboxq->context3 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12071 | /* |
| 12072 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 12073 | * else do not free the resources. |
| 12074 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12075 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12076 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12077 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12078 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12079 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12080 | } |
| 12081 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12082 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12083 | return retval; |
| 12084 | } |
| 12085 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12086 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12087 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12088 | * @phba: Pointer to HBA context. |
| 12089 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12090 | * This function is called to shutdown the driver's mailbox sub-system. |
| 12091 | * It first marks the mailbox sub-system is in a block state to prevent |
| 12092 | * the asynchronous mailbox command from issued off the pending mailbox |
| 12093 | * command queue. If the mailbox command sub-system shutdown is due to |
| 12094 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 12095 | * the mailbox sub-system flush routine to forcefully bring down the |
| 12096 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 12097 | * as with offline or HBA function reset), this routine will wait for the |
| 12098 | * outstanding mailbox command to complete before invoking the mailbox |
| 12099 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12100 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12101 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12102 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12103 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12104 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12105 | unsigned long timeout; |
| 12106 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12107 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 12108 | /* delay 100ms for port state */ |
| 12109 | msleep(100); |
| 12110 | lpfc_sli_mbox_sys_flush(phba); |
| 12111 | return; |
| 12112 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12113 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12114 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12115 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 12116 | local_bh_disable(); |
| 12117 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12118 | spin_lock_irq(&phba->hbalock); |
| 12119 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12120 | |
| 12121 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12122 | /* Determine how long we might wait for the active mailbox |
| 12123 | * command to be gracefully completed by firmware. |
| 12124 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12125 | if (phba->sli.mbox_active) |
| 12126 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 12127 | phba->sli.mbox_active) * |
| 12128 | 1000) + jiffies; |
| 12129 | spin_unlock_irq(&phba->hbalock); |
| 12130 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12131 | /* Enable softirqs again, done with phba->hbalock */ |
| 12132 | local_bh_enable(); |
| 12133 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12134 | while (phba->sli.mbox_active) { |
| 12135 | /* Check active mailbox complete status every 2ms */ |
| 12136 | msleep(2); |
| 12137 | if (time_after(jiffies, timeout)) |
| 12138 | /* Timeout, let the mailbox flush routine to |
| 12139 | * forcefully release active mailbox command |
| 12140 | */ |
| 12141 | break; |
| 12142 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12143 | } else { |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12144 | spin_unlock_irq(&phba->hbalock); |
| 12145 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12146 | /* Enable softirqs again, done with phba->hbalock */ |
| 12147 | local_bh_enable(); |
| 12148 | } |
| 12149 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12150 | lpfc_sli_mbox_sys_flush(phba); |
| 12151 | } |
| 12152 | |
| 12153 | /** |
| 12154 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 12155 | * @phba: Pointer to HBA context. |
| 12156 | * |
| 12157 | * This function is called to read the SLI3 device error attention registers |
| 12158 | * for possible error attention events. The caller must hold the hostlock |
| 12159 | * with spin_lock_irq(). |
| 12160 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12161 | * 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] | 12162 | * Register and returns 0 otherwise. |
| 12163 | **/ |
| 12164 | static int |
| 12165 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 12166 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 12167 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12168 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12169 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12170 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12171 | goto unplug_err; |
| 12172 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12173 | if (ha_copy & HA_ERATT) { |
| 12174 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12175 | if (lpfc_sli_read_hs(phba)) |
| 12176 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12177 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12178 | /* Check if there is a deferred error condition is active */ |
| 12179 | if ((HS_FFER1 & phba->work_hs) && |
| 12180 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12181 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12182 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12183 | /* Clear all interrupt enable conditions */ |
| 12184 | writel(0, phba->HCregaddr); |
| 12185 | readl(phba->HCregaddr); |
| 12186 | } |
| 12187 | |
| 12188 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12189 | phba->work_ha |= HA_ERATT; |
| 12190 | /* Indicate polling handles this ERATT */ |
| 12191 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12192 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12193 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12194 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12195 | |
| 12196 | unplug_err: |
| 12197 | /* Set the driver HS work bitmap */ |
| 12198 | phba->work_hs |= UNPLUG_ERR; |
| 12199 | /* Set the driver HA work bitmap */ |
| 12200 | phba->work_ha |= HA_ERATT; |
| 12201 | /* Indicate polling handles this ERATT */ |
| 12202 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12203 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12204 | } |
| 12205 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12206 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12207 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 12208 | * @phba: Pointer to HBA context. |
| 12209 | * |
| 12210 | * This function is called to read the SLI4 device error attention registers |
| 12211 | * for possible error attention events. The caller must hold the hostlock |
| 12212 | * with spin_lock_irq(). |
| 12213 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12214 | * 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] | 12215 | * Register and returns 0 otherwise. |
| 12216 | **/ |
| 12217 | static int |
| 12218 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 12219 | { |
| 12220 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12221 | uint32_t if_type, portsmphr; |
| 12222 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12223 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12224 | /* |
| 12225 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12226 | * registers for error attention. This can be changed later. |
| 12227 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12228 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 12229 | switch (if_type) { |
| 12230 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12231 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 12232 | &uerr_sta_lo) || |
| 12233 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 12234 | &uerr_sta_hi)) { |
| 12235 | phba->work_hs |= UNPLUG_ERR; |
| 12236 | phba->work_ha |= HA_ERATT; |
| 12237 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12238 | return 1; |
| 12239 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12240 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 12241 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 12242 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12243 | "1423 HBA Unrecoverable error: " |
| 12244 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 12245 | "ue_mask_lo_reg=0x%x, " |
| 12246 | "ue_mask_hi_reg=0x%x\n", |
| 12247 | uerr_sta_lo, uerr_sta_hi, |
| 12248 | phba->sli4_hba.ue_mask_lo, |
| 12249 | phba->sli4_hba.ue_mask_hi); |
| 12250 | phba->work_status[0] = uerr_sta_lo; |
| 12251 | phba->work_status[1] = uerr_sta_hi; |
| 12252 | phba->work_ha |= HA_ERATT; |
| 12253 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12254 | return 1; |
| 12255 | } |
| 12256 | break; |
| 12257 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 12258 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12259 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 12260 | &portstat_reg.word0) || |
| 12261 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 12262 | &portsmphr)){ |
| 12263 | phba->work_hs |= UNPLUG_ERR; |
| 12264 | phba->work_ha |= HA_ERATT; |
| 12265 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12266 | return 1; |
| 12267 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12268 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 12269 | phba->work_status[0] = |
| 12270 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 12271 | phba->work_status[1] = |
| 12272 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 12273 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12274 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12275 | "port status reg 0x%x, " |
| 12276 | "port smphr reg 0x%x, " |
| 12277 | "error 1=0x%x, error 2=0x%x\n", |
| 12278 | portstat_reg.word0, |
| 12279 | portsmphr, |
| 12280 | phba->work_status[0], |
| 12281 | phba->work_status[1]); |
| 12282 | phba->work_ha |= HA_ERATT; |
| 12283 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12284 | return 1; |
| 12285 | } |
| 12286 | break; |
| 12287 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 12288 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12289 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12290 | "2886 HBA Error Attention on unsupported " |
| 12291 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12292 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12293 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12294 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12295 | return 0; |
| 12296 | } |
| 12297 | |
| 12298 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12299 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12300 | * @phba: Pointer to HBA context. |
| 12301 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12302 | * 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] | 12303 | * error attention register bit for error attention events. |
| 12304 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12305 | * 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] | 12306 | * Register and returns 0 otherwise. |
| 12307 | **/ |
| 12308 | int |
| 12309 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 12310 | { |
| 12311 | uint32_t ha_copy; |
| 12312 | |
| 12313 | /* If somebody is waiting to handle an eratt, don't process it |
| 12314 | * here. The brdkill function will do this. |
| 12315 | */ |
| 12316 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12317 | return 0; |
| 12318 | |
| 12319 | /* Check if interrupt handler handles this ERATT */ |
| 12320 | spin_lock_irq(&phba->hbalock); |
| 12321 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 12322 | /* Interrupt handler has handled ERATT */ |
| 12323 | spin_unlock_irq(&phba->hbalock); |
| 12324 | return 0; |
| 12325 | } |
| 12326 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12327 | /* |
| 12328 | * If there is deferred error attention, do not check for error |
| 12329 | * attention |
| 12330 | */ |
| 12331 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 12332 | spin_unlock_irq(&phba->hbalock); |
| 12333 | return 0; |
| 12334 | } |
| 12335 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12336 | /* If PCI channel is offline, don't process it */ |
| 12337 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12338 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12339 | return 0; |
| 12340 | } |
| 12341 | |
| 12342 | switch (phba->sli_rev) { |
| 12343 | case LPFC_SLI_REV2: |
| 12344 | case LPFC_SLI_REV3: |
| 12345 | /* Read chip Host Attention (HA) register */ |
| 12346 | ha_copy = lpfc_sli_eratt_read(phba); |
| 12347 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12348 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12349 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12350 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 12351 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12352 | default: |
| 12353 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12354 | "0299 Invalid SLI revision (%d)\n", |
| 12355 | phba->sli_rev); |
| 12356 | ha_copy = 0; |
| 12357 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12358 | } |
| 12359 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12360 | |
| 12361 | return ha_copy; |
| 12362 | } |
| 12363 | |
| 12364 | /** |
| 12365 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 12366 | * @phba: Pointer to HBA context. |
| 12367 | * |
| 12368 | * This inline routine checks whether a device or its PCI slot is in a state |
| 12369 | * that the interrupt should be handled. |
| 12370 | * |
| 12371 | * This function returns 0 if the device or the PCI slot is in a state that |
| 12372 | * interrupt should be handled, otherwise -EIO. |
| 12373 | */ |
| 12374 | static inline int |
| 12375 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 12376 | { |
| 12377 | /* If the pci channel is offline, ignore all the interrupts */ |
| 12378 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 12379 | return -EIO; |
| 12380 | |
| 12381 | /* Update device level interrupt statistics */ |
| 12382 | phba->sli.slistat.sli_intr++; |
| 12383 | |
| 12384 | /* Ignore all interrupts during initialization. */ |
| 12385 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 12386 | return -EIO; |
| 12387 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12388 | return 0; |
| 12389 | } |
| 12390 | |
| 12391 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12392 | * 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] | 12393 | * @irq: Interrupt number. |
| 12394 | * @dev_id: The device context pointer. |
| 12395 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12396 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12397 | * service routine when device with SLI-3 interface spec is enabled with |
| 12398 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 12399 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 12400 | * interrupt mode, this function is called as part of the device-level |
| 12401 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 12402 | * is undergoing initialization, the interrupt handler will not process |
| 12403 | * the interrupt. The link attention and ELS ring attention events are |
| 12404 | * handled by the worker thread. The interrupt handler signals the worker |
| 12405 | * thread and returns for these events. This function is called without |
| 12406 | * 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] | 12407 | * structures. |
| 12408 | * |
| 12409 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12410 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12411 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12412 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12413 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12414 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12415 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12416 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12417 | uint32_t work_ha_copy; |
| 12418 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12419 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12420 | uint32_t control; |
| 12421 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12422 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12423 | struct lpfc_vport *vport; |
| 12424 | struct lpfc_nodelist *ndlp; |
| 12425 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12426 | LPFC_MBOXQ_t *pmb; |
| 12427 | int rc; |
| 12428 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12429 | /* |
| 12430 | * Get the driver's phba structure from the dev_id and |
| 12431 | * assume the HBA is not interrupting. |
| 12432 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12433 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12434 | |
| 12435 | if (unlikely(!phba)) |
| 12436 | return IRQ_NONE; |
| 12437 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12438 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12439 | * Stuff needs to be attented to when this function is invoked as an |
| 12440 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12441 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12442 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12443 | /* Check device state for handling interrupt */ |
| 12444 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12445 | return IRQ_NONE; |
| 12446 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12447 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12448 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12449 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12450 | /* If somebody is waiting to handle an eratt don't process it |
| 12451 | * here. The brdkill function will do this. |
| 12452 | */ |
| 12453 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12454 | ha_copy &= ~HA_ERATT; |
| 12455 | /* Check the need for handling ERATT in interrupt handler */ |
| 12456 | if (ha_copy & HA_ERATT) { |
| 12457 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12458 | /* ERATT polling has handled ERATT */ |
| 12459 | ha_copy &= ~HA_ERATT; |
| 12460 | else |
| 12461 | /* Indicate interrupt handler handles ERATT */ |
| 12462 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12463 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12464 | |
| 12465 | /* |
| 12466 | * If there is deferred error attention, do not check for any |
| 12467 | * interrupt. |
| 12468 | */ |
| 12469 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12470 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12471 | return IRQ_NONE; |
| 12472 | } |
| 12473 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12474 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12475 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 12476 | goto unplug_error; |
| 12477 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12478 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 12479 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12480 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12481 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 12482 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12483 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12484 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12485 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12486 | } else |
| 12487 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12488 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12489 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 12490 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12491 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12492 | if (work_ha_copy & HA_LATT) { |
| 12493 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 12494 | /* |
| 12495 | * Turn off Link Attention interrupts |
| 12496 | * until CLEAR_LA done |
| 12497 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12498 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12499 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12500 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12501 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12502 | control &= ~HC_LAINT_ENA; |
| 12503 | writel(control, phba->HCregaddr); |
| 12504 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12505 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12506 | } |
| 12507 | else |
| 12508 | work_ha_copy &= ~HA_LATT; |
| 12509 | } |
| 12510 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12511 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12512 | /* |
| 12513 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 12514 | * the only slow ring. |
| 12515 | */ |
| 12516 | status = (work_ha_copy & |
| 12517 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12518 | status >>= (4*LPFC_ELS_RING); |
| 12519 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12520 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12521 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12522 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12523 | |
| 12524 | lpfc_debugfs_slow_ring_trc(phba, |
| 12525 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 12526 | control, status, |
| 12527 | (uint32_t)phba->sli.slistat.sli_intr); |
| 12528 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12529 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12530 | lpfc_debugfs_slow_ring_trc(phba, |
| 12531 | "ISR Disable ring:" |
| 12532 | "pwork:x%x hawork:x%x wait:x%x", |
| 12533 | phba->work_ha, work_ha_copy, |
| 12534 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12535 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12536 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12537 | control &= |
| 12538 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12539 | writel(control, phba->HCregaddr); |
| 12540 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12541 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12542 | else { |
| 12543 | lpfc_debugfs_slow_ring_trc(phba, |
| 12544 | "ISR slow ring: pwork:" |
| 12545 | "x%x hawork:x%x wait:x%x", |
| 12546 | phba->work_ha, work_ha_copy, |
| 12547 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12548 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12549 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12550 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12551 | } |
| 12552 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12553 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12554 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12555 | if (lpfc_sli_read_hs(phba)) |
| 12556 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12557 | /* |
| 12558 | * Check if there is a deferred error condition |
| 12559 | * is active |
| 12560 | */ |
| 12561 | if ((HS_FFER1 & phba->work_hs) && |
| 12562 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12563 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 12564 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12565 | phba->hba_flag |= DEFER_ERATT; |
| 12566 | /* Clear all interrupt enable conditions */ |
| 12567 | writel(0, phba->HCregaddr); |
| 12568 | readl(phba->HCregaddr); |
| 12569 | } |
| 12570 | } |
| 12571 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12572 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12573 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12574 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12575 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12576 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12577 | |
| 12578 | /* First check out the status word */ |
| 12579 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 12580 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12581 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12582 | /* |
| 12583 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 12584 | * mbxStatus <status> |
| 12585 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12586 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12587 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12588 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12589 | "Interrupt mbxCommand x%x " |
| 12590 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12591 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12592 | pmbox->mbxCommand, |
| 12593 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12594 | /* clear mailbox attention bit */ |
| 12595 | work_ha_copy &= ~HA_MBATT; |
| 12596 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12597 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12598 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12599 | phba->last_completion_time = jiffies; |
| 12600 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12601 | if (pmb->mbox_cmpl) { |
| 12602 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 12603 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12604 | if (pmb->out_ext_byte_len && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12605 | pmb->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12606 | lpfc_sli_pcimem_bcopy( |
| 12607 | phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12608 | pmb->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12609 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12610 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12611 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12612 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12613 | |
| 12614 | lpfc_debugfs_disc_trc(vport, |
| 12615 | LPFC_DISC_TRC_MBOX_VPORT, |
| 12616 | "MBOX dflt rpi: : " |
| 12617 | "status:x%x rpi:x%x", |
| 12618 | (uint32_t)pmbox->mbxStatus, |
| 12619 | pmbox->un.varWords[0], 0); |
| 12620 | |
| 12621 | if (!pmbox->mbxStatus) { |
| 12622 | mp = (struct lpfc_dmabuf *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12623 | (pmb->ctx_buf); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12624 | ndlp = (struct lpfc_nodelist *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12625 | pmb->ctx_ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12626 | |
| 12627 | /* Reg_LOGIN of dflt RPI was |
| 12628 | * successful. new lets get |
| 12629 | * rid of the RPI using the |
| 12630 | * same mbox buffer. |
| 12631 | */ |
| 12632 | lpfc_unreg_login(phba, |
| 12633 | vport->vpi, |
| 12634 | pmbox->un.varWords[0], |
| 12635 | pmb); |
| 12636 | pmb->mbox_cmpl = |
| 12637 | lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12638 | pmb->ctx_buf = mp; |
| 12639 | pmb->ctx_ndlp = ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12640 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12641 | rc = lpfc_sli_issue_mbox(phba, |
| 12642 | pmb, |
| 12643 | MBX_NOWAIT); |
| 12644 | if (rc != MBX_BUSY) |
| 12645 | lpfc_printf_log(phba, |
| 12646 | KERN_ERR, |
| 12647 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12648 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12649 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12650 | if (rc != MBX_NOT_FINISHED) |
| 12651 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12652 | } |
| 12653 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12654 | spin_lock_irqsave( |
| 12655 | &phba->pport->work_port_lock, |
| 12656 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12657 | phba->pport->work_port_events &= |
| 12658 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12659 | spin_unlock_irqrestore( |
| 12660 | &phba->pport->work_port_lock, |
| 12661 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12662 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12663 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12664 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12665 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12666 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12667 | if ((work_ha_copy & HA_MBATT) && |
| 12668 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12669 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12670 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12671 | do { |
| 12672 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 12673 | MBX_NOWAIT); |
| 12674 | } while (rc == MBX_NOT_FINISHED); |
| 12675 | if (rc != MBX_SUCCESS) |
| 12676 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12677 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12678 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12679 | } |
| 12680 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12681 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12682 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12683 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12684 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12685 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12686 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12687 | unplug_error: |
| 12688 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12689 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12690 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12691 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12692 | |
| 12693 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12694 | * 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] | 12695 | * @irq: Interrupt number. |
| 12696 | * @dev_id: The device context pointer. |
| 12697 | * |
| 12698 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12699 | * service routine when device with SLI-3 interface spec is enabled with |
| 12700 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12701 | * ring event in the HBA. However, when the device is enabled with either |
| 12702 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12703 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12704 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12705 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12706 | * the intrrupt context. This function is called without any lock held. |
| 12707 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12708 | * |
| 12709 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12710 | * returns IRQ_NONE. |
| 12711 | **/ |
| 12712 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12713 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12714 | { |
| 12715 | struct lpfc_hba *phba; |
| 12716 | uint32_t ha_copy; |
| 12717 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12718 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12719 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12720 | |
| 12721 | /* Get the driver's phba structure from the dev_id and |
| 12722 | * assume the HBA is not interrupting. |
| 12723 | */ |
| 12724 | phba = (struct lpfc_hba *) dev_id; |
| 12725 | |
| 12726 | if (unlikely(!phba)) |
| 12727 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12728 | |
| 12729 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12730 | * Stuff needs to be attented to when this function is invoked as an |
| 12731 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12732 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12733 | if (phba->intr_type == MSIX) { |
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 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12738 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12739 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12740 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12741 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12742 | /* |
| 12743 | * If there is deferred error attention, do not check for |
| 12744 | * any interrupt. |
| 12745 | */ |
| 12746 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12747 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12748 | return IRQ_NONE; |
| 12749 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12750 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 12751 | phba->HAregaddr); |
| 12752 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12753 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12754 | } else |
| 12755 | ha_copy = phba->ha_copy; |
| 12756 | |
| 12757 | /* |
| 12758 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 12759 | */ |
| 12760 | ha_copy &= ~(phba->work_ha_mask); |
| 12761 | |
| 12762 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12763 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12764 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12765 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12766 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12767 | |
| 12768 | if (phba->cfg_multi_ring_support == 2) { |
| 12769 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12770 | * Process all events on extra ring. Take the optimized path |
| 12771 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12772 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12773 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12774 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12775 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12776 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12777 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12778 | status); |
| 12779 | } |
| 12780 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12781 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12782 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12783 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12784 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12785 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12786 | * @irq: Interrupt number. |
| 12787 | * @dev_id: The device context pointer. |
| 12788 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12789 | * This function is the HBA device-level interrupt handler to device with |
| 12790 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 12791 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 12792 | * requires driver attention. This function invokes the slow-path interrupt |
| 12793 | * attention handling function and fast-path interrupt attention handling |
| 12794 | * function in turn to process the relevant HBA attention events. This |
| 12795 | * function is called without any lock held. It gets the hbalock to access |
| 12796 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12797 | * |
| 12798 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12799 | * returns IRQ_NONE. |
| 12800 | **/ |
| 12801 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12802 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12803 | { |
| 12804 | struct lpfc_hba *phba; |
| 12805 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 12806 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12807 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12808 | |
| 12809 | /* |
| 12810 | * Get the driver's phba structure from the dev_id and |
| 12811 | * assume the HBA is not interrupting. |
| 12812 | */ |
| 12813 | phba = (struct lpfc_hba *) dev_id; |
| 12814 | |
| 12815 | if (unlikely(!phba)) |
| 12816 | return IRQ_NONE; |
| 12817 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12818 | /* Check device state for handling interrupt */ |
| 12819 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12820 | return IRQ_NONE; |
| 12821 | |
| 12822 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12823 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 12824 | spin_unlock(&phba->hbalock); |
| 12825 | return IRQ_HANDLED; |
| 12826 | } |
| 12827 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12828 | if (unlikely(!phba->ha_copy)) { |
| 12829 | spin_unlock(&phba->hbalock); |
| 12830 | return IRQ_NONE; |
| 12831 | } else if (phba->ha_copy & HA_ERATT) { |
| 12832 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12833 | /* ERATT polling has handled ERATT */ |
| 12834 | phba->ha_copy &= ~HA_ERATT; |
| 12835 | else |
| 12836 | /* Indicate interrupt handler handles ERATT */ |
| 12837 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12838 | } |
| 12839 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12840 | /* |
| 12841 | * If there is deferred error attention, do not check for any interrupt. |
| 12842 | */ |
| 12843 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 12844 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12845 | return IRQ_NONE; |
| 12846 | } |
| 12847 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12848 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12849 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 12850 | spin_unlock(&phba->hbalock); |
| 12851 | return IRQ_HANDLED; |
| 12852 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12853 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 12854 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12855 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12856 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12857 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12858 | readl(phba->HAregaddr); /* flush */ |
| 12859 | spin_unlock(&phba->hbalock); |
| 12860 | |
| 12861 | /* |
| 12862 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 12863 | */ |
| 12864 | |
| 12865 | /* status of events with mailbox and link attention */ |
| 12866 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 12867 | |
| 12868 | /* status of events with ELS ring */ |
| 12869 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12870 | status2 >>= (4*LPFC_ELS_RING); |
| 12871 | |
| 12872 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12873 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12874 | else |
| 12875 | sp_irq_rc = IRQ_NONE; |
| 12876 | |
| 12877 | /* |
| 12878 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12879 | */ |
| 12880 | |
| 12881 | /* status of events with FCP ring */ |
| 12882 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 12883 | status1 >>= (4*LPFC_FCP_RING); |
| 12884 | |
| 12885 | /* status of events with extra ring */ |
| 12886 | if (phba->cfg_multi_ring_support == 2) { |
| 12887 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 12888 | status2 >>= (4*LPFC_EXTRA_RING); |
| 12889 | } else |
| 12890 | status2 = 0; |
| 12891 | |
| 12892 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12893 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12894 | else |
| 12895 | fp_irq_rc = IRQ_NONE; |
| 12896 | |
| 12897 | /* Return device-level interrupt handling status */ |
| 12898 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12899 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12900 | |
| 12901 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12902 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 12903 | * @phba: pointer to lpfc hba data structure. |
| 12904 | * |
| 12905 | * This routine is invoked by the worker thread to process all the pending |
| 12906 | * SLI4 els abort xri events. |
| 12907 | **/ |
| 12908 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12909 | { |
| 12910 | struct lpfc_cq_event *cq_event; |
| 12911 | |
| 12912 | /* First, declare the els xri abort event has been handled */ |
| 12913 | spin_lock_irq(&phba->hbalock); |
| 12914 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 12915 | spin_unlock_irq(&phba->hbalock); |
| 12916 | /* Now, handle all the els xri abort events */ |
| 12917 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 12918 | /* Get the first event from the head of the event queue */ |
| 12919 | spin_lock_irq(&phba->hbalock); |
| 12920 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 12921 | cq_event, struct lpfc_cq_event, list); |
| 12922 | spin_unlock_irq(&phba->hbalock); |
| 12923 | /* Notify aborted XRI for ELS work queue */ |
| 12924 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12925 | /* Free the event processed back to the free pool */ |
| 12926 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12927 | } |
| 12928 | } |
| 12929 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12930 | /** |
| 12931 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 12932 | * @phba: pointer to lpfc hba data structure |
| 12933 | * @pIocbIn: pointer to the rspiocbq |
| 12934 | * @pIocbOut: pointer to the cmdiocbq |
| 12935 | * @wcqe: pointer to the complete wcqe |
| 12936 | * |
| 12937 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 12938 | * by copying all the IOCB fields from command iocbq and transferring the |
| 12939 | * completion status information from the complete wcqe. |
| 12940 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12941 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12942 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 12943 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12944 | struct lpfc_iocbq *pIocbOut, |
| 12945 | struct lpfc_wcqe_complete *wcqe) |
| 12946 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12947 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12948 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12949 | uint32_t status, max_response; |
| 12950 | struct lpfc_dmabuf *dmabuf; |
| 12951 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12952 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 12953 | |
| 12954 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 12955 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12956 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12957 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 12958 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12959 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 12960 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 12961 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 12962 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 12963 | wcqe->total_data_placed; |
| 12964 | else |
| 12965 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12966 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12967 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12968 | switch (pIocbOut->iocb.ulpCommand) { |
| 12969 | case CMD_ELS_REQUEST64_CR: |
| 12970 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12971 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12972 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 12973 | max_response = bde.tus.f.bdeSize; |
| 12974 | break; |
| 12975 | case CMD_GEN_REQUEST64_CR: |
| 12976 | max_response = 0; |
| 12977 | if (!pIocbOut->context3) |
| 12978 | break; |
| 12979 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 12980 | sizeof(struct ulp_bde64); |
| 12981 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12982 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12983 | for (i = 0; i < numBdes; i++) { |
| 12984 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 12985 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 12986 | max_response += bde.tus.f.bdeSize; |
| 12987 | } |
| 12988 | break; |
| 12989 | default: |
| 12990 | max_response = wcqe->total_data_placed; |
| 12991 | break; |
| 12992 | } |
| 12993 | if (max_response < wcqe->total_data_placed) |
| 12994 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 12995 | else |
| 12996 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 12997 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12998 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12999 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 13000 | /* Convert BG errors for completion status */ |
| 13001 | if (status == CQE_STATUS_DI_ERROR) { |
| 13002 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 13003 | |
| 13004 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 13005 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 13006 | else |
| 13007 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 13008 | |
| 13009 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 13010 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 13011 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13012 | BGS_GUARD_ERR_MASK; |
| 13013 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 13014 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13015 | BGS_APPTAG_ERR_MASK; |
| 13016 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 13017 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13018 | BGS_REFTAG_ERR_MASK; |
| 13019 | |
| 13020 | /* Check to see if there was any good data before the error */ |
| 13021 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 13022 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13023 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 13024 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 13025 | wcqe->total_data_placed; |
| 13026 | } |
| 13027 | |
| 13028 | /* |
| 13029 | * Set ALL the error bits to indicate we don't know what |
| 13030 | * type of error it is. |
| 13031 | */ |
| 13032 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 13033 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13034 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 13035 | BGS_GUARD_ERR_MASK); |
| 13036 | } |
| 13037 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13038 | /* Pick up HBA exchange busy condition */ |
| 13039 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 13040 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13041 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 13042 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13043 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13044 | } |
| 13045 | |
| 13046 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13047 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 13048 | * @phba: Pointer to HBA context object. |
| 13049 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13050 | * |
| 13051 | * This routine handles an ELS work-queue completion event and construct |
| 13052 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 13053 | * discovery engine to handle. |
| 13054 | * |
| 13055 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 13056 | **/ |
| 13057 | static struct lpfc_iocbq * |
| 13058 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 13059 | struct lpfc_iocbq *irspiocbq) |
| 13060 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13061 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13062 | struct lpfc_iocbq *cmdiocbq; |
| 13063 | struct lpfc_wcqe_complete *wcqe; |
| 13064 | unsigned long iflags; |
| 13065 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13066 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 13067 | if (unlikely(!pring)) |
| 13068 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13069 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13070 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13071 | pring->stats.iocb_event++; |
| 13072 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 13073 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13074 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13075 | if (unlikely(!cmdiocbq)) { |
| 13076 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13077 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13078 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 13079 | wcqe->word0, wcqe->total_data_placed, |
| 13080 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13081 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 13082 | return NULL; |
| 13083 | } |
| 13084 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 13085 | spin_lock_irqsave(&pring->ring_lock, iflags); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13086 | /* Put the iocb back on the txcmplq */ |
| 13087 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 13088 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 13089 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13090 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13091 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13092 | |
| 13093 | return irspiocbq; |
| 13094 | } |
| 13095 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13096 | inline struct lpfc_cq_event * |
| 13097 | lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size) |
| 13098 | { |
| 13099 | struct lpfc_cq_event *cq_event; |
| 13100 | |
| 13101 | /* Allocate a new internal CQ_EVENT entry */ |
| 13102 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 13103 | if (!cq_event) { |
| 13104 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13105 | "0602 Failed to alloc CQ_EVENT entry\n"); |
| 13106 | return NULL; |
| 13107 | } |
| 13108 | |
| 13109 | /* Move the CQE into the event */ |
| 13110 | memcpy(&cq_event->cqe, entry, size); |
| 13111 | return cq_event; |
| 13112 | } |
| 13113 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13114 | /** |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 13115 | * lpfc_sli4_sp_handle_async_event - Handle an asynchronous event |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13116 | * @phba: Pointer to HBA context object. |
| 13117 | * @cqe: Pointer to mailbox completion queue entry. |
| 13118 | * |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 13119 | * This routine process a mailbox completion queue entry with asynchronous |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13120 | * event. |
| 13121 | * |
| 13122 | * Return: true if work posted to worker thread, otherwise false. |
| 13123 | **/ |
| 13124 | static bool |
| 13125 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13126 | { |
| 13127 | struct lpfc_cq_event *cq_event; |
| 13128 | unsigned long iflags; |
| 13129 | |
| 13130 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13131 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 13132 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 13133 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 13134 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13135 | cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe)); |
| 13136 | if (!cq_event) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13137 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13138 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13139 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 13140 | /* Set the async event flag */ |
| 13141 | phba->hba_flag |= ASYNC_EVENT; |
| 13142 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13143 | |
| 13144 | return true; |
| 13145 | } |
| 13146 | |
| 13147 | /** |
| 13148 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 13149 | * @phba: Pointer to HBA context object. |
| 13150 | * @cqe: Pointer to mailbox completion queue entry. |
| 13151 | * |
| 13152 | * This routine process a mailbox completion queue entry with mailbox |
| 13153 | * completion event. |
| 13154 | * |
| 13155 | * Return: true if work posted to worker thread, otherwise false. |
| 13156 | **/ |
| 13157 | static bool |
| 13158 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13159 | { |
| 13160 | uint32_t mcqe_status; |
| 13161 | MAILBOX_t *mbox, *pmbox; |
| 13162 | struct lpfc_mqe *mqe; |
| 13163 | struct lpfc_vport *vport; |
| 13164 | struct lpfc_nodelist *ndlp; |
| 13165 | struct lpfc_dmabuf *mp; |
| 13166 | unsigned long iflags; |
| 13167 | LPFC_MBOXQ_t *pmb; |
| 13168 | bool workposted = false; |
| 13169 | int rc; |
| 13170 | |
| 13171 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 13172 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 13173 | goto out_no_mqe_complete; |
| 13174 | |
| 13175 | /* Get the reference to the active mbox command */ |
| 13176 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13177 | pmb = phba->sli.mbox_active; |
| 13178 | if (unlikely(!pmb)) { |
| 13179 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 13180 | "1832 No pending MBOX command to handle\n"); |
| 13181 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13182 | goto out_no_mqe_complete; |
| 13183 | } |
| 13184 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13185 | mqe = &pmb->u.mqe; |
| 13186 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 13187 | mbox = phba->mbox; |
| 13188 | vport = pmb->vport; |
| 13189 | |
| 13190 | /* Reset heartbeat timer */ |
| 13191 | phba->last_completion_time = jiffies; |
| 13192 | del_timer(&phba->sli.mbox_tmo); |
| 13193 | |
| 13194 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 13195 | if (pmb->mbox_cmpl && mbox) |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13196 | lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13197 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13198 | /* |
| 13199 | * For mcqe errors, conditionally move a modified error code to |
| 13200 | * the mbox so that the error will not be missed. |
| 13201 | */ |
| 13202 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 13203 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 13204 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 13205 | bf_set(lpfc_mqe_status, mqe, |
| 13206 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 13207 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13208 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 13209 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 13210 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 13211 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 13212 | mcqe_status, |
| 13213 | pmbox->un.varWords[0], 0); |
| 13214 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13215 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 13216 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13217 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 13218 | * RID of the PPI using the same mbox buffer. |
| 13219 | */ |
| 13220 | lpfc_unreg_login(phba, vport->vpi, |
| 13221 | pmbox->un.varWords[0], pmb); |
| 13222 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13223 | pmb->ctx_buf = mp; |
| 13224 | pmb->ctx_ndlp = ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13225 | pmb->vport = vport; |
| 13226 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 13227 | if (rc != MBX_BUSY) |
| 13228 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 13229 | LOG_SLI, "0385 rc should " |
| 13230 | "have been MBX_BUSY\n"); |
| 13231 | if (rc != MBX_NOT_FINISHED) |
| 13232 | goto send_current_mbox; |
| 13233 | } |
| 13234 | } |
| 13235 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 13236 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 13237 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 13238 | |
| 13239 | /* There is mailbox completion work to do */ |
| 13240 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13241 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 13242 | phba->work_ha |= HA_MBATT; |
| 13243 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13244 | workposted = true; |
| 13245 | |
| 13246 | send_current_mbox: |
| 13247 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13248 | /* Release the mailbox command posting token */ |
| 13249 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 13250 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 13251 | phba->sli.mbox_active = NULL; |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13252 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13253 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13254 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13255 | /* Wake up worker thread to post the next pending mailbox command */ |
| 13256 | lpfc_worker_wake_up(phba); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13257 | return workposted; |
| 13258 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13259 | out_no_mqe_complete: |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13260 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13261 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13262 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13263 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13264 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13265 | } |
| 13266 | |
| 13267 | /** |
| 13268 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 13269 | * @phba: Pointer to HBA context object. |
| 13270 | * @cqe: Pointer to mailbox completion queue entry. |
| 13271 | * |
| 13272 | * This routine process a mailbox completion queue entry, it invokes the |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 13273 | * proper mailbox complete handling or asynchronous event handling routine |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13274 | * according to the MCQE's async bit. |
| 13275 | * |
| 13276 | * Return: true if work posted to worker thread, otherwise false. |
| 13277 | **/ |
| 13278 | static bool |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13279 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13280 | struct lpfc_cqe *cqe) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13281 | { |
| 13282 | struct lpfc_mcqe mcqe; |
| 13283 | bool workposted; |
| 13284 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13285 | cq->CQ_mbox++; |
| 13286 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13287 | /* Copy the mailbox MCQE and convert endian order as needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13288 | lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13289 | |
| 13290 | /* Invoke the proper event handling routine */ |
| 13291 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 13292 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 13293 | else |
| 13294 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 13295 | return workposted; |
| 13296 | } |
| 13297 | |
| 13298 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13299 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 13300 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13301 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13302 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13303 | * |
| 13304 | * This routine handles an ELS work-queue completion event. |
| 13305 | * |
| 13306 | * Return: true if work posted to worker thread, otherwise false. |
| 13307 | **/ |
| 13308 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13309 | 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] | 13310 | struct lpfc_wcqe_complete *wcqe) |
| 13311 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13312 | struct lpfc_iocbq *irspiocbq; |
| 13313 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13314 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13315 | int txq_cnt = 0; |
| 13316 | int txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13317 | |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13318 | /* Check for response status */ |
| 13319 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13320 | /* Log the error status */ |
| 13321 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13322 | "0357 ELS CQE error: status=x%x: " |
| 13323 | "CQE: %08x %08x %08x %08x\n", |
| 13324 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 13325 | wcqe->word0, wcqe->total_data_placed, |
| 13326 | wcqe->parameter, wcqe->word3); |
| 13327 | } |
| 13328 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13329 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13330 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 13331 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13332 | if (!list_empty(&pring->txq)) |
| 13333 | txq_cnt++; |
| 13334 | if (!list_empty(&pring->txcmplq)) |
| 13335 | txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13336 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 13337 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
James Smart | ff349bc | 2019-09-21 20:59:05 -0700 | [diff] [blame] | 13338 | "els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13339 | txq_cnt, phba->iocb_cnt, |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13340 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13341 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13342 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13343 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13344 | /* Save off the slow-path queue event for work thread to process */ |
| 13345 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13346 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13347 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13348 | &phba->sli4_hba.sp_queue_event); |
| 13349 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13350 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13351 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13352 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13353 | } |
| 13354 | |
| 13355 | /** |
| 13356 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 13357 | * @phba: Pointer to HBA context object. |
| 13358 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13359 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13360 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13361 | * proper WQ release routine to the slow-path WQ. |
| 13362 | **/ |
| 13363 | static void |
| 13364 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 13365 | struct lpfc_wcqe_release *wcqe) |
| 13366 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13367 | /* sanity check on queue memory */ |
| 13368 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 13369 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13370 | /* Check for the slow-path ELS work queue */ |
| 13371 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 13372 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 13373 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 13374 | else |
| 13375 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13376 | "2579 Slow-path wqe consume event carries " |
| 13377 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 13378 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 13379 | phba->sli4_hba.els_wq->queue_id); |
| 13380 | } |
| 13381 | |
| 13382 | /** |
| 13383 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 13384 | * @phba: Pointer to HBA context object. |
| 13385 | * @cq: Pointer to a WQ completion queue. |
| 13386 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13387 | * |
| 13388 | * This routine handles an XRI abort event. |
| 13389 | * |
| 13390 | * Return: true if work posted to worker thread, otherwise false. |
| 13391 | **/ |
| 13392 | static bool |
| 13393 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 13394 | struct lpfc_queue *cq, |
| 13395 | struct sli4_wcqe_xri_aborted *wcqe) |
| 13396 | { |
| 13397 | bool workposted = false; |
| 13398 | struct lpfc_cq_event *cq_event; |
| 13399 | unsigned long iflags; |
| 13400 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13401 | switch (cq->subtype) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13402 | case LPFC_IO: |
| 13403 | lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq); |
| 13404 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 13405 | /* Notify aborted XRI for NVME work queue */ |
| 13406 | if (phba->nvmet_support) |
| 13407 | lpfc_sli4_nvmet_xri_aborted(phba, wcqe); |
| 13408 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13409 | workposted = false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13410 | break; |
James Smart | 422c4cb | 2017-11-20 16:00:32 -0800 | [diff] [blame] | 13411 | case LPFC_NVME_LS: /* NVME LS uses ELS resources */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13412 | case LPFC_ELS: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13413 | cq_event = lpfc_cq_event_setup( |
| 13414 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 13415 | if (!cq_event) |
| 13416 | return false; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13417 | cq_event->hdwq = cq->hdwq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13418 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13419 | list_add_tail(&cq_event->list, |
| 13420 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 13421 | /* Set the els xri abort event flag */ |
| 13422 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 13423 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13424 | workposted = true; |
| 13425 | break; |
| 13426 | default: |
| 13427 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13428 | "0603 Invalid CQ subtype %d: " |
| 13429 | "%08x %08x %08x %08x\n", |
| 13430 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 13431 | wcqe->word2, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13432 | workposted = false; |
| 13433 | break; |
| 13434 | } |
| 13435 | return workposted; |
| 13436 | } |
| 13437 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13438 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 13439 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13440 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13441 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13442 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13443 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13444 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13445 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13446 | * |
| 13447 | * Return: true if work posted to worker thread, otherwise false. |
| 13448 | **/ |
| 13449 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13450 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 13451 | { |
| 13452 | bool workposted = false; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13453 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13454 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 13455 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13456 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13457 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13458 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13459 | unsigned long iflags; |
| 13460 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13461 | /* sanity check on queue memory */ |
| 13462 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13463 | return workposted; |
| 13464 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13465 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13466 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13467 | else |
| 13468 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13469 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13470 | goto out; |
| 13471 | |
| 13472 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13473 | switch (status) { |
| 13474 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13475 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13476 | "2537 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 13477 | /* fall through */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13478 | case FC_STATUS_RQ_SUCCESS: |
| 13479 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13480 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13481 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 13482 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13483 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13484 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13485 | goto out; |
| 13486 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13487 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13488 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13489 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13490 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13491 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13492 | |
| 13493 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 13494 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 13495 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13496 | /* Handle MDS Loopback frames */ |
| 13497 | lpfc_sli4_handle_mds_loopback(phba->pport, dma_buf); |
| 13498 | break; |
| 13499 | } |
| 13500 | |
| 13501 | /* save off the frame for the work thread to process */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13502 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13503 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13504 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13505 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13506 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13507 | workposted = true; |
| 13508 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13509 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13510 | if (phba->nvmet_support) { |
| 13511 | tgtp = phba->targetport->private; |
| 13512 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13513 | "6402 RQE Error x%x, posted %d err_cnt " |
| 13514 | "%d: %x %x %x\n", |
| 13515 | status, hrq->RQ_buf_posted, |
| 13516 | hrq->RQ_no_posted_buf, |
| 13517 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13518 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13519 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13520 | } |
| 13521 | /* fallthrough */ |
| 13522 | |
| 13523 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13524 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13525 | /* Post more buffers if possible */ |
| 13526 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13527 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 13528 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13529 | workposted = true; |
| 13530 | break; |
| 13531 | } |
| 13532 | out: |
| 13533 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13534 | } |
| 13535 | |
| 13536 | /** |
| 13537 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 13538 | * @phba: Pointer to HBA context object. |
| 13539 | * @cq: Pointer to the completion queue. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13540 | * @cqe: Pointer to a completion queue entry. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13541 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13542 | * 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] | 13543 | * entry. |
| 13544 | * |
| 13545 | * Return: true if work posted to worker thread, otherwise false. |
| 13546 | **/ |
| 13547 | static bool |
| 13548 | 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] | 13549 | struct lpfc_cqe *cqe) |
| 13550 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13551 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13552 | bool workposted = false; |
| 13553 | |
| 13554 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13555 | lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13556 | |
| 13557 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13558 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13559 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13560 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13561 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13562 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13563 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13564 | break; |
| 13565 | case CQE_CODE_RELEASE_WQE: |
| 13566 | /* Process the WQ release event */ |
| 13567 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13568 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13569 | break; |
| 13570 | case CQE_CODE_XRI_ABORTED: |
| 13571 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13572 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13573 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13574 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13575 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13576 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13577 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13578 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13579 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13580 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13581 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13582 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13583 | default: |
| 13584 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13585 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13586 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13587 | break; |
| 13588 | } |
| 13589 | return workposted; |
| 13590 | } |
| 13591 | |
| 13592 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13593 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 13594 | * @phba: Pointer to HBA context object. |
| 13595 | * @eqe: Pointer to fast-path event queue entry. |
| 13596 | * |
| 13597 | * This routine process a event queue entry from the slow-path event queue. |
| 13598 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13599 | * completion event on a completion queue, if not, an error shall be logged |
| 13600 | * and just return. Otherwise, it will get to the corresponding completion |
| 13601 | * queue and process all the entries on that completion queue, rearm the |
| 13602 | * completion queue, and then return. |
| 13603 | * |
| 13604 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13605 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13606 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13607 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13608 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13609 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13610 | uint16_t cqid; |
| 13611 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13612 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13613 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13614 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13615 | list_for_each_entry(childq, &speq->child_list, list) { |
| 13616 | if (childq->queue_id == cqid) { |
| 13617 | cq = childq; |
| 13618 | break; |
| 13619 | } |
| 13620 | } |
| 13621 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13622 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13623 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13624 | "0365 Slow-path CQ identifier " |
| 13625 | "(%d) does not exist\n", cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13626 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13627 | } |
| 13628 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13629 | /* Save EQ associated with this CQ */ |
| 13630 | cq->assoc_qp = speq; |
| 13631 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13632 | if (!queue_work_on(cq->chann, phba->wq, &cq->spwork)) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13633 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13634 | "0390 Cannot schedule soft IRQ " |
| 13635 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 13636 | cqid, cq->queue_id, raw_smp_processor_id()); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13637 | } |
| 13638 | |
| 13639 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13640 | * __lpfc_sli4_process_cq - Process elements of a CQ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13641 | * @phba: Pointer to HBA context object. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13642 | * @cq: Pointer to CQ to be processed |
| 13643 | * @handler: Routine to process each cqe |
| 13644 | * @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] | 13645 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13646 | * This routine processes completion queue entries in a CQ. While a valid |
| 13647 | * queue element is found, the handler is called. During processing checks |
| 13648 | * are made for periodic doorbell writes to let the hardware know of |
| 13649 | * element consumption. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13650 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13651 | * If the max limit on cqes to process is hit, or there are no more valid |
| 13652 | * entries, the loop stops. If we processed a sufficient number of elements, |
| 13653 | * meaning there is sufficient load, rather than rearming and generating |
| 13654 | * another interrupt, a cq rescheduling delay will be set. A delay of 0 |
| 13655 | * indicates no rescheduling. |
| 13656 | * |
| 13657 | * Returns True if work scheduled, False otherwise. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13658 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13659 | static bool |
| 13660 | __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13661 | bool (*handler)(struct lpfc_hba *, struct lpfc_queue *, |
| 13662 | struct lpfc_cqe *), unsigned long *delay) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13663 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13664 | struct lpfc_cqe *cqe; |
| 13665 | bool workposted = false; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13666 | int count = 0, consumed = 0; |
| 13667 | bool arm = true; |
| 13668 | |
| 13669 | /* default - no reschedule */ |
| 13670 | *delay = 0; |
| 13671 | |
| 13672 | if (cmpxchg(&cq->queue_claimed, 0, 1) != 0) |
| 13673 | goto rearm_and_exit; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13674 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13675 | /* Process all the entries to the CQ */ |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13676 | cq->q_flag = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13677 | cqe = lpfc_sli4_cq_get(cq); |
| 13678 | while (cqe) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13679 | workposted |= handler(phba, cq, cqe); |
| 13680 | __lpfc_sli4_consume_cqe(phba, cq, cqe); |
| 13681 | |
| 13682 | consumed++; |
| 13683 | if (!(++count % cq->max_proc_limit)) |
| 13684 | break; |
| 13685 | |
| 13686 | if (!(count % cq->notify_interval)) { |
| 13687 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 13688 | LPFC_QUEUE_NOARM); |
| 13689 | consumed = 0; |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 13690 | cq->assoc_qp->q_flag |= HBA_EQ_DELAY_CHK; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13691 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13692 | |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13693 | if (count == LPFC_NVMET_CQ_NOTIFY) |
| 13694 | cq->q_flag |= HBA_NVMET_CQ_NOTIFY; |
| 13695 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13696 | cqe = lpfc_sli4_cq_get(cq); |
| 13697 | } |
| 13698 | if (count >= phba->cfg_cq_poll_threshold) { |
| 13699 | *delay = 1; |
| 13700 | arm = false; |
| 13701 | } |
| 13702 | |
| 13703 | /* Track the max number of CQEs processed in 1 EQ */ |
| 13704 | if (count > cq->CQ_max_cqe) |
| 13705 | cq->CQ_max_cqe = count; |
| 13706 | |
| 13707 | cq->assoc_qp->EQ_cqe_cnt += count; |
| 13708 | |
| 13709 | /* Catch the no cq entry condition */ |
| 13710 | if (unlikely(count == 0)) |
| 13711 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13712 | "0369 No entry from completion queue " |
| 13713 | "qid=%d\n", cq->queue_id); |
| 13714 | |
| 13715 | cq->queue_claimed = 0; |
| 13716 | |
| 13717 | rearm_and_exit: |
| 13718 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 13719 | arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM); |
| 13720 | |
| 13721 | return workposted; |
| 13722 | } |
| 13723 | |
| 13724 | /** |
| 13725 | * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry |
| 13726 | * @cq: pointer to CQ to process |
| 13727 | * |
| 13728 | * This routine calls the cq processing routine with a handler specific |
| 13729 | * to the type of queue bound to it. |
| 13730 | * |
| 13731 | * The CQ routine returns two values: the first is the calling status, |
| 13732 | * which indicates whether work was queued to the background discovery |
| 13733 | * thread. If true, the routine should wakeup the discovery thread; |
| 13734 | * the second is the delay parameter. If non-zero, rather than rearming |
| 13735 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 13736 | * that it is processed in a subsequent polling action. The value of |
| 13737 | * the delay indicates when to reschedule it. |
| 13738 | **/ |
| 13739 | static void |
| 13740 | __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq) |
| 13741 | { |
| 13742 | struct lpfc_hba *phba = cq->phba; |
| 13743 | unsigned long delay; |
| 13744 | bool workposted = false; |
| 13745 | |
| 13746 | /* Process and rearm the CQ */ |
| 13747 | switch (cq->type) { |
| 13748 | case LPFC_MCQ: |
| 13749 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13750 | lpfc_sli4_sp_handle_mcqe, |
| 13751 | &delay); |
| 13752 | break; |
| 13753 | case LPFC_WCQ: |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13754 | if (cq->subtype == LPFC_IO) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13755 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13756 | lpfc_sli4_fp_handle_cqe, |
| 13757 | &delay); |
| 13758 | else |
| 13759 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13760 | lpfc_sli4_sp_handle_cqe, |
| 13761 | &delay); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13762 | break; |
| 13763 | default: |
| 13764 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13765 | "0370 Invalid completion queue type (%d)\n", |
| 13766 | cq->type); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13767 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13768 | } |
| 13769 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13770 | if (delay) { |
| 13771 | if (!queue_delayed_work_on(cq->chann, phba->wq, |
| 13772 | &cq->sched_spwork, delay)) |
| 13773 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13774 | "0394 Cannot schedule soft IRQ " |
| 13775 | "for cqid=%d on CPU %d\n", |
| 13776 | cq->queue_id, cq->chann); |
| 13777 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13778 | |
| 13779 | /* wake up worker thread if there are works to be done */ |
| 13780 | if (workposted) |
| 13781 | lpfc_worker_wake_up(phba); |
| 13782 | } |
| 13783 | |
| 13784 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13785 | * lpfc_sli4_sp_process_cq - slow-path work handler when started by |
| 13786 | * interrupt |
| 13787 | * @work: pointer to work element |
| 13788 | * |
| 13789 | * translates from the work handler and calls the slow-path handler. |
| 13790 | **/ |
| 13791 | static void |
| 13792 | lpfc_sli4_sp_process_cq(struct work_struct *work) |
| 13793 | { |
| 13794 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork); |
| 13795 | |
| 13796 | __lpfc_sli4_sp_process_cq(cq); |
| 13797 | } |
| 13798 | |
| 13799 | /** |
| 13800 | * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer |
| 13801 | * @work: pointer to work element |
| 13802 | * |
| 13803 | * translates from the work handler and calls the slow-path handler. |
| 13804 | **/ |
| 13805 | static void |
| 13806 | lpfc_sli4_dly_sp_process_cq(struct work_struct *work) |
| 13807 | { |
| 13808 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 13809 | struct lpfc_queue, sched_spwork); |
| 13810 | |
| 13811 | __lpfc_sli4_sp_process_cq(cq); |
| 13812 | } |
| 13813 | |
| 13814 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13815 | * 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] | 13816 | * @phba: Pointer to HBA context object. |
| 13817 | * @cq: Pointer to associated CQ |
| 13818 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13819 | * |
| 13820 | * This routine process a fast-path work queue completion entry from fast-path |
| 13821 | * event queue for FCP command response completion. |
| 13822 | **/ |
| 13823 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13824 | 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] | 13825 | struct lpfc_wcqe_complete *wcqe) |
| 13826 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13827 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13828 | struct lpfc_iocbq *cmdiocbq; |
| 13829 | struct lpfc_iocbq irspiocbq; |
| 13830 | unsigned long iflags; |
| 13831 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13832 | /* Check for response status */ |
| 13833 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13834 | /* If resource errors reported from HBA, reduce queue |
| 13835 | * depth of the SCSI device. |
| 13836 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13837 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 13838 | IOSTAT_LOCAL_REJECT)) && |
| 13839 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 13840 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13841 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13842 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13843 | /* Log the error status */ |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13844 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13845 | "0373 FCP CQE error: status=x%x: " |
| 13846 | "CQE: %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13847 | bf_get(lpfc_wcqe_c_status, wcqe), |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13848 | wcqe->word0, wcqe->total_data_placed, |
| 13849 | wcqe->parameter, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13850 | } |
| 13851 | |
| 13852 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13853 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 13854 | pring->stats.iocb_event++; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 13855 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13856 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13857 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13858 | if (unlikely(!cmdiocbq)) { |
| 13859 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13860 | "0374 FCP complete with no corresponding " |
| 13861 | "cmdiocb: iotag (%d)\n", |
| 13862 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13863 | return; |
| 13864 | } |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13865 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13866 | cmdiocbq->isr_timestamp = cq->isr_timestamp; |
| 13867 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13868 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 13869 | if (cmdiocbq->wqe_cmpl) { |
| 13870 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13871 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13872 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13873 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13874 | } |
| 13875 | |
| 13876 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 13877 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 13878 | return; |
| 13879 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13880 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13881 | "0375 FCP cmdiocb not callback function " |
| 13882 | "iotag: (%d)\n", |
| 13883 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13884 | return; |
| 13885 | } |
| 13886 | |
| 13887 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13888 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13889 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 13890 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13891 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13892 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13893 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13894 | } |
| 13895 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13896 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 13897 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 13898 | } |
| 13899 | |
| 13900 | /** |
| 13901 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 13902 | * @phba: Pointer to HBA context object. |
| 13903 | * @cq: Pointer to completion queue. |
| 13904 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13905 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13906 | * 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] | 13907 | * proper WQ release routine to the slow-path WQ. |
| 13908 | **/ |
| 13909 | static void |
| 13910 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13911 | struct lpfc_wcqe_release *wcqe) |
| 13912 | { |
| 13913 | struct lpfc_queue *childwq; |
| 13914 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13915 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13916 | |
| 13917 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13918 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13919 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13920 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13921 | lpfc_sli4_wq_release(childwq, |
| 13922 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 13923 | if (childwq->q_flag & HBA_NVMET_WQFULL) |
| 13924 | lpfc_nvmet_wqfull_process(phba, childwq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13925 | wqid_matched = true; |
| 13926 | break; |
| 13927 | } |
| 13928 | } |
| 13929 | /* Report warning log message if no match found */ |
| 13930 | if (wqid_matched != true) |
| 13931 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13932 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13933 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13934 | } |
| 13935 | |
| 13936 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13937 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 13938 | * @phba: Pointer to HBA context object. |
| 13939 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 13940 | * |
| 13941 | * This routine process a receive-queue completion queue entry. |
| 13942 | * |
| 13943 | * Return: true if work posted to worker thread, otherwise false. |
| 13944 | **/ |
| 13945 | static bool |
| 13946 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13947 | struct lpfc_rcqe *rcqe) |
| 13948 | { |
| 13949 | bool workposted = false; |
| 13950 | struct lpfc_queue *hrq; |
| 13951 | struct lpfc_queue *drq; |
| 13952 | struct rqb_dmabuf *dma_buf; |
| 13953 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13954 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13955 | uint32_t status, rq_id; |
| 13956 | unsigned long iflags; |
| 13957 | uint32_t fctl, idx; |
| 13958 | |
| 13959 | if ((phba->nvmet_support == 0) || |
| 13960 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 13961 | return workposted; |
| 13962 | |
| 13963 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13964 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 13965 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 13966 | |
| 13967 | /* sanity check on queue memory */ |
| 13968 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13969 | return workposted; |
| 13970 | |
| 13971 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13972 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13973 | else |
| 13974 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13975 | |
| 13976 | if ((phba->nvmet_support == 0) || |
| 13977 | (rq_id != hrq->queue_id)) |
| 13978 | return workposted; |
| 13979 | |
| 13980 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13981 | switch (status) { |
| 13982 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13983 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13984 | "6126 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 13985 | /* fall through */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13986 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13987 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13988 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13989 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 13990 | if (!dma_buf) { |
| 13991 | hrq->RQ_no_buf_found++; |
| 13992 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13993 | goto out; |
| 13994 | } |
| 13995 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13996 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13997 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13998 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13999 | |
| 14000 | /* Just some basic sanity checks on FCP Command frame */ |
| 14001 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
| 14002 | fc_hdr->fh_f_ctl[1] << 8 | |
| 14003 | fc_hdr->fh_f_ctl[2]); |
| 14004 | if (((fctl & |
| 14005 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 14006 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 14007 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 14008 | goto drop; |
| 14009 | |
| 14010 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14011 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 14012 | lpfc_nvmet_unsol_fcp_event( |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14013 | phba, idx, dma_buf, cq->isr_timestamp, |
| 14014 | cq->q_flag & HBA_NVMET_CQ_NOTIFY); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14015 | return false; |
| 14016 | } |
| 14017 | drop: |
James Smart | 22b738a | 2019-03-12 16:30:11 -0700 | [diff] [blame] | 14018 | lpfc_rq_buf_free(phba, &dma_buf->hbuf); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14019 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14020 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14021 | if (phba->nvmet_support) { |
| 14022 | tgtp = phba->targetport->private; |
| 14023 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 14024 | "6401 RQE Error x%x, posted %d err_cnt " |
| 14025 | "%d: %x %x %x\n", |
| 14026 | status, hrq->RQ_buf_posted, |
| 14027 | hrq->RQ_no_posted_buf, |
| 14028 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 14029 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 14030 | atomic_read(&tgtp->xmt_fcp_release)); |
| 14031 | } |
| 14032 | /* fallthrough */ |
| 14033 | |
| 14034 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14035 | hrq->RQ_no_posted_buf++; |
| 14036 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14037 | break; |
| 14038 | } |
| 14039 | out: |
| 14040 | return workposted; |
| 14041 | } |
| 14042 | |
| 14043 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14044 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14045 | * @phba: adapter with cq |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14046 | * @cq: Pointer to the completion queue. |
| 14047 | * @eqe: Pointer to fast-path completion queue entry. |
| 14048 | * |
| 14049 | * This routine process a fast-path work queue completion entry from fast-path |
| 14050 | * event queue for FCP command response completion. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14051 | * |
| 14052 | * Return: true if work posted to worker thread, otherwise false. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14053 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14054 | static bool |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14055 | 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] | 14056 | struct lpfc_cqe *cqe) |
| 14057 | { |
| 14058 | struct lpfc_wcqe_release wcqe; |
| 14059 | bool workposted = false; |
| 14060 | |
| 14061 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 14062 | lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14063 | |
| 14064 | /* Check and process for different type of WCQE and dispatch */ |
| 14065 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 14066 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14067 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14068 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14069 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 14070 | phba->last_completion_time = jiffies; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 14071 | if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14072 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14073 | (struct lpfc_wcqe_complete *)&wcqe); |
| 14074 | break; |
| 14075 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14076 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14077 | /* Process the WQ release event */ |
| 14078 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 14079 | (struct lpfc_wcqe_release *)&wcqe); |
| 14080 | break; |
| 14081 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14082 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14083 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14084 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14085 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 14086 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 14087 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14088 | case CQE_CODE_RECEIVE_V1: |
| 14089 | case CQE_CODE_RECEIVE: |
| 14090 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14091 | if (cq->subtype == LPFC_NVMET) { |
| 14092 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 14093 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 14094 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14095 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14096 | default: |
| 14097 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14098 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14099 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 14100 | break; |
| 14101 | } |
| 14102 | return workposted; |
| 14103 | } |
| 14104 | |
| 14105 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14106 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14107 | * @phba: Pointer to HBA context object. |
| 14108 | * @eqe: Pointer to fast-path event queue entry. |
| 14109 | * |
| 14110 | * This routine process a event queue entry from the fast-path event queue. |
| 14111 | * It will check the MajorCode and MinorCode to determine this is for a |
| 14112 | * completion event on a completion queue, if not, an error shall be logged |
| 14113 | * and just return. Otherwise, it will get to the corresponding completion |
| 14114 | * queue and process all the entries on the completion queue, rearm the |
| 14115 | * completion queue, and then return. |
| 14116 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14117 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14118 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 14119 | struct lpfc_eqe *eqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14120 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14121 | struct lpfc_queue *cq = NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14122 | uint32_t qidx = eq->hdwq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14123 | uint16_t cqid, id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14124 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14125 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14126 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14127 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14128 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14129 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 14130 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14131 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14132 | } |
| 14133 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14134 | /* Get the reference to the corresponding CQ */ |
| 14135 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 14136 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14137 | /* Use the fast lookup method first */ |
| 14138 | if (cqid <= phba->sli4_hba.cq_max) { |
| 14139 | cq = phba->sli4_hba.cq_lookup[cqid]; |
| 14140 | if (cq) |
| 14141 | goto work_cq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14142 | } |
| 14143 | |
| 14144 | /* Next check for NVMET completion */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14145 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 14146 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 14147 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 14148 | /* Process NVMET unsol rcv */ |
| 14149 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 14150 | goto process_cq; |
| 14151 | } |
| 14152 | } |
| 14153 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14154 | if (phba->sli4_hba.nvmels_cq && |
| 14155 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 14156 | /* Process NVME unsol rcv */ |
| 14157 | cq = phba->sli4_hba.nvmels_cq; |
| 14158 | } |
| 14159 | |
| 14160 | /* Otherwise this is a Slow path event */ |
| 14161 | if (cq == NULL) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14162 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 14163 | phba->sli4_hba.hdwq[qidx].hba_eq); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14164 | return; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14165 | } |
| 14166 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14167 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14168 | if (unlikely(cqid != cq->queue_id)) { |
| 14169 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14170 | "0368 Miss-matched fast-path completion " |
| 14171 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 14172 | cqid, cq->queue_id); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14173 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14174 | } |
| 14175 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14176 | work_cq: |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14177 | #if defined(CONFIG_SCSI_LPFC_DEBUG_FS) |
| 14178 | if (phba->ktime_on) |
| 14179 | cq->isr_timestamp = ktime_get_ns(); |
| 14180 | else |
| 14181 | cq->isr_timestamp = 0; |
| 14182 | #endif |
James Smart | 45aa312 | 2019-01-28 11:14:29 -0800 | [diff] [blame] | 14183 | if (!queue_work_on(cq->chann, phba->wq, &cq->irqwork)) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14184 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14185 | "0363 Cannot schedule soft IRQ " |
| 14186 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 14187 | cqid, cq->queue_id, raw_smp_processor_id()); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14188 | } |
| 14189 | |
| 14190 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14191 | * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry |
| 14192 | * @cq: Pointer to CQ to be processed |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14193 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14194 | * This routine calls the cq processing routine with the handler for |
| 14195 | * fast path CQEs. |
| 14196 | * |
| 14197 | * The CQ routine returns two values: the first is the calling status, |
| 14198 | * which indicates whether work was queued to the background discovery |
| 14199 | * thread. If true, the routine should wakeup the discovery thread; |
| 14200 | * the second is the delay parameter. If non-zero, rather than rearming |
| 14201 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 14202 | * that it is processed in a subsequent polling action. The value of |
| 14203 | * the delay indicates when to reschedule it. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14204 | **/ |
| 14205 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14206 | __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14207 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14208 | struct lpfc_hba *phba = cq->phba; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14209 | unsigned long delay; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14210 | bool workposted = false; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14211 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14212 | /* process and rearm the CQ */ |
| 14213 | workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe, |
| 14214 | &delay); |
| 14215 | |
| 14216 | if (delay) { |
| 14217 | if (!queue_delayed_work_on(cq->chann, phba->wq, |
| 14218 | &cq->sched_irqwork, delay)) |
| 14219 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14220 | "0367 Cannot schedule soft IRQ " |
| 14221 | "for cqid=%d on CPU %d\n", |
| 14222 | cq->queue_id, cq->chann); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14223 | } |
| 14224 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14225 | /* wake up worker thread if there are works to be done */ |
| 14226 | if (workposted) |
| 14227 | lpfc_worker_wake_up(phba); |
| 14228 | } |
| 14229 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14230 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14231 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by |
| 14232 | * interrupt |
| 14233 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14234 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14235 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14236 | **/ |
| 14237 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14238 | lpfc_sli4_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14239 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14240 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14241 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14242 | __lpfc_sli4_hba_process_cq(cq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14243 | } |
| 14244 | |
| 14245 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14246 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by timer |
| 14247 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14248 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14249 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14250 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14251 | static void |
| 14252 | lpfc_sli4_dly_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14253 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14254 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 14255 | struct lpfc_queue, sched_irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14256 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14257 | __lpfc_sli4_hba_process_cq(cq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14258 | } |
| 14259 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14260 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14261 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14262 | * @irq: Interrupt number. |
| 14263 | * @dev_id: The device context pointer. |
| 14264 | * |
| 14265 | * This function is directly called from the PCI layer as an interrupt |
| 14266 | * service routine when device with SLI-4 interface spec is enabled with |
| 14267 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 14268 | * ring event in the HBA. However, when the device is enabled with either |
| 14269 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 14270 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 14271 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 14272 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 14273 | * the intrrupt context. This function is called without any lock held. |
| 14274 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 14275 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 14276 | * equal to that of FCP CQ index. |
| 14277 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14278 | * The link attention and ELS ring attention events are handled |
| 14279 | * by the worker thread. The interrupt handler signals the worker thread |
| 14280 | * and returns for these events. This function is called without any lock |
| 14281 | * held. It gets the hbalock to access and update SLI data structures. |
| 14282 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14283 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 14284 | * returns IRQ_NONE. |
| 14285 | **/ |
| 14286 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14287 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14288 | { |
| 14289 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14290 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14291 | struct lpfc_queue *fpeq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14292 | unsigned long iflag; |
| 14293 | int ecount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14294 | int hba_eqidx; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14295 | struct lpfc_eq_intr_info *eqi; |
| 14296 | uint32_t icnt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14297 | |
| 14298 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14299 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 14300 | phba = hba_eq_hdl->phba; |
| 14301 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14302 | |
| 14303 | if (unlikely(!phba)) |
| 14304 | return IRQ_NONE; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14305 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 14306 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14307 | |
| 14308 | /* Get to the EQ struct associated with this vector */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14309 | fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14310 | if (unlikely(!fpeq)) |
| 14311 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14312 | |
| 14313 | /* Check device state for handling interrupt */ |
| 14314 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 14315 | /* Check again for link_state with lock held */ |
| 14316 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 14317 | if (phba->link_state < LPFC_LINK_DOWN) |
| 14318 | /* Flush, clear interrupt, and rearm the EQ */ |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 14319 | lpfc_sli4_eqcq_flush(phba, fpeq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14320 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 14321 | return IRQ_NONE; |
| 14322 | } |
| 14323 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14324 | eqi = phba->sli4_hba.eq_info; |
| 14325 | icnt = this_cpu_inc_return(eqi->icnt); |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 14326 | fpeq->last_cpu = raw_smp_processor_id(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14327 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14328 | if (icnt > LPFC_EQD_ISR_TRIGGER && |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 14329 | fpeq->q_flag & HBA_EQ_DELAY_CHK && |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14330 | phba->cfg_auto_imax && |
| 14331 | fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY && |
| 14332 | phba->sli.sli_flag & LPFC_SLI_USE_EQDR) |
| 14333 | 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] | 14334 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14335 | /* process and rearm the EQ */ |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14336 | ecount = lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14337 | |
| 14338 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14339 | fpeq->EQ_no_entry++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14340 | if (phba->intr_type == MSIX) |
| 14341 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 14342 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14343 | "0358 MSI-X interrupt with no EQE\n"); |
| 14344 | else |
| 14345 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 14346 | return IRQ_NONE; |
| 14347 | } |
| 14348 | |
| 14349 | return IRQ_HANDLED; |
| 14350 | } /* lpfc_sli4_fp_intr_handler */ |
| 14351 | |
| 14352 | /** |
| 14353 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 14354 | * @irq: Interrupt number. |
| 14355 | * @dev_id: The device context pointer. |
| 14356 | * |
| 14357 | * This function is the device-level interrupt handler to device with SLI-4 |
| 14358 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 14359 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 14360 | * driver attention. This function invokes the slow-path interrupt attention |
| 14361 | * handling function and fast-path interrupt attention handling function in |
| 14362 | * turn to process the relevant HBA attention events. This function is called |
| 14363 | * without any lock held. It gets the hbalock to access and update SLI data |
| 14364 | * structures. |
| 14365 | * |
| 14366 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 14367 | * returns IRQ_NONE. |
| 14368 | **/ |
| 14369 | irqreturn_t |
| 14370 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 14371 | { |
| 14372 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14373 | irqreturn_t hba_irq_rc; |
| 14374 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14375 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14376 | |
| 14377 | /* Get the driver's phba structure from the dev_id */ |
| 14378 | phba = (struct lpfc_hba *)dev_id; |
| 14379 | |
| 14380 | if (unlikely(!phba)) |
| 14381 | return IRQ_NONE; |
| 14382 | |
| 14383 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14384 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 14385 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14386 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14387 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14388 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14389 | if (hba_irq_rc == IRQ_HANDLED) |
| 14390 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14391 | } |
| 14392 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14393 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14394 | } /* lpfc_sli4_intr_handler */ |
| 14395 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14396 | void lpfc_sli4_poll_hbtimer(struct timer_list *t) |
| 14397 | { |
| 14398 | struct lpfc_hba *phba = from_timer(phba, t, cpuhp_poll_timer); |
| 14399 | struct lpfc_queue *eq; |
| 14400 | int i = 0; |
| 14401 | |
| 14402 | rcu_read_lock(); |
| 14403 | |
| 14404 | list_for_each_entry_rcu(eq, &phba->poll_list, _poll_list) |
| 14405 | i += lpfc_sli4_poll_eq(eq, LPFC_POLL_SLOWPATH); |
| 14406 | if (!list_empty(&phba->poll_list)) |
| 14407 | mod_timer(&phba->cpuhp_poll_timer, |
| 14408 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
| 14409 | |
| 14410 | rcu_read_unlock(); |
| 14411 | } |
| 14412 | |
| 14413 | inline int lpfc_sli4_poll_eq(struct lpfc_queue *eq, uint8_t path) |
| 14414 | { |
| 14415 | struct lpfc_hba *phba = eq->phba; |
| 14416 | int i = 0; |
| 14417 | |
| 14418 | /* |
| 14419 | * Unlocking an irq is one of the entry point to check |
| 14420 | * for re-schedule, but we are good for io submission |
| 14421 | * path as midlayer does a get_cpu to glue us in. Flush |
| 14422 | * out the invalidate queue so we can see the updated |
| 14423 | * value for flag. |
| 14424 | */ |
| 14425 | smp_rmb(); |
| 14426 | |
| 14427 | if (READ_ONCE(eq->mode) == LPFC_EQ_POLL) |
| 14428 | /* We will not likely get the completion for the caller |
| 14429 | * during this iteration but i guess that's fine. |
| 14430 | * Future io's coming on this eq should be able to |
| 14431 | * pick it up. As for the case of single io's, they |
| 14432 | * will be handled through a sched from polling timer |
| 14433 | * function which is currently triggered every 1msec. |
| 14434 | */ |
| 14435 | i = lpfc_sli4_process_eq(phba, eq, LPFC_QUEUE_NOARM); |
| 14436 | |
| 14437 | return i; |
| 14438 | } |
| 14439 | |
| 14440 | static inline void lpfc_sli4_add_to_poll_list(struct lpfc_queue *eq) |
| 14441 | { |
| 14442 | struct lpfc_hba *phba = eq->phba; |
| 14443 | |
| 14444 | if (list_empty(&phba->poll_list)) { |
| 14445 | timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0); |
| 14446 | /* kickstart slowpath processing for this eq */ |
| 14447 | mod_timer(&phba->cpuhp_poll_timer, |
| 14448 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
| 14449 | } |
| 14450 | |
| 14451 | list_add_rcu(&eq->_poll_list, &phba->poll_list); |
| 14452 | synchronize_rcu(); |
| 14453 | } |
| 14454 | |
| 14455 | static inline void lpfc_sli4_remove_from_poll_list(struct lpfc_queue *eq) |
| 14456 | { |
| 14457 | struct lpfc_hba *phba = eq->phba; |
| 14458 | |
| 14459 | /* Disable slowpath processing for this eq. Kick start the eq |
| 14460 | * by RE-ARMING the eq's ASAP |
| 14461 | */ |
| 14462 | list_del_rcu(&eq->_poll_list); |
| 14463 | synchronize_rcu(); |
| 14464 | |
| 14465 | if (list_empty(&phba->poll_list)) |
| 14466 | del_timer_sync(&phba->cpuhp_poll_timer); |
| 14467 | } |
| 14468 | |
James Smart | d480e57 | 2019-11-11 15:03:58 -0800 | [diff] [blame] | 14469 | void lpfc_sli4_cleanup_poll_list(struct lpfc_hba *phba) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14470 | { |
| 14471 | struct lpfc_queue *eq, *next; |
| 14472 | |
| 14473 | list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) |
| 14474 | list_del(&eq->_poll_list); |
| 14475 | |
| 14476 | INIT_LIST_HEAD(&phba->poll_list); |
| 14477 | synchronize_rcu(); |
| 14478 | } |
| 14479 | |
| 14480 | static inline void |
| 14481 | __lpfc_sli4_switch_eqmode(struct lpfc_queue *eq, uint8_t mode) |
| 14482 | { |
| 14483 | if (mode == eq->mode) |
| 14484 | return; |
| 14485 | /* |
| 14486 | * currently this function is only called during a hotplug |
| 14487 | * event and the cpu on which this function is executing |
| 14488 | * is going offline. By now the hotplug has instructed |
| 14489 | * the scheduler to remove this cpu from cpu active mask. |
| 14490 | * So we don't need to work about being put aside by the |
| 14491 | * scheduler for a high priority process. Yes, the inte- |
| 14492 | * rrupts could come but they are known to retire ASAP. |
| 14493 | */ |
| 14494 | |
| 14495 | /* Disable polling in the fastpath */ |
| 14496 | WRITE_ONCE(eq->mode, mode); |
| 14497 | /* flush out the store buffer */ |
| 14498 | smp_wmb(); |
| 14499 | |
| 14500 | /* |
| 14501 | * Add this eq to the polling list and start polling. For |
| 14502 | * a grace period both interrupt handler and poller will |
| 14503 | * try to process the eq _but_ that's fine. We have a |
| 14504 | * synchronization mechanism in place (queue_claimed) to |
| 14505 | * deal with it. This is just a draining phase for int- |
| 14506 | * errupt handler (not eq's) as we have guranteed through |
| 14507 | * barrier that all the CPUs have seen the new CQ_POLLED |
| 14508 | * state. which will effectively disable the REARMING of |
| 14509 | * the EQ. The whole idea is eq's die off eventually as |
| 14510 | * we are not rearming EQ's anymore. |
| 14511 | */ |
| 14512 | mode ? lpfc_sli4_add_to_poll_list(eq) : |
| 14513 | lpfc_sli4_remove_from_poll_list(eq); |
| 14514 | } |
| 14515 | |
| 14516 | void lpfc_sli4_start_polling(struct lpfc_queue *eq) |
| 14517 | { |
| 14518 | __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_POLL); |
| 14519 | } |
| 14520 | |
| 14521 | void lpfc_sli4_stop_polling(struct lpfc_queue *eq) |
| 14522 | { |
| 14523 | struct lpfc_hba *phba = eq->phba; |
| 14524 | |
| 14525 | __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_INTERRUPT); |
| 14526 | |
| 14527 | /* Kick start for the pending io's in h/w. |
| 14528 | * Once we switch back to interrupt processing on a eq |
| 14529 | * the io path completion will only arm eq's when it |
| 14530 | * receives a completion. But since eq's are in disa- |
| 14531 | * rmed state it doesn't receive a completion. This |
| 14532 | * creates a deadlock scenaro. |
| 14533 | */ |
| 14534 | phba->sli4_hba.sli4_write_eq_db(phba, eq, 0, LPFC_QUEUE_REARM); |
| 14535 | } |
| 14536 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14537 | /** |
| 14538 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 14539 | * @queue: The queue structure to free. |
| 14540 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 14541 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14542 | * the host resident queue. This function must be called after destroying the |
| 14543 | * queue on the HBA. |
| 14544 | **/ |
| 14545 | void |
| 14546 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 14547 | { |
| 14548 | struct lpfc_dmabuf *dmabuf; |
| 14549 | |
| 14550 | if (!queue) |
| 14551 | return; |
| 14552 | |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 14553 | if (!list_empty(&queue->wq_list)) |
| 14554 | list_del(&queue->wq_list); |
| 14555 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14556 | while (!list_empty(&queue->page_list)) { |
| 14557 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 14558 | list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14559 | dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14560 | dmabuf->virt, dmabuf->phys); |
| 14561 | kfree(dmabuf); |
| 14562 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14563 | if (queue->rqbp) { |
| 14564 | lpfc_free_rq_buffer(queue->phba, queue); |
| 14565 | kfree(queue->rqbp); |
| 14566 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 14567 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14568 | if (!list_empty(&queue->cpu_list)) |
| 14569 | list_del(&queue->cpu_list); |
| 14570 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14571 | kfree(queue); |
| 14572 | return; |
| 14573 | } |
| 14574 | |
| 14575 | /** |
| 14576 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 14577 | * @phba: The HBA that this queue is being created on. |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14578 | * @page_size: The size of a queue page |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14579 | * @entry_size: The size of each queue entry for this queue. |
| 14580 | * @entry count: The number of entries that this queue will handle. |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14581 | * @cpu: The cpu that will primarily utilize this queue. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14582 | * |
| 14583 | * This function allocates a queue structure and the DMAable memory used for |
| 14584 | * the host resident queue. This function must be called before creating the |
| 14585 | * queue on the HBA. |
| 14586 | **/ |
| 14587 | struct lpfc_queue * |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14588 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14589 | uint32_t entry_size, uint32_t entry_count, int cpu) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14590 | { |
| 14591 | struct lpfc_queue *queue; |
| 14592 | struct lpfc_dmabuf *dmabuf; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14593 | 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] | 14594 | uint16_t x, pgcnt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14595 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14596 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14597 | hw_page_size = page_size; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14598 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14599 | pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14600 | |
| 14601 | /* If needed, Adjust page count to match the max the adapter supports */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14602 | if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt) |
| 14603 | pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 14604 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14605 | queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt), |
| 14606 | GFP_KERNEL, cpu_to_node(cpu)); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14607 | if (!queue) |
| 14608 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14609 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14610 | INIT_LIST_HEAD(&queue->list); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14611 | INIT_LIST_HEAD(&queue->_poll_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14612 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 14613 | INIT_LIST_HEAD(&queue->wqfull_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14614 | INIT_LIST_HEAD(&queue->page_list); |
| 14615 | INIT_LIST_HEAD(&queue->child_list); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14616 | INIT_LIST_HEAD(&queue->cpu_list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14617 | |
| 14618 | /* Set queue parameters now. If the system cannot provide memory |
| 14619 | * resources, the free routine needs to know what was allocated. |
| 14620 | */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14621 | queue->page_count = pgcnt; |
| 14622 | queue->q_pgs = (void **)&queue[1]; |
| 14623 | queue->entry_cnt_per_pg = hw_page_size / entry_size; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14624 | queue->entry_size = entry_size; |
| 14625 | queue->entry_count = entry_count; |
| 14626 | queue->page_size = hw_page_size; |
| 14627 | queue->phba = phba; |
| 14628 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14629 | for (x = 0; x < queue->page_count; x++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14630 | dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL, |
| 14631 | dev_to_node(&phba->pcidev->dev)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14632 | if (!dmabuf) |
| 14633 | goto out_fail; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 14634 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 14635 | hw_page_size, &dmabuf->phys, |
| 14636 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14637 | if (!dmabuf->virt) { |
| 14638 | kfree(dmabuf); |
| 14639 | goto out_fail; |
| 14640 | } |
| 14641 | dmabuf->buffer_tag = x; |
| 14642 | list_add_tail(&dmabuf->list, &queue->page_list); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14643 | /* use lpfc_sli4_qe to index a paritcular entry in this page */ |
| 14644 | queue->q_pgs[x] = dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14645 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14646 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
| 14647 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14648 | INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq); |
| 14649 | INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14650 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14651 | /* notify_interval will be set during q creation */ |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14652 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14653 | return queue; |
| 14654 | out_fail: |
| 14655 | lpfc_sli4_queue_free(queue); |
| 14656 | return NULL; |
| 14657 | } |
| 14658 | |
| 14659 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14660 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 14661 | * @phba: HBA structure that indicates port to create a queue on. |
| 14662 | * @pci_barset: PCI BAR set flag. |
| 14663 | * |
| 14664 | * This function shall perform iomap of the specified PCI BAR address to host |
| 14665 | * memory address if not already done so and return it. The returned host |
| 14666 | * memory address can be NULL. |
| 14667 | */ |
| 14668 | static void __iomem * |
| 14669 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 14670 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14671 | if (!phba->pcidev) |
| 14672 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14673 | |
| 14674 | switch (pci_barset) { |
| 14675 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14676 | return phba->pci_bar0_memmap_p; |
| 14677 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14678 | return phba->pci_bar2_memmap_p; |
| 14679 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14680 | return phba->pci_bar4_memmap_p; |
| 14681 | default: |
| 14682 | break; |
| 14683 | } |
| 14684 | return NULL; |
| 14685 | } |
| 14686 | |
| 14687 | /** |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14688 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs |
| 14689 | * @phba: HBA structure that EQs are on. |
| 14690 | * @startq: The starting EQ index to modify |
| 14691 | * @numq: The number of EQs (consecutive indexes) to modify |
| 14692 | * @usdelay: amount of delay |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14693 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14694 | * This function revises the EQ delay on 1 or more EQs. The EQ delay |
| 14695 | * is set either by writing to a register (if supported by the SLI Port) |
| 14696 | * or by mailbox command. The mailbox command allows several EQs to be |
| 14697 | * updated at once. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14698 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14699 | * The @phba struct is used to send a mailbox command to HBA. The @startq |
| 14700 | * is used to get the starting EQ index to change. The @numq value is |
| 14701 | * used to specify how many consecutive EQ indexes, starting at EQ index, |
| 14702 | * are to be changed. This function is asynchronous and will wait for any |
| 14703 | * mailbox commands to finish before returning. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14704 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14705 | * On success this function will return a zero. If unable to allocate |
| 14706 | * enough memory this function will return -ENOMEM. If a mailbox command |
| 14707 | * fails this function will return -ENXIO. Note: on ENXIO, some EQs may |
| 14708 | * have had their delay multipler changed. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14709 | **/ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14710 | void |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14711 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14712 | uint32_t numq, uint32_t usdelay) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14713 | { |
| 14714 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 14715 | LPFC_MBOXQ_t *mbox; |
| 14716 | struct lpfc_queue *eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14717 | int cnt = 0, rc, length; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14718 | uint32_t shdr_status, shdr_add_status; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14719 | uint32_t dmult; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14720 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14721 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14722 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14723 | if (startq >= phba->cfg_irq_chann) |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14724 | return; |
| 14725 | |
| 14726 | if (usdelay > 0xFFFF) { |
| 14727 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME, |
| 14728 | "6429 usdelay %d too large. Scaled down to " |
| 14729 | "0xFFFF.\n", usdelay); |
| 14730 | usdelay = 0xFFFF; |
| 14731 | } |
| 14732 | |
| 14733 | /* set values by EQ_DELAY register if supported */ |
| 14734 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 14735 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14736 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14737 | if (!eq) |
| 14738 | continue; |
| 14739 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14740 | lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14741 | |
| 14742 | if (++cnt >= numq) |
| 14743 | break; |
| 14744 | } |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14745 | return; |
| 14746 | } |
| 14747 | |
| 14748 | /* Otherwise, set values by mailbox cmd */ |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14749 | |
| 14750 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14751 | if (!mbox) { |
| 14752 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_FCP | LOG_NVME, |
| 14753 | "6428 Failed allocating mailbox cmd buffer." |
| 14754 | " EQ delay was not set.\n"); |
| 14755 | return; |
| 14756 | } |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14757 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 14758 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14759 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14760 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 14761 | length, LPFC_SLI4_MBX_EMBED); |
| 14762 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 14763 | |
| 14764 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14765 | dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC; |
| 14766 | if (dmult) |
| 14767 | dmult--; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14768 | if (dmult > LPFC_DMULT_MAX) |
| 14769 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14770 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14771 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14772 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14773 | if (!eq) |
| 14774 | continue; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14775 | eq->q_mode = usdelay; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14776 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 14777 | eq_delay->u.request.eq[cnt].phase = 0; |
| 14778 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14779 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14780 | if (++cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14781 | break; |
| 14782 | } |
| 14783 | eq_delay->u.request.num_eq = cnt; |
| 14784 | |
| 14785 | mbox->vport = phba->pport; |
| 14786 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14787 | mbox->ctx_buf = NULL; |
| 14788 | mbox->ctx_ndlp = NULL; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14789 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14790 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 14791 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14792 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14793 | if (shdr_status || shdr_add_status || rc) { |
| 14794 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14795 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 14796 | "status x%x add_status x%x, mbx status x%x\n", |
| 14797 | shdr_status, shdr_add_status, rc); |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14798 | } |
| 14799 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14800 | return; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14801 | } |
| 14802 | |
| 14803 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14804 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 14805 | * @phba: HBA structure that indicates port to create a queue on. |
| 14806 | * @eq: The queue structure to use to create the event queue. |
| 14807 | * @imax: The maximum interrupt per second limit. |
| 14808 | * |
| 14809 | * This function creates an event queue, as detailed in @eq, on a port, |
| 14810 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 14811 | * |
| 14812 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 14813 | * is used to get the entry count and entry size that are necessary to |
| 14814 | * determine the number of pages to allocate and use for this queue. This |
| 14815 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 14816 | * event queue. This function is asynchronous and will wait for the mailbox |
| 14817 | * command to finish before continuing. |
| 14818 | * |
| 14819 | * 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] | 14820 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14821 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14822 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14823 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14824 | 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] | 14825 | { |
| 14826 | struct lpfc_mbx_eq_create *eq_create; |
| 14827 | LPFC_MBOXQ_t *mbox; |
| 14828 | int rc, length, status = 0; |
| 14829 | struct lpfc_dmabuf *dmabuf; |
| 14830 | uint32_t shdr_status, shdr_add_status; |
| 14831 | union lpfc_sli4_cfg_shdr *shdr; |
| 14832 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14833 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14834 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14835 | /* sanity check on queue memory */ |
| 14836 | if (!eq) |
| 14837 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14838 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14839 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14840 | |
| 14841 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14842 | if (!mbox) |
| 14843 | return -ENOMEM; |
| 14844 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 14845 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14846 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14847 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 14848 | length, LPFC_SLI4_MBX_EMBED); |
| 14849 | eq_create = &mbox->u.mqe.un.eq_create; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14850 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14851 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 14852 | eq->page_count); |
| 14853 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 14854 | LPFC_EQE_SIZE); |
| 14855 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14856 | |
| 14857 | /* Use version 2 of CREATE_EQ if eqav is set */ |
| 14858 | if (phba->sli4_hba.pc_sli4_params.eqav) { |
| 14859 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14860 | LPFC_Q_CREATE_VERSION_2); |
| 14861 | bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context, |
| 14862 | phba->sli4_hba.pc_sli4_params.eqav); |
| 14863 | } |
| 14864 | |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 14865 | /* don't setup delay multiplier using EQ_CREATE */ |
| 14866 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14867 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 14868 | dmult); |
| 14869 | switch (eq->entry_count) { |
| 14870 | default: |
| 14871 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14872 | "0360 Unsupported EQ count. (%d)\n", |
| 14873 | eq->entry_count); |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 14874 | if (eq->entry_count < 256) { |
| 14875 | status = -EINVAL; |
| 14876 | goto out; |
| 14877 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 14878 | /* fall through - otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14879 | case 256: |
| 14880 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14881 | LPFC_EQ_CNT_256); |
| 14882 | break; |
| 14883 | case 512: |
| 14884 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14885 | LPFC_EQ_CNT_512); |
| 14886 | break; |
| 14887 | case 1024: |
| 14888 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14889 | LPFC_EQ_CNT_1024); |
| 14890 | break; |
| 14891 | case 2048: |
| 14892 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14893 | LPFC_EQ_CNT_2048); |
| 14894 | break; |
| 14895 | case 4096: |
| 14896 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14897 | LPFC_EQ_CNT_4096); |
| 14898 | break; |
| 14899 | } |
| 14900 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14901 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14902 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14903 | putPaddrLow(dmabuf->phys); |
| 14904 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14905 | putPaddrHigh(dmabuf->phys); |
| 14906 | } |
| 14907 | mbox->vport = phba->pport; |
| 14908 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14909 | mbox->ctx_buf = NULL; |
| 14910 | mbox->ctx_ndlp = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14911 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14912 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14913 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14914 | if (shdr_status || shdr_add_status || rc) { |
| 14915 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14916 | "2500 EQ_CREATE mailbox failed with " |
| 14917 | "status x%x add_status x%x, mbx status x%x\n", |
| 14918 | shdr_status, shdr_add_status, rc); |
| 14919 | status = -ENXIO; |
| 14920 | } |
| 14921 | eq->type = LPFC_EQ; |
| 14922 | eq->subtype = LPFC_NONE; |
| 14923 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 14924 | if (eq->queue_id == 0xFFFF) |
| 14925 | status = -ENXIO; |
| 14926 | eq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14927 | eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL; |
| 14928 | eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT; |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 14929 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14930 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14931 | return status; |
| 14932 | } |
| 14933 | |
| 14934 | /** |
| 14935 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 14936 | * @phba: HBA structure that indicates port to create a queue on. |
| 14937 | * @cq: The queue structure to use to create the completion queue. |
| 14938 | * @eq: The event queue to bind this completion queue to. |
| 14939 | * |
| 14940 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 14941 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 14942 | * |
| 14943 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14944 | * is used to get the entry count and entry size that are necessary to |
| 14945 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14946 | * is used to indicate which event queue to bind this completion queue to. This |
| 14947 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 14948 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14949 | * command to finish before continuing. |
| 14950 | * |
| 14951 | * 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] | 14952 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14953 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14954 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14955 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14956 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14957 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 14958 | { |
| 14959 | struct lpfc_mbx_cq_create *cq_create; |
| 14960 | struct lpfc_dmabuf *dmabuf; |
| 14961 | LPFC_MBOXQ_t *mbox; |
| 14962 | int rc, length, status = 0; |
| 14963 | uint32_t shdr_status, shdr_add_status; |
| 14964 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14965 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14966 | /* sanity check on queue memory */ |
| 14967 | if (!cq || !eq) |
| 14968 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14969 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14970 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14971 | if (!mbox) |
| 14972 | return -ENOMEM; |
| 14973 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 14974 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14975 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14976 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 14977 | length, LPFC_SLI4_MBX_EMBED); |
| 14978 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14979 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14980 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 14981 | cq->page_count); |
| 14982 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 14983 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14984 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14985 | phba->sli4_hba.pc_sli4_params.cqv); |
| 14986 | 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] | 14987 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, |
| 14988 | (cq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14989 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 14990 | eq->queue_id); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14991 | bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context, |
| 14992 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14993 | } else { |
| 14994 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 14995 | eq->queue_id); |
| 14996 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14997 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14998 | case 2048: |
| 14999 | case 4096: |
| 15000 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 15001 | LPFC_Q_CREATE_VERSION_2) { |
| 15002 | cq_create->u.request.context.lpfc_cq_context_count = |
| 15003 | cq->entry_count; |
| 15004 | bf_set(lpfc_cq_context_count, |
| 15005 | &cq_create->u.request.context, |
| 15006 | LPFC_CQ_CNT_WORD7); |
| 15007 | break; |
| 15008 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15009 | /* fall through */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15010 | default: |
| 15011 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 15012 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15013 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 15014 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15015 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15016 | if (cq->entry_count < 256) { |
| 15017 | status = -EINVAL; |
| 15018 | goto out; |
| 15019 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15020 | /* fall through - otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15021 | case 256: |
| 15022 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15023 | LPFC_CQ_CNT_256); |
| 15024 | break; |
| 15025 | case 512: |
| 15026 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15027 | LPFC_CQ_CNT_512); |
| 15028 | break; |
| 15029 | case 1024: |
| 15030 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 15031 | LPFC_CQ_CNT_1024); |
| 15032 | break; |
| 15033 | } |
| 15034 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15035 | memset(dmabuf->virt, 0, cq->page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15036 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15037 | putPaddrLow(dmabuf->phys); |
| 15038 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15039 | putPaddrHigh(dmabuf->phys); |
| 15040 | } |
| 15041 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15042 | |
| 15043 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15044 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15045 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15046 | if (shdr_status || shdr_add_status || rc) { |
| 15047 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15048 | "2501 CQ_CREATE mailbox failed with " |
| 15049 | "status x%x add_status x%x, mbx status x%x\n", |
| 15050 | shdr_status, shdr_add_status, rc); |
| 15051 | status = -ENXIO; |
| 15052 | goto out; |
| 15053 | } |
| 15054 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 15055 | if (cq->queue_id == 0xFFFF) { |
| 15056 | status = -ENXIO; |
| 15057 | goto out; |
| 15058 | } |
| 15059 | /* link the cq onto the parent eq child list */ |
| 15060 | list_add_tail(&cq->list, &eq->child_list); |
| 15061 | /* Set up completion queue's type and subtype */ |
| 15062 | cq->type = type; |
| 15063 | cq->subtype = subtype; |
| 15064 | 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] | 15065 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15066 | cq->assoc_qp = eq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15067 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15068 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 15069 | 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] | 15070 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15071 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 15072 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15073 | out: |
| 15074 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15075 | return status; |
| 15076 | } |
| 15077 | |
| 15078 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15079 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 15080 | * @phba: HBA structure that indicates port to create a queue on. |
| 15081 | * @cqp: The queue structure array to use to create the completion queues. |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15082 | * @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] | 15083 | * |
| 15084 | * This function creates a set of completion queue, s to support MRQ |
| 15085 | * as detailed in @cqp, on a port, |
| 15086 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 15087 | * |
| 15088 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15089 | * is used to get the entry count and entry size that are necessary to |
| 15090 | * determine the number of pages to allocate and use for this queue. The @eq |
| 15091 | * is used to indicate which event queue to bind this completion queue to. This |
| 15092 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 15093 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 15094 | * command to finish before continuing. |
| 15095 | * |
| 15096 | * On success this function will return a zero. If unable to allocate enough |
| 15097 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15098 | * fails this function will return -ENXIO. |
| 15099 | **/ |
| 15100 | int |
| 15101 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15102 | struct lpfc_sli4_hdw_queue *hdwq, uint32_t type, |
| 15103 | uint32_t subtype) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15104 | { |
| 15105 | struct lpfc_queue *cq; |
| 15106 | struct lpfc_queue *eq; |
| 15107 | struct lpfc_mbx_cq_create_set *cq_set; |
| 15108 | struct lpfc_dmabuf *dmabuf; |
| 15109 | LPFC_MBOXQ_t *mbox; |
| 15110 | int rc, length, alloclen, status = 0; |
| 15111 | int cnt, idx, numcq, page_idx = 0; |
| 15112 | uint32_t shdr_status, shdr_add_status; |
| 15113 | union lpfc_sli4_cfg_shdr *shdr; |
| 15114 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15115 | |
| 15116 | /* sanity check on queue memory */ |
| 15117 | numcq = phba->cfg_nvmet_mrq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15118 | if (!cqp || !hdwq || !numcq) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15119 | return -ENODEV; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15120 | |
| 15121 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15122 | if (!mbox) |
| 15123 | return -ENOMEM; |
| 15124 | |
| 15125 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 15126 | length += ((numcq * cqp[0]->page_count) * |
| 15127 | sizeof(struct dma_address)); |
| 15128 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15129 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 15130 | LPFC_SLI4_MBX_NEMBED); |
| 15131 | if (alloclen < length) { |
| 15132 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15133 | "3098 Allocated DMA memory size (%d) is " |
| 15134 | "less than the requested DMA memory size " |
| 15135 | "(%d)\n", alloclen, length); |
| 15136 | status = -ENOMEM; |
| 15137 | goto out; |
| 15138 | } |
| 15139 | cq_set = mbox->sge_array->addr[0]; |
| 15140 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 15141 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 15142 | |
| 15143 | for (idx = 0; idx < numcq; idx++) { |
| 15144 | cq = cqp[idx]; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15145 | eq = hdwq[idx].hba_eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15146 | if (!cq || !eq) { |
| 15147 | status = -ENOMEM; |
| 15148 | goto out; |
| 15149 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15150 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15151 | hw_page_size = cq->page_size; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15152 | |
| 15153 | switch (idx) { |
| 15154 | case 0: |
| 15155 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 15156 | &cq_set->u.request, |
| 15157 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 15158 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 15159 | &cq_set->u.request, cq->page_count); |
| 15160 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 15161 | &cq_set->u.request, 1); |
| 15162 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 15163 | &cq_set->u.request, 1); |
| 15164 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 15165 | &cq_set->u.request, 0); |
| 15166 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 15167 | &cq_set->u.request, numcq); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 15168 | bf_set(lpfc_mbx_cq_create_set_autovalid, |
| 15169 | &cq_set->u.request, |
| 15170 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15171 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15172 | case 2048: |
| 15173 | case 4096: |
| 15174 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 15175 | LPFC_Q_CREATE_VERSION_2) { |
| 15176 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15177 | &cq_set->u.request, |
| 15178 | cq->entry_count); |
| 15179 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15180 | &cq_set->u.request, |
| 15181 | LPFC_CQ_CNT_WORD7); |
| 15182 | break; |
| 15183 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15184 | /* fall through */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15185 | default: |
| 15186 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15187 | "3118 Bad CQ count. (%d)\n", |
| 15188 | cq->entry_count); |
| 15189 | if (cq->entry_count < 256) { |
| 15190 | status = -EINVAL; |
| 15191 | goto out; |
| 15192 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15193 | /* fall through - otherwise default to smallest */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15194 | case 256: |
| 15195 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15196 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 15197 | break; |
| 15198 | case 512: |
| 15199 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15200 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 15201 | break; |
| 15202 | case 1024: |
| 15203 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15204 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 15205 | break; |
| 15206 | } |
| 15207 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 15208 | &cq_set->u.request, eq->queue_id); |
| 15209 | break; |
| 15210 | case 1: |
| 15211 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 15212 | &cq_set->u.request, eq->queue_id); |
| 15213 | break; |
| 15214 | case 2: |
| 15215 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 15216 | &cq_set->u.request, eq->queue_id); |
| 15217 | break; |
| 15218 | case 3: |
| 15219 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 15220 | &cq_set->u.request, eq->queue_id); |
| 15221 | break; |
| 15222 | case 4: |
| 15223 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 15224 | &cq_set->u.request, eq->queue_id); |
| 15225 | break; |
| 15226 | case 5: |
| 15227 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 15228 | &cq_set->u.request, eq->queue_id); |
| 15229 | break; |
| 15230 | case 6: |
| 15231 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 15232 | &cq_set->u.request, eq->queue_id); |
| 15233 | break; |
| 15234 | case 7: |
| 15235 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 15236 | &cq_set->u.request, eq->queue_id); |
| 15237 | break; |
| 15238 | case 8: |
| 15239 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 15240 | &cq_set->u.request, eq->queue_id); |
| 15241 | break; |
| 15242 | case 9: |
| 15243 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 15244 | &cq_set->u.request, eq->queue_id); |
| 15245 | break; |
| 15246 | case 10: |
| 15247 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 15248 | &cq_set->u.request, eq->queue_id); |
| 15249 | break; |
| 15250 | case 11: |
| 15251 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 15252 | &cq_set->u.request, eq->queue_id); |
| 15253 | break; |
| 15254 | case 12: |
| 15255 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 15256 | &cq_set->u.request, eq->queue_id); |
| 15257 | break; |
| 15258 | case 13: |
| 15259 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 15260 | &cq_set->u.request, eq->queue_id); |
| 15261 | break; |
| 15262 | case 14: |
| 15263 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 15264 | &cq_set->u.request, eq->queue_id); |
| 15265 | break; |
| 15266 | case 15: |
| 15267 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 15268 | &cq_set->u.request, eq->queue_id); |
| 15269 | break; |
| 15270 | } |
| 15271 | |
| 15272 | /* link the cq onto the parent eq child list */ |
| 15273 | list_add_tail(&cq->list, &eq->child_list); |
| 15274 | /* Set up completion queue's type and subtype */ |
| 15275 | cq->type = type; |
| 15276 | cq->subtype = subtype; |
| 15277 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15278 | cq->assoc_qp = eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15279 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15280 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 15281 | cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, |
| 15282 | cq->entry_count); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15283 | cq->chann = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15284 | |
| 15285 | rc = 0; |
| 15286 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 15287 | memset(dmabuf->virt, 0, hw_page_size); |
| 15288 | cnt = page_idx + dmabuf->buffer_tag; |
| 15289 | cq_set->u.request.page[cnt].addr_lo = |
| 15290 | putPaddrLow(dmabuf->phys); |
| 15291 | cq_set->u.request.page[cnt].addr_hi = |
| 15292 | putPaddrHigh(dmabuf->phys); |
| 15293 | rc++; |
| 15294 | } |
| 15295 | page_idx += rc; |
| 15296 | } |
| 15297 | |
| 15298 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15299 | |
| 15300 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15301 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15302 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15303 | if (shdr_status || shdr_add_status || rc) { |
| 15304 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15305 | "3119 CQ_CREATE_SET mailbox failed with " |
| 15306 | "status x%x add_status x%x, mbx status x%x\n", |
| 15307 | shdr_status, shdr_add_status, rc); |
| 15308 | status = -ENXIO; |
| 15309 | goto out; |
| 15310 | } |
| 15311 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 15312 | if (rc == 0xFFFF) { |
| 15313 | status = -ENXIO; |
| 15314 | goto out; |
| 15315 | } |
| 15316 | |
| 15317 | for (idx = 0; idx < numcq; idx++) { |
| 15318 | cq = cqp[idx]; |
| 15319 | cq->queue_id = rc + idx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15320 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 15321 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15322 | } |
| 15323 | |
| 15324 | out: |
| 15325 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 15326 | return status; |
| 15327 | } |
| 15328 | |
| 15329 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15330 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15331 | * @phba: HBA structure that indicates port to create a queue on. |
| 15332 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15333 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 15334 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15335 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15336 | * This function provides failback (fb) functionality when the |
| 15337 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 15338 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15339 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15340 | * This routine cannot fail as all attributes were previously accessed and |
| 15341 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15342 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15343 | static void |
| 15344 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15345 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15346 | { |
| 15347 | struct lpfc_mbx_mq_create *mq_create; |
| 15348 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15349 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15350 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15351 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 15352 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15353 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15354 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 15355 | length, LPFC_SLI4_MBX_EMBED); |
| 15356 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15357 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15358 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15359 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15360 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15361 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 15362 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15363 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15364 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15365 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15366 | break; |
| 15367 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15368 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15369 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15370 | break; |
| 15371 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15372 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15373 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15374 | break; |
| 15375 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15376 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15377 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15378 | break; |
| 15379 | } |
| 15380 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 15381 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15382 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15383 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15384 | putPaddrHigh(dmabuf->phys); |
| 15385 | } |
| 15386 | } |
| 15387 | |
| 15388 | /** |
| 15389 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 15390 | * @phba: HBA structure that indicates port to create a queue on. |
| 15391 | * @mq: The queue structure to use to create the mailbox queue. |
| 15392 | * @cq: The completion queue to associate with this cq. |
| 15393 | * @subtype: The queue's subtype. |
| 15394 | * |
| 15395 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 15396 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 15397 | * |
| 15398 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15399 | * is used to get the entry count and entry size that are necessary to |
| 15400 | * determine the number of pages to allocate and use for this queue. This |
| 15401 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 15402 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 15403 | * command to finish before continuing. |
| 15404 | * |
| 15405 | * 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] | 15406 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15407 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15408 | **/ |
| 15409 | int32_t |
| 15410 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15411 | struct lpfc_queue *cq, uint32_t subtype) |
| 15412 | { |
| 15413 | struct lpfc_mbx_mq_create *mq_create; |
| 15414 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 15415 | struct lpfc_dmabuf *dmabuf; |
| 15416 | LPFC_MBOXQ_t *mbox; |
| 15417 | int rc, length, status = 0; |
| 15418 | uint32_t shdr_status, shdr_add_status; |
| 15419 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15420 | 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] | 15421 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15422 | /* sanity check on queue memory */ |
| 15423 | if (!mq || !cq) |
| 15424 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15425 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15426 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15427 | |
| 15428 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15429 | if (!mbox) |
| 15430 | return -ENOMEM; |
| 15431 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 15432 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15433 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15434 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 15435 | length, LPFC_SLI4_MBX_EMBED); |
| 15436 | |
| 15437 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15438 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15439 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 15440 | &mq_create_ext->u.request, mq->page_count); |
| 15441 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 15442 | &mq_create_ext->u.request, 1); |
| 15443 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15444 | &mq_create_ext->u.request, 1); |
| 15445 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 15446 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15447 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 15448 | &mq_create_ext->u.request, 1); |
| 15449 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 15450 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15451 | 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] | 15452 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15453 | phba->sli4_hba.pc_sli4_params.mqv); |
| 15454 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 15455 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 15456 | cq->queue_id); |
| 15457 | else |
| 15458 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 15459 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15460 | switch (mq->entry_count) { |
| 15461 | default: |
| 15462 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15463 | "0362 Unsupported MQ count. (%d)\n", |
| 15464 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15465 | if (mq->entry_count < 16) { |
| 15466 | status = -EINVAL; |
| 15467 | goto out; |
| 15468 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15469 | /* fall through - otherwise default to smallest count */ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15470 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15471 | bf_set(lpfc_mq_context_ring_size, |
| 15472 | &mq_create_ext->u.request.context, |
| 15473 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15474 | break; |
| 15475 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15476 | bf_set(lpfc_mq_context_ring_size, |
| 15477 | &mq_create_ext->u.request.context, |
| 15478 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15479 | break; |
| 15480 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15481 | bf_set(lpfc_mq_context_ring_size, |
| 15482 | &mq_create_ext->u.request.context, |
| 15483 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15484 | break; |
| 15485 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15486 | bf_set(lpfc_mq_context_ring_size, |
| 15487 | &mq_create_ext->u.request.context, |
| 15488 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15489 | break; |
| 15490 | } |
| 15491 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15492 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15493 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15494 | putPaddrLow(dmabuf->phys); |
| 15495 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15496 | putPaddrHigh(dmabuf->phys); |
| 15497 | } |
| 15498 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15499 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15500 | &mq_create_ext->u.response); |
| 15501 | if (rc != MBX_SUCCESS) { |
| 15502 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15503 | "2795 MQ_CREATE_EXT failed with " |
| 15504 | "status x%x. Failback to MQ_CREATE.\n", |
| 15505 | rc); |
| 15506 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 15507 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15508 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15509 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 15510 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15511 | &mq_create->u.response); |
| 15512 | } |
| 15513 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15514 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15515 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15516 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15517 | if (shdr_status || shdr_add_status || rc) { |
| 15518 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15519 | "2502 MQ_CREATE mailbox failed with " |
| 15520 | "status x%x add_status x%x, mbx status x%x\n", |
| 15521 | shdr_status, shdr_add_status, rc); |
| 15522 | status = -ENXIO; |
| 15523 | goto out; |
| 15524 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15525 | if (mq->queue_id == 0xFFFF) { |
| 15526 | status = -ENXIO; |
| 15527 | goto out; |
| 15528 | } |
| 15529 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15530 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15531 | mq->subtype = subtype; |
| 15532 | mq->host_index = 0; |
| 15533 | mq->hba_index = 0; |
| 15534 | |
| 15535 | /* link the mq onto the parent cq child list */ |
| 15536 | list_add_tail(&mq->list, &cq->child_list); |
| 15537 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15538 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15539 | return status; |
| 15540 | } |
| 15541 | |
| 15542 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15543 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 15544 | * @phba: HBA structure that indicates port to create a queue on. |
| 15545 | * @wq: The queue structure to use to create the work queue. |
| 15546 | * @cq: The completion queue to bind this work queue to. |
| 15547 | * @subtype: The subtype of the work queue indicating its functionality. |
| 15548 | * |
| 15549 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 15550 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 15551 | * |
| 15552 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 15553 | * is used to get the entry count and entry size that are necessary to |
| 15554 | * determine the number of pages to allocate and use for this queue. The @cq |
| 15555 | * is used to indicate which completion queue to bind this work queue to. This |
| 15556 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 15557 | * work queue. This function is asynchronous and will wait for the mailbox |
| 15558 | * command to finish before continuing. |
| 15559 | * |
| 15560 | * 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] | 15561 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15562 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15563 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15564 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15565 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 15566 | struct lpfc_queue *cq, uint32_t subtype) |
| 15567 | { |
| 15568 | struct lpfc_mbx_wq_create *wq_create; |
| 15569 | struct lpfc_dmabuf *dmabuf; |
| 15570 | LPFC_MBOXQ_t *mbox; |
| 15571 | int rc, length, status = 0; |
| 15572 | uint32_t shdr_status, shdr_add_status; |
| 15573 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15574 | 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] | 15575 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15576 | void __iomem *bar_memmap_p; |
| 15577 | uint32_t db_offset; |
| 15578 | uint16_t pci_barset; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15579 | uint8_t dpp_barset; |
| 15580 | uint32_t dpp_offset; |
| 15581 | unsigned long pg_addr; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15582 | uint8_t wq_create_version; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15583 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15584 | /* sanity check on queue memory */ |
| 15585 | if (!wq || !cq) |
| 15586 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15587 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15588 | hw_page_size = wq->page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15589 | |
| 15590 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15591 | if (!mbox) |
| 15592 | return -ENOMEM; |
| 15593 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 15594 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15595 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15596 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 15597 | length, LPFC_SLI4_MBX_EMBED); |
| 15598 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15599 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15600 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 15601 | wq->page_count); |
| 15602 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 15603 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15604 | |
| 15605 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15606 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15607 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15608 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 15609 | if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) || |
| 15610 | (wq->page_size > SLI4_PAGE_SIZE)) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15611 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15612 | else |
| 15613 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15614 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15615 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15616 | if (phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) |
| 15617 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15618 | else |
| 15619 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15620 | |
| 15621 | switch (wq_create_version) { |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15622 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15623 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 15624 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 15625 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15626 | LPFC_Q_CREATE_VERSION_1); |
| 15627 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15628 | switch (wq->entry_size) { |
| 15629 | default: |
| 15630 | case 64: |
| 15631 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15632 | &wq_create->u.request_1, |
| 15633 | LPFC_WQ_WQE_SIZE_64); |
| 15634 | break; |
| 15635 | case 128: |
| 15636 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15637 | &wq_create->u.request_1, |
| 15638 | LPFC_WQ_WQE_SIZE_128); |
| 15639 | break; |
| 15640 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15641 | /* Request DPP by default */ |
| 15642 | 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] | 15643 | bf_set(lpfc_mbx_wq_create_page_size, |
| 15644 | &wq_create->u.request_1, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15645 | (wq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15646 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15647 | break; |
| 15648 | default: |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15649 | page = wq_create->u.request.page; |
| 15650 | break; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15651 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15652 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15653 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15654 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15655 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 15656 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15657 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15658 | |
| 15659 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15660 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 15661 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15662 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15663 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15664 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15665 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15666 | if (shdr_status || shdr_add_status || rc) { |
| 15667 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15668 | "2503 WQ_CREATE mailbox failed with " |
| 15669 | "status x%x add_status x%x, mbx status x%x\n", |
| 15670 | shdr_status, shdr_add_status, rc); |
| 15671 | status = -ENXIO; |
| 15672 | goto out; |
| 15673 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15674 | |
| 15675 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) |
| 15676 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, |
| 15677 | &wq_create->u.response); |
| 15678 | else |
| 15679 | wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id, |
| 15680 | &wq_create->u.response_1); |
| 15681 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15682 | if (wq->queue_id == 0xFFFF) { |
| 15683 | status = -ENXIO; |
| 15684 | goto out; |
| 15685 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15686 | |
| 15687 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 15688 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) { |
| 15689 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15690 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 15691 | &wq_create->u.response); |
| 15692 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15693 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15694 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15695 | "3265 WQ[%d] doorbell format " |
| 15696 | "not supported: x%x\n", |
| 15697 | wq->queue_id, wq->db_format); |
| 15698 | status = -EINVAL; |
| 15699 | goto out; |
| 15700 | } |
| 15701 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 15702 | &wq_create->u.response); |
| 15703 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15704 | pci_barset); |
| 15705 | if (!bar_memmap_p) { |
| 15706 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15707 | "3263 WQ[%d] failed to memmap " |
| 15708 | "pci barset:x%x\n", |
| 15709 | wq->queue_id, pci_barset); |
| 15710 | status = -ENOMEM; |
| 15711 | goto out; |
| 15712 | } |
| 15713 | db_offset = wq_create->u.response.doorbell_offset; |
| 15714 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 15715 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 15716 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15717 | "3252 WQ[%d] doorbell offset " |
| 15718 | "not supported: x%x\n", |
| 15719 | wq->queue_id, db_offset); |
| 15720 | status = -EINVAL; |
| 15721 | goto out; |
| 15722 | } |
| 15723 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15724 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15725 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 15726 | "format:x%x\n", wq->queue_id, |
| 15727 | pci_barset, db_offset, wq->db_format); |
| 15728 | } else |
| 15729 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15730 | } else { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15731 | /* Check if DPP was honored by the firmware */ |
| 15732 | wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp, |
| 15733 | &wq_create->u.response_1); |
| 15734 | if (wq->dpp_enable) { |
| 15735 | pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set, |
| 15736 | &wq_create->u.response_1); |
| 15737 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15738 | pci_barset); |
| 15739 | if (!bar_memmap_p) { |
| 15740 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15741 | "3267 WQ[%d] failed to memmap " |
| 15742 | "pci barset:x%x\n", |
| 15743 | wq->queue_id, pci_barset); |
| 15744 | status = -ENOMEM; |
| 15745 | goto out; |
| 15746 | } |
| 15747 | db_offset = wq_create->u.response_1.doorbell_offset; |
| 15748 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15749 | wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id, |
| 15750 | &wq_create->u.response_1); |
| 15751 | dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar, |
| 15752 | &wq_create->u.response_1); |
| 15753 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15754 | dpp_barset); |
| 15755 | if (!bar_memmap_p) { |
| 15756 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15757 | "3268 WQ[%d] failed to memmap " |
| 15758 | "pci barset:x%x\n", |
| 15759 | wq->queue_id, dpp_barset); |
| 15760 | status = -ENOMEM; |
| 15761 | goto out; |
| 15762 | } |
| 15763 | dpp_offset = wq_create->u.response_1.dpp_offset; |
| 15764 | wq->dpp_regaddr = bar_memmap_p + dpp_offset; |
| 15765 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15766 | "3271 WQ[%d]: barset:x%x, offset:x%x, " |
| 15767 | "dpp_id:x%x dpp_barset:x%x " |
| 15768 | "dpp_offset:x%x\n", |
| 15769 | wq->queue_id, pci_barset, db_offset, |
| 15770 | wq->dpp_id, dpp_barset, dpp_offset); |
| 15771 | |
| 15772 | /* Enable combined writes for DPP aperture */ |
| 15773 | pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK; |
| 15774 | #ifdef CONFIG_X86 |
| 15775 | rc = set_memory_wc(pg_addr, 1); |
| 15776 | if (rc) { |
| 15777 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15778 | "3272 Cannot setup Combined " |
| 15779 | "Write on WQ[%d] - disable DPP\n", |
| 15780 | wq->queue_id); |
| 15781 | phba->cfg_enable_dpp = 0; |
| 15782 | } |
| 15783 | #else |
| 15784 | phba->cfg_enable_dpp = 0; |
| 15785 | #endif |
| 15786 | } else |
| 15787 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15788 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15789 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 15790 | if (wq->pring == NULL) { |
| 15791 | status = -ENOMEM; |
| 15792 | goto out; |
| 15793 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15794 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15795 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15796 | wq->subtype = subtype; |
| 15797 | wq->host_index = 0; |
| 15798 | wq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15799 | wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15800 | |
| 15801 | /* link the wq onto the parent cq child list */ |
| 15802 | list_add_tail(&wq->list, &cq->child_list); |
| 15803 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15804 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15805 | return status; |
| 15806 | } |
| 15807 | |
| 15808 | /** |
| 15809 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 15810 | * @phba: HBA structure that indicates port to create a queue on. |
| 15811 | * @hrq: The queue structure to use to create the header receive queue. |
| 15812 | * @drq: The queue structure to use to create the data receive queue. |
| 15813 | * @cq: The completion queue to bind this work queue to. |
| 15814 | * |
| 15815 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15816 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15817 | * to the HBA. |
| 15818 | * |
| 15819 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15820 | * struct is used to get the entry count that is necessary to determine the |
| 15821 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15822 | * completion queue to bind received buffers that are posted to these queues to. |
| 15823 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15824 | * receive queue pair. This function is asynchronous and will wait for the |
| 15825 | * mailbox command to finish before continuing. |
| 15826 | * |
| 15827 | * 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] | 15828 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15829 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15830 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15831 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15832 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15833 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 15834 | { |
| 15835 | struct lpfc_mbx_rq_create *rq_create; |
| 15836 | struct lpfc_dmabuf *dmabuf; |
| 15837 | LPFC_MBOXQ_t *mbox; |
| 15838 | int rc, length, status = 0; |
| 15839 | uint32_t shdr_status, shdr_add_status; |
| 15840 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15841 | 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] | 15842 | void __iomem *bar_memmap_p; |
| 15843 | uint32_t db_offset; |
| 15844 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15845 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15846 | /* sanity check on queue memory */ |
| 15847 | if (!hrq || !drq || !cq) |
| 15848 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15849 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15850 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15851 | |
| 15852 | if (hrq->entry_count != drq->entry_count) |
| 15853 | return -EINVAL; |
| 15854 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15855 | if (!mbox) |
| 15856 | return -ENOMEM; |
| 15857 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 15858 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15859 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15860 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15861 | length, LPFC_SLI4_MBX_EMBED); |
| 15862 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15863 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15864 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15865 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15866 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15867 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15868 | &rq_create->u.request.context, |
| 15869 | hrq->entry_count); |
| 15870 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15871 | bf_set(lpfc_rq_context_rqe_size, |
| 15872 | &rq_create->u.request.context, |
| 15873 | LPFC_RQE_SIZE_8); |
| 15874 | bf_set(lpfc_rq_context_page_size, |
| 15875 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 15876 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15877 | } else { |
| 15878 | switch (hrq->entry_count) { |
| 15879 | default: |
| 15880 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15881 | "2535 Unsupported RQ count. (%d)\n", |
| 15882 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15883 | if (hrq->entry_count < 512) { |
| 15884 | status = -EINVAL; |
| 15885 | goto out; |
| 15886 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15887 | /* fall through - otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15888 | case 512: |
| 15889 | bf_set(lpfc_rq_context_rqe_count, |
| 15890 | &rq_create->u.request.context, |
| 15891 | LPFC_RQ_RING_SIZE_512); |
| 15892 | break; |
| 15893 | case 1024: |
| 15894 | bf_set(lpfc_rq_context_rqe_count, |
| 15895 | &rq_create->u.request.context, |
| 15896 | LPFC_RQ_RING_SIZE_1024); |
| 15897 | break; |
| 15898 | case 2048: |
| 15899 | bf_set(lpfc_rq_context_rqe_count, |
| 15900 | &rq_create->u.request.context, |
| 15901 | LPFC_RQ_RING_SIZE_2048); |
| 15902 | break; |
| 15903 | case 4096: |
| 15904 | bf_set(lpfc_rq_context_rqe_count, |
| 15905 | &rq_create->u.request.context, |
| 15906 | LPFC_RQ_RING_SIZE_4096); |
| 15907 | break; |
| 15908 | } |
| 15909 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 15910 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15911 | } |
| 15912 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15913 | cq->queue_id); |
| 15914 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15915 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15916 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15917 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15918 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15919 | putPaddrLow(dmabuf->phys); |
| 15920 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15921 | putPaddrHigh(dmabuf->phys); |
| 15922 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15923 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15924 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 15925 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15926 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15927 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15928 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15929 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15930 | if (shdr_status || shdr_add_status || rc) { |
| 15931 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15932 | "2504 RQ_CREATE mailbox failed with " |
| 15933 | "status x%x add_status x%x, mbx status x%x\n", |
| 15934 | shdr_status, shdr_add_status, rc); |
| 15935 | status = -ENXIO; |
| 15936 | goto out; |
| 15937 | } |
| 15938 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15939 | if (hrq->queue_id == 0xFFFF) { |
| 15940 | status = -ENXIO; |
| 15941 | goto out; |
| 15942 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15943 | |
| 15944 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15945 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 15946 | &rq_create->u.response); |
| 15947 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15948 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15949 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15950 | "3262 RQ [%d] doorbell format not " |
| 15951 | "supported: x%x\n", hrq->queue_id, |
| 15952 | hrq->db_format); |
| 15953 | status = -EINVAL; |
| 15954 | goto out; |
| 15955 | } |
| 15956 | |
| 15957 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 15958 | &rq_create->u.response); |
| 15959 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 15960 | if (!bar_memmap_p) { |
| 15961 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15962 | "3269 RQ[%d] failed to memmap pci " |
| 15963 | "barset:x%x\n", hrq->queue_id, |
| 15964 | pci_barset); |
| 15965 | status = -ENOMEM; |
| 15966 | goto out; |
| 15967 | } |
| 15968 | |
| 15969 | db_offset = rq_create->u.response.doorbell_offset; |
| 15970 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 15971 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 15972 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15973 | "3270 RQ[%d] doorbell offset not " |
| 15974 | "supported: x%x\n", hrq->queue_id, |
| 15975 | db_offset); |
| 15976 | status = -EINVAL; |
| 15977 | goto out; |
| 15978 | } |
| 15979 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 15980 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 15981 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 15982 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 15983 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15984 | } else { |
| 15985 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15986 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15987 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15988 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15989 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15990 | hrq->subtype = subtype; |
| 15991 | hrq->host_index = 0; |
| 15992 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15993 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15994 | |
| 15995 | /* now create the data queue */ |
| 15996 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15997 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15998 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15999 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 16000 | phba->sli4_hba.pc_sli4_params.rqv); |
| 16001 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 16002 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 16003 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16004 | if (subtype == LPFC_NVMET) |
| 16005 | rq_create->u.request.context.buffer_size = |
| 16006 | LPFC_NVMET_DATA_BUF_SIZE; |
| 16007 | else |
| 16008 | rq_create->u.request.context.buffer_size = |
| 16009 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 16010 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 16011 | LPFC_RQE_SIZE_8); |
| 16012 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 16013 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16014 | } else { |
| 16015 | switch (drq->entry_count) { |
| 16016 | default: |
| 16017 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16018 | "2536 Unsupported RQ count. (%d)\n", |
| 16019 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 16020 | if (drq->entry_count < 512) { |
| 16021 | status = -EINVAL; |
| 16022 | goto out; |
| 16023 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 16024 | /* fall through - otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 16025 | case 512: |
| 16026 | bf_set(lpfc_rq_context_rqe_count, |
| 16027 | &rq_create->u.request.context, |
| 16028 | LPFC_RQ_RING_SIZE_512); |
| 16029 | break; |
| 16030 | case 1024: |
| 16031 | bf_set(lpfc_rq_context_rqe_count, |
| 16032 | &rq_create->u.request.context, |
| 16033 | LPFC_RQ_RING_SIZE_1024); |
| 16034 | break; |
| 16035 | case 2048: |
| 16036 | bf_set(lpfc_rq_context_rqe_count, |
| 16037 | &rq_create->u.request.context, |
| 16038 | LPFC_RQ_RING_SIZE_2048); |
| 16039 | break; |
| 16040 | case 4096: |
| 16041 | bf_set(lpfc_rq_context_rqe_count, |
| 16042 | &rq_create->u.request.context, |
| 16043 | LPFC_RQ_RING_SIZE_4096); |
| 16044 | break; |
| 16045 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16046 | if (subtype == LPFC_NVMET) |
| 16047 | bf_set(lpfc_rq_context_buf_size, |
| 16048 | &rq_create->u.request.context, |
| 16049 | LPFC_NVMET_DATA_BUF_SIZE); |
| 16050 | else |
| 16051 | bf_set(lpfc_rq_context_buf_size, |
| 16052 | &rq_create->u.request.context, |
| 16053 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16054 | } |
| 16055 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 16056 | cq->queue_id); |
| 16057 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 16058 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16059 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 16060 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 16061 | putPaddrLow(dmabuf->phys); |
| 16062 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 16063 | putPaddrHigh(dmabuf->phys); |
| 16064 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 16065 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 16066 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16067 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16068 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16069 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 16070 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16071 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16072 | if (shdr_status || shdr_add_status || rc) { |
| 16073 | status = -ENXIO; |
| 16074 | goto out; |
| 16075 | } |
| 16076 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16077 | if (drq->queue_id == 0xFFFF) { |
| 16078 | status = -ENXIO; |
| 16079 | goto out; |
| 16080 | } |
| 16081 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 16082 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16083 | drq->subtype = subtype; |
| 16084 | drq->host_index = 0; |
| 16085 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16086 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16087 | |
| 16088 | /* link the header and data RQs onto the parent cq child list */ |
| 16089 | list_add_tail(&hrq->list, &cq->child_list); |
| 16090 | list_add_tail(&drq->list, &cq->child_list); |
| 16091 | |
| 16092 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16093 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16094 | return status; |
| 16095 | } |
| 16096 | |
| 16097 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16098 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 16099 | * @phba: HBA structure that indicates port to create a queue on. |
| 16100 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 16101 | * @drqp: The queue structure array to use to create the data receive queues. |
| 16102 | * @cqp: The completion queue array to bind these receive queues to. |
| 16103 | * |
| 16104 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 16105 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 16106 | * to the HBA. |
| 16107 | * |
| 16108 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 16109 | * struct is used to get the entry count that is necessary to determine the |
| 16110 | * number of pages to use for this queue. The @cq is used to indicate which |
| 16111 | * completion queue to bind received buffers that are posted to these queues to. |
| 16112 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 16113 | * receive queue pair. This function is asynchronous and will wait for the |
| 16114 | * mailbox command to finish before continuing. |
| 16115 | * |
| 16116 | * On success this function will return a zero. If unable to allocate enough |
| 16117 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 16118 | * fails this function will return -ENXIO. |
| 16119 | **/ |
| 16120 | int |
| 16121 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 16122 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 16123 | uint32_t subtype) |
| 16124 | { |
| 16125 | struct lpfc_queue *hrq, *drq, *cq; |
| 16126 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 16127 | struct lpfc_dmabuf *dmabuf; |
| 16128 | LPFC_MBOXQ_t *mbox; |
| 16129 | int rc, length, alloclen, status = 0; |
| 16130 | int cnt, idx, numrq, page_idx = 0; |
| 16131 | uint32_t shdr_status, shdr_add_status; |
| 16132 | union lpfc_sli4_cfg_shdr *shdr; |
| 16133 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 16134 | |
| 16135 | numrq = phba->cfg_nvmet_mrq; |
| 16136 | /* sanity check on array memory */ |
| 16137 | if (!hrqp || !drqp || !cqp || !numrq) |
| 16138 | return -ENODEV; |
| 16139 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 16140 | hw_page_size = SLI4_PAGE_SIZE; |
| 16141 | |
| 16142 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16143 | if (!mbox) |
| 16144 | return -ENOMEM; |
| 16145 | |
| 16146 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 16147 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 16148 | sizeof(struct dma_address)); |
| 16149 | |
| 16150 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16151 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 16152 | LPFC_SLI4_MBX_NEMBED); |
| 16153 | if (alloclen < length) { |
| 16154 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16155 | "3099 Allocated DMA memory size (%d) is " |
| 16156 | "less than the requested DMA memory size " |
| 16157 | "(%d)\n", alloclen, length); |
| 16158 | status = -ENOMEM; |
| 16159 | goto out; |
| 16160 | } |
| 16161 | |
| 16162 | |
| 16163 | |
| 16164 | rq_create = mbox->sge_array->addr[0]; |
| 16165 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 16166 | |
| 16167 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 16168 | cnt = 0; |
| 16169 | |
| 16170 | for (idx = 0; idx < numrq; idx++) { |
| 16171 | hrq = hrqp[idx]; |
| 16172 | drq = drqp[idx]; |
| 16173 | cq = cqp[idx]; |
| 16174 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16175 | /* sanity check on queue memory */ |
| 16176 | if (!hrq || !drq || !cq) { |
| 16177 | status = -ENODEV; |
| 16178 | goto out; |
| 16179 | } |
| 16180 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 16181 | if (hrq->entry_count != drq->entry_count) { |
| 16182 | status = -EINVAL; |
| 16183 | goto out; |
| 16184 | } |
| 16185 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16186 | if (idx == 0) { |
| 16187 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 16188 | &rq_create->u.request, |
| 16189 | hrq->page_count); |
| 16190 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 16191 | &rq_create->u.request, (numrq * 2)); |
| 16192 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 16193 | 1); |
| 16194 | bf_set(lpfc_rq_context_base_cq, |
| 16195 | &rq_create->u.request.context, |
| 16196 | cq->queue_id); |
| 16197 | bf_set(lpfc_rq_context_data_size, |
| 16198 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16199 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16200 | bf_set(lpfc_rq_context_hdr_size, |
| 16201 | &rq_create->u.request.context, |
| 16202 | LPFC_HDR_BUF_SIZE); |
| 16203 | bf_set(lpfc_rq_context_rqe_count_1, |
| 16204 | &rq_create->u.request.context, |
| 16205 | hrq->entry_count); |
| 16206 | bf_set(lpfc_rq_context_rqe_size, |
| 16207 | &rq_create->u.request.context, |
| 16208 | LPFC_RQE_SIZE_8); |
| 16209 | bf_set(lpfc_rq_context_page_size, |
| 16210 | &rq_create->u.request.context, |
| 16211 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 16212 | } |
| 16213 | rc = 0; |
| 16214 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 16215 | memset(dmabuf->virt, 0, hw_page_size); |
| 16216 | cnt = page_idx + dmabuf->buffer_tag; |
| 16217 | rq_create->u.request.page[cnt].addr_lo = |
| 16218 | putPaddrLow(dmabuf->phys); |
| 16219 | rq_create->u.request.page[cnt].addr_hi = |
| 16220 | putPaddrHigh(dmabuf->phys); |
| 16221 | rc++; |
| 16222 | } |
| 16223 | page_idx += rc; |
| 16224 | |
| 16225 | rc = 0; |
| 16226 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 16227 | memset(dmabuf->virt, 0, hw_page_size); |
| 16228 | cnt = page_idx + dmabuf->buffer_tag; |
| 16229 | rq_create->u.request.page[cnt].addr_lo = |
| 16230 | putPaddrLow(dmabuf->phys); |
| 16231 | rq_create->u.request.page[cnt].addr_hi = |
| 16232 | putPaddrHigh(dmabuf->phys); |
| 16233 | rc++; |
| 16234 | } |
| 16235 | page_idx += rc; |
| 16236 | |
| 16237 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 16238 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16239 | hrq->type = LPFC_HRQ; |
| 16240 | hrq->assoc_qid = cq->queue_id; |
| 16241 | hrq->subtype = subtype; |
| 16242 | hrq->host_index = 0; |
| 16243 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16244 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16245 | |
| 16246 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 16247 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16248 | drq->type = LPFC_DRQ; |
| 16249 | drq->assoc_qid = cq->queue_id; |
| 16250 | drq->subtype = subtype; |
| 16251 | drq->host_index = 0; |
| 16252 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16253 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16254 | |
| 16255 | list_add_tail(&hrq->list, &cq->child_list); |
| 16256 | list_add_tail(&drq->list, &cq->child_list); |
| 16257 | } |
| 16258 | |
| 16259 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16260 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16261 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16262 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16263 | if (shdr_status || shdr_add_status || rc) { |
| 16264 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16265 | "3120 RQ_CREATE mailbox failed with " |
| 16266 | "status x%x add_status x%x, mbx status x%x\n", |
| 16267 | shdr_status, shdr_add_status, rc); |
| 16268 | status = -ENXIO; |
| 16269 | goto out; |
| 16270 | } |
| 16271 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16272 | if (rc == 0xFFFF) { |
| 16273 | status = -ENXIO; |
| 16274 | goto out; |
| 16275 | } |
| 16276 | |
| 16277 | /* Initialize all RQs with associated queue id */ |
| 16278 | for (idx = 0; idx < numrq; idx++) { |
| 16279 | hrq = hrqp[idx]; |
| 16280 | hrq->queue_id = rc + (2 * idx); |
| 16281 | drq = drqp[idx]; |
| 16282 | drq->queue_id = rc + (2 * idx) + 1; |
| 16283 | } |
| 16284 | |
| 16285 | out: |
| 16286 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16287 | return status; |
| 16288 | } |
| 16289 | |
| 16290 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16291 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 16292 | * @eq: The queue structure associated with the queue to destroy. |
| 16293 | * |
| 16294 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 16295 | * command, specific to the type of queue, to the HBA. |
| 16296 | * |
| 16297 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 16298 | * |
| 16299 | * 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] | 16300 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16301 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16302 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16303 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 16304 | { |
| 16305 | LPFC_MBOXQ_t *mbox; |
| 16306 | int rc, length, status = 0; |
| 16307 | uint32_t shdr_status, shdr_add_status; |
| 16308 | union lpfc_sli4_cfg_shdr *shdr; |
| 16309 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16310 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16311 | if (!eq) |
| 16312 | return -ENODEV; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16313 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16314 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16315 | if (!mbox) |
| 16316 | return -ENOMEM; |
| 16317 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 16318 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16319 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16320 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 16321 | length, LPFC_SLI4_MBX_EMBED); |
| 16322 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 16323 | eq->queue_id); |
| 16324 | mbox->vport = eq->phba->pport; |
| 16325 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16326 | |
| 16327 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 16328 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16329 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16330 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 16331 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16332 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16333 | if (shdr_status || shdr_add_status || rc) { |
| 16334 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16335 | "2505 EQ_DESTROY mailbox failed with " |
| 16336 | "status x%x add_status x%x, mbx status x%x\n", |
| 16337 | shdr_status, shdr_add_status, rc); |
| 16338 | status = -ENXIO; |
| 16339 | } |
| 16340 | |
| 16341 | /* Remove eq from any list */ |
| 16342 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16343 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16344 | return status; |
| 16345 | } |
| 16346 | |
| 16347 | /** |
| 16348 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 16349 | * @cq: The queue structure associated with the queue to destroy. |
| 16350 | * |
| 16351 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 16352 | * command, specific to the type of queue, to the HBA. |
| 16353 | * |
| 16354 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 16355 | * |
| 16356 | * 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] | 16357 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16358 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16359 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16360 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 16361 | { |
| 16362 | LPFC_MBOXQ_t *mbox; |
| 16363 | int rc, length, status = 0; |
| 16364 | uint32_t shdr_status, shdr_add_status; |
| 16365 | union lpfc_sli4_cfg_shdr *shdr; |
| 16366 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16367 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16368 | if (!cq) |
| 16369 | return -ENODEV; |
| 16370 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16371 | if (!mbox) |
| 16372 | return -ENOMEM; |
| 16373 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 16374 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16375 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16376 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 16377 | length, LPFC_SLI4_MBX_EMBED); |
| 16378 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 16379 | cq->queue_id); |
| 16380 | mbox->vport = cq->phba->pport; |
| 16381 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16382 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 16383 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16384 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16385 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 16386 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16387 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16388 | if (shdr_status || shdr_add_status || rc) { |
| 16389 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16390 | "2506 CQ_DESTROY mailbox failed with " |
| 16391 | "status x%x add_status x%x, mbx status x%x\n", |
| 16392 | shdr_status, shdr_add_status, rc); |
| 16393 | status = -ENXIO; |
| 16394 | } |
| 16395 | /* Remove cq from any list */ |
| 16396 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16397 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16398 | return status; |
| 16399 | } |
| 16400 | |
| 16401 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16402 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 16403 | * @qm: The queue structure associated with the queue to destroy. |
| 16404 | * |
| 16405 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 16406 | * command, specific to the type of queue, to the HBA. |
| 16407 | * |
| 16408 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 16409 | * |
| 16410 | * 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] | 16411 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16412 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16413 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16414 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 16415 | { |
| 16416 | LPFC_MBOXQ_t *mbox; |
| 16417 | int rc, length, status = 0; |
| 16418 | uint32_t shdr_status, shdr_add_status; |
| 16419 | union lpfc_sli4_cfg_shdr *shdr; |
| 16420 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16421 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16422 | if (!mq) |
| 16423 | return -ENODEV; |
| 16424 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16425 | if (!mbox) |
| 16426 | return -ENOMEM; |
| 16427 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 16428 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16429 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16430 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 16431 | length, LPFC_SLI4_MBX_EMBED); |
| 16432 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 16433 | mq->queue_id); |
| 16434 | mbox->vport = mq->phba->pport; |
| 16435 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16436 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 16437 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16438 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16439 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 16440 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16441 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16442 | if (shdr_status || shdr_add_status || rc) { |
| 16443 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16444 | "2507 MQ_DESTROY mailbox failed with " |
| 16445 | "status x%x add_status x%x, mbx status x%x\n", |
| 16446 | shdr_status, shdr_add_status, rc); |
| 16447 | status = -ENXIO; |
| 16448 | } |
| 16449 | /* Remove mq from any list */ |
| 16450 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16451 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16452 | return status; |
| 16453 | } |
| 16454 | |
| 16455 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16456 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 16457 | * @wq: The queue structure associated with the queue to destroy. |
| 16458 | * |
| 16459 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 16460 | * command, specific to the type of queue, to the HBA. |
| 16461 | * |
| 16462 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 16463 | * |
| 16464 | * 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] | 16465 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16466 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16467 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16468 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 16469 | { |
| 16470 | LPFC_MBOXQ_t *mbox; |
| 16471 | int rc, length, status = 0; |
| 16472 | uint32_t shdr_status, shdr_add_status; |
| 16473 | union lpfc_sli4_cfg_shdr *shdr; |
| 16474 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16475 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16476 | if (!wq) |
| 16477 | return -ENODEV; |
| 16478 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16479 | if (!mbox) |
| 16480 | return -ENOMEM; |
| 16481 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 16482 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16483 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16484 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 16485 | length, LPFC_SLI4_MBX_EMBED); |
| 16486 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 16487 | wq->queue_id); |
| 16488 | mbox->vport = wq->phba->pport; |
| 16489 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16490 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 16491 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16492 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 16493 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16494 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16495 | if (shdr_status || shdr_add_status || rc) { |
| 16496 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16497 | "2508 WQ_DESTROY mailbox failed with " |
| 16498 | "status x%x add_status x%x, mbx status x%x\n", |
| 16499 | shdr_status, shdr_add_status, rc); |
| 16500 | status = -ENXIO; |
| 16501 | } |
| 16502 | /* Remove wq from any list */ |
| 16503 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 16504 | kfree(wq->pring); |
| 16505 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16506 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16507 | return status; |
| 16508 | } |
| 16509 | |
| 16510 | /** |
| 16511 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 16512 | * @rq: The queue structure associated with the queue to destroy. |
| 16513 | * |
| 16514 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 16515 | * command, specific to the type of queue, to the HBA. |
| 16516 | * |
| 16517 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 16518 | * |
| 16519 | * 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] | 16520 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16521 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16522 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16523 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 16524 | struct lpfc_queue *drq) |
| 16525 | { |
| 16526 | LPFC_MBOXQ_t *mbox; |
| 16527 | int rc, length, status = 0; |
| 16528 | uint32_t shdr_status, shdr_add_status; |
| 16529 | union lpfc_sli4_cfg_shdr *shdr; |
| 16530 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16531 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16532 | if (!hrq || !drq) |
| 16533 | return -ENODEV; |
| 16534 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16535 | if (!mbox) |
| 16536 | return -ENOMEM; |
| 16537 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16538 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16539 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16540 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 16541 | length, LPFC_SLI4_MBX_EMBED); |
| 16542 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16543 | hrq->queue_id); |
| 16544 | mbox->vport = hrq->phba->pport; |
| 16545 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16546 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 16547 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16548 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16549 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16550 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16551 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16552 | if (shdr_status || shdr_add_status || rc) { |
| 16553 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16554 | "2509 RQ_DESTROY mailbox failed with " |
| 16555 | "status x%x add_status x%x, mbx status x%x\n", |
| 16556 | shdr_status, shdr_add_status, rc); |
| 16557 | if (rc != MBX_TIMEOUT) |
| 16558 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 16559 | return -ENXIO; |
| 16560 | } |
| 16561 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16562 | drq->queue_id); |
| 16563 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 16564 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16565 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16566 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16567 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16568 | if (shdr_status || shdr_add_status || rc) { |
| 16569 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16570 | "2510 RQ_DESTROY mailbox failed with " |
| 16571 | "status x%x add_status x%x, mbx status x%x\n", |
| 16572 | shdr_status, shdr_add_status, rc); |
| 16573 | status = -ENXIO; |
| 16574 | } |
| 16575 | list_del_init(&hrq->list); |
| 16576 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16577 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16578 | return status; |
| 16579 | } |
| 16580 | |
| 16581 | /** |
| 16582 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 16583 | * @phba: The virtual port for which this call being executed. |
| 16584 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 16585 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 16586 | * @xritag: the xritag that ties this io to the SGL pages. |
| 16587 | * |
| 16588 | * This routine will post the sgl pages for the IO that has the xritag |
| 16589 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 16590 | * creation and persists for as long as the driver is loaded. |
| 16591 | * if the caller has fewer than 256 scatter gather segments to map then |
| 16592 | * pdma_phys_addr1 should be 0. |
| 16593 | * If the caller needs to map more than 256 scatter gather segment then |
| 16594 | * pdma_phys_addr1 should be a valid physical address. |
| 16595 | * physical address for SGLs must be 64 byte aligned. |
| 16596 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 16597 | * the second sgl can have between 1 and 256 entries. |
| 16598 | * |
| 16599 | * Return codes: |
| 16600 | * 0 - Success |
| 16601 | * -ENXIO, -ENOMEM - Failure |
| 16602 | **/ |
| 16603 | int |
| 16604 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 16605 | dma_addr_t pdma_phys_addr0, |
| 16606 | dma_addr_t pdma_phys_addr1, |
| 16607 | uint16_t xritag) |
| 16608 | { |
| 16609 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 16610 | LPFC_MBOXQ_t *mbox; |
| 16611 | int rc; |
| 16612 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16613 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16614 | union lpfc_sli4_cfg_shdr *shdr; |
| 16615 | |
| 16616 | if (xritag == NO_XRI) { |
| 16617 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16618 | "0364 Invalid param:\n"); |
| 16619 | return -EINVAL; |
| 16620 | } |
| 16621 | |
| 16622 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16623 | if (!mbox) |
| 16624 | return -ENOMEM; |
| 16625 | |
| 16626 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16627 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16628 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16629 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16630 | |
| 16631 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 16632 | &mbox->u.mqe.un.post_sgl_pages; |
| 16633 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 16634 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 16635 | |
| 16636 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 16637 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 16638 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 16639 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 16640 | |
| 16641 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 16642 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 16643 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 16644 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 16645 | if (!phba->sli4_hba.intr_enable) |
| 16646 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16647 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16648 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16649 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16650 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16651 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16652 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 16653 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16654 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16655 | if (rc != MBX_TIMEOUT) |
| 16656 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16657 | if (shdr_status || shdr_add_status || rc) { |
| 16658 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16659 | "2511 POST_SGL mailbox failed with " |
| 16660 | "status x%x add_status x%x, mbx status x%x\n", |
| 16661 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16662 | } |
| 16663 | return 0; |
| 16664 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16665 | |
| 16666 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16667 | * 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] | 16668 | * @phba: pointer to lpfc hba data structure. |
| 16669 | * |
| 16670 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16671 | * HBA consistent with the SLI-4 interface spec. This routine |
| 16672 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 16673 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16674 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16675 | * Returns |
| 16676 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 16677 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 16678 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16679 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16680 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 16681 | { |
| 16682 | unsigned long xri; |
| 16683 | |
| 16684 | /* |
| 16685 | * Fetch the next logical xri. Because this index is logical, |
| 16686 | * the driver starts at 0 each time. |
| 16687 | */ |
| 16688 | spin_lock_irq(&phba->hbalock); |
| 16689 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 16690 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 16691 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 16692 | spin_unlock_irq(&phba->hbalock); |
| 16693 | return NO_XRI; |
| 16694 | } else { |
| 16695 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 16696 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16697 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16698 | spin_unlock_irq(&phba->hbalock); |
| 16699 | return xri; |
| 16700 | } |
| 16701 | |
| 16702 | /** |
| 16703 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16704 | * @phba: pointer to lpfc hba data structure. |
| 16705 | * |
| 16706 | * This routine is invoked to release an xri to the pool of |
| 16707 | * available rpis maintained by the driver. |
| 16708 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16709 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16710 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16711 | { |
| 16712 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16713 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 16714 | } |
| 16715 | } |
| 16716 | |
| 16717 | /** |
| 16718 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16719 | * @phba: pointer to lpfc hba data structure. |
| 16720 | * |
| 16721 | * This routine is invoked to release an xri to the pool of |
| 16722 | * available rpis maintained by the driver. |
| 16723 | **/ |
| 16724 | void |
| 16725 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16726 | { |
| 16727 | spin_lock_irq(&phba->hbalock); |
| 16728 | __lpfc_sli4_free_xri(phba, xri); |
| 16729 | spin_unlock_irq(&phba->hbalock); |
| 16730 | } |
| 16731 | |
| 16732 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16733 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 16734 | * @phba: Pointer to HBA context object. |
| 16735 | * |
| 16736 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 16737 | * it will return 0xffff. |
| 16738 | * The function returns the allocated xritag if successful, else returns zero. |
| 16739 | * Zero is not a valid xritag. |
| 16740 | * The caller is not required to hold any lock. |
| 16741 | **/ |
| 16742 | uint16_t |
| 16743 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 16744 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16745 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16746 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16747 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 16748 | if (xri_index == NO_XRI) |
| 16749 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 16750 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 16751 | " Max XRI is %d, Used XRI is %d\n", |
| 16752 | xri_index, |
| 16753 | phba->sli4_hba.max_cfg_param.max_xri, |
| 16754 | phba->sli4_hba.max_cfg_param.xri_used); |
| 16755 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16756 | } |
| 16757 | |
| 16758 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16759 | * 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] | 16760 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16761 | * @post_sgl_list: pointer to els sgl entry list. |
| 16762 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16763 | * |
| 16764 | * This routine is invoked to post a block of driver's sgl pages to the |
| 16765 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 16766 | * is only called when the driver is loading and after all IO has been |
| 16767 | * stopped. |
| 16768 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16769 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16770 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16771 | struct list_head *post_sgl_list, |
| 16772 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16773 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16774 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16775 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16776 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16777 | void *viraddr; |
| 16778 | LPFC_MBOXQ_t *mbox; |
| 16779 | uint32_t reqlen, alloclen, pg_pairs; |
| 16780 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16781 | uint16_t xritag_start = 0; |
| 16782 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16783 | uint32_t shdr_status, shdr_add_status; |
| 16784 | union lpfc_sli4_cfg_shdr *shdr; |
| 16785 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16786 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16787 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16788 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16789 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16790 | "2559 Block sgl registration required DMA " |
| 16791 | "size (%d) great than a page\n", reqlen); |
| 16792 | return -ENOMEM; |
| 16793 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16794 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16795 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16796 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16797 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16798 | |
| 16799 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16800 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16801 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16802 | LPFC_SLI4_MBX_NEMBED); |
| 16803 | |
| 16804 | if (alloclen < reqlen) { |
| 16805 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16806 | "0285 Allocated DMA memory size (%d) is " |
| 16807 | "less than the requested DMA memory " |
| 16808 | "size (%d)\n", alloclen, reqlen); |
| 16809 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16810 | return -ENOMEM; |
| 16811 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16812 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16813 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16814 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16815 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16816 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16817 | pg_pairs = 0; |
| 16818 | 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] | 16819 | /* Set up the sge entry */ |
| 16820 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16821 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 16822 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16823 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 16824 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16825 | cpu_to_le32(putPaddrLow(0)); |
| 16826 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16827 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16828 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16829 | /* Keep the first xritag on the list */ |
| 16830 | if (pg_pairs == 0) |
| 16831 | xritag_start = sglq_entry->sli4_xritag; |
| 16832 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16833 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16834 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16835 | |
| 16836 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16837 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16838 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16839 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16840 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16841 | if (!phba->sli4_hba.intr_enable) |
| 16842 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16843 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16844 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16845 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16846 | } |
| 16847 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16848 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16849 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16850 | if (rc != MBX_TIMEOUT) |
| 16851 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16852 | if (shdr_status || shdr_add_status || rc) { |
| 16853 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16854 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 16855 | "status x%x add_status x%x mbx status x%x\n", |
| 16856 | shdr_status, shdr_add_status, rc); |
| 16857 | rc = -ENXIO; |
| 16858 | } |
| 16859 | return rc; |
| 16860 | } |
| 16861 | |
| 16862 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16863 | * 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] | 16864 | * @phba: pointer to lpfc hba data structure. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16865 | * @nblist: pointer to nvme buffer list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16866 | * @count: number of scsi buffers on the list. |
| 16867 | * |
| 16868 | * 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] | 16869 | * SCSI buffer list @nblist to the HBA using non-embedded mailbox command. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16870 | * No Lock is held. |
| 16871 | * |
| 16872 | **/ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16873 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16874 | lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist, |
| 16875 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16876 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16877 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16878 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16879 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16880 | void *viraddr; |
| 16881 | LPFC_MBOXQ_t *mbox; |
| 16882 | uint32_t reqlen, alloclen, pg_pairs; |
| 16883 | uint32_t mbox_tmo; |
| 16884 | uint16_t xritag_start = 0; |
| 16885 | int rc = 0; |
| 16886 | uint32_t shdr_status, shdr_add_status; |
| 16887 | dma_addr_t pdma_phys_bpl1; |
| 16888 | union lpfc_sli4_cfg_shdr *shdr; |
| 16889 | |
| 16890 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16891 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16892 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16893 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16894 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16895 | "6118 Block sgl registration required DMA " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16896 | "size (%d) great than a page\n", reqlen); |
| 16897 | return -ENOMEM; |
| 16898 | } |
| 16899 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16900 | if (!mbox) { |
| 16901 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16902 | "6119 Failed to allocate mbox cmd memory\n"); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16903 | return -ENOMEM; |
| 16904 | } |
| 16905 | |
| 16906 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16907 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16908 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16909 | reqlen, LPFC_SLI4_MBX_NEMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16910 | |
| 16911 | if (alloclen < reqlen) { |
| 16912 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16913 | "6120 Allocated DMA memory size (%d) is " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16914 | "less than the requested DMA memory " |
| 16915 | "size (%d)\n", alloclen, reqlen); |
| 16916 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16917 | return -ENOMEM; |
| 16918 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16919 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16920 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16921 | viraddr = mbox->sge_array->addr[0]; |
| 16922 | |
| 16923 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 16924 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16925 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16926 | |
| 16927 | pg_pairs = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16928 | list_for_each_entry(lpfc_ncmd, nblist, list) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16929 | /* Set up the sge entry */ |
| 16930 | sgl_pg_pairs->sgl_pg0_addr_lo = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16931 | cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16932 | sgl_pg_pairs->sgl_pg0_addr_hi = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16933 | cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16934 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16935 | pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl + |
| 16936 | SGL_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16937 | else |
| 16938 | pdma_phys_bpl1 = 0; |
| 16939 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16940 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 16941 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16942 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 16943 | /* Keep the first xritag on the list */ |
| 16944 | if (pg_pairs == 0) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16945 | xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16946 | sgl_pg_pairs++; |
| 16947 | pg_pairs++; |
| 16948 | } |
| 16949 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 16950 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 16951 | /* Perform endian conversion if necessary */ |
| 16952 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 16953 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16954 | if (!phba->sli4_hba.intr_enable) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16955 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16956 | } else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16957 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16958 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16959 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16960 | shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16961 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16962 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16963 | if (rc != MBX_TIMEOUT) |
| 16964 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16965 | if (shdr_status || shdr_add_status || rc) { |
| 16966 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16967 | "6125 POST_SGL_BLOCK mailbox command failed " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16968 | "status x%x add_status x%x mbx status x%x\n", |
| 16969 | shdr_status, shdr_add_status, rc); |
| 16970 | rc = -ENXIO; |
| 16971 | } |
| 16972 | return rc; |
| 16973 | } |
| 16974 | |
| 16975 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16976 | * 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] | 16977 | * @phba: pointer to lpfc hba data structure. |
| 16978 | * @post_nblist: pointer to the nvme buffer list. |
| 16979 | * |
| 16980 | * This routine walks a list of nvme buffers that was passed in. It attempts |
| 16981 | * to construct blocks of nvme buffer sgls which contains contiguous xris and |
| 16982 | * uses the non-embedded SGL block post mailbox commands to post to the port. |
| 16983 | * For single NVME buffer sgl with non-contiguous xri, if any, it shall use |
| 16984 | * embedded SGL post mailbox command for posting. The @post_nblist passed in |
| 16985 | * must be local list, thus no lock is needed when manipulate the list. |
| 16986 | * |
| 16987 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
| 16988 | **/ |
| 16989 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16990 | lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba, |
| 16991 | struct list_head *post_nblist, int sb_count) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16992 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16993 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16994 | int status, sgl_size; |
| 16995 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
| 16996 | dma_addr_t pdma_phys_sgl1; |
| 16997 | int last_xritag = NO_XRI; |
| 16998 | int cur_xritag; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16999 | LIST_HEAD(prep_nblist); |
| 17000 | LIST_HEAD(blck_nblist); |
| 17001 | LIST_HEAD(nvme_nblist); |
| 17002 | |
| 17003 | /* sanity check */ |
| 17004 | if (sb_count <= 0) |
| 17005 | return -EINVAL; |
| 17006 | |
| 17007 | sgl_size = phba->cfg_sg_dma_buf_size; |
| 17008 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) { |
| 17009 | list_del_init(&lpfc_ncmd->list); |
| 17010 | block_cnt++; |
| 17011 | if ((last_xritag != NO_XRI) && |
| 17012 | (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) { |
| 17013 | /* a hole in xri block, form a sgl posting block */ |
| 17014 | list_splice_init(&prep_nblist, &blck_nblist); |
| 17015 | post_cnt = block_cnt - 1; |
| 17016 | /* prepare list for next posting block */ |
| 17017 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 17018 | block_cnt = 1; |
| 17019 | } else { |
| 17020 | /* prepare list for next posting block */ |
| 17021 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 17022 | /* enough sgls for non-embed sgl mbox command */ |
| 17023 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 17024 | list_splice_init(&prep_nblist, &blck_nblist); |
| 17025 | post_cnt = block_cnt; |
| 17026 | block_cnt = 0; |
| 17027 | } |
| 17028 | } |
| 17029 | num_posting++; |
| 17030 | last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 17031 | |
| 17032 | /* end of repost sgl list condition for NVME buffers */ |
| 17033 | if (num_posting == sb_count) { |
| 17034 | if (post_cnt == 0) { |
| 17035 | /* last sgl posting block */ |
| 17036 | list_splice_init(&prep_nblist, &blck_nblist); |
| 17037 | post_cnt = block_cnt; |
| 17038 | } else if (block_cnt == 1) { |
| 17039 | /* last single sgl with non-contiguous xri */ |
| 17040 | if (sgl_size > SGL_PAGE_SIZE) |
| 17041 | pdma_phys_sgl1 = |
| 17042 | lpfc_ncmd->dma_phys_sgl + |
| 17043 | SGL_PAGE_SIZE; |
| 17044 | else |
| 17045 | pdma_phys_sgl1 = 0; |
| 17046 | cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 17047 | status = lpfc_sli4_post_sgl( |
| 17048 | phba, lpfc_ncmd->dma_phys_sgl, |
| 17049 | pdma_phys_sgl1, cur_xritag); |
| 17050 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17051 | /* Post error. Buffer unavailable. */ |
| 17052 | lpfc_ncmd->flags |= |
| 17053 | LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17054 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17055 | /* Post success. Bffer available. */ |
| 17056 | lpfc_ncmd->flags &= |
| 17057 | ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17058 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 17059 | num_posted++; |
| 17060 | } |
| 17061 | /* success, put on NVME buffer sgl list */ |
| 17062 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 17063 | } |
| 17064 | } |
| 17065 | |
| 17066 | /* continue until a nembed page worth of sgls */ |
| 17067 | if (post_cnt == 0) |
| 17068 | continue; |
| 17069 | |
| 17070 | /* post block of NVME buffer list sgls */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17071 | status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist, |
| 17072 | post_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17073 | |
| 17074 | /* don't reset xirtag due to hole in xri block */ |
| 17075 | if (block_cnt == 0) |
| 17076 | last_xritag = NO_XRI; |
| 17077 | |
| 17078 | /* reset NVME buffer post count for next round of posting */ |
| 17079 | post_cnt = 0; |
| 17080 | |
| 17081 | /* put posted NVME buffer-sgl posted on NVME buffer sgl list */ |
| 17082 | while (!list_empty(&blck_nblist)) { |
| 17083 | list_remove_head(&blck_nblist, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17084 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17085 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17086 | /* Post error. Mark buffer unavailable. */ |
| 17087 | lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17088 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 17089 | /* Post success, Mark buffer available. */ |
| 17090 | lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17091 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 17092 | num_posted++; |
| 17093 | } |
| 17094 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 17095 | } |
| 17096 | } |
| 17097 | /* Push NVME buffers with sgl posted to the available list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 17098 | lpfc_io_buf_replenish(phba, &nvme_nblist); |
| 17099 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 17100 | return num_posted; |
| 17101 | } |
| 17102 | |
| 17103 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17104 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 17105 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 17106 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17107 | * |
| 17108 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 17109 | * valid type of frame that the LPFC driver will handle. This function will |
| 17110 | * return a zero if the frame is a valid frame or a non zero value when the |
| 17111 | * frame does not pass the check. |
| 17112 | **/ |
| 17113 | static int |
| 17114 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 17115 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 17116 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17117 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17118 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17119 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 17120 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 17121 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17122 | switch (fc_hdr->fh_r_ctl) { |
| 17123 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 17124 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 17125 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 17126 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 17127 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 17128 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 17129 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 17130 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 17131 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 17132 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 17133 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 17134 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 17135 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 17136 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 17137 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 17138 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 17139 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 17140 | case FC_RCTL_BA_PRMT: |
| 17141 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 17142 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 17143 | case FC_RCTL_P_RJT: /* port reject */ |
| 17144 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 17145 | case FC_RCTL_P_BSY: /* port busy */ |
| 17146 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 17147 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 17148 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17149 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17150 | case FC_RCTL_END: /* end */ |
| 17151 | break; |
| 17152 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 17153 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 17154 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 17155 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 17156 | default: |
| 17157 | goto drop; |
| 17158 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17159 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17160 | switch (fc_hdr->fh_type) { |
| 17161 | case FC_TYPE_BLS: |
| 17162 | case FC_TYPE_ELS: |
| 17163 | case FC_TYPE_FCP: |
| 17164 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17165 | case FC_TYPE_NVME: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17166 | break; |
| 17167 | case FC_TYPE_IP: |
| 17168 | case FC_TYPE_ILS: |
| 17169 | default: |
| 17170 | goto drop; |
| 17171 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17172 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17173 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17174 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 17175 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17176 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 17177 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 17178 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 17179 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 17180 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17181 | return 0; |
| 17182 | drop: |
| 17183 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17184 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 17185 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17186 | return 1; |
| 17187 | } |
| 17188 | |
| 17189 | /** |
| 17190 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 17191 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17192 | * |
| 17193 | * This function processes the FC header to retrieve the VFI from the VF |
| 17194 | * header, if one exists. This function will return the VFI if one exists |
| 17195 | * or 0 if no VSAN Header exists. |
| 17196 | **/ |
| 17197 | static uint32_t |
| 17198 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 17199 | { |
| 17200 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 17201 | |
| 17202 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 17203 | return 0; |
| 17204 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 17205 | } |
| 17206 | |
| 17207 | /** |
| 17208 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 17209 | * @phba: Pointer to the HBA structure to search for the vport on |
| 17210 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17211 | * @fcfi: The FC Fabric ID that the frame came from |
| 17212 | * |
| 17213 | * This function searches the @phba for a vport that matches the content of the |
| 17214 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 17215 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 17216 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 17217 | * vport. |
| 17218 | **/ |
| 17219 | static struct lpfc_vport * |
| 17220 | 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] | 17221 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17222 | { |
| 17223 | struct lpfc_vport **vports; |
| 17224 | struct lpfc_vport *vport = NULL; |
| 17225 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17226 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 17227 | if (did == Fabric_DID) |
| 17228 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17229 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 17230 | !(phba->link_state == LPFC_HBA_READY)) |
| 17231 | return phba->pport; |
| 17232 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17233 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17234 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17235 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 17236 | if (phba->fcf.fcfi == fcfi && |
| 17237 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 17238 | vports[i]->fc_myDID == did) { |
| 17239 | vport = vports[i]; |
| 17240 | break; |
| 17241 | } |
| 17242 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17243 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17244 | lpfc_destroy_vport_work_array(phba, vports); |
| 17245 | return vport; |
| 17246 | } |
| 17247 | |
| 17248 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17249 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 17250 | * @vport: The vport to work on. |
| 17251 | * |
| 17252 | * This function updates the receive sequence time stamp for this vport. The |
| 17253 | * receive sequence time stamp indicates the time that the last frame of the |
| 17254 | * the sequence that has been idle for the longest amount of time was received. |
| 17255 | * the driver uses this time stamp to indicate if any received sequences have |
| 17256 | * timed out. |
| 17257 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17258 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17259 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 17260 | { |
| 17261 | struct lpfc_dmabuf *h_buf; |
| 17262 | struct hbq_dmabuf *dmabuf = NULL; |
| 17263 | |
| 17264 | /* get the oldest sequence on the rcv list */ |
| 17265 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 17266 | struct lpfc_dmabuf, list); |
| 17267 | if (!h_buf) |
| 17268 | return; |
| 17269 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17270 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 17271 | } |
| 17272 | |
| 17273 | /** |
| 17274 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 17275 | * @vport: The vport that the received sequences were sent to. |
| 17276 | * |
| 17277 | * This function cleans up all outstanding received sequences. This is called |
| 17278 | * by the driver when a link event or user action invalidates all the received |
| 17279 | * sequences. |
| 17280 | **/ |
| 17281 | void |
| 17282 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 17283 | { |
| 17284 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17285 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17286 | struct hbq_dmabuf *dmabuf = NULL; |
| 17287 | |
| 17288 | /* start with the oldest sequence on the rcv list */ |
| 17289 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17290 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17291 | list_del_init(&dmabuf->hbuf.list); |
| 17292 | list_for_each_entry_safe(d_buf, dnext, |
| 17293 | &dmabuf->dbuf.list, list) { |
| 17294 | list_del_init(&d_buf->list); |
| 17295 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17296 | } |
| 17297 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17298 | } |
| 17299 | } |
| 17300 | |
| 17301 | /** |
| 17302 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 17303 | * @vport: The vport that the received sequences were sent to. |
| 17304 | * |
| 17305 | * This function determines whether any received sequences have timed out by |
| 17306 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 17307 | * indicates that there is at least one timed out sequence this routine will |
| 17308 | * go through the received sequences one at a time from most inactive to most |
| 17309 | * active to determine which ones need to be cleaned up. Once it has determined |
| 17310 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 17311 | * without sending an abort. |
| 17312 | **/ |
| 17313 | void |
| 17314 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 17315 | { |
| 17316 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17317 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17318 | struct hbq_dmabuf *dmabuf = NULL; |
| 17319 | unsigned long timeout; |
| 17320 | int abort_count = 0; |
| 17321 | |
| 17322 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17323 | vport->rcv_buffer_time_stamp); |
| 17324 | if (list_empty(&vport->rcv_buffer_list) || |
| 17325 | time_before(jiffies, timeout)) |
| 17326 | return; |
| 17327 | /* start with the oldest sequence on the rcv list */ |
| 17328 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17329 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17330 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17331 | dmabuf->time_stamp); |
| 17332 | if (time_before(jiffies, timeout)) |
| 17333 | break; |
| 17334 | abort_count++; |
| 17335 | list_del_init(&dmabuf->hbuf.list); |
| 17336 | list_for_each_entry_safe(d_buf, dnext, |
| 17337 | &dmabuf->dbuf.list, list) { |
| 17338 | list_del_init(&d_buf->list); |
| 17339 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17340 | } |
| 17341 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17342 | } |
| 17343 | if (abort_count) |
| 17344 | lpfc_update_rcv_time_stamp(vport); |
| 17345 | } |
| 17346 | |
| 17347 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17348 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 17349 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 17350 | * |
| 17351 | * This function searches through the existing incomplete sequences that have |
| 17352 | * been sent to this @vport. If the frame matches one of the incomplete |
| 17353 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 17354 | * make up that sequence. If no sequence is found that matches this frame then |
| 17355 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 17356 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 17357 | * the frame was linked to. |
| 17358 | **/ |
| 17359 | static struct hbq_dmabuf * |
| 17360 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17361 | { |
| 17362 | struct fc_frame_header *new_hdr; |
| 17363 | struct fc_frame_header *temp_hdr; |
| 17364 | struct lpfc_dmabuf *d_buf; |
| 17365 | struct lpfc_dmabuf *h_buf; |
| 17366 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17367 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17368 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17369 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17370 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17371 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17372 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17373 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17374 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 17375 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17376 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17377 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17378 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17379 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17380 | continue; |
| 17381 | /* found a pending sequence that matches this frame */ |
| 17382 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17383 | break; |
| 17384 | } |
| 17385 | if (!seq_dmabuf) { |
| 17386 | /* |
| 17387 | * This indicates first frame received for this sequence. |
| 17388 | * Queue the buffer on the vport's rcv_buffer_list. |
| 17389 | */ |
| 17390 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17391 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17392 | return dmabuf; |
| 17393 | } |
| 17394 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17395 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 17396 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17397 | list_del_init(&seq_dmabuf->hbuf.list); |
| 17398 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17399 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17400 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17401 | return dmabuf; |
| 17402 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17403 | /* move this sequence to the tail to indicate a young sequence */ |
| 17404 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17405 | seq_dmabuf->time_stamp = jiffies; |
| 17406 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17407 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 17408 | temp_hdr = dmabuf->hbuf.virt; |
| 17409 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 17410 | return seq_dmabuf; |
| 17411 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17412 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17413 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 17414 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17415 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17416 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 17417 | /* |
| 17418 | * If the frame's sequence count is greater than the frame on |
| 17419 | * the list then insert the frame right after this frame |
| 17420 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17421 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 17422 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17423 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17424 | found = 1; |
| 17425 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17426 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17427 | |
| 17428 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 17429 | break; |
| 17430 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17431 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17432 | |
| 17433 | if (found) |
| 17434 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17435 | return NULL; |
| 17436 | } |
| 17437 | |
| 17438 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17439 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 17440 | * @vport: pointer to a vitural port |
| 17441 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17442 | * |
| 17443 | * This function tries to abort from the partially assembed sequence, described |
| 17444 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 17445 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 17446 | * the frames from the partially assembled sequence. |
| 17447 | * |
| 17448 | * Return |
| 17449 | * true -- if there is matching partially assembled sequence present and all |
| 17450 | * the frames freed with the sequence; |
| 17451 | * false -- if there is no matching partially assembled sequence present so |
| 17452 | * nothing got aborted in the lower layer driver |
| 17453 | **/ |
| 17454 | static bool |
| 17455 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 17456 | struct hbq_dmabuf *dmabuf) |
| 17457 | { |
| 17458 | struct fc_frame_header *new_hdr; |
| 17459 | struct fc_frame_header *temp_hdr; |
| 17460 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 17461 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17462 | |
| 17463 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 17464 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 17465 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 17466 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17467 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17468 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17469 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17470 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17471 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17472 | continue; |
| 17473 | /* found a pending sequence that matches this frame */ |
| 17474 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17475 | break; |
| 17476 | } |
| 17477 | |
| 17478 | /* Free up all the frames from the partially assembled sequence */ |
| 17479 | if (seq_dmabuf) { |
| 17480 | list_for_each_entry_safe(d_buf, n_buf, |
| 17481 | &seq_dmabuf->dbuf.list, list) { |
| 17482 | list_del_init(&d_buf->list); |
| 17483 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17484 | } |
| 17485 | return true; |
| 17486 | } |
| 17487 | return false; |
| 17488 | } |
| 17489 | |
| 17490 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17491 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 17492 | * @vport: pointer to a vitural port |
| 17493 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17494 | * |
| 17495 | * This function tries to abort from the assembed sequence from upper level |
| 17496 | * protocol, described by the information from basic abbort @dmabuf. It |
| 17497 | * checks to see whether such pending context exists at upper level protocol. |
| 17498 | * If so, it shall clean up the pending context. |
| 17499 | * |
| 17500 | * Return |
| 17501 | * true -- if there is matching pending context of the sequence cleaned |
| 17502 | * at ulp; |
| 17503 | * false -- if there is no matching pending context of the sequence present |
| 17504 | * at ulp. |
| 17505 | **/ |
| 17506 | static bool |
| 17507 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17508 | { |
| 17509 | struct lpfc_hba *phba = vport->phba; |
| 17510 | int handled; |
| 17511 | |
| 17512 | /* Accepting abort at ulp with SLI4 only */ |
| 17513 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 17514 | return false; |
| 17515 | |
| 17516 | /* Register all caring upper level protocols to attend abort */ |
| 17517 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 17518 | if (handled) |
| 17519 | return true; |
| 17520 | |
| 17521 | return false; |
| 17522 | } |
| 17523 | |
| 17524 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17525 | * 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] | 17526 | * @phba: Pointer to HBA context object. |
| 17527 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 17528 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 17529 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17530 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17531 | * event. It properly releases the memory allocated to the sequence abort |
| 17532 | * accept iocb. |
| 17533 | **/ |
| 17534 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17535 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17536 | struct lpfc_iocbq *cmd_iocbq, |
| 17537 | struct lpfc_iocbq *rsp_iocbq) |
| 17538 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17539 | struct lpfc_nodelist *ndlp; |
| 17540 | |
| 17541 | if (cmd_iocbq) { |
| 17542 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 17543 | lpfc_nlp_put(ndlp); |
| 17544 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17545 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17546 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17547 | |
| 17548 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 17549 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 17550 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17551 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 17552 | rsp_iocbq->iocb.ulpStatus, |
| 17553 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17554 | } |
| 17555 | |
| 17556 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17557 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 17558 | * @phba: Pointer to HBA context object. |
| 17559 | * @xri: xri id in transaction. |
| 17560 | * |
| 17561 | * This function validates the xri maps to the known range of XRIs allocated an |
| 17562 | * used by the driver. |
| 17563 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17564 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17565 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 17566 | uint16_t xri) |
| 17567 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17568 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17569 | |
| 17570 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 17571 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 17572 | return i; |
| 17573 | } |
| 17574 | return NO_XRI; |
| 17575 | } |
| 17576 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17577 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17578 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17579 | * @phba: Pointer to HBA context object. |
| 17580 | * @fc_hdr: pointer to a FC frame header. |
| 17581 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17582 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17583 | * event after aborting the sequence handling. |
| 17584 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17585 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17586 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 17587 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17588 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17589 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17590 | struct lpfc_iocbq *ctiocb = NULL; |
| 17591 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17592 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17593 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17594 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17595 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17596 | |
| 17597 | if (!lpfc_is_link_up(phba)) |
| 17598 | return; |
| 17599 | |
| 17600 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 17601 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17602 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17603 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17604 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17605 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 17606 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17607 | if (!ndlp) { |
| 17608 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17609 | "1268 Failed to allocate ndlp for " |
| 17610 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 17611 | return; |
| 17612 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17613 | /* Put ndlp onto pport node list */ |
| 17614 | lpfc_enqueue_node(vport, ndlp); |
| 17615 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 17616 | /* re-setup ndlp without removing from node list */ |
| 17617 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 17618 | if (!ndlp) { |
| 17619 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17620 | "3275 Failed to active ndlp found " |
| 17621 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 17622 | return; |
| 17623 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17624 | } |
| 17625 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17626 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17627 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 17628 | if (!ctiocb) |
| 17629 | return; |
| 17630 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17631 | /* Extract the F_CTL field from FC_HDR */ |
| 17632 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 17633 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17634 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17635 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17636 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17637 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 17638 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 17639 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 17640 | |
| 17641 | /* Fill in the rest of iocb fields */ |
| 17642 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 17643 | icmd->ulpBdeCount = 0; |
| 17644 | icmd->ulpLe = 1; |
| 17645 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17646 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17647 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17648 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17649 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17650 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17651 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17652 | ctiocb->sli4_xritag = NO_XRI; |
| 17653 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17654 | if (fctl & FC_FC_EX_CTX) |
| 17655 | /* Exchange responder sent the abort so we |
| 17656 | * own the oxid. |
| 17657 | */ |
| 17658 | xri = oxid; |
| 17659 | else |
| 17660 | xri = rxid; |
| 17661 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 17662 | if (lxri != NO_XRI) |
| 17663 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 17664 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17665 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 17666 | * the oxid maps to the FCP XRI range, the port no longer has |
| 17667 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 17668 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17669 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17670 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17671 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17672 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17673 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17674 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17675 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17676 | } |
| 17677 | |
| 17678 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 17679 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 17680 | * the IOCB for a BA_RJT. |
| 17681 | */ |
| 17682 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17683 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17684 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17685 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17686 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17687 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17688 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17689 | if (fctl & FC_FC_EX_CTX) { |
| 17690 | /* ABTS sent by responder to CT exchange, construction |
| 17691 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 17692 | * field and RX_ID from ABTS for RX_ID field. |
| 17693 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17694 | 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] | 17695 | } else { |
| 17696 | /* ABTS sent by initiator to CT exchange, construction |
| 17697 | * 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] | 17698 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17699 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17700 | 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] | 17701 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 17702 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17703 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17704 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17705 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17706 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 17707 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 17708 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17709 | |
| 17710 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 17711 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17712 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 17713 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 17714 | "xri x%x, Data x%x\n", |
| 17715 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 17716 | phba->link_state); |
| 17717 | lpfc_nlp_put(ndlp); |
| 17718 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17719 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 17720 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17721 | } |
| 17722 | |
| 17723 | /** |
| 17724 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 17725 | * @vport: Pointer to the vport on which this sequence was received |
| 17726 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17727 | * |
| 17728 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 17729 | * receive sequence is only partially assembed by the driver, it shall abort |
| 17730 | * the partially assembled frames for the sequence. Otherwise, if the |
| 17731 | * unsolicited receive sequence has been completely assembled and passed to |
| 17732 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 17733 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 17734 | * accept to accept the abort. |
| 17735 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17736 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17737 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 17738 | struct hbq_dmabuf *dmabuf) |
| 17739 | { |
| 17740 | struct lpfc_hba *phba = vport->phba; |
| 17741 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17742 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17743 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17744 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17745 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 17746 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17747 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17748 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17749 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17750 | /* ABTS by responder to exchange, no cleanup needed */ |
| 17751 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17752 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17753 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 17754 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 17755 | if (aborted == false) |
| 17756 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17757 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17758 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17759 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17760 | if (phba->nvmet_support) { |
| 17761 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 17762 | return; |
| 17763 | } |
| 17764 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17765 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 17766 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17767 | } |
| 17768 | |
| 17769 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17770 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 17771 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17772 | * |
| 17773 | * This function checks the sequence, starting with the frame described by |
| 17774 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 17775 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 17776 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 17777 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 17778 | * set. 3) That there are no holes in the sequence count. The function will |
| 17779 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 17780 | **/ |
| 17781 | static int |
| 17782 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 17783 | { |
| 17784 | struct fc_frame_header *hdr; |
| 17785 | struct lpfc_dmabuf *d_buf; |
| 17786 | struct hbq_dmabuf *seq_dmabuf; |
| 17787 | uint32_t fctl; |
| 17788 | int seq_count = 0; |
| 17789 | |
| 17790 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17791 | /* make sure first fame of sequence has a sequence count of zero */ |
| 17792 | if (hdr->fh_seq_cnt != seq_count) |
| 17793 | return 0; |
| 17794 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17795 | hdr->fh_f_ctl[1] << 8 | |
| 17796 | hdr->fh_f_ctl[2]); |
| 17797 | /* If last frame of sequence we can return success. */ |
| 17798 | if (fctl & FC_FC_END_SEQ) |
| 17799 | return 1; |
| 17800 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 17801 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17802 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17803 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17804 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17805 | return 0; |
| 17806 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17807 | hdr->fh_f_ctl[1] << 8 | |
| 17808 | hdr->fh_f_ctl[2]); |
| 17809 | /* If last frame of sequence we can return success. */ |
| 17810 | if (fctl & FC_FC_END_SEQ) |
| 17811 | return 1; |
| 17812 | } |
| 17813 | return 0; |
| 17814 | } |
| 17815 | |
| 17816 | /** |
| 17817 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 17818 | * @vport: Pointer to the vport on which this sequence was received |
| 17819 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17820 | * |
| 17821 | * This function takes a sequence, described by a list of frames, and creates |
| 17822 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 17823 | * used to issue to the generic unsolicited sequence handler. This routine |
| 17824 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 17825 | * to allocate an iocbq then it throw out the received frames that were not |
| 17826 | * able to be described and return a pointer to the first iocbq. If unable to |
| 17827 | * allocate any iocbqs (including the first) this function will return NULL. |
| 17828 | **/ |
| 17829 | static struct lpfc_iocbq * |
| 17830 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 17831 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17832 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17833 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 17834 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 17835 | struct fc_frame_header *fc_hdr; |
| 17836 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17837 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17838 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17839 | |
| 17840 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17841 | /* remove from receive buffer list */ |
| 17842 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17843 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17844 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17845 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17846 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17847 | /* Get an iocbq struct to fill in. */ |
| 17848 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17849 | if (first_iocbq) { |
| 17850 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17851 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17852 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17853 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17854 | |
| 17855 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 17856 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 17857 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 17858 | first_iocbq->iocb.un.rcvels.parmRo = |
| 17859 | sli4_did_from_fc_hdr(fc_hdr); |
| 17860 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 17861 | } else |
| 17862 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17863 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 17864 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 17865 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 17866 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 17867 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 17868 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17869 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17870 | tot_len = bf_get(lpfc_rcqe_length, |
| 17871 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17872 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17873 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 17874 | first_iocbq->context3 = NULL; |
| 17875 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17876 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 17877 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17878 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17879 | else |
| 17880 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 17881 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17882 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17883 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17884 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17885 | } |
| 17886 | iocbq = first_iocbq; |
| 17887 | /* |
| 17888 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 17889 | * of buffers for this sequence and save two buffers in each IOCBq |
| 17890 | */ |
| 17891 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 17892 | if (!iocbq) { |
| 17893 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17894 | continue; |
| 17895 | } |
| 17896 | if (!iocbq->context3) { |
| 17897 | iocbq->context3 = d_buf; |
| 17898 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17899 | /* We need to get the size out of the right CQE */ |
| 17900 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17901 | len = bf_get(lpfc_rcqe_length, |
| 17902 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17903 | pbde = (struct ulp_bde64 *) |
| 17904 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 17905 | if (len > LPFC_DATA_BUF_SIZE) |
| 17906 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 17907 | else |
| 17908 | pbde->tus.f.bdeSize = len; |
| 17909 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17910 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 17911 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17912 | } else { |
| 17913 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17914 | if (!iocbq) { |
| 17915 | if (first_iocbq) { |
| 17916 | first_iocbq->iocb.ulpStatus = |
| 17917 | IOSTAT_FCP_RSP_ERROR; |
| 17918 | first_iocbq->iocb.un.ulpWord[4] = |
| 17919 | IOERR_NO_RESOURCES; |
| 17920 | } |
| 17921 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17922 | continue; |
| 17923 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17924 | /* We need to get the size out of the right CQE */ |
| 17925 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17926 | len = bf_get(lpfc_rcqe_length, |
| 17927 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17928 | iocbq->context2 = d_buf; |
| 17929 | iocbq->context3 = NULL; |
| 17930 | iocbq->iocb.ulpBdeCount = 1; |
| 17931 | if (len > LPFC_DATA_BUF_SIZE) |
| 17932 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 17933 | LPFC_DATA_BUF_SIZE; |
| 17934 | else |
| 17935 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 17936 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17937 | tot_len += len; |
| 17938 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 17939 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17940 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 17941 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 17942 | } |
| 17943 | } |
James Smart | 39c4f1a | 2020-01-27 16:23:01 -0800 | [diff] [blame] | 17944 | /* Free the sequence's header buffer */ |
| 17945 | if (!first_iocbq) |
| 17946 | lpfc_in_buf_free(vport->phba, &seq_dmabuf->dbuf); |
| 17947 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17948 | return first_iocbq; |
| 17949 | } |
| 17950 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17951 | static void |
| 17952 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 17953 | struct hbq_dmabuf *seq_dmabuf) |
| 17954 | { |
| 17955 | struct fc_frame_header *fc_hdr; |
| 17956 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 17957 | struct lpfc_hba *phba = vport->phba; |
| 17958 | |
| 17959 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17960 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 17961 | if (!iocbq) { |
| 17962 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17963 | "2707 Ring %d handler: Failed to allocate " |
| 17964 | "iocb Rctl x%x Type x%x received\n", |
| 17965 | LPFC_ELS_RING, |
| 17966 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17967 | return; |
| 17968 | } |
| 17969 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17970 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17971 | iocbq, fc_hdr->fh_r_ctl, |
| 17972 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17973 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17974 | "2540 Ring %d handler: unexpected Rctl " |
| 17975 | "x%x Type x%x received\n", |
| 17976 | LPFC_ELS_RING, |
| 17977 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17978 | |
| 17979 | /* Free iocb created in lpfc_prep_seq */ |
| 17980 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 17981 | &iocbq->list, list) { |
| 17982 | list_del_init(&curr_iocb->list); |
| 17983 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 17984 | } |
| 17985 | lpfc_sli_release_iocbq(phba, iocbq); |
| 17986 | } |
| 17987 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17988 | static void |
| 17989 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 17990 | struct lpfc_iocbq *rspiocb) |
| 17991 | { |
| 17992 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 17993 | |
| 17994 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17995 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17996 | kfree(pcmd); |
| 17997 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17998 | lpfc_drain_txq(phba); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17999 | } |
| 18000 | |
| 18001 | static void |
| 18002 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 18003 | struct hbq_dmabuf *dmabuf) |
| 18004 | { |
| 18005 | struct fc_frame_header *fc_hdr; |
| 18006 | struct lpfc_hba *phba = vport->phba; |
| 18007 | struct lpfc_iocbq *iocbq = NULL; |
| 18008 | union lpfc_wqe *wqe; |
| 18009 | struct lpfc_dmabuf *pcmd = NULL; |
| 18010 | uint32_t frame_len; |
| 18011 | int rc; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18012 | unsigned long iflags; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18013 | |
| 18014 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 18015 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 18016 | |
| 18017 | /* Send the received frame back */ |
| 18018 | iocbq = lpfc_sli_get_iocbq(phba); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18019 | if (!iocbq) { |
| 18020 | /* Queue cq event and wakeup worker thread to process it */ |
| 18021 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 18022 | list_add_tail(&dmabuf->cq_event.list, |
| 18023 | &phba->sli4_hba.sp_queue_event); |
| 18024 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
| 18025 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 18026 | lpfc_worker_wake_up(phba); |
| 18027 | return; |
| 18028 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18029 | |
| 18030 | /* Allocate buffer for command payload */ |
| 18031 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 18032 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 18033 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18034 | &pcmd->phys); |
| 18035 | if (!pcmd || !pcmd->virt) |
| 18036 | goto exit; |
| 18037 | |
| 18038 | INIT_LIST_HEAD(&pcmd->list); |
| 18039 | |
| 18040 | /* copyin the payload */ |
| 18041 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 18042 | |
| 18043 | /* fill in BDE's for command */ |
| 18044 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 18045 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 18046 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 18047 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 18048 | |
| 18049 | iocbq->context2 = pcmd; |
| 18050 | iocbq->vport = vport; |
| 18051 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 18052 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 18053 | |
| 18054 | /* |
| 18055 | * Setup rest of the iocb as though it were a WQE |
| 18056 | * Build the SEND_FRAME WQE |
| 18057 | */ |
| 18058 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 18059 | |
| 18060 | wqe->send_frame.frame_len = frame_len; |
| 18061 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 18062 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 18063 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 18064 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 18065 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 18066 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 18067 | |
| 18068 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 18069 | iocbq->iocb.ulpLe = 1; |
| 18070 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 18071 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 18072 | if (rc == IOCB_ERROR) |
| 18073 | goto exit; |
| 18074 | |
| 18075 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18076 | return; |
| 18077 | |
| 18078 | exit: |
| 18079 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 18080 | "2023 Unable to process MDS loopback frame\n"); |
| 18081 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 18082 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18083 | kfree(pcmd); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 18084 | if (iocbq) |
| 18085 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 18086 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18087 | } |
| 18088 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18089 | /** |
| 18090 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 18091 | * @phba: Pointer to HBA context object. |
| 18092 | * |
| 18093 | * This function is called with no lock held. This function processes all |
| 18094 | * the received buffers and gives it to upper layers when a received buffer |
| 18095 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18096 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18097 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 18098 | * appropriate receive function when the final frame in a sequence is received. |
| 18099 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18100 | void |
| 18101 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 18102 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18103 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18104 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18105 | struct fc_frame_header *fc_hdr; |
| 18106 | struct lpfc_vport *vport; |
| 18107 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18108 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18109 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18110 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18111 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 18112 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 18113 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 18114 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 18115 | vport = phba->pport; |
| 18116 | /* Handle MDS Loopback frames */ |
| 18117 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 18118 | return; |
| 18119 | } |
| 18120 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18121 | /* check to see if this a valid type of frame */ |
| 18122 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 18123 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18124 | return; |
| 18125 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 18126 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 18127 | if ((bf_get(lpfc_cqe_code, |
| 18128 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 18129 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 18130 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 18131 | else |
| 18132 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 18133 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18134 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 18135 | if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) { |
| 18136 | vport = phba->pport; |
| 18137 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 18138 | "2023 MDS Loopback %d bytes\n", |
| 18139 | bf_get(lpfc_rcqe_length, |
| 18140 | &dmabuf->cq_event.cqe.rcqe_cmpl)); |
| 18141 | /* Handle MDS Loopback frames */ |
| 18142 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 18143 | return; |
| 18144 | } |
| 18145 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18146 | /* d_id this frame is directed to */ |
| 18147 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 18148 | |
| 18149 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18150 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18151 | /* throw out the frame */ |
| 18152 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18153 | return; |
| 18154 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18155 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 18156 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 18157 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 18158 | (did != Fabric_DID)) { |
| 18159 | /* |
| 18160 | * Throw out the frame if we are not pt2pt. |
| 18161 | * The pt2pt protocol allows for discovery frames |
| 18162 | * to be received without a registered VPI. |
| 18163 | */ |
| 18164 | if (!(vport->fc_flag & FC_PT2PT) || |
| 18165 | (phba->link_state == LPFC_HBA_READY)) { |
| 18166 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18167 | return; |
| 18168 | } |
| 18169 | } |
| 18170 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18171 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 18172 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 18173 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 18174 | return; |
| 18175 | } |
| 18176 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18177 | /* Link this frame */ |
| 18178 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 18179 | if (!seq_dmabuf) { |
| 18180 | /* unable to add frame to vport - throw it out */ |
| 18181 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18182 | return; |
| 18183 | } |
| 18184 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 18185 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18186 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 18187 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18188 | /* Send the complete sequence to the upper layer protocol */ |
| 18189 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18190 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18191 | |
| 18192 | /** |
| 18193 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 18194 | * @phba: pointer to lpfc hba data structure. |
| 18195 | * |
| 18196 | * This routine is invoked to post rpi header templates to the |
| 18197 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18198 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18199 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18200 | * |
| 18201 | * This routine does not require any locks. It's usage is expected |
| 18202 | * to be driver load or reset recovery when the driver is |
| 18203 | * sequential. |
| 18204 | * |
| 18205 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18206 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18207 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18208 | * When this error occurs, the driver is not guaranteed |
| 18209 | * to have any rpi regions posted to the device and |
| 18210 | * must either attempt to repost the regions or take a |
| 18211 | * fatal error. |
| 18212 | **/ |
| 18213 | int |
| 18214 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 18215 | { |
| 18216 | struct lpfc_rpi_hdr *rpi_page; |
| 18217 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18218 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18219 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18220 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18221 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18222 | goto exit; |
| 18223 | if (phba->sli4_hba.extents_in_use) |
| 18224 | return -EIO; |
| 18225 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18226 | 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] | 18227 | /* |
| 18228 | * Assign the rpi headers a physical rpi only if the driver |
| 18229 | * has not initialized those resources. A port reset only |
| 18230 | * needs the headers posted. |
| 18231 | */ |
| 18232 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 18233 | LPFC_RPI_RSRC_RDY) |
| 18234 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 18235 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18236 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 18237 | if (rc != MBX_SUCCESS) { |
| 18238 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18239 | "2008 Error %d posting all rpi " |
| 18240 | "headers\n", rc); |
| 18241 | rc = -EIO; |
| 18242 | break; |
| 18243 | } |
| 18244 | } |
| 18245 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18246 | exit: |
| 18247 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 18248 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18249 | return rc; |
| 18250 | } |
| 18251 | |
| 18252 | /** |
| 18253 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 18254 | * @phba: pointer to lpfc hba data structure. |
| 18255 | * @rpi_page: pointer to the rpi memory region. |
| 18256 | * |
| 18257 | * This routine is invoked to post a single rpi header to the |
| 18258 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 18259 | * maps up to 64 rpi context regions. |
| 18260 | * |
| 18261 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18262 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18263 | * -ENOMEM - No available memory |
| 18264 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18265 | **/ |
| 18266 | int |
| 18267 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 18268 | { |
| 18269 | LPFC_MBOXQ_t *mboxq; |
| 18270 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 18271 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18272 | uint32_t shdr_status, shdr_add_status; |
| 18273 | union lpfc_sli4_cfg_shdr *shdr; |
| 18274 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18275 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18276 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18277 | return rc; |
| 18278 | if (phba->sli4_hba.extents_in_use) |
| 18279 | return -EIO; |
| 18280 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18281 | /* The port is notified of the header region via a mailbox command. */ |
| 18282 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18283 | if (!mboxq) { |
| 18284 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18285 | "2001 Unable to allocate memory for issuing " |
| 18286 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 18287 | return -ENOMEM; |
| 18288 | } |
| 18289 | |
| 18290 | /* Post all rpi memory regions to the port. */ |
| 18291 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18292 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18293 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 18294 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 18295 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 18296 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18297 | |
| 18298 | |
| 18299 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18300 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 18301 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18302 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 18303 | hdr_tmpl, rpi_page->page_count); |
| 18304 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18305 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 18306 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 18307 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18308 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 18309 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18310 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18311 | if (rc != MBX_TIMEOUT) |
| 18312 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18313 | if (shdr_status || shdr_add_status || rc) { |
| 18314 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18315 | "2514 POST_RPI_HDR mailbox failed with " |
| 18316 | "status x%x add_status x%x, mbx status x%x\n", |
| 18317 | shdr_status, shdr_add_status, rc); |
| 18318 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 18319 | } else { |
| 18320 | /* |
| 18321 | * The next_rpi stores the next logical module-64 rpi value used |
| 18322 | * to post physical rpis in subsequent rpi postings. |
| 18323 | */ |
| 18324 | spin_lock_irq(&phba->hbalock); |
| 18325 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 18326 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18327 | } |
| 18328 | return rc; |
| 18329 | } |
| 18330 | |
| 18331 | /** |
| 18332 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 18333 | * @phba: pointer to lpfc hba data structure. |
| 18334 | * |
| 18335 | * This routine is invoked to post rpi header templates to the |
| 18336 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18337 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18338 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18339 | * |
| 18340 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18341 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18342 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 18343 | **/ |
| 18344 | int |
| 18345 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 18346 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18347 | unsigned long rpi; |
| 18348 | uint16_t max_rpi, rpi_limit; |
| 18349 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18350 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18351 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18352 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18353 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18354 | * Fetch the next logical rpi. Because this index is logical, |
| 18355 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18356 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18357 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18358 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 18359 | rpi_limit = phba->sli4_hba.next_rpi; |
| 18360 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18361 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 18362 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18363 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 18364 | else { |
| 18365 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 18366 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 18367 | phba->sli4_hba.rpi_count++; |
| 18368 | } |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 18369 | lpfc_printf_log(phba, KERN_INFO, |
| 18370 | LOG_NODE | LOG_DISCOVERY, |
| 18371 | "0001 Allocated rpi:x%x max:x%x lim:x%x\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18372 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18373 | |
| 18374 | /* |
| 18375 | * 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] | 18376 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18377 | */ |
| 18378 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 18379 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18380 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18381 | return rpi; |
| 18382 | } |
| 18383 | |
| 18384 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18385 | * RPI header postings are not required for SLI4 ports capable of |
| 18386 | * extents. |
| 18387 | */ |
| 18388 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18389 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18390 | return rpi; |
| 18391 | } |
| 18392 | |
| 18393 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18394 | * If the driver is running low on rpi resources, allocate another |
| 18395 | * page now. Note that the next_rpi value is used because |
| 18396 | * it represents how many are actually in use whereas max_rpi notes |
| 18397 | * how many are supported max by the device. |
| 18398 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18399 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18400 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18401 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 18402 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 18403 | if (!rpi_hdr) { |
| 18404 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18405 | "2002 Error Could not grow rpi " |
| 18406 | "count\n"); |
| 18407 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18408 | lrpi = rpi_hdr->start_rpi; |
| 18409 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18410 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 18411 | } |
| 18412 | } |
| 18413 | |
| 18414 | return rpi; |
| 18415 | } |
| 18416 | |
| 18417 | /** |
| 18418 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18419 | * @phba: pointer to lpfc hba data structure. |
| 18420 | * |
| 18421 | * This routine is invoked to release an rpi to the pool of |
| 18422 | * available rpis maintained by the driver. |
| 18423 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18424 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18425 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18426 | { |
James Smart | 7cfd563 | 2019-11-04 16:56:58 -0800 | [diff] [blame] | 18427 | /* |
| 18428 | * if the rpi value indicates a prior unreg has already |
| 18429 | * been done, skip the unreg. |
| 18430 | */ |
| 18431 | if (rpi == LPFC_RPI_ALLOC_ERROR) |
| 18432 | return; |
| 18433 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18434 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 18435 | phba->sli4_hba.rpi_count--; |
| 18436 | phba->sli4_hba.max_cfg_param.rpi_used--; |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 18437 | } else { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 18438 | lpfc_printf_log(phba, KERN_INFO, |
| 18439 | LOG_NODE | LOG_DISCOVERY, |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 18440 | "2016 rpi %x not inuse\n", |
| 18441 | rpi); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18442 | } |
| 18443 | } |
| 18444 | |
| 18445 | /** |
| 18446 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18447 | * @phba: pointer to lpfc hba data structure. |
| 18448 | * |
| 18449 | * This routine is invoked to release an rpi to the pool of |
| 18450 | * available rpis maintained by the driver. |
| 18451 | **/ |
| 18452 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18453 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18454 | { |
| 18455 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18456 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18457 | spin_unlock_irq(&phba->hbalock); |
| 18458 | } |
| 18459 | |
| 18460 | /** |
| 18461 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 18462 | * @phba: pointer to lpfc hba data structure. |
| 18463 | * |
| 18464 | * This routine is invoked to remove the memory region that |
| 18465 | * provided rpi via a bitmask. |
| 18466 | **/ |
| 18467 | void |
| 18468 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 18469 | { |
| 18470 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18471 | kfree(phba->sli4_hba.rpi_ids); |
| 18472 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18473 | } |
| 18474 | |
| 18475 | /** |
| 18476 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 18477 | * @phba: pointer to lpfc hba data structure. |
| 18478 | * |
| 18479 | * This routine is invoked to remove the memory region that |
| 18480 | * provided rpi via a bitmask. |
| 18481 | **/ |
| 18482 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18483 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 18484 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18485 | { |
| 18486 | LPFC_MBOXQ_t *mboxq; |
| 18487 | struct lpfc_hba *phba = ndlp->phba; |
| 18488 | int rc; |
| 18489 | |
| 18490 | /* The port is notified of the header region via a mailbox command. */ |
| 18491 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18492 | if (!mboxq) |
| 18493 | return -ENOMEM; |
| 18494 | |
| 18495 | /* Post all rpi memory regions to the port. */ |
| 18496 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18497 | if (cmpl) { |
| 18498 | mboxq->mbox_cmpl = cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 18499 | mboxq->ctx_buf = arg; |
| 18500 | mboxq->ctx_ndlp = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 18501 | } else |
| 18502 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18503 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18504 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18505 | if (rc == MBX_NOT_FINISHED) { |
| 18506 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18507 | "2010 Resume RPI Mailbox failed " |
| 18508 | "status %d, mbxStatus x%x\n", rc, |
| 18509 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 18510 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18511 | return -EIO; |
| 18512 | } |
| 18513 | return 0; |
| 18514 | } |
| 18515 | |
| 18516 | /** |
| 18517 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18518 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18519 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18520 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18521 | * |
| 18522 | * Returns: |
| 18523 | * 0 success |
| 18524 | * -Evalue otherwise |
| 18525 | **/ |
| 18526 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18527 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18528 | { |
| 18529 | LPFC_MBOXQ_t *mboxq; |
| 18530 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18531 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18532 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18533 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18534 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18535 | if (!mboxq) |
| 18536 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18537 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18538 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18539 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18540 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18541 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18542 | "2022 INIT VPI Mailbox failed " |
| 18543 | "status %d, mbxStatus x%x\n", rc, |
| 18544 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18545 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18546 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18547 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18548 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18549 | |
| 18550 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18551 | } |
| 18552 | |
| 18553 | /** |
| 18554 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 18555 | * @phba: pointer to lpfc hba data structure. |
| 18556 | * @mboxq: Pointer to mailbox object. |
| 18557 | * |
| 18558 | * This routine is invoked to manually add a single FCF record. The caller |
| 18559 | * must pass a completely initialized FCF_Record. This routine takes |
| 18560 | * care of the nonembedded mailbox operations. |
| 18561 | **/ |
| 18562 | static void |
| 18563 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 18564 | { |
| 18565 | void *virt_addr; |
| 18566 | union lpfc_sli4_cfg_shdr *shdr; |
| 18567 | uint32_t shdr_status, shdr_add_status; |
| 18568 | |
| 18569 | virt_addr = mboxq->sge_array->addr[0]; |
| 18570 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 18571 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 18572 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18573 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18574 | |
| 18575 | if ((shdr_status || shdr_add_status) && |
| 18576 | (shdr_status != STATUS_FCF_IN_USE)) |
| 18577 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18578 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 18579 | "status x%x add_status x%x\n", |
| 18580 | shdr_status, shdr_add_status); |
| 18581 | |
| 18582 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18583 | } |
| 18584 | |
| 18585 | /** |
| 18586 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 18587 | * @phba: pointer to lpfc hba data structure. |
| 18588 | * @fcf_record: pointer to the initialized fcf record to add. |
| 18589 | * |
| 18590 | * This routine is invoked to manually add a single FCF record. The caller |
| 18591 | * must pass a completely initialized FCF_Record. This routine takes |
| 18592 | * care of the nonembedded mailbox operations. |
| 18593 | **/ |
| 18594 | int |
| 18595 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 18596 | { |
| 18597 | int rc = 0; |
| 18598 | LPFC_MBOXQ_t *mboxq; |
| 18599 | uint8_t *bytep; |
| 18600 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18601 | struct lpfc_mbx_sge sge; |
| 18602 | uint32_t alloc_len, req_len; |
| 18603 | uint32_t fcfindex; |
| 18604 | |
| 18605 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18606 | if (!mboxq) { |
| 18607 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18608 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 18609 | return -ENOMEM; |
| 18610 | } |
| 18611 | |
| 18612 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 18613 | sizeof(uint32_t); |
| 18614 | |
| 18615 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 18616 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18617 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 18618 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 18619 | if (alloc_len < req_len) { |
| 18620 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18621 | "2523 Allocated DMA memory size (x%x) is " |
| 18622 | "less than the requested DMA memory " |
| 18623 | "size (x%x)\n", alloc_len, req_len); |
| 18624 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18625 | return -ENOMEM; |
| 18626 | } |
| 18627 | |
| 18628 | /* |
| 18629 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 18630 | * routine only uses a single SGE. |
| 18631 | */ |
| 18632 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18633 | virt_addr = mboxq->sge_array->addr[0]; |
| 18634 | /* |
| 18635 | * Configure the FCF record for FCFI 0. This is the driver's |
| 18636 | * hardcoded default and gets used in nonFIP mode. |
| 18637 | */ |
| 18638 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 18639 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 18640 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 18641 | |
| 18642 | /* |
| 18643 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 18644 | * the FCoE header plus word10. The data copy needs to be endian |
| 18645 | * correct. |
| 18646 | */ |
| 18647 | bytep += sizeof(uint32_t); |
| 18648 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 18649 | mboxq->vport = phba->pport; |
| 18650 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 18651 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18652 | if (rc == MBX_NOT_FINISHED) { |
| 18653 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18654 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 18655 | "status 0x%x\n", rc); |
| 18656 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18657 | rc = -EIO; |
| 18658 | } else |
| 18659 | rc = 0; |
| 18660 | |
| 18661 | return rc; |
| 18662 | } |
| 18663 | |
| 18664 | /** |
| 18665 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 18666 | * @phba: pointer to lpfc hba data structure. |
| 18667 | * @fcf_record: pointer to the fcf record to write the default data. |
| 18668 | * @fcf_index: FCF table entry index. |
| 18669 | * |
| 18670 | * This routine is invoked to build the driver's default FCF record. The |
| 18671 | * values used are hardcoded. This routine handles memory initialization. |
| 18672 | * |
| 18673 | **/ |
| 18674 | void |
| 18675 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 18676 | struct fcf_record *fcf_record, |
| 18677 | uint16_t fcf_index) |
| 18678 | { |
| 18679 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 18680 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 18681 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 18682 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 18683 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 18684 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 18685 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 18686 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 18687 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 18688 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 18689 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 18690 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 18691 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 18692 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 18693 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18694 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 18695 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 18696 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 18697 | /* Set the VLAN bit map */ |
| 18698 | if (phba->valid_vlan) { |
| 18699 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 18700 | = 1 << (phba->vlan_id % 8); |
| 18701 | } |
| 18702 | } |
| 18703 | |
| 18704 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18705 | * 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] | 18706 | * @phba: pointer to lpfc hba data structure. |
| 18707 | * @fcf_index: FCF table entry offset. |
| 18708 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18709 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 18710 | * record and processing it one at a time starting from the @fcf_index |
| 18711 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 18712 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18713 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18714 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18715 | **/ |
| 18716 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18717 | 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] | 18718 | { |
| 18719 | int rc = 0, error; |
| 18720 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18721 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18722 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 18723 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18724 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18725 | if (!mboxq) { |
| 18726 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18727 | "2000 Failed to allocate mbox for " |
| 18728 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18729 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18730 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18731 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18732 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18733 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18734 | if (rc) { |
| 18735 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18736 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18737 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18738 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18739 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18740 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18741 | |
| 18742 | spin_lock_irq(&phba->hbalock); |
| 18743 | phba->hba_flag |= FCF_TS_INPROG; |
| 18744 | spin_unlock_irq(&phba->hbalock); |
| 18745 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18746 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18747 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18748 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18749 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 18750 | /* Reset eligible FCF count for new scan */ |
| 18751 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 18752 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18753 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18754 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18755 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18756 | if (error) { |
| 18757 | if (mboxq) |
| 18758 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18759 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18760 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18761 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18762 | spin_unlock_irq(&phba->hbalock); |
| 18763 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18764 | return error; |
| 18765 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18766 | |
| 18767 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18768 | * 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] | 18769 | * @phba: pointer to lpfc hba data structure. |
| 18770 | * @fcf_index: FCF table entry offset. |
| 18771 | * |
| 18772 | * 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] | 18773 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18774 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18775 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18776 | * otherwise. |
| 18777 | **/ |
| 18778 | int |
| 18779 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18780 | { |
| 18781 | int rc = 0, error; |
| 18782 | LPFC_MBOXQ_t *mboxq; |
| 18783 | |
| 18784 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18785 | if (!mboxq) { |
| 18786 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18787 | "2763 Failed to allocate mbox for " |
| 18788 | "READ_FCF cmd\n"); |
| 18789 | error = -ENOMEM; |
| 18790 | goto fail_fcf_read; |
| 18791 | } |
| 18792 | /* Construct the read FCF record mailbox command */ |
| 18793 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18794 | if (rc) { |
| 18795 | error = -EINVAL; |
| 18796 | goto fail_fcf_read; |
| 18797 | } |
| 18798 | /* Issue the mailbox command asynchronously */ |
| 18799 | mboxq->vport = phba->pport; |
| 18800 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 18801 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18802 | if (rc == MBX_NOT_FINISHED) |
| 18803 | error = -EIO; |
| 18804 | else |
| 18805 | error = 0; |
| 18806 | |
| 18807 | fail_fcf_read: |
| 18808 | if (error && mboxq) |
| 18809 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18810 | return error; |
| 18811 | } |
| 18812 | |
| 18813 | /** |
| 18814 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 18815 | * @phba: pointer to lpfc hba data structure. |
| 18816 | * @fcf_index: FCF table entry offset. |
| 18817 | * |
| 18818 | * 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] | 18819 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18820 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18821 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18822 | * otherwise. |
| 18823 | **/ |
| 18824 | int |
| 18825 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18826 | { |
| 18827 | int rc = 0, error; |
| 18828 | LPFC_MBOXQ_t *mboxq; |
| 18829 | |
| 18830 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18831 | if (!mboxq) { |
| 18832 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18833 | "2758 Failed to allocate mbox for " |
| 18834 | "READ_FCF cmd\n"); |
| 18835 | error = -ENOMEM; |
| 18836 | goto fail_fcf_read; |
| 18837 | } |
| 18838 | /* Construct the read FCF record mailbox command */ |
| 18839 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18840 | if (rc) { |
| 18841 | error = -EINVAL; |
| 18842 | goto fail_fcf_read; |
| 18843 | } |
| 18844 | /* Issue the mailbox command asynchronously */ |
| 18845 | mboxq->vport = phba->pport; |
| 18846 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 18847 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18848 | if (rc == MBX_NOT_FINISHED) |
| 18849 | error = -EIO; |
| 18850 | else |
| 18851 | error = 0; |
| 18852 | |
| 18853 | fail_fcf_read: |
| 18854 | if (error && mboxq) |
| 18855 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18856 | return error; |
| 18857 | } |
| 18858 | |
| 18859 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18860 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18861 | * phba pointer to the lpfc_hba struct for this port. |
| 18862 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 18863 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 18864 | * rr_bmask based on their priority level. Starting from the highest priority |
| 18865 | * to the lowest. The most likely FCF candidate will be in the highest |
| 18866 | * priority group. When this routine is called it searches the fcf_pri list for |
| 18867 | * next lowest priority group and repopulates the rr_bmask with only those |
| 18868 | * fcf_indexes. |
| 18869 | * returns: |
| 18870 | * 1=success 0=failure |
| 18871 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18872 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18873 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 18874 | { |
| 18875 | uint16_t next_fcf_pri; |
| 18876 | uint16_t last_index; |
| 18877 | struct lpfc_fcf_pri *fcf_pri; |
| 18878 | int rc; |
| 18879 | int ret = 0; |
| 18880 | |
| 18881 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 18882 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18883 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 18884 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18885 | |
| 18886 | /* Verify the priority list has 2 or more entries */ |
| 18887 | spin_lock_irq(&phba->hbalock); |
| 18888 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 18889 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 18890 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18891 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 18892 | "3061 Last IDX %d\n", last_index); |
| 18893 | return 0; /* Empty rr list */ |
| 18894 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18895 | spin_unlock_irq(&phba->hbalock); |
| 18896 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18897 | next_fcf_pri = 0; |
| 18898 | /* |
| 18899 | * Clear the rr_bmask and set all of the bits that are at this |
| 18900 | * priority. |
| 18901 | */ |
| 18902 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 18903 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 18904 | spin_lock_irq(&phba->hbalock); |
| 18905 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18906 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 18907 | continue; |
| 18908 | /* |
| 18909 | * the 1st priority that has not FLOGI failed |
| 18910 | * will be the highest. |
| 18911 | */ |
| 18912 | if (!next_fcf_pri) |
| 18913 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18914 | spin_unlock_irq(&phba->hbalock); |
| 18915 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18916 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18917 | fcf_pri->fcf_rec.fcf_index); |
| 18918 | if (rc) |
| 18919 | return 0; |
| 18920 | } |
| 18921 | spin_lock_irq(&phba->hbalock); |
| 18922 | } |
| 18923 | /* |
| 18924 | * if next_fcf_pri was not set above and the list is not empty then |
| 18925 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 18926 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18927 | */ |
| 18928 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 18929 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18930 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 18931 | /* |
| 18932 | * the 1st priority that has not FLOGI failed |
| 18933 | * will be the highest. |
| 18934 | */ |
| 18935 | if (!next_fcf_pri) |
| 18936 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18937 | spin_unlock_irq(&phba->hbalock); |
| 18938 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18939 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18940 | fcf_pri->fcf_rec.fcf_index); |
| 18941 | if (rc) |
| 18942 | return 0; |
| 18943 | } |
| 18944 | spin_lock_irq(&phba->hbalock); |
| 18945 | } |
| 18946 | } else |
| 18947 | ret = 1; |
| 18948 | spin_unlock_irq(&phba->hbalock); |
| 18949 | |
| 18950 | return ret; |
| 18951 | } |
| 18952 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18953 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 18954 | * @phba: pointer to lpfc hba data structure. |
| 18955 | * |
| 18956 | * This routine is to get the next eligible FCF record index in a round |
| 18957 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18958 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18959 | * shall be returned, otherwise, the next eligible FCF record's index |
| 18960 | * shall be returned. |
| 18961 | **/ |
| 18962 | uint16_t |
| 18963 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 18964 | { |
| 18965 | uint16_t next_fcf_index; |
| 18966 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18967 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18968 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18969 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 18970 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18971 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18972 | /* Determine the next fcf index to check */ |
| 18973 | 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] | 18974 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18975 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18976 | next_fcf_index); |
| 18977 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18978 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18979 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18980 | /* |
| 18981 | * If we have wrapped then we need to clear the bits that |
| 18982 | * have been tested so that we can detect when we should |
| 18983 | * change the priority level. |
| 18984 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18985 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18986 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18987 | } |
| 18988 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18989 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18990 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18991 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 18992 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 18993 | /* |
| 18994 | * If next fcf index is not found check if there are lower |
| 18995 | * Priority level fcf's in the fcf_priority list. |
| 18996 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 18997 | * at that level and continue the selection process. |
| 18998 | */ |
| 18999 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 19000 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19001 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 19002 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 19003 | |
| 19004 | return LPFC_FCOE_FCF_NEXT_NONE; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19005 | } |
| 19006 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19007 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 19008 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 19009 | LPFC_FCF_FLOGI_FAILED) { |
| 19010 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 19011 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 19012 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19013 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 19014 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19015 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19016 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19017 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 19018 | next_fcf_index); |
| 19019 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19020 | return next_fcf_index; |
| 19021 | } |
| 19022 | |
| 19023 | /** |
| 19024 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 19025 | * @phba: pointer to lpfc hba data structure. |
| 19026 | * |
| 19027 | * 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] | 19028 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19029 | * does not go beyond the range of the driver allocated bmask dimension |
| 19030 | * before setting the bit. |
| 19031 | * |
| 19032 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 19033 | * -EINVAL. |
| 19034 | **/ |
| 19035 | int |
| 19036 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 19037 | { |
| 19038 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 19039 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19040 | "2610 FCF (x%x) reached driver's book " |
| 19041 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19042 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 19043 | return -EINVAL; |
| 19044 | } |
| 19045 | /* Set the eligible FCF record index bmask */ |
| 19046 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 19047 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19048 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19049 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19050 | "bmask\n", fcf_index); |
| 19051 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19052 | return 0; |
| 19053 | } |
| 19054 | |
| 19055 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19056 | * 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] | 19057 | * @phba: pointer to lpfc hba data structure. |
| 19058 | * |
| 19059 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19060 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19061 | * does not go beyond the range of the driver allocated bmask dimension |
| 19062 | * before clearing the bit. |
| 19063 | **/ |
| 19064 | void |
| 19065 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 19066 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 19067 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19068 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 19069 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19070 | "2762 FCF (x%x) reached driver's book " |
| 19071 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19072 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 19073 | return; |
| 19074 | } |
| 19075 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19076 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 19077 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 19078 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 19079 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 19080 | list_del_init(&fcf_pri->list); |
| 19081 | break; |
| 19082 | } |
| 19083 | } |
| 19084 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19085 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19086 | |
| 19087 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19088 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19089 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19090 | } |
| 19091 | |
| 19092 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19093 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 19094 | * @phba: pointer to lpfc hba data structure. |
| 19095 | * |
| 19096 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 19097 | * command. If the mailbox command returned failure, it will try to stop the |
| 19098 | * FCF rediscover wait timer. |
| 19099 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 19100 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19101 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 19102 | { |
| 19103 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 19104 | uint32_t shdr_status, shdr_add_status; |
| 19105 | |
| 19106 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 19107 | |
| 19108 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 19109 | &redisc_fcf->header.cfg_shdr.response); |
| 19110 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 19111 | &redisc_fcf->header.cfg_shdr.response); |
| 19112 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19113 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19114 | "2746 Requesting for FCF rediscovery failed " |
| 19115 | "status x%x add_status x%x\n", |
| 19116 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19117 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19118 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19119 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19120 | spin_unlock_irq(&phba->hbalock); |
| 19121 | /* |
| 19122 | * CVL event triggered FCF rediscover request failed, |
| 19123 | * last resort to re-try current registered FCF entry. |
| 19124 | */ |
| 19125 | lpfc_retry_pport_discovery(phba); |
| 19126 | } else { |
| 19127 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19128 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19129 | spin_unlock_irq(&phba->hbalock); |
| 19130 | /* |
| 19131 | * DEAD FCF event triggered FCF rediscover request |
| 19132 | * failed, last resort to fail over as a link down |
| 19133 | * to FCF registration. |
| 19134 | */ |
| 19135 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 19136 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19137 | } else { |
| 19138 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 19139 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19140 | /* |
| 19141 | * Start FCF rediscovery wait timer for pending FCF |
| 19142 | * before rescan FCF record table. |
| 19143 | */ |
| 19144 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19145 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19146 | |
| 19147 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19148 | } |
| 19149 | |
| 19150 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 19151 | * 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] | 19152 | * @phba: pointer to lpfc hba data structure. |
| 19153 | * |
| 19154 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 19155 | * by the port. |
| 19156 | **/ |
| 19157 | int |
| 19158 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 19159 | { |
| 19160 | LPFC_MBOXQ_t *mbox; |
| 19161 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 19162 | int rc, length; |
| 19163 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 19164 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 19165 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 19166 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 19167 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19168 | if (!mbox) { |
| 19169 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19170 | "2745 Failed to allocate mbox for " |
| 19171 | "requesting FCF rediscover.\n"); |
| 19172 | return -ENOMEM; |
| 19173 | } |
| 19174 | |
| 19175 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 19176 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 19177 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 19178 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 19179 | length, LPFC_SLI4_MBX_EMBED); |
| 19180 | |
| 19181 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 19182 | /* Set count to 0 for invalidating the entire FCF database */ |
| 19183 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 19184 | |
| 19185 | /* Issue the mailbox command asynchronously */ |
| 19186 | mbox->vport = phba->pport; |
| 19187 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 19188 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 19189 | |
| 19190 | if (rc == MBX_NOT_FINISHED) { |
| 19191 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19192 | return -EIO; |
| 19193 | } |
| 19194 | return 0; |
| 19195 | } |
| 19196 | |
| 19197 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19198 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 19199 | * @phba: pointer to lpfc hba data structure. |
| 19200 | * |
| 19201 | * This function is the failover routine as a last resort to the FCF DEAD |
| 19202 | * event when driver failed to perform fast FCF failover. |
| 19203 | **/ |
| 19204 | void |
| 19205 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 19206 | { |
| 19207 | uint32_t link_state; |
| 19208 | |
| 19209 | /* |
| 19210 | * Last resort as FCF DEAD event failover will treat this as |
| 19211 | * a link down, but save the link state because we don't want |
| 19212 | * it to be changed to Link Down unless it is already down. |
| 19213 | */ |
| 19214 | link_state = phba->link_state; |
| 19215 | lpfc_linkdown(phba); |
| 19216 | phba->link_state = link_state; |
| 19217 | |
| 19218 | /* Unregister FCF if no devices connected to it */ |
| 19219 | lpfc_unregister_unused_fcf(phba); |
| 19220 | } |
| 19221 | |
| 19222 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19223 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19224 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19225 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19226 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19227 | * This function gets SLI3 port configure region 23 data through memory dump |
| 19228 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19229 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19230 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19231 | static uint32_t |
| 19232 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19233 | { |
| 19234 | LPFC_MBOXQ_t *pmb = NULL; |
| 19235 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19236 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19237 | int rc; |
| 19238 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19239 | if (!rgn23_data) |
| 19240 | return 0; |
| 19241 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19242 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19243 | if (!pmb) { |
| 19244 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19245 | "2600 failed to allocate mailbox memory\n"); |
| 19246 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19247 | } |
| 19248 | mb = &pmb->u.mb; |
| 19249 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19250 | do { |
| 19251 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 19252 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 19253 | |
| 19254 | if (rc != MBX_SUCCESS) { |
| 19255 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19256 | "2601 failed to read config " |
| 19257 | "region 23, rc 0x%x Status 0x%x\n", |
| 19258 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19259 | mb->un.varDmp.word_cnt = 0; |
| 19260 | } |
| 19261 | /* |
| 19262 | * dump mem may return a zero when finished or we got a |
| 19263 | * mailbox error, either way we are done. |
| 19264 | */ |
| 19265 | if (mb->un.varDmp.word_cnt == 0) |
| 19266 | break; |
| 19267 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 19268 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 19269 | |
| 19270 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19271 | rgn23_data + offset, |
| 19272 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19273 | offset += mb->un.varDmp.word_cnt; |
| 19274 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 19275 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19276 | mempool_free(pmb, phba->mbox_mem_pool); |
| 19277 | return offset; |
| 19278 | } |
| 19279 | |
| 19280 | /** |
| 19281 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 19282 | * @phba: pointer to lpfc hba data structure. |
| 19283 | * @rgn23_data: pointer to configure region 23 data. |
| 19284 | * |
| 19285 | * This function gets SLI4 port configure region 23 data through memory dump |
| 19286 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19287 | * will be returned, otherwise, 0 will be returned. |
| 19288 | **/ |
| 19289 | static uint32_t |
| 19290 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 19291 | { |
| 19292 | LPFC_MBOXQ_t *mboxq = NULL; |
| 19293 | struct lpfc_dmabuf *mp = NULL; |
| 19294 | struct lpfc_mqe *mqe; |
| 19295 | uint32_t data_length = 0; |
| 19296 | int rc; |
| 19297 | |
| 19298 | if (!rgn23_data) |
| 19299 | return 0; |
| 19300 | |
| 19301 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19302 | if (!mboxq) { |
| 19303 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19304 | "3105 failed to allocate mailbox memory\n"); |
| 19305 | return 0; |
| 19306 | } |
| 19307 | |
| 19308 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 19309 | goto out; |
| 19310 | mqe = &mboxq->u.mqe; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19311 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19312 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 19313 | if (rc) |
| 19314 | goto out; |
| 19315 | data_length = mqe->un.mb_words[5]; |
| 19316 | if (data_length == 0) |
| 19317 | goto out; |
| 19318 | if (data_length > DMP_RGN23_SIZE) { |
| 19319 | data_length = 0; |
| 19320 | goto out; |
| 19321 | } |
| 19322 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 19323 | out: |
| 19324 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 19325 | if (mp) { |
| 19326 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19327 | kfree(mp); |
| 19328 | } |
| 19329 | return data_length; |
| 19330 | } |
| 19331 | |
| 19332 | /** |
| 19333 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 19334 | * @phba: pointer to lpfc hba data structure. |
| 19335 | * |
| 19336 | * This function read region 23 and parse TLV for port status to |
| 19337 | * decide if the user disaled the port. If the TLV indicates the |
| 19338 | * port is disabled, the hba_flag is set accordingly. |
| 19339 | **/ |
| 19340 | void |
| 19341 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 19342 | { |
| 19343 | uint8_t *rgn23_data = NULL; |
| 19344 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 19345 | uint32_t offset = 0; |
| 19346 | |
| 19347 | /* Get adapter Region 23 data */ |
| 19348 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 19349 | if (!rgn23_data) |
| 19350 | goto out; |
| 19351 | |
| 19352 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 19353 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 19354 | else { |
| 19355 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 19356 | &phba->sli4_hba.sli_intf); |
| 19357 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 19358 | goto out; |
| 19359 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 19360 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19361 | |
| 19362 | if (!data_size) |
| 19363 | goto out; |
| 19364 | |
| 19365 | /* Check the region signature first */ |
| 19366 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 19367 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19368 | "2619 Config region 23 has bad signature\n"); |
| 19369 | goto out; |
| 19370 | } |
| 19371 | offset += 4; |
| 19372 | |
| 19373 | /* Check the data structure version */ |
| 19374 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 19375 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19376 | "2620 Config region 23 has bad version\n"); |
| 19377 | goto out; |
| 19378 | } |
| 19379 | offset += 4; |
| 19380 | |
| 19381 | /* Parse TLV entries in the region */ |
| 19382 | while (offset < data_size) { |
| 19383 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 19384 | break; |
| 19385 | /* |
| 19386 | * If the TLV is not driver specific TLV or driver id is |
| 19387 | * not linux driver id, skip the record. |
| 19388 | */ |
| 19389 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 19390 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 19391 | (rgn23_data[offset + 3] != 0)) { |
| 19392 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19393 | continue; |
| 19394 | } |
| 19395 | |
| 19396 | /* Driver found a driver specific TLV in the config region */ |
| 19397 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 19398 | offset += 4; |
| 19399 | tlv_offset = 0; |
| 19400 | |
| 19401 | /* |
| 19402 | * Search for configured port state sub-TLV. |
| 19403 | */ |
| 19404 | while ((offset < data_size) && |
| 19405 | (tlv_offset < sub_tlv_len)) { |
| 19406 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 19407 | offset += 4; |
| 19408 | tlv_offset += 4; |
| 19409 | break; |
| 19410 | } |
| 19411 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 19412 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19413 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 19414 | continue; |
| 19415 | } |
| 19416 | |
| 19417 | /* This HBA contains PORT_STE configured */ |
| 19418 | if (!rgn23_data[offset + 2]) |
| 19419 | phba->hba_flag |= LINK_DISABLED; |
| 19420 | |
| 19421 | goto out; |
| 19422 | } |
| 19423 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19424 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19425 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19426 | kfree(rgn23_data); |
| 19427 | return; |
| 19428 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19429 | |
| 19430 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19431 | * lpfc_wr_object - write an object to the firmware |
| 19432 | * @phba: HBA structure that indicates port to create a queue on. |
| 19433 | * @dmabuf_list: list of dmabufs to write to the port. |
| 19434 | * @size: the total byte value of the objects to write to the port. |
| 19435 | * @offset: the current offset to be used to start the transfer. |
| 19436 | * |
| 19437 | * This routine will create a wr_object mailbox command to send to the port. |
| 19438 | * the mailbox command will be constructed using the dma buffers described in |
| 19439 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 19440 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 19441 | * used to indicate the starting offset of the transfer and will also return |
| 19442 | * the offset after the write object mailbox has completed. @size is used to |
| 19443 | * determine the end of the object and whether the eof bit should be set. |
| 19444 | * |
| 19445 | * Return 0 is successful and offset will contain the the new offset to use |
| 19446 | * for the next write. |
| 19447 | * Return negative value for error cases. |
| 19448 | **/ |
| 19449 | int |
| 19450 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 19451 | uint32_t size, uint32_t *offset) |
| 19452 | { |
| 19453 | struct lpfc_mbx_wr_object *wr_object; |
| 19454 | LPFC_MBOXQ_t *mbox; |
| 19455 | int rc = 0, i = 0; |
James Smart | f3d0a8a | 2019-12-18 15:58:01 -0800 | [diff] [blame] | 19456 | uint32_t shdr_status, shdr_add_status, shdr_change_status, shdr_csf; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19457 | uint32_t mbox_tmo; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19458 | struct lpfc_dmabuf *dmabuf; |
| 19459 | uint32_t written = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19460 | bool check_change_status = false; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19461 | |
| 19462 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19463 | if (!mbox) |
| 19464 | return -ENOMEM; |
| 19465 | |
| 19466 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 19467 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 19468 | sizeof(struct lpfc_mbx_wr_object) - |
| 19469 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 19470 | |
| 19471 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 19472 | wr_object->u.request.write_offset = *offset; |
| 19473 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 19474 | wr_object->u.request.object_name[0] = |
| 19475 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 19476 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 19477 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 19478 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 19479 | break; |
| 19480 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 19481 | wr_object->u.request.bde[i].addrHigh = |
| 19482 | putPaddrHigh(dmabuf->phys); |
| 19483 | if (written + SLI4_PAGE_SIZE >= size) { |
| 19484 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19485 | (size - written); |
| 19486 | written += (size - written); |
| 19487 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19488 | bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1); |
| 19489 | check_change_status = true; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19490 | } else { |
| 19491 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19492 | SLI4_PAGE_SIZE; |
| 19493 | written += SLI4_PAGE_SIZE; |
| 19494 | } |
| 19495 | i++; |
| 19496 | } |
| 19497 | wr_object->u.request.bde_count = i; |
| 19498 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 19499 | if (!phba->sli4_hba.intr_enable) |
| 19500 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 19501 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 19502 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19503 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 19504 | } |
| 19505 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19506 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 19507 | &wr_object->header.cfg_shdr.response); |
| 19508 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 19509 | &wr_object->header.cfg_shdr.response); |
| 19510 | if (check_change_status) { |
| 19511 | shdr_change_status = bf_get(lpfc_wr_object_change_status, |
| 19512 | &wr_object->u.response); |
James Smart | f3d0a8a | 2019-12-18 15:58:01 -0800 | [diff] [blame] | 19513 | |
| 19514 | if (shdr_change_status == LPFC_CHANGE_STATUS_FW_RESET || |
| 19515 | shdr_change_status == LPFC_CHANGE_STATUS_PORT_MIGRATION) { |
| 19516 | shdr_csf = bf_get(lpfc_wr_object_csf, |
| 19517 | &wr_object->u.response); |
| 19518 | if (shdr_csf) |
| 19519 | shdr_change_status = |
| 19520 | LPFC_CHANGE_STATUS_PCI_RESET; |
| 19521 | } |
| 19522 | |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19523 | switch (shdr_change_status) { |
| 19524 | case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET): |
| 19525 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19526 | "3198 Firmware write complete: System " |
| 19527 | "reboot required to instantiate\n"); |
| 19528 | break; |
| 19529 | case (LPFC_CHANGE_STATUS_FW_RESET): |
| 19530 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19531 | "3199 Firmware write complete: Firmware" |
| 19532 | " reset required to instantiate\n"); |
| 19533 | break; |
| 19534 | case (LPFC_CHANGE_STATUS_PORT_MIGRATION): |
| 19535 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19536 | "3200 Firmware write complete: Port " |
| 19537 | "Migration or PCI Reset required to " |
| 19538 | "instantiate\n"); |
| 19539 | break; |
| 19540 | case (LPFC_CHANGE_STATUS_PCI_RESET): |
| 19541 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19542 | "3201 Firmware write complete: PCI " |
| 19543 | "Reset required to instantiate\n"); |
| 19544 | break; |
| 19545 | default: |
| 19546 | break; |
| 19547 | } |
| 19548 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19549 | if (rc != MBX_TIMEOUT) |
| 19550 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19551 | if (shdr_status || shdr_add_status || rc) { |
| 19552 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19553 | "3025 Write Object mailbox failed with " |
| 19554 | "status x%x add_status x%x, mbx status x%x\n", |
| 19555 | shdr_status, shdr_add_status, rc); |
| 19556 | rc = -ENXIO; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 19557 | *offset = shdr_add_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19558 | } else |
| 19559 | *offset += wr_object->u.response.actual_write_length; |
| 19560 | return rc; |
| 19561 | } |
| 19562 | |
| 19563 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19564 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 19565 | * @vport: pointer to vport data structure. |
| 19566 | * |
| 19567 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 19568 | * and REG_VPI mailbox commands associated with the vport. This function |
| 19569 | * is called when driver want to restart discovery of the vport due to |
| 19570 | * a Clear Virtual Link event. |
| 19571 | **/ |
| 19572 | void |
| 19573 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 19574 | { |
| 19575 | struct lpfc_hba *phba = vport->phba; |
| 19576 | LPFC_MBOXQ_t *mb, *nextmb; |
| 19577 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19578 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19579 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19580 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19581 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19582 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19583 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19584 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19585 | spin_lock_irq(&phba->hbalock); |
| 19586 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 19587 | if (mb->vport != vport) |
| 19588 | continue; |
| 19589 | |
| 19590 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19591 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19592 | continue; |
| 19593 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19594 | list_del(&mb->list); |
| 19595 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 19596 | } |
| 19597 | /* Clean up active mailbox command with the vport */ |
| 19598 | mb = phba->sli.mbox_active; |
| 19599 | if (mb && (mb->vport == vport)) { |
| 19600 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 19601 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 19602 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19603 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19604 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19605 | /* Put reference count for delayed processing */ |
| 19606 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 19607 | /* Unregister the RPI when mailbox complete */ |
| 19608 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19609 | } |
| 19610 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19611 | /* Cleanup any mailbox completions which are not yet processed */ |
| 19612 | do { |
| 19613 | restart_loop = 0; |
| 19614 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 19615 | /* |
| 19616 | * If this mailox is already processed or it is |
| 19617 | * for another vport ignore it. |
| 19618 | */ |
| 19619 | if ((mb->vport != vport) || |
| 19620 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 19621 | continue; |
| 19622 | |
| 19623 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19624 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19625 | continue; |
| 19626 | |
| 19627 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19628 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19629 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19630 | /* Unregister the RPI when mailbox complete */ |
| 19631 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19632 | restart_loop = 1; |
| 19633 | spin_unlock_irq(&phba->hbalock); |
| 19634 | spin_lock(shost->host_lock); |
| 19635 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19636 | spin_unlock(shost->host_lock); |
| 19637 | spin_lock_irq(&phba->hbalock); |
| 19638 | break; |
| 19639 | } |
| 19640 | } |
| 19641 | } while (restart_loop); |
| 19642 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19643 | spin_unlock_irq(&phba->hbalock); |
| 19644 | |
| 19645 | /* Release the cleaned-up mailbox commands */ |
| 19646 | while (!list_empty(&mbox_cmd_list)) { |
| 19647 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19648 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19649 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19650 | if (mp) { |
| 19651 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19652 | kfree(mp); |
| 19653 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19654 | mb->ctx_buf = NULL; |
| 19655 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
| 19656 | mb->ctx_ndlp = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19657 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19658 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19659 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19660 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19661 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19662 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19663 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19664 | mempool_free(mb, phba->mbox_mem_pool); |
| 19665 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19666 | |
| 19667 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 19668 | if (act_mbx_ndlp) { |
| 19669 | spin_lock(shost->host_lock); |
| 19670 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19671 | spin_unlock(shost->host_lock); |
| 19672 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19673 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19674 | } |
| 19675 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19676 | /** |
| 19677 | * lpfc_drain_txq - Drain the txq |
| 19678 | * @phba: Pointer to HBA context object. |
| 19679 | * |
| 19680 | * This function attempt to submit IOCBs on the txq |
| 19681 | * to the adapter. For SLI4 adapters, the txq contains |
| 19682 | * ELS IOCBs that have been deferred because the there |
| 19683 | * are no SGLs. This congestion can occur with large |
| 19684 | * vport counts during node discovery. |
| 19685 | **/ |
| 19686 | |
| 19687 | uint32_t |
| 19688 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 19689 | { |
| 19690 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19691 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 19692 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19693 | unsigned long iflags = 0; |
| 19694 | char *fail_msg = NULL; |
| 19695 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19696 | union lpfc_wqe128 wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 19697 | uint32_t txq_cnt = 0; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19698 | struct lpfc_queue *wq; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19699 | |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19700 | if (phba->link_flag & LS_MDS_LOOPBACK) { |
| 19701 | /* MDS WQE are posted only to first WQ*/ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19702 | wq = phba->sli4_hba.hdwq[0].io_wq; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19703 | if (unlikely(!wq)) |
| 19704 | return 0; |
| 19705 | pring = wq->pring; |
| 19706 | } else { |
| 19707 | wq = phba->sli4_hba.els_wq; |
| 19708 | if (unlikely(!wq)) |
| 19709 | return 0; |
| 19710 | pring = lpfc_phba_elsring(phba); |
| 19711 | } |
| 19712 | |
| 19713 | if (unlikely(!pring) || list_empty(&pring->txq)) |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 19714 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19715 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19716 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19717 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 19718 | txq_cnt++; |
| 19719 | } |
| 19720 | |
| 19721 | if (txq_cnt > pring->txq_max) |
| 19722 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19723 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19724 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19725 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19726 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19727 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19728 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19729 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19730 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19731 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19732 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19733 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19734 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19735 | break; |
| 19736 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19737 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19738 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19739 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19740 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19741 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19742 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19743 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19744 | |
| 19745 | /* The xri and iocb resources secured, |
| 19746 | * attempt to issue request |
| 19747 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19748 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19749 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 19750 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 19751 | fail_msg = "to convert bpl to sgl"; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19752 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19753 | fail_msg = "to convert iocb to wqe"; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19754 | else if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19755 | fail_msg = " - Wq is full"; |
| 19756 | else |
| 19757 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 19758 | |
| 19759 | if (fail_msg) { |
| 19760 | /* Failed means we can't issue and need to cancel */ |
| 19761 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19762 | "2822 IOCB failed %s iotag 0x%x " |
| 19763 | "xri 0x%x\n", |
| 19764 | fail_msg, |
| 19765 | piocbq->iotag, piocbq->sli4_xritag); |
| 19766 | list_add_tail(&piocbq->list, &completions); |
| 19767 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19768 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19769 | } |
| 19770 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19771 | /* Cancel all the IOCBs that cannot be issued */ |
| 19772 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 19773 | IOERR_SLI_ABORTED); |
| 19774 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19775 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19776 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19777 | |
| 19778 | /** |
| 19779 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 19780 | * @phba: Pointer to HBA context object. |
| 19781 | * @pwqe: Pointer to command WQE. |
| 19782 | * @sglq: Pointer to the scatter gather queue object. |
| 19783 | * |
| 19784 | * This routine converts the bpl or bde that is in the WQE |
| 19785 | * to a sgl list for the sli4 hardware. The physical address |
| 19786 | * of the bpl/bde is converted back to a virtual address. |
| 19787 | * If the WQE contains a BPL then the list of BDE's is |
| 19788 | * converted to sli4_sge's. If the WQE contains a single |
| 19789 | * BDE then it is converted to a single sli_sge. |
| 19790 | * The WQE is still in cpu endianness so the contents of |
| 19791 | * the bpl can be used without byte swapping. |
| 19792 | * |
| 19793 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 19794 | */ |
| 19795 | static uint16_t |
| 19796 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 19797 | struct lpfc_sglq *sglq) |
| 19798 | { |
| 19799 | uint16_t xritag = NO_XRI; |
| 19800 | struct ulp_bde64 *bpl = NULL; |
| 19801 | struct ulp_bde64 bde; |
| 19802 | struct sli4_sge *sgl = NULL; |
| 19803 | struct lpfc_dmabuf *dmabuf; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19804 | union lpfc_wqe128 *wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19805 | int numBdes = 0; |
| 19806 | int i = 0; |
| 19807 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 19808 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 19809 | uint32_t cmd; |
| 19810 | |
| 19811 | if (!pwqeq || !sglq) |
| 19812 | return xritag; |
| 19813 | |
| 19814 | sgl = (struct sli4_sge *)sglq->sgl; |
| 19815 | wqe = &pwqeq->wqe; |
| 19816 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 19817 | |
| 19818 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 19819 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 19820 | return sglq->sli4_xritag; |
| 19821 | numBdes = pwqeq->rsvd2; |
| 19822 | if (numBdes) { |
| 19823 | /* The addrHigh and addrLow fields within the WQE |
| 19824 | * have not been byteswapped yet so there is no |
| 19825 | * need to swap them back. |
| 19826 | */ |
| 19827 | if (pwqeq->context3) |
| 19828 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 19829 | else |
| 19830 | return xritag; |
| 19831 | |
| 19832 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 19833 | if (!bpl) |
| 19834 | return xritag; |
| 19835 | |
| 19836 | for (i = 0; i < numBdes; i++) { |
| 19837 | /* Should already be byte swapped. */ |
| 19838 | sgl->addr_hi = bpl->addrHigh; |
| 19839 | sgl->addr_lo = bpl->addrLow; |
| 19840 | |
| 19841 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19842 | if ((i+1) == numBdes) |
| 19843 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19844 | else |
| 19845 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 19846 | /* swap the size field back to the cpu so we |
| 19847 | * can assign it to the sgl. |
| 19848 | */ |
| 19849 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 19850 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 19851 | /* The offsets in the sgl need to be accumulated |
| 19852 | * separately for the request and reply lists. |
| 19853 | * The request is always first, the reply follows. |
| 19854 | */ |
| 19855 | switch (cmd) { |
| 19856 | case CMD_GEN_REQUEST64_WQE: |
| 19857 | /* add up the reply sg entries */ |
| 19858 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 19859 | inbound++; |
| 19860 | /* first inbound? reset the offset */ |
| 19861 | if (inbound == 1) |
| 19862 | offset = 0; |
| 19863 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19864 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19865 | LPFC_SGE_TYPE_DATA); |
| 19866 | offset += bde.tus.f.bdeSize; |
| 19867 | break; |
| 19868 | case CMD_FCP_TRSP64_WQE: |
| 19869 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 19870 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19871 | LPFC_SGE_TYPE_DATA); |
| 19872 | break; |
| 19873 | case CMD_FCP_TSEND64_WQE: |
| 19874 | case CMD_FCP_TRECEIVE64_WQE: |
| 19875 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19876 | bpl->tus.f.bdeFlags); |
| 19877 | if (i < 3) |
| 19878 | offset = 0; |
| 19879 | else |
| 19880 | offset += bde.tus.f.bdeSize; |
| 19881 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19882 | break; |
| 19883 | } |
| 19884 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19885 | bpl++; |
| 19886 | sgl++; |
| 19887 | } |
| 19888 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 19889 | /* The addrHigh and addrLow fields of the BDE have not |
| 19890 | * been byteswapped yet so they need to be swapped |
| 19891 | * before putting them in the sgl. |
| 19892 | */ |
| 19893 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 19894 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 19895 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19896 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19897 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19898 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 19899 | } |
| 19900 | return sglq->sli4_xritag; |
| 19901 | } |
| 19902 | |
| 19903 | /** |
| 19904 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 19905 | * @phba: Pointer to HBA context object. |
| 19906 | * @ring_number: Base sli ring number |
| 19907 | * @pwqe: Pointer to command WQE. |
| 19908 | **/ |
| 19909 | int |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19910 | 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] | 19911 | struct lpfc_iocbq *pwqe) |
| 19912 | { |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19913 | union lpfc_wqe128 *wqe = &pwqe->wqe; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19914 | struct lpfc_nvmet_rcv_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19915 | struct lpfc_queue *wq; |
| 19916 | struct lpfc_sglq *sglq; |
| 19917 | struct lpfc_sli_ring *pring; |
| 19918 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19919 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19920 | |
| 19921 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 19922 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 19923 | pring = phba->sli4_hba.nvmels_wq->pring; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19924 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19925 | qp, wq_access); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19926 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 19927 | if (!sglq) { |
| 19928 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19929 | return WQE_BUSY; |
| 19930 | } |
| 19931 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19932 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19933 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 19934 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19935 | return WQE_ERROR; |
| 19936 | } |
| 19937 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19938 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19939 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 19940 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19941 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19942 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19943 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19944 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19945 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19946 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 19947 | |
| 19948 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19949 | return 0; |
| 19950 | } |
| 19951 | |
| 19952 | /* NVME_FCREQ and NVME_ABTS requests */ |
| 19953 | if (pwqe->iocb_flag & LPFC_IO_NVME) { |
| 19954 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19955 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19956 | pring = wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19957 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19958 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19959 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19960 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19961 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19962 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19963 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19964 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19965 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19966 | } |
| 19967 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19968 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 19969 | |
| 19970 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19971 | return 0; |
| 19972 | } |
| 19973 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19974 | /* NVMET requests */ |
| 19975 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 19976 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19977 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19978 | pring = wq->pring; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19979 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19980 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 19981 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19982 | if (pwqe->sli4_xritag == NO_XRI) { |
| 19983 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19984 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19985 | } |
| 19986 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19987 | pwqe->sli4_xritag); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19988 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19989 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19990 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19991 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19992 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19993 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19994 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19995 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19996 | } |
| 19997 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19998 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 19999 | |
| 20000 | lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 20001 | return 0; |
| 20002 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 20003 | return WQE_ERROR; |
| 20004 | } |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20005 | |
| 20006 | #ifdef LPFC_MXP_STAT |
| 20007 | /** |
| 20008 | * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count |
| 20009 | * @phba: pointer to lpfc hba data structure. |
| 20010 | * @hwqid: belong to which HWQ. |
| 20011 | * |
| 20012 | * The purpose of this routine is to take a snapshot of pbl, pvt and busy count |
| 20013 | * 15 seconds after a test case is running. |
| 20014 | * |
| 20015 | * The user should call lpfc_debugfs_multixripools_write before running a test |
| 20016 | * case to clear stat_snapshot_taken. Then the user starts a test case. During |
| 20017 | * test case is running, stat_snapshot_taken is incremented by 1 every time when |
| 20018 | * this routine is called from heartbeat timer. When stat_snapshot_taken is |
| 20019 | * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken. |
| 20020 | **/ |
| 20021 | void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid) |
| 20022 | { |
| 20023 | struct lpfc_sli4_hdw_queue *qp; |
| 20024 | struct lpfc_multixri_pool *multixri_pool; |
| 20025 | struct lpfc_pvt_pool *pvt_pool; |
| 20026 | struct lpfc_pbl_pool *pbl_pool; |
| 20027 | u32 txcmplq_cnt; |
| 20028 | |
| 20029 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20030 | multixri_pool = qp->p_multixri_pool; |
| 20031 | if (!multixri_pool) |
| 20032 | return; |
| 20033 | |
| 20034 | if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) { |
| 20035 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 20036 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20037 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20038 | |
| 20039 | multixri_pool->stat_pbl_count = pbl_pool->count; |
| 20040 | multixri_pool->stat_pvt_count = pvt_pool->count; |
| 20041 | multixri_pool->stat_busy_count = txcmplq_cnt; |
| 20042 | } |
| 20043 | |
| 20044 | multixri_pool->stat_snapshot_taken++; |
| 20045 | } |
| 20046 | #endif |
| 20047 | |
| 20048 | /** |
| 20049 | * lpfc_adjust_pvt_pool_count - Adjust private pool count |
| 20050 | * @phba: pointer to lpfc hba data structure. |
| 20051 | * @hwqid: belong to which HWQ. |
| 20052 | * |
| 20053 | * This routine moves some XRIs from private to public pool when private pool |
| 20054 | * is not busy. |
| 20055 | **/ |
| 20056 | void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid) |
| 20057 | { |
| 20058 | struct lpfc_multixri_pool *multixri_pool; |
| 20059 | u32 io_req_count; |
| 20060 | u32 prev_io_req_count; |
| 20061 | |
| 20062 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 20063 | if (!multixri_pool) |
| 20064 | return; |
| 20065 | io_req_count = multixri_pool->io_req_count; |
| 20066 | prev_io_req_count = multixri_pool->prev_io_req_count; |
| 20067 | |
| 20068 | if (prev_io_req_count != io_req_count) { |
| 20069 | /* Private pool is busy */ |
| 20070 | multixri_pool->prev_io_req_count = io_req_count; |
| 20071 | } else { |
| 20072 | /* Private pool is not busy. |
| 20073 | * Move XRIs from private to public pool. |
| 20074 | */ |
| 20075 | lpfc_move_xri_pvt_to_pbl(phba, hwqid); |
| 20076 | } |
| 20077 | } |
| 20078 | |
| 20079 | /** |
| 20080 | * lpfc_adjust_high_watermark - Adjust high watermark |
| 20081 | * @phba: pointer to lpfc hba data structure. |
| 20082 | * @hwqid: belong to which HWQ. |
| 20083 | * |
| 20084 | * This routine sets high watermark as number of outstanding XRIs, |
| 20085 | * but make sure the new value is between xri_limit/2 and xri_limit. |
| 20086 | **/ |
| 20087 | void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid) |
| 20088 | { |
| 20089 | u32 new_watermark; |
| 20090 | u32 watermark_max; |
| 20091 | u32 watermark_min; |
| 20092 | u32 xri_limit; |
| 20093 | u32 txcmplq_cnt; |
| 20094 | u32 abts_io_bufs; |
| 20095 | struct lpfc_multixri_pool *multixri_pool; |
| 20096 | struct lpfc_sli4_hdw_queue *qp; |
| 20097 | |
| 20098 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20099 | multixri_pool = qp->p_multixri_pool; |
| 20100 | if (!multixri_pool) |
| 20101 | return; |
| 20102 | xri_limit = multixri_pool->xri_limit; |
| 20103 | |
| 20104 | watermark_max = xri_limit; |
| 20105 | watermark_min = xri_limit / 2; |
| 20106 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20107 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20108 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20109 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20110 | |
| 20111 | new_watermark = txcmplq_cnt + abts_io_bufs; |
| 20112 | new_watermark = min(watermark_max, new_watermark); |
| 20113 | new_watermark = max(watermark_min, new_watermark); |
| 20114 | multixri_pool->pvt_pool.high_watermark = new_watermark; |
| 20115 | |
| 20116 | #ifdef LPFC_MXP_STAT |
| 20117 | multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm, |
| 20118 | new_watermark); |
| 20119 | #endif |
| 20120 | } |
| 20121 | |
| 20122 | /** |
| 20123 | * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool |
| 20124 | * @phba: pointer to lpfc hba data structure. |
| 20125 | * @hwqid: belong to which HWQ. |
| 20126 | * |
| 20127 | * This routine is called from hearbeat timer when pvt_pool is idle. |
| 20128 | * All free XRIs are moved from private to public pool on hwqid with 2 steps. |
| 20129 | * The first step moves (all - low_watermark) amount of XRIs. |
| 20130 | * The second step moves the rest of XRIs. |
| 20131 | **/ |
| 20132 | void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid) |
| 20133 | { |
| 20134 | struct lpfc_pbl_pool *pbl_pool; |
| 20135 | struct lpfc_pvt_pool *pvt_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20136 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20137 | struct lpfc_io_buf *lpfc_ncmd; |
| 20138 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20139 | unsigned long iflag; |
| 20140 | struct list_head tmp_list; |
| 20141 | u32 tmp_count; |
| 20142 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20143 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20144 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 20145 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20146 | tmp_count = 0; |
| 20147 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20148 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool); |
| 20149 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20150 | |
| 20151 | if (pvt_pool->count > pvt_pool->low_watermark) { |
| 20152 | /* Step 1: move (all - low_watermark) from pvt_pool |
| 20153 | * to pbl_pool |
| 20154 | */ |
| 20155 | |
| 20156 | /* Move low watermark of bufs from pvt_pool to tmp_list */ |
| 20157 | INIT_LIST_HEAD(&tmp_list); |
| 20158 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20159 | &pvt_pool->list, list) { |
| 20160 | list_move_tail(&lpfc_ncmd->list, &tmp_list); |
| 20161 | tmp_count++; |
| 20162 | if (tmp_count >= pvt_pool->low_watermark) |
| 20163 | break; |
| 20164 | } |
| 20165 | |
| 20166 | /* Move all bufs from pvt_pool to pbl_pool */ |
| 20167 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 20168 | |
| 20169 | /* Move all bufs from tmp_list to pvt_pool */ |
| 20170 | list_splice(&tmp_list, &pvt_pool->list); |
| 20171 | |
| 20172 | pbl_pool->count += (pvt_pool->count - tmp_count); |
| 20173 | pvt_pool->count = tmp_count; |
| 20174 | } else { |
| 20175 | /* Step 2: move the rest from pvt_pool to pbl_pool */ |
| 20176 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 20177 | pbl_pool->count += pvt_pool->count; |
| 20178 | pvt_pool->count = 0; |
| 20179 | } |
| 20180 | |
| 20181 | spin_unlock(&pvt_pool->lock); |
| 20182 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20183 | } |
| 20184 | |
| 20185 | /** |
| 20186 | * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 20187 | * @phba: pointer to lpfc hba data structure |
| 20188 | * @pbl_pool: specified public free XRI pool |
| 20189 | * @pvt_pool: specified private free XRI pool |
| 20190 | * @count: number of XRIs to move |
| 20191 | * |
| 20192 | * This routine tries to move some free common bufs from the specified pbl_pool |
| 20193 | * to the specified pvt_pool. It might move less than count XRIs if there's not |
| 20194 | * enough in public pool. |
| 20195 | * |
| 20196 | * Return: |
| 20197 | * true - if XRIs are successfully moved from the specified pbl_pool to the |
| 20198 | * specified pvt_pool |
| 20199 | * false - if the specified pbl_pool is empty or locked by someone else |
| 20200 | **/ |
| 20201 | static bool |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20202 | _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp, |
| 20203 | struct lpfc_pbl_pool *pbl_pool, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20204 | struct lpfc_pvt_pool *pvt_pool, u32 count) |
| 20205 | { |
| 20206 | struct lpfc_io_buf *lpfc_ncmd; |
| 20207 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20208 | unsigned long iflag; |
| 20209 | int ret; |
| 20210 | |
| 20211 | ret = spin_trylock_irqsave(&pbl_pool->lock, iflag); |
| 20212 | if (ret) { |
| 20213 | if (pbl_pool->count) { |
| 20214 | /* Move a batch of XRIs from public to private pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20215 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20216 | list_for_each_entry_safe(lpfc_ncmd, |
| 20217 | lpfc_ncmd_next, |
| 20218 | &pbl_pool->list, |
| 20219 | list) { |
| 20220 | list_move_tail(&lpfc_ncmd->list, |
| 20221 | &pvt_pool->list); |
| 20222 | pvt_pool->count++; |
| 20223 | pbl_pool->count--; |
| 20224 | count--; |
| 20225 | if (count == 0) |
| 20226 | break; |
| 20227 | } |
| 20228 | |
| 20229 | spin_unlock(&pvt_pool->lock); |
| 20230 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20231 | return true; |
| 20232 | } |
| 20233 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20234 | } |
| 20235 | |
| 20236 | return false; |
| 20237 | } |
| 20238 | |
| 20239 | /** |
| 20240 | * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 20241 | * @phba: pointer to lpfc hba data structure. |
| 20242 | * @hwqid: belong to which HWQ. |
| 20243 | * @count: number of XRIs to move |
| 20244 | * |
| 20245 | * This routine tries to find some free common bufs in one of public pools with |
| 20246 | * Round Robin method. The search always starts from local hwqid, then the next |
| 20247 | * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found, |
| 20248 | * a batch of free common bufs are moved to private pool on hwqid. |
| 20249 | * It might move less than count XRIs if there's not enough in public pool. |
| 20250 | **/ |
| 20251 | void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count) |
| 20252 | { |
| 20253 | struct lpfc_multixri_pool *multixri_pool; |
| 20254 | struct lpfc_multixri_pool *next_multixri_pool; |
| 20255 | struct lpfc_pvt_pool *pvt_pool; |
| 20256 | struct lpfc_pbl_pool *pbl_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20257 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20258 | u32 next_hwqid; |
| 20259 | u32 hwq_count; |
| 20260 | int ret; |
| 20261 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20262 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20263 | multixri_pool = qp->p_multixri_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20264 | pvt_pool = &multixri_pool->pvt_pool; |
| 20265 | pbl_pool = &multixri_pool->pbl_pool; |
| 20266 | |
| 20267 | /* Check if local pbl_pool is available */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20268 | 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] | 20269 | if (ret) { |
| 20270 | #ifdef LPFC_MXP_STAT |
| 20271 | multixri_pool->local_pbl_hit_count++; |
| 20272 | #endif |
| 20273 | return; |
| 20274 | } |
| 20275 | |
| 20276 | hwq_count = phba->cfg_hdw_queue; |
| 20277 | |
| 20278 | /* Get the next hwqid which was found last time */ |
| 20279 | next_hwqid = multixri_pool->rrb_next_hwqid; |
| 20280 | |
| 20281 | do { |
| 20282 | /* Go to next hwq */ |
| 20283 | next_hwqid = (next_hwqid + 1) % hwq_count; |
| 20284 | |
| 20285 | next_multixri_pool = |
| 20286 | phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool; |
| 20287 | pbl_pool = &next_multixri_pool->pbl_pool; |
| 20288 | |
| 20289 | /* Check if the public free xri pool is available */ |
| 20290 | ret = _lpfc_move_xri_pbl_to_pvt( |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20291 | phba, qp, pbl_pool, pvt_pool, count); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20292 | |
| 20293 | /* Exit while-loop if success or all hwqid are checked */ |
| 20294 | } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid); |
| 20295 | |
| 20296 | /* Starting point for the next time */ |
| 20297 | multixri_pool->rrb_next_hwqid = next_hwqid; |
| 20298 | |
| 20299 | if (!ret) { |
| 20300 | /* stats: all public pools are empty*/ |
| 20301 | multixri_pool->pbl_empty_count++; |
| 20302 | } |
| 20303 | |
| 20304 | #ifdef LPFC_MXP_STAT |
| 20305 | if (ret) { |
| 20306 | if (next_hwqid == hwqid) |
| 20307 | multixri_pool->local_pbl_hit_count++; |
| 20308 | else |
| 20309 | multixri_pool->other_pbl_hit_count++; |
| 20310 | } |
| 20311 | #endif |
| 20312 | } |
| 20313 | |
| 20314 | /** |
| 20315 | * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark |
| 20316 | * @phba: pointer to lpfc hba data structure. |
| 20317 | * @qp: belong to which HWQ. |
| 20318 | * |
| 20319 | * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than |
| 20320 | * low watermark. |
| 20321 | **/ |
| 20322 | void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid) |
| 20323 | { |
| 20324 | struct lpfc_multixri_pool *multixri_pool; |
| 20325 | struct lpfc_pvt_pool *pvt_pool; |
| 20326 | |
| 20327 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 20328 | pvt_pool = &multixri_pool->pvt_pool; |
| 20329 | |
| 20330 | if (pvt_pool->count < pvt_pool->low_watermark) |
| 20331 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20332 | } |
| 20333 | |
| 20334 | /** |
| 20335 | * lpfc_release_io_buf - Return one IO buf back to free pool |
| 20336 | * @phba: pointer to lpfc hba data structure. |
| 20337 | * @lpfc_ncmd: IO buf to be returned. |
| 20338 | * @qp: belong to which HWQ. |
| 20339 | * |
| 20340 | * This routine returns one IO buf back to free pool. If this is an urgent IO, |
| 20341 | * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1, |
| 20342 | * the IO buf is returned to pbl_pool or pvt_pool based on watermark and |
| 20343 | * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to |
| 20344 | * lpfc_io_buf_list_put. |
| 20345 | **/ |
| 20346 | void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd, |
| 20347 | struct lpfc_sli4_hdw_queue *qp) |
| 20348 | { |
| 20349 | unsigned long iflag; |
| 20350 | struct lpfc_pbl_pool *pbl_pool; |
| 20351 | struct lpfc_pvt_pool *pvt_pool; |
| 20352 | struct lpfc_epd_pool *epd_pool; |
| 20353 | u32 txcmplq_cnt; |
| 20354 | u32 xri_owned; |
| 20355 | u32 xri_limit; |
| 20356 | u32 abts_io_bufs; |
| 20357 | |
| 20358 | /* MUST zero fields if buffer is reused by another protocol */ |
| 20359 | lpfc_ncmd->nvmeCmd = NULL; |
| 20360 | lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL; |
| 20361 | lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL; |
| 20362 | |
James Smart | 35a635a | 2019-09-21 20:59:02 -0700 | [diff] [blame] | 20363 | if (phba->cfg_xpsgl && !phba->nvmet_support && |
| 20364 | !list_empty(&lpfc_ncmd->dma_sgl_xtra_list)) |
| 20365 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 20366 | |
| 20367 | if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list)) |
| 20368 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
| 20369 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20370 | if (phba->cfg_xri_rebalancing) { |
| 20371 | if (lpfc_ncmd->expedite) { |
| 20372 | /* Return to expedite pool */ |
| 20373 | epd_pool = &phba->epd_pool; |
| 20374 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20375 | list_add_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 20376 | epd_pool->count++; |
| 20377 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20378 | return; |
| 20379 | } |
| 20380 | |
| 20381 | /* Avoid invalid access if an IO sneaks in and is being rejected |
| 20382 | * just _after_ xri pools are destroyed in lpfc_offline. |
| 20383 | * Nothing much can be done at this point. |
| 20384 | */ |
| 20385 | if (!qp->p_multixri_pool) |
| 20386 | return; |
| 20387 | |
| 20388 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 20389 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 20390 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20391 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20392 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20393 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20394 | |
| 20395 | xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs; |
| 20396 | xri_limit = qp->p_multixri_pool->xri_limit; |
| 20397 | |
| 20398 | #ifdef LPFC_MXP_STAT |
| 20399 | if (xri_owned <= xri_limit) |
| 20400 | qp->p_multixri_pool->below_limit_count++; |
| 20401 | else |
| 20402 | qp->p_multixri_pool->above_limit_count++; |
| 20403 | #endif |
| 20404 | |
| 20405 | /* XRI goes to either public or private free xri pool |
| 20406 | * based on watermark and xri_limit |
| 20407 | */ |
| 20408 | if ((pvt_pool->count < pvt_pool->low_watermark) || |
| 20409 | (xri_owned < xri_limit && |
| 20410 | pvt_pool->count < pvt_pool->high_watermark)) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20411 | lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, |
| 20412 | qp, free_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20413 | list_add_tail(&lpfc_ncmd->list, |
| 20414 | &pvt_pool->list); |
| 20415 | pvt_pool->count++; |
| 20416 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20417 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20418 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, |
| 20419 | qp, free_pub_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20420 | list_add_tail(&lpfc_ncmd->list, |
| 20421 | &pbl_pool->list); |
| 20422 | pbl_pool->count++; |
| 20423 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20424 | } |
| 20425 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20426 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag, |
| 20427 | qp, free_xri); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20428 | list_add_tail(&lpfc_ncmd->list, |
| 20429 | &qp->lpfc_io_buf_list_put); |
| 20430 | qp->put_io_bufs++; |
| 20431 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, |
| 20432 | iflag); |
| 20433 | } |
| 20434 | } |
| 20435 | |
| 20436 | /** |
| 20437 | * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool |
| 20438 | * @phba: pointer to lpfc hba data structure. |
| 20439 | * @pvt_pool: pointer to private pool data structure. |
| 20440 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20441 | * |
| 20442 | * This routine tries to get one free IO buf from private pool. |
| 20443 | * |
| 20444 | * Return: |
| 20445 | * pointer to one free IO buf - if private pool is not empty |
| 20446 | * NULL - if private pool is empty |
| 20447 | **/ |
| 20448 | static struct lpfc_io_buf * |
| 20449 | lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20450 | struct lpfc_sli4_hdw_queue *qp, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20451 | struct lpfc_pvt_pool *pvt_pool, |
| 20452 | struct lpfc_nodelist *ndlp) |
| 20453 | { |
| 20454 | struct lpfc_io_buf *lpfc_ncmd; |
| 20455 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20456 | unsigned long iflag; |
| 20457 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20458 | 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] | 20459 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20460 | &pvt_pool->list, list) { |
| 20461 | if (lpfc_test_rrq_active( |
| 20462 | phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag)) |
| 20463 | continue; |
| 20464 | list_del(&lpfc_ncmd->list); |
| 20465 | pvt_pool->count--; |
| 20466 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20467 | return lpfc_ncmd; |
| 20468 | } |
| 20469 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20470 | |
| 20471 | return NULL; |
| 20472 | } |
| 20473 | |
| 20474 | /** |
| 20475 | * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool |
| 20476 | * @phba: pointer to lpfc hba data structure. |
| 20477 | * |
| 20478 | * This routine tries to get one free IO buf from expedite pool. |
| 20479 | * |
| 20480 | * Return: |
| 20481 | * pointer to one free IO buf - if expedite pool is not empty |
| 20482 | * NULL - if expedite pool is empty |
| 20483 | **/ |
| 20484 | static struct lpfc_io_buf * |
| 20485 | lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba) |
| 20486 | { |
| 20487 | struct lpfc_io_buf *lpfc_ncmd; |
| 20488 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20489 | unsigned long iflag; |
| 20490 | struct lpfc_epd_pool *epd_pool; |
| 20491 | |
| 20492 | epd_pool = &phba->epd_pool; |
| 20493 | lpfc_ncmd = NULL; |
| 20494 | |
| 20495 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20496 | if (epd_pool->count > 0) { |
| 20497 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20498 | &epd_pool->list, list) { |
| 20499 | list_del(&lpfc_ncmd->list); |
| 20500 | epd_pool->count--; |
| 20501 | break; |
| 20502 | } |
| 20503 | } |
| 20504 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20505 | |
| 20506 | return lpfc_ncmd; |
| 20507 | } |
| 20508 | |
| 20509 | /** |
| 20510 | * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs |
| 20511 | * @phba: pointer to lpfc hba data structure. |
| 20512 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20513 | * @hwqid: belong to which HWQ |
| 20514 | * @expedite: 1 means this request is urgent. |
| 20515 | * |
| 20516 | * This routine will do the following actions and then return a pointer to |
| 20517 | * one free IO buf. |
| 20518 | * |
| 20519 | * 1. If private free xri count is empty, move some XRIs from public to |
| 20520 | * private pool. |
| 20521 | * 2. Get one XRI from private free xri pool. |
| 20522 | * 3. If we fail to get one from pvt_pool and this is an expedite request, |
| 20523 | * get one free xri from expedite pool. |
| 20524 | * |
| 20525 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20526 | * The caller should pass NULL for ndlp on NVME side. |
| 20527 | * |
| 20528 | * Return: |
| 20529 | * pointer to one free IO buf - if private pool is not empty |
| 20530 | * NULL - if private pool is empty |
| 20531 | **/ |
| 20532 | static struct lpfc_io_buf * |
| 20533 | lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba, |
| 20534 | struct lpfc_nodelist *ndlp, |
| 20535 | int hwqid, int expedite) |
| 20536 | { |
| 20537 | struct lpfc_sli4_hdw_queue *qp; |
| 20538 | struct lpfc_multixri_pool *multixri_pool; |
| 20539 | struct lpfc_pvt_pool *pvt_pool; |
| 20540 | struct lpfc_io_buf *lpfc_ncmd; |
| 20541 | |
| 20542 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20543 | lpfc_ncmd = NULL; |
| 20544 | multixri_pool = qp->p_multixri_pool; |
| 20545 | pvt_pool = &multixri_pool->pvt_pool; |
| 20546 | multixri_pool->io_req_count++; |
| 20547 | |
| 20548 | /* If pvt_pool is empty, move some XRIs from public to private pool */ |
| 20549 | if (pvt_pool->count == 0) |
| 20550 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20551 | |
| 20552 | /* Get one XRI from private free xri pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20553 | 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] | 20554 | |
| 20555 | if (lpfc_ncmd) { |
| 20556 | lpfc_ncmd->hdwq = qp; |
| 20557 | lpfc_ncmd->hdwq_no = hwqid; |
| 20558 | } else if (expedite) { |
| 20559 | /* If we fail to get one from pvt_pool and this is an expedite |
| 20560 | * request, get one free xri from expedite pool. |
| 20561 | */ |
| 20562 | lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba); |
| 20563 | } |
| 20564 | |
| 20565 | return lpfc_ncmd; |
| 20566 | } |
| 20567 | |
| 20568 | static inline struct lpfc_io_buf * |
| 20569 | lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx) |
| 20570 | { |
| 20571 | struct lpfc_sli4_hdw_queue *qp; |
| 20572 | struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next; |
| 20573 | |
| 20574 | qp = &phba->sli4_hba.hdwq[idx]; |
| 20575 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 20576 | &qp->lpfc_io_buf_list_get, list) { |
| 20577 | if (lpfc_test_rrq_active(phba, ndlp, |
| 20578 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 20579 | continue; |
| 20580 | |
| 20581 | if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED) |
| 20582 | continue; |
| 20583 | |
| 20584 | list_del_init(&lpfc_cmd->list); |
| 20585 | qp->get_io_bufs--; |
| 20586 | lpfc_cmd->hdwq = qp; |
| 20587 | lpfc_cmd->hdwq_no = idx; |
| 20588 | return lpfc_cmd; |
| 20589 | } |
| 20590 | return NULL; |
| 20591 | } |
| 20592 | |
| 20593 | /** |
| 20594 | * lpfc_get_io_buf - Get one IO buffer from free pool |
| 20595 | * @phba: The HBA for which this call is being executed. |
| 20596 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20597 | * @hwqid: belong to which HWQ |
| 20598 | * @expedite: 1 means this request is urgent. |
| 20599 | * |
| 20600 | * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1, |
| 20601 | * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes |
| 20602 | * a IO buffer from head of @hdwq io_buf_list and returns to caller. |
| 20603 | * |
| 20604 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20605 | * The caller should pass NULL for ndlp on NVME side. |
| 20606 | * |
| 20607 | * Return codes: |
| 20608 | * NULL - Error |
| 20609 | * Pointer to lpfc_io_buf - Success |
| 20610 | **/ |
| 20611 | struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba, |
| 20612 | struct lpfc_nodelist *ndlp, |
| 20613 | u32 hwqid, int expedite) |
| 20614 | { |
| 20615 | struct lpfc_sli4_hdw_queue *qp; |
| 20616 | unsigned long iflag; |
| 20617 | struct lpfc_io_buf *lpfc_cmd; |
| 20618 | |
| 20619 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20620 | lpfc_cmd = NULL; |
| 20621 | |
| 20622 | if (phba->cfg_xri_rebalancing) |
| 20623 | lpfc_cmd = lpfc_get_io_buf_from_multixri_pools( |
| 20624 | phba, ndlp, hwqid, expedite); |
| 20625 | else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20626 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag, |
| 20627 | qp, alloc_xri_get); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20628 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite) |
| 20629 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20630 | if (!lpfc_cmd) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20631 | lpfc_qp_spin_lock(&qp->io_buf_list_put_lock, |
| 20632 | qp, alloc_xri_put); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20633 | list_splice(&qp->lpfc_io_buf_list_put, |
| 20634 | &qp->lpfc_io_buf_list_get); |
| 20635 | qp->get_io_bufs += qp->put_io_bufs; |
| 20636 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 20637 | qp->put_io_bufs = 0; |
| 20638 | spin_unlock(&qp->io_buf_list_put_lock); |
| 20639 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || |
| 20640 | expedite) |
| 20641 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20642 | } |
| 20643 | spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag); |
| 20644 | } |
| 20645 | |
| 20646 | return lpfc_cmd; |
| 20647 | } |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20648 | |
| 20649 | /** |
| 20650 | * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool |
| 20651 | * @phba: The HBA for which this call is being executed. |
| 20652 | * @lpfc_buf: IO buf structure to append the SGL chunk |
| 20653 | * |
| 20654 | * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool, |
| 20655 | * and will allocate an SGL chunk if the pool is empty. |
| 20656 | * |
| 20657 | * Return codes: |
| 20658 | * NULL - Error |
| 20659 | * Pointer to sli4_hybrid_sgl - Success |
| 20660 | **/ |
| 20661 | struct sli4_hybrid_sgl * |
| 20662 | lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 20663 | { |
| 20664 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20665 | struct sli4_hybrid_sgl *tmp = NULL; |
| 20666 | struct sli4_hybrid_sgl *allocated_sgl = NULL; |
| 20667 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20668 | struct list_head *buf_list = &hdwq->sgl_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20669 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20670 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20671 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20672 | |
| 20673 | if (likely(!list_empty(buf_list))) { |
| 20674 | /* break off 1 chunk from the sgl_list */ |
| 20675 | list_for_each_entry_safe(list_entry, tmp, |
| 20676 | buf_list, list_node) { |
| 20677 | list_move_tail(&list_entry->list_node, |
| 20678 | &lpfc_buf->dma_sgl_xtra_list); |
| 20679 | break; |
| 20680 | } |
| 20681 | } else { |
| 20682 | /* allocate more */ |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20683 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20684 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
James Smart | 4583a4f | 2019-11-15 16:38:47 -0800 | [diff] [blame] | 20685 | cpu_to_node(hdwq->io_wq->chann)); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20686 | if (!tmp) { |
| 20687 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20688 | "8353 error kmalloc memory for HDWQ " |
| 20689 | "%d %s\n", |
| 20690 | lpfc_buf->hdwq_no, __func__); |
| 20691 | return NULL; |
| 20692 | } |
| 20693 | |
| 20694 | tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool, |
| 20695 | GFP_ATOMIC, &tmp->dma_phys_sgl); |
| 20696 | if (!tmp->dma_sgl) { |
| 20697 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20698 | "8354 error pool_alloc memory for HDWQ " |
| 20699 | "%d %s\n", |
| 20700 | lpfc_buf->hdwq_no, __func__); |
| 20701 | kfree(tmp); |
| 20702 | return NULL; |
| 20703 | } |
| 20704 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20705 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20706 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list); |
| 20707 | } |
| 20708 | |
| 20709 | allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list, |
| 20710 | struct sli4_hybrid_sgl, |
| 20711 | list_node); |
| 20712 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20713 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20714 | |
| 20715 | return allocated_sgl; |
| 20716 | } |
| 20717 | |
| 20718 | /** |
| 20719 | * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool |
| 20720 | * @phba: The HBA for which this call is being executed. |
| 20721 | * @lpfc_buf: IO buf structure with the SGL chunk |
| 20722 | * |
| 20723 | * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool. |
| 20724 | * |
| 20725 | * Return codes: |
| 20726 | * 0 - Success |
| 20727 | * -EINVAL - Error |
| 20728 | **/ |
| 20729 | int |
| 20730 | lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 20731 | { |
| 20732 | int rc = 0; |
| 20733 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20734 | struct sli4_hybrid_sgl *tmp = NULL; |
| 20735 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20736 | struct list_head *buf_list = &hdwq->sgl_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20737 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20738 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20739 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20740 | |
| 20741 | if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) { |
| 20742 | list_for_each_entry_safe(list_entry, tmp, |
| 20743 | &lpfc_buf->dma_sgl_xtra_list, |
| 20744 | list_node) { |
| 20745 | list_move_tail(&list_entry->list_node, |
| 20746 | buf_list); |
| 20747 | } |
| 20748 | } else { |
| 20749 | rc = -EINVAL; |
| 20750 | } |
| 20751 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20752 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20753 | return rc; |
| 20754 | } |
| 20755 | |
| 20756 | /** |
| 20757 | * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool |
| 20758 | * @phba: phba object |
| 20759 | * @hdwq: hdwq to cleanup sgl buff resources on |
| 20760 | * |
| 20761 | * This routine frees all SGL chunks of hdwq SGL chunk pool. |
| 20762 | * |
| 20763 | * Return codes: |
| 20764 | * None |
| 20765 | **/ |
| 20766 | void |
| 20767 | lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba, |
| 20768 | struct lpfc_sli4_hdw_queue *hdwq) |
| 20769 | { |
| 20770 | struct list_head *buf_list = &hdwq->sgl_list; |
| 20771 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20772 | struct sli4_hybrid_sgl *tmp = NULL; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20773 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20774 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20775 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20776 | |
| 20777 | /* Free sgl pool */ |
| 20778 | list_for_each_entry_safe(list_entry, tmp, |
| 20779 | buf_list, list_node) { |
| 20780 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 20781 | list_entry->dma_sgl, |
| 20782 | list_entry->dma_phys_sgl); |
| 20783 | list_del(&list_entry->list_node); |
| 20784 | kfree(list_entry); |
| 20785 | } |
| 20786 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20787 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20788 | } |
| 20789 | |
| 20790 | /** |
| 20791 | * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq |
| 20792 | * @phba: The HBA for which this call is being executed. |
| 20793 | * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer |
| 20794 | * |
| 20795 | * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool, |
| 20796 | * and will allocate an CMD/RSP buffer if the pool is empty. |
| 20797 | * |
| 20798 | * Return codes: |
| 20799 | * NULL - Error |
| 20800 | * Pointer to fcp_cmd_rsp_buf - Success |
| 20801 | **/ |
| 20802 | struct fcp_cmd_rsp_buf * |
| 20803 | lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 20804 | struct lpfc_io_buf *lpfc_buf) |
| 20805 | { |
| 20806 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 20807 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 20808 | struct fcp_cmd_rsp_buf *allocated_buf = NULL; |
| 20809 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20810 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20811 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20812 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20813 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20814 | |
| 20815 | if (likely(!list_empty(buf_list))) { |
| 20816 | /* break off 1 chunk from the list */ |
| 20817 | list_for_each_entry_safe(list_entry, tmp, |
| 20818 | buf_list, |
| 20819 | list_node) { |
| 20820 | list_move_tail(&list_entry->list_node, |
| 20821 | &lpfc_buf->dma_cmd_rsp_list); |
| 20822 | break; |
| 20823 | } |
| 20824 | } else { |
| 20825 | /* allocate more */ |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20826 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20827 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
James Smart | 4583a4f | 2019-11-15 16:38:47 -0800 | [diff] [blame] | 20828 | cpu_to_node(hdwq->io_wq->chann)); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20829 | if (!tmp) { |
| 20830 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20831 | "8355 error kmalloc memory for HDWQ " |
| 20832 | "%d %s\n", |
| 20833 | lpfc_buf->hdwq_no, __func__); |
| 20834 | return NULL; |
| 20835 | } |
| 20836 | |
| 20837 | tmp->fcp_cmnd = dma_pool_alloc(phba->lpfc_cmd_rsp_buf_pool, |
| 20838 | GFP_ATOMIC, |
| 20839 | &tmp->fcp_cmd_rsp_dma_handle); |
| 20840 | |
| 20841 | if (!tmp->fcp_cmnd) { |
| 20842 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20843 | "8356 error pool_alloc memory for HDWQ " |
| 20844 | "%d %s\n", |
| 20845 | lpfc_buf->hdwq_no, __func__); |
| 20846 | kfree(tmp); |
| 20847 | return NULL; |
| 20848 | } |
| 20849 | |
| 20850 | tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd + |
| 20851 | sizeof(struct fcp_cmnd)); |
| 20852 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20853 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20854 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list); |
| 20855 | } |
| 20856 | |
| 20857 | allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list, |
| 20858 | struct fcp_cmd_rsp_buf, |
| 20859 | list_node); |
| 20860 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20861 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20862 | |
| 20863 | return allocated_buf; |
| 20864 | } |
| 20865 | |
| 20866 | /** |
| 20867 | * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool |
| 20868 | * @phba: The HBA for which this call is being executed. |
| 20869 | * @lpfc_buf: IO buf structure with the CMD/RSP buf |
| 20870 | * |
| 20871 | * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool. |
| 20872 | * |
| 20873 | * Return codes: |
| 20874 | * 0 - Success |
| 20875 | * -EINVAL - Error |
| 20876 | **/ |
| 20877 | int |
| 20878 | lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 20879 | struct lpfc_io_buf *lpfc_buf) |
| 20880 | { |
| 20881 | int rc = 0; |
| 20882 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 20883 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 20884 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20885 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20886 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20887 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20888 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20889 | |
| 20890 | if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) { |
| 20891 | list_for_each_entry_safe(list_entry, tmp, |
| 20892 | &lpfc_buf->dma_cmd_rsp_list, |
| 20893 | list_node) { |
| 20894 | list_move_tail(&list_entry->list_node, |
| 20895 | buf_list); |
| 20896 | } |
| 20897 | } else { |
| 20898 | rc = -EINVAL; |
| 20899 | } |
| 20900 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20901 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20902 | return rc; |
| 20903 | } |
| 20904 | |
| 20905 | /** |
| 20906 | * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool |
| 20907 | * @phba: phba object |
| 20908 | * @hdwq: hdwq to cleanup cmd rsp buff resources on |
| 20909 | * |
| 20910 | * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool. |
| 20911 | * |
| 20912 | * Return codes: |
| 20913 | * None |
| 20914 | **/ |
| 20915 | void |
| 20916 | lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 20917 | struct lpfc_sli4_hdw_queue *hdwq) |
| 20918 | { |
| 20919 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
| 20920 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 20921 | struct fcp_cmd_rsp_buf *tmp = NULL; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20922 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20923 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20924 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20925 | |
| 20926 | /* Free cmd_rsp buf pool */ |
| 20927 | list_for_each_entry_safe(list_entry, tmp, |
| 20928 | buf_list, |
| 20929 | list_node) { |
| 20930 | dma_pool_free(phba->lpfc_cmd_rsp_buf_pool, |
| 20931 | list_entry->fcp_cmnd, |
| 20932 | list_entry->fcp_cmd_rsp_dma_handle); |
| 20933 | list_del(&list_entry->list_node); |
| 20934 | kfree(list_entry); |
| 20935 | } |
| 20936 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20937 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20938 | } |