| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 0d04121 | 2019-01-28 11:14:41 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term * |
James Smart | 3e21d1c | 2018-05-04 20:37:59 -0700 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 12 | * modify it under the terms of version 2 of the GNU General * |
| 13 | * Public License as published by the Free Software Foundation. * |
| 14 | * This program is distributed in the hope that it will be useful. * |
| 15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 20 | * more details, a copy of which can be found in the file COPYING * |
| 21 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
| 23 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/blkdev.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 29 | #include <linux/lockdep.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 30 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 31 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | #include <scsi/scsi_cmnd.h> |
| 33 | #include <scsi/scsi_device.h> |
| 34 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 35 | #include <scsi/scsi_transport_fc.h> |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 36 | #include <scsi/fc/fc_fs.h> |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 37 | #include <linux/aer.h> |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 38 | #ifdef CONFIG_X86 |
| 39 | #include <asm/set_memory.h> |
| 40 | #endif |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 42 | #include <linux/nvme-fc-driver.h> |
| 43 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 44 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | #include "lpfc_hw.h" |
| 46 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 47 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 48 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 50 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 51 | #include "lpfc_scsi.h" |
| 52 | #include "lpfc_nvme.h" |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 53 | #include "lpfc_nvmet.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | #include "lpfc_crtn.h" |
| 55 | #include "lpfc_logmsg.h" |
| 56 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 57 | #include "lpfc_debugfs.h" |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 58 | #include "lpfc_vport.h" |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 59 | #include "lpfc_version.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 60 | |
| 61 | /* There are only four IOCB completion types. */ |
| 62 | typedef enum _lpfc_iocb_type { |
| 63 | LPFC_UNKNOWN_IOCB, |
| 64 | LPFC_UNSOL_IOCB, |
| 65 | LPFC_SOL_IOCB, |
| 66 | LPFC_ABORT_IOCB |
| 67 | } lpfc_iocb_type; |
| 68 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 69 | |
| 70 | /* Provide function prototypes local to this module. */ |
| 71 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, |
| 72 | uint32_t); |
| 73 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 74 | uint8_t *, uint32_t *); |
| 75 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, |
| 76 | struct lpfc_iocbq *); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 77 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
| 78 | struct hbq_dmabuf *); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 79 | static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 80 | struct hbq_dmabuf *dmabuf); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 81 | static bool lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, |
| 82 | struct lpfc_queue *cq, struct lpfc_cqe *cqe); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 83 | static int lpfc_sli4_post_sgl_list(struct lpfc_hba *, struct list_head *, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 84 | int); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 85 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 86 | struct lpfc_queue *eq, |
| 87 | struct lpfc_eqe *eqe); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 88 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
| 89 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); |
James Smart | 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 |
| 518 | lpfc_sli4_process_eq(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 519 | { |
| 520 | struct lpfc_eqe *eqe; |
| 521 | int count = 0, consumed = 0; |
| 522 | |
| 523 | if (cmpxchg(&eq->queue_claimed, 0, 1) != 0) |
| 524 | goto rearm_and_exit; |
| 525 | |
| 526 | eqe = lpfc_sli4_eq_get(eq); |
| 527 | while (eqe) { |
| 528 | lpfc_sli4_hba_handle_eqe(phba, eq, eqe); |
| 529 | __lpfc_sli4_consume_eqe(phba, eq, eqe); |
| 530 | |
| 531 | consumed++; |
| 532 | if (!(++count % eq->max_proc_limit)) |
| 533 | break; |
| 534 | |
| 535 | if (!(count % eq->notify_interval)) { |
| 536 | phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, |
| 537 | LPFC_QUEUE_NOARM); |
| 538 | consumed = 0; |
| 539 | } |
| 540 | |
| 541 | eqe = lpfc_sli4_eq_get(eq); |
| 542 | } |
| 543 | eq->EQ_processed += count; |
| 544 | |
| 545 | /* Track the max number of EQEs processed in 1 intr */ |
| 546 | if (count > eq->EQ_max_eqe) |
| 547 | eq->EQ_max_eqe = count; |
| 548 | |
| 549 | eq->queue_claimed = 0; |
| 550 | |
| 551 | rearm_and_exit: |
| 552 | /* Always clear and re-arm the EQ */ |
| 553 | phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, LPFC_QUEUE_REARM); |
| 554 | |
| 555 | return count; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 559 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 560 | * @q: The Completion Queue to get the first valid CQE from |
| 561 | * |
| 562 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 563 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 564 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 565 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 566 | **/ |
| 567 | static struct lpfc_cqe * |
| 568 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 569 | { |
| 570 | struct lpfc_cqe *cqe; |
| 571 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 572 | /* sanity check on queue memory */ |
| 573 | if (unlikely(!q)) |
| 574 | return NULL; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 575 | cqe = lpfc_sli4_qe(q, q->host_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 576 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 577 | /* If the next CQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 578 | if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 579 | return NULL; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 580 | |
| 581 | /* |
| 582 | * insert barrier for instruction interlock : data from the hardware |
| 583 | * 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] | 584 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 585 | * instructions allowing action on content before valid bit checked, |
| 586 | * add barrier here as well. May not be needed as "content" is a |
| 587 | * single 32-bit entity here (vs multi word structure for cq's). |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 588 | */ |
| 589 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 590 | return cqe; |
| 591 | } |
| 592 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 593 | static void |
| 594 | __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 595 | struct lpfc_cqe *cqe) |
| 596 | { |
| 597 | if (!phba->sli4_hba.pc_sli4_params.cqav) |
| 598 | bf_set_le32(lpfc_cqe_valid, cqe, 0); |
| 599 | |
| 600 | cq->host_index = ((cq->host_index + 1) % cq->entry_count); |
| 601 | |
| 602 | /* if the index wrapped around, toggle the valid bit */ |
| 603 | if (phba->sli4_hba.pc_sli4_params.cqav && !cq->host_index) |
| 604 | cq->qe_valid = (cq->qe_valid) ? 0 : 1; |
| 605 | } |
| 606 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 607 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 608 | * lpfc_sli4_write_cq_db - write cq DB for entries consumed or arm state. |
| 609 | * @phba: the adapter with the CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 610 | * @q: The Completion Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 611 | * @count: the number of elements that were consumed |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 612 | * @arm: Indicates whether the host wants to arms this CQ. |
| 613 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 614 | * This routine will notify the HBA, by ringing the doorbell, that the |
| 615 | * CQEs have been processed. The @arm parameter specifies whether the |
| 616 | * queue should be rearmed when ringing the doorbell. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 617 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 618 | void |
| 619 | lpfc_sli4_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 620 | uint32_t count, bool arm) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 621 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 622 | struct lpfc_register doorbell; |
| 623 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 624 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 625 | if (unlikely(!q || (count == 0 && !arm))) |
| 626 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 627 | |
| 628 | /* ring doorbell for number popped */ |
| 629 | doorbell.word0 = 0; |
| 630 | if (arm) |
| 631 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 632 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 633 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 634 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 635 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 636 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 637 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 641 | * lpfc_sli4_if6_write_cq_db - write cq DB for entries consumed or arm state. |
| 642 | * @phba: the adapter with the CQ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 643 | * @q: The Completion Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 644 | * @count: the number of elements that were consumed |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 645 | * @arm: Indicates whether the host wants to arms this CQ. |
| 646 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 647 | * This routine will notify the HBA, by ringing the doorbell, that the |
| 648 | * CQEs have been processed. The @arm parameter specifies whether the |
| 649 | * queue should be rearmed when ringing the doorbell. |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 650 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 651 | void |
| 652 | lpfc_sli4_if6_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 653 | uint32_t count, bool arm) |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 654 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 655 | struct lpfc_register doorbell; |
| 656 | |
| 657 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 658 | if (unlikely(!q || (count == 0 && !arm))) |
| 659 | return; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 660 | |
| 661 | /* ring doorbell for number popped */ |
| 662 | doorbell.word0 = 0; |
| 663 | if (arm) |
| 664 | bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 665 | bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, count); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 666 | bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id); |
| 667 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 671 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 672 | * @q: The Header Receive Queue to operate on. |
| 673 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 674 | * |
| 675 | * This routine will copy the contents of @wqe to the next available entry on |
| 676 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 677 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 678 | * index that the rqe was copied to if successful. If no entries are available |
| 679 | * on @q then this function will return -ENOMEM. |
| 680 | * The caller is expected to hold the hbalock when calling this routine. |
| 681 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 682 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 683 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 684 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 685 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 686 | struct lpfc_rqe *temp_hrqe; |
| 687 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 688 | struct lpfc_register doorbell; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 689 | int hq_put_index; |
| 690 | int dq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 691 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 692 | /* sanity check on queue memory */ |
| 693 | if (unlikely(!hq) || unlikely(!dq)) |
| 694 | return -ENOMEM; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 695 | hq_put_index = hq->host_index; |
| 696 | dq_put_index = dq->host_index; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 697 | temp_hrqe = lpfc_sli4_qe(hq, hq_put_index); |
| 698 | temp_drqe = lpfc_sli4_qe(dq, dq_put_index); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 699 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 700 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 701 | return -EINVAL; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 702 | if (hq_put_index != dq_put_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 703 | return -EINVAL; |
| 704 | /* 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] | 705 | if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 706 | return -EBUSY; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 707 | lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 708 | lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 709 | |
| 710 | /* Update the host index to point to the next slot */ |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 711 | hq->host_index = ((hq_put_index + 1) % hq->entry_count); |
| 712 | dq->host_index = ((dq_put_index + 1) % dq->entry_count); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 713 | hq->RQ_buf_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 714 | |
| 715 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 716 | if (!(hq->host_index % hq->notify_interval)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 717 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 718 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 719 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 720 | hq->notify_interval); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 721 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 722 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 723 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 724 | hq->notify_interval); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 725 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 726 | hq->host_index); |
| 727 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 728 | } else { |
| 729 | return -EINVAL; |
| 730 | } |
| 731 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 732 | } |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 733 | return hq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | /** |
| 737 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 738 | * @q: The Header Receive Queue to operate on. |
| 739 | * |
| 740 | * This routine will update the HBA index of a queue to reflect consumption of |
| 741 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 742 | * consumed an entry the host calls this function to update the queue's |
| 743 | * internal pointers. This routine returns the number of entries that were |
| 744 | * consumed by the HBA. |
| 745 | **/ |
| 746 | static uint32_t |
| 747 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 748 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 749 | /* sanity check on queue memory */ |
| 750 | if (unlikely(!hq) || unlikely(!dq)) |
| 751 | return 0; |
| 752 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 753 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 754 | return 0; |
| 755 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 756 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 757 | return 1; |
| 758 | } |
| 759 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 760 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 761 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 762 | * @phba: Pointer to HBA context object. |
| 763 | * @pring: Pointer to driver SLI ring object. |
| 764 | * |
| 765 | * This function returns pointer to next command iocb entry |
| 766 | * in the command ring. The caller must hold hbalock to prevent |
| 767 | * other threads consume the next command iocb. |
| 768 | * SLI-2/SLI-3 provide different sized iocbs. |
| 769 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 770 | static inline IOCB_t * |
| 771 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 772 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 773 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 774 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 775 | } |
| 776 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 777 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 778 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 779 | * @phba: Pointer to HBA context object. |
| 780 | * @pring: Pointer to driver SLI ring object. |
| 781 | * |
| 782 | * This function returns pointer to next response iocb entry |
| 783 | * in the response ring. The caller must hold hbalock to make sure |
| 784 | * that no other thread consume the next response iocb. |
| 785 | * SLI-2/SLI-3 provide different sized iocbs. |
| 786 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 787 | static inline IOCB_t * |
| 788 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 789 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 790 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 791 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 792 | } |
| 793 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 794 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 795 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 796 | * @phba: Pointer to HBA context object. |
| 797 | * |
| 798 | * This function is called with hbalock held. This function |
| 799 | * allocates a new driver iocb object from the iocb pool. If the |
| 800 | * allocation is successful, it returns pointer to the newly |
| 801 | * allocated iocb object else it returns NULL. |
| 802 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 803 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 804 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 805 | { |
| 806 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 807 | struct lpfc_iocbq * iocbq = NULL; |
| 808 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 809 | lockdep_assert_held(&phba->hbalock); |
| 810 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 811 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 812 | if (iocbq) |
| 813 | phba->iocb_cnt++; |
| 814 | if (phba->iocb_cnt > phba->iocb_max) |
| 815 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 816 | return iocbq; |
| 817 | } |
| 818 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 819 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 820 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 821 | * @phba: Pointer to HBA context object. |
| 822 | * @xritag: XRI value. |
| 823 | * |
| 824 | * This function clears the sglq pointer from the array of acive |
| 825 | * sglq's. The xritag that is passed in is used to index into the |
| 826 | * array. Before the xritag can be used it needs to be adjusted |
| 827 | * by subtracting the xribase. |
| 828 | * |
| 829 | * Returns sglq ponter = success, NULL = Failure. |
| 830 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 831 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 832 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 833 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 834 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 835 | |
| 836 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 837 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 838 | return sglq; |
| 839 | } |
| 840 | |
| 841 | /** |
| 842 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 843 | * @phba: Pointer to HBA context object. |
| 844 | * @xritag: XRI value. |
| 845 | * |
| 846 | * This function returns the sglq pointer from the array of acive |
| 847 | * sglq's. The xritag that is passed in is used to index into the |
| 848 | * array. Before the xritag can be used it needs to be adjusted |
| 849 | * by subtracting the xribase. |
| 850 | * |
| 851 | * Returns sglq ponter = success, NULL = Failure. |
| 852 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 853 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 854 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 855 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 856 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 857 | |
| 858 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 859 | return sglq; |
| 860 | } |
| 861 | |
| 862 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 863 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 864 | * @phba: Pointer to HBA context object. |
| 865 | * @xritag: xri used in this exchange. |
| 866 | * @rrq: The RRQ to be cleared. |
| 867 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 868 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 869 | void |
| 870 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 871 | uint16_t xritag, |
| 872 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 873 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 874 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 875 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 876 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 877 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 878 | |
| 879 | /* The target DID could have been swapped (cable swap) |
| 880 | * we should use the ndlp from the findnode if it is |
| 881 | * available. |
| 882 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 883 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 884 | ndlp = rrq->ndlp; |
| 885 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 886 | if (!ndlp) |
| 887 | goto out; |
| 888 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 889 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 890 | rrq->send_rrq = 0; |
| 891 | rrq->xritag = 0; |
| 892 | rrq->rrq_stop_time = 0; |
| 893 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 894 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 895 | mempool_free(rrq, phba->rrq_pool); |
| 896 | } |
| 897 | |
| 898 | /** |
| 899 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 900 | * @phba: Pointer to HBA context object. |
| 901 | * |
| 902 | * This function is called with hbalock held. This function |
| 903 | * Checks if stop_time (ratov from setting rrq active) has |
| 904 | * been reached, if it has and the send_rrq flag is set then |
| 905 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 906 | * then it will just call the routine to clear the rrq and |
| 907 | * free the rrq resource. |
| 908 | * The timer is set to the next rrq that is going to expire before |
| 909 | * leaving the routine. |
| 910 | * |
| 911 | **/ |
| 912 | void |
| 913 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 914 | { |
| 915 | struct lpfc_node_rrq *rrq; |
| 916 | struct lpfc_node_rrq *nextrrq; |
| 917 | unsigned long next_time; |
| 918 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 919 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 920 | |
| 921 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 922 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 923 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 924 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 925 | &phba->active_rrq_list, list) { |
| 926 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 927 | list_move(&rrq->list, &send_rrq); |
| 928 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 929 | next_time = rrq->rrq_stop_time; |
| 930 | } |
| 931 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 932 | if ((!list_empty(&phba->active_rrq_list)) && |
| 933 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 934 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 935 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 936 | list_del(&rrq->list); |
Bart Van Assche | ffd4381 | 2019-03-28 11:06:17 -0700 | [diff] [blame] | 937 | if (!rrq->send_rrq) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 938 | /* this call will free the rrq */ |
Bart Van Assche | ffd4381 | 2019-03-28 11:06:17 -0700 | [diff] [blame] | 939 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 940 | } else if (lpfc_send_rrq(phba, rrq)) { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 941 | /* if we send the rrq then the completion handler |
| 942 | * will clear the bit in the xribitmap. |
| 943 | */ |
| 944 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 945 | rrq); |
| 946 | } |
| 947 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | /** |
| 951 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 952 | * @vport: Pointer to vport context object. |
| 953 | * @xri: The xri used in the exchange. |
| 954 | * @did: The targets DID for this exchange. |
| 955 | * |
| 956 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 957 | * rrq = rrq for this xri and target. |
| 958 | **/ |
| 959 | struct lpfc_node_rrq * |
| 960 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 961 | { |
| 962 | struct lpfc_hba *phba = vport->phba; |
| 963 | struct lpfc_node_rrq *rrq; |
| 964 | struct lpfc_node_rrq *nextrrq; |
| 965 | unsigned long iflags; |
| 966 | |
| 967 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 968 | return NULL; |
| 969 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 970 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 971 | if (rrq->vport == vport && rrq->xritag == xri && |
| 972 | rrq->nlp_DID == did){ |
| 973 | list_del(&rrq->list); |
| 974 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 975 | return rrq; |
| 976 | } |
| 977 | } |
| 978 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 979 | return NULL; |
| 980 | } |
| 981 | |
| 982 | /** |
| 983 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 984 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 985 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 986 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 987 | * phba->active_rrq_list and clear the rrq. |
| 988 | * 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] | 989 | **/ |
| 990 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 991 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 992 | |
| 993 | { |
| 994 | struct lpfc_hba *phba = vport->phba; |
| 995 | struct lpfc_node_rrq *rrq; |
| 996 | struct lpfc_node_rrq *nextrrq; |
| 997 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 998 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 999 | |
| 1000 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 1001 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1002 | if (!ndlp) { |
| 1003 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 1004 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1005 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1006 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1007 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 1008 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 1009 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1010 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1011 | |
| 1012 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 1013 | list_del(&rrq->list); |
| 1014 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1015 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1019 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1020 | * @phba: Pointer to HBA context object. |
| 1021 | * @ndlp: Targets nodelist pointer for this exchange. |
| 1022 | * @xritag the xri in the bitmap to test. |
| 1023 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1024 | * This function returns: |
| 1025 | * 0 = rrq not active for this xri |
| 1026 | * 1 = rrq is valid for this xri. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1027 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1028 | int |
| 1029 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1030 | uint16_t xritag) |
| 1031 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1032 | if (!ndlp) |
| 1033 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1034 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1035 | return 0; |
| 1036 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
Colin Ian King | 258f84f | 2019-02-12 15:29:45 +0000 | [diff] [blame] | 1037 | return 1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1038 | else |
| 1039 | return 0; |
| 1040 | } |
| 1041 | |
| 1042 | /** |
| 1043 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 1044 | * @phba: Pointer to HBA context object. |
| 1045 | * @ndlp: nodelist pointer for this target. |
| 1046 | * @xritag: xri used in this exchange. |
| 1047 | * @rxid: Remote Exchange ID. |
| 1048 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 1049 | * |
| 1050 | * This function takes the hbalock. |
| 1051 | * The active bit is always set in the active rrq xri_bitmap even |
| 1052 | * if there is no slot avaiable for the other rrq information. |
| 1053 | * |
| 1054 | * returns 0 rrq actived for this xri |
| 1055 | * < 0 No memory or invalid ndlp. |
| 1056 | **/ |
| 1057 | int |
| 1058 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1059 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1060 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1061 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1062 | struct lpfc_node_rrq *rrq; |
| 1063 | int empty; |
| 1064 | |
| 1065 | if (!ndlp) |
| 1066 | return -EINVAL; |
| 1067 | |
| 1068 | if (!phba->cfg_enable_rrq) |
| 1069 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1070 | |
| 1071 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1072 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1073 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 1074 | goto out; |
| 1075 | } |
| 1076 | |
| 1077 | /* |
| 1078 | * set the active bit even if there is no mem available. |
| 1079 | */ |
| 1080 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 1081 | goto out; |
| 1082 | |
| 1083 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 1084 | goto out; |
| 1085 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1086 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1087 | goto out; |
| 1088 | |
| 1089 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1090 | goto out; |
| 1091 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1092 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1093 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 1094 | if (!rrq) { |
| 1095 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1096 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 1097 | " DID:0x%x Send:%d\n", |
| 1098 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1099 | return -EINVAL; |
| 1100 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 1101 | if (phba->cfg_enable_rrq == 1) |
| 1102 | rrq->send_rrq = send_rrq; |
| 1103 | else |
| 1104 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1105 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1106 | rrq->rrq_stop_time = jiffies + |
| 1107 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1108 | rrq->ndlp = ndlp; |
| 1109 | rrq->nlp_DID = ndlp->nlp_DID; |
| 1110 | rrq->vport = ndlp->vport; |
| 1111 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1112 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1113 | empty = list_empty(&phba->active_rrq_list); |
| 1114 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 1115 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1116 | if (empty) |
| 1117 | lpfc_worker_wake_up(phba); |
| 1118 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1119 | return 0; |
| 1120 | out: |
| 1121 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1122 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1123 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 1124 | " DID:0x%x Send:%d\n", |
| 1125 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1126 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1130 | * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1131 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1132 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1133 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1134 | * The driver calls this function with either the nvme ls ring lock |
| 1135 | * or the fc els ring lock held depending on the iocb usage. This function |
| 1136 | * gets a new driver sglq object from the sglq list. If the list is not empty |
| 1137 | * then it is successful, it returns pointer to the newly allocated sglq |
| 1138 | * object else it returns NULL. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1139 | **/ |
| 1140 | static struct lpfc_sglq * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1141 | __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] | 1142 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1143 | 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] | 1144 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1145 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1146 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1147 | struct lpfc_nodelist *ndlp; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1148 | struct lpfc_sli_ring *pring = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1149 | int found = 0; |
| 1150 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1151 | if (piocbq->iocb_flag & LPFC_IO_NVME_LS) |
| 1152 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 1153 | else |
| 1154 | pring = lpfc_phba_elsring(phba); |
| 1155 | |
| 1156 | lockdep_assert_held(&pring->ring_lock); |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1157 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1158 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1159 | lpfc_cmd = (struct lpfc_io_buf *) piocbq->context1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1160 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 1161 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1162 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1163 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1164 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 1165 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 1166 | ndlp = NULL; |
| 1167 | else |
| 1168 | ndlp = piocbq->context_un.ndlp; |
| 1169 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1170 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1171 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1172 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1173 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 1174 | list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1175 | start_sglq = sglq; |
| 1176 | while (!found) { |
| 1177 | if (!sglq) |
James Smart | d11f54b | 2017-03-04 09:30:24 -0800 | [diff] [blame] | 1178 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1179 | if (ndlp && ndlp->active_rrqs_xri_bitmap && |
| 1180 | test_bit(sglq->sli4_lxritag, |
| 1181 | ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1182 | /* This xri has an rrq outstanding for this DID. |
| 1183 | * put it back in the list and get another xri. |
| 1184 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1185 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1186 | sglq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1187 | list_remove_head(lpfc_els_sgl_list, sglq, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1188 | struct lpfc_sglq, list); |
| 1189 | if (sglq == start_sglq) { |
James Smart | 14041bd | 2017-06-01 21:07:01 -0700 | [diff] [blame] | 1190 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1191 | sglq = NULL; |
| 1192 | break; |
| 1193 | } else |
| 1194 | continue; |
| 1195 | } |
| 1196 | sglq->ndlp = ndlp; |
| 1197 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1198 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1199 | sglq->state = SGL_ALLOCATED; |
| 1200 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1201 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1202 | return sglq; |
| 1203 | } |
| 1204 | |
| 1205 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1206 | * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool |
| 1207 | * @phba: Pointer to HBA context object. |
| 1208 | * @piocb: Pointer to the iocbq. |
| 1209 | * |
| 1210 | * This function is called with the sgl_list lock held. This function |
| 1211 | * gets a new driver sglq object from the sglq list. If the |
| 1212 | * list is not empty then it is successful, it returns pointer to the newly |
| 1213 | * allocated sglq object else it returns NULL. |
| 1214 | **/ |
| 1215 | struct lpfc_sglq * |
| 1216 | __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
| 1217 | { |
| 1218 | struct list_head *lpfc_nvmet_sgl_list; |
| 1219 | struct lpfc_sglq *sglq = NULL; |
| 1220 | |
| 1221 | lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list; |
| 1222 | |
| 1223 | lockdep_assert_held(&phba->sli4_hba.sgl_list_lock); |
| 1224 | |
| 1225 | list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list); |
| 1226 | if (!sglq) |
| 1227 | return NULL; |
| 1228 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
| 1229 | sglq->state = SGL_ALLOCATED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1230 | return sglq; |
| 1231 | } |
| 1232 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1233 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1234 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1235 | * @phba: Pointer to HBA context object. |
| 1236 | * |
| 1237 | * This function is called with no lock held. This function |
| 1238 | * allocates a new driver iocb object from the iocb pool. If the |
| 1239 | * allocation is successful, it returns pointer to the newly |
| 1240 | * allocated iocb object else it returns NULL. |
| 1241 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1242 | struct lpfc_iocbq * |
| 1243 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1244 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1245 | struct lpfc_iocbq * iocbq = NULL; |
| 1246 | unsigned long iflags; |
| 1247 | |
| 1248 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1249 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 1250 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1251 | return iocbq; |
| 1252 | } |
| 1253 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1254 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1255 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 1256 | * @phba: Pointer to HBA context object. |
| 1257 | * @iocbq: Pointer to driver iocb object. |
| 1258 | * |
| 1259 | * This function is called with hbalock held to release driver |
| 1260 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1261 | * does not change for each use of the iocb object. This function |
| 1262 | * clears all other fields of the iocb object when it is freed. |
| 1263 | * The sqlq structure that holds the xritag and phys and virtual |
| 1264 | * mappings for the scatter gather list is retrieved from the |
| 1265 | * active array of sglq. The get of the sglq pointer also clears |
| 1266 | * the entry in the array. If the status of the IO indiactes that |
| 1267 | * this IO was aborted then the sglq entry it put on the |
| 1268 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1269 | * 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] | 1270 | * entry is added to the free list (lpfc_els_sgl_list). |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1271 | **/ |
| 1272 | static void |
| 1273 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1274 | { |
| 1275 | struct lpfc_sglq *sglq; |
| 1276 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1277 | unsigned long iflag = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1278 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1279 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1280 | lockdep_assert_held(&phba->hbalock); |
| 1281 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1282 | if (iocbq->sli4_xritag == NO_XRI) |
| 1283 | sglq = NULL; |
| 1284 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1285 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1286 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1287 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1288 | if (sglq) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1289 | if (iocbq->iocb_flag & LPFC_IO_NVMET) { |
| 1290 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1291 | iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1292 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1293 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1294 | list_add_tail(&sglq->list, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1295 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 1296 | spin_unlock_irqrestore( |
| 1297 | &phba->sli4_hba.sgl_list_lock, iflag); |
| 1298 | goto out; |
| 1299 | } |
| 1300 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1301 | pring = phba->sli4_hba.els_wq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1302 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1303 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1304 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1305 | iflag); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1306 | list_add(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1307 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1308 | spin_unlock_irqrestore( |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1309 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1310 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1311 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1312 | iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1313 | sglq->state = SGL_FREED; |
| 1314 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1315 | list_add_tail(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1316 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1317 | spin_unlock_irqrestore( |
| 1318 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1319 | |
| 1320 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1321 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1322 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1323 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1324 | } |
| 1325 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1326 | out: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1327 | /* |
| 1328 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1329 | */ |
| 1330 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1331 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1332 | iocbq->sli4_xritag = NO_XRI; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1333 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | |
| 1334 | LPFC_IO_NVME_LS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1335 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1336 | } |
| 1337 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1338 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1339 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1340 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1341 | * @phba: Pointer to HBA context object. |
| 1342 | * @iocbq: Pointer to driver iocb object. |
| 1343 | * |
| 1344 | * This function is called with hbalock held to release driver |
| 1345 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1346 | * does not change for each use of the iocb object. This function |
| 1347 | * clears all other fields of the iocb object when it is freed. |
| 1348 | **/ |
| 1349 | static void |
| 1350 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1351 | { |
| 1352 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1353 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1354 | lockdep_assert_held(&phba->hbalock); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1355 | |
| 1356 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1357 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1358 | */ |
| 1359 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1360 | iocbq->sli4_xritag = NO_XRI; |
| 1361 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1362 | } |
| 1363 | |
| 1364 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1365 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1366 | * @phba: Pointer to HBA context object. |
| 1367 | * @iocbq: Pointer to driver iocb object. |
| 1368 | * |
| 1369 | * This function is called with hbalock held to release driver |
| 1370 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1371 | * does not change for each use of the iocb object. This function |
| 1372 | * clears all other fields of the iocb object when it is freed. |
| 1373 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1374 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1375 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1376 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1377 | lockdep_assert_held(&phba->hbalock); |
| 1378 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1379 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1380 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1381 | } |
| 1382 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1383 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1384 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1385 | * @phba: Pointer to HBA context object. |
| 1386 | * @iocbq: Pointer to driver iocb object. |
| 1387 | * |
| 1388 | * This function is called with no lock held to release the iocb to |
| 1389 | * iocb pool. |
| 1390 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1391 | void |
| 1392 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1393 | { |
| 1394 | unsigned long iflags; |
| 1395 | |
| 1396 | /* |
| 1397 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1398 | */ |
| 1399 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1400 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1401 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1402 | } |
| 1403 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1404 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1405 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1406 | * @phba: Pointer to HBA context object. |
| 1407 | * @iocblist: List of IOCBs. |
| 1408 | * @ulpstatus: ULP status in IOCB command field. |
| 1409 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1410 | * |
| 1411 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1412 | * on the list by invoking the complete callback function associated with the |
| 1413 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1414 | * fields. |
| 1415 | **/ |
| 1416 | void |
| 1417 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1418 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1419 | { |
| 1420 | struct lpfc_iocbq *piocb; |
| 1421 | |
| 1422 | while (!list_empty(iocblist)) { |
| 1423 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | 84f2ddf | 2019-08-14 16:56:55 -0700 | [diff] [blame] | 1424 | if (!piocb->iocb_cmpl) { |
| 1425 | if (piocb->iocb_flag & LPFC_IO_NVME) |
| 1426 | lpfc_nvme_cancel_iocb(phba, piocb); |
| 1427 | else |
| 1428 | lpfc_sli_release_iocbq(phba, piocb); |
| 1429 | } else { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1430 | piocb->iocb.ulpStatus = ulpstatus; |
| 1431 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1432 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1433 | } |
| 1434 | } |
| 1435 | return; |
| 1436 | } |
| 1437 | |
| 1438 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1439 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1440 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1441 | * |
| 1442 | * This function is called by ring event handler function to get the iocb type. |
| 1443 | * This function translates the iocb command to an iocb command type used to |
| 1444 | * decide the final disposition of each completed IOCB. |
| 1445 | * The function returns |
| 1446 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1447 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1448 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1449 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1450 | * |
| 1451 | * The caller is not required to hold any lock. |
| 1452 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1453 | static lpfc_iocb_type |
| 1454 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1455 | { |
| 1456 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1457 | |
| 1458 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1459 | return 0; |
| 1460 | |
| 1461 | switch (iocb_cmnd) { |
| 1462 | case CMD_XMIT_SEQUENCE_CR: |
| 1463 | case CMD_XMIT_SEQUENCE_CX: |
| 1464 | case CMD_XMIT_BCAST_CN: |
| 1465 | case CMD_XMIT_BCAST_CX: |
| 1466 | case CMD_ELS_REQUEST_CR: |
| 1467 | case CMD_ELS_REQUEST_CX: |
| 1468 | case CMD_CREATE_XRI_CR: |
| 1469 | case CMD_CREATE_XRI_CX: |
| 1470 | case CMD_GET_RPI_CN: |
| 1471 | case CMD_XMIT_ELS_RSP_CX: |
| 1472 | case CMD_GET_RPI_CR: |
| 1473 | case CMD_FCP_IWRITE_CR: |
| 1474 | case CMD_FCP_IWRITE_CX: |
| 1475 | case CMD_FCP_IREAD_CR: |
| 1476 | case CMD_FCP_IREAD_CX: |
| 1477 | case CMD_FCP_ICMND_CR: |
| 1478 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1479 | case CMD_FCP_TSEND_CX: |
| 1480 | case CMD_FCP_TRSP_CX: |
| 1481 | case CMD_FCP_TRECEIVE_CX: |
| 1482 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1483 | case CMD_ADAPTER_MSG: |
| 1484 | case CMD_ADAPTER_DUMP: |
| 1485 | case CMD_XMIT_SEQUENCE64_CR: |
| 1486 | case CMD_XMIT_SEQUENCE64_CX: |
| 1487 | case CMD_XMIT_BCAST64_CN: |
| 1488 | case CMD_XMIT_BCAST64_CX: |
| 1489 | case CMD_ELS_REQUEST64_CR: |
| 1490 | case CMD_ELS_REQUEST64_CX: |
| 1491 | case CMD_FCP_IWRITE64_CR: |
| 1492 | case CMD_FCP_IWRITE64_CX: |
| 1493 | case CMD_FCP_IREAD64_CR: |
| 1494 | case CMD_FCP_IREAD64_CX: |
| 1495 | case CMD_FCP_ICMND64_CR: |
| 1496 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1497 | case CMD_FCP_TSEND64_CX: |
| 1498 | case CMD_FCP_TRSP64_CX: |
| 1499 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1500 | case CMD_GEN_REQUEST64_CR: |
| 1501 | case CMD_GEN_REQUEST64_CX: |
| 1502 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1503 | case DSSCMD_IWRITE64_CR: |
| 1504 | case DSSCMD_IWRITE64_CX: |
| 1505 | case DSSCMD_IREAD64_CR: |
| 1506 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1507 | type = LPFC_SOL_IOCB; |
| 1508 | break; |
| 1509 | case CMD_ABORT_XRI_CN: |
| 1510 | case CMD_ABORT_XRI_CX: |
| 1511 | case CMD_CLOSE_XRI_CN: |
| 1512 | case CMD_CLOSE_XRI_CX: |
| 1513 | case CMD_XRI_ABORTED_CX: |
| 1514 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1515 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1516 | type = LPFC_ABORT_IOCB; |
| 1517 | break; |
| 1518 | case CMD_RCV_SEQUENCE_CX: |
| 1519 | case CMD_RCV_ELS_REQ_CX: |
| 1520 | case CMD_RCV_SEQUENCE64_CX: |
| 1521 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1522 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1523 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1524 | case CMD_IOCB_RCV_ELS64_CX: |
| 1525 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1526 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1527 | type = LPFC_UNSOL_IOCB; |
| 1528 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1529 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1530 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1531 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1532 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1533 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1534 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1535 | case CMD_IOCB_RET_HBQE64_CN: |
| 1536 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1537 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1538 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1539 | case CMD_IOCB_LOGENTRY_CN: |
| 1540 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1541 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1542 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1543 | type = LPFC_UNKNOWN_IOCB; |
| 1544 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1545 | default: |
| 1546 | type = LPFC_UNKNOWN_IOCB; |
| 1547 | break; |
| 1548 | } |
| 1549 | |
| 1550 | return type; |
| 1551 | } |
| 1552 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1553 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1554 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1555 | * @phba: Pointer to HBA context object. |
| 1556 | * |
| 1557 | * This function is called from SLI initialization code |
| 1558 | * to configure every ring of the HBA's SLI interface. The |
| 1559 | * caller is not required to hold any lock. This function issues |
| 1560 | * a config_ring mailbox command for each ring. |
| 1561 | * This function returns zero if successful else returns a negative |
| 1562 | * error code. |
| 1563 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1564 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1565 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1566 | { |
| 1567 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1568 | LPFC_MBOXQ_t *pmb; |
| 1569 | MAILBOX_t *pmbox; |
| 1570 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1571 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1572 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1573 | if (!pmb) |
| 1574 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1575 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1576 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1577 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1578 | lpfc_config_ring(phba, i, pmb); |
| 1579 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1580 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1581 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1582 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1583 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1584 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1585 | rc, pmbox->mbxCommand, |
| 1586 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1587 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1588 | ret = -ENXIO; |
| 1589 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1590 | } |
| 1591 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1592 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1593 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1594 | } |
| 1595 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1596 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1597 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1598 | * @phba: Pointer to HBA context object. |
| 1599 | * @pring: Pointer to driver SLI ring object. |
| 1600 | * @piocb: Pointer to the driver iocb object. |
| 1601 | * |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1602 | * The driver calls this function with the hbalock held for SLI3 ports or |
| 1603 | * the ring lock held for SLI4 ports. The function adds the |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1604 | * new iocb to txcmplq of the given ring. This function always returns |
| 1605 | * 0. If this function is called for ELS ring, this function checks if |
| 1606 | * there is a vport associated with the ELS command. This function also |
| 1607 | * starts els_tmofunc timer if this is an ELS command. |
| 1608 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1609 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1610 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1611 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1612 | { |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 1613 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1614 | lockdep_assert_held(&pring->ring_lock); |
| 1615 | else |
| 1616 | lockdep_assert_held(&phba->hbalock); |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1617 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1618 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1619 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1620 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1621 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1622 | pring->txcmplq_cnt++; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1623 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1624 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1625 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1626 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1627 | BUG_ON(!piocb->vport); |
| 1628 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1629 | mod_timer(&piocb->vport->els_tmofunc, |
| 1630 | jiffies + |
| 1631 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 1632 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1633 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1634 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1635 | } |
| 1636 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1637 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1638 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1639 | * @phba: Pointer to HBA context object. |
| 1640 | * @pring: Pointer to driver SLI ring object. |
| 1641 | * |
| 1642 | * This function is called with hbalock held to get next |
| 1643 | * iocb in txq of the given ring. If there is any iocb in |
| 1644 | * the txq, the function returns first iocb in the list after |
| 1645 | * removing the iocb from the list, else it returns NULL. |
| 1646 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1647 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1648 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1649 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1650 | struct lpfc_iocbq *cmd_iocb; |
| 1651 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1652 | lockdep_assert_held(&phba->hbalock); |
| 1653 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1654 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1655 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1656 | } |
| 1657 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1658 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1659 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1660 | * @phba: Pointer to HBA context object. |
| 1661 | * @pring: Pointer to driver SLI ring object. |
| 1662 | * |
| 1663 | * This function is called with hbalock held and the caller must post the |
| 1664 | * iocb without releasing the lock. If the caller releases the lock, |
| 1665 | * iocb slot returned by the function is not guaranteed to be available. |
| 1666 | * The function returns pointer to the next available iocb slot if there |
| 1667 | * is available slot in the ring, else it returns NULL. |
| 1668 | * If the get index of the ring is ahead of the put index, the function |
| 1669 | * will post an error attention event to the worker thread to take the |
| 1670 | * HBA to offline state. |
| 1671 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1672 | static IOCB_t * |
| 1673 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1674 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1675 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1676 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1677 | |
| 1678 | lockdep_assert_held(&phba->hbalock); |
| 1679 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1680 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1681 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1682 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1683 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1684 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1685 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1686 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1687 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1688 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1689 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1690 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1691 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1692 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1693 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1694 | pring->sli.sli3.local_getidx, |
| 1695 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1696 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1697 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1698 | /* |
| 1699 | * All error attention handlers are posted to |
| 1700 | * worker thread |
| 1701 | */ |
| 1702 | phba->work_ha |= HA_ERATT; |
| 1703 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1704 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1705 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1706 | |
| 1707 | return NULL; |
| 1708 | } |
| 1709 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1710 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1711 | return NULL; |
| 1712 | } |
| 1713 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1714 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1715 | } |
| 1716 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1717 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1718 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1719 | * @phba: Pointer to HBA context object. |
| 1720 | * @iocbq: Pointer to driver iocb object. |
| 1721 | * |
| 1722 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1723 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1724 | * array and assigns a new iotag. |
| 1725 | * The function returns the allocated iotag if successful, else returns zero. |
| 1726 | * Zero is not a valid iotag. |
| 1727 | * The caller is not required to hold any lock. |
| 1728 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1729 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1730 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1731 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1732 | struct lpfc_iocbq **new_arr; |
| 1733 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1734 | size_t new_len; |
| 1735 | struct lpfc_sli *psli = &phba->sli; |
| 1736 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1737 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1738 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1739 | iotag = psli->last_iotag; |
| 1740 | if(++iotag < psli->iocbq_lookup_len) { |
| 1741 | psli->last_iotag = iotag; |
| 1742 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1743 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1744 | iocbq->iotag = iotag; |
| 1745 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1746 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1747 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1748 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1749 | spin_unlock_irq(&phba->hbalock); |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1750 | new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1751 | GFP_KERNEL); |
| 1752 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1753 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1754 | old_arr = psli->iocbq_lookup; |
| 1755 | if (new_len <= psli->iocbq_lookup_len) { |
| 1756 | /* highly unprobable case */ |
| 1757 | kfree(new_arr); |
| 1758 | iotag = psli->last_iotag; |
| 1759 | if(++iotag < psli->iocbq_lookup_len) { |
| 1760 | psli->last_iotag = iotag; |
| 1761 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1762 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1763 | iocbq->iotag = iotag; |
| 1764 | return iotag; |
| 1765 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1766 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1767 | return 0; |
| 1768 | } |
| 1769 | if (psli->iocbq_lookup) |
| 1770 | memcpy(new_arr, old_arr, |
| 1771 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1772 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1773 | psli->iocbq_lookup = new_arr; |
| 1774 | psli->iocbq_lookup_len = new_len; |
| 1775 | psli->last_iotag = iotag; |
| 1776 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1777 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1778 | iocbq->iotag = iotag; |
| 1779 | kfree(old_arr); |
| 1780 | return iotag; |
| 1781 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1782 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1783 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1784 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1785 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1786 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1787 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1788 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1789 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1790 | } |
| 1791 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1792 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1793 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1794 | * @phba: Pointer to HBA context object. |
| 1795 | * @pring: Pointer to driver SLI ring object. |
| 1796 | * @iocb: Pointer to iocb slot in the ring. |
| 1797 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1798 | * posted to firmware. |
| 1799 | * |
| 1800 | * This function is called with hbalock held to post a new iocb to |
| 1801 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1802 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1803 | * a completion call back for this iocb else the function will free the |
| 1804 | * iocb object. |
| 1805 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1806 | static void |
| 1807 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1808 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1809 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1810 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1811 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1812 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1813 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1814 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1815 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1816 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1817 | if (pring->ringno == LPFC_ELS_RING) { |
| 1818 | lpfc_debugfs_slow_ring_trc(phba, |
| 1819 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1820 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1821 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1822 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1823 | } |
| 1824 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1825 | /* |
| 1826 | * Issue iocb command to adapter |
| 1827 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1828 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1829 | wmb(); |
| 1830 | pring->stats.iocb_cmd++; |
| 1831 | |
| 1832 | /* |
| 1833 | * If there is no completion routine to call, we can release the |
| 1834 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1835 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1836 | */ |
| 1837 | if (nextiocb->iocb_cmpl) |
| 1838 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1839 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1840 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1841 | |
| 1842 | /* |
| 1843 | * Let the HBA know what IOCB slot will be the next one the |
| 1844 | * driver will put a command into. |
| 1845 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1846 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1847 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1848 | } |
| 1849 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1850 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1851 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1852 | * @phba: Pointer to HBA context object. |
| 1853 | * @pring: Pointer to driver SLI ring object. |
| 1854 | * |
| 1855 | * The caller is not required to hold any lock for calling this function. |
| 1856 | * This function updates the chip attention bits for the ring to inform firmware |
| 1857 | * that there are pending work to be done for this ring and requests an |
| 1858 | * interrupt when there is space available in the ring. This function is |
| 1859 | * called when the driver is unable to post more iocbs to the ring due |
| 1860 | * to unavailability of space in the ring. |
| 1861 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1862 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1863 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1864 | { |
| 1865 | int ringno = pring->ringno; |
| 1866 | |
| 1867 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1868 | |
| 1869 | wmb(); |
| 1870 | |
| 1871 | /* |
| 1872 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1873 | * The HBA will tell us when an IOCB entry is available. |
| 1874 | */ |
| 1875 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1876 | readl(phba->CAregaddr); /* flush */ |
| 1877 | |
| 1878 | pring->stats.iocb_cmd_full++; |
| 1879 | } |
| 1880 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1881 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1882 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1883 | * @phba: Pointer to HBA context object. |
| 1884 | * @pring: Pointer to driver SLI ring object. |
| 1885 | * |
| 1886 | * This function updates the chip attention register bit for the |
| 1887 | * given ring to inform HBA that there is more work to be done |
| 1888 | * in this ring. The caller is not required to hold any lock. |
| 1889 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1890 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1891 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1892 | { |
| 1893 | int ringno = pring->ringno; |
| 1894 | |
| 1895 | /* |
| 1896 | * Tell the HBA that there is work to do in this ring. |
| 1897 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1898 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1899 | wmb(); |
| 1900 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1901 | readl(phba->CAregaddr); /* flush */ |
| 1902 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1903 | } |
| 1904 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1905 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1906 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1907 | * @phba: Pointer to HBA context object. |
| 1908 | * @pring: Pointer to driver SLI ring object. |
| 1909 | * |
| 1910 | * This function is called with hbalock held to post pending iocbs |
| 1911 | * in the txq to the firmware. This function is called when driver |
| 1912 | * detects space available in the ring. |
| 1913 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1914 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1915 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1916 | { |
| 1917 | IOCB_t *iocb; |
| 1918 | struct lpfc_iocbq *nextiocb; |
| 1919 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1920 | lockdep_assert_held(&phba->hbalock); |
| 1921 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1922 | /* |
| 1923 | * Check to see if: |
| 1924 | * (a) there is anything on the txq to send |
| 1925 | * (b) link is up |
| 1926 | * (c) link attention events can be processed (fcp ring only) |
| 1927 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1928 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1929 | |
| 1930 | if (lpfc_is_link_up(phba) && |
| 1931 | (!list_empty(&pring->txq)) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1932 | (pring->ringno != LPFC_FCP_RING || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1933 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1934 | |
| 1935 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1936 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1937 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1938 | |
| 1939 | if (iocb) |
| 1940 | lpfc_sli_update_ring(phba, pring); |
| 1941 | else |
| 1942 | lpfc_sli_update_full_ring(phba, pring); |
| 1943 | } |
| 1944 | |
| 1945 | return; |
| 1946 | } |
| 1947 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1948 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1949 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1950 | * @phba: Pointer to HBA context object. |
| 1951 | * @hbqno: HBQ number. |
| 1952 | * |
| 1953 | * This function is called with hbalock held to get the next |
| 1954 | * available slot for the given HBQ. If there is free slot |
| 1955 | * available for the HBQ it will return pointer to the next available |
| 1956 | * HBQ entry else it will return NULL. |
| 1957 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1958 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1959 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1960 | { |
| 1961 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1962 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1963 | lockdep_assert_held(&phba->hbalock); |
| 1964 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1965 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1966 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1967 | hbqp->next_hbqPutIdx = 0; |
| 1968 | |
| 1969 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1970 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1971 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1972 | |
| 1973 | hbqp->local_hbqGetIdx = getidx; |
| 1974 | |
| 1975 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1976 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1977 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1978 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1979 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1980 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1981 | hbqp->entry_count); |
| 1982 | |
| 1983 | phba->link_state = LPFC_HBA_ERROR; |
| 1984 | return NULL; |
| 1985 | } |
| 1986 | |
| 1987 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1988 | return NULL; |
| 1989 | } |
| 1990 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1991 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1992 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1993 | } |
| 1994 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1995 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1996 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1997 | * @phba: Pointer to HBA context object. |
| 1998 | * |
| 1999 | * This function is called with no lock held to free all the |
| 2000 | * hbq buffers while uninitializing the SLI interface. It also |
| 2001 | * frees the HBQ buffers returned by the firmware but not yet |
| 2002 | * processed by the upper layers. |
| 2003 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2004 | void |
| 2005 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 2006 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2007 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 2008 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2009 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2010 | int i, hbq_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2011 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2012 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2013 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2014 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2015 | for (i = 0; i < hbq_count; ++i) { |
| 2016 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 2017 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 2018 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 2019 | list_del(&hbq_buf->dbuf.list); |
| 2020 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 2021 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2022 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2023 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2024 | |
| 2025 | /* Mark the HBQs not in use */ |
| 2026 | phba->hbq_in_use = 0; |
| 2027 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2028 | } |
| 2029 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2030 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2031 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2032 | * @phba: Pointer to HBA context object. |
| 2033 | * @hbqno: HBQ number. |
| 2034 | * @hbq_buf: Pointer to HBQ buffer. |
| 2035 | * |
| 2036 | * This function is called with the hbalock held to post a |
| 2037 | * hbq buffer to the firmware. If the function finds an empty |
| 2038 | * slot in the HBQ, it will post the buffer. The function will return |
| 2039 | * pointer to the hbq entry if it successfully post the buffer |
| 2040 | * else it will return NULL. |
| 2041 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2042 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2043 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2044 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2045 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2046 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2047 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 2048 | } |
| 2049 | |
| 2050 | /** |
| 2051 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 2052 | * @phba: Pointer to HBA context object. |
| 2053 | * @hbqno: HBQ number. |
| 2054 | * @hbq_buf: Pointer to HBQ buffer. |
| 2055 | * |
| 2056 | * This function is called with the hbalock held to post a hbq buffer to the |
| 2057 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 2058 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 2059 | * it successfully post the buffer else it will return an error. |
| 2060 | **/ |
| 2061 | static int |
| 2062 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 2063 | struct hbq_dmabuf *hbq_buf) |
| 2064 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2065 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2066 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2067 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2068 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2069 | /* Get next HBQ entry slot to use */ |
| 2070 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 2071 | if (hbqe) { |
| 2072 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 2073 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2074 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 2075 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2076 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2077 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2078 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 2079 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 2080 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2081 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 2082 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2083 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2084 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2085 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2086 | return 0; |
| 2087 | } else |
| 2088 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2089 | } |
| 2090 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2091 | /** |
| 2092 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 2093 | * @phba: Pointer to HBA context object. |
| 2094 | * @hbqno: HBQ number. |
| 2095 | * @hbq_buf: Pointer to HBQ buffer. |
| 2096 | * |
| 2097 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 2098 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 2099 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 2100 | **/ |
| 2101 | static int |
| 2102 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 2103 | struct hbq_dmabuf *hbq_buf) |
| 2104 | { |
| 2105 | int rc; |
| 2106 | struct lpfc_rqe hrqe; |
| 2107 | struct lpfc_rqe drqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2108 | struct lpfc_queue *hrq; |
| 2109 | struct lpfc_queue *drq; |
| 2110 | |
| 2111 | if (hbqno != LPFC_ELS_HBQ) |
| 2112 | return 1; |
| 2113 | hrq = phba->sli4_hba.hdr_rq; |
| 2114 | drq = phba->sli4_hba.dat_rq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2115 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2116 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2117 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 2118 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 2119 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 2120 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2121 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2122 | if (rc < 0) |
| 2123 | return rc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2124 | hbq_buf->tag = (rc | (hbqno << 16)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2125 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 2126 | return 0; |
| 2127 | } |
| 2128 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2129 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2130 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 2131 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2132 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2133 | .mask_count = 0, |
| 2134 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2135 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2136 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2137 | .init_count = 40, |
| 2138 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2139 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2140 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2141 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2142 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2143 | &lpfc_els_hbq, |
| 2144 | }; |
| 2145 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2146 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2147 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2148 | * @phba: Pointer to HBA context object. |
| 2149 | * @hbqno: HBQ number. |
| 2150 | * @count: Number of HBQ buffers to be posted. |
| 2151 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2152 | * This function is called with no lock held to post more hbq buffers to the |
| 2153 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 2154 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2155 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 2156 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2157 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 2158 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2159 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2160 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2161 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2162 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2163 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2164 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2165 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2166 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 2167 | lpfc_hbq_defs[hbqno]->entry_count) |
| 2168 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 2169 | phba->hbqs[hbqno].buffer_count; |
| 2170 | if (!count) |
| 2171 | return 0; |
| 2172 | /* Allocate HBQ entries */ |
| 2173 | for (i = 0; i < count; i++) { |
| 2174 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 2175 | if (!hbq_buffer) |
| 2176 | break; |
| 2177 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 2178 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2179 | /* Check whether HBQ is still in use */ |
| 2180 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2181 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2182 | goto err; |
| 2183 | while (!list_empty(&hbq_buf_list)) { |
| 2184 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2185 | dbuf.list); |
| 2186 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 2187 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2188 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2189 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2190 | posted++; |
| 2191 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2192 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2193 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2194 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2195 | return posted; |
| 2196 | err: |
| 2197 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 2198 | while (!list_empty(&hbq_buf_list)) { |
| 2199 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2200 | dbuf.list); |
| 2201 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 2202 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2203 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2204 | } |
| 2205 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2206 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2207 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2208 | * @phba: Pointer to HBA context object. |
| 2209 | * @qno: HBQ number. |
| 2210 | * |
| 2211 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2212 | * is called with no lock held. The function returns the number of HBQ entries |
| 2213 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2214 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2215 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2216 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2217 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2218 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2219 | return 0; |
| 2220 | else |
| 2221 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2222 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2223 | } |
| 2224 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2225 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2226 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2227 | * @phba: Pointer to HBA context object. |
| 2228 | * @qno: HBQ queue number. |
| 2229 | * |
| 2230 | * This function is called from SLI initialization code path with |
| 2231 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2232 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2233 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2234 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2235 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2236 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2237 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2238 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2239 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2240 | else |
| 2241 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2242 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2243 | } |
| 2244 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2245 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2246 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 2247 | * @phba: Pointer to HBA context object. |
| 2248 | * @hbqno: HBQ number. |
| 2249 | * |
| 2250 | * This function removes the first hbq buffer on an hbq list and returns a |
| 2251 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2252 | **/ |
| 2253 | static struct hbq_dmabuf * |
| 2254 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 2255 | { |
| 2256 | struct lpfc_dmabuf *d_buf; |
| 2257 | |
| 2258 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 2259 | if (!d_buf) |
| 2260 | return NULL; |
| 2261 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2262 | } |
| 2263 | |
| 2264 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2265 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list |
| 2266 | * @phba: Pointer to HBA context object. |
| 2267 | * @hbqno: HBQ number. |
| 2268 | * |
| 2269 | * This function removes the first RQ buffer on an RQ buffer list and returns a |
| 2270 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2271 | **/ |
| 2272 | static struct rqb_dmabuf * |
| 2273 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) |
| 2274 | { |
| 2275 | struct lpfc_dmabuf *h_buf; |
| 2276 | struct lpfc_rqb *rqbp; |
| 2277 | |
| 2278 | rqbp = hrq->rqbp; |
| 2279 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 2280 | struct lpfc_dmabuf, list); |
| 2281 | if (!h_buf) |
| 2282 | return NULL; |
| 2283 | rqbp->buffer_count--; |
| 2284 | return container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 2285 | } |
| 2286 | |
| 2287 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2288 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2289 | * @phba: Pointer to HBA context object. |
| 2290 | * @tag: Tag of the hbq buffer. |
| 2291 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2292 | * This function searches for the hbq buffer associated with the given tag in |
| 2293 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2294 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2295 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2296 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2297 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2298 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2299 | struct lpfc_dmabuf *d_buf; |
| 2300 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2301 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2302 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2303 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2304 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2305 | return NULL; |
| 2306 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2307 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2308 | 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] | 2309 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2310 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2311 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2312 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2313 | } |
| 2314 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2315 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2316 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2317 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2318 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2319 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2320 | } |
| 2321 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2322 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2323 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2324 | * @phba: Pointer to HBA context object. |
| 2325 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2326 | * |
| 2327 | * This function is called with hbalock. This function gives back |
| 2328 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2329 | * post the buffer, it will free the buffer. |
| 2330 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2331 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2332 | 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] | 2333 | { |
| 2334 | uint32_t hbqno; |
| 2335 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2336 | if (hbq_buffer) { |
| 2337 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2338 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2339 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2340 | } |
| 2341 | } |
| 2342 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2343 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2344 | * 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] | 2345 | * @mbxCommand: mailbox command code. |
| 2346 | * |
| 2347 | * This function is called by the mailbox event handler function to verify |
| 2348 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2349 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2350 | * and the mailbox event handler will take the HBA offline. |
| 2351 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2352 | static int |
| 2353 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2354 | { |
| 2355 | uint8_t ret; |
| 2356 | |
| 2357 | switch (mbxCommand) { |
| 2358 | case MBX_LOAD_SM: |
| 2359 | case MBX_READ_NV: |
| 2360 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2361 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2362 | case MBX_RUN_BIU_DIAG: |
| 2363 | case MBX_INIT_LINK: |
| 2364 | case MBX_DOWN_LINK: |
| 2365 | case MBX_CONFIG_LINK: |
| 2366 | case MBX_CONFIG_RING: |
| 2367 | case MBX_RESET_RING: |
| 2368 | case MBX_READ_CONFIG: |
| 2369 | case MBX_READ_RCONFIG: |
| 2370 | case MBX_READ_SPARM: |
| 2371 | case MBX_READ_STATUS: |
| 2372 | case MBX_READ_RPI: |
| 2373 | case MBX_READ_XRI: |
| 2374 | case MBX_READ_REV: |
| 2375 | case MBX_READ_LNK_STAT: |
| 2376 | case MBX_REG_LOGIN: |
| 2377 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2378 | case MBX_CLEAR_LA: |
| 2379 | case MBX_DUMP_MEMORY: |
| 2380 | case MBX_DUMP_CONTEXT: |
| 2381 | case MBX_RUN_DIAGS: |
| 2382 | case MBX_RESTART: |
| 2383 | case MBX_UPDATE_CFG: |
| 2384 | case MBX_DOWN_LOAD: |
| 2385 | case MBX_DEL_LD_ENTRY: |
| 2386 | case MBX_RUN_PROGRAM: |
| 2387 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2388 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2389 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2390 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2391 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2392 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2393 | case MBX_LOAD_AREA: |
| 2394 | case MBX_RUN_BIU_DIAG64: |
| 2395 | case MBX_CONFIG_PORT: |
| 2396 | case MBX_READ_SPARM64: |
| 2397 | case MBX_READ_RPI64: |
| 2398 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2399 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2400 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2401 | case MBX_SET_DEBUG: |
| 2402 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2403 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2404 | case MBX_REG_VPI: |
| 2405 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2406 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2407 | case MBX_PORT_CAPABILITIES: |
| 2408 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2409 | case MBX_SLI4_CONFIG: |
| 2410 | case MBX_SLI4_REQ_FTRS: |
| 2411 | case MBX_REG_FCFI: |
| 2412 | case MBX_UNREG_FCFI: |
| 2413 | case MBX_REG_VFI: |
| 2414 | case MBX_UNREG_VFI: |
| 2415 | case MBX_INIT_VPI: |
| 2416 | case MBX_INIT_VFI: |
| 2417 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2418 | case MBX_READ_EVENT_LOG_STATUS: |
| 2419 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2420 | case MBX_SECURITY_MGMT: |
| 2421 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2422 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2423 | ret = mbxCommand; |
| 2424 | break; |
| 2425 | default: |
| 2426 | ret = MBX_SHUTDOWN; |
| 2427 | break; |
| 2428 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2429 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2431 | |
| 2432 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2433 | * 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] | 2434 | * @phba: Pointer to HBA context object. |
| 2435 | * @pmboxq: Pointer to mailbox command. |
| 2436 | * |
| 2437 | * This is completion handler function for mailbox commands issued from |
| 2438 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2439 | * mailbox event handler function with no lock held. This function |
| 2440 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2441 | * of the mailbox. |
| 2442 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2443 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2444 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2445 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2446 | unsigned long drvr_flag; |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2447 | struct completion *pmbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2448 | |
| 2449 | /* |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2450 | * If pmbox_done is empty, the driver thread gave up waiting and |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2451 | * continued running. |
| 2452 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2453 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2454 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2455 | pmbox_done = (struct completion *)pmboxq->context3; |
| 2456 | if (pmbox_done) |
| 2457 | complete(pmbox_done); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2458 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2459 | return; |
| 2460 | } |
| 2461 | |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2462 | static void |
| 2463 | __lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 2464 | { |
| 2465 | unsigned long iflags; |
| 2466 | |
| 2467 | if (ndlp->nlp_flag & NLP_RELEASE_RPI) { |
| 2468 | lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi); |
| 2469 | spin_lock_irqsave(&vport->phba->ndlp_lock, iflags); |
| 2470 | ndlp->nlp_flag &= ~NLP_RELEASE_RPI; |
| 2471 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
| 2472 | spin_unlock_irqrestore(&vport->phba->ndlp_lock, iflags); |
| 2473 | } |
| 2474 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
| 2475 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2476 | |
| 2477 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2478 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2479 | * @phba: Pointer to HBA context object. |
| 2480 | * @pmb: Pointer to mailbox object. |
| 2481 | * |
| 2482 | * This function is the default mailbox completion handler. It |
| 2483 | * frees the memory resources associated with the completed mailbox |
| 2484 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2485 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2486 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2487 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2488 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2489 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2490 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2491 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2492 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2493 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2494 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2495 | int rc; |
| 2496 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2497 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2498 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2499 | if (mp) { |
| 2500 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2501 | kfree(mp); |
| 2502 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2503 | |
| 2504 | /* |
| 2505 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2506 | * is in re-discovery driver need to cleanup the RPI. |
| 2507 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2508 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2509 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2510 | !pmb->u.mb.mbxStatus) { |
| 2511 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2512 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2513 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2514 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2515 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2516 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2517 | if (rc != MBX_NOT_FINISHED) |
| 2518 | return; |
| 2519 | } |
| 2520 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2521 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2522 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2523 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2524 | shost = lpfc_shost_from_vport(vport); |
| 2525 | spin_lock_irq(shost->host_lock); |
| 2526 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2527 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2528 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2529 | } |
| 2530 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2531 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2532 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2533 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2534 | pmb->ctx_buf = NULL; |
| 2535 | pmb->ctx_ndlp = NULL; |
| 2536 | } |
| 2537 | |
| 2538 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2539 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 2540 | |
| 2541 | /* Check to see if there are any deferred events to process */ |
| 2542 | if (ndlp) { |
| 2543 | lpfc_printf_vlog( |
| 2544 | vport, |
| 2545 | KERN_INFO, LOG_MBOX | LOG_DISCOVERY, |
| 2546 | "1438 UNREG cmpl deferred mbox x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2547 | "on NPort x%x Data: x%x x%x %px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2548 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2549 | ndlp->nlp_flag, ndlp->nlp_defer_did, ndlp); |
| 2550 | |
| 2551 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2552 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2553 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2554 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
| 2555 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2556 | } else { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2557 | __lpfc_sli_rpi_release(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2558 | } |
James Smart | 97acd00 | 2019-09-21 20:58:51 -0700 | [diff] [blame] | 2559 | if (vport->load_flag & FC_UNLOADING) |
| 2560 | lpfc_nlp_put(ndlp); |
James Smart | 9b16406 | 2019-03-12 16:30:06 -0700 | [diff] [blame] | 2561 | pmb->ctx_ndlp = NULL; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2562 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2563 | } |
| 2564 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2565 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2566 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2567 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2568 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2569 | "2860 SLI authentication is required " |
| 2570 | "for INIT_LINK but has not done yet\n"); |
| 2571 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2572 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2573 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2574 | else |
| 2575 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2576 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2577 | /** |
| 2578 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2579 | * @phba: Pointer to HBA context object. |
| 2580 | * @pmb: Pointer to mailbox object. |
| 2581 | * |
| 2582 | * This function is the unreg rpi mailbox completion handler. It |
| 2583 | * frees the memory resources associated with the completed mailbox |
| 2584 | * command. An additional refrenece is put on the ndlp to prevent |
| 2585 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2586 | * the unreg mailbox command completes, this routine puts the |
| 2587 | * reference back. |
| 2588 | * |
| 2589 | **/ |
| 2590 | void |
| 2591 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2592 | { |
| 2593 | struct lpfc_vport *vport = pmb->vport; |
| 2594 | struct lpfc_nodelist *ndlp; |
| 2595 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2596 | ndlp = pmb->ctx_ndlp; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2597 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2598 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2599 | (bf_get(lpfc_sli_intf_if_type, |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 2600 | &phba->sli4_hba.sli_intf) >= |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2601 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2602 | if (ndlp) { |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2603 | lpfc_printf_vlog( |
| 2604 | vport, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 2605 | "0010 UNREG_LOGIN vpi:%x " |
| 2606 | "rpi:%x DID:%x defer x%x flg x%x " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2607 | "map:%x %px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2608 | vport->vpi, ndlp->nlp_rpi, |
| 2609 | ndlp->nlp_DID, ndlp->nlp_defer_did, |
| 2610 | ndlp->nlp_flag, |
| 2611 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2612 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2613 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2614 | |
| 2615 | /* Check to see if there are any deferred |
| 2616 | * events to process |
| 2617 | */ |
| 2618 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2619 | (ndlp->nlp_defer_did != |
| 2620 | NLP_EVT_NOTHING_PENDING)) { |
| 2621 | lpfc_printf_vlog( |
| 2622 | vport, KERN_INFO, LOG_DISCOVERY, |
| 2623 | "4111 UNREG cmpl deferred " |
| 2624 | "clr x%x on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 2625 | "NPort x%x Data: x%x x%px\n", |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2626 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2627 | ndlp->nlp_defer_did, ndlp); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2628 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2629 | ndlp->nlp_defer_did = |
| 2630 | NLP_EVT_NOTHING_PENDING; |
| 2631 | lpfc_issue_els_plogi( |
| 2632 | vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2633 | } else { |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 2634 | __lpfc_sli_rpi_release(vport, ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2635 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2636 | } |
| 2637 | } |
| 2638 | } |
| 2639 | |
| 2640 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2641 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2642 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2643 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2644 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2645 | * @phba: Pointer to HBA context object. |
| 2646 | * |
| 2647 | * This function is called with no lock held. This function processes all |
| 2648 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2649 | * service routine processes mailbox completion interrupt and adds completed |
| 2650 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2651 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2652 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2653 | * function returns the mailbox commands to the upper layer by calling the |
| 2654 | * completion handler function of each mailbox. |
| 2655 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2656 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2657 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2659 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2660 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2661 | int rc; |
| 2662 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2663 | |
| 2664 | phba->sli.slistat.mbox_event++; |
| 2665 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2666 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2667 | spin_lock_irq(&phba->hbalock); |
| 2668 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2669 | spin_unlock_irq(&phba->hbalock); |
| 2670 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2671 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2672 | do { |
| 2673 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2674 | if (pmb == NULL) |
| 2675 | break; |
| 2676 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2677 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2678 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2679 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2680 | if (pmb->vport) { |
| 2681 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2682 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2683 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2684 | (uint32_t)pmbox->mbxCommand, |
| 2685 | pmbox->un.varWords[0], |
| 2686 | pmbox->un.varWords[1]); |
| 2687 | } |
| 2688 | else { |
| 2689 | lpfc_debugfs_disc_trc(phba->pport, |
| 2690 | LPFC_DISC_TRC_MBOX, |
| 2691 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2692 | (uint32_t)pmbox->mbxCommand, |
| 2693 | pmbox->un.varWords[0], |
| 2694 | pmbox->un.varWords[1]); |
| 2695 | } |
| 2696 | } |
| 2697 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2698 | /* |
| 2699 | * It is a fatal error if unknown mbox command completion. |
| 2700 | */ |
| 2701 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2702 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2703 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2704 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2705 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2706 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 2707 | pmb->vport ? pmb->vport->vpi : |
| 2708 | LPFC_VPORT_UNKNOWN, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2709 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2710 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2711 | pmb), |
| 2712 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2713 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2714 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2715 | phba->work_hs = HS_FFER3; |
| 2716 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2717 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2718 | } |
| 2719 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2720 | if (pmbox->mbxStatus) { |
| 2721 | phba->sli.slistat.mbox_stat_err++; |
| 2722 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2723 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2724 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2725 | LOG_MBOX | LOG_SLI, |
| 2726 | "(%d):0305 Mbox cmd cmpl " |
| 2727 | "error - RETRYing Data: x%x " |
| 2728 | "(x%x/x%x) x%x x%x x%x\n", |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 2729 | pmb->vport ? pmb->vport->vpi : |
| 2730 | LPFC_VPORT_UNKNOWN, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2731 | pmbox->mbxCommand, |
| 2732 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2733 | pmb), |
| 2734 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2735 | pmb), |
| 2736 | pmbox->mbxStatus, |
| 2737 | pmbox->un.varWords[0], |
James Smart | 43bfea1 | 2019-09-21 20:58:57 -0700 | [diff] [blame] | 2738 | pmb->vport ? pmb->vport->port_state : |
| 2739 | LPFC_VPORT_UNKNOWN); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2740 | pmbox->mbxStatus = 0; |
| 2741 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2743 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2744 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2745 | } |
| 2746 | } |
| 2747 | |
| 2748 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2749 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
Sakari Ailus | 2d44d16 | 2019-09-04 19:04:23 +0300 | [diff] [blame] | 2750 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl %ps " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2751 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2752 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2753 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2754 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2755 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2756 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2757 | pmb->mbox_cmpl, |
| 2758 | *((uint32_t *) pmbox), |
| 2759 | pmbox->un.varWords[0], |
| 2760 | pmbox->un.varWords[1], |
| 2761 | pmbox->un.varWords[2], |
| 2762 | pmbox->un.varWords[3], |
| 2763 | pmbox->un.varWords[4], |
| 2764 | pmbox->un.varWords[5], |
| 2765 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2766 | pmbox->un.varWords[7], |
| 2767 | pmbox->un.varWords[8], |
| 2768 | pmbox->un.varWords[9], |
| 2769 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2770 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2771 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2772 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2773 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2774 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2775 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2776 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2777 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2778 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2779 | * @phba: Pointer to HBA context object. |
| 2780 | * @pring: Pointer to driver SLI ring object. |
| 2781 | * @tag: buffer tag. |
| 2782 | * |
| 2783 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2784 | * is set in the tag the buffer is posted for a particular exchange, |
| 2785 | * the function will return the buffer without replacing the buffer. |
| 2786 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2787 | * returns the buffer and also posts another buffer to the firmware. |
| 2788 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2789 | static struct lpfc_dmabuf * |
| 2790 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2791 | struct lpfc_sli_ring *pring, |
| 2792 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2793 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2794 | struct hbq_dmabuf *hbq_entry; |
| 2795 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2796 | if (tag & QUE_BUFTAG_BIT) |
| 2797 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2798 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2799 | if (!hbq_entry) |
| 2800 | return NULL; |
| 2801 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2802 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2803 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2804 | /** |
| 2805 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2806 | * @phba: Pointer to HBA context object. |
| 2807 | * @pring: Pointer to driver SLI ring object. |
| 2808 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2809 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2810 | * @fch_type: the type for the first frame of the sequence. |
| 2811 | * |
| 2812 | * This function is called with no lock held. This function uses the r_ctl and |
| 2813 | * type of the received sequence to find the correct callback function to call |
| 2814 | * to process the sequence. |
| 2815 | **/ |
| 2816 | static int |
| 2817 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2818 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2819 | uint32_t fch_type) |
| 2820 | { |
| 2821 | int i; |
| 2822 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2823 | switch (fch_type) { |
| 2824 | case FC_TYPE_NVME: |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2825 | lpfc_nvmet_unsol_ls_event(phba, pring, saveq); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2826 | return 1; |
| 2827 | default: |
| 2828 | break; |
| 2829 | } |
| 2830 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2831 | /* unSolicited Responses */ |
| 2832 | if (pring->prt[0].profile) { |
| 2833 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2834 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2835 | saveq); |
| 2836 | return 1; |
| 2837 | } |
| 2838 | /* We must search, based on rctl / type |
| 2839 | for the right routine */ |
| 2840 | for (i = 0; i < pring->num_mask; i++) { |
| 2841 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2842 | (pring->prt[i].type == fch_type)) { |
| 2843 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2844 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2845 | (phba, pring, saveq); |
| 2846 | return 1; |
| 2847 | } |
| 2848 | } |
| 2849 | return 0; |
| 2850 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2851 | |
| 2852 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2853 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2854 | * @phba: Pointer to HBA context object. |
| 2855 | * @pring: Pointer to driver SLI ring object. |
| 2856 | * @saveq: Pointer to the unsolicited iocb. |
| 2857 | * |
| 2858 | * This function is called with no lock held by the ring event handler |
| 2859 | * when there is an unsolicited iocb posted to the response ring by the |
| 2860 | * firmware. This function gets the buffer associated with the iocbs |
| 2861 | * and calls the event handler for the ring. This function handles both |
| 2862 | * qring buffers and hbq buffers. |
| 2863 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2864 | * upper layer functions will free the iocb objects. |
| 2865 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2866 | static int |
| 2867 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2868 | struct lpfc_iocbq *saveq) |
| 2869 | { |
| 2870 | IOCB_t * irsp; |
| 2871 | WORD5 * w5p; |
| 2872 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2873 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2874 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2875 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2876 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2877 | |
| 2878 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2879 | if (pring->lpfc_sli_rcv_async_status) |
| 2880 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2881 | else |
| 2882 | lpfc_printf_log(phba, |
| 2883 | KERN_WARNING, |
| 2884 | LOG_SLI, |
| 2885 | "0316 Ring %d handler: unexpected " |
| 2886 | "ASYNC_STATUS iocb received evt_code " |
| 2887 | "0x%x\n", |
| 2888 | pring->ringno, |
| 2889 | irsp->un.asyncstat.evt_code); |
| 2890 | return 1; |
| 2891 | } |
| 2892 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2893 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2894 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2895 | if (irsp->ulpBdeCount > 0) { |
| 2896 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2897 | irsp->un.ulpWord[3]); |
| 2898 | lpfc_in_buf_free(phba, dmzbuf); |
| 2899 | } |
| 2900 | |
| 2901 | if (irsp->ulpBdeCount > 1) { |
| 2902 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2903 | irsp->unsli3.sli3Words[3]); |
| 2904 | lpfc_in_buf_free(phba, dmzbuf); |
| 2905 | } |
| 2906 | |
| 2907 | if (irsp->ulpBdeCount > 2) { |
| 2908 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2909 | irsp->unsli3.sli3Words[7]); |
| 2910 | lpfc_in_buf_free(phba, dmzbuf); |
| 2911 | } |
| 2912 | |
| 2913 | return 1; |
| 2914 | } |
| 2915 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2916 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2917 | if (irsp->ulpBdeCount != 0) { |
| 2918 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2919 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2920 | if (!saveq->context2) |
| 2921 | lpfc_printf_log(phba, |
| 2922 | KERN_ERR, |
| 2923 | LOG_SLI, |
| 2924 | "0341 Ring %d Cannot find buffer for " |
| 2925 | "an unsolicited iocb. tag 0x%x\n", |
| 2926 | pring->ringno, |
| 2927 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2928 | } |
| 2929 | if (irsp->ulpBdeCount == 2) { |
| 2930 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2931 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2932 | if (!saveq->context3) |
| 2933 | lpfc_printf_log(phba, |
| 2934 | KERN_ERR, |
| 2935 | LOG_SLI, |
| 2936 | "0342 Ring %d Cannot find buffer for an" |
| 2937 | " unsolicited iocb. tag 0x%x\n", |
| 2938 | pring->ringno, |
| 2939 | irsp->unsli3.sli3Words[7]); |
| 2940 | } |
| 2941 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2942 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2943 | if (irsp->ulpBdeCount != 0) { |
| 2944 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2945 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2946 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2947 | lpfc_printf_log(phba, |
| 2948 | KERN_ERR, |
| 2949 | LOG_SLI, |
| 2950 | "0343 Ring %d Cannot find " |
| 2951 | "buffer for an unsolicited iocb" |
| 2952 | ". tag 0x%x\n", pring->ringno, |
| 2953 | irsp->un.ulpWord[3]); |
| 2954 | } |
| 2955 | if (irsp->ulpBdeCount == 2) { |
| 2956 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2957 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2958 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2959 | lpfc_printf_log(phba, |
| 2960 | KERN_ERR, |
| 2961 | LOG_SLI, |
| 2962 | "0344 Ring %d Cannot find " |
| 2963 | "buffer for an unsolicited " |
| 2964 | "iocb. tag 0x%x\n", |
| 2965 | pring->ringno, |
| 2966 | irsp->unsli3.sli3Words[7]); |
| 2967 | } |
| 2968 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2969 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2970 | if (irsp->ulpBdeCount != 0 && |
| 2971 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2972 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2973 | int found = 0; |
| 2974 | |
| 2975 | /* search continue save q for same XRI */ |
| 2976 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2977 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2978 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2979 | list_add_tail(&saveq->list, &iocbq->list); |
| 2980 | found = 1; |
| 2981 | break; |
| 2982 | } |
| 2983 | } |
| 2984 | if (!found) |
| 2985 | list_add_tail(&saveq->clist, |
| 2986 | &pring->iocb_continue_saveq); |
| 2987 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2988 | list_del_init(&iocbq->clist); |
| 2989 | saveq = iocbq; |
| 2990 | irsp = &(saveq->iocb); |
| 2991 | } else |
| 2992 | return 0; |
| 2993 | } |
| 2994 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2995 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2996 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2997 | Rctl = FC_RCTL_ELS_REQ; |
| 2998 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2999 | } else { |
| 3000 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 3001 | Rctl = w5p->hcsw.Rctl; |
| 3002 | Type = w5p->hcsw.Type; |
| 3003 | |
| 3004 | /* Firmware Workaround */ |
| 3005 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 3006 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 3007 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 3008 | Rctl = FC_RCTL_ELS_REQ; |
| 3009 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 3010 | w5p->hcsw.Rctl = Rctl; |
| 3011 | w5p->hcsw.Type = Type; |
| 3012 | } |
| 3013 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3014 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3015 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3016 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3017 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3018 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3019 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3020 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3021 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3022 | } |
| 3023 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3024 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3025 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3026 | * @phba: Pointer to HBA context object. |
| 3027 | * @pring: Pointer to driver SLI ring object. |
| 3028 | * @prspiocb: Pointer to response iocb object. |
| 3029 | * |
| 3030 | * This function looks up the iocb_lookup table to get the command iocb |
| 3031 | * corresponding to the given response iocb using the iotag of the |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3032 | * response iocb. The driver calls this function with the hbalock held |
| 3033 | * for SLI3 ports or the ring lock held for SLI4 ports. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3034 | * This function returns the command iocb object if it finds the command |
| 3035 | * iocb else returns NULL. |
| 3036 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3037 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3038 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 3039 | struct lpfc_sli_ring *pring, |
| 3040 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3041 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3042 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 3043 | uint16_t iotag; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3044 | spinlock_t *temp_lock = NULL; |
| 3045 | unsigned long iflag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3046 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3047 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3048 | temp_lock = &pring->ring_lock; |
| 3049 | else |
| 3050 | temp_lock = &phba->hbalock; |
| 3051 | |
| 3052 | spin_lock_irqsave(temp_lock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3053 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3054 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3055 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3056 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3057 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3058 | /* remove from txcmpl queue list */ |
| 3059 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3060 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3061 | pring->txcmplq_cnt--; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3062 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3063 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3064 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3065 | } |
| 3066 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3067 | spin_unlock_irqrestore(temp_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3068 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3069 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3070 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3071 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3072 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3073 | return NULL; |
| 3074 | } |
| 3075 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3076 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3077 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 3078 | * @phba: Pointer to HBA context object. |
| 3079 | * @pring: Pointer to driver SLI ring object. |
| 3080 | * @iotag: IOCB tag. |
| 3081 | * |
| 3082 | * 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] | 3083 | * corresponding to the given iotag. The driver calls this function with |
| 3084 | * 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] | 3085 | * This function returns the command iocb object if it finds the command |
| 3086 | * iocb else returns NULL. |
| 3087 | **/ |
| 3088 | static struct lpfc_iocbq * |
| 3089 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 3090 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 3091 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3092 | struct lpfc_iocbq *cmd_iocb = NULL; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3093 | spinlock_t *temp_lock = NULL; |
| 3094 | unsigned long iflag = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3095 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3096 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3097 | temp_lock = &pring->ring_lock; |
| 3098 | else |
| 3099 | temp_lock = &phba->hbalock; |
| 3100 | |
| 3101 | spin_lock_irqsave(temp_lock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3102 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3103 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3104 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 3105 | /* remove from txcmpl queue list */ |
| 3106 | list_del_init(&cmd_iocb->list); |
| 3107 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3108 | pring->txcmplq_cnt--; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3109 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3110 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3111 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3112 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3113 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3114 | spin_unlock_irqrestore(temp_lock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3115 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3116 | "0372 iotag x%x lookup error: max iotag (x%x) " |
| 3117 | "iocb_flag x%x\n", |
| 3118 | iotag, phba->sli.last_iotag, |
| 3119 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3120 | return NULL; |
| 3121 | } |
| 3122 | |
| 3123 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3124 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3125 | * @phba: Pointer to HBA context object. |
| 3126 | * @pring: Pointer to driver SLI ring object. |
| 3127 | * @saveq: Pointer to the response iocb to be processed. |
| 3128 | * |
| 3129 | * This function is called by the ring event handler for non-fcp |
| 3130 | * rings when there is a new response iocb in the response ring. |
| 3131 | * The caller is not required to hold any locks. This function |
| 3132 | * gets the command iocb associated with the response iocb and |
| 3133 | * calls the completion handler for the command iocb. If there |
| 3134 | * is no completion handler, the function will free the resources |
| 3135 | * associated with command iocb. If the response iocb is for |
| 3136 | * an already aborted command iocb, the status of the completion |
| 3137 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 3138 | * This function always returns 1. |
| 3139 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3140 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3141 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3142 | struct lpfc_iocbq *saveq) |
| 3143 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3144 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3145 | int rc = 1; |
| 3146 | unsigned long iflag; |
| 3147 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3148 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3149 | if (cmdiocbp) { |
| 3150 | if (cmdiocbp->iocb_cmpl) { |
| 3151 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3152 | * If an ELS command failed send an event to mgmt |
| 3153 | * application. |
| 3154 | */ |
| 3155 | if (saveq->iocb.ulpStatus && |
| 3156 | (pring->ringno == LPFC_ELS_RING) && |
| 3157 | (cmdiocbp->iocb.ulpCommand == |
| 3158 | CMD_ELS_REQUEST64_CR)) |
| 3159 | lpfc_send_els_failure_event(phba, |
| 3160 | cmdiocbp, saveq); |
| 3161 | |
| 3162 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3163 | * Post all ELS completions to the worker thread. |
| 3164 | * All other are passed to the completion callback. |
| 3165 | */ |
| 3166 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3167 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3168 | (cmdiocbp->iocb_flag & |
| 3169 | LPFC_DRIVER_ABORTED)) { |
| 3170 | spin_lock_irqsave(&phba->hbalock, |
| 3171 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3172 | cmdiocbp->iocb_flag &= |
| 3173 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3174 | spin_unlock_irqrestore(&phba->hbalock, |
| 3175 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3176 | saveq->iocb.ulpStatus = |
| 3177 | IOSTAT_LOCAL_REJECT; |
| 3178 | saveq->iocb.un.ulpWord[4] = |
| 3179 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3180 | |
| 3181 | /* Firmware could still be in progress |
| 3182 | * of DMAing payload, so don't free data |
| 3183 | * buffer till after a hbeat. |
| 3184 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3185 | spin_lock_irqsave(&phba->hbalock, |
| 3186 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3187 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3188 | spin_unlock_irqrestore(&phba->hbalock, |
| 3189 | iflag); |
| 3190 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3191 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3192 | if (saveq->iocb_flag & |
| 3193 | LPFC_EXCHANGE_BUSY) { |
| 3194 | /* Set cmdiocb flag for the |
| 3195 | * exchange busy so sgl (xri) |
| 3196 | * will not be released until |
| 3197 | * the abort xri is received |
| 3198 | * from hba. |
| 3199 | */ |
| 3200 | spin_lock_irqsave( |
| 3201 | &phba->hbalock, iflag); |
| 3202 | cmdiocbp->iocb_flag |= |
| 3203 | LPFC_EXCHANGE_BUSY; |
| 3204 | spin_unlock_irqrestore( |
| 3205 | &phba->hbalock, iflag); |
| 3206 | } |
| 3207 | if (cmdiocbp->iocb_flag & |
| 3208 | LPFC_DRIVER_ABORTED) { |
| 3209 | /* |
| 3210 | * Clear LPFC_DRIVER_ABORTED |
| 3211 | * bit in case it was driver |
| 3212 | * initiated abort. |
| 3213 | */ |
| 3214 | spin_lock_irqsave( |
| 3215 | &phba->hbalock, iflag); |
| 3216 | cmdiocbp->iocb_flag &= |
| 3217 | ~LPFC_DRIVER_ABORTED; |
| 3218 | spin_unlock_irqrestore( |
| 3219 | &phba->hbalock, iflag); |
| 3220 | cmdiocbp->iocb.ulpStatus = |
| 3221 | IOSTAT_LOCAL_REJECT; |
| 3222 | cmdiocbp->iocb.un.ulpWord[4] = |
| 3223 | IOERR_ABORT_REQUESTED; |
| 3224 | /* |
| 3225 | * For SLI4, irsiocb contains |
| 3226 | * NO_XRI in sli_xritag, it |
| 3227 | * shall not affect releasing |
| 3228 | * sgl (xri) process. |
| 3229 | */ |
| 3230 | saveq->iocb.ulpStatus = |
| 3231 | IOSTAT_LOCAL_REJECT; |
| 3232 | saveq->iocb.un.ulpWord[4] = |
| 3233 | IOERR_SLI_ABORTED; |
| 3234 | spin_lock_irqsave( |
| 3235 | &phba->hbalock, iflag); |
| 3236 | saveq->iocb_flag |= |
| 3237 | LPFC_DELAY_MEM_FREE; |
| 3238 | spin_unlock_irqrestore( |
| 3239 | &phba->hbalock, iflag); |
| 3240 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3241 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3242 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3243 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3244 | } else |
| 3245 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3246 | } else { |
| 3247 | /* |
| 3248 | * Unknown initiating command based on the response iotag. |
| 3249 | * This could be the case on the ELS ring because of |
| 3250 | * lpfc_els_abort(). |
| 3251 | */ |
| 3252 | if (pring->ringno != LPFC_ELS_RING) { |
| 3253 | /* |
| 3254 | * Ring <ringno> handler: unexpected completion IoTag |
| 3255 | * <IoTag> |
| 3256 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3257 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3258 | "0322 Ring %d handler: " |
| 3259 | "unexpected completion IoTag x%x " |
| 3260 | "Data: x%x x%x x%x x%x\n", |
| 3261 | pring->ringno, |
| 3262 | saveq->iocb.ulpIoTag, |
| 3263 | saveq->iocb.ulpStatus, |
| 3264 | saveq->iocb.un.ulpWord[4], |
| 3265 | saveq->iocb.ulpCommand, |
| 3266 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3267 | } |
| 3268 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3269 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3270 | return rc; |
| 3271 | } |
| 3272 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3273 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3274 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3275 | * @phba: Pointer to HBA context object. |
| 3276 | * @pring: Pointer to driver SLI ring object. |
| 3277 | * |
| 3278 | * This function is called from the iocb ring event handlers when |
| 3279 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 3280 | * an error attention condition to the worker thread and the worker |
| 3281 | * thread will transition the HBA to offline state. |
| 3282 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3283 | static void |
| 3284 | 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] | 3285 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3286 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3287 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3288 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3289 | * rsp ring <portRspMax> |
| 3290 | */ |
| 3291 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3292 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3293 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3294 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3295 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3296 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3297 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3298 | |
| 3299 | /* |
| 3300 | * All error attention handlers are posted to |
| 3301 | * worker thread |
| 3302 | */ |
| 3303 | phba->work_ha |= HA_ERATT; |
| 3304 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3305 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3306 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3307 | |
| 3308 | return; |
| 3309 | } |
| 3310 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3311 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3312 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3313 | * @ptr: Pointer to address of HBA context object. |
| 3314 | * |
| 3315 | * This function is invoked by the Error Attention polling timer when the |
| 3316 | * timer times out. It will check the SLI Error Attention register for |
| 3317 | * possible attention events. If so, it will post an Error Attention event |
| 3318 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 3319 | * Error Attention polling timer for the next poll. |
| 3320 | **/ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3321 | void lpfc_poll_eratt(struct timer_list *t) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3322 | { |
| 3323 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3324 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3325 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3326 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3327 | phba = from_timer(phba, t, eratt_poll); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3328 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3329 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 3330 | sli_intr = phba->sli.slistat.sli_intr; |
| 3331 | |
| 3332 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 3333 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 3334 | sli_intr); |
| 3335 | else |
| 3336 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 3337 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3338 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 3339 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3340 | phba->sli.slistat.sli_ips = cnt; |
| 3341 | |
| 3342 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 3343 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3344 | /* Check chip HA register for error event */ |
| 3345 | eratt = lpfc_sli_check_eratt(phba); |
| 3346 | |
| 3347 | if (eratt) |
| 3348 | /* Tell the worker thread there is work to do */ |
| 3349 | lpfc_worker_wake_up(phba); |
| 3350 | else |
| 3351 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3352 | mod_timer(&phba->eratt_poll, |
| 3353 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3354 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3355 | return; |
| 3356 | } |
| 3357 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3358 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3359 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3360 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3361 | * @phba: Pointer to HBA context object. |
| 3362 | * @pring: Pointer to driver SLI ring object. |
| 3363 | * @mask: Host attention register mask for this ring. |
| 3364 | * |
| 3365 | * This function is called from the interrupt context when there is a ring |
| 3366 | * event for the fcp ring. The caller does not hold any lock. |
| 3367 | * 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] | 3368 | * 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] | 3369 | * LE bit set. The function will call the completion handler of the command iocb |
| 3370 | * if the response iocb indicates a completion for a command iocb or it is |
| 3371 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 3372 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3373 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3374 | * to check it explicitly. |
| 3375 | */ |
| 3376 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3377 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 3378 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3379 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3380 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3382 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3383 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 3384 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3385 | uint32_t status; |
| 3386 | uint32_t portRspPut, portRspMax; |
| 3387 | int rc = 1; |
| 3388 | lpfc_iocb_type type; |
| 3389 | unsigned long iflag; |
| 3390 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3391 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3392 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3393 | pring->stats.iocb_event++; |
| 3394 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3395 | /* |
| 3396 | * The next available response entry should never exceed the maximum |
| 3397 | * entries. If it does, treat it as an adapter hardware error. |
| 3398 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3399 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3400 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3401 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3402 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3403 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3404 | return 1; |
| 3405 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3406 | if (phba->fcp_ring_in_use) { |
| 3407 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3408 | return 1; |
| 3409 | } else |
| 3410 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3411 | |
| 3412 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3413 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3414 | /* |
| 3415 | * Fetch an entry off the ring and copy it into a local data |
| 3416 | * structure. The copy involves a byte-swap since the |
| 3417 | * network byte order and pci byte orders are different. |
| 3418 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3419 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3420 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3421 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3422 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3423 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3424 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3425 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3426 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3427 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3428 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3429 | irsp = &rspiocbq.iocb; |
| 3430 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3431 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3432 | pring->stats.iocb_rsp++; |
| 3433 | rsp_cmpl++; |
| 3434 | |
| 3435 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3436 | /* |
| 3437 | * If resource errors reported from HBA, reduce |
| 3438 | * queuedepths of the SCSI device. |
| 3439 | */ |
| 3440 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3441 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3442 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3443 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3444 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3445 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3446 | } |
| 3447 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3448 | /* Rsp ring <ringno> error: IOCB */ |
| 3449 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3450 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3451 | "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] | 3452 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3453 | irsp->un.ulpWord[0], |
| 3454 | irsp->un.ulpWord[1], |
| 3455 | irsp->un.ulpWord[2], |
| 3456 | irsp->un.ulpWord[3], |
| 3457 | irsp->un.ulpWord[4], |
| 3458 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3459 | *(uint32_t *)&irsp->un1, |
| 3460 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3461 | } |
| 3462 | |
| 3463 | switch (type) { |
| 3464 | case LPFC_ABORT_IOCB: |
| 3465 | case LPFC_SOL_IOCB: |
| 3466 | /* |
| 3467 | * Idle exchange closed via ABTS from port. No iocb |
| 3468 | * resources need to be recovered. |
| 3469 | */ |
| 3470 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3471 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3472 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3473 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3474 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3475 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3476 | break; |
| 3477 | } |
| 3478 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3479 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3480 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3481 | &rspiocbq); |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3482 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3483 | if (unlikely(!cmdiocbq)) |
| 3484 | break; |
| 3485 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3486 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3487 | if (cmdiocbq->iocb_cmpl) { |
| 3488 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3489 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3490 | &rspiocbq); |
| 3491 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3492 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3493 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3494 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3495 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3496 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3497 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3498 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3499 | default: |
| 3500 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3501 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3502 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3503 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3504 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3505 | dev_warn(&((phba->pcidev)->dev), |
| 3506 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3507 | phba->brd_no, adaptermsg); |
| 3508 | } else { |
| 3509 | /* Unknown IOCB command */ |
| 3510 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3511 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3512 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3513 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3514 | irsp->ulpStatus, |
| 3515 | irsp->ulpIoTag, |
| 3516 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3517 | } |
| 3518 | break; |
| 3519 | } |
| 3520 | |
| 3521 | /* |
| 3522 | * The response IOCB has been processed. Update the ring |
| 3523 | * pointer in SLIM. If the port response put pointer has not |
| 3524 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3525 | * response put pointer. |
| 3526 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3527 | writel(pring->sli.sli3.rspidx, |
| 3528 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3529 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3530 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3531 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3532 | } |
| 3533 | |
| 3534 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3535 | pring->stats.iocb_rsp_full++; |
| 3536 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3537 | writel(status, phba->CAregaddr); |
| 3538 | readl(phba->CAregaddr); |
| 3539 | } |
| 3540 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3541 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3542 | pring->stats.iocb_cmd_empty++; |
| 3543 | |
| 3544 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3545 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3546 | lpfc_sli_resume_iocb(phba, pring); |
| 3547 | |
| 3548 | if ((pring->lpfc_sli_cmd_available)) |
| 3549 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3550 | |
| 3551 | } |
| 3552 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3553 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3554 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3555 | return rc; |
| 3556 | } |
| 3557 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3558 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3559 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3560 | * @phba: Pointer to HBA context object. |
| 3561 | * @pring: Pointer to driver SLI ring object. |
| 3562 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3563 | * |
| 3564 | * This function is called from the worker thread when there is a slow-path |
| 3565 | * response IOCB to process. This function chains all the response iocbs until |
| 3566 | * seeing the iocb with the LE bit set. The function will call |
| 3567 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3568 | * completion of a command iocb. The function will call the |
| 3569 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3570 | * The function frees the resources or calls the completion handler if this |
| 3571 | * iocb is an abort completion. The function returns NULL when the response |
| 3572 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3573 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3574 | * response iocb passed in. |
| 3575 | **/ |
| 3576 | static struct lpfc_iocbq * |
| 3577 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3578 | struct lpfc_iocbq *rspiocbp) |
| 3579 | { |
| 3580 | struct lpfc_iocbq *saveq; |
| 3581 | struct lpfc_iocbq *cmdiocbp; |
| 3582 | struct lpfc_iocbq *next_iocb; |
| 3583 | IOCB_t *irsp = NULL; |
| 3584 | uint32_t free_saveq; |
| 3585 | uint8_t iocb_cmd_type; |
| 3586 | lpfc_iocb_type type; |
| 3587 | unsigned long iflag; |
| 3588 | int rc; |
| 3589 | |
| 3590 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3591 | /* First add the response iocb to the countinueq list */ |
| 3592 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3593 | pring->iocb_continueq_cnt++; |
| 3594 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3595 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3596 | irsp = &rspiocbp->iocb; |
| 3597 | if (irsp->ulpLe) { |
| 3598 | /* |
| 3599 | * By default, the driver expects to free all resources |
| 3600 | * associated with this iocb completion. |
| 3601 | */ |
| 3602 | free_saveq = 1; |
| 3603 | saveq = list_get_first(&pring->iocb_continueq, |
| 3604 | struct lpfc_iocbq, list); |
| 3605 | irsp = &(saveq->iocb); |
| 3606 | list_del_init(&pring->iocb_continueq); |
| 3607 | pring->iocb_continueq_cnt = 0; |
| 3608 | |
| 3609 | pring->stats.iocb_rsp++; |
| 3610 | |
| 3611 | /* |
| 3612 | * If resource errors reported from HBA, reduce |
| 3613 | * queuedepths of the SCSI device. |
| 3614 | */ |
| 3615 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3616 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3617 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3618 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3619 | phba->lpfc_rampdown_queue_depth(phba); |
| 3620 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3621 | } |
| 3622 | |
| 3623 | if (irsp->ulpStatus) { |
| 3624 | /* Rsp ring <ringno> error: IOCB */ |
| 3625 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3626 | "0328 Rsp Ring %d error: " |
| 3627 | "IOCB Data: " |
| 3628 | "x%x x%x x%x x%x " |
| 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\n", |
| 3632 | pring->ringno, |
| 3633 | irsp->un.ulpWord[0], |
| 3634 | irsp->un.ulpWord[1], |
| 3635 | irsp->un.ulpWord[2], |
| 3636 | irsp->un.ulpWord[3], |
| 3637 | irsp->un.ulpWord[4], |
| 3638 | irsp->un.ulpWord[5], |
| 3639 | *(((uint32_t *) irsp) + 6), |
| 3640 | *(((uint32_t *) irsp) + 7), |
| 3641 | *(((uint32_t *) irsp) + 8), |
| 3642 | *(((uint32_t *) irsp) + 9), |
| 3643 | *(((uint32_t *) irsp) + 10), |
| 3644 | *(((uint32_t *) irsp) + 11), |
| 3645 | *(((uint32_t *) irsp) + 12), |
| 3646 | *(((uint32_t *) irsp) + 13), |
| 3647 | *(((uint32_t *) irsp) + 14), |
| 3648 | *(((uint32_t *) irsp) + 15)); |
| 3649 | } |
| 3650 | |
| 3651 | /* |
| 3652 | * Fetch the IOCB command type and call the correct completion |
| 3653 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3654 | * get freed back to the lpfc_iocb_list by the discovery |
| 3655 | * kernel thread. |
| 3656 | */ |
| 3657 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3658 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3659 | switch (type) { |
| 3660 | case LPFC_SOL_IOCB: |
| 3661 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3662 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3663 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3664 | break; |
| 3665 | |
| 3666 | case LPFC_UNSOL_IOCB: |
| 3667 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3668 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3669 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3670 | if (!rc) |
| 3671 | free_saveq = 0; |
| 3672 | break; |
| 3673 | |
| 3674 | case LPFC_ABORT_IOCB: |
| 3675 | cmdiocbp = NULL; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3676 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) { |
| 3677 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3678 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3679 | saveq); |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 3680 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3681 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3682 | if (cmdiocbp) { |
| 3683 | /* Call the specified completion routine */ |
| 3684 | if (cmdiocbp->iocb_cmpl) { |
| 3685 | spin_unlock_irqrestore(&phba->hbalock, |
| 3686 | iflag); |
| 3687 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3688 | saveq); |
| 3689 | spin_lock_irqsave(&phba->hbalock, |
| 3690 | iflag); |
| 3691 | } else |
| 3692 | __lpfc_sli_release_iocbq(phba, |
| 3693 | cmdiocbp); |
| 3694 | } |
| 3695 | break; |
| 3696 | |
| 3697 | case LPFC_UNKNOWN_IOCB: |
| 3698 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3699 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3700 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3701 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3702 | MAX_MSG_DATA); |
| 3703 | dev_warn(&((phba->pcidev)->dev), |
| 3704 | "lpfc%d: %s\n", |
| 3705 | phba->brd_no, adaptermsg); |
| 3706 | } else { |
| 3707 | /* Unknown IOCB command */ |
| 3708 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3709 | "0335 Unknown IOCB " |
| 3710 | "command Data: x%x " |
| 3711 | "x%x x%x x%x\n", |
| 3712 | irsp->ulpCommand, |
| 3713 | irsp->ulpStatus, |
| 3714 | irsp->ulpIoTag, |
| 3715 | irsp->ulpContext); |
| 3716 | } |
| 3717 | break; |
| 3718 | } |
| 3719 | |
| 3720 | if (free_saveq) { |
| 3721 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3722 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3723 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3724 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3725 | } |
| 3726 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3727 | } |
| 3728 | rspiocbp = NULL; |
| 3729 | } |
| 3730 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3731 | return rspiocbp; |
| 3732 | } |
| 3733 | |
| 3734 | /** |
| 3735 | * 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] | 3736 | * @phba: Pointer to HBA context object. |
| 3737 | * @pring: Pointer to driver SLI ring object. |
| 3738 | * @mask: Host attention register mask for this ring. |
| 3739 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3740 | * This routine wraps the actual slow_ring event process routine from the |
| 3741 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3742 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3743 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3744 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3745 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3746 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3747 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3748 | } |
| 3749 | |
| 3750 | /** |
| 3751 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3752 | * @phba: Pointer to HBA context object. |
| 3753 | * @pring: Pointer to driver SLI ring object. |
| 3754 | * @mask: Host attention register mask for this ring. |
| 3755 | * |
| 3756 | * This function is called from the worker thread when there is a ring event |
| 3757 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3758 | * remove each response iocb in the response ring and calls the handle |
| 3759 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3760 | **/ |
| 3761 | static void |
| 3762 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3763 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3764 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3765 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3766 | IOCB_t *entry; |
| 3767 | IOCB_t *irsp = NULL; |
| 3768 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3769 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3770 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3771 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3772 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3773 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3774 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3775 | pring->stats.iocb_event++; |
| 3776 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3777 | /* |
| 3778 | * The next available response entry should never exceed the maximum |
| 3779 | * entries. If it does, treat it as an adapter hardware error. |
| 3780 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3781 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3782 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3783 | if (portRspPut >= portRspMax) { |
| 3784 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3785 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3786 | * rsp ring <portRspMax> |
| 3787 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3788 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3789 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3790 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3791 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3792 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3793 | phba->link_state = LPFC_HBA_ERROR; |
| 3794 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3795 | |
| 3796 | phba->work_hs = HS_FFER3; |
| 3797 | lpfc_handle_eratt(phba); |
| 3798 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3799 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3803 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | /* |
| 3805 | * Build a completion list and call the appropriate handler. |
| 3806 | * The process is to get the next available response iocb, get |
| 3807 | * a free iocb from the list, copy the response data into the |
| 3808 | * free iocb, insert to the continuation list, and update the |
| 3809 | * next response index to slim. This process makes response |
| 3810 | * iocb's in the ring available to DMA as fast as possible but |
| 3811 | * pays a penalty for a copy operation. Since the iocb is |
| 3812 | * only 32 bytes, this penalty is considered small relative to |
| 3813 | * the PCI reads for register values and a slim write. When |
| 3814 | * the ulpLe field is set, the entire Command has been |
| 3815 | * received. |
| 3816 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3817 | entry = lpfc_resp_iocb(phba, pring); |
| 3818 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3819 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3820 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3821 | if (rspiocbp == NULL) { |
| 3822 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3823 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3824 | break; |
| 3825 | } |
| 3826 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3827 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3828 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3829 | irsp = &rspiocbp->iocb; |
| 3830 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3831 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3832 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3833 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3834 | if (pring->ringno == LPFC_ELS_RING) { |
| 3835 | lpfc_debugfs_slow_ring_trc(phba, |
| 3836 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3837 | *(((uint32_t *) irsp) + 4), |
| 3838 | *(((uint32_t *) irsp) + 6), |
| 3839 | *(((uint32_t *) irsp) + 7)); |
| 3840 | } |
| 3841 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3842 | writel(pring->sli.sli3.rspidx, |
| 3843 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3844 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3845 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3846 | /* Handle the response IOCB */ |
| 3847 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3848 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | |
| 3850 | /* |
| 3851 | * If the port response put pointer has not been updated, sync |
| 3852 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3853 | * response put pointer. |
| 3854 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3855 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3856 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3857 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3858 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3859 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3860 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3861 | /* At least one response entry has been freed */ |
| 3862 | pring->stats.iocb_rsp_full++; |
| 3863 | /* SET RxRE_RSP in Chip Att register */ |
| 3864 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3865 | writel(status, phba->CAregaddr); |
| 3866 | readl(phba->CAregaddr); /* flush */ |
| 3867 | } |
| 3868 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3869 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3870 | pring->stats.iocb_cmd_empty++; |
| 3871 | |
| 3872 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3873 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3874 | lpfc_sli_resume_iocb(phba, pring); |
| 3875 | |
| 3876 | if ((pring->lpfc_sli_cmd_available)) |
| 3877 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3878 | |
| 3879 | } |
| 3880 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3881 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3882 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3883 | } |
| 3884 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3885 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3886 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3887 | * @phba: Pointer to HBA context object. |
| 3888 | * @pring: Pointer to driver SLI ring object. |
| 3889 | * @mask: Host attention register mask for this ring. |
| 3890 | * |
| 3891 | * This function is called from the worker thread when there is a pending |
| 3892 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3893 | * queue. The caller does not hold any lock. The function will remove each |
| 3894 | * response iocb from the response worker queue and calls the handle |
| 3895 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3896 | **/ |
| 3897 | static void |
| 3898 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3899 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3900 | { |
| 3901 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3902 | struct hbq_dmabuf *dmabuf; |
| 3903 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3904 | unsigned long iflag; |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3905 | int count = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3906 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3907 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3908 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3909 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3910 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3911 | /* Get the response iocb from the head of work queue */ |
| 3912 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3913 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3914 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3915 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3916 | |
| 3917 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3918 | case CQE_CODE_COMPL_WQE: |
| 3919 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3920 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3921 | /* Translate ELS WCQE to response IOCBQ */ |
| 3922 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3923 | irspiocbq); |
| 3924 | if (irspiocbq) |
| 3925 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3926 | irspiocbq); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3927 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3928 | break; |
| 3929 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3930 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3931 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3932 | cq_event); |
| 3933 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3934 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3935 | break; |
| 3936 | default: |
| 3937 | break; |
| 3938 | } |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3939 | |
| 3940 | /* Limit the number of events to 64 to avoid soft lockups */ |
| 3941 | if (count == 64) |
| 3942 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3943 | } |
| 3944 | } |
| 3945 | |
| 3946 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3947 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3948 | * @phba: Pointer to HBA context object. |
| 3949 | * @pring: Pointer to driver SLI ring object. |
| 3950 | * |
| 3951 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3952 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3953 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3954 | * the return of this function. The caller is not required to hold any locks. |
| 3955 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3956 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3957 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3958 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3959 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3960 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3961 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3962 | if (pring->ringno == LPFC_ELS_RING) { |
| 3963 | lpfc_fabric_abort_hba(phba); |
| 3964 | } |
| 3965 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3966 | /* Error everything on txq and txcmplq |
| 3967 | * First do the txq. |
| 3968 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3969 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3970 | spin_lock_irq(&pring->ring_lock); |
| 3971 | list_splice_init(&pring->txq, &completions); |
| 3972 | pring->txq_cnt = 0; |
| 3973 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3974 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3975 | spin_lock_irq(&phba->hbalock); |
| 3976 | /* Next issue ABTS for everything on the txcmplq */ |
| 3977 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3978 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3979 | spin_unlock_irq(&phba->hbalock); |
| 3980 | } else { |
| 3981 | spin_lock_irq(&phba->hbalock); |
| 3982 | list_splice_init(&pring->txq, &completions); |
| 3983 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3984 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3985 | /* Next issue ABTS for everything on the txcmplq */ |
| 3986 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3987 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3988 | spin_unlock_irq(&phba->hbalock); |
| 3989 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3990 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3991 | /* Cancel all the IOCBs from the completions list */ |
| 3992 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3993 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3994 | } |
| 3995 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3996 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3997 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 3998 | * @phba: Pointer to HBA context object. |
| 3999 | * @pring: Pointer to driver SLI ring object. |
| 4000 | * |
| 4001 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 4002 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 4003 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 4004 | * the return of this function. The caller is not required to hold any locks. |
| 4005 | **/ |
| 4006 | void |
| 4007 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 4008 | { |
| 4009 | struct lpfc_sli *psli = &phba->sli; |
| 4010 | struct lpfc_sli_ring *pring; |
| 4011 | uint32_t i; |
| 4012 | |
| 4013 | /* Look on all the FCP Rings for the iotag */ |
| 4014 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4015 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4016 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4017 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 4018 | } |
| 4019 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4020 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4021 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 4022 | } |
| 4023 | } |
| 4024 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4025 | /** |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4026 | * lpfc_sli_flush_io_rings - flush all iocbs in the IO ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4027 | * @phba: Pointer to HBA context object. |
| 4028 | * |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4029 | * 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] | 4030 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 4031 | * for all the iocb commands in txcmplq, they will just be returned with |
| 4032 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 4033 | * slot has been permanently disabled. |
| 4034 | **/ |
| 4035 | void |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4036 | lpfc_sli_flush_io_rings(struct lpfc_hba *phba) |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4037 | { |
| 4038 | LIST_HEAD(txq); |
| 4039 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4040 | struct lpfc_sli *psli = &phba->sli; |
| 4041 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4042 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4043 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4044 | |
| 4045 | spin_lock_irq(&phba->hbalock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4046 | /* Indicate the I/O queues are flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4047 | phba->hba_flag |= HBA_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4048 | spin_unlock_irq(&phba->hbalock); |
| 4049 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4050 | /* Look on all the FCP Rings for the iotag */ |
| 4051 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4052 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 4053 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4054 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4055 | spin_lock_irq(&pring->ring_lock); |
| 4056 | /* Retrieve everything on txq */ |
| 4057 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4058 | list_for_each_entry_safe(piocb, next_iocb, |
| 4059 | &pring->txcmplq, list) |
| 4060 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4061 | /* Retrieve everything on the txcmplq */ |
| 4062 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4063 | pring->txq_cnt = 0; |
| 4064 | pring->txcmplq_cnt = 0; |
| 4065 | spin_unlock_irq(&pring->ring_lock); |
| 4066 | |
| 4067 | /* Flush the txq */ |
| 4068 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 4069 | IOSTAT_LOCAL_REJECT, |
| 4070 | IOERR_SLI_DOWN); |
| 4071 | /* Flush the txcmpq */ |
| 4072 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4073 | IOSTAT_LOCAL_REJECT, |
| 4074 | IOERR_SLI_DOWN); |
| 4075 | } |
| 4076 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4077 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4078 | |
| 4079 | spin_lock_irq(&phba->hbalock); |
| 4080 | /* Retrieve everything on txq */ |
| 4081 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4082 | list_for_each_entry_safe(piocb, next_iocb, |
| 4083 | &pring->txcmplq, list) |
| 4084 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4085 | /* Retrieve everything on the txcmplq */ |
| 4086 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4087 | pring->txq_cnt = 0; |
| 4088 | pring->txcmplq_cnt = 0; |
| 4089 | spin_unlock_irq(&phba->hbalock); |
| 4090 | |
| 4091 | /* Flush the txq */ |
| 4092 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 4093 | IOERR_SLI_DOWN); |
| 4094 | /* Flush the txcmpq */ |
| 4095 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 4096 | IOERR_SLI_DOWN); |
| 4097 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4098 | } |
| 4099 | |
| 4100 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4101 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4102 | * @phba: Pointer to HBA context object. |
| 4103 | * @mask: Bit mask to be checked. |
| 4104 | * |
| 4105 | * This function reads the host status register and compares |
| 4106 | * with the provided bit mask to check if HBA completed |
| 4107 | * the restart. This function will wait in a loop for the |
| 4108 | * HBA to complete restart. If the HBA does not restart within |
| 4109 | * 15 iterations, the function will reset the HBA again. The |
| 4110 | * function returns 1 when HBA fail to restart otherwise returns |
| 4111 | * zero. |
| 4112 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4113 | static int |
| 4114 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4115 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4116 | uint32_t status; |
| 4117 | int i = 0; |
| 4118 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4119 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4120 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4121 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4122 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4123 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4124 | /* |
| 4125 | * Check status register every 100ms for 5 retries, then every |
| 4126 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 4127 | * every 2.5 sec for 4. |
| 4128 | * Break our of the loop if errors occurred during init. |
| 4129 | */ |
| 4130 | while (((status & mask) != mask) && |
| 4131 | !(status & HS_FFERM) && |
| 4132 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4133 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4134 | if (i <= 5) |
| 4135 | msleep(10); |
| 4136 | else if (i <= 10) |
| 4137 | msleep(500); |
| 4138 | else |
| 4139 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4140 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4141 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4142 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4143 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4144 | lpfc_sli_brdrestart(phba); |
| 4145 | } |
| 4146 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4147 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 4148 | retval = 1; |
| 4149 | break; |
| 4150 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4151 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4152 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4153 | /* Check to see if any errors occurred during init */ |
| 4154 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4155 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4156 | "2751 Adapter failed to restart, " |
| 4157 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 4158 | status, |
| 4159 | readl(phba->MBslimaddr + 0xa8), |
| 4160 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4161 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4162 | retval = 1; |
| 4163 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4164 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4165 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4166 | } |
| 4167 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4168 | /** |
| 4169 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 4170 | * @phba: Pointer to HBA context object. |
| 4171 | * @mask: Bit mask to be checked. |
| 4172 | * |
| 4173 | * This function checks the host status register to check if HBA is |
| 4174 | * ready. This function will wait in a loop for the HBA to be ready |
| 4175 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 4176 | * function again. The function returns 1 when HBA fail to be ready |
| 4177 | * otherwise returns zero. |
| 4178 | **/ |
| 4179 | static int |
| 4180 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 4181 | { |
| 4182 | uint32_t status; |
| 4183 | int retval = 0; |
| 4184 | |
| 4185 | /* Read the HBA Host Status Register */ |
| 4186 | status = lpfc_sli4_post_status_check(phba); |
| 4187 | |
| 4188 | if (status) { |
| 4189 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 4190 | lpfc_sli_brdrestart(phba); |
| 4191 | status = lpfc_sli4_post_status_check(phba); |
| 4192 | } |
| 4193 | |
| 4194 | /* Check to see if any errors occurred during init */ |
| 4195 | if (status) { |
| 4196 | phba->link_state = LPFC_HBA_ERROR; |
| 4197 | retval = 1; |
| 4198 | } else |
| 4199 | phba->sli4_hba.intr_enable = 0; |
| 4200 | |
| 4201 | return retval; |
| 4202 | } |
| 4203 | |
| 4204 | /** |
| 4205 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 4206 | * @phba: Pointer to HBA context object. |
| 4207 | * @mask: Bit mask to be checked. |
| 4208 | * |
| 4209 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 4210 | * from the API jump table function pointer from the lpfc_hba struct. |
| 4211 | **/ |
| 4212 | int |
| 4213 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 4214 | { |
| 4215 | return phba->lpfc_sli_brdready(phba, mask); |
| 4216 | } |
| 4217 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4218 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 4219 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4220 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4221 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4222 | * @phba: Pointer to HBA context object. |
| 4223 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 4224 | * This function is called before resetting an HBA. This function is called |
| 4225 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4226 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4227 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4228 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4229 | uint32_t __iomem *resp_buf; |
| 4230 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4231 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4232 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4233 | int i; |
| 4234 | uint8_t hdrtype; |
| 4235 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 4236 | lockdep_assert_held(&phba->hbalock); |
| 4237 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4238 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 4239 | if (hdrtype != 0x80 || |
| 4240 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 4241 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 4242 | return; |
| 4243 | |
| 4244 | /* |
| 4245 | * Tell the other part of the chip to suspend temporarily all |
| 4246 | * its DMA activity. |
| 4247 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4248 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4249 | |
| 4250 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4251 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 4252 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4253 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 4254 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4255 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4256 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4257 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4258 | return; |
| 4259 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4260 | /* Clear Chip error bit */ |
| 4261 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4262 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | mbox = 0; |
| 4266 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 4267 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 4268 | |
| 4269 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4270 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4271 | writel(mbox, mbox_buf); |
| 4272 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4273 | for (i = 0; i < 50; i++) { |
| 4274 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4275 | return; |
| 4276 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 4277 | mdelay(1); |
| 4278 | else |
| 4279 | break; |
| 4280 | } |
| 4281 | resp_data = 0; |
| 4282 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4283 | return; |
| 4284 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4285 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4286 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4287 | goto restore_hc; |
| 4288 | else |
| 4289 | goto clear_errat; |
| 4290 | } |
| 4291 | |
| 4292 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4293 | resp_data = 0; |
| 4294 | for (i = 0; i < 500; i++) { |
| 4295 | if (lpfc_readl(resp_buf, &resp_data)) |
| 4296 | return; |
| 4297 | if (resp_data != mbox) |
| 4298 | mdelay(1); |
| 4299 | else |
| 4300 | break; |
| 4301 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4302 | |
| 4303 | clear_errat: |
| 4304 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4305 | while (++i < 500) { |
| 4306 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4307 | return; |
| 4308 | if (!(ha_copy & HA_ERATT)) |
| 4309 | mdelay(1); |
| 4310 | else |
| 4311 | break; |
| 4312 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4313 | |
| 4314 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 4315 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4316 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4320 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4321 | writel(hc_copy, phba->HCregaddr); |
| 4322 | readl(phba->HCregaddr); /* flush */ |
| 4323 | } |
| 4324 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4325 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4326 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4327 | * @phba: Pointer to HBA context object. |
| 4328 | * |
| 4329 | * This function issues a kill_board mailbox command and waits for |
| 4330 | * the error attention interrupt. This function is called for stopping |
| 4331 | * the firmware processing. The caller is not required to hold any |
| 4332 | * locks. This function calls lpfc_hba_down_post function to free |
| 4333 | * any pending commands after the kill. The function will return 1 when it |
| 4334 | * fails to kill the board else will return 0. |
| 4335 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4336 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4337 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4338 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4339 | struct lpfc_sli *psli; |
| 4340 | LPFC_MBOXQ_t *pmb; |
| 4341 | uint32_t status; |
| 4342 | uint32_t ha_copy; |
| 4343 | int retval; |
| 4344 | int i = 0; |
| 4345 | |
| 4346 | psli = &phba->sli; |
| 4347 | |
| 4348 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4349 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4350 | "0329 Kill HBA Data: x%x x%x\n", |
| 4351 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4352 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4353 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4354 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4355 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4356 | |
| 4357 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4358 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4359 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 4360 | spin_unlock_irq(&phba->hbalock); |
| 4361 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4362 | return 1; |
| 4363 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4364 | status &= ~HC_ERINT_ENA; |
| 4365 | writel(status, phba->HCregaddr); |
| 4366 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4367 | phba->link_flag |= LS_IGNORE_ERATT; |
| 4368 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4369 | |
| 4370 | lpfc_kill_board(phba, pmb); |
| 4371 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4372 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4373 | |
| 4374 | if (retval != MBX_SUCCESS) { |
| 4375 | if (retval != MBX_BUSY) |
| 4376 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4377 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4378 | "2752 KILL_BOARD command failed retval %d\n", |
| 4379 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4380 | spin_lock_irq(&phba->hbalock); |
| 4381 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4382 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4383 | return 1; |
| 4384 | } |
| 4385 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4386 | spin_lock_irq(&phba->hbalock); |
| 4387 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 4388 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4389 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4390 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4391 | |
| 4392 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 4393 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 4394 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 4395 | * board is now undefined. |
| 4396 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4397 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4398 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4399 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 4400 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4401 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4402 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4403 | } |
| 4404 | |
| 4405 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4406 | if (ha_copy & HA_ERATT) { |
| 4407 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4408 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4409 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4410 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4411 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4412 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4413 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4414 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4415 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4416 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4417 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4418 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4419 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4420 | } |
| 4421 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4422 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4423 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4424 | * @phba: Pointer to HBA context object. |
| 4425 | * |
| 4426 | * This function resets the HBA by writing HC_INITFF to the control |
| 4427 | * register. After the HBA resets, this function resets all the iocb ring |
| 4428 | * indices. This function disables PCI layer parity checking during |
| 4429 | * the reset. |
| 4430 | * This function returns 0 always. |
| 4431 | * The caller is not required to hold any locks. |
| 4432 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4433 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4434 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4435 | { |
| 4436 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4437 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4438 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4439 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4440 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4441 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4442 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4443 | /* Reset HBA */ |
| 4444 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4445 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4446 | (phba->pport) ? phba->pport->port_state : 0, |
| 4447 | psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4448 | |
| 4449 | /* perform board reset */ |
| 4450 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4451 | phba->link_events = 0; |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4452 | if (phba->pport) { |
| 4453 | phba->pport->fc_myDID = 0; |
| 4454 | phba->pport->fc_prevDID = 0; |
| 4455 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4456 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4457 | /* Turn off parity checking and serr during the physical reset */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 4458 | if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) |
| 4459 | return -EIO; |
| 4460 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4461 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4462 | (cfg_value & |
| 4463 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4464 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4465 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4466 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4467 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4468 | writel(HC_INITFF, phba->HCregaddr); |
| 4469 | mdelay(1); |
| 4470 | readl(phba->HCregaddr); /* flush */ |
| 4471 | writel(0, phba->HCregaddr); |
| 4472 | readl(phba->HCregaddr); /* flush */ |
| 4473 | |
| 4474 | /* Restore PCI cmd register */ |
| 4475 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4476 | |
| 4477 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4478 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4479 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4480 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4481 | pring->sli.sli3.rspidx = 0; |
| 4482 | pring->sli.sli3.next_cmdidx = 0; |
| 4483 | pring->sli.sli3.local_getidx = 0; |
| 4484 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4485 | pring->missbufcnt = 0; |
| 4486 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4487 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4488 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4489 | return 0; |
| 4490 | } |
| 4491 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4492 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4493 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4494 | * @phba: Pointer to HBA context object. |
| 4495 | * |
| 4496 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4497 | * checking during resets the device. The caller is not required to hold |
| 4498 | * any locks. |
| 4499 | * |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 4500 | * This function returns 0 on success else returns negative error code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4501 | **/ |
| 4502 | int |
| 4503 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4504 | { |
| 4505 | struct lpfc_sli *psli = &phba->sli; |
| 4506 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4507 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4508 | |
| 4509 | /* Reset HBA */ |
| 4510 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4511 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4512 | phba->pport->port_state, psli->sli_flag, |
| 4513 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4514 | |
| 4515 | /* perform board reset */ |
| 4516 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4517 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4518 | phba->pport->fc_myDID = 0; |
| 4519 | phba->pport->fc_prevDID = 0; |
| 4520 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4521 | spin_lock_irq(&phba->hbalock); |
| 4522 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4523 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4524 | spin_unlock_irq(&phba->hbalock); |
| 4525 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4526 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4527 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4528 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4529 | return rc; |
| 4530 | } |
| 4531 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4532 | /* Now physically reset the device */ |
| 4533 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4534 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4535 | |
| 4536 | /* Turn off parity checking and serr during the physical reset */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 4537 | if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) { |
| 4538 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4539 | "3205 PCI read Config failed\n"); |
| 4540 | return -EIO; |
| 4541 | } |
| 4542 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4543 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4544 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4545 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4546 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4547 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4548 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4549 | /* Restore PCI cmd register */ |
| 4550 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4551 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4552 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4553 | } |
| 4554 | |
| 4555 | /** |
| 4556 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4557 | * @phba: Pointer to HBA context object. |
| 4558 | * |
| 4559 | * This function is called in the SLI initialization code path to |
| 4560 | * restart the HBA. The caller is not required to hold any lock. |
| 4561 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4562 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4563 | * function to free any pending commands. The function enables |
| 4564 | * POST only during the first initialization. The function returns zero. |
| 4565 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4566 | * command before the return of this function. |
| 4567 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4568 | static int |
| 4569 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4570 | { |
| 4571 | MAILBOX_t *mb; |
| 4572 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4573 | volatile uint32_t word0; |
| 4574 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4575 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4576 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4577 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4578 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4579 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4580 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4581 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4582 | psli = &phba->sli; |
| 4583 | |
| 4584 | /* Restart HBA */ |
| 4585 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4586 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4587 | (phba->pport) ? phba->pport->port_state : 0, |
| 4588 | psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4589 | |
| 4590 | word0 = 0; |
| 4591 | mb = (MAILBOX_t *) &word0; |
| 4592 | mb->mbxCommand = MBX_RESTART; |
| 4593 | mb->mbxHc = 1; |
| 4594 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4595 | lpfc_reset_barrier(phba); |
| 4596 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4597 | to_slim = phba->MBslimaddr; |
| 4598 | writel(*(uint32_t *) mb, to_slim); |
| 4599 | readl(to_slim); /* flush */ |
| 4600 | |
| 4601 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4602 | if (phba->pport && phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4603 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4604 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4605 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4606 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4607 | writel(*(uint32_t *) mb, to_slim); |
| 4608 | readl(to_slim); /* flush */ |
| 4609 | |
| 4610 | lpfc_sli_brdreset(phba); |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4611 | if (phba->pport) |
| 4612 | phba->pport->stopped = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4613 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4614 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4615 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4616 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4617 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4618 | psli->stats_start = ktime_get_seconds(); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4619 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4620 | /* Give the INITFF and Post time to settle. */ |
| 4621 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4622 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4623 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4624 | if (hba_aer_enabled) |
| 4625 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4626 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4627 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4628 | |
| 4629 | return 0; |
| 4630 | } |
| 4631 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4632 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4633 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4634 | * @phba: Pointer to HBA context object. |
| 4635 | * |
| 4636 | * This function is called in the SLI initialization code path to restart |
| 4637 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4638 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4639 | * free any pending commands. |
| 4640 | **/ |
| 4641 | static int |
| 4642 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4643 | { |
| 4644 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4645 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4646 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4647 | |
| 4648 | /* Restart HBA */ |
| 4649 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4650 | "0296 Restart HBA Data: x%x x%x\n", |
| 4651 | phba->pport->port_state, psli->sli_flag); |
| 4652 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4653 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4654 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4655 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4656 | rc = lpfc_sli4_brdreset(phba); |
James Smart | 4fb86a6 | 2019-09-03 14:54:41 -0700 | [diff] [blame] | 4657 | if (rc) { |
| 4658 | phba->link_state = LPFC_HBA_ERROR; |
| 4659 | goto hba_down_queue; |
| 4660 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4661 | |
| 4662 | spin_lock_irq(&phba->hbalock); |
| 4663 | phba->pport->stopped = 0; |
| 4664 | phba->link_state = LPFC_INIT_START; |
| 4665 | phba->hba_flag = 0; |
| 4666 | spin_unlock_irq(&phba->hbalock); |
| 4667 | |
| 4668 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4669 | psli->stats_start = ktime_get_seconds(); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4670 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4671 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4672 | if (hba_aer_enabled) |
| 4673 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4674 | |
James Smart | 4fb86a6 | 2019-09-03 14:54:41 -0700 | [diff] [blame] | 4675 | hba_down_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4676 | lpfc_hba_down_post(phba); |
James Smart | 569dbe8 | 2017-06-15 22:56:47 -0700 | [diff] [blame] | 4677 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4678 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4679 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4680 | } |
| 4681 | |
| 4682 | /** |
| 4683 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4684 | * @phba: Pointer to HBA context object. |
| 4685 | * |
| 4686 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4687 | * API jump table function pointer from the lpfc_hba struct. |
| 4688 | **/ |
| 4689 | int |
| 4690 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4691 | { |
| 4692 | return phba->lpfc_sli_brdrestart(phba); |
| 4693 | } |
| 4694 | |
| 4695 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4696 | * 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] | 4697 | * @phba: Pointer to HBA context object. |
| 4698 | * |
| 4699 | * This function is called after a HBA restart to wait for successful |
| 4700 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4701 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4702 | * iteration, the function will restart the HBA again. The function returns |
| 4703 | * zero if HBA successfully restarted else returns negative error code. |
| 4704 | **/ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4705 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4706 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4707 | { |
| 4708 | uint32_t status, i = 0; |
| 4709 | |
| 4710 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4711 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4712 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4713 | |
| 4714 | /* Check status register to see what current state is */ |
| 4715 | i = 0; |
| 4716 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4717 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4718 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4719 | * retries, then every 1 sec for 50 retires for a total of |
| 4720 | * ~60 seconds before reset the board again and check every |
| 4721 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4722 | * board ready is required by the Falcon FIPS zeroization |
| 4723 | * complete, and any reset the board in between shall cause |
| 4724 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4725 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4726 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4727 | /* Adapter failed to init, timeout, status reg |
| 4728 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4729 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4730 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4731 | "timeout, status reg x%x, " |
| 4732 | "FW Data: A8 x%x AC x%x\n", status, |
| 4733 | readl(phba->MBslimaddr + 0xa8), |
| 4734 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4735 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4736 | return -ETIMEDOUT; |
| 4737 | } |
| 4738 | |
| 4739 | /* Check to see if any errors occurred during init */ |
| 4740 | if (status & HS_FFERM) { |
| 4741 | /* ERROR: During chipset initialization */ |
| 4742 | /* Adapter failed to init, chipset, status reg |
| 4743 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4744 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4745 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4746 | "chipset, status reg x%x, " |
| 4747 | "FW Data: A8 x%x AC x%x\n", status, |
| 4748 | readl(phba->MBslimaddr + 0xa8), |
| 4749 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4750 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4751 | return -EIO; |
| 4752 | } |
| 4753 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4754 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4755 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4756 | else if (i <= 100) |
| 4757 | msleep(100); |
| 4758 | else |
| 4759 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4760 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4761 | if (i == 150) { |
| 4762 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4763 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4764 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4765 | } |
| 4766 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4767 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4768 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | /* Check to see if any errors occurred during init */ |
| 4772 | if (status & HS_FFERM) { |
| 4773 | /* ERROR: During chipset initialization */ |
| 4774 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4775 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4776 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4777 | "status reg x%x, " |
| 4778 | "FW Data: A8 x%x AC x%x\n", status, |
| 4779 | readl(phba->MBslimaddr + 0xa8), |
| 4780 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4781 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4782 | return -EIO; |
| 4783 | } |
| 4784 | |
| 4785 | /* Clear all interrupt enable conditions */ |
| 4786 | writel(0, phba->HCregaddr); |
| 4787 | readl(phba->HCregaddr); /* flush */ |
| 4788 | |
| 4789 | /* setup host attn register */ |
| 4790 | writel(0xffffffff, phba->HAregaddr); |
| 4791 | readl(phba->HAregaddr); /* flush */ |
| 4792 | return 0; |
| 4793 | } |
| 4794 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4795 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4796 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4797 | * |
| 4798 | * This function calculates and returns the number of HBQs required to be |
| 4799 | * configured. |
| 4800 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4801 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4802 | lpfc_sli_hbq_count(void) |
| 4803 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4804 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4805 | } |
| 4806 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4807 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4808 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4809 | * |
| 4810 | * This function adds the number of hbq entries in every HBQ to get |
| 4811 | * the total number of hbq entries required for the HBA and returns |
| 4812 | * the total count. |
| 4813 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4814 | static int |
| 4815 | lpfc_sli_hbq_entry_count(void) |
| 4816 | { |
| 4817 | int hbq_count = lpfc_sli_hbq_count(); |
| 4818 | int count = 0; |
| 4819 | int i; |
| 4820 | |
| 4821 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4822 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4823 | return count; |
| 4824 | } |
| 4825 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4826 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4827 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4828 | * |
| 4829 | * This function calculates amount of memory required for all hbq entries |
| 4830 | * to be configured and returns the total memory required. |
| 4831 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4832 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4833 | lpfc_sli_hbq_size(void) |
| 4834 | { |
| 4835 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4836 | } |
| 4837 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4838 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4839 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4840 | * @phba: Pointer to HBA context object. |
| 4841 | * |
| 4842 | * This function is called during the SLI initialization to configure |
| 4843 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4844 | * required to hold any locks. This function will return zero if successful |
| 4845 | * else it will return negative error code. |
| 4846 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4847 | static int |
| 4848 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4849 | { |
| 4850 | int hbq_count = lpfc_sli_hbq_count(); |
| 4851 | LPFC_MBOXQ_t *pmb; |
| 4852 | MAILBOX_t *pmbox; |
| 4853 | uint32_t hbqno; |
| 4854 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4855 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4856 | /* Get a Mailbox buffer to setup mailbox |
| 4857 | * commands for HBA initialization |
| 4858 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4859 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4860 | |
| 4861 | if (!pmb) |
| 4862 | return -ENOMEM; |
| 4863 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4864 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4865 | |
| 4866 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4867 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4868 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4869 | |
| 4870 | hbq_entry_index = 0; |
| 4871 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4872 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4873 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4874 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4875 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4876 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4877 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4878 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4879 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4880 | |
| 4881 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4882 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4883 | mbxStatus <status>, ring <num> */ |
| 4884 | |
| 4885 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4886 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4887 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4888 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4889 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4890 | pmbox->mbxStatus, hbqno); |
| 4891 | |
| 4892 | phba->link_state = LPFC_HBA_ERROR; |
| 4893 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4894 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4895 | } |
| 4896 | } |
| 4897 | phba->hbq_count = hbq_count; |
| 4898 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4899 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4900 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4901 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4902 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4903 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4904 | return 0; |
| 4905 | } |
| 4906 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4907 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4908 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4909 | * @phba: Pointer to HBA context object. |
| 4910 | * |
| 4911 | * This function is called during the SLI initialization to configure |
| 4912 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4913 | * required to hold any locks. This function will return zero if successful |
| 4914 | * else it will return negative error code. |
| 4915 | **/ |
| 4916 | static int |
| 4917 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4918 | { |
| 4919 | phba->hbq_in_use = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4920 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 4921 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4922 | phba->hbq_count = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4923 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4924 | /* Initially populate or replenish the HBQs */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4925 | return 0; |
| 4926 | } |
| 4927 | |
| 4928 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4929 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4930 | * @phba: Pointer to HBA context object. |
| 4931 | * @sli_mode: sli mode - 2/3 |
| 4932 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4933 | * This function is called by the sli initialization code path |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4934 | * to issue config_port mailbox command. This function restarts the |
| 4935 | * HBA firmware and issues a config_port mailbox command to configure |
| 4936 | * the SLI interface in the sli mode specified by sli_mode |
| 4937 | * variable. The caller is not required to hold any locks. |
| 4938 | * The function returns 0 if successful, else returns negative error |
| 4939 | * code. |
| 4940 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4941 | int |
| 4942 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4943 | { |
| 4944 | LPFC_MBOXQ_t *pmb; |
| 4945 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4946 | |
| 4947 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4948 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4949 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4950 | return -ENOMEM; |
| 4951 | } |
| 4952 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4953 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4954 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4955 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4956 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4957 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4958 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4959 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4960 | rc = lpfc_sli_chipset_init(phba); |
| 4961 | if (rc) |
| 4962 | break; |
| 4963 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4964 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4965 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4966 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4967 | resetcount++; |
| 4968 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4969 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4970 | * value of 0 means the call was successful. Any other |
| 4971 | * nonzero value is a failure, but if ERESTART is returned, |
| 4972 | * the driver may reset the HBA and try again. |
| 4973 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4974 | rc = lpfc_config_port_prep(phba); |
| 4975 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4976 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4977 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4978 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4979 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4980 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4981 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4982 | lpfc_config_port(phba, pmb); |
| 4983 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4984 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4985 | LPFC_SLI3_HBQ_ENABLED | |
| 4986 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4987 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4988 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4989 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4990 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4991 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4992 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4993 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4994 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4995 | spin_unlock_irq(&phba->hbalock); |
| 4996 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4997 | } else { |
| 4998 | /* Allow asynchronous mailbox command to go through */ |
| 4999 | spin_lock_irq(&phba->hbalock); |
| 5000 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 5001 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5002 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5003 | |
| 5004 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 5005 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 5006 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5007 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5008 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5009 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5010 | if (!done) { |
| 5011 | rc = -EINVAL; |
| 5012 | goto do_prep_failed; |
| 5013 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5014 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 5015 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5016 | rc = -ENXIO; |
| 5017 | goto do_prep_failed; |
| 5018 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5019 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5020 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5021 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 5022 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 5023 | phba->max_vpi : phba->max_vports; |
| 5024 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5025 | } else |
| 5026 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5027 | phba->fips_level = 0; |
| 5028 | phba->fips_spec_rev = 0; |
| 5029 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5030 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5031 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 5032 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 5033 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5034 | "2850 Security Crypto Active. FIPS x%d " |
| 5035 | "(Spec Rev: x%d)", |
| 5036 | phba->fips_level, phba->fips_spec_rev); |
| 5037 | } |
| 5038 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 5039 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5040 | "2856 Config Port Security Crypto " |
| 5041 | "Error: x%x ", |
| 5042 | pmb->u.mb.un.varCfgPort.sec_err); |
| 5043 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5044 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5045 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5046 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5047 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 5048 | |
| 5049 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 5050 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5051 | |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5052 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 5053 | if (pmb->u.mb.un.varCfgPort.gbg == 0) { |
| 5054 | phba->cfg_enable_bg = 0; |
| 5055 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5056 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5057 | "0443 Adapter did not grant " |
| 5058 | "BlockGuard\n"); |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5059 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5060 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5061 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 5062 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5063 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5064 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5065 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5066 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5067 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5068 | return rc; |
| 5069 | } |
| 5070 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5071 | |
| 5072 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5073 | * lpfc_sli_hba_setup - SLI initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5074 | * @phba: Pointer to HBA context object. |
| 5075 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5076 | * This function is the main SLI initialization function. This function |
| 5077 | * is called by the HBA initialization code, HBA reset code and HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5078 | * error attention handler code. Caller is not required to hold any |
| 5079 | * locks. This function issues config_port mailbox command to configure |
| 5080 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 5081 | * calls the config_port_post function to issue init_link mailbox |
| 5082 | * command and to start the discovery. The function will return zero |
| 5083 | * if successful, else it will return negative error code. |
| 5084 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5085 | int |
| 5086 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 5087 | { |
| 5088 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5089 | int mode = 3, i; |
| 5090 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5091 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5092 | switch (phba->cfg_sli_mode) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5093 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 5094 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5095 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5096 | "1824 NPIV enabled: Override sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5097 | "parameter (%d) to auto (0).\n", |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5098 | phba->cfg_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5099 | break; |
| 5100 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5101 | mode = 2; |
| 5102 | break; |
| 5103 | case 0: |
| 5104 | case 3: |
| 5105 | break; |
| 5106 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5107 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5108 | "1819 Unrecognized sli_mode parameter: %d.\n", |
| 5109 | phba->cfg_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5110 | |
| 5111 | break; |
| 5112 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 5113 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5114 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5115 | rc = lpfc_sli_config_port(phba, mode); |
| 5116 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5117 | if (rc && phba->cfg_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5118 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5119 | "1820 Unable to select SLI-3. " |
| 5120 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5121 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5122 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | 4597663f | 2016-07-06 12:36:01 -0700 | [diff] [blame] | 5123 | else if (rc && mode == 2) |
| 5124 | rc = lpfc_sli_config_port(phba, 3); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5125 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5126 | goto lpfc_sli_hba_setup_error; |
| 5127 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5128 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 5129 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 5130 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 5131 | if (!rc) { |
| 5132 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5133 | "2709 This device supports " |
| 5134 | "Advanced Error Reporting (AER)\n"); |
| 5135 | spin_lock_irq(&phba->hbalock); |
| 5136 | phba->hba_flag |= HBA_AER_ENABLED; |
| 5137 | spin_unlock_irq(&phba->hbalock); |
| 5138 | } else { |
| 5139 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5140 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 5141 | "Advanced Error Reporting (AER): %d\n", |
| 5142 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5143 | phba->cfg_aer_support = 0; |
| 5144 | } |
| 5145 | } |
| 5146 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5147 | if (phba->sli_rev == 3) { |
| 5148 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 5149 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5150 | } else { |
| 5151 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 5152 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5153 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5154 | } |
| 5155 | |
| 5156 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5157 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 5158 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5159 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5160 | |
| 5161 | if (rc) |
| 5162 | goto lpfc_sli_hba_setup_error; |
| 5163 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5164 | /* Initialize VPIs. */ |
| 5165 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 5166 | /* |
| 5167 | * The VPI bitmask and physical ID array are allocated |
| 5168 | * and initialized once only - at driver load. A port |
| 5169 | * reset doesn't need to reinitialize this memory. |
| 5170 | */ |
| 5171 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 5172 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5173 | phba->vpi_bmask = kcalloc(longs, |
| 5174 | sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5175 | GFP_KERNEL); |
| 5176 | if (!phba->vpi_bmask) { |
| 5177 | rc = -ENOMEM; |
| 5178 | goto lpfc_sli_hba_setup_error; |
| 5179 | } |
| 5180 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5181 | phba->vpi_ids = kcalloc(phba->max_vpi + 1, |
| 5182 | sizeof(uint16_t), |
| 5183 | GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5184 | if (!phba->vpi_ids) { |
| 5185 | kfree(phba->vpi_bmask); |
| 5186 | rc = -ENOMEM; |
| 5187 | goto lpfc_sli_hba_setup_error; |
| 5188 | } |
| 5189 | for (i = 0; i < phba->max_vpi; i++) |
| 5190 | phba->vpi_ids[i] = i; |
| 5191 | } |
| 5192 | } |
| 5193 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5194 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5195 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 5196 | rc = lpfc_sli_hbq_setup(phba); |
| 5197 | if (rc) |
| 5198 | goto lpfc_sli_hba_setup_error; |
| 5199 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5200 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5201 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5202 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5203 | |
| 5204 | rc = lpfc_config_port_post(phba); |
| 5205 | if (rc) |
| 5206 | goto lpfc_sli_hba_setup_error; |
| 5207 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5208 | return rc; |
| 5209 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5210 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5211 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 5212 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5213 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5214 | return rc; |
| 5215 | } |
| 5216 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5217 | /** |
| 5218 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 5219 | * @phba: Pointer to HBA context object. |
| 5220 | * @mboxq: mailbox pointer. |
| 5221 | * This function issue a dump mailbox command to read config region |
| 5222 | * 23 and parse the records in the region and populate driver |
| 5223 | * data structure. |
| 5224 | **/ |
| 5225 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5226 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5227 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5228 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5229 | struct lpfc_dmabuf *mp; |
| 5230 | struct lpfc_mqe *mqe; |
| 5231 | uint32_t data_length; |
| 5232 | int rc; |
| 5233 | |
| 5234 | /* Program the default value of vlan_id and fc_map */ |
| 5235 | phba->valid_vlan = 0; |
| 5236 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5237 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5238 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5239 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5240 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5241 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5242 | return -ENOMEM; |
| 5243 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5244 | mqe = &mboxq->u.mqe; |
| 5245 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 5246 | rc = -ENOMEM; |
| 5247 | goto out_free_mboxq; |
| 5248 | } |
| 5249 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5250 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5251 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5252 | |
| 5253 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5254 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 5255 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5256 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5257 | "CQ: x%x x%x x%x x%x\n", |
| 5258 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5259 | bf_get(lpfc_mqe_command, mqe), |
| 5260 | bf_get(lpfc_mqe_status, mqe), |
| 5261 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 5262 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 5263 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 5264 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 5265 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 5266 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 5267 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 5268 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 5269 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 5270 | mboxq->mcqe.word0, |
| 5271 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 5272 | mboxq->mcqe.trailer); |
| 5273 | |
| 5274 | if (rc) { |
| 5275 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5276 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5277 | rc = -EIO; |
| 5278 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5279 | } |
| 5280 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 5281 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5282 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5283 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5284 | rc = -EIO; |
| 5285 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5286 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5287 | |
| 5288 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 5289 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5290 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5291 | rc = 0; |
| 5292 | |
| 5293 | out_free_mboxq: |
| 5294 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5295 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5296 | } |
| 5297 | |
| 5298 | /** |
| 5299 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 5300 | * @phba: pointer to lpfc hba data structure. |
| 5301 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 5302 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 5303 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 5304 | * On output, the number of data bytes in @vpd. |
| 5305 | * |
| 5306 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 5307 | * addition, this routine gets the port vpd data. |
| 5308 | * |
| 5309 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5310 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5311 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5312 | **/ |
| 5313 | static int |
| 5314 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 5315 | uint8_t *vpd, uint32_t *vpd_size) |
| 5316 | { |
| 5317 | int rc = 0; |
| 5318 | uint32_t dma_size; |
| 5319 | struct lpfc_dmabuf *dmabuf; |
| 5320 | struct lpfc_mqe *mqe; |
| 5321 | |
| 5322 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5323 | if (!dmabuf) |
| 5324 | return -ENOMEM; |
| 5325 | |
| 5326 | /* |
| 5327 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 5328 | * mailbox command. |
| 5329 | */ |
| 5330 | dma_size = *vpd_size; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 5331 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, dma_size, |
| 5332 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5333 | if (!dmabuf->virt) { |
| 5334 | kfree(dmabuf); |
| 5335 | return -ENOMEM; |
| 5336 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5337 | |
| 5338 | /* |
| 5339 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 5340 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 5341 | * in SLI3. This code corrects the conflicts. |
| 5342 | */ |
| 5343 | lpfc_read_rev(phba, mboxq); |
| 5344 | mqe = &mboxq->u.mqe; |
| 5345 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 5346 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 5347 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 5348 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 5349 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 5350 | |
| 5351 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5352 | if (rc) { |
| 5353 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5354 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 5355 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5356 | return -EIO; |
| 5357 | } |
| 5358 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5359 | /* |
| 5360 | * The available vpd length cannot be bigger than the |
| 5361 | * DMA buffer passed to the port. Catch the less than |
| 5362 | * case and update the caller's size. |
| 5363 | */ |
| 5364 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 5365 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 5366 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5367 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 5368 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5369 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5370 | dmabuf->virt, dmabuf->phys); |
| 5371 | kfree(dmabuf); |
| 5372 | return 0; |
| 5373 | } |
| 5374 | |
| 5375 | /** |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5376 | * lpfc_sli4_get_ctl_attr - Retrieve SLI4 device controller attributes |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5377 | * @phba: pointer to lpfc hba data structure. |
| 5378 | * |
| 5379 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5380 | * is attached to. |
| 5381 | * |
| 5382 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5383 | * 0 - successful |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5384 | * otherwise - failed to retrieve controller attributes |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5385 | **/ |
| 5386 | static int |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5387 | lpfc_sli4_get_ctl_attr(struct lpfc_hba *phba) |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5388 | { |
| 5389 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5390 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 5391 | struct lpfc_controller_attribute *cntl_attr; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5392 | void *virtaddr = NULL; |
| 5393 | uint32_t alloclen, reqlen; |
| 5394 | uint32_t shdr_status, shdr_add_status; |
| 5395 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5396 | int rc; |
| 5397 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5398 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5399 | if (!mboxq) |
| 5400 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5401 | |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5402 | /* Send COMMON_GET_CNTL_ATTRIBUTES mbox cmd */ |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5403 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 5404 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5405 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 5406 | LPFC_SLI4_MBX_NEMBED); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5407 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5408 | if (alloclen < reqlen) { |
| 5409 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5410 | "3084 Allocated DMA memory size (%d) is " |
| 5411 | "less than the requested DMA memory size " |
| 5412 | "(%d)\n", alloclen, reqlen); |
| 5413 | rc = -ENOMEM; |
| 5414 | goto out_free_mboxq; |
| 5415 | } |
| 5416 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5417 | virtaddr = mboxq->sge_array->addr[0]; |
| 5418 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5419 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5420 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5421 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5422 | if (shdr_status || shdr_add_status || rc) { |
| 5423 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5424 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5425 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5426 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5427 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5428 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5429 | rc, shdr_status, shdr_add_status); |
| 5430 | rc = -ENXIO; |
| 5431 | goto out_free_mboxq; |
| 5432 | } |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5433 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5434 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5435 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5436 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5437 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5438 | phba->sli4_hba.lnk_info.lnk_no = |
| 5439 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5440 | |
| 5441 | memset(phba->BIOSVersion, 0, sizeof(phba->BIOSVersion)); |
| 5442 | strlcat(phba->BIOSVersion, (char *)cntl_attr->bios_ver_str, |
| 5443 | sizeof(phba->BIOSVersion)); |
| 5444 | |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5445 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5446 | "3086 lnk_type:%d, lnk_numb:%d, bios_ver:%s\n", |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5447 | phba->sli4_hba.lnk_info.lnk_tp, |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 5448 | phba->sli4_hba.lnk_info.lnk_no, |
| 5449 | phba->BIOSVersion); |
| 5450 | out_free_mboxq: |
| 5451 | if (rc != MBX_TIMEOUT) { |
| 5452 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5453 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5454 | else |
| 5455 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5456 | } |
| 5457 | return rc; |
| 5458 | } |
| 5459 | |
| 5460 | /** |
| 5461 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 5462 | * @phba: pointer to lpfc hba data structure. |
| 5463 | * |
| 5464 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5465 | * is attached to. |
| 5466 | * |
| 5467 | * Return codes |
| 5468 | * 0 - successful |
| 5469 | * otherwise - failed to retrieve physical port name |
| 5470 | **/ |
| 5471 | static int |
| 5472 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 5473 | { |
| 5474 | LPFC_MBOXQ_t *mboxq; |
| 5475 | struct lpfc_mbx_get_port_name *get_port_name; |
| 5476 | uint32_t shdr_status, shdr_add_status; |
| 5477 | union lpfc_sli4_cfg_shdr *shdr; |
| 5478 | char cport_name = 0; |
| 5479 | int rc; |
| 5480 | |
| 5481 | /* We assume nothing at this point */ |
| 5482 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5483 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 5484 | |
| 5485 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5486 | if (!mboxq) |
| 5487 | return -ENOMEM; |
| 5488 | /* obtain link type and link number via READ_CONFIG */ |
| 5489 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5490 | lpfc_sli4_read_config(phba); |
| 5491 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 5492 | goto retrieve_ppname; |
| 5493 | |
| 5494 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 5495 | rc = lpfc_sli4_get_ctl_attr(phba); |
| 5496 | if (rc) |
| 5497 | goto out_free_mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5498 | |
| 5499 | retrieve_ppname: |
| 5500 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5501 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5502 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5503 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5504 | LPFC_SLI4_MBX_EMBED); |
| 5505 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5506 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5507 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5508 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5509 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5510 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5511 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5512 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5513 | if (shdr_status || shdr_add_status || rc) { |
| 5514 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5515 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5516 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5517 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5518 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5519 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5520 | rc, shdr_status, shdr_add_status); |
| 5521 | rc = -ENXIO; |
| 5522 | goto out_free_mboxq; |
| 5523 | } |
| 5524 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5525 | case LPFC_LINK_NUMBER_0: |
| 5526 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5527 | &get_port_name->u.response); |
| 5528 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5529 | break; |
| 5530 | case LPFC_LINK_NUMBER_1: |
| 5531 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5532 | &get_port_name->u.response); |
| 5533 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5534 | break; |
| 5535 | case LPFC_LINK_NUMBER_2: |
| 5536 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5537 | &get_port_name->u.response); |
| 5538 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5539 | break; |
| 5540 | case LPFC_LINK_NUMBER_3: |
| 5541 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5542 | &get_port_name->u.response); |
| 5543 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5544 | break; |
| 5545 | default: |
| 5546 | break; |
| 5547 | } |
| 5548 | |
| 5549 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5550 | phba->Port[0] = cport_name; |
| 5551 | phba->Port[1] = '\0'; |
| 5552 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5553 | "3091 SLI get port name: %s\n", phba->Port); |
| 5554 | } |
| 5555 | |
| 5556 | out_free_mboxq: |
| 5557 | if (rc != MBX_TIMEOUT) { |
| 5558 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5559 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5560 | else |
| 5561 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5562 | } |
| 5563 | return rc; |
| 5564 | } |
| 5565 | |
| 5566 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5567 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5568 | * @phba: pointer to lpfc hba data structure. |
| 5569 | * |
| 5570 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5571 | * event queues |
| 5572 | **/ |
| 5573 | static void |
| 5574 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5575 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5576 | int qidx; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5577 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5578 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5579 | struct lpfc_queue *eq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5580 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5581 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM); |
| 5582 | 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] | 5583 | if (sli4_hba->nvmels_cq) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5584 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0, |
| 5585 | LPFC_QUEUE_REARM); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5586 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5587 | if (sli4_hba->hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5588 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5589 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5590 | qp = &sli4_hba->hdwq[qidx]; |
| 5591 | /* ARM the corresponding CQ */ |
James Smart | 01f2ef6 | 2019-08-28 16:19:11 -0700 | [diff] [blame] | 5592 | sli4_hba->sli4_write_cq_db(phba, qp->io_cq, 0, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 5593 | LPFC_QUEUE_REARM); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5594 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5595 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 5596 | /* Loop thru all IRQ vectors */ |
| 5597 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 5598 | eq = sli4_hba->hba_eq_hdl[qidx].eq; |
| 5599 | /* ARM the corresponding EQ */ |
| 5600 | sli4_hba->sli4_write_eq_db(phba, eq, |
| 5601 | 0, LPFC_QUEUE_REARM); |
| 5602 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5603 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5604 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5605 | if (phba->nvmet_support) { |
| 5606 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5607 | sli4_hba->sli4_write_cq_db(phba, |
| 5608 | sli4_hba->nvmet_cqset[qidx], 0, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5609 | LPFC_QUEUE_REARM); |
| 5610 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5611 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5612 | } |
| 5613 | |
| 5614 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5615 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5616 | * @phba: Pointer to HBA context object. |
| 5617 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5618 | * @extnt_count: buffer to hold port available extent count. |
| 5619 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5620 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5621 | * This function calls the port and retrievs the number of available |
| 5622 | * extents and their size for a particular extent type. |
| 5623 | * |
| 5624 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5625 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5626 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5627 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5628 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5629 | { |
| 5630 | int rc = 0; |
| 5631 | uint32_t length; |
| 5632 | uint32_t mbox_tmo; |
| 5633 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5634 | LPFC_MBOXQ_t *mbox; |
| 5635 | |
| 5636 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5637 | if (!mbox) |
| 5638 | return -ENOMEM; |
| 5639 | |
| 5640 | /* Find out how many extents are available for this resource type */ |
| 5641 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5642 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5643 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5644 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5645 | length, LPFC_SLI4_MBX_EMBED); |
| 5646 | |
| 5647 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5648 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5649 | LPFC_SLI4_MBX_EMBED); |
| 5650 | if (unlikely(rc)) { |
| 5651 | rc = -EIO; |
| 5652 | goto err_exit; |
| 5653 | } |
| 5654 | |
| 5655 | if (!phba->sli4_hba.intr_enable) |
| 5656 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5657 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5658 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5659 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5660 | } |
| 5661 | if (unlikely(rc)) { |
| 5662 | rc = -EIO; |
| 5663 | goto err_exit; |
| 5664 | } |
| 5665 | |
| 5666 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5667 | if (bf_get(lpfc_mbox_hdr_status, |
| 5668 | &rsrc_info->header.cfg_shdr.response)) { |
| 5669 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5670 | "2930 Failed to get resource extents " |
| 5671 | "Status 0x%x Add'l Status 0x%x\n", |
| 5672 | bf_get(lpfc_mbox_hdr_status, |
| 5673 | &rsrc_info->header.cfg_shdr.response), |
| 5674 | bf_get(lpfc_mbox_hdr_add_status, |
| 5675 | &rsrc_info->header.cfg_shdr.response)); |
| 5676 | rc = -EIO; |
| 5677 | goto err_exit; |
| 5678 | } |
| 5679 | |
| 5680 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5681 | &rsrc_info->u.rsp); |
| 5682 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5683 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5684 | |
| 5685 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5686 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5687 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5688 | |
| 5689 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5690 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5691 | return rc; |
| 5692 | } |
| 5693 | |
| 5694 | /** |
| 5695 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5696 | * @phba: Pointer to HBA context object. |
| 5697 | * @type: The extent type to check. |
| 5698 | * |
| 5699 | * This function reads the current available extents from the port and checks |
| 5700 | * if the extent count or extent size has changed since the last access. |
| 5701 | * Callers use this routine post port reset to understand if there is a |
| 5702 | * extent reprovisioning requirement. |
| 5703 | * |
| 5704 | * Returns: |
| 5705 | * -Error: error indicates problem. |
| 5706 | * 1: Extent count or size has changed. |
| 5707 | * 0: No changes. |
| 5708 | **/ |
| 5709 | static int |
| 5710 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5711 | { |
| 5712 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5713 | uint16_t size_diff, rsrc_ext_size; |
| 5714 | int rc = 0; |
| 5715 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5716 | struct list_head *rsrc_blk_list = NULL; |
| 5717 | |
| 5718 | size_diff = 0; |
| 5719 | curr_ext_cnt = 0; |
| 5720 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5721 | &rsrc_ext_cnt, |
| 5722 | &rsrc_ext_size); |
| 5723 | if (unlikely(rc)) |
| 5724 | return -EIO; |
| 5725 | |
| 5726 | switch (type) { |
| 5727 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5728 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5729 | break; |
| 5730 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5731 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5732 | break; |
| 5733 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5734 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5735 | break; |
| 5736 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5737 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5738 | break; |
| 5739 | default: |
| 5740 | break; |
| 5741 | } |
| 5742 | |
| 5743 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5744 | curr_ext_cnt++; |
| 5745 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5746 | size_diff++; |
| 5747 | } |
| 5748 | |
| 5749 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5750 | rc = 1; |
| 5751 | |
| 5752 | return rc; |
| 5753 | } |
| 5754 | |
| 5755 | /** |
| 5756 | * lpfc_sli4_cfg_post_extnts - |
| 5757 | * @phba: Pointer to HBA context object. |
| 5758 | * @extnt_cnt - number of available extents. |
| 5759 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5760 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5761 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5762 | * |
| 5763 | * This function executes the extents allocation request. It also |
| 5764 | * takes care of the amount of memory needed to allocate or get the |
| 5765 | * allocated extents. It is the caller's responsibility to evaluate |
| 5766 | * the response. |
| 5767 | * |
| 5768 | * Returns: |
| 5769 | * -Error: Error value describes the condition found. |
| 5770 | * 0: if successful |
| 5771 | **/ |
| 5772 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5773 | 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] | 5774 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5775 | { |
| 5776 | int rc = 0; |
| 5777 | uint32_t req_len; |
| 5778 | uint32_t emb_len; |
| 5779 | uint32_t alloc_len, mbox_tmo; |
| 5780 | |
| 5781 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5782 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5783 | |
| 5784 | /* |
| 5785 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5786 | * accounts for extents-specific word. |
| 5787 | */ |
| 5788 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5789 | sizeof(uint32_t); |
| 5790 | |
| 5791 | /* |
| 5792 | * Presume the allocation and response will fit into an embedded |
| 5793 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5794 | */ |
| 5795 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5796 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5797 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5798 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5799 | sizeof(uint32_t); |
| 5800 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5801 | } |
| 5802 | |
| 5803 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5804 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5805 | req_len, *emb); |
| 5806 | if (alloc_len < req_len) { |
| 5807 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5808 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5809 | "less than the requested DMA memory " |
| 5810 | "size (x%x)\n", alloc_len, req_len); |
| 5811 | return -ENOMEM; |
| 5812 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5813 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5814 | if (unlikely(rc)) |
| 5815 | return -EIO; |
| 5816 | |
| 5817 | if (!phba->sli4_hba.intr_enable) |
| 5818 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5819 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5820 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5821 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5822 | } |
| 5823 | |
| 5824 | if (unlikely(rc)) |
| 5825 | rc = -EIO; |
| 5826 | return rc; |
| 5827 | } |
| 5828 | |
| 5829 | /** |
| 5830 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5831 | * @phba: Pointer to HBA context object. |
| 5832 | * @type: The resource extent type to allocate. |
| 5833 | * |
| 5834 | * This function allocates the number of elements for the specified |
| 5835 | * resource type. |
| 5836 | **/ |
| 5837 | static int |
| 5838 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5839 | { |
| 5840 | bool emb = false; |
| 5841 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5842 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5843 | uint16_t *ids; |
| 5844 | int i, rc; |
| 5845 | unsigned long longs; |
| 5846 | unsigned long *bmask; |
| 5847 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5848 | LPFC_MBOXQ_t *mbox; |
| 5849 | uint32_t length; |
| 5850 | struct lpfc_id_range *id_array = NULL; |
| 5851 | void *virtaddr = NULL; |
| 5852 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5853 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5854 | struct list_head *ext_blk_list; |
| 5855 | |
| 5856 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5857 | &rsrc_cnt, |
| 5858 | &rsrc_size); |
| 5859 | if (unlikely(rc)) |
| 5860 | return -EIO; |
| 5861 | |
| 5862 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5863 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5864 | "3009 No available Resource Extents " |
| 5865 | "for resource type 0x%x: Count: 0x%x, " |
| 5866 | "Size 0x%x\n", type, rsrc_cnt, |
| 5867 | rsrc_size); |
| 5868 | return -ENOMEM; |
| 5869 | } |
| 5870 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5871 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5872 | "2903 Post resource extents type-0x%x: " |
| 5873 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5874 | |
| 5875 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5876 | if (!mbox) |
| 5877 | return -ENOMEM; |
| 5878 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5879 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5880 | if (unlikely(rc)) { |
| 5881 | rc = -EIO; |
| 5882 | goto err_exit; |
| 5883 | } |
| 5884 | |
| 5885 | /* |
| 5886 | * Figure out where the response is located. Then get local pointers |
| 5887 | * to the response data. The port does not guarantee to respond to |
| 5888 | * all extents counts request so update the local variable with the |
| 5889 | * allocated count from the port. |
| 5890 | */ |
| 5891 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5892 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5893 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5894 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5895 | } else { |
| 5896 | virtaddr = mbox->sge_array->addr[0]; |
| 5897 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5898 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5899 | id_array = &n_rsrc->id; |
| 5900 | } |
| 5901 | |
| 5902 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5903 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5904 | |
| 5905 | /* |
| 5906 | * Based on the resource size and count, correct the base and max |
| 5907 | * resource values. |
| 5908 | */ |
| 5909 | length = sizeof(struct lpfc_rsrc_blks); |
| 5910 | switch (type) { |
| 5911 | case LPFC_RSC_TYPE_FCOE_RPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5912 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5913 | sizeof(unsigned long), |
| 5914 | GFP_KERNEL); |
| 5915 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5916 | rc = -ENOMEM; |
| 5917 | goto err_exit; |
| 5918 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5919 | phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5920 | sizeof(uint16_t), |
| 5921 | GFP_KERNEL); |
| 5922 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5923 | kfree(phba->sli4_hba.rpi_bmask); |
| 5924 | rc = -ENOMEM; |
| 5925 | goto err_exit; |
| 5926 | } |
| 5927 | |
| 5928 | /* |
| 5929 | * The next_rpi was initialized with the maximum available |
| 5930 | * count but the port may allocate a smaller number. Catch |
| 5931 | * that case and update the next_rpi. |
| 5932 | */ |
| 5933 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5934 | |
| 5935 | /* Initialize local ptrs for common extent processing later. */ |
| 5936 | bmask = phba->sli4_hba.rpi_bmask; |
| 5937 | ids = phba->sli4_hba.rpi_ids; |
| 5938 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5939 | break; |
| 5940 | case LPFC_RSC_TYPE_FCOE_VPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5941 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5942 | GFP_KERNEL); |
| 5943 | if (unlikely(!phba->vpi_bmask)) { |
| 5944 | rc = -ENOMEM; |
| 5945 | goto err_exit; |
| 5946 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5947 | phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5948 | GFP_KERNEL); |
| 5949 | if (unlikely(!phba->vpi_ids)) { |
| 5950 | kfree(phba->vpi_bmask); |
| 5951 | rc = -ENOMEM; |
| 5952 | goto err_exit; |
| 5953 | } |
| 5954 | |
| 5955 | /* Initialize local ptrs for common extent processing later. */ |
| 5956 | bmask = phba->vpi_bmask; |
| 5957 | ids = phba->vpi_ids; |
| 5958 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5959 | break; |
| 5960 | case LPFC_RSC_TYPE_FCOE_XRI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5961 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5962 | sizeof(unsigned long), |
| 5963 | GFP_KERNEL); |
| 5964 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5965 | rc = -ENOMEM; |
| 5966 | goto err_exit; |
| 5967 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5968 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5969 | phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5970 | sizeof(uint16_t), |
| 5971 | GFP_KERNEL); |
| 5972 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5973 | kfree(phba->sli4_hba.xri_bmask); |
| 5974 | rc = -ENOMEM; |
| 5975 | goto err_exit; |
| 5976 | } |
| 5977 | |
| 5978 | /* Initialize local ptrs for common extent processing later. */ |
| 5979 | bmask = phba->sli4_hba.xri_bmask; |
| 5980 | ids = phba->sli4_hba.xri_ids; |
| 5981 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5982 | break; |
| 5983 | case LPFC_RSC_TYPE_FCOE_VFI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5984 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5985 | sizeof(unsigned long), |
| 5986 | GFP_KERNEL); |
| 5987 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5988 | rc = -ENOMEM; |
| 5989 | goto err_exit; |
| 5990 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5991 | phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5992 | sizeof(uint16_t), |
| 5993 | GFP_KERNEL); |
| 5994 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5995 | kfree(phba->sli4_hba.vfi_bmask); |
| 5996 | rc = -ENOMEM; |
| 5997 | goto err_exit; |
| 5998 | } |
| 5999 | |
| 6000 | /* Initialize local ptrs for common extent processing later. */ |
| 6001 | bmask = phba->sli4_hba.vfi_bmask; |
| 6002 | ids = phba->sli4_hba.vfi_ids; |
| 6003 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6004 | break; |
| 6005 | default: |
| 6006 | /* Unsupported Opcode. Fail call. */ |
| 6007 | id_array = NULL; |
| 6008 | bmask = NULL; |
| 6009 | ids = NULL; |
| 6010 | ext_blk_list = NULL; |
| 6011 | goto err_exit; |
| 6012 | } |
| 6013 | |
| 6014 | /* |
| 6015 | * Complete initializing the extent configuration with the |
| 6016 | * allocated ids assigned to this function. The bitmask serves |
| 6017 | * as an index into the array and manages the available ids. The |
| 6018 | * array just stores the ids communicated to the port via the wqes. |
| 6019 | */ |
| 6020 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 6021 | if ((i % 2) == 0) |
| 6022 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 6023 | &id_array[k]); |
| 6024 | else |
| 6025 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 6026 | &id_array[k]); |
| 6027 | |
| 6028 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 6029 | if (unlikely(!rsrc_blks)) { |
| 6030 | rc = -ENOMEM; |
| 6031 | kfree(bmask); |
| 6032 | kfree(ids); |
| 6033 | goto err_exit; |
| 6034 | } |
| 6035 | rsrc_blks->rsrc_start = rsrc_id; |
| 6036 | rsrc_blks->rsrc_size = rsrc_size; |
| 6037 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 6038 | rsrc_start = rsrc_id; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6039 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6040 | phba->sli4_hba.io_xri_start = rsrc_start + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6041 | lpfc_sli4_get_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6042 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6043 | |
| 6044 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 6045 | ids[j] = rsrc_id; |
| 6046 | rsrc_id++; |
| 6047 | j++; |
| 6048 | } |
| 6049 | /* Entire word processed. Get next word.*/ |
| 6050 | if ((i % 2) == 1) |
| 6051 | k++; |
| 6052 | } |
| 6053 | err_exit: |
| 6054 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6055 | return rc; |
| 6056 | } |
| 6057 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6058 | |
| 6059 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6060 | /** |
| 6061 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 6062 | * @phba: Pointer to HBA context object. |
| 6063 | * @type: the extent's type. |
| 6064 | * |
| 6065 | * This function deallocates all extents of a particular resource type. |
| 6066 | * SLI4 does not allow for deallocating a particular extent range. It |
| 6067 | * is the caller's responsibility to release all kernel memory resources. |
| 6068 | **/ |
| 6069 | static int |
| 6070 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 6071 | { |
| 6072 | int rc; |
| 6073 | uint32_t length, mbox_tmo = 0; |
| 6074 | LPFC_MBOXQ_t *mbox; |
| 6075 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 6076 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 6077 | |
| 6078 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6079 | if (!mbox) |
| 6080 | return -ENOMEM; |
| 6081 | |
| 6082 | /* |
| 6083 | * This function sends an embedded mailbox because it only sends the |
| 6084 | * the resource type. All extents of this type are released by the |
| 6085 | * port. |
| 6086 | */ |
| 6087 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 6088 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6089 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6090 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 6091 | length, LPFC_SLI4_MBX_EMBED); |
| 6092 | |
| 6093 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 6094 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 6095 | LPFC_SLI4_MBX_EMBED); |
| 6096 | if (unlikely(rc)) { |
| 6097 | rc = -EIO; |
| 6098 | goto out_free_mbox; |
| 6099 | } |
| 6100 | if (!phba->sli4_hba.intr_enable) |
| 6101 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6102 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6103 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6104 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6105 | } |
| 6106 | if (unlikely(rc)) { |
| 6107 | rc = -EIO; |
| 6108 | goto out_free_mbox; |
| 6109 | } |
| 6110 | |
| 6111 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 6112 | if (bf_get(lpfc_mbox_hdr_status, |
| 6113 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 6114 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6115 | "2919 Failed to release resource extents " |
| 6116 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 6117 | "Resource memory not released.\n", |
| 6118 | type, |
| 6119 | bf_get(lpfc_mbox_hdr_status, |
| 6120 | &dealloc_rsrc->header.cfg_shdr.response), |
| 6121 | bf_get(lpfc_mbox_hdr_add_status, |
| 6122 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 6123 | rc = -EIO; |
| 6124 | goto out_free_mbox; |
| 6125 | } |
| 6126 | |
| 6127 | /* Release kernel memory resources for the specific type. */ |
| 6128 | switch (type) { |
| 6129 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6130 | kfree(phba->vpi_bmask); |
| 6131 | kfree(phba->vpi_ids); |
| 6132 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6133 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6134 | &phba->lpfc_vpi_blk_list, list) { |
| 6135 | list_del_init(&rsrc_blk->list); |
| 6136 | kfree(rsrc_blk); |
| 6137 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6138 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6139 | break; |
| 6140 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6141 | kfree(phba->sli4_hba.xri_bmask); |
| 6142 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6143 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6144 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 6145 | list_del_init(&rsrc_blk->list); |
| 6146 | kfree(rsrc_blk); |
| 6147 | } |
| 6148 | break; |
| 6149 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6150 | kfree(phba->sli4_hba.vfi_bmask); |
| 6151 | kfree(phba->sli4_hba.vfi_ids); |
| 6152 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6153 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6154 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 6155 | list_del_init(&rsrc_blk->list); |
| 6156 | kfree(rsrc_blk); |
| 6157 | } |
| 6158 | break; |
| 6159 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6160 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 6161 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6162 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 6163 | list_del_init(&rsrc_blk->list); |
| 6164 | kfree(rsrc_blk); |
| 6165 | } |
| 6166 | break; |
| 6167 | default: |
| 6168 | break; |
| 6169 | } |
| 6170 | |
| 6171 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6172 | |
| 6173 | out_free_mbox: |
| 6174 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6175 | return rc; |
| 6176 | } |
| 6177 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 6178 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6179 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 6180 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6181 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6182 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6183 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6184 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 6185 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6186 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6187 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 6188 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6189 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6190 | switch (feature) { |
| 6191 | case LPFC_SET_UE_RECOVERY: |
| 6192 | bf_set(lpfc_mbx_set_feature_UER, |
| 6193 | &mbox->u.mqe.un.set_feature, 1); |
| 6194 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 6195 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6196 | break; |
| 6197 | case LPFC_SET_MDS_DIAGS: |
| 6198 | bf_set(lpfc_mbx_set_feature_mds, |
| 6199 | &mbox->u.mqe.un.set_feature, 1); |
| 6200 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 6201 | &mbox->u.mqe.un.set_feature, 1); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6202 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 6203 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6204 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6205 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6206 | |
| 6207 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6208 | } |
| 6209 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6210 | /** |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6211 | * lpfc_ras_stop_fwlog: Disable FW logging by the adapter |
| 6212 | * @phba: Pointer to HBA context object. |
| 6213 | * |
| 6214 | * Disable FW logging into host memory on the adapter. To |
| 6215 | * be done before reading logs from the host memory. |
| 6216 | **/ |
| 6217 | void |
| 6218 | lpfc_ras_stop_fwlog(struct lpfc_hba *phba) |
| 6219 | { |
| 6220 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6221 | |
| 6222 | ras_fwlog->ras_active = false; |
| 6223 | |
| 6224 | /* Disable FW logging to host memory */ |
| 6225 | writel(LPFC_CTL_PDEV_CTL_DDL_RAS, |
| 6226 | phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET); |
| 6227 | } |
| 6228 | |
| 6229 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6230 | * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging. |
| 6231 | * @phba: Pointer to HBA context object. |
| 6232 | * |
| 6233 | * This function is called to free memory allocated for RAS FW logging |
| 6234 | * support in the driver. |
| 6235 | **/ |
| 6236 | void |
| 6237 | lpfc_sli4_ras_dma_free(struct lpfc_hba *phba) |
| 6238 | { |
| 6239 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6240 | struct lpfc_dmabuf *dmabuf, *next; |
| 6241 | |
| 6242 | if (!list_empty(&ras_fwlog->fwlog_buff_list)) { |
| 6243 | list_for_each_entry_safe(dmabuf, next, |
| 6244 | &ras_fwlog->fwlog_buff_list, |
| 6245 | list) { |
| 6246 | list_del(&dmabuf->list); |
| 6247 | dma_free_coherent(&phba->pcidev->dev, |
| 6248 | LPFC_RAS_MAX_ENTRY_SIZE, |
| 6249 | dmabuf->virt, dmabuf->phys); |
| 6250 | kfree(dmabuf); |
| 6251 | } |
| 6252 | } |
| 6253 | |
| 6254 | if (ras_fwlog->lwpd.virt) { |
| 6255 | dma_free_coherent(&phba->pcidev->dev, |
| 6256 | sizeof(uint32_t) * 2, |
| 6257 | ras_fwlog->lwpd.virt, |
| 6258 | ras_fwlog->lwpd.phys); |
| 6259 | ras_fwlog->lwpd.virt = NULL; |
| 6260 | } |
| 6261 | |
| 6262 | ras_fwlog->ras_active = false; |
| 6263 | } |
| 6264 | |
| 6265 | /** |
| 6266 | * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support |
| 6267 | * @phba: Pointer to HBA context object. |
| 6268 | * @fwlog_buff_count: Count of buffers to be created. |
| 6269 | * |
| 6270 | * This routine DMA memory for Log Write Position Data[LPWD] and buffer |
| 6271 | * to update FW log is posted to the adapter. |
| 6272 | * Buffer count is calculated based on module param ras_fwlog_buffsize |
| 6273 | * Size of each buffer posted to FW is 64K. |
| 6274 | **/ |
| 6275 | |
| 6276 | static int |
| 6277 | lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba, |
| 6278 | uint32_t fwlog_buff_count) |
| 6279 | { |
| 6280 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6281 | struct lpfc_dmabuf *dmabuf; |
| 6282 | int rc = 0, i = 0; |
| 6283 | |
| 6284 | /* Initialize List */ |
| 6285 | INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list); |
| 6286 | |
| 6287 | /* Allocate memory for the LWPD */ |
| 6288 | ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6289 | sizeof(uint32_t) * 2, |
| 6290 | &ras_fwlog->lwpd.phys, |
| 6291 | GFP_KERNEL); |
| 6292 | if (!ras_fwlog->lwpd.virt) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6293 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6294 | "6185 LWPD Memory Alloc Failed\n"); |
| 6295 | |
| 6296 | return -ENOMEM; |
| 6297 | } |
| 6298 | |
| 6299 | ras_fwlog->fw_buffcount = fwlog_buff_count; |
| 6300 | for (i = 0; i < ras_fwlog->fw_buffcount; i++) { |
| 6301 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 6302 | GFP_KERNEL); |
| 6303 | if (!dmabuf) { |
| 6304 | rc = -ENOMEM; |
| 6305 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6306 | "6186 Memory Alloc failed FW logging"); |
| 6307 | goto free_mem; |
| 6308 | } |
| 6309 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6310 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6311 | LPFC_RAS_MAX_ENTRY_SIZE, |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6312 | &dmabuf->phys, GFP_KERNEL); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6313 | if (!dmabuf->virt) { |
| 6314 | kfree(dmabuf); |
| 6315 | rc = -ENOMEM; |
| 6316 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6317 | "6187 DMA Alloc Failed FW logging"); |
| 6318 | goto free_mem; |
| 6319 | } |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6320 | dmabuf->buffer_tag = i; |
| 6321 | list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list); |
| 6322 | } |
| 6323 | |
| 6324 | free_mem: |
| 6325 | if (rc) |
| 6326 | lpfc_sli4_ras_dma_free(phba); |
| 6327 | |
| 6328 | return rc; |
| 6329 | } |
| 6330 | |
| 6331 | /** |
| 6332 | * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command |
| 6333 | * @phba: pointer to lpfc hba data structure. |
| 6334 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 6335 | * |
| 6336 | * Completion handler for driver's RAS MBX command to the device. |
| 6337 | **/ |
| 6338 | static void |
| 6339 | lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6340 | { |
| 6341 | MAILBOX_t *mb; |
| 6342 | union lpfc_sli4_cfg_shdr *shdr; |
| 6343 | uint32_t shdr_status, shdr_add_status; |
| 6344 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6345 | |
| 6346 | mb = &pmb->u.mb; |
| 6347 | |
| 6348 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6349 | &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr; |
| 6350 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6351 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6352 | |
| 6353 | if (mb->mbxStatus != MBX_SUCCESS || shdr_status) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6354 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6355 | "6188 FW LOG mailbox " |
| 6356 | "completed with status x%x add_status x%x," |
| 6357 | " mbx status x%x\n", |
| 6358 | shdr_status, shdr_add_status, mb->mbxStatus); |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6359 | |
| 6360 | ras_fwlog->ras_hwsupport = false; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6361 | goto disable_ras; |
| 6362 | } |
| 6363 | |
| 6364 | ras_fwlog->ras_active = true; |
| 6365 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6366 | |
| 6367 | return; |
| 6368 | |
| 6369 | disable_ras: |
| 6370 | /* Free RAS DMA memory */ |
| 6371 | lpfc_sli4_ras_dma_free(phba); |
| 6372 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6373 | } |
| 6374 | |
| 6375 | /** |
| 6376 | * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command |
| 6377 | * @phba: pointer to lpfc hba data structure. |
| 6378 | * @fwlog_level: Logging verbosity level. |
| 6379 | * @fwlog_enable: Enable/Disable logging. |
| 6380 | * |
| 6381 | * Initialize memory and post mailbox command to enable FW logging in host |
| 6382 | * memory. |
| 6383 | **/ |
| 6384 | int |
| 6385 | lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba, |
| 6386 | uint32_t fwlog_level, |
| 6387 | uint32_t fwlog_enable) |
| 6388 | { |
| 6389 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6390 | struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL; |
| 6391 | struct lpfc_dmabuf *dmabuf; |
| 6392 | LPFC_MBOXQ_t *mbox; |
| 6393 | uint32_t len = 0, fwlog_buffsize, fwlog_entry_count; |
| 6394 | int rc = 0; |
| 6395 | |
| 6396 | fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE * |
| 6397 | phba->cfg_ras_fwlog_buffsize); |
| 6398 | fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE); |
| 6399 | |
| 6400 | /* |
| 6401 | * If re-enabling FW logging support use earlier allocated |
| 6402 | * DMA buffers while posting MBX command. |
| 6403 | **/ |
| 6404 | if (!ras_fwlog->lwpd.virt) { |
| 6405 | rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count); |
| 6406 | if (rc) { |
| 6407 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6408 | "6189 FW Log Memory Allocation Failed"); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6409 | return rc; |
| 6410 | } |
| 6411 | } |
| 6412 | |
| 6413 | /* Setup Mailbox command */ |
| 6414 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6415 | if (!mbox) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6416 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6417 | "6190 RAS MBX Alloc Failed"); |
| 6418 | rc = -ENOMEM; |
| 6419 | goto mem_free; |
| 6420 | } |
| 6421 | |
| 6422 | ras_fwlog->fw_loglevel = fwlog_level; |
| 6423 | len = (sizeof(struct lpfc_mbx_set_ras_fwlog) - |
| 6424 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6425 | |
| 6426 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL, |
| 6427 | LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION, |
| 6428 | len, LPFC_SLI4_MBX_EMBED); |
| 6429 | |
| 6430 | mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog; |
| 6431 | bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request, |
| 6432 | fwlog_enable); |
| 6433 | bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request, |
| 6434 | ras_fwlog->fw_loglevel); |
| 6435 | bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request, |
| 6436 | ras_fwlog->fw_buffcount); |
| 6437 | bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request, |
| 6438 | LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE); |
| 6439 | |
| 6440 | /* Update DMA buffer address */ |
| 6441 | list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) { |
| 6442 | memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE); |
| 6443 | |
| 6444 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo = |
| 6445 | putPaddrLow(dmabuf->phys); |
| 6446 | |
| 6447 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi = |
| 6448 | putPaddrHigh(dmabuf->phys); |
| 6449 | } |
| 6450 | |
| 6451 | /* Update LPWD address */ |
| 6452 | mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys); |
| 6453 | mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys); |
| 6454 | |
| 6455 | mbox->vport = phba->pport; |
| 6456 | mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl; |
| 6457 | |
| 6458 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6459 | |
| 6460 | if (rc == MBX_NOT_FINISHED) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6461 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6462 | "6191 FW-Log Mailbox failed. " |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6463 | "status %d mbxStatus : x%x", rc, |
| 6464 | bf_get(lpfc_mqe_status, &mbox->u.mqe)); |
| 6465 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6466 | rc = -EIO; |
| 6467 | goto mem_free; |
| 6468 | } else |
| 6469 | rc = 0; |
| 6470 | mem_free: |
| 6471 | if (rc) |
| 6472 | lpfc_sli4_ras_dma_free(phba); |
| 6473 | |
| 6474 | return rc; |
| 6475 | } |
| 6476 | |
| 6477 | /** |
| 6478 | * lpfc_sli4_ras_setup - Check if RAS supported on the adapter |
| 6479 | * @phba: Pointer to HBA context object. |
| 6480 | * |
| 6481 | * Check if RAS is supported on the adapter and initialize it. |
| 6482 | **/ |
| 6483 | void |
| 6484 | lpfc_sli4_ras_setup(struct lpfc_hba *phba) |
| 6485 | { |
| 6486 | /* Check RAS FW Log needs to be enabled or not */ |
| 6487 | if (lpfc_check_fwlog_support(phba)) |
| 6488 | return; |
| 6489 | |
| 6490 | lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level, |
| 6491 | LPFC_RAS_ENABLE_LOGGING); |
| 6492 | } |
| 6493 | |
| 6494 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6495 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 6496 | * @phba: Pointer to HBA context object. |
| 6497 | * |
| 6498 | * This function allocates all SLI4 resource identifiers. |
| 6499 | **/ |
| 6500 | int |
| 6501 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 6502 | { |
| 6503 | int i, rc, error = 0; |
| 6504 | uint16_t count, base; |
| 6505 | unsigned long longs; |
| 6506 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6507 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6508 | 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] | 6509 | if (phba->sli4_hba.extents_in_use) { |
| 6510 | /* |
| 6511 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 6512 | * resource extent count must be read and allocated before |
| 6513 | * provisioning the resource id arrays. |
| 6514 | */ |
| 6515 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 6516 | LPFC_IDX_RSRC_RDY) { |
| 6517 | /* |
| 6518 | * Extent-based resources are set - the driver could |
| 6519 | * be in a port reset. Figure out if any corrective |
| 6520 | * actions need to be taken. |
| 6521 | */ |
| 6522 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6523 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6524 | if (rc != 0) |
| 6525 | error++; |
| 6526 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6527 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6528 | if (rc != 0) |
| 6529 | error++; |
| 6530 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6531 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6532 | if (rc != 0) |
| 6533 | error++; |
| 6534 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6535 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6536 | if (rc != 0) |
| 6537 | error++; |
| 6538 | |
| 6539 | /* |
| 6540 | * It's possible that the number of resources |
| 6541 | * provided to this port instance changed between |
| 6542 | * resets. Detect this condition and reallocate |
| 6543 | * resources. Otherwise, there is no action. |
| 6544 | */ |
| 6545 | if (error) { |
| 6546 | lpfc_printf_log(phba, KERN_INFO, |
| 6547 | LOG_MBOX | LOG_INIT, |
| 6548 | "2931 Detected extent resource " |
| 6549 | "change. Reallocating all " |
| 6550 | "extents.\n"); |
| 6551 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6552 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6553 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6554 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6555 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6556 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6557 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6558 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6559 | } else |
| 6560 | return 0; |
| 6561 | } |
| 6562 | |
| 6563 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6564 | if (unlikely(rc)) |
| 6565 | goto err_exit; |
| 6566 | |
| 6567 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6568 | if (unlikely(rc)) |
| 6569 | goto err_exit; |
| 6570 | |
| 6571 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6572 | if (unlikely(rc)) |
| 6573 | goto err_exit; |
| 6574 | |
| 6575 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6576 | if (unlikely(rc)) |
| 6577 | goto err_exit; |
| 6578 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6579 | LPFC_IDX_RSRC_RDY); |
| 6580 | return rc; |
| 6581 | } else { |
| 6582 | /* |
| 6583 | * The port does not support resource extents. The XRI, VPI, |
| 6584 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 6585 | * Just allocate the bitmasks and provision the resource id |
| 6586 | * arrays. If a port reset is active, the resources don't |
| 6587 | * need any action - just exit. |
| 6588 | */ |
| 6589 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6590 | LPFC_IDX_RSRC_RDY) { |
| 6591 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6592 | lpfc_sli4_remove_rpis(phba); |
| 6593 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6594 | /* RPIs. */ |
| 6595 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6596 | if (count <= 0) { |
| 6597 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6598 | "3279 Invalid provisioning of " |
| 6599 | "rpi:%d\n", count); |
| 6600 | rc = -EINVAL; |
| 6601 | goto err_exit; |
| 6602 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6603 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 6604 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6605 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6606 | sizeof(unsigned long), |
| 6607 | GFP_KERNEL); |
| 6608 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6609 | rc = -ENOMEM; |
| 6610 | goto err_exit; |
| 6611 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6612 | phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6613 | GFP_KERNEL); |
| 6614 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6615 | rc = -ENOMEM; |
| 6616 | goto free_rpi_bmask; |
| 6617 | } |
| 6618 | |
| 6619 | for (i = 0; i < count; i++) |
| 6620 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 6621 | |
| 6622 | /* VPIs. */ |
| 6623 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6624 | if (count <= 0) { |
| 6625 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6626 | "3280 Invalid provisioning of " |
| 6627 | "vpi:%d\n", count); |
| 6628 | rc = -EINVAL; |
| 6629 | goto free_rpi_ids; |
| 6630 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6631 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6632 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6633 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6634 | GFP_KERNEL); |
| 6635 | if (unlikely(!phba->vpi_bmask)) { |
| 6636 | rc = -ENOMEM; |
| 6637 | goto free_rpi_ids; |
| 6638 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6639 | phba->vpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6640 | GFP_KERNEL); |
| 6641 | if (unlikely(!phba->vpi_ids)) { |
| 6642 | rc = -ENOMEM; |
| 6643 | goto free_vpi_bmask; |
| 6644 | } |
| 6645 | |
| 6646 | for (i = 0; i < count; i++) |
| 6647 | phba->vpi_ids[i] = base + i; |
| 6648 | |
| 6649 | /* XRIs. */ |
| 6650 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6651 | if (count <= 0) { |
| 6652 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6653 | "3281 Invalid provisioning of " |
| 6654 | "xri:%d\n", count); |
| 6655 | rc = -EINVAL; |
| 6656 | goto free_vpi_ids; |
| 6657 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6658 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 6659 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6660 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6661 | sizeof(unsigned long), |
| 6662 | GFP_KERNEL); |
| 6663 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6664 | rc = -ENOMEM; |
| 6665 | goto free_vpi_ids; |
| 6666 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 6667 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6668 | phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6669 | GFP_KERNEL); |
| 6670 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6671 | rc = -ENOMEM; |
| 6672 | goto free_xri_bmask; |
| 6673 | } |
| 6674 | |
| 6675 | for (i = 0; i < count; i++) |
| 6676 | phba->sli4_hba.xri_ids[i] = base + i; |
| 6677 | |
| 6678 | /* VFIs. */ |
| 6679 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6680 | if (count <= 0) { |
| 6681 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6682 | "3282 Invalid provisioning of " |
| 6683 | "vfi:%d\n", count); |
| 6684 | rc = -EINVAL; |
| 6685 | goto free_xri_ids; |
| 6686 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6687 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 6688 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6689 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6690 | sizeof(unsigned long), |
| 6691 | GFP_KERNEL); |
| 6692 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6693 | rc = -ENOMEM; |
| 6694 | goto free_xri_ids; |
| 6695 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6696 | phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6697 | GFP_KERNEL); |
| 6698 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6699 | rc = -ENOMEM; |
| 6700 | goto free_vfi_bmask; |
| 6701 | } |
| 6702 | |
| 6703 | for (i = 0; i < count; i++) |
| 6704 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 6705 | |
| 6706 | /* |
| 6707 | * Mark all resources ready. An HBA reset doesn't need |
| 6708 | * to reset the initialization. |
| 6709 | */ |
| 6710 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6711 | LPFC_IDX_RSRC_RDY); |
| 6712 | return 0; |
| 6713 | } |
| 6714 | |
| 6715 | free_vfi_bmask: |
| 6716 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6717 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6718 | free_xri_ids: |
| 6719 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6720 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6721 | free_xri_bmask: |
| 6722 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6723 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6724 | free_vpi_ids: |
| 6725 | kfree(phba->vpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6726 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6727 | free_vpi_bmask: |
| 6728 | kfree(phba->vpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6729 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6730 | free_rpi_ids: |
| 6731 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6732 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6733 | free_rpi_bmask: |
| 6734 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6735 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6736 | err_exit: |
| 6737 | return rc; |
| 6738 | } |
| 6739 | |
| 6740 | /** |
| 6741 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 6742 | * @phba: Pointer to HBA context object. |
| 6743 | * |
| 6744 | * This function allocates the number of elements for the specified |
| 6745 | * resource type. |
| 6746 | **/ |
| 6747 | int |
| 6748 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 6749 | { |
| 6750 | if (phba->sli4_hba.extents_in_use) { |
| 6751 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6752 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6753 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6754 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6755 | } else { |
| 6756 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6757 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6758 | kfree(phba->vpi_ids); |
| 6759 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6760 | kfree(phba->sli4_hba.xri_bmask); |
| 6761 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6762 | kfree(phba->sli4_hba.vfi_bmask); |
| 6763 | kfree(phba->sli4_hba.vfi_ids); |
| 6764 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6765 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6766 | } |
| 6767 | |
| 6768 | return 0; |
| 6769 | } |
| 6770 | |
| 6771 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6772 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 6773 | * @phba: Pointer to HBA context object. |
| 6774 | * @type: The resource extent type. |
| 6775 | * @extnt_count: buffer to hold port extent count response |
| 6776 | * @extnt_size: buffer to hold port extent size response. |
| 6777 | * |
| 6778 | * This function calls the port to read the host allocated extents |
| 6779 | * for a particular type. |
| 6780 | **/ |
| 6781 | int |
| 6782 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 6783 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 6784 | { |
| 6785 | bool emb; |
| 6786 | int rc = 0; |
| 6787 | uint16_t curr_blks = 0; |
| 6788 | uint32_t req_len, emb_len; |
| 6789 | uint32_t alloc_len, mbox_tmo; |
| 6790 | struct list_head *blk_list_head; |
| 6791 | struct lpfc_rsrc_blks *rsrc_blk; |
| 6792 | LPFC_MBOXQ_t *mbox; |
| 6793 | void *virtaddr = NULL; |
| 6794 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6795 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6796 | union lpfc_sli4_cfg_shdr *shdr; |
| 6797 | |
| 6798 | switch (type) { |
| 6799 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6800 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6801 | break; |
| 6802 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6803 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6804 | break; |
| 6805 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6806 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6807 | break; |
| 6808 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6809 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6810 | break; |
| 6811 | default: |
| 6812 | return -EIO; |
| 6813 | } |
| 6814 | |
| 6815 | /* Count the number of extents currently allocatd for this type. */ |
| 6816 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6817 | if (curr_blks == 0) { |
| 6818 | /* |
| 6819 | * The GET_ALLOCATED mailbox does not return the size, |
| 6820 | * just the count. The size should be just the size |
| 6821 | * stored in the current allocated block and all sizes |
| 6822 | * for an extent type are the same so set the return |
| 6823 | * value now. |
| 6824 | */ |
| 6825 | *extnt_size = rsrc_blk->rsrc_size; |
| 6826 | } |
| 6827 | curr_blks++; |
| 6828 | } |
| 6829 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6830 | /* |
| 6831 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6832 | * accounts for extents-specific word. |
| 6833 | */ |
| 6834 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6835 | sizeof(uint32_t); |
| 6836 | |
| 6837 | /* |
| 6838 | * Presume the allocation and response will fit into an embedded |
| 6839 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6840 | */ |
| 6841 | emb = LPFC_SLI4_MBX_EMBED; |
| 6842 | req_len = emb_len; |
| 6843 | if (req_len > emb_len) { |
| 6844 | req_len = curr_blks * sizeof(uint16_t) + |
| 6845 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6846 | sizeof(uint32_t); |
| 6847 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6848 | } |
| 6849 | |
| 6850 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6851 | if (!mbox) |
| 6852 | return -ENOMEM; |
| 6853 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6854 | |
| 6855 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6856 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6857 | req_len, emb); |
| 6858 | if (alloc_len < req_len) { |
| 6859 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6860 | "2983 Allocated DMA memory size (x%x) is " |
| 6861 | "less than the requested DMA memory " |
| 6862 | "size (x%x)\n", alloc_len, req_len); |
| 6863 | rc = -ENOMEM; |
| 6864 | goto err_exit; |
| 6865 | } |
| 6866 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6867 | if (unlikely(rc)) { |
| 6868 | rc = -EIO; |
| 6869 | goto err_exit; |
| 6870 | } |
| 6871 | |
| 6872 | if (!phba->sli4_hba.intr_enable) |
| 6873 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6874 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6875 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6876 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6877 | } |
| 6878 | |
| 6879 | if (unlikely(rc)) { |
| 6880 | rc = -EIO; |
| 6881 | goto err_exit; |
| 6882 | } |
| 6883 | |
| 6884 | /* |
| 6885 | * Figure out where the response is located. Then get local pointers |
| 6886 | * to the response data. The port does not guarantee to respond to |
| 6887 | * all extents counts request so update the local variable with the |
| 6888 | * allocated count from the port. |
| 6889 | */ |
| 6890 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6891 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6892 | shdr = &rsrc_ext->header.cfg_shdr; |
| 6893 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6894 | } else { |
| 6895 | virtaddr = mbox->sge_array->addr[0]; |
| 6896 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6897 | shdr = &n_rsrc->cfg_shdr; |
| 6898 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6899 | } |
| 6900 | |
| 6901 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 6902 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6903 | "2984 Failed to read allocated resources " |
| 6904 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 6905 | type, |
| 6906 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 6907 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 6908 | rc = -EIO; |
| 6909 | goto err_exit; |
| 6910 | } |
| 6911 | err_exit: |
| 6912 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6913 | return rc; |
| 6914 | } |
| 6915 | |
| 6916 | /** |
James Smart | 0ef6996 | 2017-04-21 16:04:50 -0700 | [diff] [blame] | 6917 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6918 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6919 | * @pring: Pointer to driver SLI ring object. |
| 6920 | * @sgl_list: linked link of sgl buffers to post |
| 6921 | * @cnt: number of linked list buffers |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6922 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6923 | * This routine walks the list of buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6924 | * repost them to the port by using SGL block post. This is needed after a |
| 6925 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6926 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
| 6927 | * 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] | 6928 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 6929 | * mailbox command for posting. |
| 6930 | * |
| 6931 | * Returns: 0 = success, non-zero failure. |
| 6932 | **/ |
| 6933 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6934 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
| 6935 | struct list_head *sgl_list, int cnt) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6936 | { |
| 6937 | struct lpfc_sglq *sglq_entry = NULL; |
| 6938 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 6939 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6940 | int status, total_cnt; |
| 6941 | int post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6942 | int last_xritag = NO_XRI; |
| 6943 | LIST_HEAD(prep_sgl_list); |
| 6944 | LIST_HEAD(blck_sgl_list); |
| 6945 | LIST_HEAD(allc_sgl_list); |
| 6946 | LIST_HEAD(post_sgl_list); |
| 6947 | LIST_HEAD(free_sgl_list); |
| 6948 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6949 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6950 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6951 | list_splice_init(sgl_list, &allc_sgl_list); |
| 6952 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6953 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6954 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6955 | total_cnt = cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6956 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6957 | &allc_sgl_list, list) { |
| 6958 | list_del_init(&sglq_entry->list); |
| 6959 | block_cnt++; |
| 6960 | if ((last_xritag != NO_XRI) && |
| 6961 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6962 | /* a hole in xri block, form a sgl posting block */ |
| 6963 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6964 | post_cnt = block_cnt - 1; |
| 6965 | /* prepare list for next posting block */ |
| 6966 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6967 | block_cnt = 1; |
| 6968 | } else { |
| 6969 | /* prepare list for next posting block */ |
| 6970 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6971 | /* enough sgls for non-embed sgl mbox command */ |
| 6972 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6973 | list_splice_init(&prep_sgl_list, |
| 6974 | &blck_sgl_list); |
| 6975 | post_cnt = block_cnt; |
| 6976 | block_cnt = 0; |
| 6977 | } |
| 6978 | } |
| 6979 | num_posted++; |
| 6980 | |
| 6981 | /* keep track of last sgl's xritag */ |
| 6982 | last_xritag = sglq_entry->sli4_xritag; |
| 6983 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6984 | /* end of repost sgl list condition for buffers */ |
| 6985 | if (num_posted == total_cnt) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6986 | if (post_cnt == 0) { |
| 6987 | list_splice_init(&prep_sgl_list, |
| 6988 | &blck_sgl_list); |
| 6989 | post_cnt = block_cnt; |
| 6990 | } else if (block_cnt == 1) { |
| 6991 | status = lpfc_sli4_post_sgl(phba, |
| 6992 | sglq_entry->phys, 0, |
| 6993 | sglq_entry->sli4_xritag); |
| 6994 | if (!status) { |
| 6995 | /* successful, put sgl to posted list */ |
| 6996 | list_add_tail(&sglq_entry->list, |
| 6997 | &post_sgl_list); |
| 6998 | } else { |
| 6999 | /* Failure, put sgl to free list */ |
| 7000 | lpfc_printf_log(phba, KERN_WARNING, |
| 7001 | LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7002 | "3159 Failed to post " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7003 | "sgl, xritag:x%x\n", |
| 7004 | sglq_entry->sli4_xritag); |
| 7005 | list_add_tail(&sglq_entry->list, |
| 7006 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7007 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7008 | } |
| 7009 | } |
| 7010 | } |
| 7011 | |
| 7012 | /* continue until a nembed page worth of sgls */ |
| 7013 | if (post_cnt == 0) |
| 7014 | continue; |
| 7015 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7016 | /* post the buffer list sgls as a block */ |
| 7017 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, |
| 7018 | post_cnt); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7019 | |
| 7020 | if (!status) { |
| 7021 | /* success, put sgl list to posted sgl list */ |
| 7022 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 7023 | } else { |
| 7024 | /* Failure, put sgl list to free sgl list */ |
| 7025 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 7026 | struct lpfc_sglq, |
| 7027 | list); |
| 7028 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7029 | "3160 Failed to post sgl-list, " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7030 | "xritag:x%x-x%x\n", |
| 7031 | sglq_entry_first->sli4_xritag, |
| 7032 | (sglq_entry_first->sli4_xritag + |
| 7033 | post_cnt - 1)); |
| 7034 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7035 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7036 | } |
| 7037 | |
| 7038 | /* don't reset xirtag due to hole in xri block */ |
| 7039 | if (block_cnt == 0) |
| 7040 | last_xritag = NO_XRI; |
| 7041 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7042 | /* reset sgl post count for next round of posting */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7043 | post_cnt = 0; |
| 7044 | } |
| 7045 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7046 | /* free the sgls failed to post */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7047 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 7048 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7049 | /* push sgls posted to the available list */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7050 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7051 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7052 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7053 | list_splice_init(&post_sgl_list, sgl_list); |
| 7054 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7055 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7056 | } else { |
| 7057 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7058 | "3161 Failure to post sgl to port.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7059 | return -EIO; |
| 7060 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7061 | |
| 7062 | /* return the number of XRIs actually posted */ |
| 7063 | return total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7064 | } |
| 7065 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7066 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7067 | * 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] | 7068 | * @phba: pointer to lpfc hba data structure. |
| 7069 | * |
| 7070 | * This routine walks the list of nvme buffers that have been allocated and |
| 7071 | * repost them to the port by using SGL block post. This is needed after a |
| 7072 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 7073 | * 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] | 7074 | * 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] | 7075 | * |
| 7076 | * Returns: 0 = success, non-zero failure. |
| 7077 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 7078 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7079 | lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7080 | { |
| 7081 | LIST_HEAD(post_nblist); |
| 7082 | int num_posted, rc = 0; |
| 7083 | |
| 7084 | /* get all NVME buffers need to repost to a local list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7085 | lpfc_io_buf_flush(phba, &post_nblist); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7086 | |
| 7087 | /* post the list of nvme buffer sgls to port if available */ |
| 7088 | if (!list_empty(&post_nblist)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7089 | num_posted = lpfc_sli4_post_io_sgl_list( |
| 7090 | phba, &post_nblist, phba->sli4_hba.io_xri_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7091 | /* failed to post any nvme buffer, return error */ |
| 7092 | if (num_posted == 0) |
| 7093 | rc = -EIO; |
| 7094 | } |
| 7095 | return rc; |
| 7096 | } |
| 7097 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 7098 | static void |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7099 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 7100 | { |
| 7101 | uint32_t len; |
| 7102 | |
| 7103 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 7104 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 7105 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7106 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 7107 | LPFC_SLI4_MBX_EMBED); |
| 7108 | |
| 7109 | 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] | 7110 | mbox->u.mqe.un.set_host_data.param_len = |
| 7111 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7112 | snprintf(mbox->u.mqe.un.set_host_data.data, |
| 7113 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 7114 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 7115 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 7116 | } |
| 7117 | |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7118 | int |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7119 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7120 | struct lpfc_queue *drq, int count, int idx) |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7121 | { |
| 7122 | int rc, i; |
| 7123 | struct lpfc_rqe hrqe; |
| 7124 | struct lpfc_rqe drqe; |
| 7125 | struct lpfc_rqb *rqbp; |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7126 | unsigned long flags; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7127 | struct rqb_dmabuf *rqb_buffer; |
| 7128 | LIST_HEAD(rqb_buf_list); |
| 7129 | |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7130 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7131 | rqbp = hrq->rqbp; |
| 7132 | for (i = 0; i < count; i++) { |
| 7133 | /* IF RQ is already full, don't bother */ |
| 7134 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) |
| 7135 | break; |
| 7136 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); |
| 7137 | if (!rqb_buffer) |
| 7138 | break; |
| 7139 | rqb_buffer->hrq = hrq; |
| 7140 | rqb_buffer->drq = drq; |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7141 | rqb_buffer->idx = idx; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7142 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
| 7143 | } |
| 7144 | while (!list_empty(&rqb_buf_list)) { |
| 7145 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, |
| 7146 | hbuf.list); |
| 7147 | |
| 7148 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); |
| 7149 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); |
| 7150 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); |
| 7151 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); |
| 7152 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
| 7153 | if (rc < 0) { |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7154 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7155 | "6421 Cannot post to HRQ %d: %x %x %x " |
| 7156 | "DRQ %x %x\n", |
| 7157 | hrq->queue_id, |
| 7158 | hrq->host_index, |
| 7159 | hrq->hba_index, |
| 7160 | hrq->entry_count, |
| 7161 | drq->host_index, |
| 7162 | drq->hba_index); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7163 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
| 7164 | } else { |
| 7165 | list_add_tail(&rqb_buffer->hbuf.list, |
| 7166 | &rqbp->rqb_buffer_list); |
| 7167 | rqbp->buffer_count++; |
| 7168 | } |
| 7169 | } |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7170 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7171 | return 1; |
| 7172 | } |
| 7173 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7174 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7175 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7176 | * @phba: Pointer to HBA context object. |
| 7177 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7178 | * This function is the main SLI4 device initialization PCI function. This |
| 7179 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7180 | * HBA error attention handler code. Caller is not required to hold any |
| 7181 | * locks. |
| 7182 | **/ |
| 7183 | int |
| 7184 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 7185 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7186 | int rc, i, cnt, len; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7187 | LPFC_MBOXQ_t *mboxq; |
| 7188 | struct lpfc_mqe *mqe; |
| 7189 | uint8_t *vpd; |
| 7190 | uint32_t vpd_size; |
| 7191 | uint32_t ftr_rsp = 0; |
| 7192 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 7193 | struct lpfc_vport *vport = phba->pport; |
| 7194 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7195 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7196 | |
| 7197 | /* Perform a PCI function reset to start from clean */ |
| 7198 | rc = lpfc_pci_function_reset(phba); |
| 7199 | if (unlikely(rc)) |
| 7200 | return -ENODEV; |
| 7201 | |
| 7202 | /* Check the HBA Host Status Register for readyness */ |
| 7203 | rc = lpfc_sli4_post_status_check(phba); |
| 7204 | if (unlikely(rc)) |
| 7205 | return -ENODEV; |
| 7206 | else { |
| 7207 | spin_lock_irq(&phba->hbalock); |
| 7208 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 7209 | spin_unlock_irq(&phba->hbalock); |
| 7210 | } |
| 7211 | |
| 7212 | /* |
| 7213 | * Allocate a single mailbox container for initializing the |
| 7214 | * port. |
| 7215 | */ |
| 7216 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7217 | if (!mboxq) |
| 7218 | return -ENOMEM; |
| 7219 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7220 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7221 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7222 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 7223 | if (!vpd) { |
| 7224 | rc = -ENOMEM; |
| 7225 | goto out_free_mbox; |
| 7226 | } |
| 7227 | |
| 7228 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7229 | if (unlikely(rc)) { |
| 7230 | kfree(vpd); |
| 7231 | goto out_free_mbox; |
| 7232 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7233 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7234 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7235 | 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] | 7236 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7237 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7238 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 7239 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7240 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7241 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7242 | |
| 7243 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 7244 | LPFC_DCBX_CEE_MODE) |
| 7245 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 7246 | else |
| 7247 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 7248 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 7249 | phba->hba_flag &= ~HBA_IOQ_FLUSH; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 7250 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7251 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7252 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7253 | "0376 READ_REV Error. SLI Level %d " |
| 7254 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7255 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7256 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7257 | kfree(vpd); |
| 7258 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7259 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7260 | |
| 7261 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7262 | * Continue initialization with default values even if driver failed |
| 7263 | * to read FCoE param config regions, only read parameters if the |
| 7264 | * board is FCoE |
| 7265 | */ |
| 7266 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 7267 | lpfc_sli4_read_fcoe_params(phba)) |
| 7268 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 7269 | "2570 Failed to read FCoE parameters\n"); |
| 7270 | |
| 7271 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7272 | * Retrieve sli4 device physical port name, failure of doing it |
| 7273 | * is considered as non-fatal. |
| 7274 | */ |
| 7275 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 7276 | if (!rc) |
| 7277 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7278 | "3080 Successful retrieving SLI4 device " |
| 7279 | "physical port name: %s.\n", phba->Port); |
| 7280 | |
James Smart | b3b4f3e | 2019-03-12 16:30:23 -0700 | [diff] [blame] | 7281 | rc = lpfc_sli4_get_ctl_attr(phba); |
| 7282 | if (!rc) |
| 7283 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7284 | "8351 Successful retrieving SLI4 device " |
| 7285 | "CTL ATTR\n"); |
| 7286 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7287 | /* |
| 7288 | * Evaluate the read rev and vpd data. Populate the driver |
| 7289 | * state with the results. If this routine fails, the failure |
| 7290 | * is not fatal as the driver will use generic values. |
| 7291 | */ |
| 7292 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 7293 | if (unlikely(!rc)) { |
| 7294 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7295 | "0377 Error %d parsing vpd. " |
| 7296 | "Using defaults.\n", rc); |
| 7297 | rc = 0; |
| 7298 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7299 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7300 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7301 | /* Save information as VPD data */ |
| 7302 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 7303 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 7304 | |
| 7305 | /* |
| 7306 | * This is because first G7 ASIC doesn't support the standard |
| 7307 | * 0x5a NVME cmd descriptor type/subtype |
| 7308 | */ |
| 7309 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 7310 | LPFC_SLI_INTF_IF_TYPE_6) && |
| 7311 | (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) && |
| 7312 | (phba->vpd.rev.smRev == 0) && |
| 7313 | (phba->cfg_nvme_embed_cmd == 1)) |
| 7314 | phba->cfg_nvme_embed_cmd = 0; |
| 7315 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7316 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 7317 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 7318 | &mqe->un.read_rev); |
| 7319 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 7320 | &mqe->un.read_rev); |
| 7321 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 7322 | &mqe->un.read_rev); |
| 7323 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 7324 | &mqe->un.read_rev); |
| 7325 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 7326 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 7327 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 7328 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 7329 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 7330 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 7331 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7332 | "(%d):0380 READ_REV Status x%x " |
| 7333 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 7334 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7335 | bf_get(lpfc_mqe_status, mqe), |
| 7336 | phba->vpd.rev.opFwName, |
| 7337 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 7338 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7339 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7340 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 7341 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 7342 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 7343 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7344 | "3362 LUN queue depth changed from %d to %d\n", |
| 7345 | phba->pport->cfg_lun_queue_depth, rc); |
| 7346 | phba->pport->cfg_lun_queue_depth = rc; |
| 7347 | } |
| 7348 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7349 | 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] | 7350 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 7351 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 7352 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7353 | if (rc == MBX_SUCCESS) { |
| 7354 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 7355 | /* Set 1Sec interval to detect UE */ |
| 7356 | phba->eratt_poll_interval = 1; |
| 7357 | phba->sli4_hba.ue_to_sr = bf_get( |
| 7358 | lpfc_mbx_set_feature_UESR, |
| 7359 | &mboxq->u.mqe.un.set_feature); |
| 7360 | phba->sli4_hba.ue_to_rp = bf_get( |
| 7361 | lpfc_mbx_set_feature_UERP, |
| 7362 | &mboxq->u.mqe.un.set_feature); |
| 7363 | } |
| 7364 | } |
| 7365 | |
| 7366 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 7367 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 7368 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 7369 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7370 | if (rc != MBX_SUCCESS) |
| 7371 | phba->mds_diags_support = 0; |
| 7372 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7373 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7374 | /* |
| 7375 | * Discover the port's supported feature set and match it against the |
| 7376 | * hosts requests. |
| 7377 | */ |
| 7378 | lpfc_request_features(phba, mboxq); |
| 7379 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7380 | if (unlikely(rc)) { |
| 7381 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7382 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7383 | } |
| 7384 | |
| 7385 | /* |
| 7386 | * The port must support FCP initiator mode as this is the |
| 7387 | * only mode running in the host. |
| 7388 | */ |
| 7389 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 7390 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7391 | "0378 No support for fcpi mode.\n"); |
| 7392 | ftr_rsp++; |
| 7393 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 7394 | |
| 7395 | /* Performance Hints are ONLY for FCoE */ |
| 7396 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 7397 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 7398 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 7399 | else |
| 7400 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
| 7401 | } |
| 7402 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7403 | /* |
| 7404 | * If the port cannot support the host's requested features |
| 7405 | * then turn off the global config parameters to disable the |
| 7406 | * feature in the driver. This is not a fatal error. |
| 7407 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7408 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 7409 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) { |
| 7410 | phba->cfg_enable_bg = 0; |
| 7411 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7412 | ftr_rsp++; |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7413 | } |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7414 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7415 | |
| 7416 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 7417 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7418 | ftr_rsp++; |
| 7419 | |
| 7420 | if (ftr_rsp) { |
| 7421 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7422 | "0379 Feature Mismatch Data: x%08x %08x " |
| 7423 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 7424 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 7425 | phba->cfg_enable_npiv, phba->max_vpi); |
| 7426 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 7427 | phba->cfg_enable_bg = 0; |
| 7428 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7429 | phba->cfg_enable_npiv = 0; |
| 7430 | } |
| 7431 | |
| 7432 | /* These SLI3 features are assumed in SLI4 */ |
| 7433 | spin_lock_irq(&phba->hbalock); |
| 7434 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 7435 | spin_unlock_irq(&phba->hbalock); |
| 7436 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7437 | /* |
| 7438 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 7439 | * calls depends on these resources to complete port setup. |
| 7440 | */ |
| 7441 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 7442 | if (rc) { |
| 7443 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7444 | "2920 Failed to alloc Resource IDs " |
| 7445 | "rc = x%x\n", rc); |
| 7446 | goto out_free_mbox; |
| 7447 | } |
| 7448 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7449 | lpfc_set_host_data(phba, mboxq); |
| 7450 | |
| 7451 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7452 | if (rc) { |
| 7453 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7454 | "2134 Failed to set host os driver version %x", |
| 7455 | rc); |
| 7456 | } |
| 7457 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7458 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7459 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 7460 | if (rc) { |
| 7461 | phba->link_state = LPFC_HBA_ERROR; |
| 7462 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7463 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7464 | } |
| 7465 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7466 | mboxq->vport = vport; |
| 7467 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7468 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7469 | if (rc == MBX_SUCCESS) { |
| 7470 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 7471 | rc = 0; |
| 7472 | } |
| 7473 | |
| 7474 | /* |
| 7475 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 7476 | * it to the mbuf pool. |
| 7477 | */ |
| 7478 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 7479 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7480 | mboxq->ctx_buf = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7481 | if (unlikely(rc)) { |
| 7482 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7483 | "0382 READ_SPARAM command failed " |
| 7484 | "status %d, mbxStatus x%x\n", |
| 7485 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 7486 | phba->link_state = LPFC_HBA_ERROR; |
| 7487 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7488 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7489 | } |
| 7490 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7491 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7492 | |
| 7493 | /* Update the fc_host data structures with new wwn. */ |
| 7494 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 7495 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 7496 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7497 | /* Create all the SLI4 queues */ |
| 7498 | rc = lpfc_sli4_queue_create(phba); |
| 7499 | if (rc) { |
| 7500 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7501 | "3089 Failed to allocate queues\n"); |
| 7502 | rc = -ENODEV; |
| 7503 | goto out_free_mbox; |
| 7504 | } |
| 7505 | /* Set up all the queues to the device */ |
| 7506 | rc = lpfc_sli4_queue_setup(phba); |
| 7507 | if (unlikely(rc)) { |
| 7508 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7509 | "0381 Error %d during queue setup.\n ", rc); |
| 7510 | goto out_stop_timers; |
| 7511 | } |
| 7512 | /* Initialize the driver internal SLI layer lists. */ |
| 7513 | lpfc_sli4_setup(phba); |
| 7514 | lpfc_sli4_queue_init(phba); |
| 7515 | |
| 7516 | /* update host els xri-sgl sizes and mappings */ |
| 7517 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7518 | if (unlikely(rc)) { |
| 7519 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7520 | "1400 Failed to update xri-sgl size and " |
| 7521 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7522 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7523 | } |
| 7524 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7525 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7526 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 7527 | phba->sli4_hba.els_xri_cnt); |
| 7528 | if (unlikely(rc < 0)) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7529 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7530 | "0582 Error %d during els sgl post " |
| 7531 | "operation\n", rc); |
| 7532 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7533 | goto out_destroy_queue; |
| 7534 | } |
| 7535 | phba->sli4_hba.els_xri_cnt = rc; |
| 7536 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7537 | if (phba->nvmet_support) { |
| 7538 | /* update host nvmet xri-sgl sizes and mappings */ |
| 7539 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 7540 | if (unlikely(rc)) { |
| 7541 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7542 | "6308 Failed to update nvmet-sgl size " |
| 7543 | "and mapping: %d\n", rc); |
| 7544 | goto out_destroy_queue; |
| 7545 | } |
| 7546 | |
| 7547 | /* register the nvmet sgl pool to the port */ |
| 7548 | rc = lpfc_sli4_repost_sgl_list( |
| 7549 | phba, |
| 7550 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 7551 | phba->sli4_hba.nvmet_xri_cnt); |
| 7552 | if (unlikely(rc < 0)) { |
| 7553 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7554 | "3117 Error %d during nvmet " |
| 7555 | "sgl post\n", rc); |
| 7556 | rc = -ENODEV; |
| 7557 | goto out_destroy_queue; |
| 7558 | } |
| 7559 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7560 | |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7561 | /* We allocate an iocbq for every receive context SGL. |
| 7562 | * The additional allocation is for abort and ls handling. |
| 7563 | */ |
| 7564 | cnt = phba->sli4_hba.nvmet_xri_cnt + |
| 7565 | phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7566 | } else { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7567 | /* update host common xri-sgl sizes and mappings */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7568 | rc = lpfc_sli4_io_sgl_update(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7569 | if (unlikely(rc)) { |
| 7570 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7571 | "6082 Failed to update nvme-sgl size " |
| 7572 | "and mapping: %d\n", rc); |
| 7573 | goto out_destroy_queue; |
| 7574 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7575 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7576 | /* register the allocated common sgl pool to the port */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7577 | rc = lpfc_sli4_repost_io_sgl_list(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7578 | if (unlikely(rc)) { |
| 7579 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7580 | "6116 Error %d during nvme sgl post " |
| 7581 | "operation\n", rc); |
| 7582 | /* Some NVME buffers were moved to abort nvme list */ |
| 7583 | /* A pci function reset will repost them */ |
| 7584 | rc = -ENODEV; |
| 7585 | goto out_destroy_queue; |
| 7586 | } |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7587 | /* Each lpfc_io_buf job structure has an iocbq element. |
| 7588 | * This cnt provides for abort, els, ct and ls requests. |
| 7589 | */ |
| 7590 | cnt = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7591 | } |
| 7592 | |
| 7593 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7594 | /* Initialize and populate the iocb list per host */ |
| 7595 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7596 | "2821 initialize iocb list with %d entries\n", |
| 7597 | cnt); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7598 | rc = lpfc_init_iocb_list(phba, cnt); |
| 7599 | if (rc) { |
| 7600 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7601 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7602 | goto out_destroy_queue; |
| 7603 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7604 | } |
| 7605 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7606 | if (phba->nvmet_support) |
| 7607 | lpfc_nvmet_create_targetport(phba); |
| 7608 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7609 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7610 | /* Post initial buffers to all RQs created */ |
| 7611 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 7612 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 7613 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 7614 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 7615 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 7616 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7617 | rqbp->buffer_count = 0; |
| 7618 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7619 | lpfc_post_rq_buffer( |
| 7620 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 7621 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | 2448e48 | 2018-04-09 14:24:24 -0700 | [diff] [blame] | 7622 | phba->cfg_nvmet_mrq_post, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7623 | } |
| 7624 | } |
| 7625 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7626 | /* Post the rpi header region to the device. */ |
| 7627 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 7628 | if (unlikely(rc)) { |
| 7629 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7630 | "0393 Error %d during rpi post operation\n", |
| 7631 | rc); |
| 7632 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7633 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7634 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7635 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7636 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7637 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7638 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7639 | /* |
| 7640 | * The FC Port needs to register FCFI (index 0) |
| 7641 | */ |
| 7642 | lpfc_reg_fcfi(phba, mboxq); |
| 7643 | mboxq->vport = phba->pport; |
| 7644 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7645 | if (rc != MBX_SUCCESS) |
| 7646 | goto out_unset_queue; |
| 7647 | rc = 0; |
| 7648 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 7649 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7650 | } else { |
| 7651 | /* We are a NVME Target mode with MRQ > 1 */ |
| 7652 | |
| 7653 | /* First register the FCFI */ |
| 7654 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 7655 | mboxq->vport = phba->pport; |
| 7656 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7657 | if (rc != MBX_SUCCESS) |
| 7658 | goto out_unset_queue; |
| 7659 | rc = 0; |
| 7660 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 7661 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 7662 | |
| 7663 | /* Next register the MRQs */ |
| 7664 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 7665 | mboxq->vport = phba->pport; |
| 7666 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7667 | if (rc != MBX_SUCCESS) |
| 7668 | goto out_unset_queue; |
| 7669 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7670 | } |
| 7671 | /* Check if the port is configured to be disabled */ |
| 7672 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7673 | } |
| 7674 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7675 | /* Don't post more new bufs if repost already recovered |
| 7676 | * the nvme sgls. |
| 7677 | */ |
| 7678 | if (phba->nvmet_support == 0) { |
| 7679 | if (phba->sli4_hba.io_xri_cnt == 0) { |
| 7680 | len = lpfc_new_io_buf( |
| 7681 | phba, phba->sli4_hba.io_xri_max); |
| 7682 | if (len == 0) { |
| 7683 | rc = -ENOMEM; |
| 7684 | goto out_unset_queue; |
| 7685 | } |
| 7686 | |
| 7687 | if (phba->cfg_xri_rebalancing) |
| 7688 | lpfc_create_multixri_pools(phba); |
| 7689 | } |
| 7690 | } else { |
| 7691 | phba->cfg_xri_rebalancing = 0; |
| 7692 | } |
| 7693 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7694 | /* Allow asynchronous mailbox command to go through */ |
| 7695 | spin_lock_irq(&phba->hbalock); |
| 7696 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7697 | spin_unlock_irq(&phba->hbalock); |
| 7698 | |
| 7699 | /* Post receive buffers to the device */ |
| 7700 | lpfc_sli4_rb_setup(phba); |
| 7701 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7702 | /* Reset HBA FCF states after HBA reset */ |
| 7703 | phba->fcf.fcf_flag = 0; |
| 7704 | phba->fcf.current_rec.flag = 0; |
| 7705 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7706 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7707 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7708 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7709 | |
| 7710 | /* Start heart beat timer */ |
| 7711 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7712 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7713 | phba->hb_outstanding = 0; |
| 7714 | phba->last_completion_time = jiffies; |
| 7715 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7716 | /* start eq_delay heartbeat */ |
| 7717 | if (phba->cfg_auto_imax) |
| 7718 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 7719 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 7720 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7721 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7722 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7723 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7724 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7725 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 7726 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 7727 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 7728 | if (!rc) { |
| 7729 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7730 | "2829 This device supports " |
| 7731 | "Advanced Error Reporting (AER)\n"); |
| 7732 | spin_lock_irq(&phba->hbalock); |
| 7733 | phba->hba_flag |= HBA_AER_ENABLED; |
| 7734 | spin_unlock_irq(&phba->hbalock); |
| 7735 | } else { |
| 7736 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7737 | "2830 This device does not support " |
| 7738 | "Advanced Error Reporting (AER)\n"); |
| 7739 | phba->cfg_aer_support = 0; |
| 7740 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7741 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7742 | } |
| 7743 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7744 | /* |
| 7745 | * The port is ready, set the host's link state to LINK_DOWN |
| 7746 | * in preparation for link interrupts. |
| 7747 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7748 | spin_lock_irq(&phba->hbalock); |
| 7749 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7750 | |
| 7751 | /* Check if physical ports are trunked */ |
| 7752 | if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba)) |
| 7753 | phba->trunk_link.link0.state = LPFC_LINK_DOWN; |
| 7754 | if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba)) |
| 7755 | phba->trunk_link.link1.state = LPFC_LINK_DOWN; |
| 7756 | if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba)) |
| 7757 | phba->trunk_link.link2.state = LPFC_LINK_DOWN; |
| 7758 | if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba)) |
| 7759 | phba->trunk_link.link3.state = LPFC_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7760 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7761 | |
James Smart | e8869f5 | 2019-03-12 16:30:18 -0700 | [diff] [blame] | 7762 | /* Arm the CQs and then EQs on device */ |
| 7763 | lpfc_sli4_arm_cqeq_intr(phba); |
| 7764 | |
| 7765 | /* Indicate device interrupt mode */ |
| 7766 | phba->sli4_hba.intr_enable = 1; |
| 7767 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7768 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 7769 | (phba->hba_flag & LINK_DISABLED)) { |
| 7770 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7771 | "3103 Adapter Link is disabled.\n"); |
| 7772 | lpfc_down_link(phba, mboxq); |
| 7773 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7774 | if (rc != MBX_SUCCESS) { |
| 7775 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7776 | "3104 Adapter failed to issue " |
| 7777 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7778 | goto out_io_buff_free; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7779 | } |
| 7780 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7781 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 7782 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 7783 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 7784 | if (rc) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7785 | goto out_io_buff_free; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7786 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7787 | } |
| 7788 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7789 | return rc; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7790 | out_io_buff_free: |
| 7791 | /* Free allocated IO Buffers */ |
| 7792 | lpfc_io_free(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7793 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7794 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7795 | lpfc_sli4_queue_unset(phba); |
| 7796 | out_destroy_queue: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7797 | lpfc_free_iocb_list(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7798 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7799 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7800 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7801 | out_free_mbox: |
| 7802 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7803 | return rc; |
| 7804 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7805 | |
| 7806 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7807 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7808 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7809 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7810 | * This is the callback function for mailbox timer. The mailbox |
| 7811 | * timer is armed when a new mailbox command is issued and the timer |
| 7812 | * is deleted when the mailbox complete. The function is called by |
| 7813 | * the kernel timer code when a mailbox does not complete within |
| 7814 | * expected time. This function wakes up the worker thread to |
| 7815 | * process the mailbox timeout and returns. All the processing is |
| 7816 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 7817 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7818 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7819 | lpfc_mbox_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7820 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7821 | struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7822 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7823 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7824 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7825 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7826 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7827 | if (!tmo_posted) |
| 7828 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 7829 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 7830 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7831 | if (!tmo_posted) |
| 7832 | lpfc_worker_wake_up(phba); |
| 7833 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7834 | } |
| 7835 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7836 | /** |
| 7837 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 7838 | * are pending |
| 7839 | * @phba: Pointer to HBA context object. |
| 7840 | * |
| 7841 | * This function checks if any mailbox completions are present on the mailbox |
| 7842 | * completion queue. |
| 7843 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 7844 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7845 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 7846 | { |
| 7847 | |
| 7848 | uint32_t idx; |
| 7849 | struct lpfc_queue *mcq; |
| 7850 | struct lpfc_mcqe *mcqe; |
| 7851 | bool pending_completions = false; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7852 | uint8_t qe_valid; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7853 | |
| 7854 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7855 | return false; |
| 7856 | |
| 7857 | /* Check for completions on mailbox completion queue */ |
| 7858 | |
| 7859 | mcq = phba->sli4_hba.mbx_cq; |
| 7860 | idx = mcq->hba_index; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7861 | qe_valid = mcq->qe_valid; |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 7862 | while (bf_get_le32(lpfc_cqe_valid, |
| 7863 | (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) { |
| 7864 | mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx)); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7865 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 7866 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 7867 | pending_completions = true; |
| 7868 | break; |
| 7869 | } |
| 7870 | idx = (idx + 1) % mcq->entry_count; |
| 7871 | if (mcq->hba_index == idx) |
| 7872 | break; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7873 | |
| 7874 | /* if the index wrapped around, toggle the valid bit */ |
| 7875 | if (phba->sli4_hba.pc_sli4_params.cqav && !idx) |
| 7876 | qe_valid = (qe_valid) ? 0 : 1; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7877 | } |
| 7878 | return pending_completions; |
| 7879 | |
| 7880 | } |
| 7881 | |
| 7882 | /** |
| 7883 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 7884 | * that were missed. |
| 7885 | * @phba: Pointer to HBA context object. |
| 7886 | * |
| 7887 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 7888 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 7889 | * checks to see if mbox completions are on the mailbox completion queue |
| 7890 | * and will process all the completions associated with the eq for the |
| 7891 | * mailbox completion queue. |
| 7892 | **/ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 7893 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7894 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 7895 | { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7896 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7897 | uint32_t eqidx; |
| 7898 | struct lpfc_queue *fpeq = NULL; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 7899 | struct lpfc_queue *eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7900 | bool mbox_pending; |
| 7901 | |
| 7902 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7903 | return false; |
| 7904 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 7905 | /* Find the EQ associated with the mbox CQ */ |
| 7906 | if (sli4_hba->hdwq) { |
| 7907 | for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) { |
| 7908 | eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq; |
| 7909 | if (eq->queue_id == sli4_hba->mbx_cq->assoc_qid) { |
| 7910 | fpeq = eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7911 | break; |
| 7912 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 7913 | } |
| 7914 | } |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7915 | if (!fpeq) |
| 7916 | return false; |
| 7917 | |
| 7918 | /* Turn off interrupts from this EQ */ |
| 7919 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7920 | sli4_hba->sli4_eq_clr_intr(fpeq); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7921 | |
| 7922 | /* Check to see if a mbox completion is pending */ |
| 7923 | |
| 7924 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 7925 | |
| 7926 | /* |
| 7927 | * If a mbox completion is pending, process all the events on EQ |
| 7928 | * associated with the mbox completion queue (this could include |
| 7929 | * mailbox commands, async events, els commands, receive queue data |
| 7930 | * and fcp commands) |
| 7931 | */ |
| 7932 | |
| 7933 | if (mbox_pending) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7934 | /* process and rearm the EQ */ |
| 7935 | lpfc_sli4_process_eq(phba, fpeq); |
| 7936 | else |
| 7937 | /* Always clear and re-arm the EQ */ |
| 7938 | sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7939 | |
| 7940 | return mbox_pending; |
| 7941 | |
| 7942 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7943 | |
| 7944 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7945 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7946 | * @phba: Pointer to HBA context object. |
| 7947 | * |
| 7948 | * This function is called from worker thread when a mailbox command times out. |
| 7949 | * The caller is not required to hold any locks. This function will reset the |
| 7950 | * HBA and recover all the pending commands. |
| 7951 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7952 | void |
| 7953 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 7954 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7955 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7956 | MAILBOX_t *mb = NULL; |
| 7957 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7958 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7959 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7960 | /* If the mailbox completed, process the completion and return */ |
| 7961 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 7962 | return; |
| 7963 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7964 | if (pmbox != NULL) |
| 7965 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7966 | /* Check the pmbox pointer first. There is a race condition |
| 7967 | * between the mbox timeout handler getting executed in the |
| 7968 | * worklist and the mailbox actually completing. When this |
| 7969 | * race condition occurs, the mbox_active will be NULL. |
| 7970 | */ |
| 7971 | spin_lock_irq(&phba->hbalock); |
| 7972 | if (pmbox == NULL) { |
| 7973 | lpfc_printf_log(phba, KERN_WARNING, |
| 7974 | LOG_MBOX | LOG_SLI, |
| 7975 | "0353 Active Mailbox cleared - mailbox timeout " |
| 7976 | "exiting\n"); |
| 7977 | spin_unlock_irq(&phba->hbalock); |
| 7978 | return; |
| 7979 | } |
| 7980 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7981 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7982 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 7983 | "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] | 7984 | mb->mbxCommand, |
| 7985 | phba->pport->port_state, |
| 7986 | phba->sli.sli_flag, |
| 7987 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7988 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7989 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7990 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 7991 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7992 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7993 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7994 | spin_lock_irq(&phba->pport->work_port_lock); |
| 7995 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 7996 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 7997 | spin_lock_irq(&phba->hbalock); |
| 7998 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 7999 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8000 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8001 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 8002 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 8003 | |
| 8004 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 8005 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8006 | |
| 8007 | /* Reset the HBA device */ |
| 8008 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8009 | } |
| 8010 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8011 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8012 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8013 | * @phba: Pointer to HBA context object. |
| 8014 | * @pmbox: Pointer to mailbox object. |
| 8015 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8016 | * |
| 8017 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8018 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 8019 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8020 | * The mailbox command can be submitted in polling mode, in which case |
| 8021 | * this function will wait in a polling loop for the completion of the |
| 8022 | * mailbox. |
| 8023 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 8024 | * function will submit the command and returns immediately without waiting |
| 8025 | * for the mailbox completion. The no_wait is supported only when HBA |
| 8026 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 8027 | * The SLI interface allows only one mailbox pending at a time. If the |
| 8028 | * mailbox is issued in polling mode and there is already a mailbox |
| 8029 | * pending, then the function will return an error. If the mailbox is issued |
| 8030 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 8031 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 8032 | * The sli layer owns the mailbox object until the completion of mailbox |
| 8033 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 8034 | * return codes the caller owns the mailbox command after the return of |
| 8035 | * the function. |
| 8036 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8037 | static int |
| 8038 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 8039 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8040 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8041 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8042 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8043 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8044 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8045 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8046 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8047 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8048 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8049 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8050 | int processing_queue = 0; |
| 8051 | |
| 8052 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8053 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 8054 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8055 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8056 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8057 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8058 | return MBX_SUCCESS; |
| 8059 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8060 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8061 | pmbox = lpfc_mbox_get(phba); |
| 8062 | if (!pmbox) { |
| 8063 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8064 | return MBX_SUCCESS; |
| 8065 | } |
| 8066 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8067 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8068 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8069 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8070 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8071 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8072 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8073 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8074 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8075 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8076 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8077 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8078 | } |
| 8079 | } |
| 8080 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8081 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8082 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 8083 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8084 | goto out_not_finished; |
| 8085 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8086 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8087 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8088 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 8089 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8090 | goto out_not_finished; |
| 8091 | } |
| 8092 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8093 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8094 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8095 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8096 | status = MBX_SUCCESS; |
| 8097 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8098 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 8099 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8100 | |
| 8101 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8102 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8103 | "(%d):0311 Mailbox command x%x cannot " |
| 8104 | "issue Data: x%x x%x\n", |
| 8105 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8106 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8107 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8108 | } |
| 8109 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8110 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8111 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 8112 | !(hc_copy & HC_MBINT_ENA)) { |
| 8113 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8114 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8115 | "(%d):2528 Mailbox command x%x cannot " |
| 8116 | "issue Data: x%x x%x\n", |
| 8117 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8118 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8119 | goto out_not_finished; |
| 8120 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 8121 | } |
| 8122 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8123 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8124 | /* Polling for a mbox command when another one is already active |
| 8125 | * is not allowed in SLI. Also, the driver must have established |
| 8126 | * SLI2 mode to queue and process multiple mbox commands. |
| 8127 | */ |
| 8128 | |
| 8129 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8130 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8131 | |
| 8132 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8133 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8134 | "(%d):2529 Mailbox command x%x " |
| 8135 | "cannot issue Data: x%x x%x\n", |
| 8136 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8137 | pmbox->u.mb.mbxCommand, |
| 8138 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8139 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8140 | } |
| 8141 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8142 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8143 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8144 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8145 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8146 | "(%d):2530 Mailbox command x%x " |
| 8147 | "cannot issue Data: x%x x%x\n", |
| 8148 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8149 | pmbox->u.mb.mbxCommand, |
| 8150 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8151 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8152 | } |
| 8153 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8154 | /* Another mailbox command is still being processed, queue this |
| 8155 | * command to be processed later. |
| 8156 | */ |
| 8157 | lpfc_mbox_put(phba, pmbox); |
| 8158 | |
| 8159 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8160 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8161 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8162 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8163 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8164 | mbx->mbxCommand, |
| 8165 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8166 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8167 | |
| 8168 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8169 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8170 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8171 | if (pmbox->vport) { |
| 8172 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8173 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8174 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8175 | (uint32_t)mbx->mbxCommand, |
| 8176 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8177 | } |
| 8178 | else { |
| 8179 | lpfc_debugfs_disc_trc(phba->pport, |
| 8180 | LPFC_DISC_TRC_MBOX, |
| 8181 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8182 | (uint32_t)mbx->mbxCommand, |
| 8183 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8184 | } |
| 8185 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8186 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8187 | } |
| 8188 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8189 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8190 | |
| 8191 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 8192 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8193 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8194 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8195 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8196 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8197 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8198 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8199 | "(%d):2531 Mailbox command x%x " |
| 8200 | "cannot issue Data: x%x x%x\n", |
| 8201 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8202 | pmbox->u.mb.mbxCommand, |
| 8203 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8204 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8205 | } |
| 8206 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8207 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8208 | 1000); |
| 8209 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8210 | } |
| 8211 | |
| 8212 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8213 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8214 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8215 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8216 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8217 | mbx->mbxCommand, |
| 8218 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8219 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8220 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8221 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8222 | if (pmbox->vport) { |
| 8223 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8224 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8225 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8226 | (uint32_t)mbx->mbxCommand, |
| 8227 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8228 | } |
| 8229 | else { |
| 8230 | lpfc_debugfs_disc_trc(phba->pport, |
| 8231 | LPFC_DISC_TRC_MBOX, |
| 8232 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8233 | (uint32_t)mbx->mbxCommand, |
| 8234 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8235 | } |
| 8236 | } |
| 8237 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8238 | psli->slistat.mbox_cmd++; |
| 8239 | evtctr = psli->slistat.mbox_event; |
| 8240 | |
| 8241 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8242 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8243 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8244 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8245 | /* Populate mbox extension offset word. */ |
| 8246 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8247 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8248 | = (uint8_t *)phba->mbox_ext |
| 8249 | - (uint8_t *)phba->mbox; |
| 8250 | } |
| 8251 | |
| 8252 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8253 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) { |
| 8254 | lpfc_sli_pcimem_bcopy(pmbox->ctx_buf, |
| 8255 | (uint8_t *)phba->mbox_ext, |
| 8256 | pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8257 | } |
| 8258 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8259 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8260 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8261 | /* Populate mbox extension offset word. */ |
| 8262 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8263 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8264 | = MAILBOX_HBA_EXT_OFFSET; |
| 8265 | |
| 8266 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8267 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8268 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 8269 | MAILBOX_HBA_EXT_OFFSET, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8270 | pmbox->ctx_buf, pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8271 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8272 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8273 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8274 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 8275 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8276 | |
| 8277 | /* First copy mbox command data to HBA SLIM, skip past first |
| 8278 | word */ |
| 8279 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8280 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8281 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 8282 | |
| 8283 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8284 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8285 | to_slim = phba->MBslimaddr; |
| 8286 | writel(ldata, to_slim); |
| 8287 | readl(to_slim); /* flush */ |
| 8288 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8289 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8290 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8291 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8292 | } |
| 8293 | |
| 8294 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8295 | |
| 8296 | switch (flag) { |
| 8297 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8298 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8299 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8300 | /* Interrupt board to do it */ |
| 8301 | writel(CA_MBATT, phba->CAregaddr); |
| 8302 | readl(phba->CAregaddr); /* flush */ |
| 8303 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8304 | break; |
| 8305 | |
| 8306 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8307 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8308 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8309 | /* Interrupt board to do it */ |
| 8310 | writel(CA_MBATT, phba->CAregaddr); |
| 8311 | readl(phba->CAregaddr); /* flush */ |
| 8312 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8313 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8314 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8315 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8316 | word0 = le32_to_cpu(word0); |
| 8317 | } else { |
| 8318 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8319 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 8320 | spin_unlock_irqrestore(&phba->hbalock, |
| 8321 | drvr_flag); |
| 8322 | goto out_not_finished; |
| 8323 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8324 | } |
| 8325 | |
| 8326 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8327 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8328 | spin_unlock_irqrestore(&phba->hbalock, |
| 8329 | drvr_flag); |
| 8330 | goto out_not_finished; |
| 8331 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8332 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8333 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8334 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8335 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8336 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 8337 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8338 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8339 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8340 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8341 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8342 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8343 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8344 | } |
| 8345 | |
| 8346 | /* Check if we took a mbox interrupt while we were |
| 8347 | polling */ |
| 8348 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 8349 | && (evtctr != psli->slistat.mbox_event)) |
| 8350 | break; |
| 8351 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8352 | if (i++ > 10) { |
| 8353 | spin_unlock_irqrestore(&phba->hbalock, |
| 8354 | drvr_flag); |
| 8355 | msleep(1); |
| 8356 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8357 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8358 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8359 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8360 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8361 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8362 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8363 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8364 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8365 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8366 | /* Check real SLIM for any errors */ |
| 8367 | slimword0 = readl(phba->MBslimaddr); |
| 8368 | slimmb = (MAILBOX_t *) & slimword0; |
| 8369 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 8370 | && slimmb->mbxStatus) { |
| 8371 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8372 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8373 | word0 = slimword0; |
| 8374 | } |
| 8375 | } |
| 8376 | } else { |
| 8377 | /* First copy command data */ |
| 8378 | word0 = readl(phba->MBslimaddr); |
| 8379 | } |
| 8380 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8381 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8382 | spin_unlock_irqrestore(&phba->hbalock, |
| 8383 | drvr_flag); |
| 8384 | goto out_not_finished; |
| 8385 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8386 | } |
| 8387 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8388 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8389 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8390 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 8391 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8392 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8393 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8394 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8395 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8396 | pmbox->out_ext_byte_len); |
| 8397 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8398 | } else { |
| 8399 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8400 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8401 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8402 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8403 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
| 8404 | lpfc_memcpy_from_slim( |
| 8405 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8406 | phba->MBslimaddr + |
| 8407 | MAILBOX_HBA_EXT_OFFSET, |
| 8408 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8409 | } |
| 8410 | } |
| 8411 | |
| 8412 | writel(HA_MBATT, phba->HAregaddr); |
| 8413 | readl(phba->HAregaddr); /* flush */ |
| 8414 | |
| 8415 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8416 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8417 | } |
| 8418 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8419 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8420 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8421 | |
| 8422 | out_not_finished: |
| 8423 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8424 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8425 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 8426 | } |
| 8427 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8428 | } |
| 8429 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8430 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8431 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 8432 | * @phba: Pointer to HBA context object. |
| 8433 | * |
| 8434 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 8435 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 8436 | * possible outstanding mailbox command before return. |
| 8437 | * |
| 8438 | * Returns: |
| 8439 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 8440 | * the outstanding mailbox command timed out. |
| 8441 | **/ |
| 8442 | static int |
| 8443 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 8444 | { |
| 8445 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8446 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8447 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8448 | |
| 8449 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 8450 | spin_lock_irq(&phba->hbalock); |
| 8451 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8452 | /* Determine how long we might wait for the active mailbox |
| 8453 | * command to be gracefully completed by firmware. |
| 8454 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8455 | if (phba->sli.mbox_active) |
| 8456 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 8457 | phba->sli.mbox_active) * |
| 8458 | 1000) + jiffies; |
| 8459 | spin_unlock_irq(&phba->hbalock); |
| 8460 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8461 | /* Make sure the mailbox is really active */ |
| 8462 | if (timeout) |
| 8463 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 8464 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8465 | /* Wait for the outstnading mailbox command to complete */ |
| 8466 | while (phba->sli.mbox_active) { |
| 8467 | /* Check active mailbox complete status every 2ms */ |
| 8468 | msleep(2); |
| 8469 | if (time_after(jiffies, timeout)) { |
| 8470 | /* Timeout, marked the outstanding cmd not complete */ |
| 8471 | rc = 1; |
| 8472 | break; |
| 8473 | } |
| 8474 | } |
| 8475 | |
| 8476 | /* Can not cleanly block async mailbox command, fails it */ |
| 8477 | if (rc) { |
| 8478 | spin_lock_irq(&phba->hbalock); |
| 8479 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8480 | spin_unlock_irq(&phba->hbalock); |
| 8481 | } |
| 8482 | return rc; |
| 8483 | } |
| 8484 | |
| 8485 | /** |
| 8486 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 8487 | * @phba: Pointer to HBA context object. |
| 8488 | * |
| 8489 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 8490 | * commands from the driver internal pending mailbox queue. It makes sure |
| 8491 | * that there is no outstanding mailbox command before resuming posting |
| 8492 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 8493 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 8494 | * mailbox command posting. |
| 8495 | **/ |
| 8496 | static void |
| 8497 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 8498 | { |
| 8499 | struct lpfc_sli *psli = &phba->sli; |
| 8500 | |
| 8501 | spin_lock_irq(&phba->hbalock); |
| 8502 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8503 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 8504 | spin_unlock_irq(&phba->hbalock); |
| 8505 | return; |
| 8506 | } |
| 8507 | |
| 8508 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 8509 | * successful or timeout, after timing-out the outstanding mailbox |
| 8510 | * command shall always be removed, so just unblock posting async |
| 8511 | * mailbox command and resume |
| 8512 | */ |
| 8513 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8514 | spin_unlock_irq(&phba->hbalock); |
| 8515 | |
| 8516 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 8517 | lpfc_worker_wake_up(phba); |
| 8518 | } |
| 8519 | |
| 8520 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8521 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 8522 | * @phba: Pointer to HBA context object. |
| 8523 | * @mboxq: Pointer to mailbox object. |
| 8524 | * |
| 8525 | * The function waits for the bootstrap mailbox register ready bit from |
| 8526 | * port for twice the regular mailbox command timeout value. |
| 8527 | * |
| 8528 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 8529 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 8530 | **/ |
| 8531 | static int |
| 8532 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8533 | { |
| 8534 | uint32_t db_ready; |
| 8535 | unsigned long timeout; |
| 8536 | struct lpfc_register bmbx_reg; |
| 8537 | |
| 8538 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 8539 | * 1000) + jiffies; |
| 8540 | |
| 8541 | do { |
| 8542 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 8543 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 8544 | if (!db_ready) |
James Smart | e2ffe4d | 2019-03-12 16:30:15 -0700 | [diff] [blame] | 8545 | mdelay(2); |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8546 | |
| 8547 | if (time_after(jiffies, timeout)) |
| 8548 | return MBXERR_ERROR; |
| 8549 | } while (!db_ready); |
| 8550 | |
| 8551 | return 0; |
| 8552 | } |
| 8553 | |
| 8554 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8555 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 8556 | * @phba: Pointer to HBA context object. |
| 8557 | * @mboxq: Pointer to mailbox object. |
| 8558 | * |
| 8559 | * The function posts a mailbox to the port. The mailbox is expected |
| 8560 | * to be comletely filled in and ready for the port to operate on it. |
| 8561 | * This routine executes a synchronous completion operation on the |
| 8562 | * mailbox by polling for its completion. |
| 8563 | * |
| 8564 | * The caller must not be holding any locks when calling this routine. |
| 8565 | * |
| 8566 | * Returns: |
| 8567 | * MBX_SUCCESS - mailbox posted successfully |
| 8568 | * Any of the MBX error values. |
| 8569 | **/ |
| 8570 | static int |
| 8571 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8572 | { |
| 8573 | int rc = MBX_SUCCESS; |
| 8574 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8575 | uint32_t mcqe_status; |
| 8576 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8577 | struct lpfc_sli *psli = &phba->sli; |
| 8578 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 8579 | struct lpfc_bmbx_create *mbox_rgn; |
| 8580 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8581 | |
| 8582 | /* |
| 8583 | * Only one mailbox can be active to the bootstrap mailbox region |
| 8584 | * at a time and there is no queueing provided. |
| 8585 | */ |
| 8586 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8587 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8588 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8589 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8590 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8591 | "cannot issue Data: x%x x%x\n", |
| 8592 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8593 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8594 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8595 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8596 | psli->sli_flag, MBX_POLL); |
| 8597 | return MBXERR_ERROR; |
| 8598 | } |
| 8599 | /* The server grabs the token and owns it until release */ |
| 8600 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8601 | phba->sli.mbox_active = mboxq; |
| 8602 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8603 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8604 | /* wait for bootstrap mbox register for readyness */ |
| 8605 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8606 | if (rc) |
| 8607 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8608 | /* |
| 8609 | * Initialize the bootstrap memory region to avoid stale data areas |
| 8610 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 8611 | * the bmbx mailbox region. |
| 8612 | */ |
| 8613 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 8614 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8615 | lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 8616 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8617 | |
| 8618 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 8619 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8620 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 8621 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8622 | /* wait for bootstrap mbox register for hi-address write done */ |
| 8623 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8624 | if (rc) |
| 8625 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8626 | |
| 8627 | /* Post the low mailbox dma address to the port. */ |
| 8628 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8629 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8630 | /* wait for bootstrap mbox register for low address write done */ |
| 8631 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8632 | if (rc) |
| 8633 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8634 | |
| 8635 | /* |
| 8636 | * Read the CQ to ensure the mailbox has completed. |
| 8637 | * If so, update the mailbox status so that the upper layers |
| 8638 | * can complete the request normally. |
| 8639 | */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8640 | lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 8641 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8642 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8643 | lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 8644 | sizeof(struct lpfc_mcqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8645 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8646 | /* |
| 8647 | * When the CQE status indicates a failure and the mailbox status |
| 8648 | * indicates success then copy the CQE status into the mailbox status |
| 8649 | * (and prefix it with x4000). |
| 8650 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8651 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8652 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 8653 | bf_set(lpfc_mqe_status, mb, |
| 8654 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8655 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8656 | } else |
| 8657 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8658 | |
| 8659 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8660 | "(%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] | 8661 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 8662 | " 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] | 8663 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 8664 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8665 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8666 | bf_get(lpfc_mqe_status, mb), |
| 8667 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 8668 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 8669 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 8670 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 8671 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 8672 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 8673 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 8674 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 8675 | mboxq->mcqe.trailer); |
| 8676 | exit: |
| 8677 | /* We are holding the token, no needed for lock when release */ |
| 8678 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8679 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8680 | phba->sli.mbox_active = NULL; |
| 8681 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8682 | return rc; |
| 8683 | } |
| 8684 | |
| 8685 | /** |
| 8686 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 8687 | * @phba: Pointer to HBA context object. |
| 8688 | * @pmbox: Pointer to mailbox object. |
| 8689 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8690 | * |
| 8691 | * This function is called by discovery code and HBA management code to submit |
| 8692 | * a mailbox command to firmware with SLI-4 interface spec. |
| 8693 | * |
| 8694 | * Return codes the caller owns the mailbox command after the return of the |
| 8695 | * function. |
| 8696 | **/ |
| 8697 | static int |
| 8698 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 8699 | uint32_t flag) |
| 8700 | { |
| 8701 | struct lpfc_sli *psli = &phba->sli; |
| 8702 | unsigned long iflags; |
| 8703 | int rc; |
| 8704 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 8705 | /* dump from issue mailbox command if setup */ |
| 8706 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 8707 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8708 | rc = lpfc_mbox_dev_check(phba); |
| 8709 | if (unlikely(rc)) { |
| 8710 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8711 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8712 | "cannot issue Data: x%x x%x\n", |
| 8713 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8714 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8715 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8716 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8717 | psli->sli_flag, flag); |
| 8718 | goto out_not_finished; |
| 8719 | } |
| 8720 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8721 | /* Detect polling mode and jump to a handler */ |
| 8722 | if (!phba->sli4_hba.intr_enable) { |
| 8723 | if (flag == MBX_POLL) |
| 8724 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8725 | else |
| 8726 | rc = -EIO; |
| 8727 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8728 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8729 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8730 | "(x%x/x%x) failure: " |
| 8731 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8732 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8733 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8734 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8735 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8736 | mboxq), |
| 8737 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8738 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8739 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8740 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8741 | bf_get(lpfc_mcqe_ext_status, |
| 8742 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8743 | psli->sli_flag, flag); |
| 8744 | return rc; |
| 8745 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8746 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8747 | "(%d):2542 Try to issue mailbox command " |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8748 | "x%x (x%x/x%x) synchronously ahead of async " |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8749 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8750 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8751 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8752 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8753 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8754 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8755 | /* Try to block the asynchronous mailbox posting */ |
| 8756 | rc = lpfc_sli4_async_mbox_block(phba); |
| 8757 | if (!rc) { |
| 8758 | /* Successfully blocked, now issue sync mbox cmd */ |
| 8759 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8760 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8761 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8762 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8763 | "(%d):2597 Sync Mailbox command " |
| 8764 | "x%x (x%x/x%x) failure: " |
| 8765 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8766 | "Data: x%x x%x\n,", |
| 8767 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8768 | mboxq->u.mb.mbxCommand, |
| 8769 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8770 | mboxq), |
| 8771 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8772 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8773 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8774 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8775 | bf_get(lpfc_mcqe_ext_status, |
| 8776 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8777 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8778 | /* Unblock the async mailbox posting afterward */ |
| 8779 | lpfc_sli4_async_mbox_unblock(phba); |
| 8780 | } |
| 8781 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8782 | } |
| 8783 | |
| 8784 | /* Now, interrupt mode asynchrous mailbox command */ |
| 8785 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 8786 | if (rc) { |
| 8787 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8788 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8789 | "cannot issue Data: x%x x%x\n", |
| 8790 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8791 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8792 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8793 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8794 | psli->sli_flag, flag); |
| 8795 | goto out_not_finished; |
| 8796 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8797 | |
| 8798 | /* Put the mailbox command to the driver internal FIFO */ |
| 8799 | psli->slistat.mbox_busy++; |
| 8800 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8801 | lpfc_mbox_put(phba, mboxq); |
| 8802 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8803 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8804 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8805 | "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] | 8806 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 8807 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8808 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8809 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8810 | phba->pport->port_state, |
| 8811 | psli->sli_flag, MBX_NOWAIT); |
| 8812 | /* Wake up worker thread to transport mailbox command from head */ |
| 8813 | lpfc_worker_wake_up(phba); |
| 8814 | |
| 8815 | return MBX_BUSY; |
| 8816 | |
| 8817 | out_not_finished: |
| 8818 | return MBX_NOT_FINISHED; |
| 8819 | } |
| 8820 | |
| 8821 | /** |
| 8822 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 8823 | * @phba: Pointer to HBA context object. |
| 8824 | * |
| 8825 | * This function is called by worker thread to send a mailbox command to |
| 8826 | * SLI4 HBA firmware. |
| 8827 | * |
| 8828 | **/ |
| 8829 | int |
| 8830 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 8831 | { |
| 8832 | struct lpfc_sli *psli = &phba->sli; |
| 8833 | LPFC_MBOXQ_t *mboxq; |
| 8834 | int rc = MBX_SUCCESS; |
| 8835 | unsigned long iflags; |
| 8836 | struct lpfc_mqe *mqe; |
| 8837 | uint32_t mbx_cmnd; |
| 8838 | |
| 8839 | /* Check interrupt mode before post async mailbox command */ |
| 8840 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 8841 | return MBX_NOT_FINISHED; |
| 8842 | |
| 8843 | /* Check for mailbox command service token */ |
| 8844 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8845 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8846 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8847 | return MBX_NOT_FINISHED; |
| 8848 | } |
| 8849 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8850 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8851 | return MBX_NOT_FINISHED; |
| 8852 | } |
| 8853 | if (unlikely(phba->sli.mbox_active)) { |
| 8854 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8855 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8856 | "0384 There is pending active mailbox cmd\n"); |
| 8857 | return MBX_NOT_FINISHED; |
| 8858 | } |
| 8859 | /* Take the mailbox command service token */ |
| 8860 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8861 | |
| 8862 | /* Get the next mailbox command from head of queue */ |
| 8863 | mboxq = lpfc_mbox_get(phba); |
| 8864 | |
| 8865 | /* If no more mailbox command waiting for post, we're done */ |
| 8866 | if (!mboxq) { |
| 8867 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8868 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8869 | return MBX_SUCCESS; |
| 8870 | } |
| 8871 | phba->sli.mbox_active = mboxq; |
| 8872 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8873 | |
| 8874 | /* Check device readiness for posting mailbox command */ |
| 8875 | rc = lpfc_mbox_dev_check(phba); |
| 8876 | if (unlikely(rc)) |
| 8877 | /* Driver clean routine will clean up pending mailbox */ |
| 8878 | goto out_not_finished; |
| 8879 | |
| 8880 | /* Prepare the mbox command to be posted */ |
| 8881 | mqe = &mboxq->u.mqe; |
| 8882 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 8883 | |
| 8884 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 8885 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8886 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8887 | |
| 8888 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8889 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8890 | "x%x x%x\n", |
| 8891 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8892 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8893 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8894 | phba->pport->port_state, psli->sli_flag); |
| 8895 | |
| 8896 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 8897 | if (mboxq->vport) { |
| 8898 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 8899 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8900 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 8901 | mbx_cmnd, mqe->un.mb_words[0], |
| 8902 | mqe->un.mb_words[1]); |
| 8903 | } else { |
| 8904 | lpfc_debugfs_disc_trc(phba->pport, |
| 8905 | LPFC_DISC_TRC_MBOX, |
| 8906 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 8907 | mbx_cmnd, mqe->un.mb_words[0], |
| 8908 | mqe->un.mb_words[1]); |
| 8909 | } |
| 8910 | } |
| 8911 | psli->slistat.mbox_cmd++; |
| 8912 | |
| 8913 | /* Post the mailbox command to the port */ |
| 8914 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 8915 | if (rc != MBX_SUCCESS) { |
| 8916 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8917 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8918 | "cannot issue Data: x%x x%x\n", |
| 8919 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8920 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8921 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8922 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8923 | psli->sli_flag, MBX_NOWAIT); |
| 8924 | goto out_not_finished; |
| 8925 | } |
| 8926 | |
| 8927 | return rc; |
| 8928 | |
| 8929 | out_not_finished: |
| 8930 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 8931 | if (phba->sli.mbox_active) { |
| 8932 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8933 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8934 | /* Release the token */ |
| 8935 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8936 | phba->sli.mbox_active = NULL; |
| 8937 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8938 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8939 | |
| 8940 | return MBX_NOT_FINISHED; |
| 8941 | } |
| 8942 | |
| 8943 | /** |
| 8944 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 8945 | * @phba: Pointer to HBA context object. |
| 8946 | * @pmbox: Pointer to mailbox object. |
| 8947 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8948 | * |
| 8949 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 8950 | * the API jump table function pointer from the lpfc_hba struct. |
| 8951 | * |
| 8952 | * Return codes the caller owns the mailbox command after the return of the |
| 8953 | * function. |
| 8954 | **/ |
| 8955 | int |
| 8956 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 8957 | { |
| 8958 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 8959 | } |
| 8960 | |
| 8961 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8962 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8963 | * @phba: The hba struct for which this call is being executed. |
| 8964 | * @dev_grp: The HBA PCI-Device group number. |
| 8965 | * |
| 8966 | * This routine sets up the mbox interface API function jump table in @phba |
| 8967 | * struct. |
| 8968 | * Returns: 0 - success, -ENODEV - failure. |
| 8969 | **/ |
| 8970 | int |
| 8971 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8972 | { |
| 8973 | |
| 8974 | switch (dev_grp) { |
| 8975 | case LPFC_PCI_DEV_LP: |
| 8976 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 8977 | phba->lpfc_sli_handle_slow_ring_event = |
| 8978 | lpfc_sli_handle_slow_ring_event_s3; |
| 8979 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 8980 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 8981 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 8982 | break; |
| 8983 | case LPFC_PCI_DEV_OC: |
| 8984 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 8985 | phba->lpfc_sli_handle_slow_ring_event = |
| 8986 | lpfc_sli_handle_slow_ring_event_s4; |
| 8987 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 8988 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 8989 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 8990 | break; |
| 8991 | default: |
| 8992 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8993 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 8994 | dev_grp); |
| 8995 | return -ENODEV; |
| 8996 | break; |
| 8997 | } |
| 8998 | return 0; |
| 8999 | } |
| 9000 | |
| 9001 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9002 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9003 | * @phba: Pointer to HBA context object. |
| 9004 | * @pring: Pointer to driver SLI ring object. |
| 9005 | * @piocb: Pointer to address of newly added command iocb. |
| 9006 | * |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame^] | 9007 | * This function is called with hbalock held for SLI3 ports or |
| 9008 | * the ring lock held for SLI4 ports to add a command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9009 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 9010 | * to the ring. |
| 9011 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9012 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9013 | __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] | 9014 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9015 | { |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame^] | 9016 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 9017 | lockdep_assert_held(&pring->ring_lock); |
| 9018 | else |
| 9019 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9020 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 9021 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9022 | } |
| 9023 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9024 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9025 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9026 | * @phba: Pointer to HBA context object. |
| 9027 | * @pring: Pointer to driver SLI ring object. |
| 9028 | * @piocb: Pointer to address of newly added command iocb. |
| 9029 | * |
| 9030 | * This function is called with hbalock held before a new |
| 9031 | * iocb is submitted to the firmware. This function checks |
| 9032 | * txq to flush the iocbs in txq to Firmware before |
| 9033 | * submitting new iocbs to the Firmware. |
| 9034 | * If there are iocbs in the txq which need to be submitted |
| 9035 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 9036 | * of the txq after dequeuing it from txq. |
| 9037 | * If there is no iocb in the txq then the function will return |
| 9038 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 9039 | * *piocb to find if there are more commands in the txq. |
| 9040 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9041 | static struct lpfc_iocbq * |
| 9042 | 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] | 9043 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9044 | { |
| 9045 | struct lpfc_iocbq * nextiocb; |
| 9046 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9047 | lockdep_assert_held(&phba->hbalock); |
| 9048 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9049 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 9050 | if (!nextiocb) { |
| 9051 | nextiocb = *piocb; |
| 9052 | *piocb = NULL; |
| 9053 | } |
| 9054 | |
| 9055 | return nextiocb; |
| 9056 | } |
| 9057 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9058 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9059 | * __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] | 9060 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9061 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9062 | * @piocb: Pointer to command iocb. |
| 9063 | * @flag: Flag indicating if this command can be put into txq. |
| 9064 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9065 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 9066 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 9067 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 9068 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 9069 | * this function allows only iocbs for posting buffers. This function finds |
| 9070 | * next available slot in the command ring and posts the command to the |
| 9071 | * available slot and writes the port attention register to request HBA start |
| 9072 | * processing new iocb. If there is no slot available in the ring and |
| 9073 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 9074 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9075 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9076 | * This function is called with hbalock held. The function will return success |
| 9077 | * after it successfully submit the iocb to firmware or after adding to the |
| 9078 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9079 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9080 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9081 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9082 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9083 | { |
| 9084 | struct lpfc_iocbq *nextiocb; |
| 9085 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9086 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9087 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9088 | lockdep_assert_held(&phba->hbalock); |
| 9089 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9090 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 9091 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 9092 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 9093 | lpfc_printf_log(phba, KERN_ERR, |
| 9094 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9095 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9096 | piocb->iocb.ulpCommand); |
| 9097 | dump_stack(); |
| 9098 | return IOCB_ERROR; |
| 9099 | } |
| 9100 | |
| 9101 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9102 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 9103 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 9104 | return IOCB_ERROR; |
| 9105 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9106 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 9107 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 9108 | return IOCB_ERROR; |
| 9109 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9110 | /* |
| 9111 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 9112 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9113 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9114 | return IOCB_ERROR; |
| 9115 | |
| 9116 | /* |
| 9117 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9118 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9119 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9120 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9121 | goto iocb_busy; |
| 9122 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9123 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9124 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9125 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9126 | * can be issued if the link is not up. |
| 9127 | */ |
| 9128 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9129 | case CMD_GEN_REQUEST64_CR: |
| 9130 | case CMD_GEN_REQUEST64_CX: |
| 9131 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 9132 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9133 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9134 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 9135 | MENLO_TRANSPORT_TYPE)) |
| 9136 | |
| 9137 | goto iocb_busy; |
| 9138 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9139 | case CMD_QUE_RING_BUF_CN: |
| 9140 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9141 | /* |
| 9142 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 9143 | * completion, iocb_cmpl MUST be 0. |
| 9144 | */ |
| 9145 | if (piocb->iocb_cmpl) |
| 9146 | piocb->iocb_cmpl = NULL; |
| 9147 | /*FALLTHROUGH*/ |
| 9148 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9149 | case CMD_CLOSE_XRI_CN: |
| 9150 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9151 | break; |
| 9152 | default: |
| 9153 | goto iocb_busy; |
| 9154 | } |
| 9155 | |
| 9156 | /* |
| 9157 | * For FCP commands, we must be in a state where we can process link |
| 9158 | * attention events. |
| 9159 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9160 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9161 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9162 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9163 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9164 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9165 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 9166 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 9167 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 9168 | |
| 9169 | if (iocb) |
| 9170 | lpfc_sli_update_ring(phba, pring); |
| 9171 | else |
| 9172 | lpfc_sli_update_full_ring(phba, pring); |
| 9173 | |
| 9174 | if (!piocb) |
| 9175 | return IOCB_SUCCESS; |
| 9176 | |
| 9177 | goto out_busy; |
| 9178 | |
| 9179 | iocb_busy: |
| 9180 | pring->stats.iocb_cmd_delay++; |
| 9181 | |
| 9182 | out_busy: |
| 9183 | |
| 9184 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9185 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9186 | return IOCB_SUCCESS; |
| 9187 | } |
| 9188 | |
| 9189 | return IOCB_BUSY; |
| 9190 | } |
| 9191 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9192 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9193 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 9194 | * @phba: Pointer to HBA context object. |
| 9195 | * @piocb: Pointer to command iocb. |
| 9196 | * @sglq: Pointer to the scatter gather queue object. |
| 9197 | * |
| 9198 | * This routine converts the bpl or bde that is in the IOCB |
| 9199 | * to a sgl list for the sli4 hardware. The physical address |
| 9200 | * of the bpl/bde is converted back to a virtual address. |
| 9201 | * If the IOCB contains a BPL then the list of BDE's is |
| 9202 | * converted to sli4_sge's. If the IOCB contains a single |
| 9203 | * BDE then it is converted to a single sli_sge. |
| 9204 | * The IOCB is still in cpu endianess so the contents of |
| 9205 | * the bpl can be used without byte swapping. |
| 9206 | * |
| 9207 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 9208 | **/ |
| 9209 | static uint16_t |
| 9210 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 9211 | struct lpfc_sglq *sglq) |
| 9212 | { |
| 9213 | uint16_t xritag = NO_XRI; |
| 9214 | struct ulp_bde64 *bpl = NULL; |
| 9215 | struct ulp_bde64 bde; |
| 9216 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9217 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9218 | IOCB_t *icmd; |
| 9219 | int numBdes = 0; |
| 9220 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9221 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 9222 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9223 | |
| 9224 | if (!piocbq || !sglq) |
| 9225 | return xritag; |
| 9226 | |
| 9227 | sgl = (struct sli4_sge *)sglq->sgl; |
| 9228 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9229 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 9230 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9231 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 9232 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 9233 | sizeof(struct ulp_bde64); |
| 9234 | /* The addrHigh and addrLow fields within the IOCB |
| 9235 | * have not been byteswapped yet so there is no |
| 9236 | * need to swap them back. |
| 9237 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9238 | if (piocbq->context3) |
| 9239 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 9240 | else |
| 9241 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9242 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9243 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9244 | if (!bpl) |
| 9245 | return xritag; |
| 9246 | |
| 9247 | for (i = 0; i < numBdes; i++) { |
| 9248 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9249 | sgl->addr_hi = bpl->addrHigh; |
| 9250 | sgl->addr_lo = bpl->addrLow; |
| 9251 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9252 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9253 | if ((i+1) == numBdes) |
| 9254 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9255 | else |
| 9256 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9257 | /* swap the size field back to the cpu so we |
| 9258 | * can assign it to the sgl. |
| 9259 | */ |
| 9260 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 9261 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9262 | /* The offsets in the sgl need to be accumulated |
| 9263 | * separately for the request and reply lists. |
| 9264 | * The request is always first, the reply follows. |
| 9265 | */ |
| 9266 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 9267 | /* add up the reply sg entries */ |
| 9268 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 9269 | inbound++; |
| 9270 | /* first inbound? reset the offset */ |
| 9271 | if (inbound == 1) |
| 9272 | offset = 0; |
| 9273 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 9274 | bf_set(lpfc_sli4_sge_type, sgl, |
| 9275 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9276 | offset += bde.tus.f.bdeSize; |
| 9277 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9278 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9279 | bpl++; |
| 9280 | sgl++; |
| 9281 | } |
| 9282 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 9283 | /* The addrHigh and addrLow fields of the BDE have not |
| 9284 | * been byteswapped yet so they need to be swapped |
| 9285 | * before putting them in the sgl. |
| 9286 | */ |
| 9287 | sgl->addr_hi = |
| 9288 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 9289 | sgl->addr_lo = |
| 9290 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9291 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9292 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9293 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9294 | sgl->sge_len = |
| 9295 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9296 | } |
| 9297 | return sglq->sli4_xritag; |
| 9298 | } |
| 9299 | |
| 9300 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9301 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 9302 | * @phba: Pointer to HBA context object. |
| 9303 | * @piocb: Pointer to command iocb. |
| 9304 | * @wqe: Pointer to the work queue entry. |
| 9305 | * |
| 9306 | * This routine converts the iocb command to its Work Queue Entry |
| 9307 | * equivalent. The wqe pointer should not have any fields set when |
| 9308 | * this routine is called because it will memcpy over them. |
| 9309 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 9310 | * wqe. |
| 9311 | * |
| 9312 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 9313 | **/ |
| 9314 | static int |
| 9315 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9316 | union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9317 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9318 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9319 | uint8_t ct = 0; |
| 9320 | uint32_t fip; |
| 9321 | uint32_t abort_tag; |
| 9322 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 9323 | uint8_t cmnd; |
| 9324 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9325 | uint16_t abrt_iotag; |
| 9326 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9327 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9328 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9329 | int numBdes, i; |
| 9330 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9331 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9332 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9333 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9334 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9335 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9336 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9337 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9338 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9339 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9340 | command_type = ELS_COMMAND_FIP; |
| 9341 | else |
| 9342 | command_type = ELS_COMMAND_NON_FIP; |
| 9343 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9344 | if (phba->fcp_embed_io) |
| 9345 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9346 | /* Some of the fields are in the right position already */ |
| 9347 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 9348 | /* The ct field has moved so reset */ |
| 9349 | wqe->generic.wqe_com.word7 = 0; |
| 9350 | wqe->generic.wqe_com.word10 = 0; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9351 | |
| 9352 | abort_tag = (uint32_t) iocbq->iotag; |
| 9353 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9354 | /* words0-2 bpl convert bde */ |
| 9355 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9356 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9357 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9358 | bpl = (struct ulp_bde64 *) |
| 9359 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 9360 | if (!bpl) |
| 9361 | return IOCB_ERROR; |
| 9362 | |
| 9363 | /* Should already be byte swapped. */ |
| 9364 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 9365 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 9366 | /* swap the size field back to the cpu so we |
| 9367 | * can assign it to the sgl. |
| 9368 | */ |
| 9369 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9370 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 9371 | total_len = 0; |
| 9372 | for (i = 0; i < numBdes; i++) { |
| 9373 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 9374 | total_len += bde.tus.f.bdeSize; |
| 9375 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9376 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9377 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9378 | |
| 9379 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 9380 | cmnd = iocbq->iocb.ulpCommand; |
| 9381 | |
| 9382 | switch (iocbq->iocb.ulpCommand) { |
| 9383 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 9384 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 9385 | ndlp = iocbq->context_un.ndlp; |
| 9386 | else |
| 9387 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9388 | if (!iocbq->iocb.ulpLe) { |
| 9389 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9390 | "2007 Only Limited Edition cmd Format" |
| 9391 | " supported 0x%x\n", |
| 9392 | iocbq->iocb.ulpCommand); |
| 9393 | return IOCB_ERROR; |
| 9394 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9395 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9396 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9397 | /* Els_reguest64 has a TMO */ |
| 9398 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 9399 | iocbq->iocb.ulpTimeout); |
| 9400 | /* Need a VF for word 4 set the vf bit*/ |
| 9401 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 9402 | /* And a VFID for word 12 */ |
| 9403 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9404 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9405 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9406 | iocbq->iocb.ulpContext); |
| 9407 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 9408 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9409 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9410 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9411 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 9412 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9413 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9414 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9415 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9416 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9417 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9418 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9419 | *pcmd == ELS_CMD_SCR || |
James Smart | f60cb93 | 2019-05-14 14:58:05 -0700 | [diff] [blame] | 9420 | *pcmd == ELS_CMD_RSCN_XMT || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9421 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 9422 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9423 | *pcmd == ELS_CMD_PLOGI)) { |
| 9424 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 9425 | bf_set(els_req64_sid, &wqe->els_req, |
| 9426 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9427 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 9428 | !(phba->fc_topology == |
| 9429 | LPFC_TOPOLOGY_LOOP)) |
| 9430 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9431 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 9432 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 9433 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 9434 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9435 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 9436 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9437 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 9438 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9439 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9440 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 9441 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9442 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 9443 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 9444 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9445 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 9446 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9447 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9448 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9449 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9450 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9451 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 9452 | iocbq->iocb.un.ulpWord[3]); |
| 9453 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9454 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9455 | /* The entire sequence is transmitted for this IOCB */ |
| 9456 | xmit_len = total_len; |
| 9457 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9458 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 9459 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 9460 | /* fall through */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9461 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9462 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 9463 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9464 | /* word4 relative_offset memcpy */ |
| 9465 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9466 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 9467 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 9468 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 9469 | LPFC_WQE_IOD_WRITE); |
| 9470 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 9471 | LPFC_WQE_LENLOC_WORD12); |
| 9472 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9473 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 9474 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9475 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9476 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9477 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 9478 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9479 | /* word4 iocb=rsvd wqe=rsvd */ |
| 9480 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 9481 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9482 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9483 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9484 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 9485 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9486 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 9487 | LPFC_WQE_LENLOC_WORD3); |
| 9488 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9489 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9490 | case CMD_FCP_IWRITE64_CR: |
| 9491 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9492 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9493 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9494 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 9495 | xmit_len + sizeof(struct fcp_rsp)); |
| 9496 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 9497 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9498 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9499 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9500 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 9501 | iocbq->iocb.ulpFCP2Rcvy); |
| 9502 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 9503 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9504 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9505 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 9506 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9507 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9508 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9509 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9510 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9511 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 9512 | if (iocbq->priority) { |
| 9513 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9514 | (iocbq->priority << 1)); |
| 9515 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9516 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9517 | (phba->cfg_XLanePriority << 1)); |
| 9518 | } |
| 9519 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9520 | /* Note, word 10 is already initialized to 0 */ |
| 9521 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9522 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9523 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9524 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); |
| 9525 | else |
| 9526 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 9527 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9528 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9529 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9530 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9531 | struct fcp_cmnd *fcp_cmnd; |
| 9532 | uint32_t *ptr; |
| 9533 | |
| 9534 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9535 | |
| 9536 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9537 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9538 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9539 | |
| 9540 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9541 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9542 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9543 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9544 | wqe->generic.bde.addrHigh = 0; |
| 9545 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9546 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9547 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 9548 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9549 | |
| 9550 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9551 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9552 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9553 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9554 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9555 | case CMD_FCP_IREAD64_CR: |
| 9556 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9557 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9558 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 9559 | xmit_len + sizeof(struct fcp_rsp)); |
| 9560 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 9561 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9562 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9563 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9564 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 9565 | iocbq->iocb.ulpFCP2Rcvy); |
| 9566 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9567 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9568 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 9569 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 9570 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9571 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9572 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9573 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9574 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9575 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 9576 | if (iocbq->priority) { |
| 9577 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9578 | (iocbq->priority << 1)); |
| 9579 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9580 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9581 | (phba->cfg_XLanePriority << 1)); |
| 9582 | } |
| 9583 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9584 | /* Note, word 10 is already initialized to 0 */ |
| 9585 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9586 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9587 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9588 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); |
| 9589 | else |
| 9590 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0); |
| 9591 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9592 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9593 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9594 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9595 | struct fcp_cmnd *fcp_cmnd; |
| 9596 | uint32_t *ptr; |
| 9597 | |
| 9598 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9599 | |
| 9600 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9601 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9602 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9603 | |
| 9604 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9605 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9606 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9607 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9608 | wqe->generic.bde.addrHigh = 0; |
| 9609 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9610 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9611 | bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); |
| 9612 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9613 | |
| 9614 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9615 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9616 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9617 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9618 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9619 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9620 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9621 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 9622 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 9623 | xmit_len + sizeof(struct fcp_rsp)); |
| 9624 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 9625 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9626 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9627 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9628 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9629 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 9630 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9631 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 9632 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 9633 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 9634 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 9635 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9636 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9637 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9638 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 9639 | if (iocbq->priority) { |
| 9640 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9641 | (iocbq->priority << 1)); |
| 9642 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9643 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9644 | (phba->cfg_XLanePriority << 1)); |
| 9645 | } |
| 9646 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9647 | /* Note, word 10 is already initialized to 0 */ |
| 9648 | |
| 9649 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9650 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9651 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9652 | struct fcp_cmnd *fcp_cmnd; |
| 9653 | uint32_t *ptr; |
| 9654 | |
| 9655 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9656 | |
| 9657 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9658 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9659 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9660 | |
| 9661 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9662 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9663 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9664 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9665 | wqe->generic.bde.addrHigh = 0; |
| 9666 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9667 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9668 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); |
| 9669 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9670 | |
| 9671 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9672 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9673 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9674 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9675 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9676 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9677 | /* For this command calculate the xmit length of the |
| 9678 | * request bde. |
| 9679 | */ |
| 9680 | xmit_len = 0; |
| 9681 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9682 | sizeof(struct ulp_bde64); |
| 9683 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9684 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9685 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 9686 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9687 | xmit_len += bde.tus.f.bdeSize; |
| 9688 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9689 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 9690 | wqe->gen_req.request_payload_len = xmit_len; |
| 9691 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 9692 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9693 | /* word6 context tag copied in memcpy */ |
| 9694 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 9695 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 9696 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9697 | "2015 Invalid CT %x command 0x%x\n", |
| 9698 | ct, iocbq->iocb.ulpCommand); |
| 9699 | return IOCB_ERROR; |
| 9700 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9701 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 9702 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 9703 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 9704 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 9705 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9706 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 9707 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9708 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9709 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9710 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9711 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9712 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9713 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9714 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9715 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 9716 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9717 | /* word4 */ |
| 9718 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9719 | /* word5 iocb=rsvd wge=did */ |
| 9720 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9721 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 9722 | |
| 9723 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9724 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9725 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9726 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 9727 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9728 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 9729 | iocbq->vport->fc_myDID); |
| 9730 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 9731 | bf_set(wqe_els_did, |
| 9732 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 9733 | } |
| 9734 | } |
| 9735 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9736 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 9737 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9738 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 9739 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9740 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9741 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9742 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9743 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9744 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9745 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9746 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9747 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 9748 | LPFC_WQE_LENLOC_WORD3); |
| 9749 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9750 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 9751 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9752 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9753 | iocbq->context2)->virt); |
| 9754 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9755 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9756 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9757 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9758 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9759 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9760 | phba->vpi_ids[phba->pport->vpi]); |
| 9761 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9762 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9763 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9764 | case CMD_CLOSE_XRI_CN: |
| 9765 | case CMD_ABORT_XRI_CN: |
| 9766 | case CMD_ABORT_XRI_CX: |
| 9767 | /* words 0-2 memcpy should be 0 rserved */ |
| 9768 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9769 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 9770 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 9771 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 9772 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 9773 | } else |
| 9774 | fip = 0; |
| 9775 | |
| 9776 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9777 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9778 | * The link is down, or the command was ELS_FIP |
| 9779 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9780 | * on the wire. |
| 9781 | */ |
| 9782 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 9783 | else |
| 9784 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 9785 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9786 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 9787 | wqe->abort_cmd.rsrvd5 = 0; |
| 9788 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9789 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9790 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9791 | /* |
| 9792 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 9793 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 9794 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9795 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 9796 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 9797 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 9798 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9799 | cmnd = CMD_ABORT_XRI_CX; |
| 9800 | command_type = OTHER_COMMAND; |
| 9801 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9802 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9803 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9804 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9805 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9806 | * we re-construct this WQE here based on information in |
| 9807 | * iocbq from scratch. |
| 9808 | */ |
James Smart | d9f492a | 2019-08-14 16:57:04 -0700 | [diff] [blame] | 9809 | memset(wqe, 0, sizeof(*wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9810 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9811 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9812 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 9813 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9814 | LPFC_ABTS_UNSOL_INT) { |
| 9815 | /* ABTS sent by initiator to CT exchange, the |
| 9816 | * RX_ID field will be filled with the newly |
| 9817 | * allocated responder XRI. |
| 9818 | */ |
| 9819 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 9820 | iocbq->sli4_xritag); |
| 9821 | } else { |
| 9822 | /* ABTS sent by responder to CT exchange, the |
| 9823 | * RX_ID field will be filled with the responder |
| 9824 | * RX_ID from ABTS. |
| 9825 | */ |
| 9826 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9827 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9828 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9829 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 9830 | 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] | 9831 | |
| 9832 | /* Use CT=VPI */ |
| 9833 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 9834 | ndlp->nlp_DID); |
| 9835 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 9836 | iocbq->iocb.ulpContext); |
| 9837 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9838 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9839 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9840 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 9841 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 9842 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9843 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 9844 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9845 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 9846 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 9847 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 9848 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 9849 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 9850 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 9851 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 9852 | } |
| 9853 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9854 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9855 | case CMD_SEND_FRAME: |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 9856 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_SEND_FRAME); |
| 9857 | bf_set(wqe_sof, &wqe->generic.wqe_com, 0x2E); /* SOF byte */ |
| 9858 | bf_set(wqe_eof, &wqe->generic.wqe_com, 0x41); /* EOF byte */ |
| 9859 | bf_set(wqe_lenloc, &wqe->generic.wqe_com, 1); |
| 9860 | bf_set(wqe_xbl, &wqe->generic.wqe_com, 1); |
| 9861 | bf_set(wqe_dbde, &wqe->generic.wqe_com, 1); |
| 9862 | bf_set(wqe_xc, &wqe->generic.wqe_com, 1); |
| 9863 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 0xA); |
| 9864 | 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] | 9865 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9866 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9867 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9868 | case CMD_XRI_ABORTED_CX: |
| 9869 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9870 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 9871 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 9872 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 9873 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 9874 | default: |
| 9875 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9876 | "2014 Invalid command 0x%x\n", |
| 9877 | iocbq->iocb.ulpCommand); |
| 9878 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9879 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9880 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9881 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 9882 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 9883 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 9884 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 9885 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 9886 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 9887 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 9888 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 9889 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9890 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9891 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9892 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 9893 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 9894 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 9895 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 9896 | 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] | 9897 | return 0; |
| 9898 | } |
| 9899 | |
| 9900 | /** |
| 9901 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 9902 | * @phba: Pointer to HBA context object. |
| 9903 | * @ring_number: SLI ring number to issue iocb on. |
| 9904 | * @piocb: Pointer to command iocb. |
| 9905 | * @flag: Flag indicating if this command can be put into txq. |
| 9906 | * |
| 9907 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 9908 | * an iocb command to an HBA with SLI-4 interface spec. |
| 9909 | * |
James Smart | 27f3efd | 2019-10-18 14:18:19 -0700 | [diff] [blame^] | 9910 | * This function is called with ringlock held. The function will return success |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9911 | * after it successfully submit the iocb to firmware or after adding to the |
| 9912 | * txq. |
| 9913 | **/ |
| 9914 | static int |
| 9915 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 9916 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9917 | { |
| 9918 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9919 | union lpfc_wqe128 wqe; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9920 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9921 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9922 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9923 | /* Get the WQ */ |
| 9924 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 9925 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9926 | wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9927 | } else { |
| 9928 | wq = phba->sli4_hba.els_wq; |
| 9929 | } |
| 9930 | |
| 9931 | /* Get corresponding ring */ |
| 9932 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9933 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9934 | /* |
| 9935 | * The WQE can be either 64 or 128 bytes, |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9936 | */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9937 | |
James Smart | cda7fa18 | 2019-03-04 15:15:43 -0800 | [diff] [blame] | 9938 | lockdep_assert_held(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9939 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9940 | if (piocb->sli4_xritag == NO_XRI) { |
| 9941 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9942 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9943 | sglq = NULL; |
| 9944 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9945 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9946 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9947 | __lpfc_sli_ringtx_put(phba, |
| 9948 | pring, piocb); |
| 9949 | return IOCB_SUCCESS; |
| 9950 | } else { |
| 9951 | return IOCB_BUSY; |
| 9952 | } |
| 9953 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9954 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9955 | if (!sglq) { |
| 9956 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9957 | __lpfc_sli_ringtx_put(phba, |
| 9958 | pring, |
| 9959 | piocb); |
| 9960 | return IOCB_SUCCESS; |
| 9961 | } else |
| 9962 | return IOCB_BUSY; |
| 9963 | } |
| 9964 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9965 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9966 | } else if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9967 | /* These IO's already have an XRI and a mapped sgl. */ |
| 9968 | sglq = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9969 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9970 | /* |
| 9971 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9972 | * sglq is on the active list |
| 9973 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 9974 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9975 | if (!sglq) |
| 9976 | return IOCB_ERROR; |
| 9977 | } |
| 9978 | |
| 9979 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9980 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9981 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9982 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9983 | return IOCB_ERROR; |
| 9984 | } |
| 9985 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9986 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9987 | return IOCB_ERROR; |
| 9988 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9989 | if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9990 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9991 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 9992 | |
| 9993 | return 0; |
| 9994 | } |
| 9995 | |
| 9996 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9997 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 9998 | * |
| 9999 | * This routine wraps the actual lockless version for issusing IOCB function |
| 10000 | * pointer from the lpfc_hba struct. |
| 10001 | * |
| 10002 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10003 | * IOCB_ERROR - Error |
| 10004 | * IOCB_SUCCESS - Success |
| 10005 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10006 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10007 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10008 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 10009 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10010 | { |
| 10011 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10012 | } |
| 10013 | |
| 10014 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10015 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10016 | * @phba: The hba struct for which this call is being executed. |
| 10017 | * @dev_grp: The HBA PCI-Device group number. |
| 10018 | * |
| 10019 | * This routine sets up the SLI interface API function jump table in @phba |
| 10020 | * struct. |
| 10021 | * Returns: 0 - success, -ENODEV - failure. |
| 10022 | **/ |
| 10023 | int |
| 10024 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 10025 | { |
| 10026 | |
| 10027 | switch (dev_grp) { |
| 10028 | case LPFC_PCI_DEV_LP: |
| 10029 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 10030 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 10031 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 10032 | case LPFC_PCI_DEV_OC: |
| 10033 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 10034 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 10035 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10036 | default: |
| 10037 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10038 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 10039 | dev_grp); |
| 10040 | return -ENODEV; |
| 10041 | break; |
| 10042 | } |
| 10043 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 10044 | return 0; |
| 10045 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10046 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10047 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10048 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10049 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10050 | * @piocb: Pointer to command iocb. |
| 10051 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10052 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 10053 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10054 | * 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] | 10055 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10056 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10057 | struct lpfc_sli_ring * |
| 10058 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10059 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10060 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10061 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10062 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10063 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 10064 | return NULL; |
| 10065 | /* |
| 10066 | * for abort iocb hba_wqidx should already |
| 10067 | * be setup based on what work queue we used. |
| 10068 | */ |
| 10069 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10070 | lpfc_cmd = (struct lpfc_io_buf *)piocb->context1; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 10071 | piocb->hba_wqidx = lpfc_cmd->hdwq_no; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10072 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10073 | return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10074 | } else { |
| 10075 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 10076 | return NULL; |
| 10077 | piocb->hba_wqidx = 0; |
| 10078 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10079 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10080 | } |
| 10081 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10082 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10083 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10084 | * @phba: Pointer to HBA context object. |
| 10085 | * @pring: Pointer to driver SLI ring object. |
| 10086 | * @piocb: Pointer to command iocb. |
| 10087 | * @flag: Flag indicating if this command can be put into txq. |
| 10088 | * |
| 10089 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 10090 | * function. This function gets the hbalock and calls |
| 10091 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 10092 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 10093 | * functions which do not hold hbalock. |
| 10094 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10095 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10096 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10097 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10098 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10099 | struct lpfc_sli_ring *pring; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10100 | unsigned long iflags; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10101 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10102 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10103 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10104 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 10105 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10106 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10107 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10108 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10109 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10110 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10111 | } else { |
| 10112 | /* For now, SLI2/3 will still use hbalock */ |
| 10113 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10114 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10115 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10116 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10117 | return rc; |
| 10118 | } |
| 10119 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10120 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10121 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10122 | * @phba: Pointer to HBA context object. |
| 10123 | * |
| 10124 | * This function is called while driver attaches with the |
| 10125 | * HBA to setup the extra ring. The extra ring is used |
| 10126 | * only when driver needs to support target mode functionality |
| 10127 | * or IP over FC functionalities. |
| 10128 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10129 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10130 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10131 | static int |
| 10132 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 10133 | { |
| 10134 | struct lpfc_sli *psli; |
| 10135 | struct lpfc_sli_ring *pring; |
| 10136 | |
| 10137 | psli = &phba->sli; |
| 10138 | |
| 10139 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10140 | |
| 10141 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10142 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10143 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10144 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10145 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10146 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10147 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10148 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10149 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10150 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10151 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10152 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10153 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10154 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10155 | |
| 10156 | /* Setup default profile for this ring */ |
| 10157 | pring->iotag_max = 4096; |
| 10158 | pring->num_mask = 1; |
| 10159 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10160 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 10161 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10162 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 10163 | return 0; |
| 10164 | } |
| 10165 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10166 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 10167 | * @phba: Pointer to HBA context object. |
| 10168 | * @iocbq: Pointer to iocb object. |
| 10169 | * |
| 10170 | * The async_event handler calls this routine when it receives |
| 10171 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 10172 | * this event when an Abort Sequence request to an rport fails |
| 10173 | * twice in succession. The abort could be originated by the |
| 10174 | * driver or by the port. The ABTS could have been for an ELS |
| 10175 | * or FCP IO. The port only generates this event when an ABTS |
| 10176 | * fails to complete after one retry. |
| 10177 | */ |
| 10178 | static void |
| 10179 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 10180 | struct lpfc_iocbq *iocbq) |
| 10181 | { |
| 10182 | struct lpfc_nodelist *ndlp = NULL; |
| 10183 | uint16_t rpi = 0, vpi = 0; |
| 10184 | struct lpfc_vport *vport = NULL; |
| 10185 | |
| 10186 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 10187 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 10188 | rpi = iocbq->iocb.ulpContext; |
| 10189 | |
| 10190 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10191 | "3092 Port generated ABTS async event " |
| 10192 | "on vpi %d rpi %d status 0x%x\n", |
| 10193 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 10194 | |
| 10195 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 10196 | if (!vport) |
| 10197 | goto err_exit; |
| 10198 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 10199 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 10200 | goto err_exit; |
| 10201 | |
| 10202 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 10203 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10204 | return; |
| 10205 | |
| 10206 | err_exit: |
| 10207 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10208 | "3095 Event Context not found, no " |
| 10209 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 10210 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 10211 | vpi, rpi); |
| 10212 | } |
| 10213 | |
| 10214 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 10215 | * @phba: pointer to HBA context object. |
| 10216 | * @ndlp: nodelist pointer for the impacted rport. |
| 10217 | * @axri: pointer to the wcqe containing the failed exchange. |
| 10218 | * |
| 10219 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 10220 | * port. The port generates this event when an abort exchange request to an |
| 10221 | * rport fails twice in succession with no reply. The abort could be originated |
| 10222 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 10223 | */ |
| 10224 | void |
| 10225 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 10226 | struct lpfc_nodelist *ndlp, |
| 10227 | struct sli4_wcqe_xri_aborted *axri) |
| 10228 | { |
| 10229 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10230 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10231 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10232 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10233 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10234 | "3115 Node Context not found, driver " |
| 10235 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10236 | return; |
| 10237 | } |
| 10238 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10239 | vport = ndlp->vport; |
| 10240 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10241 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10242 | "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] | 10243 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10244 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10245 | bf_get(lpfc_wcqe_xa_status, axri), |
| 10246 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10247 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10248 | /* |
| 10249 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 10250 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 10251 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 10252 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 10253 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10254 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 10255 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10256 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10257 | } |
| 10258 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10259 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10260 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10261 | * @phba: Pointer to HBA context object. |
| 10262 | * @pring: Pointer to driver SLI ring object. |
| 10263 | * @iocbq: Pointer to iocb object. |
| 10264 | * |
| 10265 | * This function is called by the slow ring event handler |
| 10266 | * function when there is an ASYNC event iocb in the ring. |
| 10267 | * This function is called with no lock held. |
| 10268 | * Currently this function handles only temperature related |
| 10269 | * ASYNC events. The function decodes the temperature sensor |
| 10270 | * event message and posts events for the management applications. |
| 10271 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10272 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10273 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 10274 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 10275 | { |
| 10276 | IOCB_t *icmd; |
| 10277 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10278 | struct temp_event temp_event_data; |
| 10279 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10280 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10281 | |
| 10282 | icmd = &iocbq->iocb; |
| 10283 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10284 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10285 | switch (evt_code) { |
| 10286 | case ASYNC_TEMP_WARN: |
| 10287 | case ASYNC_TEMP_SAFE: |
| 10288 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 10289 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 10290 | if (evt_code == ASYNC_TEMP_WARN) { |
| 10291 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 10292 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10293 | "0347 Adapter is very hot, please take " |
| 10294 | "corrective action. temperature : %d Celsius\n", |
| 10295 | (uint32_t) icmd->ulpContext); |
| 10296 | } else { |
| 10297 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 10298 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10299 | "0340 Adapter temperature is OK now. " |
| 10300 | "temperature : %d Celsius\n", |
| 10301 | (uint32_t) icmd->ulpContext); |
| 10302 | } |
| 10303 | |
| 10304 | /* Send temperature change event to applications */ |
| 10305 | shost = lpfc_shost_from_vport(phba->pport); |
| 10306 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 10307 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 10308 | LPFC_NL_VENDOR_ID); |
| 10309 | break; |
| 10310 | case ASYNC_STATUS_CN: |
| 10311 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 10312 | break; |
| 10313 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10314 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10315 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10316 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 10317 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10318 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 10319 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 10320 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 10321 | "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] | 10322 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10323 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 10324 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 10325 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 10326 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 10327 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10328 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10329 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10330 | } |
| 10331 | |
| 10332 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10333 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10334 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10335 | * @phba: Pointer to HBA context object. |
| 10336 | * |
| 10337 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10338 | * number of iocbs per ring and iotags. This function is |
| 10339 | * called while driver attach to the HBA and before the |
| 10340 | * interrupts are enabled. So there is no need for locking. |
| 10341 | * |
| 10342 | * This function always returns 0. |
| 10343 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10344 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10345 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 10346 | { |
| 10347 | struct lpfc_sli_ring *pring; |
| 10348 | |
| 10349 | pring = phba->sli4_hba.els_wq->pring; |
| 10350 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 10351 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 10352 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10353 | pring->prt[0].type = FC_TYPE_ELS; |
| 10354 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 10355 | lpfc_els_unsol_event; |
| 10356 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 10357 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10358 | pring->prt[1].type = FC_TYPE_ELS; |
| 10359 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 10360 | lpfc_els_unsol_event; |
| 10361 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10362 | /* NameServer Inquiry */ |
| 10363 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 10364 | /* NameServer */ |
| 10365 | pring->prt[2].type = FC_TYPE_CT; |
| 10366 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 10367 | lpfc_ct_unsol_event; |
| 10368 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10369 | /* NameServer response */ |
| 10370 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 10371 | /* NameServer */ |
| 10372 | pring->prt[3].type = FC_TYPE_CT; |
| 10373 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 10374 | lpfc_ct_unsol_event; |
| 10375 | return 0; |
| 10376 | } |
| 10377 | |
| 10378 | /** |
| 10379 | * lpfc_sli_setup - SLI ring setup function |
| 10380 | * @phba: Pointer to HBA context object. |
| 10381 | * |
| 10382 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10383 | * number of iocbs per ring and iotags. This function is |
| 10384 | * called while driver attach to the HBA and before the |
| 10385 | * interrupts are enabled. So there is no need for locking. |
| 10386 | * |
| 10387 | * This function always returns 0. SLI3 only. |
| 10388 | **/ |
| 10389 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10390 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 10391 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10392 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10393 | struct lpfc_sli *psli = &phba->sli; |
| 10394 | struct lpfc_sli_ring *pring; |
| 10395 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10396 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10397 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10398 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10399 | psli->iocbq_lookup = NULL; |
| 10400 | psli->iocbq_lookup_len = 0; |
| 10401 | psli->last_iotag = 0; |
| 10402 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10403 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10404 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10405 | switch (i) { |
| 10406 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 10407 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10408 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 10409 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 10410 | pring->sli.sli3.numCiocb += |
| 10411 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10412 | pring->sli.sli3.numRiocb += |
| 10413 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10414 | pring->sli.sli3.numCiocb += |
| 10415 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10416 | pring->sli.sli3.numRiocb += |
| 10417 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 10418 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10419 | SLI3_IOCB_CMD_SIZE : |
| 10420 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10421 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10422 | SLI3_IOCB_RSP_SIZE : |
| 10423 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10424 | pring->iotag_ctr = 0; |
| 10425 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10426 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10427 | pring->fast_iotag = pring->iotag_max; |
| 10428 | pring->num_mask = 0; |
| 10429 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10430 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10431 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10432 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 10433 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 10434 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10435 | SLI3_IOCB_CMD_SIZE : |
| 10436 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10437 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10438 | SLI3_IOCB_RSP_SIZE : |
| 10439 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10440 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10441 | pring->num_mask = 0; |
| 10442 | break; |
| 10443 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 10444 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10445 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 10446 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 10447 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10448 | SLI3_IOCB_CMD_SIZE : |
| 10449 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10450 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10451 | SLI3_IOCB_RSP_SIZE : |
| 10452 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10453 | pring->fast_iotag = 0; |
| 10454 | pring->iotag_ctr = 0; |
| 10455 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10456 | pring->lpfc_sli_rcv_async_status = |
| 10457 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10458 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10459 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10460 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10461 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10462 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10463 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10464 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10465 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10466 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10467 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10468 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10469 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10470 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10471 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10472 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10473 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10474 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10475 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10476 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10477 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10478 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10479 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10480 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10481 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10482 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10483 | break; |
| 10484 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10485 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 10486 | pring->sli.sli3.sizeCiocb) + |
| 10487 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10488 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10489 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10490 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10491 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 10492 | "SLI2 SLIM Data: x%x x%lx\n", |
| 10493 | phba->brd_no, totiocbsize, |
| 10494 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10495 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10496 | if (phba->cfg_multi_ring_support == 2) |
| 10497 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10498 | |
| 10499 | return 0; |
| 10500 | } |
| 10501 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10502 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10503 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10504 | * @phba: Pointer to HBA context object. |
| 10505 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10506 | * 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] | 10507 | * ring. This function also initializes ring indices of each ring. |
| 10508 | * This function is called during the initialization of the SLI |
| 10509 | * interface of an HBA. |
| 10510 | * This function is called with no lock held and always returns |
| 10511 | * 1. |
| 10512 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10513 | void |
| 10514 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 10515 | { |
| 10516 | struct lpfc_sli *psli; |
| 10517 | struct lpfc_sli_ring *pring; |
| 10518 | int i; |
| 10519 | |
| 10520 | psli = &phba->sli; |
| 10521 | spin_lock_irq(&phba->hbalock); |
| 10522 | INIT_LIST_HEAD(&psli->mboxq); |
| 10523 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 10524 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10525 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10526 | pring = phba->sli4_hba.hdwq[i].io_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10527 | pring->flag = 0; |
| 10528 | pring->ringno = LPFC_FCP_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10529 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10530 | INIT_LIST_HEAD(&pring->txq); |
| 10531 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10532 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10533 | spin_lock_init(&pring->ring_lock); |
| 10534 | } |
| 10535 | pring = phba->sli4_hba.els_wq->pring; |
| 10536 | pring->flag = 0; |
| 10537 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10538 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10539 | INIT_LIST_HEAD(&pring->txq); |
| 10540 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10541 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10542 | spin_lock_init(&pring->ring_lock); |
| 10543 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10544 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10545 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 10546 | pring->flag = 0; |
| 10547 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10548 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10549 | INIT_LIST_HEAD(&pring->txq); |
| 10550 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10551 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10552 | spin_lock_init(&pring->ring_lock); |
| 10553 | } |
| 10554 | |
| 10555 | spin_unlock_irq(&phba->hbalock); |
| 10556 | } |
| 10557 | |
| 10558 | /** |
| 10559 | * lpfc_sli_queue_init - Queue initialization function |
| 10560 | * @phba: Pointer to HBA context object. |
| 10561 | * |
| 10562 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 10563 | * ring. This function also initializes ring indices of each ring. |
| 10564 | * This function is called during the initialization of the SLI |
| 10565 | * interface of an HBA. |
| 10566 | * This function is called with no lock held and always returns |
| 10567 | * 1. |
| 10568 | **/ |
| 10569 | void |
| 10570 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10571 | { |
| 10572 | struct lpfc_sli *psli; |
| 10573 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10574 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10575 | |
| 10576 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10577 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10578 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10579 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10580 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 10581 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10582 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10583 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10584 | pring->sli.sli3.next_cmdidx = 0; |
| 10585 | pring->sli.sli3.local_getidx = 0; |
| 10586 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10587 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 10588 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10589 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10590 | pring->flag = 0; |
| 10591 | INIT_LIST_HEAD(&pring->txq); |
| 10592 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10593 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10594 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10595 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10596 | } |
| 10597 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10598 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10599 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 10600 | * @phba: Pointer to HBA context object. |
| 10601 | * |
| 10602 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 10603 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 10604 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 10605 | * command; and completed mailbox command queue. It is caller's responsibility |
| 10606 | * to make sure that the driver is in the proper state to flush the mailbox |
| 10607 | * command sub-system. Namely, the posting of mailbox commands into the |
| 10608 | * pending mailbox command queue from the various clients must be stopped; |
| 10609 | * either the HBA is in a state that it will never works on the outstanding |
| 10610 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 10611 | * mailbox command has been completed. |
| 10612 | **/ |
| 10613 | static void |
| 10614 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 10615 | { |
| 10616 | LIST_HEAD(completions); |
| 10617 | struct lpfc_sli *psli = &phba->sli; |
| 10618 | LPFC_MBOXQ_t *pmb; |
| 10619 | unsigned long iflag; |
| 10620 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10621 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10622 | local_bh_disable(); |
| 10623 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10624 | /* Flush all the mailbox commands in the mbox system */ |
| 10625 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10626 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10627 | /* The pending mailbox command queue */ |
| 10628 | list_splice_init(&phba->sli.mboxq, &completions); |
| 10629 | /* The outstanding active mailbox command */ |
| 10630 | if (psli->mbox_active) { |
| 10631 | list_add_tail(&psli->mbox_active->list, &completions); |
| 10632 | psli->mbox_active = NULL; |
| 10633 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10634 | } |
| 10635 | /* The completed mailbox command queue */ |
| 10636 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 10637 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10638 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10639 | /* Enable softirqs again, done with phba->hbalock */ |
| 10640 | local_bh_enable(); |
| 10641 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10642 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 10643 | while (!list_empty(&completions)) { |
| 10644 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 10645 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10646 | if (pmb->mbox_cmpl) |
| 10647 | pmb->mbox_cmpl(phba, pmb); |
| 10648 | } |
| 10649 | } |
| 10650 | |
| 10651 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10652 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10653 | * @vport: Pointer to virtual port object. |
| 10654 | * |
| 10655 | * lpfc_sli_host_down is called to clean up the resources |
| 10656 | * associated with a vport before destroying virtual |
| 10657 | * port data structures. |
| 10658 | * This function does following operations: |
| 10659 | * - Free discovery resources associated with this virtual |
| 10660 | * port. |
| 10661 | * - Free iocbs associated with this virtual port in |
| 10662 | * the txq. |
| 10663 | * - Send abort for all iocb commands associated with this |
| 10664 | * vport in txcmplq. |
| 10665 | * |
| 10666 | * This function is called with no lock held and always returns 1. |
| 10667 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10668 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10669 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 10670 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10671 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10672 | struct lpfc_hba *phba = vport->phba; |
| 10673 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10674 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10675 | struct lpfc_sli_ring *pring; |
| 10676 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10677 | int i; |
| 10678 | unsigned long flags = 0; |
| 10679 | uint16_t prev_pring_flag; |
| 10680 | |
| 10681 | lpfc_cleanup_discovery_resources(vport); |
| 10682 | |
| 10683 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10684 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10685 | /* |
| 10686 | * Error everything on the txq since these iocbs |
| 10687 | * have not been given to the FW yet. |
| 10688 | * Also issue ABTS for everything on the txcmplq |
| 10689 | */ |
| 10690 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10691 | for (i = 0; i < psli->num_rings; i++) { |
| 10692 | pring = &psli->sli3_ring[i]; |
| 10693 | prev_pring_flag = pring->flag; |
| 10694 | /* Only slow rings */ |
| 10695 | if (pring->ringno == LPFC_ELS_RING) { |
| 10696 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10697 | /* Set the lpfc data pending flag */ |
| 10698 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10699 | } |
| 10700 | list_for_each_entry_safe(iocb, next_iocb, |
| 10701 | &pring->txq, list) { |
| 10702 | if (iocb->vport != vport) |
| 10703 | continue; |
| 10704 | list_move_tail(&iocb->list, &completions); |
| 10705 | } |
| 10706 | list_for_each_entry_safe(iocb, next_iocb, |
| 10707 | &pring->txcmplq, list) { |
| 10708 | if (iocb->vport != vport) |
| 10709 | continue; |
| 10710 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10711 | } |
| 10712 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10713 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10714 | } else { |
| 10715 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10716 | pring = qp->pring; |
| 10717 | if (!pring) |
| 10718 | continue; |
| 10719 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10720 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10721 | /* Set the lpfc data pending flag */ |
| 10722 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10723 | } |
| 10724 | prev_pring_flag = pring->flag; |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 10725 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10726 | list_for_each_entry_safe(iocb, next_iocb, |
| 10727 | &pring->txq, list) { |
| 10728 | if (iocb->vport != vport) |
| 10729 | continue; |
| 10730 | list_move_tail(&iocb->list, &completions); |
| 10731 | } |
James Smart | 65a3df6 | 2019-09-21 20:58:48 -0700 | [diff] [blame] | 10732 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10733 | list_for_each_entry_safe(iocb, next_iocb, |
| 10734 | &pring->txcmplq, list) { |
| 10735 | if (iocb->vport != vport) |
| 10736 | continue; |
| 10737 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10738 | } |
| 10739 | pring->flag = prev_pring_flag; |
| 10740 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10741 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10742 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10743 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10744 | /* Cancel all the IOCBs from the completions list */ |
| 10745 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10746 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10747 | return 1; |
| 10748 | } |
| 10749 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10750 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10751 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10752 | * @phba: Pointer to HBA context object. |
| 10753 | * |
| 10754 | * This function cleans up all iocb, buffers, mailbox commands |
| 10755 | * while shutting down the HBA. This function is called with no |
| 10756 | * lock held and always returns 1. |
| 10757 | * This function does the following to cleanup driver resources: |
| 10758 | * - Free discovery resources for each virtual port |
| 10759 | * - Cleanup any pending fabric iocbs |
| 10760 | * - Iterate through the iocb txq and free each entry |
| 10761 | * in the list. |
| 10762 | * - Free up any buffer posted to the HBA |
| 10763 | * - Free mailbox commands in the mailbox queue. |
| 10764 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10765 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10766 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10767 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10768 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10769 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10770 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10771 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10772 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10773 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10774 | int i; |
| 10775 | |
| 10776 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10777 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10778 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10779 | lpfc_hba_down_prep(phba); |
| 10780 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10781 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10782 | local_bh_disable(); |
| 10783 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10784 | lpfc_fabric_abort_hba(phba); |
| 10785 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10786 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10787 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10788 | /* |
| 10789 | * Error everything on the txq since these iocbs |
| 10790 | * have not been given to the FW yet. |
| 10791 | */ |
| 10792 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10793 | for (i = 0; i < psli->num_rings; i++) { |
| 10794 | pring = &psli->sli3_ring[i]; |
| 10795 | /* Only slow rings */ |
| 10796 | if (pring->ringno == LPFC_ELS_RING) { |
| 10797 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10798 | /* Set the lpfc data pending flag */ |
| 10799 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10800 | } |
| 10801 | list_splice_init(&pring->txq, &completions); |
| 10802 | } |
| 10803 | } else { |
| 10804 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10805 | pring = qp->pring; |
| 10806 | if (!pring) |
| 10807 | continue; |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 10808 | spin_lock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10809 | list_splice_init(&pring->txq, &completions); |
James Smart | 4b0a42b | 2019-08-14 16:56:42 -0700 | [diff] [blame] | 10810 | spin_unlock(&pring->ring_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10811 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10812 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10813 | /* Set the lpfc data pending flag */ |
| 10814 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10815 | } |
| 10816 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10817 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10818 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10819 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10820 | /* Cancel all the IOCBs from the completions list */ |
| 10821 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10822 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10823 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10824 | spin_lock_irqsave(&phba->hbalock, flags); |
| 10825 | list_splice_init(&phba->elsbuf, &completions); |
| 10826 | phba->elsbuf_cnt = 0; |
| 10827 | phba->elsbuf_prev_cnt = 0; |
| 10828 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10829 | |
| 10830 | while (!list_empty(&completions)) { |
| 10831 | list_remove_head(&completions, buf_ptr, |
| 10832 | struct lpfc_dmabuf, list); |
| 10833 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 10834 | kfree(buf_ptr); |
| 10835 | } |
| 10836 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10837 | /* Enable softirqs again, done with phba->hbalock */ |
| 10838 | local_bh_enable(); |
| 10839 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10840 | /* Return any active mbox cmds */ |
| 10841 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10842 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10843 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10844 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10845 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10846 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10847 | return 1; |
| 10848 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10849 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10850 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10851 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10852 | * @srcp: Source memory pointer. |
| 10853 | * @destp: Destination memory pointer. |
| 10854 | * @cnt: Number of words required to be copied. |
| 10855 | * |
| 10856 | * This function is used for copying data between driver memory |
| 10857 | * and the SLI memory. This function also changes the endianness |
| 10858 | * of each word if native endianness is different from SLI |
| 10859 | * endianness. This function can be called with or without |
| 10860 | * lock. |
| 10861 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10862 | void |
| 10863 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10864 | { |
| 10865 | uint32_t *src = srcp; |
| 10866 | uint32_t *dest = destp; |
| 10867 | uint32_t ldata; |
| 10868 | int i; |
| 10869 | |
| 10870 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 10871 | ldata = *src; |
| 10872 | ldata = le32_to_cpu(ldata); |
| 10873 | *dest = ldata; |
| 10874 | src++; |
| 10875 | dest++; |
| 10876 | } |
| 10877 | } |
| 10878 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10879 | |
| 10880 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 10881 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 10882 | * @srcp: Source memory pointer. |
| 10883 | * @destp: Destination memory pointer. |
| 10884 | * @cnt: Number of words required to be copied. |
| 10885 | * |
| 10886 | * This function is used for copying data between a data structure |
| 10887 | * with big endian representation to local endianness. |
| 10888 | * This function can be called with or without lock. |
| 10889 | **/ |
| 10890 | void |
| 10891 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10892 | { |
| 10893 | uint32_t *src = srcp; |
| 10894 | uint32_t *dest = destp; |
| 10895 | uint32_t ldata; |
| 10896 | int i; |
| 10897 | |
| 10898 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 10899 | ldata = *src; |
| 10900 | ldata = be32_to_cpu(ldata); |
| 10901 | *dest = ldata; |
| 10902 | src++; |
| 10903 | dest++; |
| 10904 | } |
| 10905 | } |
| 10906 | |
| 10907 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10908 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10909 | * @phba: Pointer to HBA context object. |
| 10910 | * @pring: Pointer to driver SLI ring object. |
| 10911 | * @mp: Pointer to driver buffer object. |
| 10912 | * |
| 10913 | * This function is called with no lock held. |
| 10914 | * It always return zero after adding the buffer to the postbufq |
| 10915 | * buffer list. |
| 10916 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10917 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10918 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10919 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10920 | { |
| 10921 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 10922 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10923 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10924 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10925 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10926 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10927 | return 0; |
| 10928 | } |
| 10929 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10930 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10931 | * 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] | 10932 | * @phba: Pointer to HBA context object. |
| 10933 | * |
| 10934 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 10935 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 10936 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 10937 | * does not conflict with tags of buffer posted for unsolicited events. |
| 10938 | * The function returns the allocated tag. The function is called with |
| 10939 | * no locks held. |
| 10940 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10941 | uint32_t |
| 10942 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 10943 | { |
| 10944 | spin_lock_irq(&phba->hbalock); |
| 10945 | phba->buffer_tag_count++; |
| 10946 | /* |
| 10947 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 10948 | * a tag assigned by HBQ. |
| 10949 | */ |
| 10950 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 10951 | spin_unlock_irq(&phba->hbalock); |
| 10952 | return phba->buffer_tag_count; |
| 10953 | } |
| 10954 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10955 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10956 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10957 | * @phba: Pointer to HBA context object. |
| 10958 | * @pring: Pointer to driver SLI ring object. |
| 10959 | * @tag: Buffer tag. |
| 10960 | * |
| 10961 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 10962 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 10963 | * iocb is posted to the response ring with the tag of the buffer. |
| 10964 | * This function searches the pring->postbufq list using the tag |
| 10965 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 10966 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 10967 | * buffer is returned to the caller else NULL is returned. |
| 10968 | * This function is called with no lock held. |
| 10969 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10970 | struct lpfc_dmabuf * |
| 10971 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10972 | uint32_t tag) |
| 10973 | { |
| 10974 | struct lpfc_dmabuf *mp, *next_mp; |
| 10975 | struct list_head *slp = &pring->postbufq; |
| 10976 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10977 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10978 | spin_lock_irq(&phba->hbalock); |
| 10979 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10980 | if (mp->buffer_tag == tag) { |
| 10981 | list_del_init(&mp->list); |
| 10982 | pring->postbufq_cnt--; |
| 10983 | spin_unlock_irq(&phba->hbalock); |
| 10984 | return mp; |
| 10985 | } |
| 10986 | } |
| 10987 | |
| 10988 | spin_unlock_irq(&phba->hbalock); |
| 10989 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10990 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 10991 | "ring %d Data x%lx x%px x%px x%x\n", |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10992 | pring->ringno, (unsigned long) tag, |
| 10993 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10994 | |
| 10995 | return NULL; |
| 10996 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10997 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10998 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10999 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11000 | * @phba: Pointer to HBA context object. |
| 11001 | * @pring: Pointer to driver SLI ring object. |
| 11002 | * @phys: DMA address of the buffer. |
| 11003 | * |
| 11004 | * This function searches the buffer list using the dma_address |
| 11005 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 11006 | * corresponding to the dma_address. The function returns the |
| 11007 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 11008 | * This function is called by the ct and els unsolicited event |
| 11009 | * handlers to get the buffer associated with the unsolicited |
| 11010 | * event. |
| 11011 | * |
| 11012 | * This function is called with no lock held. |
| 11013 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11014 | struct lpfc_dmabuf * |
| 11015 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11016 | dma_addr_t phys) |
| 11017 | { |
| 11018 | struct lpfc_dmabuf *mp, *next_mp; |
| 11019 | struct list_head *slp = &pring->postbufq; |
| 11020 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11021 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11022 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11023 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 11024 | if (mp->phys == phys) { |
| 11025 | list_del_init(&mp->list); |
| 11026 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11027 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11028 | return mp; |
| 11029 | } |
| 11030 | } |
| 11031 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11032 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11033 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11034 | "0410 Cannot find virtual addr for mapped buf on " |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11035 | "ring %d Data x%llx x%px x%px x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11036 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11037 | slp->next, slp->prev, pring->postbufq_cnt); |
| 11038 | return NULL; |
| 11039 | } |
| 11040 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11041 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11042 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11043 | * @phba: Pointer to HBA context object. |
| 11044 | * @cmdiocb: Pointer to driver command iocb object. |
| 11045 | * @rspiocb: Pointer to driver response iocb object. |
| 11046 | * |
| 11047 | * This function is the completion handler for the abort iocbs for |
| 11048 | * ELS commands. This function is called from the ELS ring event |
| 11049 | * handler with no lock held. This function frees memory resources |
| 11050 | * associated with the abort iocb. |
| 11051 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11052 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11053 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11054 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11055 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11056 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11057 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11058 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11059 | |
| 11060 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11061 | |
| 11062 | /* |
| 11063 | * Assume that the port already completed and returned, or |
| 11064 | * will return the iocb. Just Log the message. |
| 11065 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11066 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 11067 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 11068 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11069 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11070 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11071 | if (irsp->ulpCommand == CMD_ABORT_XRI_CX && |
| 11072 | irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 11073 | irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) { |
| 11074 | spin_unlock_irq(&phba->hbalock); |
| 11075 | goto release_iocb; |
| 11076 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11077 | if (abort_iotag != 0 && |
| 11078 | abort_iotag <= phba->sli.last_iotag) |
| 11079 | abort_iocb = |
| 11080 | phba->sli.iocbq_lookup[abort_iotag]; |
| 11081 | } else |
| 11082 | /* For sli4 the abort_tag is the XRI, |
| 11083 | * so the abort routine puts the iotag of the iocb |
| 11084 | * being aborted in the context field of the abort |
| 11085 | * IOCB. |
| 11086 | */ |
| 11087 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11088 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11089 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
James Smart | 3235066 | 2019-08-14 16:57:06 -0700 | [diff] [blame] | 11090 | "0327 Cannot abort els iocb x%px " |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11091 | "with tag %x context %x, abort status %x, " |
| 11092 | "abort code %x\n", |
| 11093 | abort_iocb, abort_iotag, abort_context, |
| 11094 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11095 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11096 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11097 | } |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11098 | release_iocb: |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11099 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11100 | return; |
| 11101 | } |
| 11102 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11103 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11104 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11105 | * @phba: Pointer to HBA context object. |
| 11106 | * @cmdiocb: Pointer to driver command iocb object. |
| 11107 | * @rspiocb: Pointer to driver response iocb object. |
| 11108 | * |
| 11109 | * The function is called from SLI ring event handler with no |
| 11110 | * lock held. This function is the completion handler for ELS commands |
| 11111 | * which are aborted. The function frees memory resources used for |
| 11112 | * the aborted ELS commands. |
| 11113 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11114 | static void |
| 11115 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11116 | struct lpfc_iocbq *rspiocb) |
| 11117 | { |
| 11118 | IOCB_t *irsp = &rspiocb->iocb; |
| 11119 | |
| 11120 | /* ELS cmd tag <ulpIoTag> completes */ |
| 11121 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11122 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11123 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11124 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11125 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11126 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 11127 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 11128 | else |
| 11129 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11130 | return; |
| 11131 | } |
| 11132 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11133 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11134 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11135 | * @phba: Pointer to HBA context object. |
| 11136 | * @pring: Pointer to driver SLI ring object. |
| 11137 | * @cmdiocb: Pointer to driver command iocb object. |
| 11138 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11139 | * This function issues an abort iocb for the provided command iocb down to |
| 11140 | * the port. Other than the case the outstanding command iocb is an abort |
| 11141 | * request, this function issues abort out unconditionally. This function is |
| 11142 | * called with hbalock held. The function returns 0 when it fails due to |
| 11143 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11144 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11145 | static int |
| 11146 | 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] | 11147 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11148 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11149 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11150 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11151 | IOCB_t *icmd = NULL; |
| 11152 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11153 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11154 | unsigned long iflags; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11155 | struct lpfc_nodelist *ndlp; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11156 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11157 | lockdep_assert_held(&phba->hbalock); |
| 11158 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11159 | /* |
| 11160 | * There are certain command types we don't want to abort. And we |
| 11161 | * don't want to abort commands that are already in the process of |
| 11162 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11163 | */ |
| 11164 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11165 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11166 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11167 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11168 | return 0; |
| 11169 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11170 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11171 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11172 | if (abtsiocbp == NULL) |
| 11173 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11174 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11175 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11176 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11177 | */ |
| 11178 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11179 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11180 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11181 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11182 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11183 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11184 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11185 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11186 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11187 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11188 | if (pring->ringno == LPFC_ELS_RING) { |
| 11189 | ndlp = (struct lpfc_nodelist *)(cmdiocb->context1); |
| 11190 | iabt->un.acxri.abortContextTag = ndlp->nlp_rpi; |
| 11191 | } |
| 11192 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11193 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11194 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11195 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11196 | /* 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] | 11197 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11198 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 11199 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11200 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 11201 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11202 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11203 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11204 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 11205 | else |
| 11206 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 11207 | |
| 11208 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 11209 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 11210 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11211 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 11212 | "0339 Abort xri x%x, original iotag x%x, " |
| 11213 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11214 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11215 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11216 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11217 | |
| 11218 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11219 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 11220 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11221 | return 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11222 | /* Note: both hbalock and ring_lock need to be set here */ |
| 11223 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11224 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11225 | abtsiocbp, 0); |
| 11226 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 11227 | } else { |
| 11228 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11229 | abtsiocbp, 0); |
| 11230 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11231 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11232 | if (retval) |
| 11233 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11234 | |
| 11235 | /* |
| 11236 | * Caller to this routine should check for IOCB_ERROR |
| 11237 | * and handle it properly. This routine no longer removes |
| 11238 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 11239 | */ |
| 11240 | return retval; |
| 11241 | } |
| 11242 | |
| 11243 | /** |
| 11244 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 11245 | * @phba: Pointer to HBA context object. |
| 11246 | * @pring: Pointer to driver SLI ring object. |
| 11247 | * @cmdiocb: Pointer to driver command iocb object. |
| 11248 | * |
| 11249 | * This function issues an abort iocb for the provided command iocb. In case |
| 11250 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 11251 | * ring. Instead, the callback function shall be changed to those commands |
| 11252 | * so that nothing happens when them finishes. This function is called with |
| 11253 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 11254 | * request. |
| 11255 | **/ |
| 11256 | int |
| 11257 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11258 | struct lpfc_iocbq *cmdiocb) |
| 11259 | { |
| 11260 | struct lpfc_vport *vport = cmdiocb->vport; |
| 11261 | int retval = IOCB_ERROR; |
| 11262 | IOCB_t *icmd = NULL; |
| 11263 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11264 | lockdep_assert_held(&phba->hbalock); |
| 11265 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11266 | /* |
| 11267 | * There are certain command types we don't want to abort. And we |
| 11268 | * don't want to abort commands that are already in the process of |
| 11269 | * being aborted. |
| 11270 | */ |
| 11271 | icmd = &cmdiocb->iocb; |
| 11272 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 11273 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11274 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 11275 | return 0; |
| 11276 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 11277 | if (!pring) { |
| 11278 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11279 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11280 | else |
| 11281 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11282 | goto abort_iotag_exit; |
| 11283 | } |
| 11284 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11285 | /* |
| 11286 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 11287 | * the callback so that nothing happens when it finishes. |
| 11288 | */ |
| 11289 | if ((vport->load_flag & FC_UNLOADING) && |
| 11290 | (pring->ringno == LPFC_ELS_RING)) { |
| 11291 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11292 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11293 | else |
| 11294 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11295 | goto abort_iotag_exit; |
| 11296 | } |
| 11297 | |
| 11298 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 11299 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 11300 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11301 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11302 | /* |
| 11303 | * Caller to this routine should check for IOCB_ERROR |
| 11304 | * and handle it properly. This routine no longer removes |
| 11305 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11306 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11307 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11308 | } |
| 11309 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11310 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11311 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 11312 | * @phba: pointer to lpfc HBA data structure. |
| 11313 | * |
| 11314 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 11315 | **/ |
| 11316 | void |
| 11317 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 11318 | { |
| 11319 | struct lpfc_sli *psli = &phba->sli; |
| 11320 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11321 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11322 | int i; |
| 11323 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11324 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11325 | for (i = 0; i < psli->num_rings; i++) { |
| 11326 | pring = &psli->sli3_ring[i]; |
| 11327 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 11328 | } |
| 11329 | return; |
| 11330 | } |
| 11331 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11332 | pring = qp->pring; |
| 11333 | if (!pring) |
| 11334 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 11335 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11336 | } |
| 11337 | } |
| 11338 | |
| 11339 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11340 | * 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] | 11341 | * @iocbq: Pointer to driver iocb object. |
| 11342 | * @vport: Pointer to driver virtual port object. |
| 11343 | * @tgt_id: SCSI ID of the target. |
| 11344 | * @lun_id: LUN ID of the scsi device. |
| 11345 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 11346 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11347 | * 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] | 11348 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 11349 | * 0 if the filtering criteria is met for the given iocb and will return |
| 11350 | * 1 if the filtering criteria is not met. |
| 11351 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 11352 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 11353 | * lun_id parameter. |
| 11354 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 11355 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 11356 | * parameters. |
| 11357 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 11358 | * given iocb is for the SCSI host associated with the given vport. |
| 11359 | * This function is called with no locks held. |
| 11360 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11361 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11362 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 11363 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11364 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11365 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11366 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11367 | int rc = 1; |
| 11368 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11369 | if (iocbq->vport != vport) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11370 | return rc; |
| 11371 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11372 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 11373 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11374 | return rc; |
| 11375 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11376 | 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] | 11377 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11378 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11379 | return rc; |
| 11380 | |
| 11381 | switch (ctx_cmd) { |
| 11382 | case LPFC_CTX_LUN: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11383 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11384 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 11385 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11386 | rc = 0; |
| 11387 | break; |
| 11388 | case LPFC_CTX_TGT: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11389 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11390 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11391 | rc = 0; |
| 11392 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11393 | case LPFC_CTX_HOST: |
| 11394 | rc = 0; |
| 11395 | break; |
| 11396 | default: |
| 11397 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 11398 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11399 | break; |
| 11400 | } |
| 11401 | |
| 11402 | return rc; |
| 11403 | } |
| 11404 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11405 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11406 | * 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] | 11407 | * @vport: Pointer to virtual port. |
| 11408 | * @tgt_id: SCSI ID of the target. |
| 11409 | * @lun_id: LUN ID of the scsi device. |
| 11410 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11411 | * |
| 11412 | * This function returns number of FCP commands pending for the vport. |
| 11413 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 11414 | * commands pending on the vport associated with SCSI device specified |
| 11415 | * by tgt_id and lun_id parameters. |
| 11416 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 11417 | * commands pending on the vport associated with SCSI target specified |
| 11418 | * by tgt_id parameter. |
| 11419 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 11420 | * commands pending on the vport. |
| 11421 | * This function returns the number of iocbs which satisfy the filter. |
| 11422 | * This function is called without any lock held. |
| 11423 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11424 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11425 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 11426 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11427 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11428 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11429 | struct lpfc_iocbq *iocbq; |
| 11430 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11431 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11432 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11433 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 11434 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11435 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11436 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 11437 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11438 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11439 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11440 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11441 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11442 | return sum; |
| 11443 | } |
| 11444 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11445 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11446 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11447 | * @phba: Pointer to HBA context object |
| 11448 | * @cmdiocb: Pointer to command iocb object. |
| 11449 | * @rspiocb: Pointer to response iocb object. |
| 11450 | * |
| 11451 | * This function is called when an aborted FCP iocb completes. This |
| 11452 | * function is called by the ring event handler with no lock held. |
| 11453 | * This function frees the iocb. |
| 11454 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11455 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11456 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11457 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11458 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11459 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 11460 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11461 | "original iotag x%x, abort cmd iotag x%x " |
| 11462 | "status 0x%x, reason 0x%x\n", |
| 11463 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 11464 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 11465 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 11466 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11467 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11468 | return; |
| 11469 | } |
| 11470 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11471 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11472 | * 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] | 11473 | * @vport: Pointer to virtual port. |
| 11474 | * @pring: Pointer to driver SLI ring object. |
| 11475 | * @tgt_id: SCSI ID of the target. |
| 11476 | * @lun_id: LUN ID of the scsi device. |
| 11477 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11478 | * |
| 11479 | * This function sends an abort command for every SCSI command |
| 11480 | * associated with the given virtual port pending on the ring |
| 11481 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11482 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11483 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11484 | * parameters |
| 11485 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11486 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11487 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11488 | * FCP iocbs associated with virtual port. |
| 11489 | * This function returns number of iocbs it failed to abort. |
| 11490 | * This function is called with no locks held. |
| 11491 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11492 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11493 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11494 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11495 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11496 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11497 | struct lpfc_iocbq *iocbq; |
| 11498 | struct lpfc_iocbq *abtsiocb; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11499 | struct lpfc_sli_ring *pring_s4; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11500 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11501 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11502 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11503 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11504 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11505 | if (phba->hba_flag & HBA_IOQ_FLUSH) |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11506 | return errcnt; |
| 11507 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11508 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11509 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11510 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11511 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11512 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11513 | continue; |
| 11514 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11515 | /* |
| 11516 | * If the iocbq is already being aborted, don't take a second |
| 11517 | * action, but do count it. |
| 11518 | */ |
| 11519 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11520 | continue; |
| 11521 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11522 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11523 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11524 | if (abtsiocb == NULL) { |
| 11525 | errcnt++; |
| 11526 | continue; |
| 11527 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11528 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11529 | /* indicate the IO is being aborted by the driver. */ |
| 11530 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11531 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11532 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11533 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11534 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11535 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11536 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 11537 | else |
| 11538 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11539 | abtsiocb->iocb.ulpLe = 1; |
| 11540 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11541 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11542 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11543 | /* 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] | 11544 | abtsiocb->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11545 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11546 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11547 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11548 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11549 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11550 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11551 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11552 | else |
| 11553 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11554 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11555 | /* Setup callback routine and issue the command. */ |
| 11556 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11557 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11558 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11559 | if (!pring_s4) |
| 11560 | continue; |
| 11561 | ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11562 | abtsiocb, 0); |
| 11563 | } else |
| 11564 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11565 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11566 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11567 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11568 | errcnt++; |
| 11569 | continue; |
| 11570 | } |
| 11571 | } |
| 11572 | |
| 11573 | return errcnt; |
| 11574 | } |
| 11575 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11576 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11577 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 11578 | * @vport: Pointer to virtual port. |
| 11579 | * @pring: Pointer to driver SLI ring object. |
| 11580 | * @tgt_id: SCSI ID of the target. |
| 11581 | * @lun_id: LUN ID of the scsi device. |
| 11582 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11583 | * |
| 11584 | * This function sends an abort command for every SCSI command |
| 11585 | * associated with the given virtual port pending on the ring |
| 11586 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11587 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11588 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11589 | * parameters |
| 11590 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11591 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11592 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11593 | * FCP iocbs associated with virtual port. |
| 11594 | * This function returns number of iocbs it aborted . |
| 11595 | * This function is called with no locks held right after a taskmgmt |
| 11596 | * command is sent. |
| 11597 | **/ |
| 11598 | int |
| 11599 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11600 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 11601 | { |
| 11602 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11603 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11604 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11605 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11606 | struct lpfc_iocbq *iocbq; |
| 11607 | IOCB_t *icmd; |
| 11608 | int sum, i, ret_val; |
| 11609 | unsigned long iflags; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11610 | struct lpfc_sli_ring *pring_s4 = NULL; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11611 | |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11612 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11613 | |
| 11614 | /* all I/Os are in process of being flushed */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11615 | if (phba->hba_flag & HBA_IOQ_FLUSH) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11616 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11617 | return 0; |
| 11618 | } |
| 11619 | sum = 0; |
| 11620 | |
| 11621 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11622 | iocbq = phba->sli.iocbq_lookup[i]; |
| 11623 | |
| 11624 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 11625 | cmd) != 0) |
| 11626 | continue; |
| 11627 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11628 | /* Guard against IO completion being called at same time */ |
| 11629 | lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq); |
| 11630 | spin_lock(&lpfc_cmd->buf_lock); |
| 11631 | |
| 11632 | if (!lpfc_cmd->pCmd) { |
| 11633 | spin_unlock(&lpfc_cmd->buf_lock); |
| 11634 | continue; |
| 11635 | } |
| 11636 | |
| 11637 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11638 | pring_s4 = |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11639 | phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11640 | if (!pring_s4) { |
| 11641 | spin_unlock(&lpfc_cmd->buf_lock); |
| 11642 | continue; |
| 11643 | } |
| 11644 | /* Note: both hbalock and ring_lock must be set here */ |
| 11645 | spin_lock(&pring_s4->ring_lock); |
| 11646 | } |
| 11647 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11648 | /* |
| 11649 | * If the iocbq is already being aborted, don't take a second |
| 11650 | * action, but do count it. |
| 11651 | */ |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11652 | if ((iocbq->iocb_flag & LPFC_DRIVER_ABORTED) || |
| 11653 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
| 11654 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11655 | spin_unlock(&pring_s4->ring_lock); |
| 11656 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11657 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11658 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11659 | |
| 11660 | /* issue ABTS for this IOCB based on iotag */ |
| 11661 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11662 | if (!abtsiocbq) { |
| 11663 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11664 | spin_unlock(&pring_s4->ring_lock); |
| 11665 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11666 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11667 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11668 | |
| 11669 | icmd = &iocbq->iocb; |
| 11670 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11671 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 11672 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11673 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 11674 | iocbq->sli4_xritag; |
| 11675 | else |
| 11676 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 11677 | abtsiocbq->iocb.ulpLe = 1; |
| 11678 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 11679 | abtsiocbq->vport = vport; |
| 11680 | |
| 11681 | /* 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] | 11682 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11683 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11684 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11685 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11686 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11687 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11688 | ndlp = lpfc_cmd->rdata->pnode; |
| 11689 | |
| 11690 | if (lpfc_is_link_up(phba) && |
| 11691 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11692 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11693 | else |
| 11694 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11695 | |
| 11696 | /* Setup callback routine and issue the command. */ |
| 11697 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 11698 | |
| 11699 | /* |
| 11700 | * Indicate the IO is being aborted by the driver and set |
| 11701 | * the caller's flag into the aborted IO. |
| 11702 | */ |
| 11703 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11704 | |
| 11705 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11706 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11707 | abtsiocbq, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11708 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11709 | } else { |
| 11710 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11711 | abtsiocbq, 0); |
| 11712 | } |
| 11713 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11714 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11715 | |
| 11716 | if (ret_val == IOCB_ERROR) |
| 11717 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 11718 | else |
| 11719 | sum++; |
| 11720 | } |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11721 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11722 | return sum; |
| 11723 | } |
| 11724 | |
| 11725 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11726 | * 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] | 11727 | * @phba: Pointer to HBA context object. |
| 11728 | * @cmdiocbq: Pointer to command iocb. |
| 11729 | * @rspiocbq: Pointer to response iocb. |
| 11730 | * |
| 11731 | * This function is the completion handler for iocbs issued using |
| 11732 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 11733 | * ring event handler function without any lock held. This function |
| 11734 | * can be called from both worker thread context and interrupt |
| 11735 | * context. This function also can be called from other thread which |
| 11736 | * cleans up the SLI layer objects. |
| 11737 | * This function copy the contents of the response iocb to the |
| 11738 | * response iocb memory object provided by the caller of |
| 11739 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 11740 | * sleeps for the iocb completion. |
| 11741 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11742 | static void |
| 11743 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 11744 | struct lpfc_iocbq *cmdiocbq, |
| 11745 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11746 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11747 | wait_queue_head_t *pdone_q; |
| 11748 | unsigned long iflags; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11749 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11750 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11751 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11752 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 11753 | |
| 11754 | /* |
| 11755 | * A time out has occurred for the iocb. If a time out |
| 11756 | * completion handler has been supplied, call it. Otherwise, |
| 11757 | * just free the iocbq. |
| 11758 | */ |
| 11759 | |
| 11760 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11761 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 11762 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 11763 | if (cmdiocbq->iocb_cmpl) |
| 11764 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 11765 | else |
| 11766 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 11767 | return; |
| 11768 | } |
| 11769 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11770 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 11771 | if (cmdiocbq->context2 && rspiocbq) |
| 11772 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 11773 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 11774 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11775 | /* Set the exchange busy flag for task management commands */ |
| 11776 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 11777 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11778 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf, |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11779 | cur_iocbq); |
| 11780 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 11781 | } |
| 11782 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11783 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11784 | if (pdone_q) |
| 11785 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11786 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11787 | return; |
| 11788 | } |
| 11789 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11790 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11791 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 11792 | * @phba: Pointer to HBA context object.. |
| 11793 | * @piocbq: Pointer to command iocb. |
| 11794 | * @flag: Flag to test. |
| 11795 | * |
| 11796 | * This routine grabs the hbalock and then test the iocb_flag to |
| 11797 | * see if the passed in flag is set. |
| 11798 | * Returns: |
| 11799 | * 1 if flag is set. |
| 11800 | * 0 if flag is not set. |
| 11801 | **/ |
| 11802 | static int |
| 11803 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 11804 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 11805 | { |
| 11806 | unsigned long iflags; |
| 11807 | int ret; |
| 11808 | |
| 11809 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11810 | ret = piocbq->iocb_flag & flag; |
| 11811 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11812 | return ret; |
| 11813 | |
| 11814 | } |
| 11815 | |
| 11816 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11817 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11818 | * @phba: Pointer to HBA context object.. |
| 11819 | * @pring: Pointer to sli ring. |
| 11820 | * @piocb: Pointer to command iocb. |
| 11821 | * @prspiocbq: Pointer to response iocb. |
| 11822 | * @timeout: Timeout in number of seconds. |
| 11823 | * |
| 11824 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11825 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 11826 | * to handle iocbs which time out. If the field is NULL, the |
| 11827 | * function shall free the iocbq structure. If more clean up is |
| 11828 | * needed, the caller is expected to provide a completion function |
| 11829 | * that will provide the needed clean up. If the iocb command is |
| 11830 | * not completed within timeout seconds, the function will either |
| 11831 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 11832 | * completion function set in the iocb_cmpl field and then return |
| 11833 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 11834 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11835 | * The function waits for the iocb completion using an |
| 11836 | * non-interruptible wait. |
| 11837 | * This function will sleep while waiting for iocb completion. |
| 11838 | * So, this function should not be called from any context which |
| 11839 | * does not allow sleeping. Due to the same reason, this function |
| 11840 | * cannot be called with interrupt disabled. |
| 11841 | * This function assumes that the iocb completions occur while |
| 11842 | * this function sleep. So, this function cannot be called from |
| 11843 | * the thread which process iocb completion for this ring. |
| 11844 | * This function clears the iocb_flag of the iocb object before |
| 11845 | * issuing the iocb and the iocb completion handler sets this |
| 11846 | * flag and wakes this thread when the iocb completes. |
| 11847 | * The contents of the response iocb will be copied to prspiocbq |
| 11848 | * by the completion handler when the command completes. |
| 11849 | * This function returns IOCB_SUCCESS when success. |
| 11850 | * This function is called with no lock held. |
| 11851 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11852 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11853 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11854 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11855 | struct lpfc_iocbq *piocb, |
| 11856 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11857 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11858 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 11859 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11860 | long timeleft, timeout_req = 0; |
| 11861 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11862 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11863 | struct lpfc_iocbq *iocb; |
| 11864 | int txq_cnt = 0; |
| 11865 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11866 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11867 | unsigned long iflags; |
| 11868 | bool iocb_completed = true; |
| 11869 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11870 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 11871 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 11872 | else |
| 11873 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11874 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11875 | * If the caller has provided a response iocbq buffer, then context2 |
| 11876 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11877 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11878 | if (prspiocbq) { |
| 11879 | if (piocb->context2) |
| 11880 | return IOCB_ERROR; |
| 11881 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11882 | } |
| 11883 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11884 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11885 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 11886 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11887 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11888 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11889 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11890 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11891 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11892 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 11893 | writel(creg_val, phba->HCregaddr); |
| 11894 | readl(phba->HCregaddr); /* flush */ |
| 11895 | } |
| 11896 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11897 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 11898 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11899 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 11900 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11901 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11902 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11903 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11904 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11905 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11906 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11907 | /* |
| 11908 | * IOCB timed out. Inform the wake iocb wait |
| 11909 | * completion function and set local status |
| 11910 | */ |
| 11911 | |
| 11912 | iocb_completed = false; |
| 11913 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 11914 | } |
| 11915 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11916 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11917 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11918 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 11919 | /* Note: we are not indicating if the IOCB has a success |
| 11920 | * status or not - that's for the caller to check. |
| 11921 | * IOCB_SUCCESS means just that the command was sent and |
| 11922 | * completed. Not that it completed successfully. |
| 11923 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11924 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11925 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11926 | "0338 IOCB wait timeout error - no " |
| 11927 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11928 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11929 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11930 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11931 | "0330 IOCB wake NOT set, " |
| 11932 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11933 | timeout, (timeleft / jiffies)); |
| 11934 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11935 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11936 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11937 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 11938 | list_for_each_entry(iocb, &pring->txq, list) { |
| 11939 | txq_cnt++; |
| 11940 | } |
| 11941 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 11942 | txcmplq_cnt++; |
| 11943 | } |
| 11944 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11945 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 11946 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 11947 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11948 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11949 | } else { |
| 11950 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11951 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11952 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11953 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11954 | } |
| 11955 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11956 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11957 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11958 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11959 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 11960 | writel(creg_val, phba->HCregaddr); |
| 11961 | readl(phba->HCregaddr); /* flush */ |
| 11962 | } |
| 11963 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11964 | if (prspiocbq) |
| 11965 | piocb->context2 = NULL; |
| 11966 | |
| 11967 | piocb->context_un.wait_queue = NULL; |
| 11968 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11969 | return retval; |
| 11970 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11971 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11972 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11973 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11974 | * @phba: Pointer to HBA context object. |
| 11975 | * @pmboxq: Pointer to driver mailbox object. |
| 11976 | * @timeout: Timeout in number of seconds. |
| 11977 | * |
| 11978 | * This function issues the mailbox to firmware and waits for the |
| 11979 | * mailbox command to complete. If the mailbox command is not |
| 11980 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 11981 | * The function waits for the mailbox completion using an |
| 11982 | * interruptible wait. If the thread is woken up due to a |
| 11983 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 11984 | * should not free the mailbox resources, if this function returns |
| 11985 | * MBX_TIMEOUT. |
| 11986 | * This function will sleep while waiting for mailbox completion. |
| 11987 | * So, this function should not be called from any context which |
| 11988 | * does not allow sleeping. Due to the same reason, this function |
| 11989 | * cannot be called with interrupt disabled. |
| 11990 | * This function assumes that the mailbox completion occurs while |
| 11991 | * this function sleep. So, this function cannot be called from |
| 11992 | * the worker thread which processes mailbox completion. |
| 11993 | * This function is called in the context of HBA management |
| 11994 | * applications. |
| 11995 | * This function returns MBX_SUCCESS when successful. |
| 11996 | * This function is called with no lock held. |
| 11997 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11998 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11999 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12000 | uint32_t timeout) |
| 12001 | { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12002 | struct completion mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12003 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12004 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12005 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 12006 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12007 | /* setup wake call as IOCB callback */ |
| 12008 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12009 | |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12010 | /* setup context3 field to pass wait_queue pointer to wake function */ |
| 12011 | init_completion(&mbox_done); |
| 12012 | pmboxq->context3 = &mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12013 | /* now issue the command */ |
| 12014 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12015 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12016 | wait_for_completion_timeout(&mbox_done, |
| 12017 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12018 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12019 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12020 | pmboxq->context3 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12021 | /* |
| 12022 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 12023 | * else do not free the resources. |
| 12024 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12025 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12026 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12027 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12028 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12029 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12030 | } |
| 12031 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12032 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12033 | return retval; |
| 12034 | } |
| 12035 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12036 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12037 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12038 | * @phba: Pointer to HBA context. |
| 12039 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12040 | * This function is called to shutdown the driver's mailbox sub-system. |
| 12041 | * It first marks the mailbox sub-system is in a block state to prevent |
| 12042 | * the asynchronous mailbox command from issued off the pending mailbox |
| 12043 | * command queue. If the mailbox command sub-system shutdown is due to |
| 12044 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 12045 | * the mailbox sub-system flush routine to forcefully bring down the |
| 12046 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 12047 | * as with offline or HBA function reset), this routine will wait for the |
| 12048 | * outstanding mailbox command to complete before invoking the mailbox |
| 12049 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12050 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12051 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12052 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12053 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12054 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12055 | unsigned long timeout; |
| 12056 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12057 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 12058 | /* delay 100ms for port state */ |
| 12059 | msleep(100); |
| 12060 | lpfc_sli_mbox_sys_flush(phba); |
| 12061 | return; |
| 12062 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12063 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12064 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12065 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 12066 | local_bh_disable(); |
| 12067 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12068 | spin_lock_irq(&phba->hbalock); |
| 12069 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12070 | |
| 12071 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12072 | /* Determine how long we might wait for the active mailbox |
| 12073 | * command to be gracefully completed by firmware. |
| 12074 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12075 | if (phba->sli.mbox_active) |
| 12076 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 12077 | phba->sli.mbox_active) * |
| 12078 | 1000) + jiffies; |
| 12079 | spin_unlock_irq(&phba->hbalock); |
| 12080 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12081 | /* Enable softirqs again, done with phba->hbalock */ |
| 12082 | local_bh_enable(); |
| 12083 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12084 | while (phba->sli.mbox_active) { |
| 12085 | /* Check active mailbox complete status every 2ms */ |
| 12086 | msleep(2); |
| 12087 | if (time_after(jiffies, timeout)) |
| 12088 | /* Timeout, let the mailbox flush routine to |
| 12089 | * forcefully release active mailbox command |
| 12090 | */ |
| 12091 | break; |
| 12092 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12093 | } else { |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12094 | spin_unlock_irq(&phba->hbalock); |
| 12095 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12096 | /* Enable softirqs again, done with phba->hbalock */ |
| 12097 | local_bh_enable(); |
| 12098 | } |
| 12099 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12100 | lpfc_sli_mbox_sys_flush(phba); |
| 12101 | } |
| 12102 | |
| 12103 | /** |
| 12104 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 12105 | * @phba: Pointer to HBA context. |
| 12106 | * |
| 12107 | * This function is called to read the SLI3 device error attention registers |
| 12108 | * for possible error attention events. The caller must hold the hostlock |
| 12109 | * with spin_lock_irq(). |
| 12110 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12111 | * 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] | 12112 | * Register and returns 0 otherwise. |
| 12113 | **/ |
| 12114 | static int |
| 12115 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 12116 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 12117 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12118 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12119 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12120 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12121 | goto unplug_err; |
| 12122 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12123 | if (ha_copy & HA_ERATT) { |
| 12124 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12125 | if (lpfc_sli_read_hs(phba)) |
| 12126 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12127 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12128 | /* Check if there is a deferred error condition is active */ |
| 12129 | if ((HS_FFER1 & phba->work_hs) && |
| 12130 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12131 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12132 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12133 | /* Clear all interrupt enable conditions */ |
| 12134 | writel(0, phba->HCregaddr); |
| 12135 | readl(phba->HCregaddr); |
| 12136 | } |
| 12137 | |
| 12138 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12139 | phba->work_ha |= HA_ERATT; |
| 12140 | /* Indicate polling handles this ERATT */ |
| 12141 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12142 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12143 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12144 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12145 | |
| 12146 | unplug_err: |
| 12147 | /* Set the driver HS work bitmap */ |
| 12148 | phba->work_hs |= UNPLUG_ERR; |
| 12149 | /* Set the driver HA work bitmap */ |
| 12150 | phba->work_ha |= HA_ERATT; |
| 12151 | /* Indicate polling handles this ERATT */ |
| 12152 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12153 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12154 | } |
| 12155 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12156 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12157 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 12158 | * @phba: Pointer to HBA context. |
| 12159 | * |
| 12160 | * This function is called to read the SLI4 device error attention registers |
| 12161 | * for possible error attention events. The caller must hold the hostlock |
| 12162 | * with spin_lock_irq(). |
| 12163 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12164 | * 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] | 12165 | * Register and returns 0 otherwise. |
| 12166 | **/ |
| 12167 | static int |
| 12168 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 12169 | { |
| 12170 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12171 | uint32_t if_type, portsmphr; |
| 12172 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12173 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12174 | /* |
| 12175 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12176 | * registers for error attention. This can be changed later. |
| 12177 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12178 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 12179 | switch (if_type) { |
| 12180 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12181 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 12182 | &uerr_sta_lo) || |
| 12183 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 12184 | &uerr_sta_hi)) { |
| 12185 | phba->work_hs |= UNPLUG_ERR; |
| 12186 | phba->work_ha |= HA_ERATT; |
| 12187 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12188 | return 1; |
| 12189 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12190 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 12191 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 12192 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12193 | "1423 HBA Unrecoverable error: " |
| 12194 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 12195 | "ue_mask_lo_reg=0x%x, " |
| 12196 | "ue_mask_hi_reg=0x%x\n", |
| 12197 | uerr_sta_lo, uerr_sta_hi, |
| 12198 | phba->sli4_hba.ue_mask_lo, |
| 12199 | phba->sli4_hba.ue_mask_hi); |
| 12200 | phba->work_status[0] = uerr_sta_lo; |
| 12201 | phba->work_status[1] = uerr_sta_hi; |
| 12202 | phba->work_ha |= HA_ERATT; |
| 12203 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12204 | return 1; |
| 12205 | } |
| 12206 | break; |
| 12207 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 12208 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12209 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 12210 | &portstat_reg.word0) || |
| 12211 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 12212 | &portsmphr)){ |
| 12213 | phba->work_hs |= UNPLUG_ERR; |
| 12214 | phba->work_ha |= HA_ERATT; |
| 12215 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12216 | return 1; |
| 12217 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12218 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 12219 | phba->work_status[0] = |
| 12220 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 12221 | phba->work_status[1] = |
| 12222 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 12223 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12224 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12225 | "port status reg 0x%x, " |
| 12226 | "port smphr reg 0x%x, " |
| 12227 | "error 1=0x%x, error 2=0x%x\n", |
| 12228 | portstat_reg.word0, |
| 12229 | portsmphr, |
| 12230 | phba->work_status[0], |
| 12231 | phba->work_status[1]); |
| 12232 | phba->work_ha |= HA_ERATT; |
| 12233 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12234 | return 1; |
| 12235 | } |
| 12236 | break; |
| 12237 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 12238 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12239 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12240 | "2886 HBA Error Attention on unsupported " |
| 12241 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12242 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12243 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12244 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12245 | return 0; |
| 12246 | } |
| 12247 | |
| 12248 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12249 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12250 | * @phba: Pointer to HBA context. |
| 12251 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12252 | * 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] | 12253 | * error attention register bit for error attention events. |
| 12254 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12255 | * 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] | 12256 | * Register and returns 0 otherwise. |
| 12257 | **/ |
| 12258 | int |
| 12259 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 12260 | { |
| 12261 | uint32_t ha_copy; |
| 12262 | |
| 12263 | /* If somebody is waiting to handle an eratt, don't process it |
| 12264 | * here. The brdkill function will do this. |
| 12265 | */ |
| 12266 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12267 | return 0; |
| 12268 | |
| 12269 | /* Check if interrupt handler handles this ERATT */ |
| 12270 | spin_lock_irq(&phba->hbalock); |
| 12271 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 12272 | /* Interrupt handler has handled ERATT */ |
| 12273 | spin_unlock_irq(&phba->hbalock); |
| 12274 | return 0; |
| 12275 | } |
| 12276 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12277 | /* |
| 12278 | * If there is deferred error attention, do not check for error |
| 12279 | * attention |
| 12280 | */ |
| 12281 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 12282 | spin_unlock_irq(&phba->hbalock); |
| 12283 | return 0; |
| 12284 | } |
| 12285 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12286 | /* If PCI channel is offline, don't process it */ |
| 12287 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12288 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12289 | return 0; |
| 12290 | } |
| 12291 | |
| 12292 | switch (phba->sli_rev) { |
| 12293 | case LPFC_SLI_REV2: |
| 12294 | case LPFC_SLI_REV3: |
| 12295 | /* Read chip Host Attention (HA) register */ |
| 12296 | ha_copy = lpfc_sli_eratt_read(phba); |
| 12297 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12298 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12299 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12300 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 12301 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12302 | default: |
| 12303 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12304 | "0299 Invalid SLI revision (%d)\n", |
| 12305 | phba->sli_rev); |
| 12306 | ha_copy = 0; |
| 12307 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12308 | } |
| 12309 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12310 | |
| 12311 | return ha_copy; |
| 12312 | } |
| 12313 | |
| 12314 | /** |
| 12315 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 12316 | * @phba: Pointer to HBA context. |
| 12317 | * |
| 12318 | * This inline routine checks whether a device or its PCI slot is in a state |
| 12319 | * that the interrupt should be handled. |
| 12320 | * |
| 12321 | * This function returns 0 if the device or the PCI slot is in a state that |
| 12322 | * interrupt should be handled, otherwise -EIO. |
| 12323 | */ |
| 12324 | static inline int |
| 12325 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 12326 | { |
| 12327 | /* If the pci channel is offline, ignore all the interrupts */ |
| 12328 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 12329 | return -EIO; |
| 12330 | |
| 12331 | /* Update device level interrupt statistics */ |
| 12332 | phba->sli.slistat.sli_intr++; |
| 12333 | |
| 12334 | /* Ignore all interrupts during initialization. */ |
| 12335 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 12336 | return -EIO; |
| 12337 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12338 | return 0; |
| 12339 | } |
| 12340 | |
| 12341 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12342 | * 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] | 12343 | * @irq: Interrupt number. |
| 12344 | * @dev_id: The device context pointer. |
| 12345 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12346 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12347 | * service routine when device with SLI-3 interface spec is enabled with |
| 12348 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 12349 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 12350 | * interrupt mode, this function is called as part of the device-level |
| 12351 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 12352 | * is undergoing initialization, the interrupt handler will not process |
| 12353 | * the interrupt. The link attention and ELS ring attention events are |
| 12354 | * handled by the worker thread. The interrupt handler signals the worker |
| 12355 | * thread and returns for these events. This function is called without |
| 12356 | * 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] | 12357 | * structures. |
| 12358 | * |
| 12359 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12360 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12361 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12362 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12363 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12364 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12365 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12366 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12367 | uint32_t work_ha_copy; |
| 12368 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12369 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12370 | uint32_t control; |
| 12371 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12372 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12373 | struct lpfc_vport *vport; |
| 12374 | struct lpfc_nodelist *ndlp; |
| 12375 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12376 | LPFC_MBOXQ_t *pmb; |
| 12377 | int rc; |
| 12378 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12379 | /* |
| 12380 | * Get the driver's phba structure from the dev_id and |
| 12381 | * assume the HBA is not interrupting. |
| 12382 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12383 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12384 | |
| 12385 | if (unlikely(!phba)) |
| 12386 | return IRQ_NONE; |
| 12387 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12388 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12389 | * Stuff needs to be attented to when this function is invoked as an |
| 12390 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12391 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12392 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12393 | /* Check device state for handling interrupt */ |
| 12394 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12395 | return IRQ_NONE; |
| 12396 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12397 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12398 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12399 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12400 | /* If somebody is waiting to handle an eratt don't process it |
| 12401 | * here. The brdkill function will do this. |
| 12402 | */ |
| 12403 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12404 | ha_copy &= ~HA_ERATT; |
| 12405 | /* Check the need for handling ERATT in interrupt handler */ |
| 12406 | if (ha_copy & HA_ERATT) { |
| 12407 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12408 | /* ERATT polling has handled ERATT */ |
| 12409 | ha_copy &= ~HA_ERATT; |
| 12410 | else |
| 12411 | /* Indicate interrupt handler handles ERATT */ |
| 12412 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12413 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12414 | |
| 12415 | /* |
| 12416 | * If there is deferred error attention, do not check for any |
| 12417 | * interrupt. |
| 12418 | */ |
| 12419 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12420 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12421 | return IRQ_NONE; |
| 12422 | } |
| 12423 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12424 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12425 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 12426 | goto unplug_error; |
| 12427 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12428 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 12429 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12430 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12431 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 12432 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12433 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12434 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12435 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12436 | } else |
| 12437 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12438 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12439 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 12440 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12441 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12442 | if (work_ha_copy & HA_LATT) { |
| 12443 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 12444 | /* |
| 12445 | * Turn off Link Attention interrupts |
| 12446 | * until CLEAR_LA done |
| 12447 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12448 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12449 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12450 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12451 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12452 | control &= ~HC_LAINT_ENA; |
| 12453 | writel(control, phba->HCregaddr); |
| 12454 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12455 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12456 | } |
| 12457 | else |
| 12458 | work_ha_copy &= ~HA_LATT; |
| 12459 | } |
| 12460 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12461 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12462 | /* |
| 12463 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 12464 | * the only slow ring. |
| 12465 | */ |
| 12466 | status = (work_ha_copy & |
| 12467 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12468 | status >>= (4*LPFC_ELS_RING); |
| 12469 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12470 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12471 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12472 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12473 | |
| 12474 | lpfc_debugfs_slow_ring_trc(phba, |
| 12475 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 12476 | control, status, |
| 12477 | (uint32_t)phba->sli.slistat.sli_intr); |
| 12478 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12479 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12480 | lpfc_debugfs_slow_ring_trc(phba, |
| 12481 | "ISR Disable ring:" |
| 12482 | "pwork:x%x hawork:x%x wait:x%x", |
| 12483 | phba->work_ha, work_ha_copy, |
| 12484 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12485 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12486 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12487 | control &= |
| 12488 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12489 | writel(control, phba->HCregaddr); |
| 12490 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12491 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12492 | else { |
| 12493 | lpfc_debugfs_slow_ring_trc(phba, |
| 12494 | "ISR slow ring: pwork:" |
| 12495 | "x%x hawork:x%x wait:x%x", |
| 12496 | phba->work_ha, work_ha_copy, |
| 12497 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12498 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12499 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12500 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12501 | } |
| 12502 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12503 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12504 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12505 | if (lpfc_sli_read_hs(phba)) |
| 12506 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12507 | /* |
| 12508 | * Check if there is a deferred error condition |
| 12509 | * is active |
| 12510 | */ |
| 12511 | if ((HS_FFER1 & phba->work_hs) && |
| 12512 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12513 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 12514 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12515 | phba->hba_flag |= DEFER_ERATT; |
| 12516 | /* Clear all interrupt enable conditions */ |
| 12517 | writel(0, phba->HCregaddr); |
| 12518 | readl(phba->HCregaddr); |
| 12519 | } |
| 12520 | } |
| 12521 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12522 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12523 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12524 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12525 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12526 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12527 | |
| 12528 | /* First check out the status word */ |
| 12529 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 12530 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12531 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12532 | /* |
| 12533 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 12534 | * mbxStatus <status> |
| 12535 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12536 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12537 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12538 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12539 | "Interrupt mbxCommand x%x " |
| 12540 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12541 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12542 | pmbox->mbxCommand, |
| 12543 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12544 | /* clear mailbox attention bit */ |
| 12545 | work_ha_copy &= ~HA_MBATT; |
| 12546 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12547 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12548 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12549 | phba->last_completion_time = jiffies; |
| 12550 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12551 | if (pmb->mbox_cmpl) { |
| 12552 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 12553 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12554 | if (pmb->out_ext_byte_len && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12555 | pmb->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12556 | lpfc_sli_pcimem_bcopy( |
| 12557 | phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12558 | pmb->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12559 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12560 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12561 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12562 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12563 | |
| 12564 | lpfc_debugfs_disc_trc(vport, |
| 12565 | LPFC_DISC_TRC_MBOX_VPORT, |
| 12566 | "MBOX dflt rpi: : " |
| 12567 | "status:x%x rpi:x%x", |
| 12568 | (uint32_t)pmbox->mbxStatus, |
| 12569 | pmbox->un.varWords[0], 0); |
| 12570 | |
| 12571 | if (!pmbox->mbxStatus) { |
| 12572 | mp = (struct lpfc_dmabuf *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12573 | (pmb->ctx_buf); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12574 | ndlp = (struct lpfc_nodelist *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12575 | pmb->ctx_ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12576 | |
| 12577 | /* Reg_LOGIN of dflt RPI was |
| 12578 | * successful. new lets get |
| 12579 | * rid of the RPI using the |
| 12580 | * same mbox buffer. |
| 12581 | */ |
| 12582 | lpfc_unreg_login(phba, |
| 12583 | vport->vpi, |
| 12584 | pmbox->un.varWords[0], |
| 12585 | pmb); |
| 12586 | pmb->mbox_cmpl = |
| 12587 | lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12588 | pmb->ctx_buf = mp; |
| 12589 | pmb->ctx_ndlp = ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12590 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12591 | rc = lpfc_sli_issue_mbox(phba, |
| 12592 | pmb, |
| 12593 | MBX_NOWAIT); |
| 12594 | if (rc != MBX_BUSY) |
| 12595 | lpfc_printf_log(phba, |
| 12596 | KERN_ERR, |
| 12597 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12598 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12599 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12600 | if (rc != MBX_NOT_FINISHED) |
| 12601 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12602 | } |
| 12603 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12604 | spin_lock_irqsave( |
| 12605 | &phba->pport->work_port_lock, |
| 12606 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12607 | phba->pport->work_port_events &= |
| 12608 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12609 | spin_unlock_irqrestore( |
| 12610 | &phba->pport->work_port_lock, |
| 12611 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12612 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12613 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12614 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12615 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12616 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12617 | if ((work_ha_copy & HA_MBATT) && |
| 12618 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12619 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12620 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12621 | do { |
| 12622 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 12623 | MBX_NOWAIT); |
| 12624 | } while (rc == MBX_NOT_FINISHED); |
| 12625 | if (rc != MBX_SUCCESS) |
| 12626 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12627 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12628 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12629 | } |
| 12630 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12631 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12632 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12633 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12634 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12635 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12636 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12637 | unplug_error: |
| 12638 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12639 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12640 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12641 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12642 | |
| 12643 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12644 | * 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] | 12645 | * @irq: Interrupt number. |
| 12646 | * @dev_id: The device context pointer. |
| 12647 | * |
| 12648 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12649 | * service routine when device with SLI-3 interface spec is enabled with |
| 12650 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12651 | * ring event in the HBA. However, when the device is enabled with either |
| 12652 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12653 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12654 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12655 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12656 | * the intrrupt context. This function is called without any lock held. |
| 12657 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12658 | * |
| 12659 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12660 | * returns IRQ_NONE. |
| 12661 | **/ |
| 12662 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12663 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12664 | { |
| 12665 | struct lpfc_hba *phba; |
| 12666 | uint32_t ha_copy; |
| 12667 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12668 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12669 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12670 | |
| 12671 | /* Get the driver's phba structure from the dev_id and |
| 12672 | * assume the HBA is not interrupting. |
| 12673 | */ |
| 12674 | phba = (struct lpfc_hba *) dev_id; |
| 12675 | |
| 12676 | if (unlikely(!phba)) |
| 12677 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12678 | |
| 12679 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12680 | * Stuff needs to be attented to when this function is invoked as an |
| 12681 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12682 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12683 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12684 | /* Check device state for handling interrupt */ |
| 12685 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12686 | return IRQ_NONE; |
| 12687 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12688 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12689 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12690 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12691 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12692 | /* |
| 12693 | * If there is deferred error attention, do not check for |
| 12694 | * any interrupt. |
| 12695 | */ |
| 12696 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12697 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12698 | return IRQ_NONE; |
| 12699 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12700 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 12701 | phba->HAregaddr); |
| 12702 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12703 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12704 | } else |
| 12705 | ha_copy = phba->ha_copy; |
| 12706 | |
| 12707 | /* |
| 12708 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 12709 | */ |
| 12710 | ha_copy &= ~(phba->work_ha_mask); |
| 12711 | |
| 12712 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12713 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12714 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12715 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12716 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12717 | |
| 12718 | if (phba->cfg_multi_ring_support == 2) { |
| 12719 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12720 | * Process all events on extra ring. Take the optimized path |
| 12721 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12722 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12723 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12724 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12725 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12726 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12727 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12728 | status); |
| 12729 | } |
| 12730 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12731 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12732 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12733 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12734 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12735 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12736 | * @irq: Interrupt number. |
| 12737 | * @dev_id: The device context pointer. |
| 12738 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12739 | * This function is the HBA device-level interrupt handler to device with |
| 12740 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 12741 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 12742 | * requires driver attention. This function invokes the slow-path interrupt |
| 12743 | * attention handling function and fast-path interrupt attention handling |
| 12744 | * function in turn to process the relevant HBA attention events. This |
| 12745 | * function is called without any lock held. It gets the hbalock to access |
| 12746 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12747 | * |
| 12748 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12749 | * returns IRQ_NONE. |
| 12750 | **/ |
| 12751 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12752 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12753 | { |
| 12754 | struct lpfc_hba *phba; |
| 12755 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 12756 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12757 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12758 | |
| 12759 | /* |
| 12760 | * Get the driver's phba structure from the dev_id and |
| 12761 | * assume the HBA is not interrupting. |
| 12762 | */ |
| 12763 | phba = (struct lpfc_hba *) dev_id; |
| 12764 | |
| 12765 | if (unlikely(!phba)) |
| 12766 | return IRQ_NONE; |
| 12767 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12768 | /* Check device state for handling interrupt */ |
| 12769 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12770 | return IRQ_NONE; |
| 12771 | |
| 12772 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12773 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 12774 | spin_unlock(&phba->hbalock); |
| 12775 | return IRQ_HANDLED; |
| 12776 | } |
| 12777 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12778 | if (unlikely(!phba->ha_copy)) { |
| 12779 | spin_unlock(&phba->hbalock); |
| 12780 | return IRQ_NONE; |
| 12781 | } else if (phba->ha_copy & HA_ERATT) { |
| 12782 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12783 | /* ERATT polling has handled ERATT */ |
| 12784 | phba->ha_copy &= ~HA_ERATT; |
| 12785 | else |
| 12786 | /* Indicate interrupt handler handles ERATT */ |
| 12787 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12788 | } |
| 12789 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12790 | /* |
| 12791 | * If there is deferred error attention, do not check for any interrupt. |
| 12792 | */ |
| 12793 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 12794 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12795 | return IRQ_NONE; |
| 12796 | } |
| 12797 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12798 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12799 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 12800 | spin_unlock(&phba->hbalock); |
| 12801 | return IRQ_HANDLED; |
| 12802 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12803 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 12804 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12805 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12806 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12807 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12808 | readl(phba->HAregaddr); /* flush */ |
| 12809 | spin_unlock(&phba->hbalock); |
| 12810 | |
| 12811 | /* |
| 12812 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 12813 | */ |
| 12814 | |
| 12815 | /* status of events with mailbox and link attention */ |
| 12816 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 12817 | |
| 12818 | /* status of events with ELS ring */ |
| 12819 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12820 | status2 >>= (4*LPFC_ELS_RING); |
| 12821 | |
| 12822 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12823 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12824 | else |
| 12825 | sp_irq_rc = IRQ_NONE; |
| 12826 | |
| 12827 | /* |
| 12828 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12829 | */ |
| 12830 | |
| 12831 | /* status of events with FCP ring */ |
| 12832 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 12833 | status1 >>= (4*LPFC_FCP_RING); |
| 12834 | |
| 12835 | /* status of events with extra ring */ |
| 12836 | if (phba->cfg_multi_ring_support == 2) { |
| 12837 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 12838 | status2 >>= (4*LPFC_EXTRA_RING); |
| 12839 | } else |
| 12840 | status2 = 0; |
| 12841 | |
| 12842 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12843 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12844 | else |
| 12845 | fp_irq_rc = IRQ_NONE; |
| 12846 | |
| 12847 | /* Return device-level interrupt handling status */ |
| 12848 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12849 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12850 | |
| 12851 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12852 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 12853 | * @phba: pointer to lpfc hba data structure. |
| 12854 | * |
| 12855 | * This routine is invoked by the worker thread to process all the pending |
| 12856 | * SLI4 els abort xri events. |
| 12857 | **/ |
| 12858 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12859 | { |
| 12860 | struct lpfc_cq_event *cq_event; |
| 12861 | |
| 12862 | /* First, declare the els xri abort event has been handled */ |
| 12863 | spin_lock_irq(&phba->hbalock); |
| 12864 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 12865 | spin_unlock_irq(&phba->hbalock); |
| 12866 | /* Now, handle all the els xri abort events */ |
| 12867 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 12868 | /* Get the first event from the head of the event queue */ |
| 12869 | spin_lock_irq(&phba->hbalock); |
| 12870 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 12871 | cq_event, struct lpfc_cq_event, list); |
| 12872 | spin_unlock_irq(&phba->hbalock); |
| 12873 | /* Notify aborted XRI for ELS work queue */ |
| 12874 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12875 | /* Free the event processed back to the free pool */ |
| 12876 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12877 | } |
| 12878 | } |
| 12879 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12880 | /** |
| 12881 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 12882 | * @phba: pointer to lpfc hba data structure |
| 12883 | * @pIocbIn: pointer to the rspiocbq |
| 12884 | * @pIocbOut: pointer to the cmdiocbq |
| 12885 | * @wcqe: pointer to the complete wcqe |
| 12886 | * |
| 12887 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 12888 | * by copying all the IOCB fields from command iocbq and transferring the |
| 12889 | * completion status information from the complete wcqe. |
| 12890 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12891 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12892 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 12893 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12894 | struct lpfc_iocbq *pIocbOut, |
| 12895 | struct lpfc_wcqe_complete *wcqe) |
| 12896 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12897 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12898 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12899 | uint32_t status, max_response; |
| 12900 | struct lpfc_dmabuf *dmabuf; |
| 12901 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12902 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 12903 | |
| 12904 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 12905 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12906 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12907 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 12908 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12909 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 12910 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 12911 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 12912 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 12913 | wcqe->total_data_placed; |
| 12914 | else |
| 12915 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12916 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12917 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12918 | switch (pIocbOut->iocb.ulpCommand) { |
| 12919 | case CMD_ELS_REQUEST64_CR: |
| 12920 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12921 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12922 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 12923 | max_response = bde.tus.f.bdeSize; |
| 12924 | break; |
| 12925 | case CMD_GEN_REQUEST64_CR: |
| 12926 | max_response = 0; |
| 12927 | if (!pIocbOut->context3) |
| 12928 | break; |
| 12929 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 12930 | sizeof(struct ulp_bde64); |
| 12931 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12932 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12933 | for (i = 0; i < numBdes; i++) { |
| 12934 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 12935 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 12936 | max_response += bde.tus.f.bdeSize; |
| 12937 | } |
| 12938 | break; |
| 12939 | default: |
| 12940 | max_response = wcqe->total_data_placed; |
| 12941 | break; |
| 12942 | } |
| 12943 | if (max_response < wcqe->total_data_placed) |
| 12944 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 12945 | else |
| 12946 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 12947 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12948 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12949 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12950 | /* Convert BG errors for completion status */ |
| 12951 | if (status == CQE_STATUS_DI_ERROR) { |
| 12952 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 12953 | |
| 12954 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 12955 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 12956 | else |
| 12957 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 12958 | |
| 12959 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 12960 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 12961 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12962 | BGS_GUARD_ERR_MASK; |
| 12963 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 12964 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12965 | BGS_APPTAG_ERR_MASK; |
| 12966 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 12967 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12968 | BGS_REFTAG_ERR_MASK; |
| 12969 | |
| 12970 | /* Check to see if there was any good data before the error */ |
| 12971 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 12972 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12973 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 12974 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 12975 | wcqe->total_data_placed; |
| 12976 | } |
| 12977 | |
| 12978 | /* |
| 12979 | * Set ALL the error bits to indicate we don't know what |
| 12980 | * type of error it is. |
| 12981 | */ |
| 12982 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 12983 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12984 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 12985 | BGS_GUARD_ERR_MASK); |
| 12986 | } |
| 12987 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12988 | /* Pick up HBA exchange busy condition */ |
| 12989 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 12990 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12991 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 12992 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12993 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12994 | } |
| 12995 | |
| 12996 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12997 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 12998 | * @phba: Pointer to HBA context object. |
| 12999 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13000 | * |
| 13001 | * This routine handles an ELS work-queue completion event and construct |
| 13002 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 13003 | * discovery engine to handle. |
| 13004 | * |
| 13005 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 13006 | **/ |
| 13007 | static struct lpfc_iocbq * |
| 13008 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 13009 | struct lpfc_iocbq *irspiocbq) |
| 13010 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13011 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13012 | struct lpfc_iocbq *cmdiocbq; |
| 13013 | struct lpfc_wcqe_complete *wcqe; |
| 13014 | unsigned long iflags; |
| 13015 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13016 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 13017 | if (unlikely(!pring)) |
| 13018 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13019 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13020 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13021 | pring->stats.iocb_event++; |
| 13022 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 13023 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13024 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13025 | if (unlikely(!cmdiocbq)) { |
| 13026 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13027 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13028 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 13029 | wcqe->word0, wcqe->total_data_placed, |
| 13030 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13031 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 13032 | return NULL; |
| 13033 | } |
| 13034 | |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 13035 | spin_lock_irqsave(&pring->ring_lock, iflags); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13036 | /* Put the iocb back on the txcmplq */ |
| 13037 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 13038 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 13039 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13040 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13041 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13042 | |
| 13043 | return irspiocbq; |
| 13044 | } |
| 13045 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13046 | inline struct lpfc_cq_event * |
| 13047 | lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size) |
| 13048 | { |
| 13049 | struct lpfc_cq_event *cq_event; |
| 13050 | |
| 13051 | /* Allocate a new internal CQ_EVENT entry */ |
| 13052 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 13053 | if (!cq_event) { |
| 13054 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13055 | "0602 Failed to alloc CQ_EVENT entry\n"); |
| 13056 | return NULL; |
| 13057 | } |
| 13058 | |
| 13059 | /* Move the CQE into the event */ |
| 13060 | memcpy(&cq_event->cqe, entry, size); |
| 13061 | return cq_event; |
| 13062 | } |
| 13063 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13064 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13065 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 13066 | * @phba: Pointer to HBA context object. |
| 13067 | * @cqe: Pointer to mailbox completion queue entry. |
| 13068 | * |
| 13069 | * This routine process a mailbox completion queue entry with asynchrous |
| 13070 | * event. |
| 13071 | * |
| 13072 | * Return: true if work posted to worker thread, otherwise false. |
| 13073 | **/ |
| 13074 | static bool |
| 13075 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13076 | { |
| 13077 | struct lpfc_cq_event *cq_event; |
| 13078 | unsigned long iflags; |
| 13079 | |
| 13080 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13081 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 13082 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 13083 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 13084 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13085 | cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe)); |
| 13086 | if (!cq_event) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13087 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13088 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13089 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 13090 | /* Set the async event flag */ |
| 13091 | phba->hba_flag |= ASYNC_EVENT; |
| 13092 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13093 | |
| 13094 | return true; |
| 13095 | } |
| 13096 | |
| 13097 | /** |
| 13098 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 13099 | * @phba: Pointer to HBA context object. |
| 13100 | * @cqe: Pointer to mailbox completion queue entry. |
| 13101 | * |
| 13102 | * This routine process a mailbox completion queue entry with mailbox |
| 13103 | * completion event. |
| 13104 | * |
| 13105 | * Return: true if work posted to worker thread, otherwise false. |
| 13106 | **/ |
| 13107 | static bool |
| 13108 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13109 | { |
| 13110 | uint32_t mcqe_status; |
| 13111 | MAILBOX_t *mbox, *pmbox; |
| 13112 | struct lpfc_mqe *mqe; |
| 13113 | struct lpfc_vport *vport; |
| 13114 | struct lpfc_nodelist *ndlp; |
| 13115 | struct lpfc_dmabuf *mp; |
| 13116 | unsigned long iflags; |
| 13117 | LPFC_MBOXQ_t *pmb; |
| 13118 | bool workposted = false; |
| 13119 | int rc; |
| 13120 | |
| 13121 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 13122 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 13123 | goto out_no_mqe_complete; |
| 13124 | |
| 13125 | /* Get the reference to the active mbox command */ |
| 13126 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13127 | pmb = phba->sli.mbox_active; |
| 13128 | if (unlikely(!pmb)) { |
| 13129 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 13130 | "1832 No pending MBOX command to handle\n"); |
| 13131 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13132 | goto out_no_mqe_complete; |
| 13133 | } |
| 13134 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13135 | mqe = &pmb->u.mqe; |
| 13136 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 13137 | mbox = phba->mbox; |
| 13138 | vport = pmb->vport; |
| 13139 | |
| 13140 | /* Reset heartbeat timer */ |
| 13141 | phba->last_completion_time = jiffies; |
| 13142 | del_timer(&phba->sli.mbox_tmo); |
| 13143 | |
| 13144 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 13145 | if (pmb->mbox_cmpl && mbox) |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13146 | lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13147 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13148 | /* |
| 13149 | * For mcqe errors, conditionally move a modified error code to |
| 13150 | * the mbox so that the error will not be missed. |
| 13151 | */ |
| 13152 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 13153 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 13154 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 13155 | bf_set(lpfc_mqe_status, mqe, |
| 13156 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 13157 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13158 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 13159 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 13160 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 13161 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 13162 | mcqe_status, |
| 13163 | pmbox->un.varWords[0], 0); |
| 13164 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13165 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 13166 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13167 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 13168 | * RID of the PPI using the same mbox buffer. |
| 13169 | */ |
| 13170 | lpfc_unreg_login(phba, vport->vpi, |
| 13171 | pmbox->un.varWords[0], pmb); |
| 13172 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13173 | pmb->ctx_buf = mp; |
| 13174 | pmb->ctx_ndlp = ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13175 | pmb->vport = vport; |
| 13176 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 13177 | if (rc != MBX_BUSY) |
| 13178 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 13179 | LOG_SLI, "0385 rc should " |
| 13180 | "have been MBX_BUSY\n"); |
| 13181 | if (rc != MBX_NOT_FINISHED) |
| 13182 | goto send_current_mbox; |
| 13183 | } |
| 13184 | } |
| 13185 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 13186 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 13187 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 13188 | |
| 13189 | /* There is mailbox completion work to do */ |
| 13190 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13191 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 13192 | phba->work_ha |= HA_MBATT; |
| 13193 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13194 | workposted = true; |
| 13195 | |
| 13196 | send_current_mbox: |
| 13197 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13198 | /* Release the mailbox command posting token */ |
| 13199 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 13200 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 13201 | phba->sli.mbox_active = NULL; |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13202 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13203 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13204 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13205 | /* Wake up worker thread to post the next pending mailbox command */ |
| 13206 | lpfc_worker_wake_up(phba); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13207 | return workposted; |
| 13208 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13209 | out_no_mqe_complete: |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13210 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13211 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13212 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
James Smart | 07b8582 | 2019-09-21 20:58:53 -0700 | [diff] [blame] | 13213 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13214 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13215 | } |
| 13216 | |
| 13217 | /** |
| 13218 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 13219 | * @phba: Pointer to HBA context object. |
| 13220 | * @cqe: Pointer to mailbox completion queue entry. |
| 13221 | * |
| 13222 | * This routine process a mailbox completion queue entry, it invokes the |
| 13223 | * proper mailbox complete handling or asynchrous event handling routine |
| 13224 | * according to the MCQE's async bit. |
| 13225 | * |
| 13226 | * Return: true if work posted to worker thread, otherwise false. |
| 13227 | **/ |
| 13228 | static bool |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13229 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13230 | struct lpfc_cqe *cqe) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13231 | { |
| 13232 | struct lpfc_mcqe mcqe; |
| 13233 | bool workposted; |
| 13234 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13235 | cq->CQ_mbox++; |
| 13236 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13237 | /* Copy the mailbox MCQE and convert endian order as needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13238 | lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13239 | |
| 13240 | /* Invoke the proper event handling routine */ |
| 13241 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 13242 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 13243 | else |
| 13244 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 13245 | return workposted; |
| 13246 | } |
| 13247 | |
| 13248 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13249 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 13250 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13251 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13252 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13253 | * |
| 13254 | * This routine handles an ELS work-queue completion event. |
| 13255 | * |
| 13256 | * Return: true if work posted to worker thread, otherwise false. |
| 13257 | **/ |
| 13258 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13259 | 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] | 13260 | struct lpfc_wcqe_complete *wcqe) |
| 13261 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13262 | struct lpfc_iocbq *irspiocbq; |
| 13263 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13264 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13265 | int txq_cnt = 0; |
| 13266 | int txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13267 | |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13268 | /* Check for response status */ |
| 13269 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13270 | /* Log the error status */ |
| 13271 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13272 | "0357 ELS CQE error: status=x%x: " |
| 13273 | "CQE: %08x %08x %08x %08x\n", |
| 13274 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 13275 | wcqe->word0, wcqe->total_data_placed, |
| 13276 | wcqe->parameter, wcqe->word3); |
| 13277 | } |
| 13278 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13279 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13280 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 13281 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13282 | if (!list_empty(&pring->txq)) |
| 13283 | txq_cnt++; |
| 13284 | if (!list_empty(&pring->txcmplq)) |
| 13285 | txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13286 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 13287 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
James Smart | ff349bc | 2019-09-21 20:59:05 -0700 | [diff] [blame] | 13288 | "els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13289 | txq_cnt, phba->iocb_cnt, |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13290 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13291 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13292 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13293 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13294 | /* Save off the slow-path queue event for work thread to process */ |
| 13295 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13296 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13297 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13298 | &phba->sli4_hba.sp_queue_event); |
| 13299 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13300 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13301 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13302 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13303 | } |
| 13304 | |
| 13305 | /** |
| 13306 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 13307 | * @phba: Pointer to HBA context object. |
| 13308 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13309 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13310 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13311 | * proper WQ release routine to the slow-path WQ. |
| 13312 | **/ |
| 13313 | static void |
| 13314 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 13315 | struct lpfc_wcqe_release *wcqe) |
| 13316 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13317 | /* sanity check on queue memory */ |
| 13318 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 13319 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13320 | /* Check for the slow-path ELS work queue */ |
| 13321 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 13322 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 13323 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 13324 | else |
| 13325 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13326 | "2579 Slow-path wqe consume event carries " |
| 13327 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 13328 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 13329 | phba->sli4_hba.els_wq->queue_id); |
| 13330 | } |
| 13331 | |
| 13332 | /** |
| 13333 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 13334 | * @phba: Pointer to HBA context object. |
| 13335 | * @cq: Pointer to a WQ completion queue. |
| 13336 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13337 | * |
| 13338 | * This routine handles an XRI abort event. |
| 13339 | * |
| 13340 | * Return: true if work posted to worker thread, otherwise false. |
| 13341 | **/ |
| 13342 | static bool |
| 13343 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 13344 | struct lpfc_queue *cq, |
| 13345 | struct sli4_wcqe_xri_aborted *wcqe) |
| 13346 | { |
| 13347 | bool workposted = false; |
| 13348 | struct lpfc_cq_event *cq_event; |
| 13349 | unsigned long iflags; |
| 13350 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13351 | switch (cq->subtype) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13352 | case LPFC_IO: |
| 13353 | lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq); |
| 13354 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 13355 | /* Notify aborted XRI for NVME work queue */ |
| 13356 | if (phba->nvmet_support) |
| 13357 | lpfc_sli4_nvmet_xri_aborted(phba, wcqe); |
| 13358 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13359 | workposted = false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13360 | break; |
James Smart | 422c4cb | 2017-11-20 16:00:32 -0800 | [diff] [blame] | 13361 | case LPFC_NVME_LS: /* NVME LS uses ELS resources */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13362 | case LPFC_ELS: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13363 | cq_event = lpfc_cq_event_setup( |
| 13364 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 13365 | if (!cq_event) |
| 13366 | return false; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13367 | cq_event->hdwq = cq->hdwq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13368 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13369 | list_add_tail(&cq_event->list, |
| 13370 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 13371 | /* Set the els xri abort event flag */ |
| 13372 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 13373 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13374 | workposted = true; |
| 13375 | break; |
| 13376 | default: |
| 13377 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13378 | "0603 Invalid CQ subtype %d: " |
| 13379 | "%08x %08x %08x %08x\n", |
| 13380 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 13381 | wcqe->word2, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13382 | workposted = false; |
| 13383 | break; |
| 13384 | } |
| 13385 | return workposted; |
| 13386 | } |
| 13387 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13388 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 13389 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13390 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13391 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13392 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13393 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13394 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13395 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13396 | * |
| 13397 | * Return: true if work posted to worker thread, otherwise false. |
| 13398 | **/ |
| 13399 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13400 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 13401 | { |
| 13402 | bool workposted = false; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13403 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13404 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 13405 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13406 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13407 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13408 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13409 | unsigned long iflags; |
| 13410 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13411 | /* sanity check on queue memory */ |
| 13412 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13413 | return workposted; |
| 13414 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13415 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13416 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13417 | else |
| 13418 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13419 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13420 | goto out; |
| 13421 | |
| 13422 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13423 | switch (status) { |
| 13424 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13425 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13426 | "2537 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 13427 | /* fall through */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13428 | case FC_STATUS_RQ_SUCCESS: |
| 13429 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13430 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13431 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 13432 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13433 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13434 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13435 | goto out; |
| 13436 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13437 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13438 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13439 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13440 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13441 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13442 | |
| 13443 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 13444 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 13445 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13446 | /* Handle MDS Loopback frames */ |
| 13447 | lpfc_sli4_handle_mds_loopback(phba->pport, dma_buf); |
| 13448 | break; |
| 13449 | } |
| 13450 | |
| 13451 | /* save off the frame for the work thread to process */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13452 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13453 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13454 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13455 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13456 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13457 | workposted = true; |
| 13458 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13459 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13460 | if (phba->nvmet_support) { |
| 13461 | tgtp = phba->targetport->private; |
| 13462 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13463 | "6402 RQE Error x%x, posted %d err_cnt " |
| 13464 | "%d: %x %x %x\n", |
| 13465 | status, hrq->RQ_buf_posted, |
| 13466 | hrq->RQ_no_posted_buf, |
| 13467 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13468 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13469 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13470 | } |
| 13471 | /* fallthrough */ |
| 13472 | |
| 13473 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13474 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13475 | /* Post more buffers if possible */ |
| 13476 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13477 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 13478 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13479 | workposted = true; |
| 13480 | break; |
| 13481 | } |
| 13482 | out: |
| 13483 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13484 | } |
| 13485 | |
| 13486 | /** |
| 13487 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 13488 | * @phba: Pointer to HBA context object. |
| 13489 | * @cq: Pointer to the completion queue. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13490 | * @cqe: Pointer to a completion queue entry. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13491 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13492 | * 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] | 13493 | * entry. |
| 13494 | * |
| 13495 | * Return: true if work posted to worker thread, otherwise false. |
| 13496 | **/ |
| 13497 | static bool |
| 13498 | 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] | 13499 | struct lpfc_cqe *cqe) |
| 13500 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13501 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13502 | bool workposted = false; |
| 13503 | |
| 13504 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13505 | lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13506 | |
| 13507 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13508 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13509 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13510 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13511 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13512 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13513 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13514 | break; |
| 13515 | case CQE_CODE_RELEASE_WQE: |
| 13516 | /* Process the WQ release event */ |
| 13517 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13518 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13519 | break; |
| 13520 | case CQE_CODE_XRI_ABORTED: |
| 13521 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13522 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13523 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13524 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13525 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13526 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13527 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13528 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13529 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13530 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13531 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13532 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13533 | default: |
| 13534 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13535 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13536 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13537 | break; |
| 13538 | } |
| 13539 | return workposted; |
| 13540 | } |
| 13541 | |
| 13542 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13543 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 13544 | * @phba: Pointer to HBA context object. |
| 13545 | * @eqe: Pointer to fast-path event queue entry. |
| 13546 | * |
| 13547 | * This routine process a event queue entry from the slow-path event queue. |
| 13548 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13549 | * completion event on a completion queue, if not, an error shall be logged |
| 13550 | * and just return. Otherwise, it will get to the corresponding completion |
| 13551 | * queue and process all the entries on that completion queue, rearm the |
| 13552 | * completion queue, and then return. |
| 13553 | * |
| 13554 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13555 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13556 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13557 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13558 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13559 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13560 | uint16_t cqid; |
| 13561 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13562 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13563 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13564 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13565 | list_for_each_entry(childq, &speq->child_list, list) { |
| 13566 | if (childq->queue_id == cqid) { |
| 13567 | cq = childq; |
| 13568 | break; |
| 13569 | } |
| 13570 | } |
| 13571 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13572 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13573 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13574 | "0365 Slow-path CQ identifier " |
| 13575 | "(%d) does not exist\n", cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13576 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13577 | } |
| 13578 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13579 | /* Save EQ associated with this CQ */ |
| 13580 | cq->assoc_qp = speq; |
| 13581 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13582 | if (!queue_work_on(cq->chann, phba->wq, &cq->spwork)) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13583 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13584 | "0390 Cannot schedule soft IRQ " |
| 13585 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 13586 | cqid, cq->queue_id, raw_smp_processor_id()); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13587 | } |
| 13588 | |
| 13589 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13590 | * __lpfc_sli4_process_cq - Process elements of a CQ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13591 | * @phba: Pointer to HBA context object. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13592 | * @cq: Pointer to CQ to be processed |
| 13593 | * @handler: Routine to process each cqe |
| 13594 | * @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] | 13595 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13596 | * This routine processes completion queue entries in a CQ. While a valid |
| 13597 | * queue element is found, the handler is called. During processing checks |
| 13598 | * are made for periodic doorbell writes to let the hardware know of |
| 13599 | * element consumption. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13600 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13601 | * If the max limit on cqes to process is hit, or there are no more valid |
| 13602 | * entries, the loop stops. If we processed a sufficient number of elements, |
| 13603 | * meaning there is sufficient load, rather than rearming and generating |
| 13604 | * another interrupt, a cq rescheduling delay will be set. A delay of 0 |
| 13605 | * indicates no rescheduling. |
| 13606 | * |
| 13607 | * Returns True if work scheduled, False otherwise. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13608 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13609 | static bool |
| 13610 | __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13611 | bool (*handler)(struct lpfc_hba *, struct lpfc_queue *, |
| 13612 | struct lpfc_cqe *), unsigned long *delay) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13613 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13614 | struct lpfc_cqe *cqe; |
| 13615 | bool workposted = false; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13616 | int count = 0, consumed = 0; |
| 13617 | bool arm = true; |
| 13618 | |
| 13619 | /* default - no reschedule */ |
| 13620 | *delay = 0; |
| 13621 | |
| 13622 | if (cmpxchg(&cq->queue_claimed, 0, 1) != 0) |
| 13623 | goto rearm_and_exit; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13624 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13625 | /* Process all the entries to the CQ */ |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13626 | cq->q_flag = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13627 | cqe = lpfc_sli4_cq_get(cq); |
| 13628 | while (cqe) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13629 | workposted |= handler(phba, cq, cqe); |
| 13630 | __lpfc_sli4_consume_cqe(phba, cq, cqe); |
| 13631 | |
| 13632 | consumed++; |
| 13633 | if (!(++count % cq->max_proc_limit)) |
| 13634 | break; |
| 13635 | |
| 13636 | if (!(count % cq->notify_interval)) { |
| 13637 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 13638 | LPFC_QUEUE_NOARM); |
| 13639 | consumed = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13640 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13641 | |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13642 | if (count == LPFC_NVMET_CQ_NOTIFY) |
| 13643 | cq->q_flag |= HBA_NVMET_CQ_NOTIFY; |
| 13644 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13645 | cqe = lpfc_sli4_cq_get(cq); |
| 13646 | } |
| 13647 | if (count >= phba->cfg_cq_poll_threshold) { |
| 13648 | *delay = 1; |
| 13649 | arm = false; |
| 13650 | } |
| 13651 | |
| 13652 | /* Track the max number of CQEs processed in 1 EQ */ |
| 13653 | if (count > cq->CQ_max_cqe) |
| 13654 | cq->CQ_max_cqe = count; |
| 13655 | |
| 13656 | cq->assoc_qp->EQ_cqe_cnt += count; |
| 13657 | |
| 13658 | /* Catch the no cq entry condition */ |
| 13659 | if (unlikely(count == 0)) |
| 13660 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13661 | "0369 No entry from completion queue " |
| 13662 | "qid=%d\n", cq->queue_id); |
| 13663 | |
| 13664 | cq->queue_claimed = 0; |
| 13665 | |
| 13666 | rearm_and_exit: |
| 13667 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 13668 | arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM); |
| 13669 | |
| 13670 | return workposted; |
| 13671 | } |
| 13672 | |
| 13673 | /** |
| 13674 | * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry |
| 13675 | * @cq: pointer to CQ to process |
| 13676 | * |
| 13677 | * This routine calls the cq processing routine with a handler specific |
| 13678 | * to the type of queue bound to it. |
| 13679 | * |
| 13680 | * The CQ routine returns two values: the first is the calling status, |
| 13681 | * which indicates whether work was queued to the background discovery |
| 13682 | * thread. If true, the routine should wakeup the discovery thread; |
| 13683 | * the second is the delay parameter. If non-zero, rather than rearming |
| 13684 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 13685 | * that it is processed in a subsequent polling action. The value of |
| 13686 | * the delay indicates when to reschedule it. |
| 13687 | **/ |
| 13688 | static void |
| 13689 | __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq) |
| 13690 | { |
| 13691 | struct lpfc_hba *phba = cq->phba; |
| 13692 | unsigned long delay; |
| 13693 | bool workposted = false; |
| 13694 | |
| 13695 | /* Process and rearm the CQ */ |
| 13696 | switch (cq->type) { |
| 13697 | case LPFC_MCQ: |
| 13698 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13699 | lpfc_sli4_sp_handle_mcqe, |
| 13700 | &delay); |
| 13701 | break; |
| 13702 | case LPFC_WCQ: |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13703 | if (cq->subtype == LPFC_IO) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13704 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13705 | lpfc_sli4_fp_handle_cqe, |
| 13706 | &delay); |
| 13707 | else |
| 13708 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13709 | lpfc_sli4_sp_handle_cqe, |
| 13710 | &delay); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13711 | break; |
| 13712 | default: |
| 13713 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13714 | "0370 Invalid completion queue type (%d)\n", |
| 13715 | cq->type); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13716 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13717 | } |
| 13718 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13719 | if (delay) { |
| 13720 | if (!queue_delayed_work_on(cq->chann, phba->wq, |
| 13721 | &cq->sched_spwork, delay)) |
| 13722 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13723 | "0394 Cannot schedule soft IRQ " |
| 13724 | "for cqid=%d on CPU %d\n", |
| 13725 | cq->queue_id, cq->chann); |
| 13726 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13727 | |
| 13728 | /* wake up worker thread if there are works to be done */ |
| 13729 | if (workposted) |
| 13730 | lpfc_worker_wake_up(phba); |
| 13731 | } |
| 13732 | |
| 13733 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13734 | * lpfc_sli4_sp_process_cq - slow-path work handler when started by |
| 13735 | * interrupt |
| 13736 | * @work: pointer to work element |
| 13737 | * |
| 13738 | * translates from the work handler and calls the slow-path handler. |
| 13739 | **/ |
| 13740 | static void |
| 13741 | lpfc_sli4_sp_process_cq(struct work_struct *work) |
| 13742 | { |
| 13743 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork); |
| 13744 | |
| 13745 | __lpfc_sli4_sp_process_cq(cq); |
| 13746 | } |
| 13747 | |
| 13748 | /** |
| 13749 | * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer |
| 13750 | * @work: pointer to work element |
| 13751 | * |
| 13752 | * translates from the work handler and calls the slow-path handler. |
| 13753 | **/ |
| 13754 | static void |
| 13755 | lpfc_sli4_dly_sp_process_cq(struct work_struct *work) |
| 13756 | { |
| 13757 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 13758 | struct lpfc_queue, sched_spwork); |
| 13759 | |
| 13760 | __lpfc_sli4_sp_process_cq(cq); |
| 13761 | } |
| 13762 | |
| 13763 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13764 | * 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] | 13765 | * @phba: Pointer to HBA context object. |
| 13766 | * @cq: Pointer to associated CQ |
| 13767 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13768 | * |
| 13769 | * This routine process a fast-path work queue completion entry from fast-path |
| 13770 | * event queue for FCP command response completion. |
| 13771 | **/ |
| 13772 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13773 | 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] | 13774 | struct lpfc_wcqe_complete *wcqe) |
| 13775 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13776 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13777 | struct lpfc_iocbq *cmdiocbq; |
| 13778 | struct lpfc_iocbq irspiocbq; |
| 13779 | unsigned long iflags; |
| 13780 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13781 | /* Check for response status */ |
| 13782 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13783 | /* If resource errors reported from HBA, reduce queue |
| 13784 | * depth of the SCSI device. |
| 13785 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13786 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 13787 | IOSTAT_LOCAL_REJECT)) && |
| 13788 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 13789 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13790 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13791 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13792 | /* Log the error status */ |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13793 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13794 | "0373 FCP CQE error: status=x%x: " |
| 13795 | "CQE: %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13796 | bf_get(lpfc_wcqe_c_status, wcqe), |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13797 | wcqe->word0, wcqe->total_data_placed, |
| 13798 | wcqe->parameter, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13799 | } |
| 13800 | |
| 13801 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13802 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 13803 | pring->stats.iocb_event++; |
James Smart | e2a8be5 | 2019-05-06 17:26:47 -0700 | [diff] [blame] | 13804 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13805 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13806 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13807 | if (unlikely(!cmdiocbq)) { |
| 13808 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13809 | "0374 FCP complete with no corresponding " |
| 13810 | "cmdiocb: iotag (%d)\n", |
| 13811 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13812 | return; |
| 13813 | } |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13814 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13815 | cmdiocbq->isr_timestamp = cq->isr_timestamp; |
| 13816 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13817 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 13818 | if (cmdiocbq->wqe_cmpl) { |
| 13819 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13820 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13821 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13822 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13823 | } |
| 13824 | |
| 13825 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 13826 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 13827 | return; |
| 13828 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13829 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13830 | "0375 FCP cmdiocb not callback function " |
| 13831 | "iotag: (%d)\n", |
| 13832 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13833 | return; |
| 13834 | } |
| 13835 | |
| 13836 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13837 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13838 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 13839 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13840 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13841 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13842 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13843 | } |
| 13844 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13845 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 13846 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 13847 | } |
| 13848 | |
| 13849 | /** |
| 13850 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 13851 | * @phba: Pointer to HBA context object. |
| 13852 | * @cq: Pointer to completion queue. |
| 13853 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13854 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13855 | * 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] | 13856 | * proper WQ release routine to the slow-path WQ. |
| 13857 | **/ |
| 13858 | static void |
| 13859 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13860 | struct lpfc_wcqe_release *wcqe) |
| 13861 | { |
| 13862 | struct lpfc_queue *childwq; |
| 13863 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13864 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13865 | |
| 13866 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13867 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13868 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13869 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13870 | lpfc_sli4_wq_release(childwq, |
| 13871 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 13872 | if (childwq->q_flag & HBA_NVMET_WQFULL) |
| 13873 | lpfc_nvmet_wqfull_process(phba, childwq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13874 | wqid_matched = true; |
| 13875 | break; |
| 13876 | } |
| 13877 | } |
| 13878 | /* Report warning log message if no match found */ |
| 13879 | if (wqid_matched != true) |
| 13880 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13881 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13882 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13883 | } |
| 13884 | |
| 13885 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13886 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 13887 | * @phba: Pointer to HBA context object. |
| 13888 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 13889 | * |
| 13890 | * This routine process a receive-queue completion queue entry. |
| 13891 | * |
| 13892 | * Return: true if work posted to worker thread, otherwise false. |
| 13893 | **/ |
| 13894 | static bool |
| 13895 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13896 | struct lpfc_rcqe *rcqe) |
| 13897 | { |
| 13898 | bool workposted = false; |
| 13899 | struct lpfc_queue *hrq; |
| 13900 | struct lpfc_queue *drq; |
| 13901 | struct rqb_dmabuf *dma_buf; |
| 13902 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13903 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13904 | uint32_t status, rq_id; |
| 13905 | unsigned long iflags; |
| 13906 | uint32_t fctl, idx; |
| 13907 | |
| 13908 | if ((phba->nvmet_support == 0) || |
| 13909 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 13910 | return workposted; |
| 13911 | |
| 13912 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13913 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 13914 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 13915 | |
| 13916 | /* sanity check on queue memory */ |
| 13917 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13918 | return workposted; |
| 13919 | |
| 13920 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13921 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13922 | else |
| 13923 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13924 | |
| 13925 | if ((phba->nvmet_support == 0) || |
| 13926 | (rq_id != hrq->queue_id)) |
| 13927 | return workposted; |
| 13928 | |
| 13929 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13930 | switch (status) { |
| 13931 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13932 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13933 | "6126 Receive Frame Truncated!!\n"); |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 13934 | /* fall through */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13935 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13936 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13937 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13938 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 13939 | if (!dma_buf) { |
| 13940 | hrq->RQ_no_buf_found++; |
| 13941 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13942 | goto out; |
| 13943 | } |
| 13944 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13945 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13946 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13947 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13948 | |
| 13949 | /* Just some basic sanity checks on FCP Command frame */ |
| 13950 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
| 13951 | fc_hdr->fh_f_ctl[1] << 8 | |
| 13952 | fc_hdr->fh_f_ctl[2]); |
| 13953 | if (((fctl & |
| 13954 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 13955 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 13956 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 13957 | goto drop; |
| 13958 | |
| 13959 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13960 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 13961 | lpfc_nvmet_unsol_fcp_event( |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 13962 | phba, idx, dma_buf, cq->isr_timestamp, |
| 13963 | cq->q_flag & HBA_NVMET_CQ_NOTIFY); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13964 | return false; |
| 13965 | } |
| 13966 | drop: |
James Smart | 22b738a | 2019-03-12 16:30:11 -0700 | [diff] [blame] | 13967 | lpfc_rq_buf_free(phba, &dma_buf->hbuf); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13968 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13969 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13970 | if (phba->nvmet_support) { |
| 13971 | tgtp = phba->targetport->private; |
| 13972 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13973 | "6401 RQE Error x%x, posted %d err_cnt " |
| 13974 | "%d: %x %x %x\n", |
| 13975 | status, hrq->RQ_buf_posted, |
| 13976 | hrq->RQ_no_posted_buf, |
| 13977 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13978 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13979 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13980 | } |
| 13981 | /* fallthrough */ |
| 13982 | |
| 13983 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13984 | hrq->RQ_no_posted_buf++; |
| 13985 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13986 | break; |
| 13987 | } |
| 13988 | out: |
| 13989 | return workposted; |
| 13990 | } |
| 13991 | |
| 13992 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13993 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13994 | * @phba: adapter with cq |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13995 | * @cq: Pointer to the completion queue. |
| 13996 | * @eqe: Pointer to fast-path completion queue entry. |
| 13997 | * |
| 13998 | * This routine process a fast-path work queue completion entry from fast-path |
| 13999 | * event queue for FCP command response completion. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14000 | * |
| 14001 | * Return: true if work posted to worker thread, otherwise false. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14002 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14003 | static bool |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14004 | 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] | 14005 | struct lpfc_cqe *cqe) |
| 14006 | { |
| 14007 | struct lpfc_wcqe_release wcqe; |
| 14008 | bool workposted = false; |
| 14009 | |
| 14010 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 14011 | lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14012 | |
| 14013 | /* Check and process for different type of WCQE and dispatch */ |
| 14014 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 14015 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14016 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14017 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14018 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 14019 | phba->last_completion_time = jiffies; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 14020 | if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14021 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14022 | (struct lpfc_wcqe_complete *)&wcqe); |
| 14023 | break; |
| 14024 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14025 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14026 | /* Process the WQ release event */ |
| 14027 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 14028 | (struct lpfc_wcqe_release *)&wcqe); |
| 14029 | break; |
| 14030 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14031 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14032 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14033 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14034 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 14035 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 14036 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14037 | case CQE_CODE_RECEIVE_V1: |
| 14038 | case CQE_CODE_RECEIVE: |
| 14039 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14040 | if (cq->subtype == LPFC_NVMET) { |
| 14041 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 14042 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 14043 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14044 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14045 | default: |
| 14046 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14047 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14048 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 14049 | break; |
| 14050 | } |
| 14051 | return workposted; |
| 14052 | } |
| 14053 | |
| 14054 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14055 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14056 | * @phba: Pointer to HBA context object. |
| 14057 | * @eqe: Pointer to fast-path event queue entry. |
| 14058 | * |
| 14059 | * This routine process a event queue entry from the fast-path event queue. |
| 14060 | * It will check the MajorCode and MinorCode to determine this is for a |
| 14061 | * completion event on a completion queue, if not, an error shall be logged |
| 14062 | * and just return. Otherwise, it will get to the corresponding completion |
| 14063 | * queue and process all the entries on the completion queue, rearm the |
| 14064 | * completion queue, and then return. |
| 14065 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14066 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14067 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 14068 | struct lpfc_eqe *eqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14069 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14070 | struct lpfc_queue *cq = NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14071 | uint32_t qidx = eq->hdwq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14072 | uint16_t cqid, id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14073 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14074 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14075 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14076 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14077 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14078 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 14079 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14080 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14081 | } |
| 14082 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14083 | /* Get the reference to the corresponding CQ */ |
| 14084 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 14085 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14086 | /* Use the fast lookup method first */ |
| 14087 | if (cqid <= phba->sli4_hba.cq_max) { |
| 14088 | cq = phba->sli4_hba.cq_lookup[cqid]; |
| 14089 | if (cq) |
| 14090 | goto work_cq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14091 | } |
| 14092 | |
| 14093 | /* Next check for NVMET completion */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14094 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 14095 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 14096 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 14097 | /* Process NVMET unsol rcv */ |
| 14098 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 14099 | goto process_cq; |
| 14100 | } |
| 14101 | } |
| 14102 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14103 | if (phba->sli4_hba.nvmels_cq && |
| 14104 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 14105 | /* Process NVME unsol rcv */ |
| 14106 | cq = phba->sli4_hba.nvmels_cq; |
| 14107 | } |
| 14108 | |
| 14109 | /* Otherwise this is a Slow path event */ |
| 14110 | if (cq == NULL) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14111 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 14112 | phba->sli4_hba.hdwq[qidx].hba_eq); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14113 | return; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14114 | } |
| 14115 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14116 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14117 | if (unlikely(cqid != cq->queue_id)) { |
| 14118 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14119 | "0368 Miss-matched fast-path completion " |
| 14120 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 14121 | cqid, cq->queue_id); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14122 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14123 | } |
| 14124 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14125 | work_cq: |
James Smart | d74a89a | 2019-05-21 17:48:55 -0700 | [diff] [blame] | 14126 | #if defined(CONFIG_SCSI_LPFC_DEBUG_FS) |
| 14127 | if (phba->ktime_on) |
| 14128 | cq->isr_timestamp = ktime_get_ns(); |
| 14129 | else |
| 14130 | cq->isr_timestamp = 0; |
| 14131 | #endif |
James Smart | 45aa312 | 2019-01-28 11:14:29 -0800 | [diff] [blame] | 14132 | if (!queue_work_on(cq->chann, phba->wq, &cq->irqwork)) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14133 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14134 | "0363 Cannot schedule soft IRQ " |
| 14135 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 14136 | cqid, cq->queue_id, raw_smp_processor_id()); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14137 | } |
| 14138 | |
| 14139 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14140 | * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry |
| 14141 | * @cq: Pointer to CQ to be processed |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14142 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14143 | * This routine calls the cq processing routine with the handler for |
| 14144 | * fast path CQEs. |
| 14145 | * |
| 14146 | * The CQ routine returns two values: the first is the calling status, |
| 14147 | * which indicates whether work was queued to the background discovery |
| 14148 | * thread. If true, the routine should wakeup the discovery thread; |
| 14149 | * the second is the delay parameter. If non-zero, rather than rearming |
| 14150 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 14151 | * that it is processed in a subsequent polling action. The value of |
| 14152 | * the delay indicates when to reschedule it. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14153 | **/ |
| 14154 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14155 | __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14156 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14157 | struct lpfc_hba *phba = cq->phba; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14158 | unsigned long delay; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14159 | bool workposted = false; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14160 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14161 | /* process and rearm the CQ */ |
| 14162 | workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe, |
| 14163 | &delay); |
| 14164 | |
| 14165 | if (delay) { |
| 14166 | if (!queue_delayed_work_on(cq->chann, phba->wq, |
| 14167 | &cq->sched_irqwork, delay)) |
| 14168 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14169 | "0367 Cannot schedule soft IRQ " |
| 14170 | "for cqid=%d on CPU %d\n", |
| 14171 | cq->queue_id, cq->chann); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14172 | } |
| 14173 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14174 | /* wake up worker thread if there are works to be done */ |
| 14175 | if (workposted) |
| 14176 | lpfc_worker_wake_up(phba); |
| 14177 | } |
| 14178 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14179 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14180 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by |
| 14181 | * interrupt |
| 14182 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14183 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14184 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14185 | **/ |
| 14186 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14187 | lpfc_sli4_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14188 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14189 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14190 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14191 | __lpfc_sli4_hba_process_cq(cq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14192 | } |
| 14193 | |
| 14194 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14195 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by timer |
| 14196 | * @work: pointer to work element |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14197 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14198 | * translates from the work handler and calls the fast-path handler. |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14199 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14200 | static void |
| 14201 | lpfc_sli4_dly_hba_process_cq(struct work_struct *work) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14202 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14203 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 14204 | struct lpfc_queue, sched_irqwork); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14205 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14206 | __lpfc_sli4_hba_process_cq(cq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14207 | } |
| 14208 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14209 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14210 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14211 | * @irq: Interrupt number. |
| 14212 | * @dev_id: The device context pointer. |
| 14213 | * |
| 14214 | * This function is directly called from the PCI layer as an interrupt |
| 14215 | * service routine when device with SLI-4 interface spec is enabled with |
| 14216 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 14217 | * ring event in the HBA. However, when the device is enabled with either |
| 14218 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 14219 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 14220 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 14221 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 14222 | * the intrrupt context. This function is called without any lock held. |
| 14223 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 14224 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 14225 | * equal to that of FCP CQ index. |
| 14226 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14227 | * The link attention and ELS ring attention events are handled |
| 14228 | * by the worker thread. The interrupt handler signals the worker thread |
| 14229 | * and returns for these events. This function is called without any lock |
| 14230 | * held. It gets the hbalock to access and update SLI data structures. |
| 14231 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14232 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 14233 | * returns IRQ_NONE. |
| 14234 | **/ |
| 14235 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14236 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14237 | { |
| 14238 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14239 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14240 | struct lpfc_queue *fpeq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14241 | unsigned long iflag; |
| 14242 | int ecount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14243 | int hba_eqidx; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14244 | struct lpfc_eq_intr_info *eqi; |
| 14245 | uint32_t icnt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14246 | |
| 14247 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14248 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 14249 | phba = hba_eq_hdl->phba; |
| 14250 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14251 | |
| 14252 | if (unlikely(!phba)) |
| 14253 | return IRQ_NONE; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14254 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 14255 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14256 | |
| 14257 | /* Get to the EQ struct associated with this vector */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14258 | fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14259 | if (unlikely(!fpeq)) |
| 14260 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14261 | |
| 14262 | /* Check device state for handling interrupt */ |
| 14263 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 14264 | /* Check again for link_state with lock held */ |
| 14265 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 14266 | if (phba->link_state < LPFC_LINK_DOWN) |
| 14267 | /* Flush, clear interrupt, and rearm the EQ */ |
James Smart | 24c7c0a | 2019-09-21 20:58:58 -0700 | [diff] [blame] | 14268 | lpfc_sli4_eqcq_flush(phba, fpeq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14269 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 14270 | return IRQ_NONE; |
| 14271 | } |
| 14272 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14273 | eqi = phba->sli4_hba.eq_info; |
| 14274 | icnt = this_cpu_inc_return(eqi->icnt); |
Bart Van Assche | d6d189c | 2019-03-28 11:06:22 -0700 | [diff] [blame] | 14275 | fpeq->last_cpu = raw_smp_processor_id(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14276 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14277 | if (icnt > LPFC_EQD_ISR_TRIGGER && |
| 14278 | phba->cfg_irq_chann == 1 && |
| 14279 | phba->cfg_auto_imax && |
| 14280 | fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY && |
| 14281 | phba->sli.sli_flag & LPFC_SLI_USE_EQDR) |
| 14282 | 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] | 14283 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14284 | /* process and rearm the EQ */ |
| 14285 | ecount = lpfc_sli4_process_eq(phba, fpeq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14286 | |
| 14287 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14288 | fpeq->EQ_no_entry++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14289 | if (phba->intr_type == MSIX) |
| 14290 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 14291 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14292 | "0358 MSI-X interrupt with no EQE\n"); |
| 14293 | else |
| 14294 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 14295 | return IRQ_NONE; |
| 14296 | } |
| 14297 | |
| 14298 | return IRQ_HANDLED; |
| 14299 | } /* lpfc_sli4_fp_intr_handler */ |
| 14300 | |
| 14301 | /** |
| 14302 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 14303 | * @irq: Interrupt number. |
| 14304 | * @dev_id: The device context pointer. |
| 14305 | * |
| 14306 | * This function is the device-level interrupt handler to device with SLI-4 |
| 14307 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 14308 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 14309 | * driver attention. This function invokes the slow-path interrupt attention |
| 14310 | * handling function and fast-path interrupt attention handling function in |
| 14311 | * turn to process the relevant HBA attention events. This function is called |
| 14312 | * without any lock held. It gets the hbalock to access and update SLI data |
| 14313 | * structures. |
| 14314 | * |
| 14315 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 14316 | * returns IRQ_NONE. |
| 14317 | **/ |
| 14318 | irqreturn_t |
| 14319 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 14320 | { |
| 14321 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14322 | irqreturn_t hba_irq_rc; |
| 14323 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14324 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14325 | |
| 14326 | /* Get the driver's phba structure from the dev_id */ |
| 14327 | phba = (struct lpfc_hba *)dev_id; |
| 14328 | |
| 14329 | if (unlikely(!phba)) |
| 14330 | return IRQ_NONE; |
| 14331 | |
| 14332 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14333 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 14334 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14335 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14336 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14337 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14338 | if (hba_irq_rc == IRQ_HANDLED) |
| 14339 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14340 | } |
| 14341 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14342 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14343 | } /* lpfc_sli4_intr_handler */ |
| 14344 | |
| 14345 | /** |
| 14346 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 14347 | * @queue: The queue structure to free. |
| 14348 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 14349 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14350 | * the host resident queue. This function must be called after destroying the |
| 14351 | * queue on the HBA. |
| 14352 | **/ |
| 14353 | void |
| 14354 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 14355 | { |
| 14356 | struct lpfc_dmabuf *dmabuf; |
| 14357 | |
| 14358 | if (!queue) |
| 14359 | return; |
| 14360 | |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 14361 | if (!list_empty(&queue->wq_list)) |
| 14362 | list_del(&queue->wq_list); |
| 14363 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14364 | while (!list_empty(&queue->page_list)) { |
| 14365 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 14366 | list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14367 | dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14368 | dmabuf->virt, dmabuf->phys); |
| 14369 | kfree(dmabuf); |
| 14370 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14371 | if (queue->rqbp) { |
| 14372 | lpfc_free_rq_buffer(queue->phba, queue); |
| 14373 | kfree(queue->rqbp); |
| 14374 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 14375 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14376 | if (!list_empty(&queue->cpu_list)) |
| 14377 | list_del(&queue->cpu_list); |
| 14378 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14379 | kfree(queue); |
| 14380 | return; |
| 14381 | } |
| 14382 | |
| 14383 | /** |
| 14384 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 14385 | * @phba: The HBA that this queue is being created on. |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14386 | * @page_size: The size of a queue page |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14387 | * @entry_size: The size of each queue entry for this queue. |
| 14388 | * @entry count: The number of entries that this queue will handle. |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14389 | * @cpu: The cpu that will primarily utilize this queue. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14390 | * |
| 14391 | * This function allocates a queue structure and the DMAable memory used for |
| 14392 | * the host resident queue. This function must be called before creating the |
| 14393 | * queue on the HBA. |
| 14394 | **/ |
| 14395 | struct lpfc_queue * |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14396 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14397 | uint32_t entry_size, uint32_t entry_count, int cpu) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14398 | { |
| 14399 | struct lpfc_queue *queue; |
| 14400 | struct lpfc_dmabuf *dmabuf; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14401 | 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] | 14402 | uint16_t x, pgcnt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14403 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14404 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14405 | hw_page_size = page_size; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14406 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14407 | pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14408 | |
| 14409 | /* If needed, Adjust page count to match the max the adapter supports */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14410 | if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt) |
| 14411 | pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 14412 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14413 | queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt), |
| 14414 | GFP_KERNEL, cpu_to_node(cpu)); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14415 | if (!queue) |
| 14416 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14417 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14418 | INIT_LIST_HEAD(&queue->list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14419 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 14420 | INIT_LIST_HEAD(&queue->wqfull_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14421 | INIT_LIST_HEAD(&queue->page_list); |
| 14422 | INIT_LIST_HEAD(&queue->child_list); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14423 | INIT_LIST_HEAD(&queue->cpu_list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14424 | |
| 14425 | /* Set queue parameters now. If the system cannot provide memory |
| 14426 | * resources, the free routine needs to know what was allocated. |
| 14427 | */ |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14428 | queue->page_count = pgcnt; |
| 14429 | queue->q_pgs = (void **)&queue[1]; |
| 14430 | queue->entry_cnt_per_pg = hw_page_size / entry_size; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14431 | queue->entry_size = entry_size; |
| 14432 | queue->entry_count = entry_count; |
| 14433 | queue->page_size = hw_page_size; |
| 14434 | queue->phba = phba; |
| 14435 | |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14436 | for (x = 0; x < queue->page_count; x++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 14437 | dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL, |
| 14438 | dev_to_node(&phba->pcidev->dev)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14439 | if (!dmabuf) |
| 14440 | goto out_fail; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 14441 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 14442 | hw_page_size, &dmabuf->phys, |
| 14443 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14444 | if (!dmabuf->virt) { |
| 14445 | kfree(dmabuf); |
| 14446 | goto out_fail; |
| 14447 | } |
| 14448 | dmabuf->buffer_tag = x; |
| 14449 | list_add_tail(&dmabuf->list, &queue->page_list); |
James Smart | 9afbee3 | 2019-03-12 16:30:28 -0700 | [diff] [blame] | 14450 | /* use lpfc_sli4_qe to index a paritcular entry in this page */ |
| 14451 | queue->q_pgs[x] = dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14452 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14453 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
| 14454 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14455 | INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq); |
| 14456 | INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14457 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14458 | /* notify_interval will be set during q creation */ |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14459 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14460 | return queue; |
| 14461 | out_fail: |
| 14462 | lpfc_sli4_queue_free(queue); |
| 14463 | return NULL; |
| 14464 | } |
| 14465 | |
| 14466 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14467 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 14468 | * @phba: HBA structure that indicates port to create a queue on. |
| 14469 | * @pci_barset: PCI BAR set flag. |
| 14470 | * |
| 14471 | * This function shall perform iomap of the specified PCI BAR address to host |
| 14472 | * memory address if not already done so and return it. The returned host |
| 14473 | * memory address can be NULL. |
| 14474 | */ |
| 14475 | static void __iomem * |
| 14476 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 14477 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14478 | if (!phba->pcidev) |
| 14479 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14480 | |
| 14481 | switch (pci_barset) { |
| 14482 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14483 | return phba->pci_bar0_memmap_p; |
| 14484 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14485 | return phba->pci_bar2_memmap_p; |
| 14486 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14487 | return phba->pci_bar4_memmap_p; |
| 14488 | default: |
| 14489 | break; |
| 14490 | } |
| 14491 | return NULL; |
| 14492 | } |
| 14493 | |
| 14494 | /** |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14495 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs |
| 14496 | * @phba: HBA structure that EQs are on. |
| 14497 | * @startq: The starting EQ index to modify |
| 14498 | * @numq: The number of EQs (consecutive indexes) to modify |
| 14499 | * @usdelay: amount of delay |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14500 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14501 | * This function revises the EQ delay on 1 or more EQs. The EQ delay |
| 14502 | * is set either by writing to a register (if supported by the SLI Port) |
| 14503 | * or by mailbox command. The mailbox command allows several EQs to be |
| 14504 | * updated at once. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14505 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14506 | * The @phba struct is used to send a mailbox command to HBA. The @startq |
| 14507 | * is used to get the starting EQ index to change. The @numq value is |
| 14508 | * used to specify how many consecutive EQ indexes, starting at EQ index, |
| 14509 | * are to be changed. This function is asynchronous and will wait for any |
| 14510 | * mailbox commands to finish before returning. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14511 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14512 | * On success this function will return a zero. If unable to allocate |
| 14513 | * enough memory this function will return -ENOMEM. If a mailbox command |
| 14514 | * fails this function will return -ENXIO. Note: on ENXIO, some EQs may |
| 14515 | * have had their delay multipler changed. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14516 | **/ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14517 | void |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14518 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14519 | uint32_t numq, uint32_t usdelay) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14520 | { |
| 14521 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 14522 | LPFC_MBOXQ_t *mbox; |
| 14523 | struct lpfc_queue *eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14524 | int cnt = 0, rc, length; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14525 | uint32_t shdr_status, shdr_add_status; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14526 | uint32_t dmult; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14527 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14528 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14529 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14530 | if (startq >= phba->cfg_irq_chann) |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14531 | return; |
| 14532 | |
| 14533 | if (usdelay > 0xFFFF) { |
| 14534 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME, |
| 14535 | "6429 usdelay %d too large. Scaled down to " |
| 14536 | "0xFFFF.\n", usdelay); |
| 14537 | usdelay = 0xFFFF; |
| 14538 | } |
| 14539 | |
| 14540 | /* set values by EQ_DELAY register if supported */ |
| 14541 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 14542 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14543 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14544 | if (!eq) |
| 14545 | continue; |
| 14546 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14547 | lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14548 | |
| 14549 | if (++cnt >= numq) |
| 14550 | break; |
| 14551 | } |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14552 | return; |
| 14553 | } |
| 14554 | |
| 14555 | /* Otherwise, set values by mailbox cmd */ |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14556 | |
| 14557 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14558 | if (!mbox) { |
| 14559 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_FCP | LOG_NVME, |
| 14560 | "6428 Failed allocating mailbox cmd buffer." |
| 14561 | " EQ delay was not set.\n"); |
| 14562 | return; |
| 14563 | } |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14564 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 14565 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14566 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14567 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 14568 | length, LPFC_SLI4_MBX_EMBED); |
| 14569 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 14570 | |
| 14571 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14572 | dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC; |
| 14573 | if (dmult) |
| 14574 | dmult--; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14575 | if (dmult > LPFC_DMULT_MAX) |
| 14576 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14577 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14578 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 14579 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14580 | if (!eq) |
| 14581 | continue; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14582 | eq->q_mode = usdelay; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14583 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 14584 | eq_delay->u.request.eq[cnt].phase = 0; |
| 14585 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14586 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14587 | if (++cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14588 | break; |
| 14589 | } |
| 14590 | eq_delay->u.request.num_eq = cnt; |
| 14591 | |
| 14592 | mbox->vport = phba->pport; |
| 14593 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14594 | mbox->ctx_buf = NULL; |
| 14595 | mbox->ctx_ndlp = NULL; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14596 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14597 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 14598 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14599 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14600 | if (shdr_status || shdr_add_status || rc) { |
| 14601 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14602 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 14603 | "status x%x add_status x%x, mbx status x%x\n", |
| 14604 | shdr_status, shdr_add_status, rc); |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14605 | } |
| 14606 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14607 | return; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14608 | } |
| 14609 | |
| 14610 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14611 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 14612 | * @phba: HBA structure that indicates port to create a queue on. |
| 14613 | * @eq: The queue structure to use to create the event queue. |
| 14614 | * @imax: The maximum interrupt per second limit. |
| 14615 | * |
| 14616 | * This function creates an event queue, as detailed in @eq, on a port, |
| 14617 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 14618 | * |
| 14619 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 14620 | * is used to get the entry count and entry size that are necessary to |
| 14621 | * determine the number of pages to allocate and use for this queue. This |
| 14622 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 14623 | * event queue. This function is asynchronous and will wait for the mailbox |
| 14624 | * command to finish before continuing. |
| 14625 | * |
| 14626 | * 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] | 14627 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14628 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14629 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14630 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14631 | 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] | 14632 | { |
| 14633 | struct lpfc_mbx_eq_create *eq_create; |
| 14634 | LPFC_MBOXQ_t *mbox; |
| 14635 | int rc, length, status = 0; |
| 14636 | struct lpfc_dmabuf *dmabuf; |
| 14637 | uint32_t shdr_status, shdr_add_status; |
| 14638 | union lpfc_sli4_cfg_shdr *shdr; |
| 14639 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14640 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14641 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14642 | /* sanity check on queue memory */ |
| 14643 | if (!eq) |
| 14644 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14645 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14646 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14647 | |
| 14648 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14649 | if (!mbox) |
| 14650 | return -ENOMEM; |
| 14651 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 14652 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14653 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14654 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 14655 | length, LPFC_SLI4_MBX_EMBED); |
| 14656 | eq_create = &mbox->u.mqe.un.eq_create; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14657 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14658 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 14659 | eq->page_count); |
| 14660 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 14661 | LPFC_EQE_SIZE); |
| 14662 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14663 | |
| 14664 | /* Use version 2 of CREATE_EQ if eqav is set */ |
| 14665 | if (phba->sli4_hba.pc_sli4_params.eqav) { |
| 14666 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14667 | LPFC_Q_CREATE_VERSION_2); |
| 14668 | bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context, |
| 14669 | phba->sli4_hba.pc_sli4_params.eqav); |
| 14670 | } |
| 14671 | |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 14672 | /* don't setup delay multiplier using EQ_CREATE */ |
| 14673 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14674 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 14675 | dmult); |
| 14676 | switch (eq->entry_count) { |
| 14677 | default: |
| 14678 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14679 | "0360 Unsupported EQ count. (%d)\n", |
| 14680 | eq->entry_count); |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 14681 | if (eq->entry_count < 256) { |
| 14682 | status = -EINVAL; |
| 14683 | goto out; |
| 14684 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 14685 | /* fall through - otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14686 | case 256: |
| 14687 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14688 | LPFC_EQ_CNT_256); |
| 14689 | break; |
| 14690 | case 512: |
| 14691 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14692 | LPFC_EQ_CNT_512); |
| 14693 | break; |
| 14694 | case 1024: |
| 14695 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14696 | LPFC_EQ_CNT_1024); |
| 14697 | break; |
| 14698 | case 2048: |
| 14699 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14700 | LPFC_EQ_CNT_2048); |
| 14701 | break; |
| 14702 | case 4096: |
| 14703 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14704 | LPFC_EQ_CNT_4096); |
| 14705 | break; |
| 14706 | } |
| 14707 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14708 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14709 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14710 | putPaddrLow(dmabuf->phys); |
| 14711 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14712 | putPaddrHigh(dmabuf->phys); |
| 14713 | } |
| 14714 | mbox->vport = phba->pport; |
| 14715 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14716 | mbox->ctx_buf = NULL; |
| 14717 | mbox->ctx_ndlp = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14718 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14719 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14720 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14721 | if (shdr_status || shdr_add_status || rc) { |
| 14722 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14723 | "2500 EQ_CREATE mailbox failed with " |
| 14724 | "status x%x add_status x%x, mbx status x%x\n", |
| 14725 | shdr_status, shdr_add_status, rc); |
| 14726 | status = -ENXIO; |
| 14727 | } |
| 14728 | eq->type = LPFC_EQ; |
| 14729 | eq->subtype = LPFC_NONE; |
| 14730 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 14731 | if (eq->queue_id == 0xFFFF) |
| 14732 | status = -ENXIO; |
| 14733 | eq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14734 | eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL; |
| 14735 | eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT; |
James Smart | 04d210c | 2019-05-21 17:49:03 -0700 | [diff] [blame] | 14736 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14737 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14738 | return status; |
| 14739 | } |
| 14740 | |
| 14741 | /** |
| 14742 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 14743 | * @phba: HBA structure that indicates port to create a queue on. |
| 14744 | * @cq: The queue structure to use to create the completion queue. |
| 14745 | * @eq: The event queue to bind this completion queue to. |
| 14746 | * |
| 14747 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 14748 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 14749 | * |
| 14750 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14751 | * is used to get the entry count and entry size that are necessary to |
| 14752 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14753 | * is used to indicate which event queue to bind this completion queue to. This |
| 14754 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 14755 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14756 | * command to finish before continuing. |
| 14757 | * |
| 14758 | * 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] | 14759 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14760 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14761 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14762 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14763 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14764 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 14765 | { |
| 14766 | struct lpfc_mbx_cq_create *cq_create; |
| 14767 | struct lpfc_dmabuf *dmabuf; |
| 14768 | LPFC_MBOXQ_t *mbox; |
| 14769 | int rc, length, status = 0; |
| 14770 | uint32_t shdr_status, shdr_add_status; |
| 14771 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14772 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14773 | /* sanity check on queue memory */ |
| 14774 | if (!cq || !eq) |
| 14775 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14776 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14777 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14778 | if (!mbox) |
| 14779 | return -ENOMEM; |
| 14780 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 14781 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14782 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14783 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 14784 | length, LPFC_SLI4_MBX_EMBED); |
| 14785 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14786 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14787 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 14788 | cq->page_count); |
| 14789 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 14790 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14791 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14792 | phba->sli4_hba.pc_sli4_params.cqv); |
| 14793 | 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] | 14794 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, |
| 14795 | (cq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14796 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 14797 | eq->queue_id); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14798 | bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context, |
| 14799 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14800 | } else { |
| 14801 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 14802 | eq->queue_id); |
| 14803 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14804 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14805 | case 2048: |
| 14806 | case 4096: |
| 14807 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 14808 | LPFC_Q_CREATE_VERSION_2) { |
| 14809 | cq_create->u.request.context.lpfc_cq_context_count = |
| 14810 | cq->entry_count; |
| 14811 | bf_set(lpfc_cq_context_count, |
| 14812 | &cq_create->u.request.context, |
| 14813 | LPFC_CQ_CNT_WORD7); |
| 14814 | break; |
| 14815 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 14816 | /* fall through */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14817 | default: |
| 14818 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14819 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14820 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14821 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14822 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14823 | if (cq->entry_count < 256) { |
| 14824 | status = -EINVAL; |
| 14825 | goto out; |
| 14826 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 14827 | /* fall through - otherwise default to smallest count */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14828 | case 256: |
| 14829 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14830 | LPFC_CQ_CNT_256); |
| 14831 | break; |
| 14832 | case 512: |
| 14833 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14834 | LPFC_CQ_CNT_512); |
| 14835 | break; |
| 14836 | case 1024: |
| 14837 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14838 | LPFC_CQ_CNT_1024); |
| 14839 | break; |
| 14840 | } |
| 14841 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14842 | memset(dmabuf->virt, 0, cq->page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14843 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14844 | putPaddrLow(dmabuf->phys); |
| 14845 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14846 | putPaddrHigh(dmabuf->phys); |
| 14847 | } |
| 14848 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14849 | |
| 14850 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14851 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14852 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14853 | if (shdr_status || shdr_add_status || rc) { |
| 14854 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14855 | "2501 CQ_CREATE mailbox failed with " |
| 14856 | "status x%x add_status x%x, mbx status x%x\n", |
| 14857 | shdr_status, shdr_add_status, rc); |
| 14858 | status = -ENXIO; |
| 14859 | goto out; |
| 14860 | } |
| 14861 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 14862 | if (cq->queue_id == 0xFFFF) { |
| 14863 | status = -ENXIO; |
| 14864 | goto out; |
| 14865 | } |
| 14866 | /* link the cq onto the parent eq child list */ |
| 14867 | list_add_tail(&cq->list, &eq->child_list); |
| 14868 | /* Set up completion queue's type and subtype */ |
| 14869 | cq->type = type; |
| 14870 | cq->subtype = subtype; |
| 14871 | 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] | 14872 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14873 | cq->assoc_qp = eq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14874 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14875 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 14876 | 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] | 14877 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14878 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 14879 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14880 | out: |
| 14881 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14882 | return status; |
| 14883 | } |
| 14884 | |
| 14885 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14886 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 14887 | * @phba: HBA structure that indicates port to create a queue on. |
| 14888 | * @cqp: The queue structure array to use to create the completion queues. |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14889 | * @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] | 14890 | * |
| 14891 | * This function creates a set of completion queue, s to support MRQ |
| 14892 | * as detailed in @cqp, on a port, |
| 14893 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 14894 | * |
| 14895 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14896 | * is used to get the entry count and entry size that are necessary to |
| 14897 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14898 | * is used to indicate which event queue to bind this completion queue to. This |
| 14899 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 14900 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14901 | * command to finish before continuing. |
| 14902 | * |
| 14903 | * On success this function will return a zero. If unable to allocate enough |
| 14904 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14905 | * fails this function will return -ENXIO. |
| 14906 | **/ |
| 14907 | int |
| 14908 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14909 | struct lpfc_sli4_hdw_queue *hdwq, uint32_t type, |
| 14910 | uint32_t subtype) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14911 | { |
| 14912 | struct lpfc_queue *cq; |
| 14913 | struct lpfc_queue *eq; |
| 14914 | struct lpfc_mbx_cq_create_set *cq_set; |
| 14915 | struct lpfc_dmabuf *dmabuf; |
| 14916 | LPFC_MBOXQ_t *mbox; |
| 14917 | int rc, length, alloclen, status = 0; |
| 14918 | int cnt, idx, numcq, page_idx = 0; |
| 14919 | uint32_t shdr_status, shdr_add_status; |
| 14920 | union lpfc_sli4_cfg_shdr *shdr; |
| 14921 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14922 | |
| 14923 | /* sanity check on queue memory */ |
| 14924 | numcq = phba->cfg_nvmet_mrq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14925 | if (!cqp || !hdwq || !numcq) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14926 | return -ENODEV; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14927 | |
| 14928 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14929 | if (!mbox) |
| 14930 | return -ENOMEM; |
| 14931 | |
| 14932 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 14933 | length += ((numcq * cqp[0]->page_count) * |
| 14934 | sizeof(struct dma_address)); |
| 14935 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14936 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 14937 | LPFC_SLI4_MBX_NEMBED); |
| 14938 | if (alloclen < length) { |
| 14939 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14940 | "3098 Allocated DMA memory size (%d) is " |
| 14941 | "less than the requested DMA memory size " |
| 14942 | "(%d)\n", alloclen, length); |
| 14943 | status = -ENOMEM; |
| 14944 | goto out; |
| 14945 | } |
| 14946 | cq_set = mbox->sge_array->addr[0]; |
| 14947 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 14948 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 14949 | |
| 14950 | for (idx = 0; idx < numcq; idx++) { |
| 14951 | cq = cqp[idx]; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14952 | eq = hdwq[idx].hba_eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14953 | if (!cq || !eq) { |
| 14954 | status = -ENOMEM; |
| 14955 | goto out; |
| 14956 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14957 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14958 | hw_page_size = cq->page_size; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14959 | |
| 14960 | switch (idx) { |
| 14961 | case 0: |
| 14962 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 14963 | &cq_set->u.request, |
| 14964 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 14965 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 14966 | &cq_set->u.request, cq->page_count); |
| 14967 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 14968 | &cq_set->u.request, 1); |
| 14969 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 14970 | &cq_set->u.request, 1); |
| 14971 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 14972 | &cq_set->u.request, 0); |
| 14973 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 14974 | &cq_set->u.request, numcq); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14975 | bf_set(lpfc_mbx_cq_create_set_autovalid, |
| 14976 | &cq_set->u.request, |
| 14977 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14978 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14979 | case 2048: |
| 14980 | case 4096: |
| 14981 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 14982 | LPFC_Q_CREATE_VERSION_2) { |
| 14983 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14984 | &cq_set->u.request, |
| 14985 | cq->entry_count); |
| 14986 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14987 | &cq_set->u.request, |
| 14988 | LPFC_CQ_CNT_WORD7); |
| 14989 | break; |
| 14990 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 14991 | /* fall through */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14992 | default: |
| 14993 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14994 | "3118 Bad CQ count. (%d)\n", |
| 14995 | cq->entry_count); |
| 14996 | if (cq->entry_count < 256) { |
| 14997 | status = -EINVAL; |
| 14998 | goto out; |
| 14999 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15000 | /* fall through - otherwise default to smallest */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15001 | case 256: |
| 15002 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15003 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 15004 | break; |
| 15005 | case 512: |
| 15006 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15007 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 15008 | break; |
| 15009 | case 1024: |
| 15010 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15011 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 15012 | break; |
| 15013 | } |
| 15014 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 15015 | &cq_set->u.request, eq->queue_id); |
| 15016 | break; |
| 15017 | case 1: |
| 15018 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 15019 | &cq_set->u.request, eq->queue_id); |
| 15020 | break; |
| 15021 | case 2: |
| 15022 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 15023 | &cq_set->u.request, eq->queue_id); |
| 15024 | break; |
| 15025 | case 3: |
| 15026 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 15027 | &cq_set->u.request, eq->queue_id); |
| 15028 | break; |
| 15029 | case 4: |
| 15030 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 15031 | &cq_set->u.request, eq->queue_id); |
| 15032 | break; |
| 15033 | case 5: |
| 15034 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 15035 | &cq_set->u.request, eq->queue_id); |
| 15036 | break; |
| 15037 | case 6: |
| 15038 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 15039 | &cq_set->u.request, eq->queue_id); |
| 15040 | break; |
| 15041 | case 7: |
| 15042 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 15043 | &cq_set->u.request, eq->queue_id); |
| 15044 | break; |
| 15045 | case 8: |
| 15046 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 15047 | &cq_set->u.request, eq->queue_id); |
| 15048 | break; |
| 15049 | case 9: |
| 15050 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 15051 | &cq_set->u.request, eq->queue_id); |
| 15052 | break; |
| 15053 | case 10: |
| 15054 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 15055 | &cq_set->u.request, eq->queue_id); |
| 15056 | break; |
| 15057 | case 11: |
| 15058 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 15059 | &cq_set->u.request, eq->queue_id); |
| 15060 | break; |
| 15061 | case 12: |
| 15062 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 15063 | &cq_set->u.request, eq->queue_id); |
| 15064 | break; |
| 15065 | case 13: |
| 15066 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 15067 | &cq_set->u.request, eq->queue_id); |
| 15068 | break; |
| 15069 | case 14: |
| 15070 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 15071 | &cq_set->u.request, eq->queue_id); |
| 15072 | break; |
| 15073 | case 15: |
| 15074 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 15075 | &cq_set->u.request, eq->queue_id); |
| 15076 | break; |
| 15077 | } |
| 15078 | |
| 15079 | /* link the cq onto the parent eq child list */ |
| 15080 | list_add_tail(&cq->list, &eq->child_list); |
| 15081 | /* Set up completion queue's type and subtype */ |
| 15082 | cq->type = type; |
| 15083 | cq->subtype = subtype; |
| 15084 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15085 | cq->assoc_qp = eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15086 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15087 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 15088 | cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, |
| 15089 | cq->entry_count); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15090 | cq->chann = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15091 | |
| 15092 | rc = 0; |
| 15093 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 15094 | memset(dmabuf->virt, 0, hw_page_size); |
| 15095 | cnt = page_idx + dmabuf->buffer_tag; |
| 15096 | cq_set->u.request.page[cnt].addr_lo = |
| 15097 | putPaddrLow(dmabuf->phys); |
| 15098 | cq_set->u.request.page[cnt].addr_hi = |
| 15099 | putPaddrHigh(dmabuf->phys); |
| 15100 | rc++; |
| 15101 | } |
| 15102 | page_idx += rc; |
| 15103 | } |
| 15104 | |
| 15105 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15106 | |
| 15107 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15108 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15109 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15110 | if (shdr_status || shdr_add_status || rc) { |
| 15111 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15112 | "3119 CQ_CREATE_SET mailbox failed with " |
| 15113 | "status x%x add_status x%x, mbx status x%x\n", |
| 15114 | shdr_status, shdr_add_status, rc); |
| 15115 | status = -ENXIO; |
| 15116 | goto out; |
| 15117 | } |
| 15118 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 15119 | if (rc == 0xFFFF) { |
| 15120 | status = -ENXIO; |
| 15121 | goto out; |
| 15122 | } |
| 15123 | |
| 15124 | for (idx = 0; idx < numcq; idx++) { |
| 15125 | cq = cqp[idx]; |
| 15126 | cq->queue_id = rc + idx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15127 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 15128 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15129 | } |
| 15130 | |
| 15131 | out: |
| 15132 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 15133 | return status; |
| 15134 | } |
| 15135 | |
| 15136 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15137 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15138 | * @phba: HBA structure that indicates port to create a queue on. |
| 15139 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15140 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 15141 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15142 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15143 | * This function provides failback (fb) functionality when the |
| 15144 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 15145 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15146 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15147 | * This routine cannot fail as all attributes were previously accessed and |
| 15148 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15149 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15150 | static void |
| 15151 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15152 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15153 | { |
| 15154 | struct lpfc_mbx_mq_create *mq_create; |
| 15155 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15156 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15157 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15158 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 15159 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15160 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15161 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 15162 | length, LPFC_SLI4_MBX_EMBED); |
| 15163 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15164 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15165 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15166 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15167 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15168 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 15169 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15170 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15171 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15172 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15173 | break; |
| 15174 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15175 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15176 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15177 | break; |
| 15178 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15179 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15180 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15181 | break; |
| 15182 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15183 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15184 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15185 | break; |
| 15186 | } |
| 15187 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 15188 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15189 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15190 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15191 | putPaddrHigh(dmabuf->phys); |
| 15192 | } |
| 15193 | } |
| 15194 | |
| 15195 | /** |
| 15196 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 15197 | * @phba: HBA structure that indicates port to create a queue on. |
| 15198 | * @mq: The queue structure to use to create the mailbox queue. |
| 15199 | * @cq: The completion queue to associate with this cq. |
| 15200 | * @subtype: The queue's subtype. |
| 15201 | * |
| 15202 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 15203 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 15204 | * |
| 15205 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15206 | * is used to get the entry count and entry size that are necessary to |
| 15207 | * determine the number of pages to allocate and use for this queue. This |
| 15208 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 15209 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 15210 | * command to finish before continuing. |
| 15211 | * |
| 15212 | * 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] | 15213 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15214 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15215 | **/ |
| 15216 | int32_t |
| 15217 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15218 | struct lpfc_queue *cq, uint32_t subtype) |
| 15219 | { |
| 15220 | struct lpfc_mbx_mq_create *mq_create; |
| 15221 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 15222 | struct lpfc_dmabuf *dmabuf; |
| 15223 | LPFC_MBOXQ_t *mbox; |
| 15224 | int rc, length, status = 0; |
| 15225 | uint32_t shdr_status, shdr_add_status; |
| 15226 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15227 | 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] | 15228 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15229 | /* sanity check on queue memory */ |
| 15230 | if (!mq || !cq) |
| 15231 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15232 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15233 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15234 | |
| 15235 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15236 | if (!mbox) |
| 15237 | return -ENOMEM; |
| 15238 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 15239 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15240 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15241 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 15242 | length, LPFC_SLI4_MBX_EMBED); |
| 15243 | |
| 15244 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15245 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15246 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 15247 | &mq_create_ext->u.request, mq->page_count); |
| 15248 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 15249 | &mq_create_ext->u.request, 1); |
| 15250 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15251 | &mq_create_ext->u.request, 1); |
| 15252 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 15253 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15254 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 15255 | &mq_create_ext->u.request, 1); |
| 15256 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 15257 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15258 | 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] | 15259 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15260 | phba->sli4_hba.pc_sli4_params.mqv); |
| 15261 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 15262 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 15263 | cq->queue_id); |
| 15264 | else |
| 15265 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 15266 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15267 | switch (mq->entry_count) { |
| 15268 | default: |
| 15269 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15270 | "0362 Unsupported MQ count. (%d)\n", |
| 15271 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15272 | if (mq->entry_count < 16) { |
| 15273 | status = -EINVAL; |
| 15274 | goto out; |
| 15275 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15276 | /* fall through - otherwise default to smallest count */ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15277 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15278 | bf_set(lpfc_mq_context_ring_size, |
| 15279 | &mq_create_ext->u.request.context, |
| 15280 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15281 | break; |
| 15282 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15283 | bf_set(lpfc_mq_context_ring_size, |
| 15284 | &mq_create_ext->u.request.context, |
| 15285 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15286 | break; |
| 15287 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15288 | bf_set(lpfc_mq_context_ring_size, |
| 15289 | &mq_create_ext->u.request.context, |
| 15290 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15291 | break; |
| 15292 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15293 | bf_set(lpfc_mq_context_ring_size, |
| 15294 | &mq_create_ext->u.request.context, |
| 15295 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15296 | break; |
| 15297 | } |
| 15298 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15299 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15300 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15301 | putPaddrLow(dmabuf->phys); |
| 15302 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15303 | putPaddrHigh(dmabuf->phys); |
| 15304 | } |
| 15305 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15306 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15307 | &mq_create_ext->u.response); |
| 15308 | if (rc != MBX_SUCCESS) { |
| 15309 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15310 | "2795 MQ_CREATE_EXT failed with " |
| 15311 | "status x%x. Failback to MQ_CREATE.\n", |
| 15312 | rc); |
| 15313 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 15314 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15315 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15316 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 15317 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15318 | &mq_create->u.response); |
| 15319 | } |
| 15320 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15321 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15322 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15323 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15324 | if (shdr_status || shdr_add_status || rc) { |
| 15325 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15326 | "2502 MQ_CREATE mailbox failed with " |
| 15327 | "status x%x add_status x%x, mbx status x%x\n", |
| 15328 | shdr_status, shdr_add_status, rc); |
| 15329 | status = -ENXIO; |
| 15330 | goto out; |
| 15331 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15332 | if (mq->queue_id == 0xFFFF) { |
| 15333 | status = -ENXIO; |
| 15334 | goto out; |
| 15335 | } |
| 15336 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15337 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15338 | mq->subtype = subtype; |
| 15339 | mq->host_index = 0; |
| 15340 | mq->hba_index = 0; |
| 15341 | |
| 15342 | /* link the mq onto the parent cq child list */ |
| 15343 | list_add_tail(&mq->list, &cq->child_list); |
| 15344 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15345 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15346 | return status; |
| 15347 | } |
| 15348 | |
| 15349 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15350 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 15351 | * @phba: HBA structure that indicates port to create a queue on. |
| 15352 | * @wq: The queue structure to use to create the work queue. |
| 15353 | * @cq: The completion queue to bind this work queue to. |
| 15354 | * @subtype: The subtype of the work queue indicating its functionality. |
| 15355 | * |
| 15356 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 15357 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 15358 | * |
| 15359 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 15360 | * is used to get the entry count and entry size that are necessary to |
| 15361 | * determine the number of pages to allocate and use for this queue. The @cq |
| 15362 | * is used to indicate which completion queue to bind this work queue to. This |
| 15363 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 15364 | * work queue. This function is asynchronous and will wait for the mailbox |
| 15365 | * command to finish before continuing. |
| 15366 | * |
| 15367 | * 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] | 15368 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15369 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15370 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15371 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15372 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 15373 | struct lpfc_queue *cq, uint32_t subtype) |
| 15374 | { |
| 15375 | struct lpfc_mbx_wq_create *wq_create; |
| 15376 | struct lpfc_dmabuf *dmabuf; |
| 15377 | LPFC_MBOXQ_t *mbox; |
| 15378 | int rc, length, status = 0; |
| 15379 | uint32_t shdr_status, shdr_add_status; |
| 15380 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15381 | 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] | 15382 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15383 | void __iomem *bar_memmap_p; |
| 15384 | uint32_t db_offset; |
| 15385 | uint16_t pci_barset; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15386 | uint8_t dpp_barset; |
| 15387 | uint32_t dpp_offset; |
| 15388 | unsigned long pg_addr; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15389 | uint8_t wq_create_version; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15390 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15391 | /* sanity check on queue memory */ |
| 15392 | if (!wq || !cq) |
| 15393 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15394 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15395 | hw_page_size = wq->page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15396 | |
| 15397 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15398 | if (!mbox) |
| 15399 | return -ENOMEM; |
| 15400 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 15401 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15402 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15403 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 15404 | length, LPFC_SLI4_MBX_EMBED); |
| 15405 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15406 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15407 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 15408 | wq->page_count); |
| 15409 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 15410 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15411 | |
| 15412 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15413 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15414 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15415 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 15416 | if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) || |
| 15417 | (wq->page_size > SLI4_PAGE_SIZE)) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15418 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15419 | else |
| 15420 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15421 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15422 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15423 | if (phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) |
| 15424 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15425 | else |
| 15426 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15427 | |
| 15428 | switch (wq_create_version) { |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15429 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15430 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 15431 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 15432 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15433 | LPFC_Q_CREATE_VERSION_1); |
| 15434 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15435 | switch (wq->entry_size) { |
| 15436 | default: |
| 15437 | case 64: |
| 15438 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15439 | &wq_create->u.request_1, |
| 15440 | LPFC_WQ_WQE_SIZE_64); |
| 15441 | break; |
| 15442 | case 128: |
| 15443 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15444 | &wq_create->u.request_1, |
| 15445 | LPFC_WQ_WQE_SIZE_128); |
| 15446 | break; |
| 15447 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15448 | /* Request DPP by default */ |
| 15449 | 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] | 15450 | bf_set(lpfc_mbx_wq_create_page_size, |
| 15451 | &wq_create->u.request_1, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15452 | (wq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15453 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15454 | break; |
| 15455 | default: |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15456 | page = wq_create->u.request.page; |
| 15457 | break; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15458 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15459 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15460 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15461 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15462 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 15463 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15464 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15465 | |
| 15466 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15467 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 15468 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15469 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15470 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15471 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15472 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15473 | if (shdr_status || shdr_add_status || rc) { |
| 15474 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15475 | "2503 WQ_CREATE mailbox failed with " |
| 15476 | "status x%x add_status x%x, mbx status x%x\n", |
| 15477 | shdr_status, shdr_add_status, rc); |
| 15478 | status = -ENXIO; |
| 15479 | goto out; |
| 15480 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15481 | |
| 15482 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) |
| 15483 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, |
| 15484 | &wq_create->u.response); |
| 15485 | else |
| 15486 | wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id, |
| 15487 | &wq_create->u.response_1); |
| 15488 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15489 | if (wq->queue_id == 0xFFFF) { |
| 15490 | status = -ENXIO; |
| 15491 | goto out; |
| 15492 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15493 | |
| 15494 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 15495 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) { |
| 15496 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15497 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 15498 | &wq_create->u.response); |
| 15499 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15500 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15501 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15502 | "3265 WQ[%d] doorbell format " |
| 15503 | "not supported: x%x\n", |
| 15504 | wq->queue_id, wq->db_format); |
| 15505 | status = -EINVAL; |
| 15506 | goto out; |
| 15507 | } |
| 15508 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 15509 | &wq_create->u.response); |
| 15510 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15511 | pci_barset); |
| 15512 | if (!bar_memmap_p) { |
| 15513 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15514 | "3263 WQ[%d] failed to memmap " |
| 15515 | "pci barset:x%x\n", |
| 15516 | wq->queue_id, pci_barset); |
| 15517 | status = -ENOMEM; |
| 15518 | goto out; |
| 15519 | } |
| 15520 | db_offset = wq_create->u.response.doorbell_offset; |
| 15521 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 15522 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 15523 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15524 | "3252 WQ[%d] doorbell offset " |
| 15525 | "not supported: x%x\n", |
| 15526 | wq->queue_id, db_offset); |
| 15527 | status = -EINVAL; |
| 15528 | goto out; |
| 15529 | } |
| 15530 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15531 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15532 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 15533 | "format:x%x\n", wq->queue_id, |
| 15534 | pci_barset, db_offset, wq->db_format); |
| 15535 | } else |
| 15536 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15537 | } else { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15538 | /* Check if DPP was honored by the firmware */ |
| 15539 | wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp, |
| 15540 | &wq_create->u.response_1); |
| 15541 | if (wq->dpp_enable) { |
| 15542 | pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set, |
| 15543 | &wq_create->u.response_1); |
| 15544 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15545 | pci_barset); |
| 15546 | if (!bar_memmap_p) { |
| 15547 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15548 | "3267 WQ[%d] failed to memmap " |
| 15549 | "pci barset:x%x\n", |
| 15550 | wq->queue_id, pci_barset); |
| 15551 | status = -ENOMEM; |
| 15552 | goto out; |
| 15553 | } |
| 15554 | db_offset = wq_create->u.response_1.doorbell_offset; |
| 15555 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15556 | wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id, |
| 15557 | &wq_create->u.response_1); |
| 15558 | dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar, |
| 15559 | &wq_create->u.response_1); |
| 15560 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15561 | dpp_barset); |
| 15562 | if (!bar_memmap_p) { |
| 15563 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15564 | "3268 WQ[%d] failed to memmap " |
| 15565 | "pci barset:x%x\n", |
| 15566 | wq->queue_id, dpp_barset); |
| 15567 | status = -ENOMEM; |
| 15568 | goto out; |
| 15569 | } |
| 15570 | dpp_offset = wq_create->u.response_1.dpp_offset; |
| 15571 | wq->dpp_regaddr = bar_memmap_p + dpp_offset; |
| 15572 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15573 | "3271 WQ[%d]: barset:x%x, offset:x%x, " |
| 15574 | "dpp_id:x%x dpp_barset:x%x " |
| 15575 | "dpp_offset:x%x\n", |
| 15576 | wq->queue_id, pci_barset, db_offset, |
| 15577 | wq->dpp_id, dpp_barset, dpp_offset); |
| 15578 | |
| 15579 | /* Enable combined writes for DPP aperture */ |
| 15580 | pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK; |
| 15581 | #ifdef CONFIG_X86 |
| 15582 | rc = set_memory_wc(pg_addr, 1); |
| 15583 | if (rc) { |
| 15584 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15585 | "3272 Cannot setup Combined " |
| 15586 | "Write on WQ[%d] - disable DPP\n", |
| 15587 | wq->queue_id); |
| 15588 | phba->cfg_enable_dpp = 0; |
| 15589 | } |
| 15590 | #else |
| 15591 | phba->cfg_enable_dpp = 0; |
| 15592 | #endif |
| 15593 | } else |
| 15594 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15595 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15596 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 15597 | if (wq->pring == NULL) { |
| 15598 | status = -ENOMEM; |
| 15599 | goto out; |
| 15600 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15601 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15602 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15603 | wq->subtype = subtype; |
| 15604 | wq->host_index = 0; |
| 15605 | wq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15606 | wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15607 | |
| 15608 | /* link the wq onto the parent cq child list */ |
| 15609 | list_add_tail(&wq->list, &cq->child_list); |
| 15610 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15611 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15612 | return status; |
| 15613 | } |
| 15614 | |
| 15615 | /** |
| 15616 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 15617 | * @phba: HBA structure that indicates port to create a queue on. |
| 15618 | * @hrq: The queue structure to use to create the header receive queue. |
| 15619 | * @drq: The queue structure to use to create the data receive queue. |
| 15620 | * @cq: The completion queue to bind this work queue to. |
| 15621 | * |
| 15622 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15623 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15624 | * to the HBA. |
| 15625 | * |
| 15626 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15627 | * struct is used to get the entry count that is necessary to determine the |
| 15628 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15629 | * completion queue to bind received buffers that are posted to these queues to. |
| 15630 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15631 | * receive queue pair. This function is asynchronous and will wait for the |
| 15632 | * mailbox command to finish before continuing. |
| 15633 | * |
| 15634 | * 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] | 15635 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15636 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15637 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15638 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15639 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15640 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 15641 | { |
| 15642 | struct lpfc_mbx_rq_create *rq_create; |
| 15643 | struct lpfc_dmabuf *dmabuf; |
| 15644 | LPFC_MBOXQ_t *mbox; |
| 15645 | int rc, length, status = 0; |
| 15646 | uint32_t shdr_status, shdr_add_status; |
| 15647 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15648 | 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] | 15649 | void __iomem *bar_memmap_p; |
| 15650 | uint32_t db_offset; |
| 15651 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15652 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15653 | /* sanity check on queue memory */ |
| 15654 | if (!hrq || !drq || !cq) |
| 15655 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15656 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15657 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15658 | |
| 15659 | if (hrq->entry_count != drq->entry_count) |
| 15660 | return -EINVAL; |
| 15661 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15662 | if (!mbox) |
| 15663 | return -ENOMEM; |
| 15664 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 15665 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15666 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15667 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15668 | length, LPFC_SLI4_MBX_EMBED); |
| 15669 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15670 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15671 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15672 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15673 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15674 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15675 | &rq_create->u.request.context, |
| 15676 | hrq->entry_count); |
| 15677 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15678 | bf_set(lpfc_rq_context_rqe_size, |
| 15679 | &rq_create->u.request.context, |
| 15680 | LPFC_RQE_SIZE_8); |
| 15681 | bf_set(lpfc_rq_context_page_size, |
| 15682 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 15683 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15684 | } else { |
| 15685 | switch (hrq->entry_count) { |
| 15686 | default: |
| 15687 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15688 | "2535 Unsupported RQ count. (%d)\n", |
| 15689 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15690 | if (hrq->entry_count < 512) { |
| 15691 | status = -EINVAL; |
| 15692 | goto out; |
| 15693 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15694 | /* fall through - otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15695 | case 512: |
| 15696 | bf_set(lpfc_rq_context_rqe_count, |
| 15697 | &rq_create->u.request.context, |
| 15698 | LPFC_RQ_RING_SIZE_512); |
| 15699 | break; |
| 15700 | case 1024: |
| 15701 | bf_set(lpfc_rq_context_rqe_count, |
| 15702 | &rq_create->u.request.context, |
| 15703 | LPFC_RQ_RING_SIZE_1024); |
| 15704 | break; |
| 15705 | case 2048: |
| 15706 | bf_set(lpfc_rq_context_rqe_count, |
| 15707 | &rq_create->u.request.context, |
| 15708 | LPFC_RQ_RING_SIZE_2048); |
| 15709 | break; |
| 15710 | case 4096: |
| 15711 | bf_set(lpfc_rq_context_rqe_count, |
| 15712 | &rq_create->u.request.context, |
| 15713 | LPFC_RQ_RING_SIZE_4096); |
| 15714 | break; |
| 15715 | } |
| 15716 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 15717 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15718 | } |
| 15719 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15720 | cq->queue_id); |
| 15721 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15722 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15723 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15724 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15725 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15726 | putPaddrLow(dmabuf->phys); |
| 15727 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15728 | putPaddrHigh(dmabuf->phys); |
| 15729 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15730 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15731 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 15732 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15733 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15734 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15735 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15736 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15737 | if (shdr_status || shdr_add_status || rc) { |
| 15738 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15739 | "2504 RQ_CREATE mailbox failed with " |
| 15740 | "status x%x add_status x%x, mbx status x%x\n", |
| 15741 | shdr_status, shdr_add_status, rc); |
| 15742 | status = -ENXIO; |
| 15743 | goto out; |
| 15744 | } |
| 15745 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15746 | if (hrq->queue_id == 0xFFFF) { |
| 15747 | status = -ENXIO; |
| 15748 | goto out; |
| 15749 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15750 | |
| 15751 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15752 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 15753 | &rq_create->u.response); |
| 15754 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15755 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15756 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15757 | "3262 RQ [%d] doorbell format not " |
| 15758 | "supported: x%x\n", hrq->queue_id, |
| 15759 | hrq->db_format); |
| 15760 | status = -EINVAL; |
| 15761 | goto out; |
| 15762 | } |
| 15763 | |
| 15764 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 15765 | &rq_create->u.response); |
| 15766 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 15767 | if (!bar_memmap_p) { |
| 15768 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15769 | "3269 RQ[%d] failed to memmap pci " |
| 15770 | "barset:x%x\n", hrq->queue_id, |
| 15771 | pci_barset); |
| 15772 | status = -ENOMEM; |
| 15773 | goto out; |
| 15774 | } |
| 15775 | |
| 15776 | db_offset = rq_create->u.response.doorbell_offset; |
| 15777 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 15778 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 15779 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15780 | "3270 RQ[%d] doorbell offset not " |
| 15781 | "supported: x%x\n", hrq->queue_id, |
| 15782 | db_offset); |
| 15783 | status = -EINVAL; |
| 15784 | goto out; |
| 15785 | } |
| 15786 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 15787 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 15788 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 15789 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 15790 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15791 | } else { |
| 15792 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15793 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15794 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15795 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15796 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15797 | hrq->subtype = subtype; |
| 15798 | hrq->host_index = 0; |
| 15799 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15800 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15801 | |
| 15802 | /* now create the data queue */ |
| 15803 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15804 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15805 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15806 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15807 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15808 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15809 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15810 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15811 | if (subtype == LPFC_NVMET) |
| 15812 | rq_create->u.request.context.buffer_size = |
| 15813 | LPFC_NVMET_DATA_BUF_SIZE; |
| 15814 | else |
| 15815 | rq_create->u.request.context.buffer_size = |
| 15816 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15817 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 15818 | LPFC_RQE_SIZE_8); |
| 15819 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 15820 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15821 | } else { |
| 15822 | switch (drq->entry_count) { |
| 15823 | default: |
| 15824 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15825 | "2536 Unsupported RQ count. (%d)\n", |
| 15826 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15827 | if (drq->entry_count < 512) { |
| 15828 | status = -EINVAL; |
| 15829 | goto out; |
| 15830 | } |
Gustavo A. R. Silva | 5bd5f66 | 2018-11-27 22:32:18 -0600 | [diff] [blame] | 15831 | /* fall through - otherwise default to smallest count */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15832 | case 512: |
| 15833 | bf_set(lpfc_rq_context_rqe_count, |
| 15834 | &rq_create->u.request.context, |
| 15835 | LPFC_RQ_RING_SIZE_512); |
| 15836 | break; |
| 15837 | case 1024: |
| 15838 | bf_set(lpfc_rq_context_rqe_count, |
| 15839 | &rq_create->u.request.context, |
| 15840 | LPFC_RQ_RING_SIZE_1024); |
| 15841 | break; |
| 15842 | case 2048: |
| 15843 | bf_set(lpfc_rq_context_rqe_count, |
| 15844 | &rq_create->u.request.context, |
| 15845 | LPFC_RQ_RING_SIZE_2048); |
| 15846 | break; |
| 15847 | case 4096: |
| 15848 | bf_set(lpfc_rq_context_rqe_count, |
| 15849 | &rq_create->u.request.context, |
| 15850 | LPFC_RQ_RING_SIZE_4096); |
| 15851 | break; |
| 15852 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15853 | if (subtype == LPFC_NVMET) |
| 15854 | bf_set(lpfc_rq_context_buf_size, |
| 15855 | &rq_create->u.request.context, |
| 15856 | LPFC_NVMET_DATA_BUF_SIZE); |
| 15857 | else |
| 15858 | bf_set(lpfc_rq_context_buf_size, |
| 15859 | &rq_create->u.request.context, |
| 15860 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15861 | } |
| 15862 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15863 | cq->queue_id); |
| 15864 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15865 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15866 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 15867 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15868 | putPaddrLow(dmabuf->phys); |
| 15869 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15870 | putPaddrHigh(dmabuf->phys); |
| 15871 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15872 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15873 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15874 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15875 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15876 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15877 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15878 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15879 | if (shdr_status || shdr_add_status || rc) { |
| 15880 | status = -ENXIO; |
| 15881 | goto out; |
| 15882 | } |
| 15883 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15884 | if (drq->queue_id == 0xFFFF) { |
| 15885 | status = -ENXIO; |
| 15886 | goto out; |
| 15887 | } |
| 15888 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15889 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15890 | drq->subtype = subtype; |
| 15891 | drq->host_index = 0; |
| 15892 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15893 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15894 | |
| 15895 | /* link the header and data RQs onto the parent cq child list */ |
| 15896 | list_add_tail(&hrq->list, &cq->child_list); |
| 15897 | list_add_tail(&drq->list, &cq->child_list); |
| 15898 | |
| 15899 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15900 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15901 | return status; |
| 15902 | } |
| 15903 | |
| 15904 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15905 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 15906 | * @phba: HBA structure that indicates port to create a queue on. |
| 15907 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 15908 | * @drqp: The queue structure array to use to create the data receive queues. |
| 15909 | * @cqp: The completion queue array to bind these receive queues to. |
| 15910 | * |
| 15911 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15912 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15913 | * to the HBA. |
| 15914 | * |
| 15915 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15916 | * struct is used to get the entry count that is necessary to determine the |
| 15917 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15918 | * completion queue to bind received buffers that are posted to these queues to. |
| 15919 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15920 | * receive queue pair. This function is asynchronous and will wait for the |
| 15921 | * mailbox command to finish before continuing. |
| 15922 | * |
| 15923 | * On success this function will return a zero. If unable to allocate enough |
| 15924 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15925 | * fails this function will return -ENXIO. |
| 15926 | **/ |
| 15927 | int |
| 15928 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 15929 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 15930 | uint32_t subtype) |
| 15931 | { |
| 15932 | struct lpfc_queue *hrq, *drq, *cq; |
| 15933 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 15934 | struct lpfc_dmabuf *dmabuf; |
| 15935 | LPFC_MBOXQ_t *mbox; |
| 15936 | int rc, length, alloclen, status = 0; |
| 15937 | int cnt, idx, numrq, page_idx = 0; |
| 15938 | uint32_t shdr_status, shdr_add_status; |
| 15939 | union lpfc_sli4_cfg_shdr *shdr; |
| 15940 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15941 | |
| 15942 | numrq = phba->cfg_nvmet_mrq; |
| 15943 | /* sanity check on array memory */ |
| 15944 | if (!hrqp || !drqp || !cqp || !numrq) |
| 15945 | return -ENODEV; |
| 15946 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15947 | hw_page_size = SLI4_PAGE_SIZE; |
| 15948 | |
| 15949 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15950 | if (!mbox) |
| 15951 | return -ENOMEM; |
| 15952 | |
| 15953 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 15954 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 15955 | sizeof(struct dma_address)); |
| 15956 | |
| 15957 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15958 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 15959 | LPFC_SLI4_MBX_NEMBED); |
| 15960 | if (alloclen < length) { |
| 15961 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15962 | "3099 Allocated DMA memory size (%d) is " |
| 15963 | "less than the requested DMA memory size " |
| 15964 | "(%d)\n", alloclen, length); |
| 15965 | status = -ENOMEM; |
| 15966 | goto out; |
| 15967 | } |
| 15968 | |
| 15969 | |
| 15970 | |
| 15971 | rq_create = mbox->sge_array->addr[0]; |
| 15972 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 15973 | |
| 15974 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 15975 | cnt = 0; |
| 15976 | |
| 15977 | for (idx = 0; idx < numrq; idx++) { |
| 15978 | hrq = hrqp[idx]; |
| 15979 | drq = drqp[idx]; |
| 15980 | cq = cqp[idx]; |
| 15981 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15982 | /* sanity check on queue memory */ |
| 15983 | if (!hrq || !drq || !cq) { |
| 15984 | status = -ENODEV; |
| 15985 | goto out; |
| 15986 | } |
| 15987 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 15988 | if (hrq->entry_count != drq->entry_count) { |
| 15989 | status = -EINVAL; |
| 15990 | goto out; |
| 15991 | } |
| 15992 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15993 | if (idx == 0) { |
| 15994 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 15995 | &rq_create->u.request, |
| 15996 | hrq->page_count); |
| 15997 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 15998 | &rq_create->u.request, (numrq * 2)); |
| 15999 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 16000 | 1); |
| 16001 | bf_set(lpfc_rq_context_base_cq, |
| 16002 | &rq_create->u.request.context, |
| 16003 | cq->queue_id); |
| 16004 | bf_set(lpfc_rq_context_data_size, |
| 16005 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16006 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16007 | bf_set(lpfc_rq_context_hdr_size, |
| 16008 | &rq_create->u.request.context, |
| 16009 | LPFC_HDR_BUF_SIZE); |
| 16010 | bf_set(lpfc_rq_context_rqe_count_1, |
| 16011 | &rq_create->u.request.context, |
| 16012 | hrq->entry_count); |
| 16013 | bf_set(lpfc_rq_context_rqe_size, |
| 16014 | &rq_create->u.request.context, |
| 16015 | LPFC_RQE_SIZE_8); |
| 16016 | bf_set(lpfc_rq_context_page_size, |
| 16017 | &rq_create->u.request.context, |
| 16018 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 16019 | } |
| 16020 | rc = 0; |
| 16021 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 16022 | memset(dmabuf->virt, 0, hw_page_size); |
| 16023 | cnt = page_idx + dmabuf->buffer_tag; |
| 16024 | rq_create->u.request.page[cnt].addr_lo = |
| 16025 | putPaddrLow(dmabuf->phys); |
| 16026 | rq_create->u.request.page[cnt].addr_hi = |
| 16027 | putPaddrHigh(dmabuf->phys); |
| 16028 | rc++; |
| 16029 | } |
| 16030 | page_idx += rc; |
| 16031 | |
| 16032 | rc = 0; |
| 16033 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 16034 | memset(dmabuf->virt, 0, hw_page_size); |
| 16035 | cnt = page_idx + dmabuf->buffer_tag; |
| 16036 | rq_create->u.request.page[cnt].addr_lo = |
| 16037 | putPaddrLow(dmabuf->phys); |
| 16038 | rq_create->u.request.page[cnt].addr_hi = |
| 16039 | putPaddrHigh(dmabuf->phys); |
| 16040 | rc++; |
| 16041 | } |
| 16042 | page_idx += rc; |
| 16043 | |
| 16044 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 16045 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16046 | hrq->type = LPFC_HRQ; |
| 16047 | hrq->assoc_qid = cq->queue_id; |
| 16048 | hrq->subtype = subtype; |
| 16049 | hrq->host_index = 0; |
| 16050 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16051 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16052 | |
| 16053 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 16054 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16055 | drq->type = LPFC_DRQ; |
| 16056 | drq->assoc_qid = cq->queue_id; |
| 16057 | drq->subtype = subtype; |
| 16058 | drq->host_index = 0; |
| 16059 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16060 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16061 | |
| 16062 | list_add_tail(&hrq->list, &cq->child_list); |
| 16063 | list_add_tail(&drq->list, &cq->child_list); |
| 16064 | } |
| 16065 | |
| 16066 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16067 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16068 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16069 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16070 | if (shdr_status || shdr_add_status || rc) { |
| 16071 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16072 | "3120 RQ_CREATE mailbox failed with " |
| 16073 | "status x%x add_status x%x, mbx status x%x\n", |
| 16074 | shdr_status, shdr_add_status, rc); |
| 16075 | status = -ENXIO; |
| 16076 | goto out; |
| 16077 | } |
| 16078 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16079 | if (rc == 0xFFFF) { |
| 16080 | status = -ENXIO; |
| 16081 | goto out; |
| 16082 | } |
| 16083 | |
| 16084 | /* Initialize all RQs with associated queue id */ |
| 16085 | for (idx = 0; idx < numrq; idx++) { |
| 16086 | hrq = hrqp[idx]; |
| 16087 | hrq->queue_id = rc + (2 * idx); |
| 16088 | drq = drqp[idx]; |
| 16089 | drq->queue_id = rc + (2 * idx) + 1; |
| 16090 | } |
| 16091 | |
| 16092 | out: |
| 16093 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16094 | return status; |
| 16095 | } |
| 16096 | |
| 16097 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16098 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 16099 | * @eq: The queue structure associated with the queue to destroy. |
| 16100 | * |
| 16101 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 16102 | * command, specific to the type of queue, to the HBA. |
| 16103 | * |
| 16104 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 16105 | * |
| 16106 | * 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] | 16107 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16108 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16109 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16110 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 16111 | { |
| 16112 | LPFC_MBOXQ_t *mbox; |
| 16113 | int rc, length, status = 0; |
| 16114 | uint32_t shdr_status, shdr_add_status; |
| 16115 | union lpfc_sli4_cfg_shdr *shdr; |
| 16116 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16117 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16118 | if (!eq) |
| 16119 | return -ENODEV; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16120 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16121 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16122 | if (!mbox) |
| 16123 | return -ENOMEM; |
| 16124 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 16125 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16126 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16127 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 16128 | length, LPFC_SLI4_MBX_EMBED); |
| 16129 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 16130 | eq->queue_id); |
| 16131 | mbox->vport = eq->phba->pport; |
| 16132 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16133 | |
| 16134 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 16135 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16136 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16137 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 16138 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16139 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16140 | if (shdr_status || shdr_add_status || rc) { |
| 16141 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16142 | "2505 EQ_DESTROY mailbox failed with " |
| 16143 | "status x%x add_status x%x, mbx status x%x\n", |
| 16144 | shdr_status, shdr_add_status, rc); |
| 16145 | status = -ENXIO; |
| 16146 | } |
| 16147 | |
| 16148 | /* Remove eq from any list */ |
| 16149 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16150 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16151 | return status; |
| 16152 | } |
| 16153 | |
| 16154 | /** |
| 16155 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 16156 | * @cq: The queue structure associated with the queue to destroy. |
| 16157 | * |
| 16158 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 16159 | * command, specific to the type of queue, to the HBA. |
| 16160 | * |
| 16161 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 16162 | * |
| 16163 | * 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] | 16164 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16165 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16166 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16167 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 16168 | { |
| 16169 | LPFC_MBOXQ_t *mbox; |
| 16170 | int rc, length, status = 0; |
| 16171 | uint32_t shdr_status, shdr_add_status; |
| 16172 | union lpfc_sli4_cfg_shdr *shdr; |
| 16173 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16174 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16175 | if (!cq) |
| 16176 | return -ENODEV; |
| 16177 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16178 | if (!mbox) |
| 16179 | return -ENOMEM; |
| 16180 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 16181 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16182 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16183 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 16184 | length, LPFC_SLI4_MBX_EMBED); |
| 16185 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 16186 | cq->queue_id); |
| 16187 | mbox->vport = cq->phba->pport; |
| 16188 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16189 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 16190 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16191 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16192 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 16193 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16194 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16195 | if (shdr_status || shdr_add_status || rc) { |
| 16196 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16197 | "2506 CQ_DESTROY mailbox failed with " |
| 16198 | "status x%x add_status x%x, mbx status x%x\n", |
| 16199 | shdr_status, shdr_add_status, rc); |
| 16200 | status = -ENXIO; |
| 16201 | } |
| 16202 | /* Remove cq from any list */ |
| 16203 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16204 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16205 | return status; |
| 16206 | } |
| 16207 | |
| 16208 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16209 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 16210 | * @qm: The queue structure associated with the queue to destroy. |
| 16211 | * |
| 16212 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 16213 | * command, specific to the type of queue, to the HBA. |
| 16214 | * |
| 16215 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 16216 | * |
| 16217 | * 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] | 16218 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16219 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16220 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16221 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 16222 | { |
| 16223 | LPFC_MBOXQ_t *mbox; |
| 16224 | int rc, length, status = 0; |
| 16225 | uint32_t shdr_status, shdr_add_status; |
| 16226 | union lpfc_sli4_cfg_shdr *shdr; |
| 16227 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16228 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16229 | if (!mq) |
| 16230 | return -ENODEV; |
| 16231 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16232 | if (!mbox) |
| 16233 | return -ENOMEM; |
| 16234 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 16235 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16236 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16237 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 16238 | length, LPFC_SLI4_MBX_EMBED); |
| 16239 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 16240 | mq->queue_id); |
| 16241 | mbox->vport = mq->phba->pport; |
| 16242 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16243 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 16244 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16245 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16246 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 16247 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16248 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16249 | if (shdr_status || shdr_add_status || rc) { |
| 16250 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16251 | "2507 MQ_DESTROY mailbox failed with " |
| 16252 | "status x%x add_status x%x, mbx status x%x\n", |
| 16253 | shdr_status, shdr_add_status, rc); |
| 16254 | status = -ENXIO; |
| 16255 | } |
| 16256 | /* Remove mq from any list */ |
| 16257 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16258 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16259 | return status; |
| 16260 | } |
| 16261 | |
| 16262 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16263 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 16264 | * @wq: The queue structure associated with the queue to destroy. |
| 16265 | * |
| 16266 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 16267 | * command, specific to the type of queue, to the HBA. |
| 16268 | * |
| 16269 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 16270 | * |
| 16271 | * 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] | 16272 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16273 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16274 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16275 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 16276 | { |
| 16277 | LPFC_MBOXQ_t *mbox; |
| 16278 | int rc, length, status = 0; |
| 16279 | uint32_t shdr_status, shdr_add_status; |
| 16280 | union lpfc_sli4_cfg_shdr *shdr; |
| 16281 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16282 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16283 | if (!wq) |
| 16284 | return -ENODEV; |
| 16285 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16286 | if (!mbox) |
| 16287 | return -ENOMEM; |
| 16288 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 16289 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16290 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16291 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 16292 | length, LPFC_SLI4_MBX_EMBED); |
| 16293 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 16294 | wq->queue_id); |
| 16295 | mbox->vport = wq->phba->pport; |
| 16296 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16297 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 16298 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16299 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 16300 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16301 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16302 | if (shdr_status || shdr_add_status || rc) { |
| 16303 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16304 | "2508 WQ_DESTROY mailbox failed with " |
| 16305 | "status x%x add_status x%x, mbx status x%x\n", |
| 16306 | shdr_status, shdr_add_status, rc); |
| 16307 | status = -ENXIO; |
| 16308 | } |
| 16309 | /* Remove wq from any list */ |
| 16310 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 16311 | kfree(wq->pring); |
| 16312 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16313 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16314 | return status; |
| 16315 | } |
| 16316 | |
| 16317 | /** |
| 16318 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 16319 | * @rq: The queue structure associated with the queue to destroy. |
| 16320 | * |
| 16321 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 16322 | * command, specific to the type of queue, to the HBA. |
| 16323 | * |
| 16324 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 16325 | * |
| 16326 | * 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] | 16327 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16328 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16329 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16330 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 16331 | struct lpfc_queue *drq) |
| 16332 | { |
| 16333 | LPFC_MBOXQ_t *mbox; |
| 16334 | int rc, length, status = 0; |
| 16335 | uint32_t shdr_status, shdr_add_status; |
| 16336 | union lpfc_sli4_cfg_shdr *shdr; |
| 16337 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16338 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16339 | if (!hrq || !drq) |
| 16340 | return -ENODEV; |
| 16341 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16342 | if (!mbox) |
| 16343 | return -ENOMEM; |
| 16344 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16345 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16346 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16347 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 16348 | length, LPFC_SLI4_MBX_EMBED); |
| 16349 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16350 | hrq->queue_id); |
| 16351 | mbox->vport = hrq->phba->pport; |
| 16352 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16353 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 16354 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16355 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16356 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16357 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16358 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16359 | if (shdr_status || shdr_add_status || rc) { |
| 16360 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16361 | "2509 RQ_DESTROY mailbox failed with " |
| 16362 | "status x%x add_status x%x, mbx status x%x\n", |
| 16363 | shdr_status, shdr_add_status, rc); |
| 16364 | if (rc != MBX_TIMEOUT) |
| 16365 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 16366 | return -ENXIO; |
| 16367 | } |
| 16368 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16369 | drq->queue_id); |
| 16370 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 16371 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16372 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16373 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16374 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16375 | if (shdr_status || shdr_add_status || rc) { |
| 16376 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16377 | "2510 RQ_DESTROY mailbox failed with " |
| 16378 | "status x%x add_status x%x, mbx status x%x\n", |
| 16379 | shdr_status, shdr_add_status, rc); |
| 16380 | status = -ENXIO; |
| 16381 | } |
| 16382 | list_del_init(&hrq->list); |
| 16383 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16384 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16385 | return status; |
| 16386 | } |
| 16387 | |
| 16388 | /** |
| 16389 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 16390 | * @phba: The virtual port for which this call being executed. |
| 16391 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 16392 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 16393 | * @xritag: the xritag that ties this io to the SGL pages. |
| 16394 | * |
| 16395 | * This routine will post the sgl pages for the IO that has the xritag |
| 16396 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 16397 | * creation and persists for as long as the driver is loaded. |
| 16398 | * if the caller has fewer than 256 scatter gather segments to map then |
| 16399 | * pdma_phys_addr1 should be 0. |
| 16400 | * If the caller needs to map more than 256 scatter gather segment then |
| 16401 | * pdma_phys_addr1 should be a valid physical address. |
| 16402 | * physical address for SGLs must be 64 byte aligned. |
| 16403 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 16404 | * the second sgl can have between 1 and 256 entries. |
| 16405 | * |
| 16406 | * Return codes: |
| 16407 | * 0 - Success |
| 16408 | * -ENXIO, -ENOMEM - Failure |
| 16409 | **/ |
| 16410 | int |
| 16411 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 16412 | dma_addr_t pdma_phys_addr0, |
| 16413 | dma_addr_t pdma_phys_addr1, |
| 16414 | uint16_t xritag) |
| 16415 | { |
| 16416 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 16417 | LPFC_MBOXQ_t *mbox; |
| 16418 | int rc; |
| 16419 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16420 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16421 | union lpfc_sli4_cfg_shdr *shdr; |
| 16422 | |
| 16423 | if (xritag == NO_XRI) { |
| 16424 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16425 | "0364 Invalid param:\n"); |
| 16426 | return -EINVAL; |
| 16427 | } |
| 16428 | |
| 16429 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16430 | if (!mbox) |
| 16431 | return -ENOMEM; |
| 16432 | |
| 16433 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16434 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16435 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16436 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16437 | |
| 16438 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 16439 | &mbox->u.mqe.un.post_sgl_pages; |
| 16440 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 16441 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 16442 | |
| 16443 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 16444 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 16445 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 16446 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 16447 | |
| 16448 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 16449 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 16450 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 16451 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 16452 | if (!phba->sli4_hba.intr_enable) |
| 16453 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16454 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16455 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16456 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16457 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16458 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16459 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 16460 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16461 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16462 | if (rc != MBX_TIMEOUT) |
| 16463 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16464 | if (shdr_status || shdr_add_status || rc) { |
| 16465 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16466 | "2511 POST_SGL mailbox failed with " |
| 16467 | "status x%x add_status x%x, mbx status x%x\n", |
| 16468 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16469 | } |
| 16470 | return 0; |
| 16471 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16472 | |
| 16473 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16474 | * 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] | 16475 | * @phba: pointer to lpfc hba data structure. |
| 16476 | * |
| 16477 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16478 | * HBA consistent with the SLI-4 interface spec. This routine |
| 16479 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 16480 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16481 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16482 | * Returns |
| 16483 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 16484 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 16485 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16486 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16487 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 16488 | { |
| 16489 | unsigned long xri; |
| 16490 | |
| 16491 | /* |
| 16492 | * Fetch the next logical xri. Because this index is logical, |
| 16493 | * the driver starts at 0 each time. |
| 16494 | */ |
| 16495 | spin_lock_irq(&phba->hbalock); |
| 16496 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 16497 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 16498 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 16499 | spin_unlock_irq(&phba->hbalock); |
| 16500 | return NO_XRI; |
| 16501 | } else { |
| 16502 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 16503 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16504 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16505 | spin_unlock_irq(&phba->hbalock); |
| 16506 | return xri; |
| 16507 | } |
| 16508 | |
| 16509 | /** |
| 16510 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16511 | * @phba: pointer to lpfc hba data structure. |
| 16512 | * |
| 16513 | * This routine is invoked to release an xri to the pool of |
| 16514 | * available rpis maintained by the driver. |
| 16515 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16516 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16517 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16518 | { |
| 16519 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16520 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 16521 | } |
| 16522 | } |
| 16523 | |
| 16524 | /** |
| 16525 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16526 | * @phba: pointer to lpfc hba data structure. |
| 16527 | * |
| 16528 | * This routine is invoked to release an xri to the pool of |
| 16529 | * available rpis maintained by the driver. |
| 16530 | **/ |
| 16531 | void |
| 16532 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16533 | { |
| 16534 | spin_lock_irq(&phba->hbalock); |
| 16535 | __lpfc_sli4_free_xri(phba, xri); |
| 16536 | spin_unlock_irq(&phba->hbalock); |
| 16537 | } |
| 16538 | |
| 16539 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16540 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 16541 | * @phba: Pointer to HBA context object. |
| 16542 | * |
| 16543 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 16544 | * it will return 0xffff. |
| 16545 | * The function returns the allocated xritag if successful, else returns zero. |
| 16546 | * Zero is not a valid xritag. |
| 16547 | * The caller is not required to hold any lock. |
| 16548 | **/ |
| 16549 | uint16_t |
| 16550 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 16551 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16552 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16553 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16554 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 16555 | if (xri_index == NO_XRI) |
| 16556 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 16557 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 16558 | " Max XRI is %d, Used XRI is %d\n", |
| 16559 | xri_index, |
| 16560 | phba->sli4_hba.max_cfg_param.max_xri, |
| 16561 | phba->sli4_hba.max_cfg_param.xri_used); |
| 16562 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16563 | } |
| 16564 | |
| 16565 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16566 | * 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] | 16567 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16568 | * @post_sgl_list: pointer to els sgl entry list. |
| 16569 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16570 | * |
| 16571 | * This routine is invoked to post a block of driver's sgl pages to the |
| 16572 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 16573 | * is only called when the driver is loading and after all IO has been |
| 16574 | * stopped. |
| 16575 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16576 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16577 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16578 | struct list_head *post_sgl_list, |
| 16579 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16580 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16581 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16582 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16583 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16584 | void *viraddr; |
| 16585 | LPFC_MBOXQ_t *mbox; |
| 16586 | uint32_t reqlen, alloclen, pg_pairs; |
| 16587 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16588 | uint16_t xritag_start = 0; |
| 16589 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16590 | uint32_t shdr_status, shdr_add_status; |
| 16591 | union lpfc_sli4_cfg_shdr *shdr; |
| 16592 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16593 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16594 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16595 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16596 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16597 | "2559 Block sgl registration required DMA " |
| 16598 | "size (%d) great than a page\n", reqlen); |
| 16599 | return -ENOMEM; |
| 16600 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16601 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16602 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16603 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16604 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16605 | |
| 16606 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16607 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16608 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16609 | LPFC_SLI4_MBX_NEMBED); |
| 16610 | |
| 16611 | if (alloclen < reqlen) { |
| 16612 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16613 | "0285 Allocated DMA memory size (%d) is " |
| 16614 | "less than the requested DMA memory " |
| 16615 | "size (%d)\n", alloclen, reqlen); |
| 16616 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16617 | return -ENOMEM; |
| 16618 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16619 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16620 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16621 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16622 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16623 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16624 | pg_pairs = 0; |
| 16625 | 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] | 16626 | /* Set up the sge entry */ |
| 16627 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16628 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 16629 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16630 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 16631 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16632 | cpu_to_le32(putPaddrLow(0)); |
| 16633 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16634 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16635 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16636 | /* Keep the first xritag on the list */ |
| 16637 | if (pg_pairs == 0) |
| 16638 | xritag_start = sglq_entry->sli4_xritag; |
| 16639 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16640 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16641 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16642 | |
| 16643 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16644 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16645 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16646 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16647 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16648 | if (!phba->sli4_hba.intr_enable) |
| 16649 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16650 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16651 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16652 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16653 | } |
| 16654 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16655 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16656 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16657 | if (rc != MBX_TIMEOUT) |
| 16658 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16659 | if (shdr_status || shdr_add_status || rc) { |
| 16660 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16661 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 16662 | "status x%x add_status x%x mbx status x%x\n", |
| 16663 | shdr_status, shdr_add_status, rc); |
| 16664 | rc = -ENXIO; |
| 16665 | } |
| 16666 | return rc; |
| 16667 | } |
| 16668 | |
| 16669 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16670 | * 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] | 16671 | * @phba: pointer to lpfc hba data structure. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16672 | * @nblist: pointer to nvme buffer list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16673 | * @count: number of scsi buffers on the list. |
| 16674 | * |
| 16675 | * 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] | 16676 | * SCSI buffer list @nblist to the HBA using non-embedded mailbox command. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16677 | * No Lock is held. |
| 16678 | * |
| 16679 | **/ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16680 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16681 | lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist, |
| 16682 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16683 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16684 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16685 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16686 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16687 | void *viraddr; |
| 16688 | LPFC_MBOXQ_t *mbox; |
| 16689 | uint32_t reqlen, alloclen, pg_pairs; |
| 16690 | uint32_t mbox_tmo; |
| 16691 | uint16_t xritag_start = 0; |
| 16692 | int rc = 0; |
| 16693 | uint32_t shdr_status, shdr_add_status; |
| 16694 | dma_addr_t pdma_phys_bpl1; |
| 16695 | union lpfc_sli4_cfg_shdr *shdr; |
| 16696 | |
| 16697 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16698 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16699 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16700 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16701 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16702 | "6118 Block sgl registration required DMA " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16703 | "size (%d) great than a page\n", reqlen); |
| 16704 | return -ENOMEM; |
| 16705 | } |
| 16706 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16707 | if (!mbox) { |
| 16708 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16709 | "6119 Failed to allocate mbox cmd memory\n"); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16710 | return -ENOMEM; |
| 16711 | } |
| 16712 | |
| 16713 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16714 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16715 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16716 | reqlen, LPFC_SLI4_MBX_NEMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16717 | |
| 16718 | if (alloclen < reqlen) { |
| 16719 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16720 | "6120 Allocated DMA memory size (%d) is " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16721 | "less than the requested DMA memory " |
| 16722 | "size (%d)\n", alloclen, reqlen); |
| 16723 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16724 | return -ENOMEM; |
| 16725 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16726 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16727 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16728 | viraddr = mbox->sge_array->addr[0]; |
| 16729 | |
| 16730 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 16731 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16732 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16733 | |
| 16734 | pg_pairs = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16735 | list_for_each_entry(lpfc_ncmd, nblist, list) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16736 | /* Set up the sge entry */ |
| 16737 | sgl_pg_pairs->sgl_pg0_addr_lo = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16738 | cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16739 | sgl_pg_pairs->sgl_pg0_addr_hi = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16740 | cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16741 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16742 | pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl + |
| 16743 | SGL_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16744 | else |
| 16745 | pdma_phys_bpl1 = 0; |
| 16746 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16747 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 16748 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16749 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 16750 | /* Keep the first xritag on the list */ |
| 16751 | if (pg_pairs == 0) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16752 | xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16753 | sgl_pg_pairs++; |
| 16754 | pg_pairs++; |
| 16755 | } |
| 16756 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 16757 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 16758 | /* Perform endian conversion if necessary */ |
| 16759 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 16760 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16761 | if (!phba->sli4_hba.intr_enable) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16762 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16763 | } else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16764 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16765 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16766 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16767 | shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16768 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16769 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16770 | if (rc != MBX_TIMEOUT) |
| 16771 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16772 | if (shdr_status || shdr_add_status || rc) { |
| 16773 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16774 | "6125 POST_SGL_BLOCK mailbox command failed " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16775 | "status x%x add_status x%x mbx status x%x\n", |
| 16776 | shdr_status, shdr_add_status, rc); |
| 16777 | rc = -ENXIO; |
| 16778 | } |
| 16779 | return rc; |
| 16780 | } |
| 16781 | |
| 16782 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16783 | * 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] | 16784 | * @phba: pointer to lpfc hba data structure. |
| 16785 | * @post_nblist: pointer to the nvme buffer list. |
| 16786 | * |
| 16787 | * This routine walks a list of nvme buffers that was passed in. It attempts |
| 16788 | * to construct blocks of nvme buffer sgls which contains contiguous xris and |
| 16789 | * uses the non-embedded SGL block post mailbox commands to post to the port. |
| 16790 | * For single NVME buffer sgl with non-contiguous xri, if any, it shall use |
| 16791 | * embedded SGL post mailbox command for posting. The @post_nblist passed in |
| 16792 | * must be local list, thus no lock is needed when manipulate the list. |
| 16793 | * |
| 16794 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
| 16795 | **/ |
| 16796 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16797 | lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba, |
| 16798 | struct list_head *post_nblist, int sb_count) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16799 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16800 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16801 | int status, sgl_size; |
| 16802 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
| 16803 | dma_addr_t pdma_phys_sgl1; |
| 16804 | int last_xritag = NO_XRI; |
| 16805 | int cur_xritag; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16806 | LIST_HEAD(prep_nblist); |
| 16807 | LIST_HEAD(blck_nblist); |
| 16808 | LIST_HEAD(nvme_nblist); |
| 16809 | |
| 16810 | /* sanity check */ |
| 16811 | if (sb_count <= 0) |
| 16812 | return -EINVAL; |
| 16813 | |
| 16814 | sgl_size = phba->cfg_sg_dma_buf_size; |
| 16815 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) { |
| 16816 | list_del_init(&lpfc_ncmd->list); |
| 16817 | block_cnt++; |
| 16818 | if ((last_xritag != NO_XRI) && |
| 16819 | (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) { |
| 16820 | /* a hole in xri block, form a sgl posting block */ |
| 16821 | list_splice_init(&prep_nblist, &blck_nblist); |
| 16822 | post_cnt = block_cnt - 1; |
| 16823 | /* prepare list for next posting block */ |
| 16824 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 16825 | block_cnt = 1; |
| 16826 | } else { |
| 16827 | /* prepare list for next posting block */ |
| 16828 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 16829 | /* enough sgls for non-embed sgl mbox command */ |
| 16830 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 16831 | list_splice_init(&prep_nblist, &blck_nblist); |
| 16832 | post_cnt = block_cnt; |
| 16833 | block_cnt = 0; |
| 16834 | } |
| 16835 | } |
| 16836 | num_posting++; |
| 16837 | last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 16838 | |
| 16839 | /* end of repost sgl list condition for NVME buffers */ |
| 16840 | if (num_posting == sb_count) { |
| 16841 | if (post_cnt == 0) { |
| 16842 | /* last sgl posting block */ |
| 16843 | list_splice_init(&prep_nblist, &blck_nblist); |
| 16844 | post_cnt = block_cnt; |
| 16845 | } else if (block_cnt == 1) { |
| 16846 | /* last single sgl with non-contiguous xri */ |
| 16847 | if (sgl_size > SGL_PAGE_SIZE) |
| 16848 | pdma_phys_sgl1 = |
| 16849 | lpfc_ncmd->dma_phys_sgl + |
| 16850 | SGL_PAGE_SIZE; |
| 16851 | else |
| 16852 | pdma_phys_sgl1 = 0; |
| 16853 | cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 16854 | status = lpfc_sli4_post_sgl( |
| 16855 | phba, lpfc_ncmd->dma_phys_sgl, |
| 16856 | pdma_phys_sgl1, cur_xritag); |
| 16857 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16858 | /* Post error. Buffer unavailable. */ |
| 16859 | lpfc_ncmd->flags |= |
| 16860 | LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16861 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16862 | /* Post success. Bffer available. */ |
| 16863 | lpfc_ncmd->flags &= |
| 16864 | ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16865 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 16866 | num_posted++; |
| 16867 | } |
| 16868 | /* success, put on NVME buffer sgl list */ |
| 16869 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 16870 | } |
| 16871 | } |
| 16872 | |
| 16873 | /* continue until a nembed page worth of sgls */ |
| 16874 | if (post_cnt == 0) |
| 16875 | continue; |
| 16876 | |
| 16877 | /* post block of NVME buffer list sgls */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16878 | status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist, |
| 16879 | post_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16880 | |
| 16881 | /* don't reset xirtag due to hole in xri block */ |
| 16882 | if (block_cnt == 0) |
| 16883 | last_xritag = NO_XRI; |
| 16884 | |
| 16885 | /* reset NVME buffer post count for next round of posting */ |
| 16886 | post_cnt = 0; |
| 16887 | |
| 16888 | /* put posted NVME buffer-sgl posted on NVME buffer sgl list */ |
| 16889 | while (!list_empty(&blck_nblist)) { |
| 16890 | list_remove_head(&blck_nblist, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16891 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16892 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16893 | /* Post error. Mark buffer unavailable. */ |
| 16894 | lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16895 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16896 | /* Post success, Mark buffer available. */ |
| 16897 | lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16898 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 16899 | num_posted++; |
| 16900 | } |
| 16901 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 16902 | } |
| 16903 | } |
| 16904 | /* Push NVME buffers with sgl posted to the available list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16905 | lpfc_io_buf_replenish(phba, &nvme_nblist); |
| 16906 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16907 | return num_posted; |
| 16908 | } |
| 16909 | |
| 16910 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16911 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 16912 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 16913 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16914 | * |
| 16915 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 16916 | * valid type of frame that the LPFC driver will handle. This function will |
| 16917 | * return a zero if the frame is a valid frame or a non zero value when the |
| 16918 | * frame does not pass the check. |
| 16919 | **/ |
| 16920 | static int |
| 16921 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 16922 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 16923 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16924 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16925 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16926 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 16927 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 16928 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16929 | switch (fc_hdr->fh_r_ctl) { |
| 16930 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 16931 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 16932 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 16933 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 16934 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 16935 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 16936 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 16937 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 16938 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 16939 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 16940 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 16941 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 16942 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 16943 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 16944 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 16945 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 16946 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 16947 | case FC_RCTL_BA_PRMT: |
| 16948 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 16949 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 16950 | case FC_RCTL_P_RJT: /* port reject */ |
| 16951 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 16952 | case FC_RCTL_P_BSY: /* port busy */ |
| 16953 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 16954 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 16955 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16956 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16957 | case FC_RCTL_END: /* end */ |
| 16958 | break; |
| 16959 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 16960 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16961 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 16962 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 16963 | default: |
| 16964 | goto drop; |
| 16965 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16966 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16967 | switch (fc_hdr->fh_type) { |
| 16968 | case FC_TYPE_BLS: |
| 16969 | case FC_TYPE_ELS: |
| 16970 | case FC_TYPE_FCP: |
| 16971 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16972 | case FC_TYPE_NVME: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16973 | break; |
| 16974 | case FC_TYPE_IP: |
| 16975 | case FC_TYPE_ILS: |
| 16976 | default: |
| 16977 | goto drop; |
| 16978 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16979 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16980 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16981 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 16982 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16983 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 16984 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 16985 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 16986 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 16987 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16988 | return 0; |
| 16989 | drop: |
| 16990 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16991 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 16992 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16993 | return 1; |
| 16994 | } |
| 16995 | |
| 16996 | /** |
| 16997 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 16998 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16999 | * |
| 17000 | * This function processes the FC header to retrieve the VFI from the VF |
| 17001 | * header, if one exists. This function will return the VFI if one exists |
| 17002 | * or 0 if no VSAN Header exists. |
| 17003 | **/ |
| 17004 | static uint32_t |
| 17005 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 17006 | { |
| 17007 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 17008 | |
| 17009 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 17010 | return 0; |
| 17011 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 17012 | } |
| 17013 | |
| 17014 | /** |
| 17015 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 17016 | * @phba: Pointer to the HBA structure to search for the vport on |
| 17017 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17018 | * @fcfi: The FC Fabric ID that the frame came from |
| 17019 | * |
| 17020 | * This function searches the @phba for a vport that matches the content of the |
| 17021 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 17022 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 17023 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 17024 | * vport. |
| 17025 | **/ |
| 17026 | static struct lpfc_vport * |
| 17027 | 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] | 17028 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17029 | { |
| 17030 | struct lpfc_vport **vports; |
| 17031 | struct lpfc_vport *vport = NULL; |
| 17032 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17033 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 17034 | if (did == Fabric_DID) |
| 17035 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17036 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 17037 | !(phba->link_state == LPFC_HBA_READY)) |
| 17038 | return phba->pport; |
| 17039 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17040 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17041 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17042 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 17043 | if (phba->fcf.fcfi == fcfi && |
| 17044 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 17045 | vports[i]->fc_myDID == did) { |
| 17046 | vport = vports[i]; |
| 17047 | break; |
| 17048 | } |
| 17049 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17050 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17051 | lpfc_destroy_vport_work_array(phba, vports); |
| 17052 | return vport; |
| 17053 | } |
| 17054 | |
| 17055 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17056 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 17057 | * @vport: The vport to work on. |
| 17058 | * |
| 17059 | * This function updates the receive sequence time stamp for this vport. The |
| 17060 | * receive sequence time stamp indicates the time that the last frame of the |
| 17061 | * the sequence that has been idle for the longest amount of time was received. |
| 17062 | * the driver uses this time stamp to indicate if any received sequences have |
| 17063 | * timed out. |
| 17064 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17065 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17066 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 17067 | { |
| 17068 | struct lpfc_dmabuf *h_buf; |
| 17069 | struct hbq_dmabuf *dmabuf = NULL; |
| 17070 | |
| 17071 | /* get the oldest sequence on the rcv list */ |
| 17072 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 17073 | struct lpfc_dmabuf, list); |
| 17074 | if (!h_buf) |
| 17075 | return; |
| 17076 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17077 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 17078 | } |
| 17079 | |
| 17080 | /** |
| 17081 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 17082 | * @vport: The vport that the received sequences were sent to. |
| 17083 | * |
| 17084 | * This function cleans up all outstanding received sequences. This is called |
| 17085 | * by the driver when a link event or user action invalidates all the received |
| 17086 | * sequences. |
| 17087 | **/ |
| 17088 | void |
| 17089 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 17090 | { |
| 17091 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17092 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17093 | struct hbq_dmabuf *dmabuf = NULL; |
| 17094 | |
| 17095 | /* start with the oldest sequence on the rcv list */ |
| 17096 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17097 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17098 | list_del_init(&dmabuf->hbuf.list); |
| 17099 | list_for_each_entry_safe(d_buf, dnext, |
| 17100 | &dmabuf->dbuf.list, list) { |
| 17101 | list_del_init(&d_buf->list); |
| 17102 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17103 | } |
| 17104 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17105 | } |
| 17106 | } |
| 17107 | |
| 17108 | /** |
| 17109 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 17110 | * @vport: The vport that the received sequences were sent to. |
| 17111 | * |
| 17112 | * This function determines whether any received sequences have timed out by |
| 17113 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 17114 | * indicates that there is at least one timed out sequence this routine will |
| 17115 | * go through the received sequences one at a time from most inactive to most |
| 17116 | * active to determine which ones need to be cleaned up. Once it has determined |
| 17117 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 17118 | * without sending an abort. |
| 17119 | **/ |
| 17120 | void |
| 17121 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 17122 | { |
| 17123 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17124 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17125 | struct hbq_dmabuf *dmabuf = NULL; |
| 17126 | unsigned long timeout; |
| 17127 | int abort_count = 0; |
| 17128 | |
| 17129 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17130 | vport->rcv_buffer_time_stamp); |
| 17131 | if (list_empty(&vport->rcv_buffer_list) || |
| 17132 | time_before(jiffies, timeout)) |
| 17133 | return; |
| 17134 | /* start with the oldest sequence on the rcv list */ |
| 17135 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17136 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17137 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17138 | dmabuf->time_stamp); |
| 17139 | if (time_before(jiffies, timeout)) |
| 17140 | break; |
| 17141 | abort_count++; |
| 17142 | list_del_init(&dmabuf->hbuf.list); |
| 17143 | list_for_each_entry_safe(d_buf, dnext, |
| 17144 | &dmabuf->dbuf.list, list) { |
| 17145 | list_del_init(&d_buf->list); |
| 17146 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17147 | } |
| 17148 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17149 | } |
| 17150 | if (abort_count) |
| 17151 | lpfc_update_rcv_time_stamp(vport); |
| 17152 | } |
| 17153 | |
| 17154 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17155 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 17156 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 17157 | * |
| 17158 | * This function searches through the existing incomplete sequences that have |
| 17159 | * been sent to this @vport. If the frame matches one of the incomplete |
| 17160 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 17161 | * make up that sequence. If no sequence is found that matches this frame then |
| 17162 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 17163 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 17164 | * the frame was linked to. |
| 17165 | **/ |
| 17166 | static struct hbq_dmabuf * |
| 17167 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17168 | { |
| 17169 | struct fc_frame_header *new_hdr; |
| 17170 | struct fc_frame_header *temp_hdr; |
| 17171 | struct lpfc_dmabuf *d_buf; |
| 17172 | struct lpfc_dmabuf *h_buf; |
| 17173 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17174 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17175 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17176 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17177 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17178 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17179 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17180 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17181 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 17182 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17183 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17184 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17185 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17186 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17187 | continue; |
| 17188 | /* found a pending sequence that matches this frame */ |
| 17189 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17190 | break; |
| 17191 | } |
| 17192 | if (!seq_dmabuf) { |
| 17193 | /* |
| 17194 | * This indicates first frame received for this sequence. |
| 17195 | * Queue the buffer on the vport's rcv_buffer_list. |
| 17196 | */ |
| 17197 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17198 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17199 | return dmabuf; |
| 17200 | } |
| 17201 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17202 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 17203 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17204 | list_del_init(&seq_dmabuf->hbuf.list); |
| 17205 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17206 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17207 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17208 | return dmabuf; |
| 17209 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17210 | /* move this sequence to the tail to indicate a young sequence */ |
| 17211 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17212 | seq_dmabuf->time_stamp = jiffies; |
| 17213 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17214 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 17215 | temp_hdr = dmabuf->hbuf.virt; |
| 17216 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 17217 | return seq_dmabuf; |
| 17218 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17219 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17220 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 17221 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17222 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17223 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 17224 | /* |
| 17225 | * If the frame's sequence count is greater than the frame on |
| 17226 | * the list then insert the frame right after this frame |
| 17227 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17228 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 17229 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17230 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17231 | found = 1; |
| 17232 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17233 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17234 | |
| 17235 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 17236 | break; |
| 17237 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17238 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17239 | |
| 17240 | if (found) |
| 17241 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17242 | return NULL; |
| 17243 | } |
| 17244 | |
| 17245 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17246 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 17247 | * @vport: pointer to a vitural port |
| 17248 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17249 | * |
| 17250 | * This function tries to abort from the partially assembed sequence, described |
| 17251 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 17252 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 17253 | * the frames from the partially assembled sequence. |
| 17254 | * |
| 17255 | * Return |
| 17256 | * true -- if there is matching partially assembled sequence present and all |
| 17257 | * the frames freed with the sequence; |
| 17258 | * false -- if there is no matching partially assembled sequence present so |
| 17259 | * nothing got aborted in the lower layer driver |
| 17260 | **/ |
| 17261 | static bool |
| 17262 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 17263 | struct hbq_dmabuf *dmabuf) |
| 17264 | { |
| 17265 | struct fc_frame_header *new_hdr; |
| 17266 | struct fc_frame_header *temp_hdr; |
| 17267 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 17268 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17269 | |
| 17270 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 17271 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 17272 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 17273 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17274 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17275 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17276 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17277 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17278 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17279 | continue; |
| 17280 | /* found a pending sequence that matches this frame */ |
| 17281 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17282 | break; |
| 17283 | } |
| 17284 | |
| 17285 | /* Free up all the frames from the partially assembled sequence */ |
| 17286 | if (seq_dmabuf) { |
| 17287 | list_for_each_entry_safe(d_buf, n_buf, |
| 17288 | &seq_dmabuf->dbuf.list, list) { |
| 17289 | list_del_init(&d_buf->list); |
| 17290 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17291 | } |
| 17292 | return true; |
| 17293 | } |
| 17294 | return false; |
| 17295 | } |
| 17296 | |
| 17297 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17298 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 17299 | * @vport: pointer to a vitural port |
| 17300 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17301 | * |
| 17302 | * This function tries to abort from the assembed sequence from upper level |
| 17303 | * protocol, described by the information from basic abbort @dmabuf. It |
| 17304 | * checks to see whether such pending context exists at upper level protocol. |
| 17305 | * If so, it shall clean up the pending context. |
| 17306 | * |
| 17307 | * Return |
| 17308 | * true -- if there is matching pending context of the sequence cleaned |
| 17309 | * at ulp; |
| 17310 | * false -- if there is no matching pending context of the sequence present |
| 17311 | * at ulp. |
| 17312 | **/ |
| 17313 | static bool |
| 17314 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17315 | { |
| 17316 | struct lpfc_hba *phba = vport->phba; |
| 17317 | int handled; |
| 17318 | |
| 17319 | /* Accepting abort at ulp with SLI4 only */ |
| 17320 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 17321 | return false; |
| 17322 | |
| 17323 | /* Register all caring upper level protocols to attend abort */ |
| 17324 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 17325 | if (handled) |
| 17326 | return true; |
| 17327 | |
| 17328 | return false; |
| 17329 | } |
| 17330 | |
| 17331 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17332 | * 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] | 17333 | * @phba: Pointer to HBA context object. |
| 17334 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 17335 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 17336 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17337 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17338 | * event. It properly releases the memory allocated to the sequence abort |
| 17339 | * accept iocb. |
| 17340 | **/ |
| 17341 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17342 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17343 | struct lpfc_iocbq *cmd_iocbq, |
| 17344 | struct lpfc_iocbq *rsp_iocbq) |
| 17345 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17346 | struct lpfc_nodelist *ndlp; |
| 17347 | |
| 17348 | if (cmd_iocbq) { |
| 17349 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 17350 | lpfc_nlp_put(ndlp); |
| 17351 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17352 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17353 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17354 | |
| 17355 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 17356 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 17357 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17358 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 17359 | rsp_iocbq->iocb.ulpStatus, |
| 17360 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17361 | } |
| 17362 | |
| 17363 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17364 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 17365 | * @phba: Pointer to HBA context object. |
| 17366 | * @xri: xri id in transaction. |
| 17367 | * |
| 17368 | * This function validates the xri maps to the known range of XRIs allocated an |
| 17369 | * used by the driver. |
| 17370 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17371 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17372 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 17373 | uint16_t xri) |
| 17374 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17375 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17376 | |
| 17377 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 17378 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 17379 | return i; |
| 17380 | } |
| 17381 | return NO_XRI; |
| 17382 | } |
| 17383 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17384 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17385 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17386 | * @phba: Pointer to HBA context object. |
| 17387 | * @fc_hdr: pointer to a FC frame header. |
| 17388 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17389 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17390 | * event after aborting the sequence handling. |
| 17391 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17392 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17393 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 17394 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17395 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17396 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17397 | struct lpfc_iocbq *ctiocb = NULL; |
| 17398 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17399 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17400 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17401 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17402 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17403 | |
| 17404 | if (!lpfc_is_link_up(phba)) |
| 17405 | return; |
| 17406 | |
| 17407 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 17408 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17409 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17410 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17411 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17412 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 17413 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17414 | if (!ndlp) { |
| 17415 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17416 | "1268 Failed to allocate ndlp for " |
| 17417 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 17418 | return; |
| 17419 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17420 | /* Put ndlp onto pport node list */ |
| 17421 | lpfc_enqueue_node(vport, ndlp); |
| 17422 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 17423 | /* re-setup ndlp without removing from node list */ |
| 17424 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 17425 | if (!ndlp) { |
| 17426 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17427 | "3275 Failed to active ndlp found " |
| 17428 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 17429 | return; |
| 17430 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17431 | } |
| 17432 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17433 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17434 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 17435 | if (!ctiocb) |
| 17436 | return; |
| 17437 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17438 | /* Extract the F_CTL field from FC_HDR */ |
| 17439 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 17440 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17441 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17442 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17443 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17444 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 17445 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 17446 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 17447 | |
| 17448 | /* Fill in the rest of iocb fields */ |
| 17449 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 17450 | icmd->ulpBdeCount = 0; |
| 17451 | icmd->ulpLe = 1; |
| 17452 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17453 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17454 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17455 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17456 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17457 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17458 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17459 | ctiocb->sli4_xritag = NO_XRI; |
| 17460 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17461 | if (fctl & FC_FC_EX_CTX) |
| 17462 | /* Exchange responder sent the abort so we |
| 17463 | * own the oxid. |
| 17464 | */ |
| 17465 | xri = oxid; |
| 17466 | else |
| 17467 | xri = rxid; |
| 17468 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 17469 | if (lxri != NO_XRI) |
| 17470 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 17471 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17472 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 17473 | * the oxid maps to the FCP XRI range, the port no longer has |
| 17474 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 17475 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17476 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17477 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17478 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17479 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17480 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17481 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17482 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17483 | } |
| 17484 | |
| 17485 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 17486 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 17487 | * the IOCB for a BA_RJT. |
| 17488 | */ |
| 17489 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17490 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17491 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17492 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17493 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17494 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17495 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17496 | if (fctl & FC_FC_EX_CTX) { |
| 17497 | /* ABTS sent by responder to CT exchange, construction |
| 17498 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 17499 | * field and RX_ID from ABTS for RX_ID field. |
| 17500 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17501 | 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] | 17502 | } else { |
| 17503 | /* ABTS sent by initiator to CT exchange, construction |
| 17504 | * 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] | 17505 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17506 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17507 | 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] | 17508 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 17509 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17510 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17511 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17512 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17513 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 17514 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 17515 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17516 | |
| 17517 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 17518 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17519 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 17520 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 17521 | "xri x%x, Data x%x\n", |
| 17522 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 17523 | phba->link_state); |
| 17524 | lpfc_nlp_put(ndlp); |
| 17525 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17526 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 17527 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17528 | } |
| 17529 | |
| 17530 | /** |
| 17531 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 17532 | * @vport: Pointer to the vport on which this sequence was received |
| 17533 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17534 | * |
| 17535 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 17536 | * receive sequence is only partially assembed by the driver, it shall abort |
| 17537 | * the partially assembled frames for the sequence. Otherwise, if the |
| 17538 | * unsolicited receive sequence has been completely assembled and passed to |
| 17539 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 17540 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 17541 | * accept to accept the abort. |
| 17542 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17543 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17544 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 17545 | struct hbq_dmabuf *dmabuf) |
| 17546 | { |
| 17547 | struct lpfc_hba *phba = vport->phba; |
| 17548 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17549 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17550 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17551 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17552 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 17553 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17554 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17555 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17556 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17557 | /* ABTS by responder to exchange, no cleanup needed */ |
| 17558 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17559 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17560 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 17561 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 17562 | if (aborted == false) |
| 17563 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17564 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17565 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17566 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17567 | if (phba->nvmet_support) { |
| 17568 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 17569 | return; |
| 17570 | } |
| 17571 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17572 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 17573 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17574 | } |
| 17575 | |
| 17576 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17577 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 17578 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17579 | * |
| 17580 | * This function checks the sequence, starting with the frame described by |
| 17581 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 17582 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 17583 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 17584 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 17585 | * set. 3) That there are no holes in the sequence count. The function will |
| 17586 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 17587 | **/ |
| 17588 | static int |
| 17589 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 17590 | { |
| 17591 | struct fc_frame_header *hdr; |
| 17592 | struct lpfc_dmabuf *d_buf; |
| 17593 | struct hbq_dmabuf *seq_dmabuf; |
| 17594 | uint32_t fctl; |
| 17595 | int seq_count = 0; |
| 17596 | |
| 17597 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17598 | /* make sure first fame of sequence has a sequence count of zero */ |
| 17599 | if (hdr->fh_seq_cnt != seq_count) |
| 17600 | return 0; |
| 17601 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17602 | hdr->fh_f_ctl[1] << 8 | |
| 17603 | hdr->fh_f_ctl[2]); |
| 17604 | /* If last frame of sequence we can return success. */ |
| 17605 | if (fctl & FC_FC_END_SEQ) |
| 17606 | return 1; |
| 17607 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 17608 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17609 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17610 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17611 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17612 | return 0; |
| 17613 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17614 | hdr->fh_f_ctl[1] << 8 | |
| 17615 | hdr->fh_f_ctl[2]); |
| 17616 | /* If last frame of sequence we can return success. */ |
| 17617 | if (fctl & FC_FC_END_SEQ) |
| 17618 | return 1; |
| 17619 | } |
| 17620 | return 0; |
| 17621 | } |
| 17622 | |
| 17623 | /** |
| 17624 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 17625 | * @vport: Pointer to the vport on which this sequence was received |
| 17626 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17627 | * |
| 17628 | * This function takes a sequence, described by a list of frames, and creates |
| 17629 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 17630 | * used to issue to the generic unsolicited sequence handler. This routine |
| 17631 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 17632 | * to allocate an iocbq then it throw out the received frames that were not |
| 17633 | * able to be described and return a pointer to the first iocbq. If unable to |
| 17634 | * allocate any iocbqs (including the first) this function will return NULL. |
| 17635 | **/ |
| 17636 | static struct lpfc_iocbq * |
| 17637 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 17638 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17639 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17640 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 17641 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 17642 | struct fc_frame_header *fc_hdr; |
| 17643 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17644 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17645 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17646 | |
| 17647 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17648 | /* remove from receive buffer list */ |
| 17649 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17650 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17651 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17652 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17653 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17654 | /* Get an iocbq struct to fill in. */ |
| 17655 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17656 | if (first_iocbq) { |
| 17657 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17658 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17659 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17660 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17661 | |
| 17662 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 17663 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 17664 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 17665 | first_iocbq->iocb.un.rcvels.parmRo = |
| 17666 | sli4_did_from_fc_hdr(fc_hdr); |
| 17667 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 17668 | } else |
| 17669 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17670 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 17671 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 17672 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 17673 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 17674 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 17675 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17676 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17677 | tot_len = bf_get(lpfc_rcqe_length, |
| 17678 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17679 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17680 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 17681 | first_iocbq->context3 = NULL; |
| 17682 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17683 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 17684 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17685 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17686 | else |
| 17687 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 17688 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17689 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17690 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17691 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17692 | } |
| 17693 | iocbq = first_iocbq; |
| 17694 | /* |
| 17695 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 17696 | * of buffers for this sequence and save two buffers in each IOCBq |
| 17697 | */ |
| 17698 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 17699 | if (!iocbq) { |
| 17700 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17701 | continue; |
| 17702 | } |
| 17703 | if (!iocbq->context3) { |
| 17704 | iocbq->context3 = d_buf; |
| 17705 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17706 | /* We need to get the size out of the right CQE */ |
| 17707 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17708 | len = bf_get(lpfc_rcqe_length, |
| 17709 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17710 | pbde = (struct ulp_bde64 *) |
| 17711 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 17712 | if (len > LPFC_DATA_BUF_SIZE) |
| 17713 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 17714 | else |
| 17715 | pbde->tus.f.bdeSize = len; |
| 17716 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17717 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 17718 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17719 | } else { |
| 17720 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17721 | if (!iocbq) { |
| 17722 | if (first_iocbq) { |
| 17723 | first_iocbq->iocb.ulpStatus = |
| 17724 | IOSTAT_FCP_RSP_ERROR; |
| 17725 | first_iocbq->iocb.un.ulpWord[4] = |
| 17726 | IOERR_NO_RESOURCES; |
| 17727 | } |
| 17728 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17729 | continue; |
| 17730 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17731 | /* We need to get the size out of the right CQE */ |
| 17732 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17733 | len = bf_get(lpfc_rcqe_length, |
| 17734 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17735 | iocbq->context2 = d_buf; |
| 17736 | iocbq->context3 = NULL; |
| 17737 | iocbq->iocb.ulpBdeCount = 1; |
| 17738 | if (len > LPFC_DATA_BUF_SIZE) |
| 17739 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 17740 | LPFC_DATA_BUF_SIZE; |
| 17741 | else |
| 17742 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 17743 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17744 | tot_len += len; |
| 17745 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 17746 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17747 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 17748 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 17749 | } |
| 17750 | } |
| 17751 | return first_iocbq; |
| 17752 | } |
| 17753 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17754 | static void |
| 17755 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 17756 | struct hbq_dmabuf *seq_dmabuf) |
| 17757 | { |
| 17758 | struct fc_frame_header *fc_hdr; |
| 17759 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 17760 | struct lpfc_hba *phba = vport->phba; |
| 17761 | |
| 17762 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17763 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 17764 | if (!iocbq) { |
| 17765 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17766 | "2707 Ring %d handler: Failed to allocate " |
| 17767 | "iocb Rctl x%x Type x%x received\n", |
| 17768 | LPFC_ELS_RING, |
| 17769 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17770 | return; |
| 17771 | } |
| 17772 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17773 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17774 | iocbq, fc_hdr->fh_r_ctl, |
| 17775 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17776 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17777 | "2540 Ring %d handler: unexpected Rctl " |
| 17778 | "x%x Type x%x received\n", |
| 17779 | LPFC_ELS_RING, |
| 17780 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17781 | |
| 17782 | /* Free iocb created in lpfc_prep_seq */ |
| 17783 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 17784 | &iocbq->list, list) { |
| 17785 | list_del_init(&curr_iocb->list); |
| 17786 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 17787 | } |
| 17788 | lpfc_sli_release_iocbq(phba, iocbq); |
| 17789 | } |
| 17790 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17791 | static void |
| 17792 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 17793 | struct lpfc_iocbq *rspiocb) |
| 17794 | { |
| 17795 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 17796 | |
| 17797 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17798 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17799 | kfree(pcmd); |
| 17800 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17801 | lpfc_drain_txq(phba); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17802 | } |
| 17803 | |
| 17804 | static void |
| 17805 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 17806 | struct hbq_dmabuf *dmabuf) |
| 17807 | { |
| 17808 | struct fc_frame_header *fc_hdr; |
| 17809 | struct lpfc_hba *phba = vport->phba; |
| 17810 | struct lpfc_iocbq *iocbq = NULL; |
| 17811 | union lpfc_wqe *wqe; |
| 17812 | struct lpfc_dmabuf *pcmd = NULL; |
| 17813 | uint32_t frame_len; |
| 17814 | int rc; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17815 | unsigned long iflags; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17816 | |
| 17817 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17818 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17819 | |
| 17820 | /* Send the received frame back */ |
| 17821 | iocbq = lpfc_sli_get_iocbq(phba); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17822 | if (!iocbq) { |
| 17823 | /* Queue cq event and wakeup worker thread to process it */ |
| 17824 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 17825 | list_add_tail(&dmabuf->cq_event.list, |
| 17826 | &phba->sli4_hba.sp_queue_event); |
| 17827 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
| 17828 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 17829 | lpfc_worker_wake_up(phba); |
| 17830 | return; |
| 17831 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17832 | |
| 17833 | /* Allocate buffer for command payload */ |
| 17834 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 17835 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17836 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17837 | &pcmd->phys); |
| 17838 | if (!pcmd || !pcmd->virt) |
| 17839 | goto exit; |
| 17840 | |
| 17841 | INIT_LIST_HEAD(&pcmd->list); |
| 17842 | |
| 17843 | /* copyin the payload */ |
| 17844 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 17845 | |
| 17846 | /* fill in BDE's for command */ |
| 17847 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 17848 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 17849 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 17850 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 17851 | |
| 17852 | iocbq->context2 = pcmd; |
| 17853 | iocbq->vport = vport; |
| 17854 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 17855 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 17856 | |
| 17857 | /* |
| 17858 | * Setup rest of the iocb as though it were a WQE |
| 17859 | * Build the SEND_FRAME WQE |
| 17860 | */ |
| 17861 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 17862 | |
| 17863 | wqe->send_frame.frame_len = frame_len; |
| 17864 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 17865 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 17866 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 17867 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 17868 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 17869 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 17870 | |
| 17871 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 17872 | iocbq->iocb.ulpLe = 1; |
| 17873 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 17874 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 17875 | if (rc == IOCB_ERROR) |
| 17876 | goto exit; |
| 17877 | |
| 17878 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17879 | return; |
| 17880 | |
| 17881 | exit: |
| 17882 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 17883 | "2023 Unable to process MDS loopback frame\n"); |
| 17884 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17885 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17886 | kfree(pcmd); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 17887 | if (iocbq) |
| 17888 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17889 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17890 | } |
| 17891 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17892 | /** |
| 17893 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 17894 | * @phba: Pointer to HBA context object. |
| 17895 | * |
| 17896 | * This function is called with no lock held. This function processes all |
| 17897 | * the received buffers and gives it to upper layers when a received buffer |
| 17898 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17899 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17900 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 17901 | * appropriate receive function when the final frame in a sequence is received. |
| 17902 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17903 | void |
| 17904 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 17905 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17906 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17907 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17908 | struct fc_frame_header *fc_hdr; |
| 17909 | struct lpfc_vport *vport; |
| 17910 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17911 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17912 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17913 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17914 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17915 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17916 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 17917 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 17918 | vport = phba->pport; |
| 17919 | /* Handle MDS Loopback frames */ |
| 17920 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 17921 | return; |
| 17922 | } |
| 17923 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17924 | /* check to see if this a valid type of frame */ |
| 17925 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 17926 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17927 | return; |
| 17928 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17929 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17930 | if ((bf_get(lpfc_cqe_code, |
| 17931 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 17932 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 17933 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17934 | else |
| 17935 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 17936 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17937 | |
James Smart | e62245d | 2019-08-14 16:57:08 -0700 | [diff] [blame] | 17938 | if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) { |
| 17939 | vport = phba->pport; |
| 17940 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 17941 | "2023 MDS Loopback %d bytes\n", |
| 17942 | bf_get(lpfc_rcqe_length, |
| 17943 | &dmabuf->cq_event.cqe.rcqe_cmpl)); |
| 17944 | /* Handle MDS Loopback frames */ |
| 17945 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 17946 | return; |
| 17947 | } |
| 17948 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17949 | /* d_id this frame is directed to */ |
| 17950 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 17951 | |
| 17952 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17953 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17954 | /* throw out the frame */ |
| 17955 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17956 | return; |
| 17957 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17958 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17959 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 17960 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 17961 | (did != Fabric_DID)) { |
| 17962 | /* |
| 17963 | * Throw out the frame if we are not pt2pt. |
| 17964 | * The pt2pt protocol allows for discovery frames |
| 17965 | * to be received without a registered VPI. |
| 17966 | */ |
| 17967 | if (!(vport->fc_flag & FC_PT2PT) || |
| 17968 | (phba->link_state == LPFC_HBA_READY)) { |
| 17969 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17970 | return; |
| 17971 | } |
| 17972 | } |
| 17973 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17974 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 17975 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 17976 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 17977 | return; |
| 17978 | } |
| 17979 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17980 | /* Link this frame */ |
| 17981 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 17982 | if (!seq_dmabuf) { |
| 17983 | /* unable to add frame to vport - throw it out */ |
| 17984 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17985 | return; |
| 17986 | } |
| 17987 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17988 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17989 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17990 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17991 | /* Send the complete sequence to the upper layer protocol */ |
| 17992 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17993 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17994 | |
| 17995 | /** |
| 17996 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 17997 | * @phba: pointer to lpfc hba data structure. |
| 17998 | * |
| 17999 | * This routine is invoked to post rpi header templates to the |
| 18000 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18001 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18002 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18003 | * |
| 18004 | * This routine does not require any locks. It's usage is expected |
| 18005 | * to be driver load or reset recovery when the driver is |
| 18006 | * sequential. |
| 18007 | * |
| 18008 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18009 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18010 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18011 | * When this error occurs, the driver is not guaranteed |
| 18012 | * to have any rpi regions posted to the device and |
| 18013 | * must either attempt to repost the regions or take a |
| 18014 | * fatal error. |
| 18015 | **/ |
| 18016 | int |
| 18017 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 18018 | { |
| 18019 | struct lpfc_rpi_hdr *rpi_page; |
| 18020 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18021 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18022 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18023 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18024 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18025 | goto exit; |
| 18026 | if (phba->sli4_hba.extents_in_use) |
| 18027 | return -EIO; |
| 18028 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18029 | 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] | 18030 | /* |
| 18031 | * Assign the rpi headers a physical rpi only if the driver |
| 18032 | * has not initialized those resources. A port reset only |
| 18033 | * needs the headers posted. |
| 18034 | */ |
| 18035 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 18036 | LPFC_RPI_RSRC_RDY) |
| 18037 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 18038 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18039 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 18040 | if (rc != MBX_SUCCESS) { |
| 18041 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18042 | "2008 Error %d posting all rpi " |
| 18043 | "headers\n", rc); |
| 18044 | rc = -EIO; |
| 18045 | break; |
| 18046 | } |
| 18047 | } |
| 18048 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18049 | exit: |
| 18050 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 18051 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18052 | return rc; |
| 18053 | } |
| 18054 | |
| 18055 | /** |
| 18056 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 18057 | * @phba: pointer to lpfc hba data structure. |
| 18058 | * @rpi_page: pointer to the rpi memory region. |
| 18059 | * |
| 18060 | * This routine is invoked to post a single rpi header to the |
| 18061 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 18062 | * maps up to 64 rpi context regions. |
| 18063 | * |
| 18064 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18065 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18066 | * -ENOMEM - No available memory |
| 18067 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18068 | **/ |
| 18069 | int |
| 18070 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 18071 | { |
| 18072 | LPFC_MBOXQ_t *mboxq; |
| 18073 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 18074 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18075 | uint32_t shdr_status, shdr_add_status; |
| 18076 | union lpfc_sli4_cfg_shdr *shdr; |
| 18077 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18078 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18079 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18080 | return rc; |
| 18081 | if (phba->sli4_hba.extents_in_use) |
| 18082 | return -EIO; |
| 18083 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18084 | /* The port is notified of the header region via a mailbox command. */ |
| 18085 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18086 | if (!mboxq) { |
| 18087 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18088 | "2001 Unable to allocate memory for issuing " |
| 18089 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 18090 | return -ENOMEM; |
| 18091 | } |
| 18092 | |
| 18093 | /* Post all rpi memory regions to the port. */ |
| 18094 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18095 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18096 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 18097 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 18098 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 18099 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18100 | |
| 18101 | |
| 18102 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18103 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 18104 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18105 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 18106 | hdr_tmpl, rpi_page->page_count); |
| 18107 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18108 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 18109 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 18110 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18111 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 18112 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18113 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18114 | if (rc != MBX_TIMEOUT) |
| 18115 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18116 | if (shdr_status || shdr_add_status || rc) { |
| 18117 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18118 | "2514 POST_RPI_HDR mailbox failed with " |
| 18119 | "status x%x add_status x%x, mbx status x%x\n", |
| 18120 | shdr_status, shdr_add_status, rc); |
| 18121 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 18122 | } else { |
| 18123 | /* |
| 18124 | * The next_rpi stores the next logical module-64 rpi value used |
| 18125 | * to post physical rpis in subsequent rpi postings. |
| 18126 | */ |
| 18127 | spin_lock_irq(&phba->hbalock); |
| 18128 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 18129 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18130 | } |
| 18131 | return rc; |
| 18132 | } |
| 18133 | |
| 18134 | /** |
| 18135 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 18136 | * @phba: pointer to lpfc hba data structure. |
| 18137 | * |
| 18138 | * This routine is invoked to post rpi header templates to the |
| 18139 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18140 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18141 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18142 | * |
| 18143 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18144 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18145 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 18146 | **/ |
| 18147 | int |
| 18148 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 18149 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18150 | unsigned long rpi; |
| 18151 | uint16_t max_rpi, rpi_limit; |
| 18152 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18153 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18154 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18155 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18156 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18157 | * Fetch the next logical rpi. Because this index is logical, |
| 18158 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18159 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18160 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18161 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 18162 | rpi_limit = phba->sli4_hba.next_rpi; |
| 18163 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18164 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 18165 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18166 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 18167 | else { |
| 18168 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 18169 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 18170 | phba->sli4_hba.rpi_count++; |
| 18171 | } |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 18172 | lpfc_printf_log(phba, KERN_INFO, |
| 18173 | LOG_NODE | LOG_DISCOVERY, |
| 18174 | "0001 Allocated rpi:x%x max:x%x lim:x%x\n", |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18175 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18176 | |
| 18177 | /* |
| 18178 | * 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] | 18179 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18180 | */ |
| 18181 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 18182 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18183 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18184 | return rpi; |
| 18185 | } |
| 18186 | |
| 18187 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18188 | * RPI header postings are not required for SLI4 ports capable of |
| 18189 | * extents. |
| 18190 | */ |
| 18191 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18192 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18193 | return rpi; |
| 18194 | } |
| 18195 | |
| 18196 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18197 | * If the driver is running low on rpi resources, allocate another |
| 18198 | * page now. Note that the next_rpi value is used because |
| 18199 | * it represents how many are actually in use whereas max_rpi notes |
| 18200 | * how many are supported max by the device. |
| 18201 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18202 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18203 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18204 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 18205 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 18206 | if (!rpi_hdr) { |
| 18207 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18208 | "2002 Error Could not grow rpi " |
| 18209 | "count\n"); |
| 18210 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18211 | lrpi = rpi_hdr->start_rpi; |
| 18212 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18213 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 18214 | } |
| 18215 | } |
| 18216 | |
| 18217 | return rpi; |
| 18218 | } |
| 18219 | |
| 18220 | /** |
| 18221 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18222 | * @phba: pointer to lpfc hba data structure. |
| 18223 | * |
| 18224 | * This routine is invoked to release an rpi to the pool of |
| 18225 | * available rpis maintained by the driver. |
| 18226 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18227 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18228 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18229 | { |
| 18230 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 18231 | phba->sli4_hba.rpi_count--; |
| 18232 | phba->sli4_hba.max_cfg_param.rpi_used--; |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 18233 | } else { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 18234 | lpfc_printf_log(phba, KERN_INFO, |
| 18235 | LOG_NODE | LOG_DISCOVERY, |
James Smart | b95b211 | 2019-08-14 16:56:47 -0700 | [diff] [blame] | 18236 | "2016 rpi %x not inuse\n", |
| 18237 | rpi); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18238 | } |
| 18239 | } |
| 18240 | |
| 18241 | /** |
| 18242 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18243 | * @phba: pointer to lpfc hba data structure. |
| 18244 | * |
| 18245 | * This routine is invoked to release an rpi to the pool of |
| 18246 | * available rpis maintained by the driver. |
| 18247 | **/ |
| 18248 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18249 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18250 | { |
| 18251 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18252 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18253 | spin_unlock_irq(&phba->hbalock); |
| 18254 | } |
| 18255 | |
| 18256 | /** |
| 18257 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 18258 | * @phba: pointer to lpfc hba data structure. |
| 18259 | * |
| 18260 | * This routine is invoked to remove the memory region that |
| 18261 | * provided rpi via a bitmask. |
| 18262 | **/ |
| 18263 | void |
| 18264 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 18265 | { |
| 18266 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18267 | kfree(phba->sli4_hba.rpi_ids); |
| 18268 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18269 | } |
| 18270 | |
| 18271 | /** |
| 18272 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 18273 | * @phba: pointer to lpfc hba data structure. |
| 18274 | * |
| 18275 | * This routine is invoked to remove the memory region that |
| 18276 | * provided rpi via a bitmask. |
| 18277 | **/ |
| 18278 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18279 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 18280 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18281 | { |
| 18282 | LPFC_MBOXQ_t *mboxq; |
| 18283 | struct lpfc_hba *phba = ndlp->phba; |
| 18284 | int rc; |
| 18285 | |
| 18286 | /* The port is notified of the header region via a mailbox command. */ |
| 18287 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18288 | if (!mboxq) |
| 18289 | return -ENOMEM; |
| 18290 | |
| 18291 | /* Post all rpi memory regions to the port. */ |
| 18292 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18293 | if (cmpl) { |
| 18294 | mboxq->mbox_cmpl = cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 18295 | mboxq->ctx_buf = arg; |
| 18296 | mboxq->ctx_ndlp = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 18297 | } else |
| 18298 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18299 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18300 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18301 | if (rc == MBX_NOT_FINISHED) { |
| 18302 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18303 | "2010 Resume RPI Mailbox failed " |
| 18304 | "status %d, mbxStatus x%x\n", rc, |
| 18305 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 18306 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18307 | return -EIO; |
| 18308 | } |
| 18309 | return 0; |
| 18310 | } |
| 18311 | |
| 18312 | /** |
| 18313 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18314 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18315 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18316 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18317 | * |
| 18318 | * Returns: |
| 18319 | * 0 success |
| 18320 | * -Evalue otherwise |
| 18321 | **/ |
| 18322 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18323 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18324 | { |
| 18325 | LPFC_MBOXQ_t *mboxq; |
| 18326 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18327 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18328 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18329 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18330 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18331 | if (!mboxq) |
| 18332 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18333 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18334 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18335 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18336 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18337 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18338 | "2022 INIT VPI Mailbox failed " |
| 18339 | "status %d, mbxStatus x%x\n", rc, |
| 18340 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18341 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18342 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18343 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18344 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18345 | |
| 18346 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18347 | } |
| 18348 | |
| 18349 | /** |
| 18350 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 18351 | * @phba: pointer to lpfc hba data structure. |
| 18352 | * @mboxq: Pointer to mailbox object. |
| 18353 | * |
| 18354 | * This routine is invoked to manually add a single FCF record. The caller |
| 18355 | * must pass a completely initialized FCF_Record. This routine takes |
| 18356 | * care of the nonembedded mailbox operations. |
| 18357 | **/ |
| 18358 | static void |
| 18359 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 18360 | { |
| 18361 | void *virt_addr; |
| 18362 | union lpfc_sli4_cfg_shdr *shdr; |
| 18363 | uint32_t shdr_status, shdr_add_status; |
| 18364 | |
| 18365 | virt_addr = mboxq->sge_array->addr[0]; |
| 18366 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 18367 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 18368 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18369 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18370 | |
| 18371 | if ((shdr_status || shdr_add_status) && |
| 18372 | (shdr_status != STATUS_FCF_IN_USE)) |
| 18373 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18374 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 18375 | "status x%x add_status x%x\n", |
| 18376 | shdr_status, shdr_add_status); |
| 18377 | |
| 18378 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18379 | } |
| 18380 | |
| 18381 | /** |
| 18382 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 18383 | * @phba: pointer to lpfc hba data structure. |
| 18384 | * @fcf_record: pointer to the initialized fcf record to add. |
| 18385 | * |
| 18386 | * This routine is invoked to manually add a single FCF record. The caller |
| 18387 | * must pass a completely initialized FCF_Record. This routine takes |
| 18388 | * care of the nonembedded mailbox operations. |
| 18389 | **/ |
| 18390 | int |
| 18391 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 18392 | { |
| 18393 | int rc = 0; |
| 18394 | LPFC_MBOXQ_t *mboxq; |
| 18395 | uint8_t *bytep; |
| 18396 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18397 | struct lpfc_mbx_sge sge; |
| 18398 | uint32_t alloc_len, req_len; |
| 18399 | uint32_t fcfindex; |
| 18400 | |
| 18401 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18402 | if (!mboxq) { |
| 18403 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18404 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 18405 | return -ENOMEM; |
| 18406 | } |
| 18407 | |
| 18408 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 18409 | sizeof(uint32_t); |
| 18410 | |
| 18411 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 18412 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18413 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 18414 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 18415 | if (alloc_len < req_len) { |
| 18416 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18417 | "2523 Allocated DMA memory size (x%x) is " |
| 18418 | "less than the requested DMA memory " |
| 18419 | "size (x%x)\n", alloc_len, req_len); |
| 18420 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18421 | return -ENOMEM; |
| 18422 | } |
| 18423 | |
| 18424 | /* |
| 18425 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 18426 | * routine only uses a single SGE. |
| 18427 | */ |
| 18428 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18429 | virt_addr = mboxq->sge_array->addr[0]; |
| 18430 | /* |
| 18431 | * Configure the FCF record for FCFI 0. This is the driver's |
| 18432 | * hardcoded default and gets used in nonFIP mode. |
| 18433 | */ |
| 18434 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 18435 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 18436 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 18437 | |
| 18438 | /* |
| 18439 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 18440 | * the FCoE header plus word10. The data copy needs to be endian |
| 18441 | * correct. |
| 18442 | */ |
| 18443 | bytep += sizeof(uint32_t); |
| 18444 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 18445 | mboxq->vport = phba->pport; |
| 18446 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 18447 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18448 | if (rc == MBX_NOT_FINISHED) { |
| 18449 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18450 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 18451 | "status 0x%x\n", rc); |
| 18452 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18453 | rc = -EIO; |
| 18454 | } else |
| 18455 | rc = 0; |
| 18456 | |
| 18457 | return rc; |
| 18458 | } |
| 18459 | |
| 18460 | /** |
| 18461 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 18462 | * @phba: pointer to lpfc hba data structure. |
| 18463 | * @fcf_record: pointer to the fcf record to write the default data. |
| 18464 | * @fcf_index: FCF table entry index. |
| 18465 | * |
| 18466 | * This routine is invoked to build the driver's default FCF record. The |
| 18467 | * values used are hardcoded. This routine handles memory initialization. |
| 18468 | * |
| 18469 | **/ |
| 18470 | void |
| 18471 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 18472 | struct fcf_record *fcf_record, |
| 18473 | uint16_t fcf_index) |
| 18474 | { |
| 18475 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 18476 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 18477 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 18478 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 18479 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 18480 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 18481 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 18482 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 18483 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 18484 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 18485 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 18486 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 18487 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 18488 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 18489 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18490 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 18491 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 18492 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 18493 | /* Set the VLAN bit map */ |
| 18494 | if (phba->valid_vlan) { |
| 18495 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 18496 | = 1 << (phba->vlan_id % 8); |
| 18497 | } |
| 18498 | } |
| 18499 | |
| 18500 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18501 | * 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] | 18502 | * @phba: pointer to lpfc hba data structure. |
| 18503 | * @fcf_index: FCF table entry offset. |
| 18504 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18505 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 18506 | * record and processing it one at a time starting from the @fcf_index |
| 18507 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 18508 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18509 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18510 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18511 | **/ |
| 18512 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18513 | 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] | 18514 | { |
| 18515 | int rc = 0, error; |
| 18516 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18517 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18518 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 18519 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18520 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18521 | if (!mboxq) { |
| 18522 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18523 | "2000 Failed to allocate mbox for " |
| 18524 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18525 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18526 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18527 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18528 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18529 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18530 | if (rc) { |
| 18531 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18532 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18533 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18534 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18535 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18536 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18537 | |
| 18538 | spin_lock_irq(&phba->hbalock); |
| 18539 | phba->hba_flag |= FCF_TS_INPROG; |
| 18540 | spin_unlock_irq(&phba->hbalock); |
| 18541 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18542 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18543 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18544 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18545 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 18546 | /* Reset eligible FCF count for new scan */ |
| 18547 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 18548 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18549 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18550 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18551 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18552 | if (error) { |
| 18553 | if (mboxq) |
| 18554 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18555 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18556 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18557 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18558 | spin_unlock_irq(&phba->hbalock); |
| 18559 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18560 | return error; |
| 18561 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18562 | |
| 18563 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18564 | * 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] | 18565 | * @phba: pointer to lpfc hba data structure. |
| 18566 | * @fcf_index: FCF table entry offset. |
| 18567 | * |
| 18568 | * 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] | 18569 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18570 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18571 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18572 | * otherwise. |
| 18573 | **/ |
| 18574 | int |
| 18575 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18576 | { |
| 18577 | int rc = 0, error; |
| 18578 | LPFC_MBOXQ_t *mboxq; |
| 18579 | |
| 18580 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18581 | if (!mboxq) { |
| 18582 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18583 | "2763 Failed to allocate mbox for " |
| 18584 | "READ_FCF cmd\n"); |
| 18585 | error = -ENOMEM; |
| 18586 | goto fail_fcf_read; |
| 18587 | } |
| 18588 | /* Construct the read FCF record mailbox command */ |
| 18589 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18590 | if (rc) { |
| 18591 | error = -EINVAL; |
| 18592 | goto fail_fcf_read; |
| 18593 | } |
| 18594 | /* Issue the mailbox command asynchronously */ |
| 18595 | mboxq->vport = phba->pport; |
| 18596 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 18597 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18598 | if (rc == MBX_NOT_FINISHED) |
| 18599 | error = -EIO; |
| 18600 | else |
| 18601 | error = 0; |
| 18602 | |
| 18603 | fail_fcf_read: |
| 18604 | if (error && mboxq) |
| 18605 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18606 | return error; |
| 18607 | } |
| 18608 | |
| 18609 | /** |
| 18610 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 18611 | * @phba: pointer to lpfc hba data structure. |
| 18612 | * @fcf_index: FCF table entry offset. |
| 18613 | * |
| 18614 | * 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] | 18615 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18616 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18617 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18618 | * otherwise. |
| 18619 | **/ |
| 18620 | int |
| 18621 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18622 | { |
| 18623 | int rc = 0, error; |
| 18624 | LPFC_MBOXQ_t *mboxq; |
| 18625 | |
| 18626 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18627 | if (!mboxq) { |
| 18628 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18629 | "2758 Failed to allocate mbox for " |
| 18630 | "READ_FCF cmd\n"); |
| 18631 | error = -ENOMEM; |
| 18632 | goto fail_fcf_read; |
| 18633 | } |
| 18634 | /* Construct the read FCF record mailbox command */ |
| 18635 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18636 | if (rc) { |
| 18637 | error = -EINVAL; |
| 18638 | goto fail_fcf_read; |
| 18639 | } |
| 18640 | /* Issue the mailbox command asynchronously */ |
| 18641 | mboxq->vport = phba->pport; |
| 18642 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 18643 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18644 | if (rc == MBX_NOT_FINISHED) |
| 18645 | error = -EIO; |
| 18646 | else |
| 18647 | error = 0; |
| 18648 | |
| 18649 | fail_fcf_read: |
| 18650 | if (error && mboxq) |
| 18651 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18652 | return error; |
| 18653 | } |
| 18654 | |
| 18655 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18656 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18657 | * phba pointer to the lpfc_hba struct for this port. |
| 18658 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 18659 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 18660 | * rr_bmask based on their priority level. Starting from the highest priority |
| 18661 | * to the lowest. The most likely FCF candidate will be in the highest |
| 18662 | * priority group. When this routine is called it searches the fcf_pri list for |
| 18663 | * next lowest priority group and repopulates the rr_bmask with only those |
| 18664 | * fcf_indexes. |
| 18665 | * returns: |
| 18666 | * 1=success 0=failure |
| 18667 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18668 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18669 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 18670 | { |
| 18671 | uint16_t next_fcf_pri; |
| 18672 | uint16_t last_index; |
| 18673 | struct lpfc_fcf_pri *fcf_pri; |
| 18674 | int rc; |
| 18675 | int ret = 0; |
| 18676 | |
| 18677 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 18678 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18679 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 18680 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18681 | |
| 18682 | /* Verify the priority list has 2 or more entries */ |
| 18683 | spin_lock_irq(&phba->hbalock); |
| 18684 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 18685 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 18686 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18687 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 18688 | "3061 Last IDX %d\n", last_index); |
| 18689 | return 0; /* Empty rr list */ |
| 18690 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18691 | spin_unlock_irq(&phba->hbalock); |
| 18692 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18693 | next_fcf_pri = 0; |
| 18694 | /* |
| 18695 | * Clear the rr_bmask and set all of the bits that are at this |
| 18696 | * priority. |
| 18697 | */ |
| 18698 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 18699 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 18700 | spin_lock_irq(&phba->hbalock); |
| 18701 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18702 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 18703 | continue; |
| 18704 | /* |
| 18705 | * the 1st priority that has not FLOGI failed |
| 18706 | * will be the highest. |
| 18707 | */ |
| 18708 | if (!next_fcf_pri) |
| 18709 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18710 | spin_unlock_irq(&phba->hbalock); |
| 18711 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18712 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18713 | fcf_pri->fcf_rec.fcf_index); |
| 18714 | if (rc) |
| 18715 | return 0; |
| 18716 | } |
| 18717 | spin_lock_irq(&phba->hbalock); |
| 18718 | } |
| 18719 | /* |
| 18720 | * if next_fcf_pri was not set above and the list is not empty then |
| 18721 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 18722 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18723 | */ |
| 18724 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 18725 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18726 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 18727 | /* |
| 18728 | * the 1st priority that has not FLOGI failed |
| 18729 | * will be the highest. |
| 18730 | */ |
| 18731 | if (!next_fcf_pri) |
| 18732 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18733 | spin_unlock_irq(&phba->hbalock); |
| 18734 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18735 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18736 | fcf_pri->fcf_rec.fcf_index); |
| 18737 | if (rc) |
| 18738 | return 0; |
| 18739 | } |
| 18740 | spin_lock_irq(&phba->hbalock); |
| 18741 | } |
| 18742 | } else |
| 18743 | ret = 1; |
| 18744 | spin_unlock_irq(&phba->hbalock); |
| 18745 | |
| 18746 | return ret; |
| 18747 | } |
| 18748 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18749 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 18750 | * @phba: pointer to lpfc hba data structure. |
| 18751 | * |
| 18752 | * This routine is to get the next eligible FCF record index in a round |
| 18753 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18754 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18755 | * shall be returned, otherwise, the next eligible FCF record's index |
| 18756 | * shall be returned. |
| 18757 | **/ |
| 18758 | uint16_t |
| 18759 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 18760 | { |
| 18761 | uint16_t next_fcf_index; |
| 18762 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18763 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18764 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18765 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 18766 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18767 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18768 | /* Determine the next fcf index to check */ |
| 18769 | 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] | 18770 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18771 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18772 | next_fcf_index); |
| 18773 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18774 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18775 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18776 | /* |
| 18777 | * If we have wrapped then we need to clear the bits that |
| 18778 | * have been tested so that we can detect when we should |
| 18779 | * change the priority level. |
| 18780 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18781 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18782 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18783 | } |
| 18784 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18785 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18786 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18787 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 18788 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 18789 | /* |
| 18790 | * If next fcf index is not found check if there are lower |
| 18791 | * Priority level fcf's in the fcf_priority list. |
| 18792 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 18793 | * at that level and continue the selection process. |
| 18794 | */ |
| 18795 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18796 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18797 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 18798 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 18799 | |
| 18800 | return LPFC_FCOE_FCF_NEXT_NONE; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18801 | } |
| 18802 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18803 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 18804 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18805 | LPFC_FCF_FLOGI_FAILED) { |
| 18806 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 18807 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 18808 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18809 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18810 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18811 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18812 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18813 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 18814 | next_fcf_index); |
| 18815 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18816 | return next_fcf_index; |
| 18817 | } |
| 18818 | |
| 18819 | /** |
| 18820 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 18821 | * @phba: pointer to lpfc hba data structure. |
| 18822 | * |
| 18823 | * 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] | 18824 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18825 | * does not go beyond the range of the driver allocated bmask dimension |
| 18826 | * before setting the bit. |
| 18827 | * |
| 18828 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 18829 | * -EINVAL. |
| 18830 | **/ |
| 18831 | int |
| 18832 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18833 | { |
| 18834 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18835 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18836 | "2610 FCF (x%x) reached driver's book " |
| 18837 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18838 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18839 | return -EINVAL; |
| 18840 | } |
| 18841 | /* Set the eligible FCF record index bmask */ |
| 18842 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 18843 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18844 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18845 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18846 | "bmask\n", fcf_index); |
| 18847 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18848 | return 0; |
| 18849 | } |
| 18850 | |
| 18851 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18852 | * 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] | 18853 | * @phba: pointer to lpfc hba data structure. |
| 18854 | * |
| 18855 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18856 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18857 | * does not go beyond the range of the driver allocated bmask dimension |
| 18858 | * before clearing the bit. |
| 18859 | **/ |
| 18860 | void |
| 18861 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18862 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18863 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18864 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18865 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18866 | "2762 FCF (x%x) reached driver's book " |
| 18867 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18868 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18869 | return; |
| 18870 | } |
| 18871 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18872 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18873 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 18874 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18875 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 18876 | list_del_init(&fcf_pri->list); |
| 18877 | break; |
| 18878 | } |
| 18879 | } |
| 18880 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18881 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18882 | |
| 18883 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18884 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18885 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18886 | } |
| 18887 | |
| 18888 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18889 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 18890 | * @phba: pointer to lpfc hba data structure. |
| 18891 | * |
| 18892 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 18893 | * command. If the mailbox command returned failure, it will try to stop the |
| 18894 | * FCF rediscover wait timer. |
| 18895 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18896 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18897 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 18898 | { |
| 18899 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18900 | uint32_t shdr_status, shdr_add_status; |
| 18901 | |
| 18902 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18903 | |
| 18904 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 18905 | &redisc_fcf->header.cfg_shdr.response); |
| 18906 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 18907 | &redisc_fcf->header.cfg_shdr.response); |
| 18908 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18909 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18910 | "2746 Requesting for FCF rediscovery failed " |
| 18911 | "status x%x add_status x%x\n", |
| 18912 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18913 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18914 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18915 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18916 | spin_unlock_irq(&phba->hbalock); |
| 18917 | /* |
| 18918 | * CVL event triggered FCF rediscover request failed, |
| 18919 | * last resort to re-try current registered FCF entry. |
| 18920 | */ |
| 18921 | lpfc_retry_pport_discovery(phba); |
| 18922 | } else { |
| 18923 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18924 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18925 | spin_unlock_irq(&phba->hbalock); |
| 18926 | /* |
| 18927 | * DEAD FCF event triggered FCF rediscover request |
| 18928 | * failed, last resort to fail over as a link down |
| 18929 | * to FCF registration. |
| 18930 | */ |
| 18931 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 18932 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18933 | } else { |
| 18934 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18935 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18936 | /* |
| 18937 | * Start FCF rediscovery wait timer for pending FCF |
| 18938 | * before rescan FCF record table. |
| 18939 | */ |
| 18940 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18941 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18942 | |
| 18943 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18944 | } |
| 18945 | |
| 18946 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18947 | * 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] | 18948 | * @phba: pointer to lpfc hba data structure. |
| 18949 | * |
| 18950 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 18951 | * by the port. |
| 18952 | **/ |
| 18953 | int |
| 18954 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 18955 | { |
| 18956 | LPFC_MBOXQ_t *mbox; |
| 18957 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18958 | int rc, length; |
| 18959 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18960 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 18961 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 18962 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18963 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18964 | if (!mbox) { |
| 18965 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18966 | "2745 Failed to allocate mbox for " |
| 18967 | "requesting FCF rediscover.\n"); |
| 18968 | return -ENOMEM; |
| 18969 | } |
| 18970 | |
| 18971 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 18972 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 18973 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18974 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 18975 | length, LPFC_SLI4_MBX_EMBED); |
| 18976 | |
| 18977 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18978 | /* Set count to 0 for invalidating the entire FCF database */ |
| 18979 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 18980 | |
| 18981 | /* Issue the mailbox command asynchronously */ |
| 18982 | mbox->vport = phba->pport; |
| 18983 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 18984 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 18985 | |
| 18986 | if (rc == MBX_NOT_FINISHED) { |
| 18987 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18988 | return -EIO; |
| 18989 | } |
| 18990 | return 0; |
| 18991 | } |
| 18992 | |
| 18993 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18994 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 18995 | * @phba: pointer to lpfc hba data structure. |
| 18996 | * |
| 18997 | * This function is the failover routine as a last resort to the FCF DEAD |
| 18998 | * event when driver failed to perform fast FCF failover. |
| 18999 | **/ |
| 19000 | void |
| 19001 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 19002 | { |
| 19003 | uint32_t link_state; |
| 19004 | |
| 19005 | /* |
| 19006 | * Last resort as FCF DEAD event failover will treat this as |
| 19007 | * a link down, but save the link state because we don't want |
| 19008 | * it to be changed to Link Down unless it is already down. |
| 19009 | */ |
| 19010 | link_state = phba->link_state; |
| 19011 | lpfc_linkdown(phba); |
| 19012 | phba->link_state = link_state; |
| 19013 | |
| 19014 | /* Unregister FCF if no devices connected to it */ |
| 19015 | lpfc_unregister_unused_fcf(phba); |
| 19016 | } |
| 19017 | |
| 19018 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19019 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19020 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19021 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19022 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19023 | * This function gets SLI3 port configure region 23 data through memory dump |
| 19024 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19025 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19026 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19027 | static uint32_t |
| 19028 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19029 | { |
| 19030 | LPFC_MBOXQ_t *pmb = NULL; |
| 19031 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19032 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19033 | int rc; |
| 19034 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19035 | if (!rgn23_data) |
| 19036 | return 0; |
| 19037 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19038 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19039 | if (!pmb) { |
| 19040 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19041 | "2600 failed to allocate mailbox memory\n"); |
| 19042 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19043 | } |
| 19044 | mb = &pmb->u.mb; |
| 19045 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19046 | do { |
| 19047 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 19048 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 19049 | |
| 19050 | if (rc != MBX_SUCCESS) { |
| 19051 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19052 | "2601 failed to read config " |
| 19053 | "region 23, rc 0x%x Status 0x%x\n", |
| 19054 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19055 | mb->un.varDmp.word_cnt = 0; |
| 19056 | } |
| 19057 | /* |
| 19058 | * dump mem may return a zero when finished or we got a |
| 19059 | * mailbox error, either way we are done. |
| 19060 | */ |
| 19061 | if (mb->un.varDmp.word_cnt == 0) |
| 19062 | break; |
| 19063 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 19064 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 19065 | |
| 19066 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19067 | rgn23_data + offset, |
| 19068 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19069 | offset += mb->un.varDmp.word_cnt; |
| 19070 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 19071 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19072 | mempool_free(pmb, phba->mbox_mem_pool); |
| 19073 | return offset; |
| 19074 | } |
| 19075 | |
| 19076 | /** |
| 19077 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 19078 | * @phba: pointer to lpfc hba data structure. |
| 19079 | * @rgn23_data: pointer to configure region 23 data. |
| 19080 | * |
| 19081 | * This function gets SLI4 port configure region 23 data through memory dump |
| 19082 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19083 | * will be returned, otherwise, 0 will be returned. |
| 19084 | **/ |
| 19085 | static uint32_t |
| 19086 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 19087 | { |
| 19088 | LPFC_MBOXQ_t *mboxq = NULL; |
| 19089 | struct lpfc_dmabuf *mp = NULL; |
| 19090 | struct lpfc_mqe *mqe; |
| 19091 | uint32_t data_length = 0; |
| 19092 | int rc; |
| 19093 | |
| 19094 | if (!rgn23_data) |
| 19095 | return 0; |
| 19096 | |
| 19097 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19098 | if (!mboxq) { |
| 19099 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19100 | "3105 failed to allocate mailbox memory\n"); |
| 19101 | return 0; |
| 19102 | } |
| 19103 | |
| 19104 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 19105 | goto out; |
| 19106 | mqe = &mboxq->u.mqe; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19107 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19108 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 19109 | if (rc) |
| 19110 | goto out; |
| 19111 | data_length = mqe->un.mb_words[5]; |
| 19112 | if (data_length == 0) |
| 19113 | goto out; |
| 19114 | if (data_length > DMP_RGN23_SIZE) { |
| 19115 | data_length = 0; |
| 19116 | goto out; |
| 19117 | } |
| 19118 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 19119 | out: |
| 19120 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 19121 | if (mp) { |
| 19122 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19123 | kfree(mp); |
| 19124 | } |
| 19125 | return data_length; |
| 19126 | } |
| 19127 | |
| 19128 | /** |
| 19129 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 19130 | * @phba: pointer to lpfc hba data structure. |
| 19131 | * |
| 19132 | * This function read region 23 and parse TLV for port status to |
| 19133 | * decide if the user disaled the port. If the TLV indicates the |
| 19134 | * port is disabled, the hba_flag is set accordingly. |
| 19135 | **/ |
| 19136 | void |
| 19137 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 19138 | { |
| 19139 | uint8_t *rgn23_data = NULL; |
| 19140 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 19141 | uint32_t offset = 0; |
| 19142 | |
| 19143 | /* Get adapter Region 23 data */ |
| 19144 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 19145 | if (!rgn23_data) |
| 19146 | goto out; |
| 19147 | |
| 19148 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 19149 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 19150 | else { |
| 19151 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 19152 | &phba->sli4_hba.sli_intf); |
| 19153 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 19154 | goto out; |
| 19155 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 19156 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19157 | |
| 19158 | if (!data_size) |
| 19159 | goto out; |
| 19160 | |
| 19161 | /* Check the region signature first */ |
| 19162 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 19163 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19164 | "2619 Config region 23 has bad signature\n"); |
| 19165 | goto out; |
| 19166 | } |
| 19167 | offset += 4; |
| 19168 | |
| 19169 | /* Check the data structure version */ |
| 19170 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 19171 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19172 | "2620 Config region 23 has bad version\n"); |
| 19173 | goto out; |
| 19174 | } |
| 19175 | offset += 4; |
| 19176 | |
| 19177 | /* Parse TLV entries in the region */ |
| 19178 | while (offset < data_size) { |
| 19179 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 19180 | break; |
| 19181 | /* |
| 19182 | * If the TLV is not driver specific TLV or driver id is |
| 19183 | * not linux driver id, skip the record. |
| 19184 | */ |
| 19185 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 19186 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 19187 | (rgn23_data[offset + 3] != 0)) { |
| 19188 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19189 | continue; |
| 19190 | } |
| 19191 | |
| 19192 | /* Driver found a driver specific TLV in the config region */ |
| 19193 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 19194 | offset += 4; |
| 19195 | tlv_offset = 0; |
| 19196 | |
| 19197 | /* |
| 19198 | * Search for configured port state sub-TLV. |
| 19199 | */ |
| 19200 | while ((offset < data_size) && |
| 19201 | (tlv_offset < sub_tlv_len)) { |
| 19202 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 19203 | offset += 4; |
| 19204 | tlv_offset += 4; |
| 19205 | break; |
| 19206 | } |
| 19207 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 19208 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19209 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 19210 | continue; |
| 19211 | } |
| 19212 | |
| 19213 | /* This HBA contains PORT_STE configured */ |
| 19214 | if (!rgn23_data[offset + 2]) |
| 19215 | phba->hba_flag |= LINK_DISABLED; |
| 19216 | |
| 19217 | goto out; |
| 19218 | } |
| 19219 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19220 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19221 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19222 | kfree(rgn23_data); |
| 19223 | return; |
| 19224 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19225 | |
| 19226 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19227 | * lpfc_wr_object - write an object to the firmware |
| 19228 | * @phba: HBA structure that indicates port to create a queue on. |
| 19229 | * @dmabuf_list: list of dmabufs to write to the port. |
| 19230 | * @size: the total byte value of the objects to write to the port. |
| 19231 | * @offset: the current offset to be used to start the transfer. |
| 19232 | * |
| 19233 | * This routine will create a wr_object mailbox command to send to the port. |
| 19234 | * the mailbox command will be constructed using the dma buffers described in |
| 19235 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 19236 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 19237 | * used to indicate the starting offset of the transfer and will also return |
| 19238 | * the offset after the write object mailbox has completed. @size is used to |
| 19239 | * determine the end of the object and whether the eof bit should be set. |
| 19240 | * |
| 19241 | * Return 0 is successful and offset will contain the the new offset to use |
| 19242 | * for the next write. |
| 19243 | * Return negative value for error cases. |
| 19244 | **/ |
| 19245 | int |
| 19246 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 19247 | uint32_t size, uint32_t *offset) |
| 19248 | { |
| 19249 | struct lpfc_mbx_wr_object *wr_object; |
| 19250 | LPFC_MBOXQ_t *mbox; |
| 19251 | int rc = 0, i = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19252 | uint32_t shdr_status, shdr_add_status, shdr_change_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19253 | uint32_t mbox_tmo; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19254 | struct lpfc_dmabuf *dmabuf; |
| 19255 | uint32_t written = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19256 | bool check_change_status = false; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19257 | |
| 19258 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19259 | if (!mbox) |
| 19260 | return -ENOMEM; |
| 19261 | |
| 19262 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 19263 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 19264 | sizeof(struct lpfc_mbx_wr_object) - |
| 19265 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 19266 | |
| 19267 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 19268 | wr_object->u.request.write_offset = *offset; |
| 19269 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 19270 | wr_object->u.request.object_name[0] = |
| 19271 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 19272 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 19273 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 19274 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 19275 | break; |
| 19276 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 19277 | wr_object->u.request.bde[i].addrHigh = |
| 19278 | putPaddrHigh(dmabuf->phys); |
| 19279 | if (written + SLI4_PAGE_SIZE >= size) { |
| 19280 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19281 | (size - written); |
| 19282 | written += (size - written); |
| 19283 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19284 | bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1); |
| 19285 | check_change_status = true; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19286 | } else { |
| 19287 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19288 | SLI4_PAGE_SIZE; |
| 19289 | written += SLI4_PAGE_SIZE; |
| 19290 | } |
| 19291 | i++; |
| 19292 | } |
| 19293 | wr_object->u.request.bde_count = i; |
| 19294 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 19295 | if (!phba->sli4_hba.intr_enable) |
| 19296 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 19297 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 19298 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19299 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 19300 | } |
| 19301 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19302 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 19303 | &wr_object->header.cfg_shdr.response); |
| 19304 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 19305 | &wr_object->header.cfg_shdr.response); |
| 19306 | if (check_change_status) { |
| 19307 | shdr_change_status = bf_get(lpfc_wr_object_change_status, |
| 19308 | &wr_object->u.response); |
| 19309 | switch (shdr_change_status) { |
| 19310 | case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET): |
| 19311 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19312 | "3198 Firmware write complete: System " |
| 19313 | "reboot required to instantiate\n"); |
| 19314 | break; |
| 19315 | case (LPFC_CHANGE_STATUS_FW_RESET): |
| 19316 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19317 | "3199 Firmware write complete: Firmware" |
| 19318 | " reset required to instantiate\n"); |
| 19319 | break; |
| 19320 | case (LPFC_CHANGE_STATUS_PORT_MIGRATION): |
| 19321 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19322 | "3200 Firmware write complete: Port " |
| 19323 | "Migration or PCI Reset required to " |
| 19324 | "instantiate\n"); |
| 19325 | break; |
| 19326 | case (LPFC_CHANGE_STATUS_PCI_RESET): |
| 19327 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19328 | "3201 Firmware write complete: PCI " |
| 19329 | "Reset required to instantiate\n"); |
| 19330 | break; |
| 19331 | default: |
| 19332 | break; |
| 19333 | } |
| 19334 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19335 | if (rc != MBX_TIMEOUT) |
| 19336 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19337 | if (shdr_status || shdr_add_status || rc) { |
| 19338 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19339 | "3025 Write Object mailbox failed with " |
| 19340 | "status x%x add_status x%x, mbx status x%x\n", |
| 19341 | shdr_status, shdr_add_status, rc); |
| 19342 | rc = -ENXIO; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 19343 | *offset = shdr_add_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19344 | } else |
| 19345 | *offset += wr_object->u.response.actual_write_length; |
| 19346 | return rc; |
| 19347 | } |
| 19348 | |
| 19349 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19350 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 19351 | * @vport: pointer to vport data structure. |
| 19352 | * |
| 19353 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 19354 | * and REG_VPI mailbox commands associated with the vport. This function |
| 19355 | * is called when driver want to restart discovery of the vport due to |
| 19356 | * a Clear Virtual Link event. |
| 19357 | **/ |
| 19358 | void |
| 19359 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 19360 | { |
| 19361 | struct lpfc_hba *phba = vport->phba; |
| 19362 | LPFC_MBOXQ_t *mb, *nextmb; |
| 19363 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19364 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19365 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19366 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19367 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19368 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19369 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19370 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19371 | spin_lock_irq(&phba->hbalock); |
| 19372 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 19373 | if (mb->vport != vport) |
| 19374 | continue; |
| 19375 | |
| 19376 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19377 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19378 | continue; |
| 19379 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19380 | list_del(&mb->list); |
| 19381 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 19382 | } |
| 19383 | /* Clean up active mailbox command with the vport */ |
| 19384 | mb = phba->sli.mbox_active; |
| 19385 | if (mb && (mb->vport == vport)) { |
| 19386 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 19387 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 19388 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19389 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19390 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19391 | /* Put reference count for delayed processing */ |
| 19392 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 19393 | /* Unregister the RPI when mailbox complete */ |
| 19394 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19395 | } |
| 19396 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19397 | /* Cleanup any mailbox completions which are not yet processed */ |
| 19398 | do { |
| 19399 | restart_loop = 0; |
| 19400 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 19401 | /* |
| 19402 | * If this mailox is already processed or it is |
| 19403 | * for another vport ignore it. |
| 19404 | */ |
| 19405 | if ((mb->vport != vport) || |
| 19406 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 19407 | continue; |
| 19408 | |
| 19409 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19410 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19411 | continue; |
| 19412 | |
| 19413 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19414 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19415 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19416 | /* Unregister the RPI when mailbox complete */ |
| 19417 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19418 | restart_loop = 1; |
| 19419 | spin_unlock_irq(&phba->hbalock); |
| 19420 | spin_lock(shost->host_lock); |
| 19421 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19422 | spin_unlock(shost->host_lock); |
| 19423 | spin_lock_irq(&phba->hbalock); |
| 19424 | break; |
| 19425 | } |
| 19426 | } |
| 19427 | } while (restart_loop); |
| 19428 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19429 | spin_unlock_irq(&phba->hbalock); |
| 19430 | |
| 19431 | /* Release the cleaned-up mailbox commands */ |
| 19432 | while (!list_empty(&mbox_cmd_list)) { |
| 19433 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19434 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19435 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19436 | if (mp) { |
| 19437 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19438 | kfree(mp); |
| 19439 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19440 | mb->ctx_buf = NULL; |
| 19441 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
| 19442 | mb->ctx_ndlp = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19443 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19444 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19445 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19446 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19447 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19448 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19449 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19450 | mempool_free(mb, phba->mbox_mem_pool); |
| 19451 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19452 | |
| 19453 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 19454 | if (act_mbx_ndlp) { |
| 19455 | spin_lock(shost->host_lock); |
| 19456 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19457 | spin_unlock(shost->host_lock); |
| 19458 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19459 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19460 | } |
| 19461 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19462 | /** |
| 19463 | * lpfc_drain_txq - Drain the txq |
| 19464 | * @phba: Pointer to HBA context object. |
| 19465 | * |
| 19466 | * This function attempt to submit IOCBs on the txq |
| 19467 | * to the adapter. For SLI4 adapters, the txq contains |
| 19468 | * ELS IOCBs that have been deferred because the there |
| 19469 | * are no SGLs. This congestion can occur with large |
| 19470 | * vport counts during node discovery. |
| 19471 | **/ |
| 19472 | |
| 19473 | uint32_t |
| 19474 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 19475 | { |
| 19476 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19477 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 19478 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19479 | unsigned long iflags = 0; |
| 19480 | char *fail_msg = NULL; |
| 19481 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19482 | union lpfc_wqe128 wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 19483 | uint32_t txq_cnt = 0; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19484 | struct lpfc_queue *wq; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19485 | |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19486 | if (phba->link_flag & LS_MDS_LOOPBACK) { |
| 19487 | /* MDS WQE are posted only to first WQ*/ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19488 | wq = phba->sli4_hba.hdwq[0].io_wq; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19489 | if (unlikely(!wq)) |
| 19490 | return 0; |
| 19491 | pring = wq->pring; |
| 19492 | } else { |
| 19493 | wq = phba->sli4_hba.els_wq; |
| 19494 | if (unlikely(!wq)) |
| 19495 | return 0; |
| 19496 | pring = lpfc_phba_elsring(phba); |
| 19497 | } |
| 19498 | |
| 19499 | if (unlikely(!pring) || list_empty(&pring->txq)) |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 19500 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19501 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19502 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19503 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 19504 | txq_cnt++; |
| 19505 | } |
| 19506 | |
| 19507 | if (txq_cnt > pring->txq_max) |
| 19508 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19509 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19510 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19511 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19512 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19513 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19514 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19515 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19516 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19517 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19518 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19519 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19520 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19521 | break; |
| 19522 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19523 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19524 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19525 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19526 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19527 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19528 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19529 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19530 | |
| 19531 | /* The xri and iocb resources secured, |
| 19532 | * attempt to issue request |
| 19533 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19534 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19535 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 19536 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 19537 | fail_msg = "to convert bpl to sgl"; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19538 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19539 | fail_msg = "to convert iocb to wqe"; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19540 | else if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19541 | fail_msg = " - Wq is full"; |
| 19542 | else |
| 19543 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 19544 | |
| 19545 | if (fail_msg) { |
| 19546 | /* Failed means we can't issue and need to cancel */ |
| 19547 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19548 | "2822 IOCB failed %s iotag 0x%x " |
| 19549 | "xri 0x%x\n", |
| 19550 | fail_msg, |
| 19551 | piocbq->iotag, piocbq->sli4_xritag); |
| 19552 | list_add_tail(&piocbq->list, &completions); |
| 19553 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19554 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19555 | } |
| 19556 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19557 | /* Cancel all the IOCBs that cannot be issued */ |
| 19558 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 19559 | IOERR_SLI_ABORTED); |
| 19560 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19561 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19562 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19563 | |
| 19564 | /** |
| 19565 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 19566 | * @phba: Pointer to HBA context object. |
| 19567 | * @pwqe: Pointer to command WQE. |
| 19568 | * @sglq: Pointer to the scatter gather queue object. |
| 19569 | * |
| 19570 | * This routine converts the bpl or bde that is in the WQE |
| 19571 | * to a sgl list for the sli4 hardware. The physical address |
| 19572 | * of the bpl/bde is converted back to a virtual address. |
| 19573 | * If the WQE contains a BPL then the list of BDE's is |
| 19574 | * converted to sli4_sge's. If the WQE contains a single |
| 19575 | * BDE then it is converted to a single sli_sge. |
| 19576 | * The WQE is still in cpu endianness so the contents of |
| 19577 | * the bpl can be used without byte swapping. |
| 19578 | * |
| 19579 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 19580 | */ |
| 19581 | static uint16_t |
| 19582 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 19583 | struct lpfc_sglq *sglq) |
| 19584 | { |
| 19585 | uint16_t xritag = NO_XRI; |
| 19586 | struct ulp_bde64 *bpl = NULL; |
| 19587 | struct ulp_bde64 bde; |
| 19588 | struct sli4_sge *sgl = NULL; |
| 19589 | struct lpfc_dmabuf *dmabuf; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19590 | union lpfc_wqe128 *wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19591 | int numBdes = 0; |
| 19592 | int i = 0; |
| 19593 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 19594 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 19595 | uint32_t cmd; |
| 19596 | |
| 19597 | if (!pwqeq || !sglq) |
| 19598 | return xritag; |
| 19599 | |
| 19600 | sgl = (struct sli4_sge *)sglq->sgl; |
| 19601 | wqe = &pwqeq->wqe; |
| 19602 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 19603 | |
| 19604 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 19605 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 19606 | return sglq->sli4_xritag; |
| 19607 | numBdes = pwqeq->rsvd2; |
| 19608 | if (numBdes) { |
| 19609 | /* The addrHigh and addrLow fields within the WQE |
| 19610 | * have not been byteswapped yet so there is no |
| 19611 | * need to swap them back. |
| 19612 | */ |
| 19613 | if (pwqeq->context3) |
| 19614 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 19615 | else |
| 19616 | return xritag; |
| 19617 | |
| 19618 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 19619 | if (!bpl) |
| 19620 | return xritag; |
| 19621 | |
| 19622 | for (i = 0; i < numBdes; i++) { |
| 19623 | /* Should already be byte swapped. */ |
| 19624 | sgl->addr_hi = bpl->addrHigh; |
| 19625 | sgl->addr_lo = bpl->addrLow; |
| 19626 | |
| 19627 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19628 | if ((i+1) == numBdes) |
| 19629 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19630 | else |
| 19631 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 19632 | /* swap the size field back to the cpu so we |
| 19633 | * can assign it to the sgl. |
| 19634 | */ |
| 19635 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 19636 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 19637 | /* The offsets in the sgl need to be accumulated |
| 19638 | * separately for the request and reply lists. |
| 19639 | * The request is always first, the reply follows. |
| 19640 | */ |
| 19641 | switch (cmd) { |
| 19642 | case CMD_GEN_REQUEST64_WQE: |
| 19643 | /* add up the reply sg entries */ |
| 19644 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 19645 | inbound++; |
| 19646 | /* first inbound? reset the offset */ |
| 19647 | if (inbound == 1) |
| 19648 | offset = 0; |
| 19649 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19650 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19651 | LPFC_SGE_TYPE_DATA); |
| 19652 | offset += bde.tus.f.bdeSize; |
| 19653 | break; |
| 19654 | case CMD_FCP_TRSP64_WQE: |
| 19655 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 19656 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19657 | LPFC_SGE_TYPE_DATA); |
| 19658 | break; |
| 19659 | case CMD_FCP_TSEND64_WQE: |
| 19660 | case CMD_FCP_TRECEIVE64_WQE: |
| 19661 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19662 | bpl->tus.f.bdeFlags); |
| 19663 | if (i < 3) |
| 19664 | offset = 0; |
| 19665 | else |
| 19666 | offset += bde.tus.f.bdeSize; |
| 19667 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19668 | break; |
| 19669 | } |
| 19670 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19671 | bpl++; |
| 19672 | sgl++; |
| 19673 | } |
| 19674 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 19675 | /* The addrHigh and addrLow fields of the BDE have not |
| 19676 | * been byteswapped yet so they need to be swapped |
| 19677 | * before putting them in the sgl. |
| 19678 | */ |
| 19679 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 19680 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 19681 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19682 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19683 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19684 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 19685 | } |
| 19686 | return sglq->sli4_xritag; |
| 19687 | } |
| 19688 | |
| 19689 | /** |
| 19690 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 19691 | * @phba: Pointer to HBA context object. |
| 19692 | * @ring_number: Base sli ring number |
| 19693 | * @pwqe: Pointer to command WQE. |
| 19694 | **/ |
| 19695 | int |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19696 | 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] | 19697 | struct lpfc_iocbq *pwqe) |
| 19698 | { |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19699 | union lpfc_wqe128 *wqe = &pwqe->wqe; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19700 | struct lpfc_nvmet_rcv_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19701 | struct lpfc_queue *wq; |
| 19702 | struct lpfc_sglq *sglq; |
| 19703 | struct lpfc_sli_ring *pring; |
| 19704 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19705 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19706 | |
| 19707 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 19708 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 19709 | pring = phba->sli4_hba.nvmels_wq->pring; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19710 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19711 | qp, wq_access); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19712 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 19713 | if (!sglq) { |
| 19714 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19715 | return WQE_BUSY; |
| 19716 | } |
| 19717 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19718 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19719 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 19720 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19721 | return WQE_ERROR; |
| 19722 | } |
| 19723 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19724 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19725 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 19726 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19727 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19728 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19729 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19730 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19731 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19732 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19733 | return 0; |
| 19734 | } |
| 19735 | |
| 19736 | /* NVME_FCREQ and NVME_ABTS requests */ |
| 19737 | if (pwqe->iocb_flag & LPFC_IO_NVME) { |
| 19738 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19739 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19740 | pring = wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19741 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19742 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19743 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19744 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19745 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19746 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19747 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19748 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19749 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19750 | } |
| 19751 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19752 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19753 | return 0; |
| 19754 | } |
| 19755 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19756 | /* NVMET requests */ |
| 19757 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 19758 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19759 | wq = qp->io_wq; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19760 | pring = wq->pring; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19761 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19762 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 19763 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19764 | if (pwqe->sli4_xritag == NO_XRI) { |
| 19765 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19766 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19767 | } |
| 19768 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19769 | pwqe->sli4_xritag); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19770 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map); |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19771 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19772 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19773 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19774 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19775 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19776 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19777 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19778 | } |
| 19779 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19780 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19781 | return 0; |
| 19782 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19783 | return WQE_ERROR; |
| 19784 | } |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19785 | |
| 19786 | #ifdef LPFC_MXP_STAT |
| 19787 | /** |
| 19788 | * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count |
| 19789 | * @phba: pointer to lpfc hba data structure. |
| 19790 | * @hwqid: belong to which HWQ. |
| 19791 | * |
| 19792 | * The purpose of this routine is to take a snapshot of pbl, pvt and busy count |
| 19793 | * 15 seconds after a test case is running. |
| 19794 | * |
| 19795 | * The user should call lpfc_debugfs_multixripools_write before running a test |
| 19796 | * case to clear stat_snapshot_taken. Then the user starts a test case. During |
| 19797 | * test case is running, stat_snapshot_taken is incremented by 1 every time when |
| 19798 | * this routine is called from heartbeat timer. When stat_snapshot_taken is |
| 19799 | * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken. |
| 19800 | **/ |
| 19801 | void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid) |
| 19802 | { |
| 19803 | struct lpfc_sli4_hdw_queue *qp; |
| 19804 | struct lpfc_multixri_pool *multixri_pool; |
| 19805 | struct lpfc_pvt_pool *pvt_pool; |
| 19806 | struct lpfc_pbl_pool *pbl_pool; |
| 19807 | u32 txcmplq_cnt; |
| 19808 | |
| 19809 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 19810 | multixri_pool = qp->p_multixri_pool; |
| 19811 | if (!multixri_pool) |
| 19812 | return; |
| 19813 | |
| 19814 | if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) { |
| 19815 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 19816 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19817 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19818 | |
| 19819 | multixri_pool->stat_pbl_count = pbl_pool->count; |
| 19820 | multixri_pool->stat_pvt_count = pvt_pool->count; |
| 19821 | multixri_pool->stat_busy_count = txcmplq_cnt; |
| 19822 | } |
| 19823 | |
| 19824 | multixri_pool->stat_snapshot_taken++; |
| 19825 | } |
| 19826 | #endif |
| 19827 | |
| 19828 | /** |
| 19829 | * lpfc_adjust_pvt_pool_count - Adjust private pool count |
| 19830 | * @phba: pointer to lpfc hba data structure. |
| 19831 | * @hwqid: belong to which HWQ. |
| 19832 | * |
| 19833 | * This routine moves some XRIs from private to public pool when private pool |
| 19834 | * is not busy. |
| 19835 | **/ |
| 19836 | void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid) |
| 19837 | { |
| 19838 | struct lpfc_multixri_pool *multixri_pool; |
| 19839 | u32 io_req_count; |
| 19840 | u32 prev_io_req_count; |
| 19841 | |
| 19842 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 19843 | if (!multixri_pool) |
| 19844 | return; |
| 19845 | io_req_count = multixri_pool->io_req_count; |
| 19846 | prev_io_req_count = multixri_pool->prev_io_req_count; |
| 19847 | |
| 19848 | if (prev_io_req_count != io_req_count) { |
| 19849 | /* Private pool is busy */ |
| 19850 | multixri_pool->prev_io_req_count = io_req_count; |
| 19851 | } else { |
| 19852 | /* Private pool is not busy. |
| 19853 | * Move XRIs from private to public pool. |
| 19854 | */ |
| 19855 | lpfc_move_xri_pvt_to_pbl(phba, hwqid); |
| 19856 | } |
| 19857 | } |
| 19858 | |
| 19859 | /** |
| 19860 | * lpfc_adjust_high_watermark - Adjust high watermark |
| 19861 | * @phba: pointer to lpfc hba data structure. |
| 19862 | * @hwqid: belong to which HWQ. |
| 19863 | * |
| 19864 | * This routine sets high watermark as number of outstanding XRIs, |
| 19865 | * but make sure the new value is between xri_limit/2 and xri_limit. |
| 19866 | **/ |
| 19867 | void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid) |
| 19868 | { |
| 19869 | u32 new_watermark; |
| 19870 | u32 watermark_max; |
| 19871 | u32 watermark_min; |
| 19872 | u32 xri_limit; |
| 19873 | u32 txcmplq_cnt; |
| 19874 | u32 abts_io_bufs; |
| 19875 | struct lpfc_multixri_pool *multixri_pool; |
| 19876 | struct lpfc_sli4_hdw_queue *qp; |
| 19877 | |
| 19878 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 19879 | multixri_pool = qp->p_multixri_pool; |
| 19880 | if (!multixri_pool) |
| 19881 | return; |
| 19882 | xri_limit = multixri_pool->xri_limit; |
| 19883 | |
| 19884 | watermark_max = xri_limit; |
| 19885 | watermark_min = xri_limit / 2; |
| 19886 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19887 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19888 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 19889 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19890 | |
| 19891 | new_watermark = txcmplq_cnt + abts_io_bufs; |
| 19892 | new_watermark = min(watermark_max, new_watermark); |
| 19893 | new_watermark = max(watermark_min, new_watermark); |
| 19894 | multixri_pool->pvt_pool.high_watermark = new_watermark; |
| 19895 | |
| 19896 | #ifdef LPFC_MXP_STAT |
| 19897 | multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm, |
| 19898 | new_watermark); |
| 19899 | #endif |
| 19900 | } |
| 19901 | |
| 19902 | /** |
| 19903 | * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool |
| 19904 | * @phba: pointer to lpfc hba data structure. |
| 19905 | * @hwqid: belong to which HWQ. |
| 19906 | * |
| 19907 | * This routine is called from hearbeat timer when pvt_pool is idle. |
| 19908 | * All free XRIs are moved from private to public pool on hwqid with 2 steps. |
| 19909 | * The first step moves (all - low_watermark) amount of XRIs. |
| 19910 | * The second step moves the rest of XRIs. |
| 19911 | **/ |
| 19912 | void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid) |
| 19913 | { |
| 19914 | struct lpfc_pbl_pool *pbl_pool; |
| 19915 | struct lpfc_pvt_pool *pvt_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19916 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19917 | struct lpfc_io_buf *lpfc_ncmd; |
| 19918 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 19919 | unsigned long iflag; |
| 19920 | struct list_head tmp_list; |
| 19921 | u32 tmp_count; |
| 19922 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19923 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 19924 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 19925 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19926 | tmp_count = 0; |
| 19927 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19928 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool); |
| 19929 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19930 | |
| 19931 | if (pvt_pool->count > pvt_pool->low_watermark) { |
| 19932 | /* Step 1: move (all - low_watermark) from pvt_pool |
| 19933 | * to pbl_pool |
| 19934 | */ |
| 19935 | |
| 19936 | /* Move low watermark of bufs from pvt_pool to tmp_list */ |
| 19937 | INIT_LIST_HEAD(&tmp_list); |
| 19938 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 19939 | &pvt_pool->list, list) { |
| 19940 | list_move_tail(&lpfc_ncmd->list, &tmp_list); |
| 19941 | tmp_count++; |
| 19942 | if (tmp_count >= pvt_pool->low_watermark) |
| 19943 | break; |
| 19944 | } |
| 19945 | |
| 19946 | /* Move all bufs from pvt_pool to pbl_pool */ |
| 19947 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 19948 | |
| 19949 | /* Move all bufs from tmp_list to pvt_pool */ |
| 19950 | list_splice(&tmp_list, &pvt_pool->list); |
| 19951 | |
| 19952 | pbl_pool->count += (pvt_pool->count - tmp_count); |
| 19953 | pvt_pool->count = tmp_count; |
| 19954 | } else { |
| 19955 | /* Step 2: move the rest from pvt_pool to pbl_pool */ |
| 19956 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 19957 | pbl_pool->count += pvt_pool->count; |
| 19958 | pvt_pool->count = 0; |
| 19959 | } |
| 19960 | |
| 19961 | spin_unlock(&pvt_pool->lock); |
| 19962 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 19963 | } |
| 19964 | |
| 19965 | /** |
| 19966 | * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 19967 | * @phba: pointer to lpfc hba data structure |
| 19968 | * @pbl_pool: specified public free XRI pool |
| 19969 | * @pvt_pool: specified private free XRI pool |
| 19970 | * @count: number of XRIs to move |
| 19971 | * |
| 19972 | * This routine tries to move some free common bufs from the specified pbl_pool |
| 19973 | * to the specified pvt_pool. It might move less than count XRIs if there's not |
| 19974 | * enough in public pool. |
| 19975 | * |
| 19976 | * Return: |
| 19977 | * true - if XRIs are successfully moved from the specified pbl_pool to the |
| 19978 | * specified pvt_pool |
| 19979 | * false - if the specified pbl_pool is empty or locked by someone else |
| 19980 | **/ |
| 19981 | static bool |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19982 | _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp, |
| 19983 | struct lpfc_pbl_pool *pbl_pool, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19984 | struct lpfc_pvt_pool *pvt_pool, u32 count) |
| 19985 | { |
| 19986 | struct lpfc_io_buf *lpfc_ncmd; |
| 19987 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 19988 | unsigned long iflag; |
| 19989 | int ret; |
| 19990 | |
| 19991 | ret = spin_trylock_irqsave(&pbl_pool->lock, iflag); |
| 19992 | if (ret) { |
| 19993 | if (pbl_pool->count) { |
| 19994 | /* Move a batch of XRIs from public to private pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19995 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19996 | list_for_each_entry_safe(lpfc_ncmd, |
| 19997 | lpfc_ncmd_next, |
| 19998 | &pbl_pool->list, |
| 19999 | list) { |
| 20000 | list_move_tail(&lpfc_ncmd->list, |
| 20001 | &pvt_pool->list); |
| 20002 | pvt_pool->count++; |
| 20003 | pbl_pool->count--; |
| 20004 | count--; |
| 20005 | if (count == 0) |
| 20006 | break; |
| 20007 | } |
| 20008 | |
| 20009 | spin_unlock(&pvt_pool->lock); |
| 20010 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20011 | return true; |
| 20012 | } |
| 20013 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20014 | } |
| 20015 | |
| 20016 | return false; |
| 20017 | } |
| 20018 | |
| 20019 | /** |
| 20020 | * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 20021 | * @phba: pointer to lpfc hba data structure. |
| 20022 | * @hwqid: belong to which HWQ. |
| 20023 | * @count: number of XRIs to move |
| 20024 | * |
| 20025 | * This routine tries to find some free common bufs in one of public pools with |
| 20026 | * Round Robin method. The search always starts from local hwqid, then the next |
| 20027 | * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found, |
| 20028 | * a batch of free common bufs are moved to private pool on hwqid. |
| 20029 | * It might move less than count XRIs if there's not enough in public pool. |
| 20030 | **/ |
| 20031 | void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count) |
| 20032 | { |
| 20033 | struct lpfc_multixri_pool *multixri_pool; |
| 20034 | struct lpfc_multixri_pool *next_multixri_pool; |
| 20035 | struct lpfc_pvt_pool *pvt_pool; |
| 20036 | struct lpfc_pbl_pool *pbl_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20037 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20038 | u32 next_hwqid; |
| 20039 | u32 hwq_count; |
| 20040 | int ret; |
| 20041 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20042 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20043 | multixri_pool = qp->p_multixri_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20044 | pvt_pool = &multixri_pool->pvt_pool; |
| 20045 | pbl_pool = &multixri_pool->pbl_pool; |
| 20046 | |
| 20047 | /* Check if local pbl_pool is available */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20048 | 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] | 20049 | if (ret) { |
| 20050 | #ifdef LPFC_MXP_STAT |
| 20051 | multixri_pool->local_pbl_hit_count++; |
| 20052 | #endif |
| 20053 | return; |
| 20054 | } |
| 20055 | |
| 20056 | hwq_count = phba->cfg_hdw_queue; |
| 20057 | |
| 20058 | /* Get the next hwqid which was found last time */ |
| 20059 | next_hwqid = multixri_pool->rrb_next_hwqid; |
| 20060 | |
| 20061 | do { |
| 20062 | /* Go to next hwq */ |
| 20063 | next_hwqid = (next_hwqid + 1) % hwq_count; |
| 20064 | |
| 20065 | next_multixri_pool = |
| 20066 | phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool; |
| 20067 | pbl_pool = &next_multixri_pool->pbl_pool; |
| 20068 | |
| 20069 | /* Check if the public free xri pool is available */ |
| 20070 | ret = _lpfc_move_xri_pbl_to_pvt( |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20071 | phba, qp, pbl_pool, pvt_pool, count); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20072 | |
| 20073 | /* Exit while-loop if success or all hwqid are checked */ |
| 20074 | } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid); |
| 20075 | |
| 20076 | /* Starting point for the next time */ |
| 20077 | multixri_pool->rrb_next_hwqid = next_hwqid; |
| 20078 | |
| 20079 | if (!ret) { |
| 20080 | /* stats: all public pools are empty*/ |
| 20081 | multixri_pool->pbl_empty_count++; |
| 20082 | } |
| 20083 | |
| 20084 | #ifdef LPFC_MXP_STAT |
| 20085 | if (ret) { |
| 20086 | if (next_hwqid == hwqid) |
| 20087 | multixri_pool->local_pbl_hit_count++; |
| 20088 | else |
| 20089 | multixri_pool->other_pbl_hit_count++; |
| 20090 | } |
| 20091 | #endif |
| 20092 | } |
| 20093 | |
| 20094 | /** |
| 20095 | * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark |
| 20096 | * @phba: pointer to lpfc hba data structure. |
| 20097 | * @qp: belong to which HWQ. |
| 20098 | * |
| 20099 | * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than |
| 20100 | * low watermark. |
| 20101 | **/ |
| 20102 | void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid) |
| 20103 | { |
| 20104 | struct lpfc_multixri_pool *multixri_pool; |
| 20105 | struct lpfc_pvt_pool *pvt_pool; |
| 20106 | |
| 20107 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 20108 | pvt_pool = &multixri_pool->pvt_pool; |
| 20109 | |
| 20110 | if (pvt_pool->count < pvt_pool->low_watermark) |
| 20111 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20112 | } |
| 20113 | |
| 20114 | /** |
| 20115 | * lpfc_release_io_buf - Return one IO buf back to free pool |
| 20116 | * @phba: pointer to lpfc hba data structure. |
| 20117 | * @lpfc_ncmd: IO buf to be returned. |
| 20118 | * @qp: belong to which HWQ. |
| 20119 | * |
| 20120 | * This routine returns one IO buf back to free pool. If this is an urgent IO, |
| 20121 | * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1, |
| 20122 | * the IO buf is returned to pbl_pool or pvt_pool based on watermark and |
| 20123 | * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to |
| 20124 | * lpfc_io_buf_list_put. |
| 20125 | **/ |
| 20126 | void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd, |
| 20127 | struct lpfc_sli4_hdw_queue *qp) |
| 20128 | { |
| 20129 | unsigned long iflag; |
| 20130 | struct lpfc_pbl_pool *pbl_pool; |
| 20131 | struct lpfc_pvt_pool *pvt_pool; |
| 20132 | struct lpfc_epd_pool *epd_pool; |
| 20133 | u32 txcmplq_cnt; |
| 20134 | u32 xri_owned; |
| 20135 | u32 xri_limit; |
| 20136 | u32 abts_io_bufs; |
| 20137 | |
| 20138 | /* MUST zero fields if buffer is reused by another protocol */ |
| 20139 | lpfc_ncmd->nvmeCmd = NULL; |
| 20140 | lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL; |
| 20141 | lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL; |
| 20142 | |
James Smart | 35a635a | 2019-09-21 20:59:02 -0700 | [diff] [blame] | 20143 | if (phba->cfg_xpsgl && !phba->nvmet_support && |
| 20144 | !list_empty(&lpfc_ncmd->dma_sgl_xtra_list)) |
| 20145 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 20146 | |
| 20147 | if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list)) |
| 20148 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
| 20149 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20150 | if (phba->cfg_xri_rebalancing) { |
| 20151 | if (lpfc_ncmd->expedite) { |
| 20152 | /* Return to expedite pool */ |
| 20153 | epd_pool = &phba->epd_pool; |
| 20154 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20155 | list_add_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 20156 | epd_pool->count++; |
| 20157 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20158 | return; |
| 20159 | } |
| 20160 | |
| 20161 | /* Avoid invalid access if an IO sneaks in and is being rejected |
| 20162 | * just _after_ xri pools are destroyed in lpfc_offline. |
| 20163 | * Nothing much can be done at this point. |
| 20164 | */ |
| 20165 | if (!qp->p_multixri_pool) |
| 20166 | return; |
| 20167 | |
| 20168 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 20169 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 20170 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20171 | txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20172 | abts_io_bufs = qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 20173 | abts_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20174 | |
| 20175 | xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs; |
| 20176 | xri_limit = qp->p_multixri_pool->xri_limit; |
| 20177 | |
| 20178 | #ifdef LPFC_MXP_STAT |
| 20179 | if (xri_owned <= xri_limit) |
| 20180 | qp->p_multixri_pool->below_limit_count++; |
| 20181 | else |
| 20182 | qp->p_multixri_pool->above_limit_count++; |
| 20183 | #endif |
| 20184 | |
| 20185 | /* XRI goes to either public or private free xri pool |
| 20186 | * based on watermark and xri_limit |
| 20187 | */ |
| 20188 | if ((pvt_pool->count < pvt_pool->low_watermark) || |
| 20189 | (xri_owned < xri_limit && |
| 20190 | pvt_pool->count < pvt_pool->high_watermark)) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20191 | lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, |
| 20192 | qp, free_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20193 | list_add_tail(&lpfc_ncmd->list, |
| 20194 | &pvt_pool->list); |
| 20195 | pvt_pool->count++; |
| 20196 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20197 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20198 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, |
| 20199 | qp, free_pub_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20200 | list_add_tail(&lpfc_ncmd->list, |
| 20201 | &pbl_pool->list); |
| 20202 | pbl_pool->count++; |
| 20203 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20204 | } |
| 20205 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20206 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag, |
| 20207 | qp, free_xri); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20208 | list_add_tail(&lpfc_ncmd->list, |
| 20209 | &qp->lpfc_io_buf_list_put); |
| 20210 | qp->put_io_bufs++; |
| 20211 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, |
| 20212 | iflag); |
| 20213 | } |
| 20214 | } |
| 20215 | |
| 20216 | /** |
| 20217 | * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool |
| 20218 | * @phba: pointer to lpfc hba data structure. |
| 20219 | * @pvt_pool: pointer to private pool data structure. |
| 20220 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20221 | * |
| 20222 | * This routine tries to get one free IO buf from private pool. |
| 20223 | * |
| 20224 | * Return: |
| 20225 | * pointer to one free IO buf - if private pool is not empty |
| 20226 | * NULL - if private pool is empty |
| 20227 | **/ |
| 20228 | static struct lpfc_io_buf * |
| 20229 | lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20230 | struct lpfc_sli4_hdw_queue *qp, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20231 | struct lpfc_pvt_pool *pvt_pool, |
| 20232 | struct lpfc_nodelist *ndlp) |
| 20233 | { |
| 20234 | struct lpfc_io_buf *lpfc_ncmd; |
| 20235 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20236 | unsigned long iflag; |
| 20237 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20238 | 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] | 20239 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20240 | &pvt_pool->list, list) { |
| 20241 | if (lpfc_test_rrq_active( |
| 20242 | phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag)) |
| 20243 | continue; |
| 20244 | list_del(&lpfc_ncmd->list); |
| 20245 | pvt_pool->count--; |
| 20246 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20247 | return lpfc_ncmd; |
| 20248 | } |
| 20249 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20250 | |
| 20251 | return NULL; |
| 20252 | } |
| 20253 | |
| 20254 | /** |
| 20255 | * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool |
| 20256 | * @phba: pointer to lpfc hba data structure. |
| 20257 | * |
| 20258 | * This routine tries to get one free IO buf from expedite pool. |
| 20259 | * |
| 20260 | * Return: |
| 20261 | * pointer to one free IO buf - if expedite pool is not empty |
| 20262 | * NULL - if expedite pool is empty |
| 20263 | **/ |
| 20264 | static struct lpfc_io_buf * |
| 20265 | lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba) |
| 20266 | { |
| 20267 | struct lpfc_io_buf *lpfc_ncmd; |
| 20268 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20269 | unsigned long iflag; |
| 20270 | struct lpfc_epd_pool *epd_pool; |
| 20271 | |
| 20272 | epd_pool = &phba->epd_pool; |
| 20273 | lpfc_ncmd = NULL; |
| 20274 | |
| 20275 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20276 | if (epd_pool->count > 0) { |
| 20277 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20278 | &epd_pool->list, list) { |
| 20279 | list_del(&lpfc_ncmd->list); |
| 20280 | epd_pool->count--; |
| 20281 | break; |
| 20282 | } |
| 20283 | } |
| 20284 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20285 | |
| 20286 | return lpfc_ncmd; |
| 20287 | } |
| 20288 | |
| 20289 | /** |
| 20290 | * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs |
| 20291 | * @phba: pointer to lpfc hba data structure. |
| 20292 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20293 | * @hwqid: belong to which HWQ |
| 20294 | * @expedite: 1 means this request is urgent. |
| 20295 | * |
| 20296 | * This routine will do the following actions and then return a pointer to |
| 20297 | * one free IO buf. |
| 20298 | * |
| 20299 | * 1. If private free xri count is empty, move some XRIs from public to |
| 20300 | * private pool. |
| 20301 | * 2. Get one XRI from private free xri pool. |
| 20302 | * 3. If we fail to get one from pvt_pool and this is an expedite request, |
| 20303 | * get one free xri from expedite pool. |
| 20304 | * |
| 20305 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20306 | * The caller should pass NULL for ndlp on NVME side. |
| 20307 | * |
| 20308 | * Return: |
| 20309 | * pointer to one free IO buf - if private pool is not empty |
| 20310 | * NULL - if private pool is empty |
| 20311 | **/ |
| 20312 | static struct lpfc_io_buf * |
| 20313 | lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba, |
| 20314 | struct lpfc_nodelist *ndlp, |
| 20315 | int hwqid, int expedite) |
| 20316 | { |
| 20317 | struct lpfc_sli4_hdw_queue *qp; |
| 20318 | struct lpfc_multixri_pool *multixri_pool; |
| 20319 | struct lpfc_pvt_pool *pvt_pool; |
| 20320 | struct lpfc_io_buf *lpfc_ncmd; |
| 20321 | |
| 20322 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20323 | lpfc_ncmd = NULL; |
| 20324 | multixri_pool = qp->p_multixri_pool; |
| 20325 | pvt_pool = &multixri_pool->pvt_pool; |
| 20326 | multixri_pool->io_req_count++; |
| 20327 | |
| 20328 | /* If pvt_pool is empty, move some XRIs from public to private pool */ |
| 20329 | if (pvt_pool->count == 0) |
| 20330 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20331 | |
| 20332 | /* Get one XRI from private free xri pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20333 | 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] | 20334 | |
| 20335 | if (lpfc_ncmd) { |
| 20336 | lpfc_ncmd->hdwq = qp; |
| 20337 | lpfc_ncmd->hdwq_no = hwqid; |
| 20338 | } else if (expedite) { |
| 20339 | /* If we fail to get one from pvt_pool and this is an expedite |
| 20340 | * request, get one free xri from expedite pool. |
| 20341 | */ |
| 20342 | lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba); |
| 20343 | } |
| 20344 | |
| 20345 | return lpfc_ncmd; |
| 20346 | } |
| 20347 | |
| 20348 | static inline struct lpfc_io_buf * |
| 20349 | lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx) |
| 20350 | { |
| 20351 | struct lpfc_sli4_hdw_queue *qp; |
| 20352 | struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next; |
| 20353 | |
| 20354 | qp = &phba->sli4_hba.hdwq[idx]; |
| 20355 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 20356 | &qp->lpfc_io_buf_list_get, list) { |
| 20357 | if (lpfc_test_rrq_active(phba, ndlp, |
| 20358 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 20359 | continue; |
| 20360 | |
| 20361 | if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED) |
| 20362 | continue; |
| 20363 | |
| 20364 | list_del_init(&lpfc_cmd->list); |
| 20365 | qp->get_io_bufs--; |
| 20366 | lpfc_cmd->hdwq = qp; |
| 20367 | lpfc_cmd->hdwq_no = idx; |
| 20368 | return lpfc_cmd; |
| 20369 | } |
| 20370 | return NULL; |
| 20371 | } |
| 20372 | |
| 20373 | /** |
| 20374 | * lpfc_get_io_buf - Get one IO buffer from free pool |
| 20375 | * @phba: The HBA for which this call is being executed. |
| 20376 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20377 | * @hwqid: belong to which HWQ |
| 20378 | * @expedite: 1 means this request is urgent. |
| 20379 | * |
| 20380 | * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1, |
| 20381 | * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes |
| 20382 | * a IO buffer from head of @hdwq io_buf_list and returns to caller. |
| 20383 | * |
| 20384 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20385 | * The caller should pass NULL for ndlp on NVME side. |
| 20386 | * |
| 20387 | * Return codes: |
| 20388 | * NULL - Error |
| 20389 | * Pointer to lpfc_io_buf - Success |
| 20390 | **/ |
| 20391 | struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba, |
| 20392 | struct lpfc_nodelist *ndlp, |
| 20393 | u32 hwqid, int expedite) |
| 20394 | { |
| 20395 | struct lpfc_sli4_hdw_queue *qp; |
| 20396 | unsigned long iflag; |
| 20397 | struct lpfc_io_buf *lpfc_cmd; |
| 20398 | |
| 20399 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20400 | lpfc_cmd = NULL; |
| 20401 | |
| 20402 | if (phba->cfg_xri_rebalancing) |
| 20403 | lpfc_cmd = lpfc_get_io_buf_from_multixri_pools( |
| 20404 | phba, ndlp, hwqid, expedite); |
| 20405 | else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20406 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag, |
| 20407 | qp, alloc_xri_get); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20408 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite) |
| 20409 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20410 | if (!lpfc_cmd) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20411 | lpfc_qp_spin_lock(&qp->io_buf_list_put_lock, |
| 20412 | qp, alloc_xri_put); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20413 | list_splice(&qp->lpfc_io_buf_list_put, |
| 20414 | &qp->lpfc_io_buf_list_get); |
| 20415 | qp->get_io_bufs += qp->put_io_bufs; |
| 20416 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 20417 | qp->put_io_bufs = 0; |
| 20418 | spin_unlock(&qp->io_buf_list_put_lock); |
| 20419 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || |
| 20420 | expedite) |
| 20421 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20422 | } |
| 20423 | spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag); |
| 20424 | } |
| 20425 | |
| 20426 | return lpfc_cmd; |
| 20427 | } |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20428 | |
| 20429 | /** |
| 20430 | * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool |
| 20431 | * @phba: The HBA for which this call is being executed. |
| 20432 | * @lpfc_buf: IO buf structure to append the SGL chunk |
| 20433 | * |
| 20434 | * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool, |
| 20435 | * and will allocate an SGL chunk if the pool is empty. |
| 20436 | * |
| 20437 | * Return codes: |
| 20438 | * NULL - Error |
| 20439 | * Pointer to sli4_hybrid_sgl - Success |
| 20440 | **/ |
| 20441 | struct sli4_hybrid_sgl * |
| 20442 | lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 20443 | { |
| 20444 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20445 | struct sli4_hybrid_sgl *tmp = NULL; |
| 20446 | struct sli4_hybrid_sgl *allocated_sgl = NULL; |
| 20447 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20448 | struct list_head *buf_list = &hdwq->sgl_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20449 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20450 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20451 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20452 | |
| 20453 | if (likely(!list_empty(buf_list))) { |
| 20454 | /* break off 1 chunk from the sgl_list */ |
| 20455 | list_for_each_entry_safe(list_entry, tmp, |
| 20456 | buf_list, list_node) { |
| 20457 | list_move_tail(&list_entry->list_node, |
| 20458 | &lpfc_buf->dma_sgl_xtra_list); |
| 20459 | break; |
| 20460 | } |
| 20461 | } else { |
| 20462 | /* allocate more */ |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20463 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20464 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
| 20465 | cpu_to_node(smp_processor_id())); |
| 20466 | if (!tmp) { |
| 20467 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20468 | "8353 error kmalloc memory for HDWQ " |
| 20469 | "%d %s\n", |
| 20470 | lpfc_buf->hdwq_no, __func__); |
| 20471 | return NULL; |
| 20472 | } |
| 20473 | |
| 20474 | tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool, |
| 20475 | GFP_ATOMIC, &tmp->dma_phys_sgl); |
| 20476 | if (!tmp->dma_sgl) { |
| 20477 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20478 | "8354 error pool_alloc memory for HDWQ " |
| 20479 | "%d %s\n", |
| 20480 | lpfc_buf->hdwq_no, __func__); |
| 20481 | kfree(tmp); |
| 20482 | return NULL; |
| 20483 | } |
| 20484 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20485 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20486 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list); |
| 20487 | } |
| 20488 | |
| 20489 | allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list, |
| 20490 | struct sli4_hybrid_sgl, |
| 20491 | list_node); |
| 20492 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20493 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20494 | |
| 20495 | return allocated_sgl; |
| 20496 | } |
| 20497 | |
| 20498 | /** |
| 20499 | * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool |
| 20500 | * @phba: The HBA for which this call is being executed. |
| 20501 | * @lpfc_buf: IO buf structure with the SGL chunk |
| 20502 | * |
| 20503 | * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool. |
| 20504 | * |
| 20505 | * Return codes: |
| 20506 | * 0 - Success |
| 20507 | * -EINVAL - Error |
| 20508 | **/ |
| 20509 | int |
| 20510 | lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf) |
| 20511 | { |
| 20512 | int rc = 0; |
| 20513 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20514 | struct sli4_hybrid_sgl *tmp = NULL; |
| 20515 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20516 | struct list_head *buf_list = &hdwq->sgl_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20517 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20518 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20519 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20520 | |
| 20521 | if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) { |
| 20522 | list_for_each_entry_safe(list_entry, tmp, |
| 20523 | &lpfc_buf->dma_sgl_xtra_list, |
| 20524 | list_node) { |
| 20525 | list_move_tail(&list_entry->list_node, |
| 20526 | buf_list); |
| 20527 | } |
| 20528 | } else { |
| 20529 | rc = -EINVAL; |
| 20530 | } |
| 20531 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20532 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20533 | return rc; |
| 20534 | } |
| 20535 | |
| 20536 | /** |
| 20537 | * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool |
| 20538 | * @phba: phba object |
| 20539 | * @hdwq: hdwq to cleanup sgl buff resources on |
| 20540 | * |
| 20541 | * This routine frees all SGL chunks of hdwq SGL chunk pool. |
| 20542 | * |
| 20543 | * Return codes: |
| 20544 | * None |
| 20545 | **/ |
| 20546 | void |
| 20547 | lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba, |
| 20548 | struct lpfc_sli4_hdw_queue *hdwq) |
| 20549 | { |
| 20550 | struct list_head *buf_list = &hdwq->sgl_list; |
| 20551 | struct sli4_hybrid_sgl *list_entry = NULL; |
| 20552 | struct sli4_hybrid_sgl *tmp = NULL; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20553 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20554 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20555 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20556 | |
| 20557 | /* Free sgl pool */ |
| 20558 | list_for_each_entry_safe(list_entry, tmp, |
| 20559 | buf_list, list_node) { |
| 20560 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 20561 | list_entry->dma_sgl, |
| 20562 | list_entry->dma_phys_sgl); |
| 20563 | list_del(&list_entry->list_node); |
| 20564 | kfree(list_entry); |
| 20565 | } |
| 20566 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20567 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20568 | } |
| 20569 | |
| 20570 | /** |
| 20571 | * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq |
| 20572 | * @phba: The HBA for which this call is being executed. |
| 20573 | * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer |
| 20574 | * |
| 20575 | * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool, |
| 20576 | * and will allocate an CMD/RSP buffer if the pool is empty. |
| 20577 | * |
| 20578 | * Return codes: |
| 20579 | * NULL - Error |
| 20580 | * Pointer to fcp_cmd_rsp_buf - Success |
| 20581 | **/ |
| 20582 | struct fcp_cmd_rsp_buf * |
| 20583 | lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 20584 | struct lpfc_io_buf *lpfc_buf) |
| 20585 | { |
| 20586 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 20587 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 20588 | struct fcp_cmd_rsp_buf *allocated_buf = NULL; |
| 20589 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20590 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20591 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20592 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20593 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20594 | |
| 20595 | if (likely(!list_empty(buf_list))) { |
| 20596 | /* break off 1 chunk from the list */ |
| 20597 | list_for_each_entry_safe(list_entry, tmp, |
| 20598 | buf_list, |
| 20599 | list_node) { |
| 20600 | list_move_tail(&list_entry->list_node, |
| 20601 | &lpfc_buf->dma_cmd_rsp_list); |
| 20602 | break; |
| 20603 | } |
| 20604 | } else { |
| 20605 | /* allocate more */ |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20606 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20607 | tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC, |
| 20608 | cpu_to_node(smp_processor_id())); |
| 20609 | if (!tmp) { |
| 20610 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20611 | "8355 error kmalloc memory for HDWQ " |
| 20612 | "%d %s\n", |
| 20613 | lpfc_buf->hdwq_no, __func__); |
| 20614 | return NULL; |
| 20615 | } |
| 20616 | |
| 20617 | tmp->fcp_cmnd = dma_pool_alloc(phba->lpfc_cmd_rsp_buf_pool, |
| 20618 | GFP_ATOMIC, |
| 20619 | &tmp->fcp_cmd_rsp_dma_handle); |
| 20620 | |
| 20621 | if (!tmp->fcp_cmnd) { |
| 20622 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 20623 | "8356 error pool_alloc memory for HDWQ " |
| 20624 | "%d %s\n", |
| 20625 | lpfc_buf->hdwq_no, __func__); |
| 20626 | kfree(tmp); |
| 20627 | return NULL; |
| 20628 | } |
| 20629 | |
| 20630 | tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd + |
| 20631 | sizeof(struct fcp_cmnd)); |
| 20632 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20633 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20634 | list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list); |
| 20635 | } |
| 20636 | |
| 20637 | allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list, |
| 20638 | struct fcp_cmd_rsp_buf, |
| 20639 | list_node); |
| 20640 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20641 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20642 | |
| 20643 | return allocated_buf; |
| 20644 | } |
| 20645 | |
| 20646 | /** |
| 20647 | * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool |
| 20648 | * @phba: The HBA for which this call is being executed. |
| 20649 | * @lpfc_buf: IO buf structure with the CMD/RSP buf |
| 20650 | * |
| 20651 | * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool. |
| 20652 | * |
| 20653 | * Return codes: |
| 20654 | * 0 - Success |
| 20655 | * -EINVAL - Error |
| 20656 | **/ |
| 20657 | int |
| 20658 | lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 20659 | struct lpfc_io_buf *lpfc_buf) |
| 20660 | { |
| 20661 | int rc = 0; |
| 20662 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 20663 | struct fcp_cmd_rsp_buf *tmp = NULL; |
| 20664 | struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq; |
| 20665 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20666 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20667 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20668 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20669 | |
| 20670 | if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) { |
| 20671 | list_for_each_entry_safe(list_entry, tmp, |
| 20672 | &lpfc_buf->dma_cmd_rsp_list, |
| 20673 | list_node) { |
| 20674 | list_move_tail(&list_entry->list_node, |
| 20675 | buf_list); |
| 20676 | } |
| 20677 | } else { |
| 20678 | rc = -EINVAL; |
| 20679 | } |
| 20680 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20681 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20682 | return rc; |
| 20683 | } |
| 20684 | |
| 20685 | /** |
| 20686 | * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool |
| 20687 | * @phba: phba object |
| 20688 | * @hdwq: hdwq to cleanup cmd rsp buff resources on |
| 20689 | * |
| 20690 | * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool. |
| 20691 | * |
| 20692 | * Return codes: |
| 20693 | * None |
| 20694 | **/ |
| 20695 | void |
| 20696 | lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba, |
| 20697 | struct lpfc_sli4_hdw_queue *hdwq) |
| 20698 | { |
| 20699 | struct list_head *buf_list = &hdwq->cmd_rsp_buf_list; |
| 20700 | struct fcp_cmd_rsp_buf *list_entry = NULL; |
| 20701 | struct fcp_cmd_rsp_buf *tmp = NULL; |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20702 | unsigned long iflags; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20703 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20704 | spin_lock_irqsave(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20705 | |
| 20706 | /* Free cmd_rsp buf pool */ |
| 20707 | list_for_each_entry_safe(list_entry, tmp, |
| 20708 | buf_list, |
| 20709 | list_node) { |
| 20710 | dma_pool_free(phba->lpfc_cmd_rsp_buf_pool, |
| 20711 | list_entry->fcp_cmnd, |
| 20712 | list_entry->fcp_cmd_rsp_dma_handle); |
| 20713 | list_del(&list_entry->list_node); |
| 20714 | kfree(list_entry); |
| 20715 | } |
| 20716 | |
James Smart | a4c21ac | 2019-09-21 20:59:01 -0700 | [diff] [blame] | 20717 | spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 20718 | } |